Skip to content

Commit

Permalink
Added more chat functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tigerw committed Feb 5, 2014
1 parent 99fdadd commit 3450f0c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 27 deletions.
56 changes: 32 additions & 24 deletions src/Defines.h
Expand Up @@ -448,68 +448,76 @@ enum ChatPrefixCodes
// http://forum.mc-server.org/showthread.php?tid=1212
// MessageType...

mtCustom, // Plugin prints what it wants

This comment has been minimized.

Copy link
@worktycho

worktycho Feb 6, 2014

Member

Again, We should probably keep this temporarily (but warn on use) to prevent breaking plugins using this.

This comment has been minimized.

Copy link
@madmaxoft

madmaxoft Feb 6, 2014

Member

There are no plugins using this - it's only been implemented on a branch, not yet merged to the master.

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
mtWarning, // Something concerning (i.e. reload) is about to happen
mtFatal, // Something catastrophic occured (i.e. plugin crash)
mtDeath, // Denotes death of player
mtPrivateMessage // Player to player messaging identifier
mtPrivateMessage, // Player to player messaging identifier
mtJoin, // A player has joined the server
mtLeave, // A player has left the server
};




inline AString AppendChatEpithet(const AString & a_ChatMessage, ChatPrefixCodes a_ChatPrefix)
{
AString Message;

switch (a_ChatPrefix)
{
case mtCustom: return a_ChatMessage;
case mtFailure:
{
AString Message(Printf("%s[INFO] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str()));
Message.append(a_ChatMessage);
return Message;
Message = Printf("%s[INFO] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str());
break;
}
case mtInformation:
{
AString Message(Printf("%s[INFO] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()));
Message.append(a_ChatMessage);
return Message;
Message = Printf("%s[INFO] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str());
break;
}
case mtSuccess:
{
AString Message(Printf("%s[INFO] %s", cChatColor::Green.c_str(), cChatColor::White.c_str()));
Message.append(a_ChatMessage);
return Message;
Message = Printf("%s[INFO] %s", cChatColor::Green.c_str(), cChatColor::White.c_str());
break;
}
case mtWarning:
{
AString Message(Printf("%s[WARN] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str()));
Message.append(a_ChatMessage);
return Message;
Message = Printf("%s[WARN] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str());
break;
}
case mtFatal:
{
AString Message(Printf("%s[FATAL] %s", cChatColor::Red.c_str(), cChatColor::White.c_str()));
Message.append(a_ChatMessage);
return Message;
Message = Printf("%s[FATAL] %s", cChatColor::Red.c_str(), cChatColor::White.c_str());
break;
}
case mtDeath:
{
AString Message(Printf("%s[DEATH] %s", cChatColor::Gray.c_str(), cChatColor::White.c_str()));
Message.append(a_ChatMessage);
return Message;
Message = Printf("%s[DEATH] %s", cChatColor::Gray.c_str(), cChatColor::White.c_str());
break;
}
case mtPrivateMessage:
{
AString Message(Printf("%s[MSG] %s%s", cChatColor::LightBlue.c_str(), cChatColor::White.c_str(), cChatColor::Italic.c_str()));
Message.append(a_ChatMessage);
return Message;
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
Expand Down
1 change: 0 additions & 1 deletion src/Entities/Player.h
Expand Up @@ -201,7 +201,6 @@ class cPlayer :
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 SendMessageDeath(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtDeath)); }
void SendMessagePrivateMsg(const AString & a_Message) { SendMessage(AppendChatEpithet(a_Message, mtPrivateMessage)); }

const AString & GetName(void) const { return m_PlayerName; }
Expand Down
4 changes: 3 additions & 1 deletion src/Root.h
Expand Up @@ -104,6 +104,9 @@ class cRoot // tolua_export

/// 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)); }

// tolua_begin

Expand All @@ -115,7 +118,6 @@ class cRoot // tolua_export
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 BroadcastChatPrivateMsg(const AString & a_Message) { BroadcastChat(AppendChatEpithet(a_Message, mtPrivateMessage)); }

/// Returns the textual description of the protocol version: 49 -> "1.4.4". Provided specifically for Lua API
static AString GetProtocolVersionTextFromInt(int a_ProtocolVersionNum);
Expand Down
12 changes: 11 additions & 1 deletion src/World.h
Expand Up @@ -157,7 +157,17 @@ class cWorld : public cForEachChunkProvider, public cWorldInterface, public cBro
void BroadcastBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType, const cClientHandle * a_Exclude = NULL); // tolua_export
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
void BroadcastChat (const AString & a_Message, const cClientHandle * a_Exclude = NULL); // tolua_export

// tolua_start
void BroadcastChat(const AString & a_Message, const cClientHandle * a_Exclude = NULL);

This comment has been minimized.

Copy link
@worktycho

worktycho Feb 6, 2014

Member

Do you have to add another 5 methods to the World class. How about a separate chat manager?
Also, you should probably add a manual binding for Broadcast chat so that it doesn't break all the plugins that use chat.

This comment has been minimized.

Copy link
@madmaxoft

madmaxoft Feb 6, 2014

Member

Why not. I'm against having 50 manager classes when 1 superclass is enough. The cWorld IS a hub of MC information, so it deserves to be the hub.

I don't understand the plugin concerns - no plugins are using this, since it hasn't been merged into master yet, so there's no compatibility to be broken. And the original BroadcastChat() function is unchanged.

This comment has been minimized.

Copy link
@worktycho

worktycho Feb 6, 2014

Member

Yet at 800 lines cWorld is a giant and already unreadable. At least with managers it would be easier to find functions. If one superclass is enough why not stick everything in cRoot? As for the plugins I didn't see that this hasn't been exposed yet.

This comment has been minimized.

Copy link
@madmaxoft

madmaxoft Feb 6, 2014

Member

Managers make calling it difficult - you need to know that the specific function is in a specific manager, so instead of doing World->BroadcastMessage(), you'll need to know that the world has a messaging manager and do the long World->GetMessagingManager().BroadcastMessage() everytime you wanted a broadcast. I don't consider this very maintainable.

We might want to move this discussion into the forum in order not to spam this poor commit anymore.

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)); }
// tolua_end

void BroadcastChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude = NULL);
void BroadcastCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL);
void BroadcastDestroyEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
Expand Down

0 comments on commit 3450f0c

Please sign in to comment.