Improved chat messaging functions
* Moved string manipulation into cClientHandle and therefore... + Added configuration option for prefixes. * Cleaned up code. * Updated documentation for API.
This commit is contained in:
parent
aa8b46e947
commit
88a64ec40d
@ -1644,7 +1644,13 @@ a_Player:OpenWindow(Window);
|
||||
OpenWindow = { Params = "{{cWindow|Window}}", Return = "", Notes = "Opens the specified UI window for the player." },
|
||||
RemoveFromGroup = { Params = "GroupName", Return = "", Notes = "Temporarily removes the player from the specified group. This change is lost when the player disconnects." },
|
||||
Respawn = { Params = "", Return = "", Notes = "Restores the health, extinguishes fire, makes visible and sends the Respawn packet." },
|
||||
SendMessage = { Params = "MessageString", Return = "", Notes = "Sends the specified message to the player." },
|
||||
SendMessage = { Params = "Message", Return = "", Notes = "Sends the specified message to the player." },
|
||||
SendMessageFailure = { Params = "Message", Return = "", Notes = "Prepends Rose [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and sends message to player. For a command that failed to run because of insufficient permissions, etc." },
|
||||
SendMessageFatal = { Params = "Message", Return = "", Notes = "Prepends Red [FATAL] / colours entire text (depending on ShouldUseChatPrefixes()) and sends message to player. For something serious, such as a plugin crash, etc." },
|
||||
SendMessageInfo = { Params = "Message", Return = "", Notes = "Prepends Yellow [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and sends message to player. Informational message, such as command usage, etc." },
|
||||
SendMessagePrivateMsg = { Params = "Message, SenderName", Return = "", Notes = "Prepends Light Blue [MSG: *SenderName*] / prepends SenderName and colours entire text (depending on ShouldUseChatPrefixes()) and sends message to player. For private messaging." },
|
||||
SendMessageSuccess = { Params = "Message", Return = "", Notes = "Prepends Green [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and sends message to player. Success notification." },
|
||||
SendMessageWarning = { Params = "Message, Sender", Return = "", Notes = "Prepends Rose [WARN] / colours entire text (depending on ShouldUseChatPrefixes()) and sends message to player. Denotes that something concerning, such as plugin reload, is about to happen." },
|
||||
SetCanFly = { Params = "CanFly", Notes = "Sets if the player can fly or not." },
|
||||
SetCrouch = { Params = "IsCrouched", Return = "", Notes = "Sets the crouch state, broadcasts the change to other players." },
|
||||
SetCurrentExperience = { Params = "XPAmount", Return = "", Notes = "Sets the current amount of experience (and indirectly, the XP level)." },
|
||||
@ -1823,7 +1829,12 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage);
|
||||
Functions =
|
||||
{
|
||||
Get = { Params = "", Return = "Root object", Notes = "(STATIC)This function returns the cRoot object." },
|
||||
BroadcastChat = { Params = "Message", Return = "", Notes = "Broadcasts a message to every player in the server." },
|
||||
BroadcastChat = { Params = "Message", Return = "", Notes = "Broadcasts a message to every player in the server. No formatting is done by the server." },
|
||||
BroadcastChatFailure = { Params = "Message", Return = "", Notes = "Prepends Rose [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For a command that failed to run because of insufficient permissions, etc." },
|
||||
BroadcastChatFatal = { Params = "Message", Return = "", Notes = "Prepends Red [FATAL] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For a plugin that crashed, or similar." },
|
||||
BroadcastChatInfo = { Params = "Message", Return = "", Notes = "Prepends Yellow [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For informational messages, such as command usage." },
|
||||
BroadcastChatSuccess = { Params = "Message", Return = "", Notes = "Prepends Green [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For success messages." },
|
||||
BroadcastChatWarning = { Params = "Message", Return = "", Notes = "Prepends Rose [WARN] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For concerning events, such as plugin reload etc." },
|
||||
FindAndDoWithPlayer = { Params = "PlayerName, CallbackFunction", Return = "", Notes = "Calls the given callback function for the given player." },
|
||||
ForEachPlayer = { Params = "CallbackFunction", Return = "", Notes = "Calls the given callback function for each player. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cPlayer|cPlayer}})</pre>" },
|
||||
ForEachWorld = { Params = "CallbackFunction", Return = "", Notes = "Calls the given callback function for each world. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cWorld|cWorld}})</pre>" },
|
||||
@ -2014,8 +2025,14 @@ end
|
||||
|
||||
Functions =
|
||||
{
|
||||
AreCommandBlocksEnabled = { Params = "", Return = "bool", Notes = "Returns whether command blocks are enabled on the (entire) server" },
|
||||
BroadcastBlockAction = { Params = "BlockX, BlockY, BlockZ, ActionByte1, ActionByte2, BlockType, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Broadcasts the BlockAction packet to all clients who have the appropriate chunk loaded (except ExcludeClient). The contents of the packet are specified by the parameters for the call, the blocktype needn't match the actual block that is present in the world data at the specified location." },
|
||||
BroadcastChat = { Params = "Message, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Sends the Message to all players in this world, except the optional ExceptClient" },
|
||||
BroadcastChat = { Params = "Message, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Sends the Message to all players in this world, except the optional ExcludeClient. No formatting is done by the server." },
|
||||
BroadcastChatFailure = { Params = "Message, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Prepends Rose [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For a command that failed to run because of insufficient permissions, etc." },
|
||||
BroadcastChatFatal = { Params = "Message, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Prepends Red [FATAL] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For a plugin that crashed, or similar." },
|
||||
BroadcastChatInfo = { Params = "Message, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Prepends Yellow [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For informational messages, such as command usage." },
|
||||
BroadcastChatSuccess = { Params = "Message, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Prepends Green [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For success messages." },
|
||||
BroadcastChatWarning = { Params = "Message, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Prepends Rose [WARN] / colours entire text (depending on ShouldUseChatPrefixes()) and broadcasts message. For concerning events, such as plugin reload etc." },
|
||||
BroadcastSoundEffect = { Params = "SoundName, X, Y, Z, Volume, Pitch, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Sends the specified sound effect to all players in this world, except the optional ExceptClient" },
|
||||
BroadcastSoundParticleEffect = { Params = "EffectID, X, Y, Z, EffectData, [{{cClientHandle|ExcludeClient}}]", Return = "", Notes = "Sends the specified effect to all players in this world, except the optional ExceptClient" },
|
||||
CastThunderbolt = { Params = "X, Y, Z", Return = "", Notes = "Creates a thunderbolt at the specified coords" },
|
||||
@ -2111,6 +2128,10 @@ end
|
||||
{ Params = "{{Vector3i|BlockCoords}}, BlockMeta", Return = "", Notes = "Sets the meta for the block at the specified coords." },
|
||||
},
|
||||
SetNextBlockTick = { Params = "BlockX, BlockY, BlockZ", Return = "", Notes = "Sets the blockticking to start at the specified block in the next tick." },
|
||||
SetCommandBlockCommand = { Params = "BlockX, BlockY, BlockZ, Command", Return = "bool", Notes = "Sets the command to be executed in a command block at the specified coordinates. Returns if command was changed." },
|
||||
SetCommandBlocksEnabled = { Params = "IsEnabled (bool)", Return = "", Notes = "Sets whether command blocks should be enabled on the (entire) server." },
|
||||
SetShouldUseChatPrefixes = { Params = "", Return = "ShouldUse (bool)", Notes = "Sets whether coloured chat prefixes such as [INFO] is used with the SendMessageXXX() or BroadcastChatXXX(), or simply the entire message is coloured in the respective colour." },
|
||||
ShouldUseChatPrefixes = { Params = "", Return = "bool", Notes = "Returns whether coloured chat prefixes are prepended to chat messages or the entire message is simply coloured." },
|
||||
SetSignLines = { Params = "X, Y, Z, Line1, Line2, Line3, Line4, [{{cPlayer|Player}}]", Return = "", Notes = "Sets the sign text at the specified coords. The sign-updating hooks are called for the change. The Player parameter is used to indicate the player from whom the change has come, it may be nil. Same as UpdateSign()." },
|
||||
SetTicksUntilWeatherChange = { Params = "NumTicks", Return = "", Notes = "Sets the number of ticks after which the weather will be changed." },
|
||||
SetTimeOfDay = { Params = "TimeOfDayTicks", Return = "", Notes = "Sets the time of day, expressed as number of ticks past sunrise, in the range 0 .. 24000." },
|
||||
|
@ -566,7 +566,7 @@ void cClientHandle::HandleCommandBlockMessage(const char* a_Data, unsigned int a
|
||||
{
|
||||
if (a_Length < 14)
|
||||
{
|
||||
SendChat(AppendChatEpithet("Failure setting command block command; bad request", mtFailure));
|
||||
SendChat("Failure setting command block command; bad request", mtFailure);
|
||||
LOGD("Malformed MC|AdvCdm packet.");
|
||||
return;
|
||||
}
|
||||
@ -596,7 +596,7 @@ void cClientHandle::HandleCommandBlockMessage(const char* a_Data, unsigned int a
|
||||
|
||||
default:
|
||||
{
|
||||
SendChat(AppendChatEpithet("Failure setting command block command; unhandled mode", mtFailure));
|
||||
SendChat("Failure setting command block command; unhandled mode", mtFailure);
|
||||
LOGD("Unhandled MC|AdvCdm packet mode.");
|
||||
return;
|
||||
}
|
||||
@ -608,11 +608,11 @@ void cClientHandle::HandleCommandBlockMessage(const char* a_Data, unsigned int a
|
||||
{
|
||||
World->SetCommandBlockCommand(BlockX, BlockY, BlockZ, Command);
|
||||
|
||||
SendChat(AppendChatEpithet("Successfully set command block command", mtSuccess));
|
||||
SendChat("Successfully set command block command", mtSuccess);
|
||||
}
|
||||
else
|
||||
{
|
||||
SendChat(AppendChatEpithet("Command blocks are not enabled on this server", mtFailure));
|
||||
SendChat("Command blocks are not enabled on this server", mtFailure);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1729,9 +1729,111 @@ void cClientHandle::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlock
|
||||
|
||||
|
||||
|
||||
void cClientHandle::SendChat(const AString & a_Message)
|
||||
void cClientHandle::SendChat(const AString & a_Message, ChatPrefixCodes a_ChatPrefix, const AString & a_AdditionalData)
|
||||
{
|
||||
m_Protocol->SendChat(a_Message);
|
||||
bool ShouldAppendChatPrefixes = true;
|
||||
|
||||
if (GetPlayer()->GetWorld() == NULL)
|
||||
{
|
||||
cWorld * World = cRoot::Get()->GetWorld(GetPlayer()->GetLoadedWorldName());
|
||||
if (World == NULL)
|
||||
{
|
||||
World = cRoot::Get()->GetDefaultWorld();
|
||||
}
|
||||
|
||||
if (!World->ShouldUseChatPrefixes())
|
||||
{
|
||||
ShouldAppendChatPrefixes = false;
|
||||
}
|
||||
}
|
||||
else if (!GetPlayer()->GetWorld()->ShouldUseChatPrefixes())
|
||||
{
|
||||
ShouldAppendChatPrefixes = false;
|
||||
}
|
||||
|
||||
AString Message;
|
||||
|
||||
switch (a_ChatPrefix)
|
||||
{
|
||||
case mtCustom: break;
|
||||
case mtFailure:
|
||||
{
|
||||
if (ShouldAppendChatPrefixes)
|
||||
Message = Printf("%s[INFO] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str());
|
||||
else
|
||||
Message = Printf("%s", cChatColor::Rose.c_str());
|
||||
break;
|
||||
}
|
||||
case mtInformation:
|
||||
{
|
||||
if (ShouldAppendChatPrefixes)
|
||||
Message = Printf("%s[INFO] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str());
|
||||
else
|
||||
Message = Printf("%s", cChatColor::Yellow.c_str());
|
||||
break;
|
||||
}
|
||||
case mtSuccess:
|
||||
{
|
||||
if (ShouldAppendChatPrefixes)
|
||||
Message = Printf("%s[INFO] %s", cChatColor::Green.c_str(), cChatColor::White.c_str());
|
||||
else
|
||||
Message = Printf("%s", cChatColor::Green.c_str());
|
||||
break;
|
||||
}
|
||||
case mtWarning:
|
||||
{
|
||||
if (ShouldAppendChatPrefixes)
|
||||
Message = Printf("%s[WARN] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str());
|
||||
else
|
||||
Message = Printf("%s", cChatColor::Rose.c_str());
|
||||
break;
|
||||
}
|
||||
case mtFatal:
|
||||
{
|
||||
if (ShouldAppendChatPrefixes)
|
||||
Message = Printf("%s[FATAL] %s", cChatColor::Red.c_str(), cChatColor::White.c_str());
|
||||
else
|
||||
Message = Printf("%s", cChatColor::Red.c_str());
|
||||
break;
|
||||
}
|
||||
case mtDeath:
|
||||
{
|
||||
if (ShouldAppendChatPrefixes)
|
||||
Message = Printf("%s[DEATH] %s", cChatColor::Gray.c_str(), cChatColor::White.c_str());
|
||||
else
|
||||
Message = Printf("%s", cChatColor::Gray.c_str());
|
||||
break;
|
||||
}
|
||||
case mtPrivateMessage:
|
||||
{
|
||||
if (ShouldAppendChatPrefixes)
|
||||
Message = Printf("%s[MSG: %s] %s%s", cChatColor::LightBlue.c_str(), a_AdditionalData.c_str(), cChatColor::White.c_str(), cChatColor::Italic.c_str());
|
||||
else
|
||||
Message = Printf("%s", cChatColor::LightBlue.c_str());
|
||||
break;
|
||||
}
|
||||
case mtJoin:
|
||||
{
|
||||
if (ShouldAppendChatPrefixes)
|
||||
Message = Printf("%s[JOIN] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str());
|
||||
else
|
||||
Message = Printf("%s", cChatColor::Yellow.c_str());
|
||||
break;
|
||||
}
|
||||
case mtLeave:
|
||||
{
|
||||
if (ShouldAppendChatPrefixes)
|
||||
Message = Printf("%s[LEAVE] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str());
|
||||
else
|
||||
Message = Printf("%s", cChatColor::Yellow.c_str());
|
||||
break;
|
||||
}
|
||||
default: ASSERT(!"Unhandled chat prefix type!"); return;
|
||||
}
|
||||
|
||||
Message.append(a_Message);
|
||||
|
||||
m_Protocol->SendChat(Message);
|
||||
}
|
||||
|
||||
|
||||
|
@ -89,7 +89,7 @@ public:
|
||||
void SendBlockBreakAnim (int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage);
|
||||
void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); // tolua_export
|
||||
void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes);
|
||||
void SendChat (const AString & a_Message);
|
||||
void SendChat (const AString & a_Message, ChatPrefixCodes a_ChatPrefix, const AString & a_AdditionalData = "");
|
||||
void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer);
|
||||
void SendCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player);
|
||||
void SendDestroyEntity (const cEntity & a_Entity);
|
||||
|
@ -448,6 +448,7 @@ enum ChatPrefixCodes
|
||||
// http://forum.mc-server.org/showthread.php?tid=1212
|
||||
// MessageType...
|
||||
|
||||
mtCustom, // Send raw data without any processing
|
||||
mtFailure, // Something could not be done (i.e. command not executed due to insufficient privilege)
|
||||
mtInformation, // Informational message (i.e. command usage)
|
||||
mtSuccess, // Something executed successfully
|
||||
@ -459,70 +460,9 @@ enum ChatPrefixCodes
|
||||
mtLeave, // A player has left the server
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
inline AString AppendChatEpithet(const AString & a_ChatMessage, ChatPrefixCodes a_ChatPrefix)
|
||||
{
|
||||
AString Message;
|
||||
|
||||
switch (a_ChatPrefix)
|
||||
{
|
||||
case mtFailure:
|
||||
{
|
||||
Message = Printf("%s[INFO] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str());
|
||||
break;
|
||||
}
|
||||
case mtInformation:
|
||||
{
|
||||
Message = Printf("%s[INFO] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str());
|
||||
break;
|
||||
}
|
||||
case mtSuccess:
|
||||
{
|
||||
Message = Printf("%s[INFO] %s", cChatColor::Green.c_str(), cChatColor::White.c_str());
|
||||
break;
|
||||
}
|
||||
case mtWarning:
|
||||
{
|
||||
Message = Printf("%s[WARN] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str());
|
||||
break;
|
||||
}
|
||||
case mtFatal:
|
||||
{
|
||||
Message = Printf("%s[FATAL] %s", cChatColor::Red.c_str(), cChatColor::White.c_str());
|
||||
break;
|
||||
}
|
||||
case mtDeath:
|
||||
{
|
||||
Message = Printf("%s[DEATH] %s", cChatColor::Gray.c_str(), cChatColor::White.c_str());
|
||||
break;
|
||||
}
|
||||
case mtPrivateMessage:
|
||||
{
|
||||
Message = Printf("%s[MSG] %s%s", cChatColor::LightBlue.c_str(), cChatColor::White.c_str(), cChatColor::Italic.c_str());
|
||||
break;
|
||||
}
|
||||
case mtJoin:
|
||||
{
|
||||
Message = Printf("%s[JOIN] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str());
|
||||
break;
|
||||
}
|
||||
case mtLeave:
|
||||
{
|
||||
Message = Printf("%s[LEAVE] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str());
|
||||
break;
|
||||
}
|
||||
default: ASSERT(!"Unhandled chat prefix type!"); return "";
|
||||
}
|
||||
|
||||
Message.append(a_ChatMessage);
|
||||
return Message;
|
||||
}
|
||||
|
||||
// tolua_begin
|
||||
|
||||
/// Normalizes an angle in degrees to the [-180, +180) range:
|
||||
/** Normalizes an angle in degrees to the [-180, +180) range: */
|
||||
inline double NormalizeAngleDegrees(const double a_Degrees)
|
||||
{
|
||||
double Norm = fmod(a_Degrees + 180, 360);
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
#include "Player.h"
|
||||
#include "../Server.h"
|
||||
#include "../ClientHandle.h"
|
||||
#include "../UI/Window.h"
|
||||
#include "../UI/WindowOwner.h"
|
||||
#include "../World.h"
|
||||
@ -1121,15 +1120,6 @@ void cPlayer::SetIP(const AString & a_IP)
|
||||
|
||||
|
||||
|
||||
void cPlayer::SendMessage(const AString & a_Message)
|
||||
{
|
||||
m_ClientHandle->SendChat(a_Message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cPlayer::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ)
|
||||
{
|
||||
SetPosition( a_PosX, a_PosY, a_PosZ );
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "../Inventory.h"
|
||||
#include "../Defines.h"
|
||||
#include "../World.h"
|
||||
#include "../ClientHandle.h"
|
||||
|
||||
|
||||
|
||||
@ -195,13 +196,13 @@ public:
|
||||
|
||||
cClientHandle * GetClientHandle(void) const { return m_ClientHandle; }
|
||||
|
||||
void SendMessage(const AString & a_Message);
|
||||
void SendMessageInfo(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtInformation)); }
|
||||
void SendMessageFailure(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtFailure)); }
|
||||
void SendMessageSuccess(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtSuccess)); }
|
||||
void SendMessageWarning(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtWarning)); }
|
||||
void SendMessageFatal(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtFailure)); }
|
||||
void SendMessagePrivateMsg(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtPrivateMessage)); }
|
||||
void SendMessage (const AString & a_Message) { m_ClientHandle->SendChat(a_Message, mtCustom); }
|
||||
void SendMessageInfo (const AString & a_Message) { m_ClientHandle->SendChat(a_Message, mtInformation); }
|
||||
void SendMessageFailure (const AString & a_Message) { m_ClientHandle->SendChat(a_Message, mtFailure); }
|
||||
void SendMessageSuccess (const AString & a_Message) { m_ClientHandle->SendChat(a_Message, mtSuccess); }
|
||||
void SendMessageWarning (const AString & a_Message) { m_ClientHandle->SendChat(a_Message, mtWarning); }
|
||||
void SendMessageFatal (const AString & a_Message) { m_ClientHandle->SendChat(a_Message, mtFailure); }
|
||||
void SendMessagePrivateMsg(const AString & a_Message, const AString & a_Sender) { m_ClientHandle->SendChat(a_Message, mtPrivateMessage, a_Sender); }
|
||||
|
||||
const AString & GetName(void) const { return m_PlayerName; }
|
||||
void SetName(const AString & a_Name) { m_PlayerName = a_Name; }
|
||||
|
@ -536,11 +536,11 @@ void cRoot::SaveAllChunks(void)
|
||||
|
||||
|
||||
|
||||
void cRoot::BroadcastChat(const AString & a_Message)
|
||||
void cRoot::LoopWorldsAndBroadcastChat(const AString & a_Message, ChatPrefixCodes a_ChatPrefix)
|
||||
{
|
||||
for (WorldMap::iterator itr = m_WorldsByName.begin(), end = m_WorldsByName.end(); itr != end; ++itr)
|
||||
{
|
||||
itr->second->BroadcastChat(a_Message);
|
||||
itr->second->LoopPlayersAndBroadcastChat(a_Message, a_ChatPrefix);
|
||||
} // for itr - m_WorldsByName[]
|
||||
}
|
||||
|
||||
|
19
src/Root.h
19
src/Root.h
@ -105,19 +105,20 @@ public:
|
||||
/// Finds a player from a partial or complete player name and calls the callback - case-insensitive
|
||||
bool FindAndDoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
|
||||
|
||||
void BroadcastChatJoin(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtJoin)); }
|
||||
void BroadcastChatLeave(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtLeave)); }
|
||||
void LoopWorldsAndBroadcastChat(const AString & a_Message, ChatPrefixCodes a_ChatPrefix);
|
||||
void BroadcastChatJoin (const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtJoin); }
|
||||
void BroadcastChatLeave (const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtLeave); }
|
||||
void BroadcastChatDeath (const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtDeath); }
|
||||
|
||||
// tolua_begin
|
||||
|
||||
/// Sends a chat message to all connected clients (in all worlds)
|
||||
void BroadcastChat(const AString & a_Message);
|
||||
void BroadcastChatInfo(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtInformation)); }
|
||||
void BroadcastChatFailure(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtFailure)); }
|
||||
void BroadcastChatSuccess(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtSuccess)); }
|
||||
void BroadcastChatWarning(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtWarning)); }
|
||||
void BroadcastChatFatal(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtFailure)); }
|
||||
void BroadcastChatDeath(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtDeath)); }
|
||||
void BroadcastChat (const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtCustom); }
|
||||
void BroadcastChatInfo (const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtInformation); }
|
||||
void BroadcastChatFailure(const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtFailure); }
|
||||
void BroadcastChatSuccess(const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtSuccess); }
|
||||
void BroadcastChatWarning(const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtWarning); }
|
||||
void BroadcastChatFatal (const AString & a_Message) { LoopWorldsAndBroadcastChat(a_Message, mtFailure); }
|
||||
|
||||
/// Returns the textual description of the protocol version: 49 -> "1.4.4". Provided specifically for Lua API
|
||||
static AString GetProtocolVersionTextFromInt(int a_ProtocolVersionNum);
|
||||
|
@ -249,7 +249,9 @@ cWorld::cWorld(const AString & a_WorldName) :
|
||||
m_WeatherInterval(24000), // Guaranteed 1 day of sunshine at server start :)
|
||||
m_GeneratorCallbacks(*this),
|
||||
m_TickThread(*this),
|
||||
m_Scoreboard(this)
|
||||
m_Scoreboard(this),
|
||||
m_bCommandBlocksEnabled(false),
|
||||
m_bUseChatPrefixes(true)
|
||||
{
|
||||
LOGD("cWorld::cWorld(\"%s\")", a_WorldName.c_str());
|
||||
|
||||
@ -543,9 +545,10 @@ void cWorld::Start(void)
|
||||
m_IsSaplingBonemealable = IniFile.GetValueSetB("Plants", "IsSaplingBonemealable", true);
|
||||
m_IsSugarcaneBonemealable = IniFile.GetValueSetB("Plants", "IsSugarcaneBonemealable", false);
|
||||
m_bEnabledPVP = IniFile.GetValueSetB("PVP", "Enabled", true);
|
||||
m_IsDeepSnowEnabled = IniFile.GetValueSetB("Physics", "DeepSnow", false);
|
||||
m_IsDeepSnowEnabled = IniFile.GetValueSetB("Physics", "DeepSnow", true);
|
||||
m_ShouldLavaSpawnFire = IniFile.GetValueSetB("Physics", "ShouldLavaSpawnFire", true);
|
||||
m_bCommandBlocksEnabled = IniFile.GetValueSetB("Mechanics", "CommandBlocksEnabled", false);
|
||||
m_bUseChatPrefixes = IniFile.GetValueSetB("Mechanics", "UseChatPrefixes", true);
|
||||
m_VillagersShouldHarvestCrops = IniFile.GetValueSetB("Monsters", "VillagersShouldHarvestCrops", true);
|
||||
|
||||
m_GameMode = (eGameMode)IniFile.GetValueSetI("GameMode", "GameMode", m_GameMode);
|
||||
@ -1744,7 +1747,7 @@ void cWorld::BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cons
|
||||
|
||||
|
||||
|
||||
void cWorld::BroadcastChat(const AString & a_Message, const cClientHandle * a_Exclude)
|
||||
void cWorld::LoopPlayersAndBroadcastChat(const AString & a_Message, ChatPrefixCodes a_ChatPrefix, const cClientHandle * a_Exclude)
|
||||
{
|
||||
cCSLock Lock(m_CSPlayers);
|
||||
for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||
@ -1754,7 +1757,7 @@ void cWorld::BroadcastChat(const AString & a_Message, const cClientHandle * a_Ex
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ch->SendChat(a_Message);
|
||||
ch->SendChat(a_Message, a_ChatPrefix);
|
||||
}
|
||||
}
|
||||
|
||||
|
27
src/World.h
27
src/World.h
@ -158,14 +158,16 @@ public:
|
||||
void BroadcastBlockBreakAnimation(int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage, const cClientHandle * a_Exclude = NULL);
|
||||
void BroadcastBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL); ///< If there is a block entity at the specified coods, sends it to all clients except a_Exclude
|
||||
|
||||
// tolua_start
|
||||
void BroadcastChat(const AString & a_Message, const cClientHandle * a_Exclude = NULL);
|
||||
void BroadcastChatInfo(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { BroadcastChat(AppendChatEpithet(a_Message, mtInformation)); }
|
||||
void BroadcastChatFailure(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { BroadcastChat(AppendChatEpithet(a_Message, mtFailure)); }
|
||||
void BroadcastChatSuccess(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { BroadcastChat(AppendChatEpithet(a_Message, mtSuccess)); }
|
||||
void BroadcastChatWarning(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { BroadcastChat(AppendChatEpithet(a_Message, mtWarning)); }
|
||||
void BroadcastChatFatal(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { BroadcastChat(AppendChatEpithet(a_Message, mtFailure)); }
|
||||
void BroadcastChatDeath(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { BroadcastChat(AppendChatEpithet(a_Message, mtDeath)); }
|
||||
void LoopPlayersAndBroadcastChat(const AString & a_Message, ChatPrefixCodes a_ChatPrefix, const cClientHandle * a_Exclude = NULL);
|
||||
void BroadcastChatDeath (const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtDeath, a_Exclude); }
|
||||
|
||||
// tolua_begin
|
||||
void BroadcastChat (const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtCustom, a_Exclude); }
|
||||
void BroadcastChatInfo (const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtInformation, a_Exclude); }
|
||||
void BroadcastChatFailure(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtFailure, a_Exclude); }
|
||||
void BroadcastChatSuccess(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtSuccess, a_Exclude); }
|
||||
void BroadcastChatWarning(const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtWarning, a_Exclude); }
|
||||
void BroadcastChatFatal (const AString & a_Message, const cClientHandle * a_Exclude = NULL) { LoopPlayersAndBroadcastChat(a_Message, mtFailure, a_Exclude); }
|
||||
// tolua_end
|
||||
|
||||
void BroadcastChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude = NULL);
|
||||
@ -544,12 +546,14 @@ public:
|
||||
/** Returns the name of the world.ini file used by this world */
|
||||
const AString & GetIniFileName(void) const {return m_IniFileName; }
|
||||
|
||||
/// Returns the associated scoreboard instance
|
||||
/** Returns the associated scoreboard instance */
|
||||
cScoreboard & GetScoreBoard(void) { return m_Scoreboard; }
|
||||
|
||||
bool AreCommandBlocksEnabled(void) const { return m_bCommandBlocksEnabled; }
|
||||
|
||||
void SetCommandBlocksEnabled(bool a_Flag) { m_bCommandBlocksEnabled = a_Flag; }
|
||||
|
||||
bool ShouldUseChatPrefixes(void) const { return m_bUseChatPrefixes; }
|
||||
void SetShouldUseChatPrefixes(bool a_Flag) { m_bUseChatPrefixes = a_Flag; }
|
||||
|
||||
// tolua_end
|
||||
|
||||
@ -800,7 +804,10 @@ private:
|
||||
bool m_IsSaplingBonemealable;
|
||||
bool m_IsSugarcaneBonemealable;
|
||||
|
||||
/** Whether command blocks are enabled or not */
|
||||
bool m_bCommandBlocksEnabled;
|
||||
/** Whether prefixes such as [INFO] are prepended to SendMessageXXX() / BroadcastChatXXX() functions */
|
||||
bool m_bUseChatPrefixes;
|
||||
|
||||
|
||||
cChunkGenerator m_Generator;
|
||||
|
Loading…
Reference in New Issue
Block a user