diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2008-11-20 23:26:11 +0100 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2008-11-20 23:37:24 +0100 |
commit | b5963ec28aa76b1a19699a3d06247af93aae6bf5 (patch) | |
tree | 9a56c7408a8f3b7c66f785a775c93f793c934178 /src/net | |
parent | a05fad5acd9c0ff78a4ecd8bd213dd411b062f91 (diff) | |
download | mana-b5963ec28aa76b1a19699a3d06247af93aae6bf5.tar.gz mana-b5963ec28aa76b1a19699a3d06247af93aae6bf5.tar.bz2 mana-b5963ec28aa76b1a19699a3d06247af93aae6bf5.tar.xz mana-b5963ec28aa76b1a19699a3d06247af93aae6bf5.zip |
Renabled the dynamic updates
The update host can be optionally received from the server in a
succesful login response or register response message.
This change also merged Subversion commits 4425 and 4426:
........
r4425 | b_lindeijer | 2008-07-18 00:52:53 +0200 (Fri, 18 Jul 2008) | 3 lines
--
Added support for handling the custom eAthena packet that sends the update
host (patch by Sanga).
........
r4426 | b_lindeijer | 2008-07-18 01:08:17 +0200 (Fri, 18 Jul 2008) | 3 lines
--
Remove possible trailing slash at the end of the update host, since otherwise
there'll be two of them.
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/loginhandler.cpp | 141 | ||||
-rw-r--r-- | src/net/loginhandler.h | 14 | ||||
-rw-r--r-- | src/net/protocol.h | 13 |
3 files changed, 103 insertions, 65 deletions
diff --git a/src/net/loginhandler.cpp b/src/net/loginhandler.cpp index f1898fb5..37c3608a 100644 --- a/src/net/loginhandler.cpp +++ b/src/net/loginhandler.cpp @@ -24,6 +24,7 @@ #include "messagein.h" #include "protocol.h" +#include "../logindata.h" #include "../main.h" LoginHandler::LoginHandler() @@ -39,73 +40,20 @@ LoginHandler::LoginHandler() handledMessages = _messages; } +void LoginHandler::setLoginData(LoginData *loginData) +{ + mLoginData = loginData; +} + void LoginHandler::handleMessage(MessageIn &msg) { switch (msg.getId()) { case APMSG_LOGIN_RESPONSE: - { - int errMsg = msg.readInt8(); - // Successful login - if (errMsg == ERRMSG_OK) - { - state = STATE_CHAR_SELECT; - } - // Login failed - else - { - switch (errMsg) { - case LOGIN_INVALID_VERSION: - errorMessage = "Client has an insufficient version number to login."; - break; - case ERRMSG_INVALID_ARGUMENT: - errorMessage = "Wrong username or password"; - break; - case ERRMSG_FAILURE: - errorMessage = "Already logged in"; - break; - case LOGIN_SERVER_FULL: - errorMessage = "Server is full"; - break; - default: - errorMessage = "Unknown error"; - break; - } - state = STATE_LOGIN_ERROR; - } - } + handleLoginResponse(msg); break; case APMSG_REGISTER_RESPONSE: - { - int errMsg = msg.readInt8(); - // Successful registration - if (errMsg == ERRMSG_OK) - { - state = STATE_CHAR_SELECT; - } - // Registration failed - else - { - switch (errMsg) { - case REGISTER_INVALID_VERSION: - errorMessage = "Client has an insufficient version number to login."; - break; - case ERRMSG_INVALID_ARGUMENT: - errorMessage = "Wrong username, password or email address"; - break; - case REGISTER_EXISTS_USERNAME: - errorMessage = "Username already exists"; - break; - case REGISTER_EXISTS_EMAIL: - errorMessage = "Email address already exists"; - break; - default: - errorMessage = "Unknown error"; - break; - } - state = STATE_LOGIN_ERROR; - } - } + handleRegisterResponse(msg); break; case APMSG_RECONNECT_RESPONSE: { @@ -202,3 +150,76 @@ void LoginHandler::handleMessage(MessageIn &msg) } } + +void LoginHandler::handleLoginResponse(MessageIn &msg) +{ + const int errMsg = msg.readInt8(); + + if (errMsg == ERRMSG_OK) + { + readUpdateHost(msg); + state = STATE_CHAR_SELECT; + } + else + { + switch (errMsg) { + case LOGIN_INVALID_VERSION: + errorMessage = "Client version is too old"; + break; + case ERRMSG_INVALID_ARGUMENT: + errorMessage = "Wrong username or password"; + break; + case ERRMSG_FAILURE: + errorMessage = "Already logged in"; + break; + case LOGIN_SERVER_FULL: + errorMessage = "Server is full"; + break; + default: + errorMessage = "Unknown error"; + break; + } + state = STATE_LOGIN_ERROR; + } +} + +void LoginHandler::handleRegisterResponse(MessageIn &msg) +{ + const int errMsg = msg.readInt8(); + + if (errMsg == ERRMSG_OK) + { + readUpdateHost(msg); + state = STATE_CHAR_SELECT; + } + else + { + switch (errMsg) { + case REGISTER_INVALID_VERSION: + errorMessage = "Client version is too old"; + break; + case ERRMSG_INVALID_ARGUMENT: + errorMessage = "Wrong username, password or email address"; + break; + case REGISTER_EXISTS_USERNAME: + errorMessage = "Username already exists"; + break; + case REGISTER_EXISTS_EMAIL: + errorMessage = "Email address already exists"; + break; + default: + errorMessage = "Unknown error"; + break; + } + state = STATE_LOGIN_ERROR; + } +} + +void LoginHandler::readUpdateHost(MessageIn &msg) +{ + // Set the update host when included in the message + if (msg.getUnreadLength() > 0) + { + mLoginData->updateHost = msg.readString(); + } +} diff --git a/src/net/loginhandler.h b/src/net/loginhandler.h index f557c97b..015d6383 100644 --- a/src/net/loginhandler.h +++ b/src/net/loginhandler.h @@ -24,12 +24,24 @@ #include "messagehandler.h" +class LoginData; + class LoginHandler : public MessageHandler { public: LoginHandler(); + void setLoginData(LoginData *loginData); + void handleMessage(MessageIn &msg); + + private: + void handleLoginResponse(MessageIn &msg); + void handleRegisterResponse(MessageIn &msg); + + void readUpdateHost(MessageIn &msg); + + LoginData *mLoginData; }; -#endif +#endif // _TMW_NET_LOGINHANDLER_H diff --git a/src/net/protocol.h b/src/net/protocol.h index 5dfa78da..5406f248 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -23,24 +23,29 @@ #define _TMW_PROTOCOL_ /** - * Enumerated type for communicated messages + * Enumerated type for communicated messages: + * * - PAMSG_*: from client to account server * - APMSG_*: from account server to client * - PCMSG_*: from client to chat server * - CPMSG_*: from chat server to client * - PGMSG_*: from client to game server * - GPMSG_*: from game server to client + * * Components: B byte, W word, D double word, S variable-size string * C tile-based coordinates (B*3) + * + * Hosts: P (player's client), A (account server), C (char server), + * G (game server) */ enum { // Login/Register - PAMSG_REGISTER = 0x0000, // L version, S username, S password, S email - APMSG_REGISTER_RESPONSE = 0x0002, // B error + PAMSG_REGISTER = 0x0001, // L version, S username, S password, S email + APMSG_REGISTER_RESPONSE = 0x0002, // B error [, S updatehost] PAMSG_UNREGISTER = 0x0003, // - APMSG_UNREGISTER_RESPONSE = 0x0004, // B error PAMSG_LOGIN = 0x0010, // L version, S username, S password - APMSG_LOGIN_RESPONSE = 0x0012, // B error + APMSG_LOGIN_RESPONSE = 0x0012, // B error [, S updatehost] PAMSG_LOGOUT = 0x0013, // - APMSG_LOGOUT_RESPONSE = 0x0014, // B error PAMSG_CHAR_CREATE = 0x0020, // S name, B hair style, B hair color, B gender, W*6 stats |