00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _TMWSERV_CHATHANDLER_H_
00023 #define _TMWSERV_CHATHANDLER_H_
00024
00025 #include <map>
00026 #include <string>
00027 #include <vector>
00028
00029 #include "net/connectionhandler.hpp"
00030 #include "utils/tokencollector.hpp"
00031
00032 class ChatChannel;
00033 class ChatClient;
00034
00044 class ChatHandler : public ConnectionHandler
00045 {
00046
00050 struct Pending
00051 {
00052 std::string character;
00053 unsigned char level;
00054 };
00055
00056 struct PartyInvite
00057 {
00058 std::string mInviter;
00059 std::string mInvited;
00060 int mPartyId;
00061 };
00062
00063 std::map<std::string, ChatClient*> mPlayerMap;
00064 std::vector<PartyInvite> mPartyInvitedUsers;
00065
00066 public:
00067
00068 ChatHandler();
00069
00073 bool startListen(enet_uint16 port);
00074
00081 void warnUsersAboutPlayerEventInChat(ChatChannel *channel,
00082 const std::string &info,
00083 char eventId);
00084
00088 void deletePendingClient(ChatClient *);
00089
00093 void deletePendingConnect(Pending *);
00094
00098 void tokenMatched(ChatClient *, Pending *);
00099
00103 void sendGuildListUpdate(const std::string &guildName,
00104 const std::string &characterName,
00105 char eventId);
00106
00107 protected:
00111 void processMessage(NetComputer *computer, MessageIn &message);
00112
00116 NetComputer *computerConnected(ENetPeer *);
00117
00121 void computerDisconnected(NetComputer *);
00122
00126 void sendGuildRejoin(ChatClient &computer);
00127
00132 void sendGuildEnterChannel(const MessageOut &msg,
00133 const std::string &name);
00134
00138 void sendGuildInvite(const std::string &invitedName,
00139 const std::string &inviterName,
00140 const std::string &guildName);
00141
00142 private:
00146 void handleCommand(ChatClient &client, const std::string &command);
00147
00151 void
00152 handleChatMessage(ChatClient &client, MessageIn &msg);
00153
00157 void
00158 handleAnnounceMessage(ChatClient &client, MessageIn &msg);
00159
00163 void
00164 handlePrivMsgMessage(ChatClient &client, MessageIn &msg);
00165
00169 void handleWhoMessage(ChatClient &client);
00170
00174 void
00175 handleEnterChannelMessage(ChatClient &client, MessageIn &msg);
00176
00180 void
00181 handleModeChangeMessage(ChatClient &client, MessageIn &msg);
00182
00186 void
00187 handleKickUserMessage(ChatClient &client, MessageIn &msg);
00188
00192 void
00193 handleQuitChannelMessage(ChatClient &client, MessageIn &msg);
00194
00198 void
00199 handleListChannelsMessage(ChatClient &client, MessageIn &msg);
00200
00204 void
00205 handleListChannelUsersMessage(ChatClient &client, MessageIn &msg);
00206
00210 void
00211 handleTopicChange(ChatClient &client, MessageIn &msg);
00212
00216 void
00217 handleDisconnectMessage(ChatClient &client, MessageIn &msg);
00218
00222 void
00223 handleGuildCreation(ChatClient &client, MessageIn &msg);
00224
00228 void
00229 handleGuildInvitation(ChatClient &client, MessageIn &msg);
00230
00234 void
00235 handleGuildAcceptInvite(ChatClient &client, MessageIn &msg);
00236
00240 void
00241 handleGuildRetrieveMembers(ChatClient &client, MessageIn &msg);
00242
00246 void
00247 handleGuildMemberLevelChange(ChatClient &client, MessageIn &msg);
00248
00252 void handleGuildMemberKick(ChatClient &client, MessageIn &msg);
00253
00257 void
00258 handleGuildQuit(ChatClient &client, MessageIn &msg);
00259
00264 bool
00265 handlePartyJoin(const std::string &invited, const std::string &inviter);
00266
00270 void
00271 handlePartyInvite(ChatClient &client, MessageIn &msg);
00272
00276 void
00277 handlePartyAcceptInvite(ChatClient &client, MessageIn &msg);
00278
00282 void
00283 handlePartyQuit(ChatClient &client);
00284
00288 void handlePartyRejection(ChatClient &client, MessageIn &msg);
00289
00293 void
00294 removeUserFromParty(ChatClient &client);
00295
00299 void
00300 sendPartyMemberInfo(ChatClient &client, MessageIn &msg);
00301
00305 void
00306 informPartyMemberQuit(ChatClient &client);
00307
00311 void
00312 informPartyMemberJoined(ChatClient &client);
00313
00317 void warnPlayerAboutBadWords(ChatClient &computer);
00318
00322 void sayToPlayer(ChatClient &computer, const std::string &playerName,
00323 const std::string &text);
00324
00331 void sendInChannel(ChatChannel *channel, MessageOut &msg);
00332
00340 ChatChannel* joinGuildChannel(const std::string &name, ChatClient &client);
00341
00347 ChatClient* getClient(const std::string &name);
00348
00352 void guildChannelTopicChange(ChatChannel *channel, int playerId,
00353 const std::string &topic);
00354
00358 TokenCollector<ChatHandler, ChatClient *, Pending *> mTokenCollector;
00359 friend void registerChatClient(const std::string &, const std::string &, int);
00360
00361 };
00362
00366 void registerChatClient(const std::string &, const std::string &, int);
00367
00368 extern ChatHandler *chatHandler;
00369
00370 #endif