diff options
-rw-r--r-- | src/gui/login.cpp | 2 | ||||
-rw-r--r-- | src/main.cpp | 6 | ||||
-rw-r--r-- | src/main.h | 13 | ||||
-rw-r--r-- | src/net/ea/loginhandler.cpp | 6 | ||||
-rw-r--r-- | src/net/ea/loginhandler.h | 2 | ||||
-rw-r--r-- | src/net/logindata.h | 2 | ||||
-rw-r--r-- | src/net/loginhandler.h | 2 | ||||
-rw-r--r-- | src/net/manaserv/loginhandler.cpp | 61 | ||||
-rw-r--r-- | src/net/manaserv/loginhandler.h | 14 | ||||
-rw-r--r-- | src/net/manaserv/protocol.h | 7 |
10 files changed, 104 insertions, 11 deletions
diff --git a/src/gui/login.cpp b/src/gui/login.cpp index ae4d8de3..aa14b00e 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -115,7 +115,7 @@ void LoginDialog::action(const gcn::ActionEvent &event) mLoginData->username = mUserField->getText(); mLoginData->password = mPassField->getText(); - state = STATE_REGISTER; + state = STATE_REGISTER_PREP; } } diff --git a/src/main.cpp b/src/main.cpp index 459037ef..5308304f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1141,6 +1141,12 @@ int main(int argc, char *argv[]) currentDialog = NULL; // OkDialog deletes itself break; + case STATE_REGISTER_PREP: + logger->log("State: REGISTER_PREP"); + Net::getLoginHandler()->getRegistrationDetails(); + currentDialog = new ConnectionDialog(STATE_LOGIN); + break; + case STATE_REGISTER: logger->log("State: REGISTER"); currentDialog = new RegisterDialog(&loginData); @@ -110,21 +110,22 @@ enum State { STATE_CHANGE_MAP, // Switch map-server/gameserver STATE_LOGIN_ERROR, STATE_ACCOUNTCHANGE_ERROR, // 15 + STATE_REGISTER_PREP, STATE_REGISTER, STATE_REGISTER_ATTEMPT, STATE_CHANGEPASSWORD, - STATE_CHANGEPASSWORD_ATTEMPT, - STATE_CHANGEPASSWORD_SUCCESS, // 20 + STATE_CHANGEPASSWORD_ATTEMPT, // 20 + STATE_CHANGEPASSWORD_SUCCESS, STATE_CHANGEEMAIL, STATE_CHANGEEMAIL_ATTEMPT, STATE_CHANGEEMAIL_SUCCESS, - STATE_UNREGISTER, - STATE_UNREGISTER_ATTEMPT, // 25 + STATE_UNREGISTER, // 25 + STATE_UNREGISTER_ATTEMPT, STATE_UNREGISTER_SUCCESS, STATE_SWITCH_SERVER, STATE_SWITCH_LOGIN, - STATE_SWITCH_CHARACTER, - STATE_LOGOUT_ATTEMPT, // 30 + STATE_SWITCH_CHARACTER, // 30 + STATE_LOGOUT_ATTEMPT, STATE_WAIT, STATE_EXIT, STATE_FORCE_QUIT diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp index 2c6ac1d2..e27eccf8 100644 --- a/src/net/ea/loginhandler.cpp +++ b/src/net/ea/loginhandler.cpp @@ -209,6 +209,12 @@ void LoginHandler::disconnect() mNetwork->disconnect(); } +void LoginHandler::getRegistrationDetails() +{ + // Not supported, so move on + state = STATE_REGISTER; +} + void LoginHandler::loginAccount(LoginData *loginData) { sendLoginRegister(loginData->username, loginData->password); diff --git a/src/net/ea/loginhandler.h b/src/net/ea/loginhandler.h index ac3bf4f4..16c5fe95 100644 --- a/src/net/ea/loginhandler.h +++ b/src/net/ea/loginhandler.h @@ -49,6 +49,8 @@ class LoginHandler : public MessageHandler, public Net::LoginHandler int supportedOptionalActions() const { return SetGenderOnRegister; } + void getRegistrationDetails(); + void loginAccount(LoginData *loginData); void logout(); diff --git a/src/net/logindata.h b/src/net/logindata.h index 4f592f7d..8df06171 100644 --- a/src/net/logindata.h +++ b/src/net/logindata.h @@ -35,6 +35,7 @@ struct LoginData std::string updateHost; std::string email; + std::string captchaResponse; Gender gender; @@ -48,6 +49,7 @@ struct LoginData newPassword.clear(); updateHost.clear(); email.clear(); + captchaResponse.clear(); gender = GENDER_UNSPECIFIED; } }; diff --git a/src/net/loginhandler.h b/src/net/loginhandler.h index 89af9120..6d42088d 100644 --- a/src/net/loginhandler.h +++ b/src/net/loginhandler.h @@ -63,6 +63,8 @@ class LoginHandler */ virtual int supportedOptionalActions() const = 0; + virtual void getRegistrationDetails() = 0; + virtual unsigned int getMinUserNameLength() const { return 4; }; virtual unsigned int getMaxUserNameLength() const { return 25; }; diff --git a/src/net/manaserv/loginhandler.cpp b/src/net/manaserv/loginhandler.cpp index ff8d142d..bd29d1d9 100644 --- a/src/net/manaserv/loginhandler.cpp +++ b/src/net/manaserv/loginhandler.cpp @@ -50,6 +50,7 @@ LoginHandler::LoginHandler() APMSG_EMAIL_CHANGE_RESPONSE, APMSG_LOGOUT_RESPONSE, APMSG_UNREGISTER_RESPONSE, + APMSG_REGISTER_INFO_RESPONSE, 0 }; handledMessages = _messages; @@ -206,6 +207,35 @@ void LoginHandler::handleMessage(Net::MessageIn &msg) } } break; + + case APMSG_REGISTER_INFO_RESPONSE: + { + int allowed = msg.readInt8(); + + if (allowed) + { + mMinUserNameLength = msg.readInt8(); + mMaxUserNameLength = msg.readInt8(); + mMinPasswordLength = msg.readInt8(); + mMaxPasswordLength = msg.readInt8(); + std::string captchaURL = msg.readString(); + std::string captchaInstructions = msg.readString(); + + printf("%s: %s\n", captchaURL.c_str(), captchaInstructions.c_str()); + + state = STATE_REGISTER; + } + else + { + errorMessage = msg.readString(); + + if (errorMessage.empty()) + errorMessage = _("Client registration is not allowed. " + "Please contact server administration."); + state = STATE_LOGIN_ERROR; + } + } + break; } } @@ -270,6 +300,10 @@ void LoginHandler::handleRegisterResponse(Net::MessageIn &msg) case REGISTER_EXISTS_EMAIL: errorMessage = _("Email address already exists."); break; + case REGISTER_FAILED_CAPTCHA: + errorMessage = _("You took too long with the captcha or your " + "response was incorrect."); + break; default: errorMessage = _("Unknown error."); break; @@ -307,6 +341,32 @@ void LoginHandler::disconnect() } } +void LoginHandler::getRegistrationDetails() +{ + MessageOut msg(PAMSG_REQUEST_REGISTER_INFO); + accountServerConnection->send(msg); +} + +unsigned int LoginHandler::getMinUserNameLength() const +{ + return mMinUserNameLength; +} + +unsigned int LoginHandler::getMaxUserNameLength() const +{ + return mMaxUserNameLength; +} + +unsigned int LoginHandler::getMinPasswordLength() const +{ + return mMinPasswordLength; +} + +unsigned int LoginHandler::getMaxPasswordLength() const +{ + return mMaxPasswordLength; +} + void LoginHandler::loginAccount(LoginData *loginData) { mLoginData = loginData; @@ -366,6 +426,7 @@ void LoginHandler::registerAccount(LoginData *loginData) // This is the only time we send a clear password. msg.writeString(loginData->password); msg.writeString(loginData->email); + msg.writeString(loginData->captchaResponse); accountServerConnection->send(msg); } diff --git a/src/net/manaserv/loginhandler.h b/src/net/manaserv/loginhandler.h index 1a929c96..75e2daf3 100644 --- a/src/net/manaserv/loginhandler.h +++ b/src/net/manaserv/loginhandler.h @@ -47,9 +47,15 @@ class LoginHandler : public MessageHandler, public Net::LoginHandler int supportedOptionalActions() const { return Unregister | ChangeEmail | SetEmailOnRegister; } - unsigned int getMaxUserNameLength() const { return 15; }; + void getRegistrationDetails(); - unsigned int getMinPasswordLength() const { return 6; }; + unsigned int getMinUserNameLength() const; + + unsigned int getMaxUserNameLength() const; + + unsigned int getMinPasswordLength() const; + + unsigned int getMaxPasswordLength() const; void loginAccount(LoginData *loginData); @@ -79,6 +85,10 @@ class LoginHandler : public MessageHandler, public Net::LoginHandler void readUpdateHost(Net::MessageIn &msg); LoginData *mLoginData; + unsigned int mMinUserNameLength; + unsigned int mMaxUserNameLength; + unsigned int mMinPasswordLength; + unsigned int mMaxPasswordLength; }; } // namespace ManaServ diff --git a/src/net/manaserv/protocol.h b/src/net/manaserv/protocol.h index d1ff3f73..fe38f35c 100644 --- a/src/net/manaserv/protocol.h +++ b/src/net/manaserv/protocol.h @@ -40,10 +40,12 @@ */ enum { // Login/Register - PAMSG_REGISTER = 0x0000, // L version, S username, S password, S email + PAMSG_REGISTER = 0x0000, // L version, S username, S password, S email, S captcha response APMSG_REGISTER_RESPONSE = 0x0002, // B error [, S updatehost] PAMSG_UNREGISTER = 0x0003, // - APMSG_UNREGISTER_RESPONSE = 0x0004, // B error + PAMSG_REQUEST_REGISTER_INFO = 0x0005, // + APMSG_REGISTER_INFO_RESPONSE = 0x0006, // B byte registrationAllowed, byte minEmailLength, byte maxEmailLength, byte minNameLength, byte maxNameLength, byte minPasswordLength, byte maxPasswordLength, string captchaURL, string captchaInstructions PAMSG_LOGIN = 0x0010, // L version, S username, S password APMSG_LOGIN_RESPONSE = 0x0012, // B error [, S updatehost] PAMSG_LOGOUT = 0x0013, // - @@ -238,7 +240,8 @@ enum { enum { REGISTER_INVALID_VERSION = 0x40, // the user is using an incompatible protocol REGISTER_EXISTS_USERNAME, // there already is an account with this username - REGISTER_EXISTS_EMAIL // there already is an account with this email address + REGISTER_EXISTS_EMAIL, // there already is an account with this email address + REGISTER_FAILED_CAPTCHA // captcha respose is bad }; // Character creation specific return values |