diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2009-10-06 23:40:55 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2009-10-06 23:43:40 +0200 |
commit | 64a37da4cb8d74a29f369e96e8c3669275516394 (patch) | |
tree | caa0eb0d05ab5674b6b6ac822d151aa2585721e8 | |
parent | 610dc30ceecdfe538f71826689630e0f28c278cc (diff) | |
download | mana-64a37da4cb8d74a29f369e96e8c3669275516394.tar.gz mana-64a37da4cb8d74a29f369e96e8c3669275516394.tar.bz2 mana-64a37da4cb8d74a29f369e96e8c3669275516394.tar.xz mana-64a37da4cb8d74a29f369e96e8c3669275516394.zip |
Some cleanup regarding keeping track of gender for eAthena
LoginHandler now owns the world list and the token, instead of having
them as global variables with pointers to the 'sex' member of the token
from the GUI.
-rw-r--r-- | src/game.cpp | 3 | ||||
-rw-r--r-- | src/gui/register.cpp | 21 | ||||
-rw-r--r-- | src/gui/register.h | 16 | ||||
-rw-r--r-- | src/main.cpp | 12 | ||||
-rw-r--r-- | src/net/ea/charserverhandler.cpp | 26 | ||||
-rw-r--r-- | src/net/ea/gamehandler.cpp | 16 | ||||
-rw-r--r-- | src/net/ea/gamehandler.h | 1 | ||||
-rw-r--r-- | src/net/ea/generalhandler.cpp | 8 | ||||
-rw-r--r-- | src/net/ea/loginhandler.cpp | 35 | ||||
-rw-r--r-- | src/net/ea/loginhandler.h | 9 | ||||
-rw-r--r-- | src/net/ea/network.h | 2 | ||||
-rw-r--r-- | src/net/ea/token.h | 5 | ||||
-rw-r--r-- | src/net/logindata.h | 4 | ||||
-rw-r--r-- | src/net/loginhandler.h | 21 | ||||
-rw-r--r-- | src/net/tmwserv/loginhandler.cpp | 2 | ||||
-rw-r--r-- | src/net/tmwserv/loginhandler.h | 2 | ||||
-rw-r--r-- | src/net/worldinfo.h | 4 |
17 files changed, 102 insertions, 85 deletions
diff --git a/src/game.cpp b/src/game.cpp index 60b13a06..aea478b5 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -161,8 +161,9 @@ const int MILLISECONDS_IN_A_TICK = 10; * Listener used for exiting handling. */ namespace { - struct ExitListener : public gcn::ActionListener + class ExitListener : public gcn::ActionListener { + public: void action(const gcn::ActionEvent &event) { if (event.getId() == "yes" || event.getId() == "ok") diff --git a/src/gui/register.cpp b/src/gui/register.cpp index 78c79eeb..5d9469ca 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -54,11 +54,11 @@ void WrongDataNoticeListener::action(const gcn::ActionEvent &event) mTarget->requestFocus(); } -Gender *RegisterDialog::useGender = NULL; - RegisterDialog::RegisterDialog(LoginData *loginData): Window(_("Register")), mEmailField(0), + mMaleButton(0), + mFemaleButton(0), mWrongDataNoticeListener(new WrongDataNoticeListener), mLoginData(loginData) { @@ -70,8 +70,6 @@ RegisterDialog::RegisterDialog(LoginData *loginData): mUserField = new TextField(loginData->username); mPasswordField = new PasswordField(loginData->password); mConfirmField = new PasswordField; - mMaleButton = new RadioButton(_("Male"), "sex", true); - mFemaleButton = new RadioButton(_("Female"), "sex", false); mRegisterButton = new Button(_("Register"), "register", this); mCancelButton = new Button(_("Cancel"), "cancel", this); @@ -81,8 +79,10 @@ RegisterDialog::RegisterDialog(LoginData *loginData): place(0, 1, passwordLabel); place(0, 2, confirmLabel); - if (useGender) + if (optionalActions & Net::LoginHandler::SetGenderOnRegister) { + mMaleButton = new RadioButton(_("Male"), "sex", true); + mFemaleButton = new RadioButton(_("Female"), "sex", false); place(1, 3, mMaleButton); place(2, 3, mFemaleButton); } @@ -213,9 +213,9 @@ void RegisterDialog::action(const gcn::ActionEvent &event) mLoginData->username = mUserField->getText(); mLoginData->password = mPasswordField->getText(); - if (useGender) - *useGender = mFemaleButton->isSelected() ? GENDER_FEMALE : - GENDER_MALE; + if (mFemaleButton) + mLoginData->gender = mFemaleButton->isSelected() ? + GENDER_FEMALE : GENDER_MALE; if (mEmailField) mLoginData->email = mEmailField->getText(); mLoginData->registerLogin = true; @@ -230,11 +230,6 @@ void RegisterDialog::keyPressed(gcn::KeyEvent &keyEvent) mRegisterButton->setEnabled(canSubmit()); } -void RegisterDialog::setGender(Gender *gender) -{ - useGender = gender; -} - bool RegisterDialog::canSubmit() const { return !mUserField->getText().empty() && diff --git a/src/gui/register.h b/src/gui/register.h index 9f22a5bb..418d6dcd 100644 --- a/src/gui/register.h +++ b/src/gui/register.h @@ -80,20 +80,6 @@ class RegisterDialog : public Window, public gcn::ActionListener, */ void keyPressed(gcn::KeyEvent &keyEvent); - /** - * Tell the dialog to show an email field. Value stored in the passed - * string pointer. Default email from pointer. Passing NULL disables - * the feature. - */ - static void setEmail(std::string *email); - - /** - * Tell the dialog to show a gender selection. Value stored in the - * passed Gender pointer. Default Gender from pointer. Passing NULL - * disables the feature. - */ - static void setGender(Gender *gender); - private: /** * Returns whether submit can be enabled. This is true in the register @@ -114,8 +100,6 @@ class RegisterDialog : public Window, public gcn::ActionListener, WrongDataNoticeListener *mWrongDataNoticeListener; LoginData *mLoginData; - - static Gender *useGender; }; #endif diff --git a/src/main.cpp b/src/main.cpp index 82e8ff50..c1715fd1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -123,8 +123,9 @@ namespace { - struct SetupListener : public gcn::ActionListener + class SetupListener : public gcn::ActionListener { + public: /** * Called when receiving actions from widget. */ @@ -661,24 +662,27 @@ static void loadUpdates() } } -struct ErrorListener : public gcn::ActionListener +class ErrorListener : public gcn::ActionListener { +public: void action(const gcn::ActionEvent &event) { state = STATE_CHOOSE_SERVER; } } errorListener; -struct AccountListener : public gcn::ActionListener +class AccountListener : public gcn::ActionListener { +public: void action(const gcn::ActionEvent &event) { state = STATE_CHAR_SELECT; } } accountListener; -struct LoginListener : public gcn::ActionListener +class LoginListener : public gcn::ActionListener { +public: void action(const gcn::ActionEvent &event) { state = STATE_LOGIN; diff --git a/src/net/ea/charserverhandler.cpp b/src/net/ea/charserverhandler.cpp index e538eeaf..13c3cf45 100644 --- a/src/net/ea/charserverhandler.cpp +++ b/src/net/ea/charserverhandler.cpp @@ -21,13 +21,14 @@ #include "net/ea/charserverhandler.h" -#include "net/ea/generalhandler.h" +#include "net/ea/loginhandler.h" #include "net/ea/network.h" #include "net/ea/protocol.h" #include "net/logindata.h" #include "net/messagein.h" #include "net/messageout.h" +#include "net/net.h" #include "game.h" #include "log.h" @@ -44,7 +45,7 @@ Net::CharHandler *charHandler; namespace EAthena { -extern Token netToken; + extern ServerInfo charServer; extern ServerInfo mapServer; @@ -177,8 +178,11 @@ void CharServerHandler::handleMessage(MessageIn &msg) LocalPlayer *CharServerHandler::readPlayerData(MessageIn &msg, int &slot) { + const Token &token = + static_cast<LoginHandler*>(Net::getLoginHandler())->getToken(); + LocalPlayer *tempPlayer = new LocalPlayer(msg.readInt32(), 0, NULL); - tempPlayer->setGender(netToken.sex); + tempPlayer->setGender(token.sex); tempPlayer->setExp(msg.readInt32()); tempPlayer->setMoney(msg.readInt32()); @@ -241,8 +245,11 @@ void CharServerHandler::setCharCreateDialog(CharCreateDialog *window) attributes.push_back(_("Dexterity:")); attributes.push_back(_("Luck:")); + const Token &token = + static_cast<LoginHandler*>(Net::getLoginHandler())->getToken(); + mCharCreateDialog->setAttributes(attributes, 30, 1, 9); - mCharCreateDialog->setFixedGender(true, netToken.sex); + mCharCreateDialog->setFixedGender(true, token.sex); } void CharServerHandler::getCharacters() @@ -279,16 +286,19 @@ void CharServerHandler::deleteCharacter(int slot, LocalPlayer* character) void CharServerHandler::connect() { + const Token &token = + static_cast<LoginHandler*>(Net::getLoginHandler())->getToken(); + mNetwork->disconnect(); mNetwork->connect(charServer); MessageOut outMsg(CMSG_CHAR_SERVER_CONNECT); - outMsg.writeInt32(netToken.account_ID); - outMsg.writeInt32(netToken.session_ID1); - outMsg.writeInt32(netToken.session_ID2); + outMsg.writeInt32(token.account_ID); + outMsg.writeInt32(token.session_ID1); + outMsg.writeInt32(token.session_ID2); // [Fate] The next word is unused by the old char server, so we squeeze in // tmw client version information outMsg.writeInt16(CLIENT_PROTOCOL_VERSION); - outMsg.writeInt8((netToken.sex == GENDER_MALE) ? 1 : 0); + outMsg.writeInt8((token.sex == GENDER_MALE) ? 1 : 0); // We get 4 useless bytes before the real answer comes in (what are these?) mNetwork->skip(4); diff --git a/src/net/ea/gamehandler.cpp b/src/net/ea/gamehandler.cpp index f84688a3..a3c0ad3a 100644 --- a/src/net/ea/gamehandler.cpp +++ b/src/net/ea/gamehandler.cpp @@ -21,6 +21,7 @@ #include "net/ea/gamehandler.h" +#include "net/ea/loginhandler.h" #include "net/ea/network.h" #include "net/ea/protocol.h" @@ -41,7 +42,7 @@ Net::GameHandler *gameHandler; extern Game *game; namespace EAthena { -extern Token netToken; + extern ServerInfo mapServer; GameHandler::GameHandler() @@ -91,16 +92,19 @@ void GameHandler::connect() { mNetwork->connect(mapServer); + const Token &token = + static_cast<LoginHandler*>(Net::getLoginHandler())->getToken(); + // Send login infos MessageOut outMsg(CMSG_MAP_SERVER_CONNECT); - outMsg.writeInt32(netToken.account_ID); + outMsg.writeInt32(token.account_ID); outMsg.writeInt32(player_node->getId()); - outMsg.writeInt32(netToken.session_ID1); - outMsg.writeInt32(netToken.session_ID2); - outMsg.writeInt8((netToken.sex == GENDER_MALE) ? 1 : 0); + outMsg.writeInt32(token.session_ID1); + outMsg.writeInt32(token.session_ID2); + outMsg.writeInt8((token.sex == GENDER_MALE) ? 1 : 0); // Change the player's ID to the account ID to match what eAthena uses - player_node->setId(netToken.account_ID); + player_node->setId(token.account_ID); // We get 4 useless bytes before the real answer comes in (what are these?) mNetwork->skip(4); diff --git a/src/net/ea/gamehandler.h b/src/net/ea/gamehandler.h index 6cb640c1..d8adeeaf 100644 --- a/src/net/ea/gamehandler.h +++ b/src/net/ea/gamehandler.h @@ -55,7 +55,6 @@ class GameHandler : public MessageHandler, public Net::GameHandler void ping(int tick); void clear(); - }; } // namespace EAthena diff --git a/src/net/ea/generalhandler.cpp b/src/net/ea/generalhandler.cpp index c3eab725..78a10423 100644 --- a/src/net/ea/generalhandler.cpp +++ b/src/net/ea/generalhandler.cpp @@ -29,7 +29,6 @@ #include "net/ea/network.h" #include "net/ea/protocol.h" -#include "net/ea/token.h" #include "net/ea/adminhandler.h" #include "net/ea/beinghandler.h" @@ -67,10 +66,8 @@ Net::GeneralHandler *generalHandler = NULL; namespace EAthena { -Token netToken; ServerInfo charServer; ServerInfo mapServer; -Worlds worlds; GeneralHandler::GeneralHandler(): mAdminHandler(new AdminHandler), @@ -106,8 +103,6 @@ GeneralHandler::GeneralHandler(): stats.push_back(ItemDB::Stat("luck", N_("Luck %+d"))); ItemDB::setStatsList(stats); - - RegisterDialog::setGender(&netToken.sex); } GeneralHandler::~GeneralHandler() @@ -179,7 +174,8 @@ void GeneralHandler::reload() { if (mNetwork) mNetwork->disconnect(); - worlds.clear(); + + static_cast<LoginHandler*>(mLoginHandler.get())->clearWorlds(); } void GeneralHandler::unload() diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp index be547afa..5a77cce7 100644 --- a/src/net/ea/loginhandler.cpp +++ b/src/net/ea/loginhandler.cpp @@ -38,9 +38,8 @@ Net::LoginHandler *loginHandler; namespace EAthena { -extern Token netToken; + extern ServerInfo charServer; -extern Worlds worlds; LoginHandler::LoginHandler() { @@ -107,16 +106,16 @@ void LoginHandler::handleMessage(MessageIn &msg) // Skip the length word msg.skip(2); - delete_all(worlds); + clearWorlds(); + worldCount = (msg.getLength() - 47) / 32; - netToken.session_ID1 = msg.readInt32(); - netToken.account_ID = msg.readInt32(); - netToken.session_ID2 = msg.readInt32(); + mToken.session_ID1 = msg.readInt32(); + mToken.account_ID = msg.readInt32(); + mToken.session_ID2 = msg.readInt32(); msg.skip(30); // unknown - netToken.sex = msg.readInt8() ? GENDER_MALE : GENDER_FEMALE; + mToken.sex = msg.readInt8() ? GENDER_MALE : GENDER_FEMALE; - worlds.clear(); for (int i = 0; i < worldCount; i++) { WorldInfo *world = new WorldInfo; @@ -133,7 +132,7 @@ void LoginHandler::handleMessage(MessageIn &msg) ipToString(world->address), world->port); - worlds.push_back(world); + mWorlds.push_back(world); } state = STATE_WORLD_SELECT; break; @@ -236,12 +235,12 @@ void LoginHandler::changePassword(const std::string &username, void LoginHandler::chooseServer(unsigned int server) { - if (server >= worlds.size()) + if (server >= mWorlds.size()) return; charServer.clear(); - charServer.hostname = ipToString(worlds[server]->address); - charServer.port = worlds[server]->port; + charServer.hostname = ipToString(mWorlds[server]->address); + charServer.port = mWorlds[server]->port; state = STATE_UPDATE; } @@ -249,7 +248,7 @@ void LoginHandler::chooseServer(unsigned int server) void LoginHandler::registerAccount(LoginData *loginData) { std::string username = loginData->username; - username.append((netToken.sex == GENDER_FEMALE) ? "_F" : "_M"); + username.append((loginData->gender == GENDER_FEMALE) ? "_F" : "_M"); sendLoginRegister(username, loginData->password); } @@ -277,9 +276,15 @@ void LoginHandler::sendLoginRegister(const std::string &username, outMsg.writeInt8(0x03); } -Worlds LoginHandler::getWorlds() +Worlds LoginHandler::getWorlds() const +{ + return mWorlds; +} + +void LoginHandler::clearWorlds() { - return worlds; + delete_all(mWorlds); + mWorlds.clear(); } } // namespace EAthena diff --git a/src/net/ea/loginhandler.h b/src/net/ea/loginhandler.h index c5ce975e..0d0ef1eb 100644 --- a/src/net/ea/loginhandler.h +++ b/src/net/ea/loginhandler.h @@ -47,7 +47,7 @@ class LoginHandler : public MessageHandler, public Net::LoginHandler void disconnect(); int supportedOptionalActions() const - { return 0; } + { return SetGenderOnRegister; } void loginAccount(LoginData *loginData); @@ -66,13 +66,18 @@ class LoginHandler : public MessageHandler, public Net::LoginHandler void unregisterAccount(const std::string &username, const std::string &password); - Worlds getWorlds(); + Worlds getWorlds() const; + void clearWorlds(); + + const Token &getToken() const { return mToken; } private: void sendLoginRegister(const std::string &username, const std::string &password); std::string mUpdateHost; + Worlds mWorlds; + Token mToken; }; } // namespace EAthena diff --git a/src/net/ea/network.h b/src/net/ea/network.h index b61f363b..3b8d09f9 100644 --- a/src/net/ea/network.h +++ b/src/net/ea/network.h @@ -53,7 +53,7 @@ class Network void disconnect(); - ServerInfo getServer() + ServerInfo getServer() const { return mServer; } void registerHandler(MessageHandler *handler); diff --git a/src/net/ea/token.h b/src/net/ea/token.h index 6c47c10e..e5e4ab0d 100644 --- a/src/net/ea/token.h +++ b/src/net/ea/token.h @@ -24,7 +24,8 @@ #ifndef NET_EA_TOKEN_H #define NET_EA_TOKEN_H -typedef struct { +struct Token +{ int account_ID; int session_ID1; int session_ID2; @@ -37,6 +38,6 @@ typedef struct { session_ID2 = 0; sex = GENDER_UNSPECIFIED; } -} Token; +}; #endif // NET_EA_TOKEN_H diff --git a/src/net/logindata.h b/src/net/logindata.h index 9cc3a3eb..4f592f7d 100644 --- a/src/net/logindata.h +++ b/src/net/logindata.h @@ -36,6 +36,8 @@ struct LoginData std::string email; + Gender gender; + bool remember; /**< Whether to store the username. */ bool registerLogin; /**< Whether an account is being registered. */ @@ -45,6 +47,8 @@ struct LoginData password.clear(); newPassword.clear(); updateHost.clear(); + email.clear(); + gender = GENDER_UNSPECIFIED; } }; diff --git a/src/net/loginhandler.h b/src/net/loginhandler.h index e5a34382..12a0c26f 100644 --- a/src/net/loginhandler.h +++ b/src/net/loginhandler.h @@ -35,16 +35,22 @@ namespace Net { class LoginHandler { public: + /** + * This enum describes options specific to either eAthena or tmwserv. + * By querying for these flags, the GUI can adapt to the current + * server type dynamically. + */ enum OptionalAction { - Unregister = 0x1, - ChangeEmail = 0x2, - SetEmailOnRegister = 0x4 + Unregister = 0x1, + ChangeEmail = 0x2, + SetEmailOnRegister = 0x4, + SetGenderOnRegister = 0x8 }; - virtual void setServer(const ServerInfo &server) + void setServer(const ServerInfo &server) { mServer = server; } - virtual ServerInfo getServer() + ServerInfo getServer() const { return mServer; } virtual void connect() = 0; @@ -53,6 +59,9 @@ class LoginHandler virtual void disconnect() = 0; + /** + * @see OptionalAction + */ virtual int supportedOptionalActions() const = 0; virtual void loginAccount(LoginData *loginData) = 0; @@ -72,7 +81,7 @@ class LoginHandler virtual void unregisterAccount(const std::string &username, const std::string &password) = 0; - virtual Worlds getWorlds() = 0; + virtual Worlds getWorlds() const = 0; protected: ServerInfo mServer; diff --git a/src/net/tmwserv/loginhandler.cpp b/src/net/tmwserv/loginhandler.cpp index 7c4b1340..9c102031 100644 --- a/src/net/tmwserv/loginhandler.cpp +++ b/src/net/tmwserv/loginhandler.cpp @@ -351,7 +351,7 @@ void LoginHandler::unregisterAccount(const std::string &username, Net::AccountServer::Account::unregister(username, password); } -Worlds LoginHandler::getWorlds() +Worlds LoginHandler::getWorlds() const { return Worlds(); } diff --git a/src/net/tmwserv/loginhandler.h b/src/net/tmwserv/loginhandler.h index cbc2b96c..e9887e1a 100644 --- a/src/net/tmwserv/loginhandler.h +++ b/src/net/tmwserv/loginhandler.h @@ -64,7 +64,7 @@ class LoginHandler : public MessageHandler, public Net::LoginHandler void unregisterAccount(const std::string &username, const std::string &password); - Worlds getWorlds(); + Worlds getWorlds() const; private: void handleLoginResponse(MessageIn &msg); diff --git a/src/net/worldinfo.h b/src/net/worldinfo.h index 045c64c2..72ecddd6 100644 --- a/src/net/worldinfo.h +++ b/src/net/worldinfo.h @@ -25,13 +25,13 @@ #include <string> #include <vector> -typedef struct { +struct WorldInfo { int address; std::string name; short port; short online_users; std::string updateHost; -} WorldInfo; +}; typedef std::vector<WorldInfo*> Worlds; |