diff options
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/eathena/chathandler.cpp | 56 | ||||
-rw-r--r-- | src/net/eathena/chathandler.h | 2 | ||||
-rw-r--r-- | src/net/tmwa/chathandler.cpp | 70 | ||||
-rw-r--r-- | src/net/tmwa/chathandler.h | 2 |
4 files changed, 105 insertions, 25 deletions
diff --git a/src/net/eathena/chathandler.cpp b/src/net/eathena/chathandler.cpp index 14c0fcea5..22ec532ce 100644 --- a/src/net/eathena/chathandler.cpp +++ b/src/net/eathena/chathandler.cpp @@ -85,11 +85,14 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) break; case SMSG_PLAYER_CHAT: - case SMSG_GM_CHAT: case SMSG_COLOR_MESSAGE: processChat(msg); break; + case SMSG_GM_CHAT: + processGmChat(msg); + break; + case SMSG_GM_CHAT2: processGmChat2(msg); break; @@ -263,7 +266,6 @@ void ChatHandler::createChatRoom(const std::string &title, void ChatHandler::processChat(Net::MessageIn &msg) { BLOCK_START("ChatHandler::processChat") - const bool normalChat = msg.getId() == SMSG_PLAYER_CHAT; const bool coloredChat = msg.getId() == SMSG_COLOR_MESSAGE; int chatMsgLength = msg.readInt16("len") - 4; if (coloredChat) @@ -281,33 +283,43 @@ void ChatHandler::processChat(Net::MessageIn &msg) std::string chatMsg = msg.readRawString(chatMsgLength, "message"); const size_t pos = chatMsg.find(" : ", 0); - if (normalChat) + bool allow(true); + if (chatWindow) { - bool allow(true); - if (chatWindow) - { - allow = chatWindow->resortChatLog(chatMsg, - ChatMsgType::BY_PLAYER, - GENERAL_CHANNEL, - false, true); - } + allow = chatWindow->resortChatLog(chatMsg, + ChatMsgType::BY_PLAYER, + GENERAL_CHANNEL, + false, true); + } - if (pos != std::string::npos) - chatMsg.erase(0, pos + 3); + if (pos != std::string::npos) + chatMsg.erase(0, pos + 3); - trim(chatMsg); + trim(chatMsg); - if (localPlayer) - { - if ((chatWindow || mShowMotd) && allow) - localPlayer->setSpeech(chatMsg, GENERAL_CHANNEL); - } + if (localPlayer) + { + if ((chatWindow || mShowMotd) && allow) + localPlayer->setSpeech(chatMsg, GENERAL_CHANNEL); } - else if (localChatTab) + BLOCK_END("ChatHandler::processChat") +} + +void ChatHandler::processGmChat(Net::MessageIn &msg) +{ + BLOCK_START("ChatHandler::processChat") + int chatMsgLength = msg.readInt16("len") - 4; + if (chatMsgLength <= 0) { - if (chatWindow) - chatWindow->addGlobalMessage(chatMsg); + BLOCK_END("ChatHandler::processChat") + return; } + + std::string chatMsg = msg.readRawString(chatMsgLength, "message"); + const size_t pos = chatMsg.find(" : ", 0); + + if (chatWindow) + chatWindow->addGlobalMessage(chatMsg); BLOCK_END("ChatHandler::processChat") } diff --git a/src/net/eathena/chathandler.h b/src/net/eathena/chathandler.h index 29eca423b..b59019fef 100644 --- a/src/net/eathena/chathandler.h +++ b/src/net/eathena/chathandler.h @@ -77,6 +77,8 @@ class ChatHandler final : public MessageHandler, public Ea::ChatHandler void processWhisperResponse(Net::MessageIn &msg); + void processGmChat(Net::MessageIn &msg); + void processGmChat2(Net::MessageIn &msg); void processChatIgnoreList(Net::MessageIn &msg); diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp index 61e81428d..93f1d9815 100644 --- a/src/net/tmwa/chathandler.cpp +++ b/src/net/tmwa/chathandler.cpp @@ -92,12 +92,12 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) break; case SMSG_PLAYER_CHAT: - case SMSG_GM_CHAT: + case SMSG_PLAYER_CHAT2: processChat(msg); break; - case SMSG_PLAYER_CHAT2: - processChat(msg); + case SMSG_GM_CHAT: + processGmChat(msg); break; case SMSG_MVP: @@ -275,6 +275,70 @@ void ChatHandler::processChat(Net::MessageIn &msg) { BLOCK_START("ChatHandler::processChat") const bool channels = msg.getId() == SMSG_PLAYER_CHAT2; + int chatMsgLength = msg.readInt16("len") - 4; + std::string channel; + if (channels) + { + chatMsgLength -= 3; + channel = msg.readUInt8("channel byte 0"); + channel += msg.readUInt8("channel byte 1"); + channel += msg.readUInt8("channel byte 2"); + } + if (chatMsgLength <= 0) + { + BLOCK_END("ChatHandler::processChat") + return; + } + + std::string chatMsg = msg.readRawString(chatMsgLength, "message"); + const size_t pos = chatMsg.find(" : ", 0); + + bool allow(true); + if (chatWindow) + { + allow = chatWindow->resortChatLog(chatMsg, ChatMsgType::BY_PLAYER, + channel, false, true); + } + + if (channel.empty()) + { + const std::string senseStr("You sense the following: "); + if (actorManager && !chatMsg.find(senseStr)) + { + actorManager->parseLevels( + chatMsg.substr(senseStr.size())); + } + } + + if (pos == std::string::npos && !mShowMotd + && mSkipping && channel.empty()) + { + // skip motd from "new" tmw server + if (mMotdTime == -1) + mMotdTime = cur_time + 1; + else if (mMotdTime == cur_time || mMotdTime < cur_time) + mSkipping = false; + BLOCK_END("ChatHandler::processChat") + return; + } + + if (pos != std::string::npos) + chatMsg.erase(0, pos + 3); + + trim(chatMsg); + + if (localPlayer) + { + if ((chatWindow || mShowMotd) && allow) + localPlayer->setSpeech(chatMsg, channel); + } + BLOCK_END("ChatHandler::processChat") +} + +void ChatHandler::processGmChat(Net::MessageIn &msg) +{ + BLOCK_START("ChatHandler::processChat") + const bool channels = msg.getId() == SMSG_PLAYER_CHAT2; const bool normalChat = msg.getId() == SMSG_PLAYER_CHAT || msg.getId() == SMSG_PLAYER_CHAT2; int chatMsgLength = msg.readInt16("len") - 4; diff --git a/src/net/tmwa/chathandler.h b/src/net/tmwa/chathandler.h index 777052b98..83b23774b 100644 --- a/src/net/tmwa/chathandler.h +++ b/src/net/tmwa/chathandler.h @@ -73,6 +73,8 @@ class ChatHandler final : public MessageHandler, public Ea::ChatHandler protected: void processChat(Net::MessageIn &msg); + void processGmChat(Net::MessageIn &msg); + void processWhisper(Net::MessageIn &msg) const; void processWhisperResponse(Net::MessageIn &msg); |