diff options
author | Chuck Miller <shadowmil@gmail.com> | 2010-08-02 00:50:35 -0400 |
---|---|---|
committer | Chuck Miller <shadowmil@gmail.com> | 2010-08-02 01:18:33 -0400 |
commit | 6a0e5f20c9faf7623a465daa4a8b350d3a52e5e6 (patch) | |
tree | 0411f3e481165896c946d5bb5b4542776c8dbefb | |
parent | 9eb236c4dc25e818ee007aa2c9cb36a23111d8d9 (diff) | |
download | mana-client-6a0e5f20c9faf7623a465daa4a8b350d3a52e5e6.tar.gz mana-client-6a0e5f20c9faf7623a465daa4a8b350d3a52e5e6.tar.bz2 mana-client-6a0e5f20c9faf7623a465daa4a8b350d3a52e5e6.tar.xz mana-client-6a0e5f20c9faf7623a465daa4a8b350d3a52e5e6.zip |
Convert most of the remaining chat system to use the event system
Reviewed-by: Jared Adams
-rw-r--r-- | src/gui/chat.cpp | 25 | ||||
-rw-r--r-- | src/net/manaserv/chathandler.cpp | 13 | ||||
-rw-r--r-- | src/net/tmwa/chathandler.cpp | 54 |
3 files changed, 72 insertions, 20 deletions
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 00787182..ba912276 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -77,6 +77,7 @@ ChatWindow::ChatWindow(): Window(_("Chat")), mTmpVisible(false) { + listen("Chat"); listen("Notices"); setWindowName("Chat"); @@ -417,6 +418,30 @@ void ChatWindow::event(const std::string &channel, const Mana::Event &event) if (event.getName() == "ServerNotice") localChatTab->chatLog(event.getString("message"), BY_SERVER); } + else if (channel == "Chat") + { + if (event.getName() == "Whisper") + { + whisper(event.getString("nick"), event.getString("message")); + } + else if (event.getName() == "WhisperError") + { + whisper(event.getString("nick"), + event.getString("error"), BY_SERVER); + } + else if (event.getName() == "Player") + { + localChatTab->chatLog(event.getString("message"), BY_PLAYER); + } + else if (event.getName() == "Announcement") + { + localChatTab->chatLog(event.getString("message"), BY_GM); + } + else if (event.getName() == "Being") + { + localChatTab->chatLog(event.getString("message"), BY_OTHER); + } + } } void ChatWindow::addInputText(const std::string &text) diff --git a/src/net/manaserv/chathandler.cpp b/src/net/manaserv/chathandler.cpp index 40d56bbd..aabe8bb4 100644 --- a/src/net/manaserv/chathandler.cpp +++ b/src/net/manaserv/chathandler.cpp @@ -165,7 +165,9 @@ void ChatHandler::handleGameChatMessage(Net::MessageIn &msg) else mes = "Unknown : " + chatMsg; - localChatTab->chatLog(mes, being == player_node ? BY_PLAYER : BY_OTHER); + Mana::Event event(being == player_node ? "Player" : "Being"); + event.setString("message", mes); + Mana::EventManager::trigger("Chat", event); } void ChatHandler::handleEnterChannelResponse(Net::MessageIn &msg) @@ -225,13 +227,18 @@ void ChatHandler::handlePrivateMessage(Net::MessageIn &msg) std::string userNick = msg.readString(); std::string chatMsg = msg.readString(); - chatWindow->whisper(userNick, chatMsg); + Mana::Event event("Whisper"); + event.setString("nick", userNick); + event.setString("message", chatMsg); + Mana::EventManager::trigger("Chat", event); } void ChatHandler::handleAnnouncement(Net::MessageIn &msg) { std::string chatMsg = msg.readString(); - localChatTab->chatLog(chatMsg, BY_GM); + Mana::Event event("Announcement"); + event.setString("message", chatMsg); + Mana::EventManager::trigger("Chat", event); } void ChatHandler::handleChatMessage(Net::MessageIn &msg) diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp index 2b65b515..68c6dece 100644 --- a/src/net/tmwa/chathandler.cpp +++ b/src/net/tmwa/chathandler.cpp @@ -28,8 +28,6 @@ #include "localplayer.h" #include "playerrelations.h" -#include "gui/widgets/chattab.h" - #include "net/messagein.h" #include "net/messageout.h" @@ -61,8 +59,6 @@ ChatHandler::ChatHandler() void ChatHandler::handleMessage(Net::MessageIn &msg) { - if (!localChatTab) return; - Being *being; std::string chatMsg; std::string nick; @@ -85,14 +81,22 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) // Success (don't need to report) break; case 0x01: - chatWindow->whisper(nick, strprintf(_("Whisper could not " - "be sent, %s is offline."), nick.c_str()), - BY_SERVER); + { + Mana::Event event("WhisperError"); + event.setString("nick", nick); + event.setString("error", strprintf(_("Whisper could " + "not be sent, %s is offline."), nick.c_str())); + Mana::EventManager::trigger("Chat", event); + } break; case 0x02: - chatWindow->whisper(nick, strprintf(_("Whisper could not " - "be sent, ignored by %s."), nick.c_str()), - BY_SERVER); + { + Mana::Event event("WhisperError"); + event.setString("nick", nick); + event.setString("error", strprintf(_("Whisper could " + "not be sent, ignored by %s."), nick.c_str())); + Mana::EventManager::trigger("Chat", event); + } break; } break; @@ -110,11 +114,16 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) if (nick != "Server") { if (player_relations.hasPermission(nick, PlayerRelation::WHISPER)) - chatWindow->whisper(nick, chatMsg); + { + Mana::Event event("Whisper"); + event.setString("nick", nick); + event.setString("message", chatMsg); + Mana::EventManager::trigger("Chat", event); + } } else { - localChatTab->chatLog(chatMsg, BY_SERVER); + SERVER_NOTICE(chatMsg) } break; @@ -122,7 +131,8 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) // Received speech from being case SMSG_BEING_CHAT: { chatMsgLength = msg.readInt16() - 8; - being = actorSpriteManager->findBeing(msg.readInt32()); + int beingId = msg.readInt32(); + being = actorSpriteManager->findBeing(beingId); if (!being || chatMsgLength <= 0) break; @@ -137,7 +147,13 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) // We use getIgnorePlayer instead of ignoringPlayer here because ignorePlayer' side // effects are triggered right below for Being::IGNORE_SPEECH_FLOAT. if (player_relations.checkPermissionSilently(sender_name, PlayerRelation::SPEECH_LOG)) - localChatTab->chatLog(chatMsg, BY_OTHER); + { + Mana::Event event("Being"); + event.setString("message", chatMsg); + event.setString("nick", sender_name); + event.setInt("beingId", beingId); + Mana::EventManager::trigger("Chat", event); + } chatMsg.erase(0, pos + 3); trim(chatMsg); @@ -159,7 +175,9 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) if (msg.getId() == SMSG_PLAYER_CHAT) { - localChatTab->chatLog(chatMsg, BY_PLAYER); + Mana::Event event("Player"); + event.setString("message", chatMsg); + Mana::EventManager::trigger("Chat", event); if (pos != std::string::npos) chatMsg.erase(0, pos + 3); @@ -170,7 +188,9 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) } else { - localChatTab->chatLog(chatMsg, BY_GM); + Mana::Event event("Announcement"); + event.setString("message", chatMsg); + Mana::EventManager::trigger("Chat", event); } break; } @@ -178,7 +198,7 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) case SMSG_MVP: // Display MVP player msg.readInt32(); // id - localChatTab->chatLog(_("MVP player."), BY_SERVER); + SERVER_NOTICE(_("MVP player.")) break; } } |