From 924e0a887f87ce531bc5bd26cb55e410b7303383 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Sun, 4 Oct 2009 22:28:19 +0200 Subject: Introduced Net::LoginHandler::SetEmailOnRegister This "optional action" specifies whether the server expects to get an email address during registration. It is used now instead of having the general handlers of eAthena and tmwserv set a pointer to an email string on the GUI dialogs (to keep things understandable, the dependency should preferably go one way). --- src/gui/changeemaildialog.cpp | 13 +++---------- src/gui/changeemaildialog.h | 1 - src/gui/register.cpp | 22 +++++++++++----------- src/gui/register.h | 1 - src/main.cpp | 2 +- src/map.cpp | 23 +++++++++-------------- src/map.h | 2 +- src/net/ea/generalhandler.cpp | 1 - src/net/logindata.h | 2 ++ src/net/loginhandler.h | 5 +++-- src/net/tmwserv/generalhandler.cpp | 3 --- src/net/tmwserv/loginhandler.cpp | 3 +-- src/net/tmwserv/loginhandler.h | 2 +- 13 files changed, 32 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/gui/changeemaildialog.cpp b/src/gui/changeemaildialog.cpp index 15e54895..45dcc5f8 100644 --- a/src/gui/changeemaildialog.cpp +++ b/src/gui/changeemaildialog.cpp @@ -39,11 +39,10 @@ #include #include -std::string *ChangeEmailDialog::emailPointer = NULL; - ChangeEmailDialog::ChangeEmailDialog(Window *parent, LoginData *loginData): Window(_("Change Email Address"), true, parent), - mWrongDataNoticeListener(new WrongDataNoticeListener) + mWrongDataNoticeListener(new WrongDataNoticeListener), + mLoginData(loginData) { gcn::Label *accountLabel = new Label(strprintf(_("Account: %s"), mLoginData->username.c_str())); @@ -159,15 +158,9 @@ void ChangeEmailDialog::action(const gcn::ActionEvent &event) // No errors detected, change account password. mChangeEmailButton->setEnabled(false); // Set the new email address - *emailPointer = newFirstEmail; + mLoginData->email = newFirstEmail; state = STATE_CHANGEEMAIL_ATTEMPT; scheduleDelete(); } - } } - -void ChangeEmailDialog::setEmail(std::string *email) -{ - emailPointer = email; -} diff --git a/src/gui/changeemaildialog.h b/src/gui/changeemaildialog.h index 23aab080..ae9aa6cc 100644 --- a/src/gui/changeemaildialog.h +++ b/src/gui/changeemaildialog.h @@ -73,7 +73,6 @@ class ChangeEmailDialog : public Window, public gcn::ActionListener WrongDataNoticeListener *mWrongDataNoticeListener; LoginData *mLoginData; - static std::string *emailPointer; }; #endif // GUI_CHANGEEMAIL_H diff --git a/src/gui/register.cpp b/src/gui/register.cpp index 50f63c69..78c79eeb 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -37,6 +37,8 @@ #include "gui/widgets/textfield.h" #include "net/logindata.h" +#include "net/net.h" +#include "net/loginhandler.h" #include "utils/gettext.h" #include "utils/stringutils.h" @@ -52,24 +54,24 @@ void WrongDataNoticeListener::action(const gcn::ActionEvent &event) mTarget->requestFocus(); } -std::string *RegisterDialog::useEmail = NULL; Gender *RegisterDialog::useGender = NULL; RegisterDialog::RegisterDialog(LoginData *loginData): Window(_("Register")), + mEmailField(0), mWrongDataNoticeListener(new WrongDataNoticeListener), mLoginData(loginData) { + int optionalActions = Net::getLoginHandler()->supportedOptionalActions(); + gcn::Label *userLabel = new Label(_("Name:")); gcn::Label *passwordLabel = new Label(_("Password:")); gcn::Label *confirmLabel = new Label(_("Confirm:")); - gcn::Label *emailLabel = new Label(_("Email:")); 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); - mEmailField = new TextField; mRegisterButton = new Button(_("Register"), "register", this); mCancelButton = new Button(_("Cancel"), "cancel", this); @@ -85,11 +87,14 @@ RegisterDialog::RegisterDialog(LoginData *loginData): place(2, 3, mFemaleButton); } - if (useEmail) + if (optionalActions & Net::LoginHandler::SetEmailOnRegister) { + gcn::Label *emailLabel = new Label(_("Email:")); + mEmailField = new TextField; place(0, 3, emailLabel); place(1, 3, mEmailField, 3).setPadding(2); } + place(1, 0, mUserField, 3).setPadding(2); place(1, 1, mPasswordField, 3).setPadding(2); place(1, 2, mConfirmField, 3).setPadding(2); @@ -211,8 +216,8 @@ void RegisterDialog::action(const gcn::ActionEvent &event) if (useGender) *useGender = mFemaleButton->isSelected() ? GENDER_FEMALE : GENDER_MALE; - if (useEmail) - *useEmail = mEmailField->getText(); + if (mEmailField) + mLoginData->email = mEmailField->getText(); mLoginData->registerLogin = true; state = STATE_REGISTER_ATTEMPT; @@ -225,11 +230,6 @@ void RegisterDialog::keyPressed(gcn::KeyEvent &keyEvent) mRegisterButton->setEnabled(canSubmit()); } -void RegisterDialog::setEmail(std::string *email) -{ - useEmail = email; -} - void RegisterDialog::setGender(Gender *gender) { useGender = gender; diff --git a/src/gui/register.h b/src/gui/register.h index 8fe3d9fb..9f22a5bb 100644 --- a/src/gui/register.h +++ b/src/gui/register.h @@ -115,7 +115,6 @@ class RegisterDialog : public Window, public gcn::ActionListener, LoginData *mLoginData; - static std::string *useEmail; static Gender *useGender; }; diff --git a/src/main.cpp b/src/main.cpp index 6b9d3227..52847b3e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1134,7 +1134,7 @@ int main(int argc, char *argv[]) case STATE_CHANGEEMAIL_ATTEMPT: logger->log("State: CHANGE EMAIL ATTEMPT"); - // TODO + Net::getLoginHandler()->changeEmail(loginData.email); break; case STATE_CHANGEPASSWORD_ATTEMPT: diff --git a/src/map.cpp b/src/map.cpp index 2176327f..56e13697 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -292,13 +292,13 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY) MapSprites::const_iterator si = mSprites.begin(); while (si != mSprites.end()) { - if (*si) - // For now, just draw sprites with only one layer. + if (Sprite *sprite = *si) { - if ((*si)->getNumberOfLayers() == 1) + // For now, just draw sprites with only one layer. + if (sprite->getNumberOfLayers() == 1) { - (*si)->setAlpha(0.3f); - (*si)->draw(graphics, -scrollX, -scrollY); + sprite->setAlpha(0.3f); + sprite->draw(graphics, -scrollX, -scrollY); } } si++; @@ -398,7 +398,7 @@ void Map::drawOverlay(Graphics *graphics, // Detail 1: only one overlay, higher: all overlays if (detail == 1) break; - }; + } } class ContainsGidFunctor @@ -721,13 +721,8 @@ void Map::initializeParticleEffects(Particle *particleEngine) } } -TileAnimation *Map::getAnimationForGid(int gid) +TileAnimation *Map::getAnimationForGid(int gid) const { - std::map::iterator i = mTileAnimations.find(gid); - if (i == mTileAnimations.end()) - { - return NULL; - } else { - return i->second; - } + std::map::const_iterator i = mTileAnimations.find(gid); + return (i == mTileAnimations.end()) ? NULL : i->second; } diff --git a/src/map.h b/src/map.h index 9c04f354..9558f989 100644 --- a/src/map.h +++ b/src/map.h @@ -292,7 +292,7 @@ class Map : public Properties /** * Gets the tile animation for a specific gid */ - TileAnimation *getAnimationForGid(int gid); + TileAnimation *getAnimationForGid(int gid) const; private: /** diff --git a/src/net/ea/generalhandler.cpp b/src/net/ea/generalhandler.cpp index b9172379..c3eab725 100644 --- a/src/net/ea/generalhandler.cpp +++ b/src/net/ea/generalhandler.cpp @@ -107,7 +107,6 @@ GeneralHandler::GeneralHandler(): ItemDB::setStatsList(stats); - RegisterDialog::setEmail(NULL); RegisterDialog::setGender(&netToken.sex); } diff --git a/src/net/logindata.h b/src/net/logindata.h index c0ca0a4e..9cc3a3eb 100644 --- a/src/net/logindata.h +++ b/src/net/logindata.h @@ -34,6 +34,8 @@ struct LoginData std::string newPassword; std::string updateHost; + std::string email; + bool remember; /**< Whether to store the username. */ bool registerLogin; /**< Whether an account is being registered. */ diff --git a/src/net/loginhandler.h b/src/net/loginhandler.h index e4f8c767..e5a34382 100644 --- a/src/net/loginhandler.h +++ b/src/net/loginhandler.h @@ -36,8 +36,9 @@ class LoginHandler { public: enum OptionalAction { - Unregister = 0x1, - ChangeEmail = 0x2 + Unregister = 0x1, + ChangeEmail = 0x2, + SetEmailOnRegister = 0x4 }; virtual void setServer(const ServerInfo &server) diff --git a/src/net/tmwserv/generalhandler.cpp b/src/net/tmwserv/generalhandler.cpp index 7948953e..8e911c9c 100644 --- a/src/net/tmwserv/generalhandler.cpp +++ b/src/net/tmwserv/generalhandler.cpp @@ -63,7 +63,6 @@ Net::Connection *accountServerConnection = 0; namespace TmwServ { -std::string userEmail = ""; std::string netToken = ""; ServerInfo gameServer; ServerInfo chatServer; @@ -103,8 +102,6 @@ GeneralHandler::GeneralHandler(): ItemDB::setStatsList(stats); - ChangeEmailDialog::setEmail(&userEmail); - RegisterDialog::setEmail(&userEmail); RegisterDialog::setGender(NULL); } diff --git a/src/net/tmwserv/loginhandler.cpp b/src/net/tmwserv/loginhandler.cpp index 613b4128..7c4b1340 100644 --- a/src/net/tmwserv/loginhandler.cpp +++ b/src/net/tmwserv/loginhandler.cpp @@ -39,7 +39,6 @@ Net::LoginHandler *loginHandler; extern Net::Connection *accountServerConnection; namespace TmwServ { -extern std::string userEmail; LoginHandler::LoginHandler() { @@ -343,7 +342,7 @@ void LoginHandler::registerAccount(LoginData *loginData) 0, // client version loginData->username, loginData->password, - userEmail); + loginData->email); } void LoginHandler::unregisterAccount(const std::string &username, diff --git a/src/net/tmwserv/loginhandler.h b/src/net/tmwserv/loginhandler.h index 66f243b7..cbc2b96c 100644 --- a/src/net/tmwserv/loginhandler.h +++ b/src/net/tmwserv/loginhandler.h @@ -45,7 +45,7 @@ class LoginHandler : public MessageHandler, public Net::LoginHandler void disconnect(); int supportedOptionalActions() const - { return Unregister | ChangeEmail; } + { return Unregister | ChangeEmail | SetEmailOnRegister; } void loginAccount(LoginData *loginData); -- cgit v1.2.3-60-g2f50