From 15e87a84d62cc0b0077b25c235824879bde66a41 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 8 Sep 2014 19:24:45 +0300 Subject: Update command for sending raw packets to server. --- src/net/eathena/chathandler.cpp | 91 +++++++++++++---------------------------- src/net/tmwa/chathandler.cpp | 90 +++++++++++++--------------------------- 2 files changed, 56 insertions(+), 125 deletions(-) diff --git a/src/net/eathena/chathandler.cpp b/src/net/eathena/chathandler.cpp index b8973dd66..eed77a52c 100644 --- a/src/net/eathena/chathandler.cpp +++ b/src/net/eathena/chathandler.cpp @@ -183,75 +183,40 @@ void ChatHandler::sendRaw(const std::string &args) const void ChatHandler::processRaw(MessageOut &restrict outMsg, const std::string &restrict line) { - size_t pos = line.find(":"); - if (pos == std::string::npos) - { - const int i = atoi(line.c_str()); - if (line.length() <= 3) - outMsg.writeInt8(static_cast(i), "raw"); - else if (line.length() <= 5) - outMsg.writeInt16(static_cast(i), "raw"); - else - outMsg.writeInt32(i, "raw"); - } + if (line.size() < 2) + return; + + char cmd = tolower(line[0]); + int i = 0; + std::string str = line.substr(1); + int idx = 0; + if (strStartWith(str, "0x")) + idx = 2; + else if (str[0] == 'h' || str[0] == 'x') + idx = 1; + if (idx > 0) + sscanf(str.substr(idx).c_str(), "%10x", &i); else + i = atoi(str.c_str()); + switch (cmd) { - const std::string header = line.substr(0, pos); - std::string data = line.substr(pos + 1); - if (header.length() != 1) - return; - - int i = 0; - - switch (header[0]) + case 'b': + { + outMsg.writeInt8(static_cast(i), "raw"); + break; + } + case 'w': { - case '1': - case '2': - case '4': - i = atoi(data.c_str()); - break; - default: - break; + outMsg.writeInt16(static_cast(i), "raw"); + break; } - - switch (header[0]) + case 'l': { - case '1': - outMsg.writeInt8(static_cast(i), "raw"); - break; - case '2': - outMsg.writeInt16(static_cast(i), "raw"); - break; - case '4': - outMsg.writeInt32(i, "raw"); - break; - case 'c': - { - pos = line.find(","); - if (pos != std::string::npos) - { - const uint16_t x = static_cast( - atoi(data.substr(0, pos).c_str())); - data = data.substr(pos + 1); - pos = line.find(","); - if (pos == std::string::npos) - break; - - const uint16_t y = static_cast( - atoi(data.substr(0, pos).c_str())); - const int dir = atoi(data.substr(pos + 1).c_str()); - outMsg.writeCoordinates(x, y, - static_cast(dir), "raw"); - } - break; - } - case 't': - outMsg.writeString(data, - static_cast(data.length()), "raw"); - break; - default: - break; + outMsg.writeInt32(static_cast(i), "raw"); + break; } + default: + break; } } diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp index 3eada4215..3976aa723 100644 --- a/src/net/tmwa/chathandler.cpp +++ b/src/net/tmwa/chathandler.cpp @@ -204,74 +204,40 @@ void ChatHandler::sendRaw(const std::string &args) const void ChatHandler::processRaw(MessageOut &restrict outMsg, const std::string &restrict line) { - size_t pos = line.find(":"); - if (pos == std::string::npos) - { - const int i = atoi(line.c_str()); - if (line.length() <= 3) - outMsg.writeInt8(static_cast(i), "raw"); - else if (line.length() <= 5) - outMsg.writeInt16(static_cast(i), "raw"); - else - outMsg.writeInt32(i, "raw"); - } + if (line.size() < 2) + return; + + char cmd = tolower(line[0]); + int i = 0; + std::string str = line.substr(1); + int idx = 0; + if (strStartWith(str, "0x")) + idx = 2; + else if (str[0] == 'h' || str[0] == 'x') + idx = 1; + if (idx > 0) + sscanf(str.substr(idx).c_str(), "%10x", &i); else + i = atoi(str.c_str()); + switch (cmd) { - const std::string header = line.substr(0, pos); - if (header.length() != 1) - return; - std::string data = line.substr(pos + 1); - int i = 0; - - switch (header[0]) + case 'b': + { + outMsg.writeInt8(static_cast(i), "raw"); + break; + } + case 'w': { - case '1': - case '2': - case '4': - i = atoi(data.c_str()); - break; - default: - break; + outMsg.writeInt16(static_cast(i), "raw"); + break; } - - switch (header[0]) + case 'l': { - case '1': - outMsg.writeInt8(static_cast(i), "raw"); - break; - case '2': - outMsg.writeInt16(static_cast(i), "raw"); - break; - case '4': - outMsg.writeInt32(i, "raw"); - break; - case 'c': - { - pos = line.find(","); - if (pos != std::string::npos) - { - const uint16_t x = static_cast( - atoi(data.substr(0, pos).c_str())); - data = data.substr(pos + 1); - pos = line.find(","); - if (pos == std::string::npos) - break; - - const uint16_t y = static_cast( - atoi(data.substr(0, pos).c_str())); - const int dir = atoi(data.substr(pos + 1).c_str()); - outMsg.writeCoordinates(x, y, - static_cast(dir), "raw"); - } - break; - } - case 't': - outMsg.writeString(data, static_cast(data.length()), - "raw"); - break; - default: - break; + outMsg.writeInt32(static_cast(i), "raw"); + break; } + default: + break; } } -- cgit v1.2.3-60-g2f50