summaryrefslogtreecommitdiff
path: root/src/net/tmwa/chathandler.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-09-13 19:02:51 +0300
committerAndrei Karas <akaras@inbox.ru>2014-09-13 19:02:51 +0300
commit78bda42e4b456ad7118b8e46a07c77371f90b615 (patch)
tree79c55059258acdb5ca2c4cae2fb54ba11aa5bdfb /src/net/tmwa/chathandler.cpp
parent28808fddc14c01f93efa0e6963ec65b08e3bbd7b (diff)
downloadmv-78bda42e4b456ad7118b8e46a07c77371f90b615.tar.gz
mv-78bda42e4b456ad7118b8e46a07c77371f90b615.tar.bz2
mv-78bda42e4b456ad7118b8e46a07c77371f90b615.tar.xz
mv-78bda42e4b456ad7118b8e46a07c77371f90b615.zip
Split processChat for gm messages and all other.
Diffstat (limited to 'src/net/tmwa/chathandler.cpp')
-rw-r--r--src/net/tmwa/chathandler.cpp70
1 files changed, 67 insertions, 3 deletions
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;