summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/net/tmwa/chathandler.cpp15
-rw-r--r--src/net/tmwa/loginhandler.cpp32
-rw-r--r--src/net/tmwa/loginhandler.h7
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;