summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-09-13 20:10:15 +0300
committerAndrei Karas <akaras@inbox.ru>2014-09-13 20:10:15 +0300
commitde16b56073dd2c4926327bd990b008a39018f541 (patch)
tree7c880affc3a9e91eacd410806b4fcbccce1193c2 /src/net
parent3aebacaab2e110820994b7e0849bf65fa24c7c8c (diff)
downloadmanaplus-de16b56073dd2c4926327bd990b008a39018f541.tar.gz
manaplus-de16b56073dd2c4926327bd990b008a39018f541.tar.bz2
manaplus-de16b56073dd2c4926327bd990b008a39018f541.tar.xz
manaplus-de16b56073dd2c4926327bd990b008a39018f541.zip
Split processChat for each packet type.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/eathena/chathandler.cpp24
-rw-r--r--src/net/eathena/chathandler.h2
-rw-r--r--src/net/tmwa/chathandler.cpp27
-rw-r--r--src/net/tmwa/chathandler.h2
4 files changed, 41 insertions, 14 deletions
diff --git a/src/net/eathena/chathandler.cpp b/src/net/eathena/chathandler.cpp
index 31a585cf9..6e2ab0fb3 100644
--- a/src/net/eathena/chathandler.cpp
+++ b/src/net/eathena/chathandler.cpp
@@ -85,10 +85,13 @@ void ChatHandler::handleMessage(Net::MessageIn &msg)
break;
case SMSG_PLAYER_CHAT:
- case SMSG_COLOR_MESSAGE:
processChat(msg);
break;
+ case SMSG_COLOR_MESSAGE:
+ processColorChat(msg);
+ break;
+
case SMSG_GM_CHAT:
processGmChat(msg);
break;
@@ -266,14 +269,23 @@ void ChatHandler::createChatRoom(const std::string &title,
void ChatHandler::processChat(Net::MessageIn &msg)
{
BLOCK_START("ChatHandler::processChat")
- const bool coloredChat = msg.getId() == SMSG_COLOR_MESSAGE;
int chatMsgLength = msg.readInt16("len") - 4;
- if (coloredChat)
+ if (chatMsgLength <= 0)
{
- msg.readInt32("unused");
- msg.readInt32("chat color");
- chatMsgLength -= 8;
+ BLOCK_END("ChatHandler::processChat")
+ return;
}
+
+ processChatContinue(msg.readRawString(chatMsgLength, "message"));
+}
+
+void ChatHandler::processColorChat(Net::MessageIn &msg)
+{
+ BLOCK_START("ChatHandler::processChat")
+ int chatMsgLength = msg.readInt16("len") - 4;
+ msg.readInt32("unused");
+ msg.readInt32("chat color");
+ chatMsgLength -= 8;
if (chatMsgLength <= 0)
{
BLOCK_END("ChatHandler::processChat")
diff --git a/src/net/eathena/chathandler.h b/src/net/eathena/chathandler.h
index 0b70f6d1f..08103bc86 100644
--- a/src/net/eathena/chathandler.h
+++ b/src/net/eathena/chathandler.h
@@ -73,6 +73,8 @@ class ChatHandler final : public MessageHandler, public Ea::ChatHandler
protected:
void processChat(Net::MessageIn &msg);
+ void processColorChat(Net::MessageIn &msg);
+
void processChatContinue(std::string chatMsg);
void processWhisper(Net::MessageIn &msg) const;
diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp
index 962d21363..cc285d081 100644
--- a/src/net/tmwa/chathandler.cpp
+++ b/src/net/tmwa/chathandler.cpp
@@ -92,10 +92,13 @@ void ChatHandler::handleMessage(Net::MessageIn &msg)
break;
case SMSG_PLAYER_CHAT:
- case SMSG_PLAYER_CHAT2:
processChat(msg);
break;
+ case SMSG_PLAYER_CHAT2:
+ processChat2(msg);
+ break;
+
case SMSG_GM_CHAT:
processGmChat(msg);
break;
@@ -274,16 +277,24 @@ void ChatHandler::createChatRoom(const std::string &title A_UNUSED,
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)
+ if (chatMsgLength <= 0)
{
- chatMsgLength -= 3;
- channel = msg.readUInt8("channel byte 0");
- channel += msg.readUInt8("channel byte 1");
- channel += msg.readUInt8("channel byte 2");
+ BLOCK_END("ChatHandler::processChat")
+ return;
}
+
+ processChatContinue(msg.readRawString(chatMsgLength, "message"), "");
+}
+
+void ChatHandler::processChat2(Net::MessageIn &msg)
+{
+ BLOCK_START("ChatHandler::processChat")
+ int chatMsgLength = msg.readInt16("len") - 4 - 3;
+ std::string channel;
+ 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")
diff --git a/src/net/tmwa/chathandler.h b/src/net/tmwa/chathandler.h
index 0fbf6711a..af2333ea6 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 processChat2(Net::MessageIn &msg);
+
void processChatContinue(std::string chatMsg,
const std::string &channel);