diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-04 16:06:41 +0000 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-04 16:06:41 +0000 |
commit | 12bec57276d30cd513b1f6b865ee116bce86fc17 (patch) | |
tree | 2ccbf39a687b2601696dc721e039ab8fb4f45559 /src/net/tmwa | |
parent | a25d857ed0bebc2c3e1473d06bea89286941886c (diff) | |
download | Mana-12bec57276d30cd513b1f6b865ee116bce86fc17.tar.gz Mana-12bec57276d30cd513b1f6b865ee116bce86fc17.tar.bz2 Mana-12bec57276d30cd513b1f6b865ee116bce86fc17.tar.xz Mana-12bec57276d30cd513b1f6b865ee116bce86fc17.zip |
Fixed duplication of player name in chat
* Fixed duplication of player name in chat
Closes #49
Diffstat (limited to 'src/net/tmwa')
-rw-r--r-- | src/net/tmwa/chathandler.cpp | 15 | ||||
-rw-r--r-- | src/net/tmwa/loginhandler.cpp | 32 | ||||
-rw-r--r-- | src/net/tmwa/loginhandler.h | 7 |
3 files changed, 39 insertions, 15 deletions
diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp index beed01a1..e4a551e6 100644 --- a/src/net/tmwa/chathandler.cpp +++ b/src/net/tmwa/chathandler.cpp @@ -27,6 +27,7 @@ #include "localplayer.h" #include "playerrelations.h" +#include "net/tmwa/loginhandler.h" #include "net/tmwa/messagein.h" #include "net/tmwa/messageout.h" #include "net/tmwa/protocol.h" @@ -241,16 +242,24 @@ void ChatHandler::handleMessage(MessageIn &msg) } } -void ChatHandler::talk(const std::string &text) +static void sendChatMessage(const std::string &mes) { - std::string mes = local_player->getName() + " : " + text; - MessageOut outMsg(CMSG_CHAT_MESSAGE); // Added + 1 in order to let eAthena parse admin commands correctly outMsg.writeInt16(mes.length() + 4 + 1); outMsg.writeString(mes, mes.length() + 1); } +void ChatHandler::talk(const std::string &text) +{ + const auto loginHandler = static_cast<LoginHandler*>(Net::getLoginHandler()); + + if (loginHandler->getServerVersion() >= 0x100408) + sendChatMessage(text); + else + sendChatMessage(local_player->getName() + " : " + text); +} + void ChatHandler::me(const std::string &text) { std::string action = strprintf("*%s*", text.c_str()); diff --git a/src/net/tmwa/loginhandler.cpp b/src/net/tmwa/loginhandler.cpp index 55336a84..725e0e35 100644 --- a/src/net/tmwa/loginhandler.cpp +++ b/src/net/tmwa/loginhandler.cpp @@ -41,9 +41,12 @@ namespace TmwAthena { extern ServerInfo charServer; -LoginHandler::LoginHandler(): - mVersionResponse(false), - mRegistrationEnabled(true) +enum ServerFlags +{ + FLAG_REGISTRATION = 1 +}; + +LoginHandler::LoginHandler() { static const Uint16 _messages[] = { SMSG_UPDATE_HOST, @@ -196,16 +199,25 @@ void LoginHandler::handleMessage(MessageIn &msg) case SMSG_SERVER_VERSION_RESPONSE: { - // TODO: verify these! - - msg.readInt8(); // -1 - msg.readInt8(); // T - msg.readInt8(); // M + const uint8_t b1 = msg.readInt8(); // -1 + const uint8_t b2 = msg.readInt8(); // T + const uint8_t b3 = msg.readInt8(); // M msg.readInt8(); // W + const uint32_t options = msg.readInt32(); + + if (b1 == 255) // old TMWA + mServerVersion = 0; + else if (b1 >= 0x0d) // new TMWA + mServerVersion = (b1 << 16) | (b2 << 8) | b3; + else // eAthena + mServerVersion = 0; - unsigned int options = msg.readInt32(); + if (mServerVersion > 0) + logger->log("TMW server version: x%06x", mServerVersion); + else + logger->log("Server without version"); - mRegistrationEnabled = (options & 1); + mRegistrationEnabled = (options & FLAG_REGISTRATION); // Leave this last mVersionResponse = true; diff --git a/src/net/tmwa/loginhandler.h b/src/net/tmwa/loginhandler.h index 3ff33e83..4d137c05 100644 --- a/src/net/tmwa/loginhandler.h +++ b/src/net/tmwa/loginhandler.h @@ -79,12 +79,15 @@ class LoginHandler : public MessageHandler, public Net::LoginHandler const Token &getToken() const { return mToken; } + unsigned getServerVersion() const { return mServerVersion; } + private: void sendLoginRegister(const std::string &username, const std::string &password); - bool mVersionResponse; - bool mRegistrationEnabled; + unsigned mServerVersion = 0; + bool mVersionResponse = false; + bool mRegistrationEnabled = true; std::string mUpdateHost; Worlds mWorlds; Token mToken; |