diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 309 |
1 files changed, 172 insertions, 137 deletions
diff --git a/src/main.cpp b/src/main.cpp index c1715fd1..0df822b9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -43,6 +43,8 @@ #include "gui/widgets/label.h" #include "gui/widgets/progressbar.h" +#include "gui/changeemaildialog.h" +#include "gui/changepassworddialog.h" #include "gui/charselectdialog.h" #include "gui/connectiondialog.h" #include "gui/gui.h" @@ -55,6 +57,7 @@ #include "gui/sdlinput.h" #include "gui/serverdialog.h" #include "gui/setup.h" +#include "gui/unregisterdialog.h" #include "gui/updatewindow.h" #include "gui/worldselectdialog.h" @@ -923,7 +926,7 @@ int main(int argc, char *argv[]) loadUpdates(); } - //printf("State change: %d to %d\n", oldstate, state); + printf("State change: %d to %d\n", oldstate, state); oldstate = state; @@ -940,7 +943,7 @@ int main(int argc, char *argv[]) switch (state) { case STATE_CHOOSE_SERVER: - logger->log("State: CHOOSE_SERVER"); + logger->log("State: CHOOSE SERVER"); // Don't allow an alpha opacity // lower than the default value @@ -962,30 +965,10 @@ int main(int argc, char *argv[]) break; case STATE_CONNECT_SERVER: - logger->log("State: CONNECT_SERVER"); + logger->log("State: CONNECT SERVER"); currentDialog = new ConnectionDialog(STATE_SWITCH_SERVER); break; - case STATE_UPDATE: - if (options.skipUpdate) - { - state = STATE_LOAD_DATA; - } - else - { - // Determine which source to use for the update host - if (!options.updateHost.empty()) - updateHost = options.updateHost; - else - updateHost = loginData.updateHost; - - setUpdatesDir(); - logger->log("State: UPDATE"); - currentDialog = new UpdaterWindow(updateHost, - homeDir + "/" + updatesDir); - } - break; - case STATE_LOGIN: logger->log("State: LOGIN"); // Don't allow an alpha opacity @@ -1004,33 +987,10 @@ int main(int argc, char *argv[]) break; case STATE_LOGIN_ATTEMPT: + logger->log("State: LOGIN ATTEMPT"); accountLogin(&loginData); break; - case STATE_LOAD_DATA: - logger->log("State: LOAD DATA"); - - // Add customdata directory - ResourceManager::getInstance()->searchAndAddArchives( - "customdata/", - "zip", - false); - - // Load XML databases - ColorDB::load(); - ItemDB::load(); - Being::load(); // Hairstyles - MonsterDB::load(); - NPCDB::load(); - EmoteDB::load(); - StatusEffect::load(); - Units::loadUnits(); - - desktop->reloadWallpaper(); - - state = STATE_GET_CHARACTERS; - break; - case STATE_WORLD_SELECT: logger->log("State: WORLD SELECT"); { @@ -1059,55 +1019,61 @@ int main(int argc, char *argv[]) break; case STATE_WORLD_SELECT_ATTEMPT: - logger->log("State: Attempting world selection"); + logger->log("State: WORLD SELECT ATTEMPT"); currentDialog = new ConnectionDialog(STATE_WORLD_SELECT); break; - case STATE_LOGIN_ERROR: - logger->log("State: LOGIN ERROR"); - currentDialog = new OkDialog(_("Error"), errorMessage); - currentDialog->addActionListener(&loginListener); - currentDialog = NULL; // OkDialog deletes itself - break; - - case STATE_SWITCH_SERVER: - logger->log("State: SWITCH SERVER"); - -#ifdef TMWSERV_SUPPORT - gameServerConnection->disconnect(); - chatServerConnection->disconnect(); - accountServerConnection->disconnect(); -#endif + case STATE_UPDATE: + if (options.skipUpdate) + { + state = STATE_LOAD_DATA; + } + else + { + // Determine which source to use for the update host + if (!options.updateHost.empty()) + updateHost = options.updateHost; + else + updateHost = loginData.updateHost; - state = STATE_CHOOSE_SERVER; + setUpdatesDir(); + logger->log("State: UPDATE"); + currentDialog = new UpdaterWindow(updateHost, + homeDir + "/" + updatesDir); + } break; - case STATE_SWITCH_LOGIN: - logger->log("State: SWITCH LOGIN"); - - Net::getLoginHandler()->logout(); + case STATE_LOAD_DATA: + logger->log("State: LOAD DATA"); - state = STATE_LOGIN; - break; + // Add customdata directory + ResourceManager::getInstance()->searchAndAddArchives( + "customdata/", + "zip", + false); - case STATE_REGISTER: - logger->log("State: REGISTER"); - currentDialog = new RegisterDialog(&loginData); - break; + // Load XML databases + ColorDB::load(); + ItemDB::load(); + Being::load(); // Hairstyles + MonsterDB::load(); + NPCDB::load(); + EmoteDB::load(); + StatusEffect::load(); + Units::loadUnits(); - case STATE_REGISTER_ATTEMPT: - logger->log("Username is %s", loginData.username.c_str()); + desktop->reloadWallpaper(); - Net::getCharHandler()->setCharInfo(&charInfo); - Net::getLoginHandler()->registerAccount(&loginData); + state = STATE_GET_CHARACTERS; break; case STATE_GET_CHARACTERS: + logger->log("State: GET CHARACTERS"); Net::getCharHandler()->getCharacters(); break; case STATE_CHAR_SELECT: - logger->log("State: CHAR_SELECT"); + logger->log("State: CHAR SELECT"); // Don't allow an alpha opacity // lower than the default value SkinLoader::instance()->setMinimumOpacity(0.8f); @@ -1125,14 +1091,72 @@ int main(int argc, char *argv[]) break; - case STATE_CHANGEEMAIL: - logger->log("State: CHANGE EMAIL"); - // TODO + case STATE_CONNECT_GAME: + logger->log("State: CONNECT GAME"); + Net::getGameHandler()->connect(); + currentDialog = new ConnectionDialog(STATE_SWITCH_CHARACTER); break; - case STATE_CHANGEEMAIL_ATTEMPT: - logger->log("State: CHANGE EMAIL ATTEMPT"); - Net::getLoginHandler()->changeEmail(loginData.email); + case STATE_GAME: + logger->log("Memorizing selected character %s", + player_node->getName().c_str()); + config.setValue("lastCharacter", player_node->getName()); + + Net::getGameHandler()->inGame(); + + // Allow any alpha opacity + SkinLoader::instance()->setMinimumOpacity(-1.0f); + + sound.fadeOutMusic(1000); + + delete setupButton; + delete desktop; + setupButton = NULL; + desktop = NULL; + + currentDialog = NULL; + + logger->log("State: GAME"); + game = new Game; + game->logic(); + delete game; + game = 0; + + state = STATE_EXIT; + + Net::getGeneralHandler()->unload(); + + break; + + case STATE_LOGIN_ERROR: + logger->log("State: LOGIN ERROR"); + currentDialog = new OkDialog(_("Error"), errorMessage); + currentDialog->addActionListener(&loginListener); + currentDialog = NULL; // OkDialog deletes itself + break; + + case STATE_ACCOUNTCHANGE_ERROR: + logger->log("State: ACCOUNT CHANGE ERROR"); + currentDialog = new OkDialog(_("Error"), errorMessage); + currentDialog->addActionListener(&accountListener); + currentDialog = NULL; // OkDialog deletes itself + break; + + case STATE_REGISTER: + logger->log("State: REGISTER"); + currentDialog = new RegisterDialog(&loginData); + break; + + case STATE_REGISTER_ATTEMPT: + logger->log("Username is %s", loginData.username.c_str()); + + Net::getCharHandler()->setCharInfo(&charInfo); + Net::getLoginHandler()->registerAccount(&loginData); + break; + + case STATE_CHANGEPASSWORD: + logger->log("State: CHANGE PASSWORD"); + currentDialog = new ChangePasswordDialog(&loginData); break; case STATE_CHANGEPASSWORD_ATTEMPT: @@ -1142,8 +1166,8 @@ int main(int argc, char *argv[]) loginData.newPassword); break; - case STATE_CHANGEPASSWORD: - logger->log("State: CHANGE PASSWORD"); + case STATE_CHANGEPASSWORD_SUCCESS: + logger->log("State: CHANGE PASSWORD SUCCESS"); currentDialog = new OkDialog(_("Password Change"), _("Password changed successfully!")); currentDialog->addActionListener(&accountListener); @@ -1152,14 +1176,37 @@ int main(int argc, char *argv[]) loginData.newPassword = ""; break; + case STATE_CHANGEEMAIL: + logger->log("State: CHANGE EMAIL"); + currentDialog = new ChangeEmailDialog(&loginData); + break; + + case STATE_CHANGEEMAIL_ATTEMPT: + logger->log("State: CHANGE EMAIL ATTEMPT"); + Net::getLoginHandler()->changeEmail(loginData.email); + break; + + case STATE_CHANGEEMAIL_SUCCESS: + logger->log("State: CHANGE EMAIL SUCCESS"); + currentDialog = new OkDialog(_("Email Change"), + _("Email changed successfully!")); + currentDialog->addActionListener(&accountListener); + currentDialog = NULL; // OkDialog deletes itself + break; + + case STATE_UNREGISTER: + logger->log("State: UNREGISTER"); + currentDialog = new UnRegisterDialog(&loginData); + break; + case STATE_UNREGISTER_ATTEMPT: logger->log("State: UNREGISTER ATTEMPT"); Net::getLoginHandler()->unregisterAccount( loginData.username, loginData.password); break; - case STATE_UNREGISTER: - logger->log("State: UNREGISTER"); + case STATE_UNREGISTER_SUCCESS: + logger->log("State: UNREGISTER SUCCESS"); #ifdef TMWSERV_SUPPORT accountServerConnection->disconnect(); #endif @@ -1171,62 +1218,28 @@ int main(int argc, char *argv[]) currentDialog = NULL; // OkDialog deletes itself break; - case STATE_ACCOUNTCHANGE_ERROR: - logger->log("State: ACCOUNT CHANGE ERROR"); - currentDialog = new OkDialog(_("Error"), errorMessage); - currentDialog->addActionListener(&accountListener); - currentDialog = NULL; // OkDialog deletes itself - break; - + case STATE_SWITCH_SERVER: + logger->log("State: SWITCH SERVER"); - case STATE_ERROR: - logger->log("State: ERROR"); - currentDialog = new OkDialog(_("Error"), errorMessage); - currentDialog->addActionListener(&errorListener); - currentDialog = NULL; // OkDialog deletes itself - Net::getGameHandler()->clear(); - Net::getGeneralHandler()->clearHandlers(); - break; +#ifdef TMWSERV_SUPPORT + gameServerConnection->disconnect(); + chatServerConnection->disconnect(); + accountServerConnection->disconnect(); +#endif - case STATE_CONNECT_GAME: - logger->log("State: CONNECT_GAME"); - Net::getGameHandler()->connect(); - currentDialog = new ConnectionDialog(STATE_SWITCH_CHARACTER); + state = STATE_CHOOSE_SERVER; break; - case STATE_GAME: - logger->log("Memorizing selected character %s", - player_node->getName().c_str()); - config.setValue("lastCharacter", player_node->getName()); - - Net::getGameHandler()->inGame(); - - // Allow any alpha opacity - SkinLoader::instance()->setMinimumOpacity(-1.0f); - - sound.fadeOutMusic(1000); - - delete setupButton; - delete desktop; - setupButton = NULL; - desktop = NULL; - - currentDialog = NULL; - - logger->log("State: GAME"); - game = new Game; - game->logic(); - delete game; - game = 0; - - state = STATE_EXIT; + case STATE_SWITCH_LOGIN: + logger->log("State: SWITCH LOGIN"); - Net::getGeneralHandler()->unload(); + Net::getLoginHandler()->logout(); + state = STATE_LOGIN; break; case STATE_SWITCH_CHARACTER: - logger->log("State: SWITCH_CHARACTER"); + logger->log("State: SWITCH CHARACTER"); // Done with game Net::getGameHandler()->clear(); @@ -1234,13 +1247,35 @@ int main(int argc, char *argv[]) Net::getCharHandler()->getCharacters(); break; + case STATE_LOGOUT_ATTEMPT: + logger->log("State: LOGOUT ATTEMPT"); + // TODO + break; + + case STATE_WAIT: + logger->log("State: WAIT"); + break; + + case STATE_EXIT: + logger->log("State: EXIT"); + break; + case STATE_FORCE_QUIT: - logger->log("State: FORCE_QUIT"); + logger->log("State: FORCE QUIT"); if (Net::getGeneralHandler()) Net::getGeneralHandler()->unload(); state = STATE_EXIT; break; + case STATE_ERROR: + logger->log("State: ERROR"); + currentDialog = new OkDialog(_("Error"), errorMessage); + currentDialog->addActionListener(&errorListener); + currentDialog = NULL; // OkDialog deletes itself + Net::getGameHandler()->clear(); + Net::getGeneralHandler()->clearHandlers(); + break; + default: state = STATE_FORCE_QUIT; break; |