diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2010-02-21 20:40:07 +0100 |
---|---|---|
committer | Chuck Miller <shadowmil@gmail.com> | 2010-02-21 17:05:40 -0500 |
commit | c8b0d1e56f27c3141895d28b2fc768afffe7bb2d (patch) | |
tree | 0a03458836badee3e1b0da13a0721c9261e7fa86 /src/net | |
parent | 204a14c91bbe4436eb3b26bebf30cbe5669bdd1a (diff) | |
download | mana-c8b0d1e56f27c3141895d28b2fc768afffe7bb2d.tar.gz mana-c8b0d1e56f27c3141895d28b2fc768afffe7bb2d.tar.bz2 mana-c8b0d1e56f27c3141895d28b2fc768afffe7bb2d.tar.xz mana-c8b0d1e56f27c3141895d28b2fc768afffe7bb2d.zip |
Made tick counter and framerate limiter work during login sequence
Much code was moved from main() to the new Client::exec(). This new
event loop now integrates with the Game class, so that the tick counter
and framerate limiter apply universally.
The Client class is also responsible for some things that used to be
global variables.
Mantis-issue: ...
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/ea/beinghandler.cpp | 2 | ||||
-rw-r--r-- | src/net/ea/charserverhandler.cpp | 6 | ||||
-rw-r--r-- | src/net/ea/gamehandler.cpp | 7 | ||||
-rw-r--r-- | src/net/ea/generalhandler.cpp | 8 | ||||
-rw-r--r-- | src/net/ea/loginhandler.cpp | 15 | ||||
-rw-r--r-- | src/net/logindata.h | 3 | ||||
-rw-r--r-- | src/net/manaserv/beinghandler.cpp | 7 | ||||
-rw-r--r-- | src/net/manaserv/charhandler.cpp | 9 | ||||
-rw-r--r-- | src/net/manaserv/chathandler.cpp | 5 | ||||
-rw-r--r-- | src/net/manaserv/gamehandler.cpp | 6 | ||||
-rw-r--r-- | src/net/manaserv/generalhandler.cpp | 6 | ||||
-rw-r--r-- | src/net/manaserv/loginhandler.cpp | 36 | ||||
-rw-r--r-- | src/net/manaserv/playerhandler.cpp | 4 |
13 files changed, 55 insertions, 59 deletions
diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp index 14ed40bc..fd08ecaf 100644 --- a/src/net/ea/beinghandler.cpp +++ b/src/net/ea/beinghandler.cpp @@ -23,8 +23,8 @@ #include "being.h" #include "beingmanager.h" +#include "client.h" #include "effectmanager.h" -#include "game.h" #include "localplayer.h" #include "log.h" #include "npc.h" diff --git a/src/net/ea/charserverhandler.cpp b/src/net/ea/charserverhandler.cpp index 23d88356..f0a13f43 100644 --- a/src/net/ea/charserverhandler.cpp +++ b/src/net/ea/charserverhandler.cpp @@ -21,9 +21,9 @@ #include "net/ea/charserverhandler.h" +#include "client.h" #include "game.h" #include "log.h" -#include "main.h" #include "gui/charcreatedialog.h" #include "gui/okdialog.h" @@ -92,7 +92,7 @@ void CharServerHandler::handleMessage(Net::MessageIn &msg) character->dummy->getName().c_str(), slot); } - state = STATE_CHAR_SELECT; + Client::setState(STATE_CHAR_SELECT); } break; @@ -167,7 +167,7 @@ void CharServerHandler::handleMessage(Net::MessageIn &msg) updateCharSelectDialog(); mNetwork->disconnect(); - state = STATE_CONNECT_GAME; + Client::setState(STATE_CONNECT_GAME); break; } } diff --git a/src/net/ea/gamehandler.cpp b/src/net/ea/gamehandler.cpp index b7b8389a..3625b9ab 100644 --- a/src/net/ea/gamehandler.cpp +++ b/src/net/ea/gamehandler.cpp @@ -21,10 +21,9 @@ #include "net/ea/gamehandler.h" -#include "game.h" +#include "client.h" #include "localplayer.h" #include "log.h" -#include "main.h" #include "gui/widgets/chattab.h" @@ -74,7 +73,7 @@ void GameHandler::handleMessage(Net::MessageIn &msg) logger->log("Protocol: Player start position: (%d, %d), Direction: %d", x, y, direction); // Switch now or we'll have problems - state = STATE_GAME; + Client::setState(STATE_GAME); player_node->setTileCoords(x, y); } break; @@ -91,7 +90,7 @@ void GameHandler::handleMessage(Net::MessageIn &msg) case SMSG_CHAR_SWITCH_RESPONSE: if (msg.readInt8()) { - state = STATE_SWITCH_CHARACTER; + Client::setState(STATE_SWITCH_CHARACTER); } break; diff --git a/src/net/ea/generalhandler.cpp b/src/net/ea/generalhandler.cpp index 7fc5886a..f7d495a6 100644 --- a/src/net/ea/generalhandler.cpp +++ b/src/net/ea/generalhandler.cpp @@ -21,9 +21,9 @@ #include "net/ea/generalhandler.h" +#include "client.h" #include "configuration.h" #include "log.h" -#include "main.h" #include "gui/charselectdialog.h" #include "gui/inventorywindow.h" @@ -129,7 +129,7 @@ void GeneralHandler::handleMessage(Net::MessageIn &msg) errorMessage = _("No servers available."); break; case 2: - if (state == STATE_GAME) + if (Client::getState() == STATE_GAME) errorMessage = _("Someone else is trying to use this " "account."); else @@ -145,7 +145,7 @@ void GeneralHandler::handleMessage(Net::MessageIn &msg) errorMessage = _("Unknown connection error."); break; } - state = STATE_ERROR; + Client::setState(STATE_ERROR); break; } } @@ -199,7 +199,7 @@ void GeneralHandler::flushNetwork() else errorMessage = _("Got disconnected from server!"); - state = STATE_ERROR; + Client::setState(STATE_ERROR); } } diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp index 3f0fe0d0..bec97ed7 100644 --- a/src/net/ea/loginhandler.cpp +++ b/src/net/ea/loginhandler.cpp @@ -21,8 +21,8 @@ #include "net/ea/loginhandler.h" +#include "client.h" #include "log.h" -#include "main.h" #include "net/logindata.h" #include "net/messagein.h" @@ -68,7 +68,7 @@ void LoginHandler::handleMessage(Net::MessageIn &msg) // Successful pass change if (errMsg == 1) { - state = STATE_CHANGEPASSWORD_SUCCESS; + Client::setState(STATE_CHANGEPASSWORD_SUCCESS); } // pass change failed else @@ -88,7 +88,7 @@ void LoginHandler::handleMessage(Net::MessageIn &msg) errorMessage = _("Unknown error."); break; } - state = STATE_ACCOUNTCHANGE_ERROR; + Client::setState(STATE_ACCOUNTCHANGE_ERROR); } } break; @@ -136,7 +136,7 @@ void LoginHandler::handleMessage(Net::MessageIn &msg) mWorlds.push_back(world); } - state = STATE_WORLD_SELECT; + Client::setState(STATE_WORLD_SELECT); break; case SMSG_LOGIN_ERROR: @@ -175,8 +175,9 @@ void LoginHandler::handleMessage(Net::MessageIn &msg) errorMessage = _("Unknown error."); break; } - state = STATE_ERROR; + Client::setState(STATE_ERROR); break; + case SMSG_SERVER_VERSION_RESPONSE: { // TODO: verify these! @@ -214,7 +215,7 @@ void LoginHandler::disconnect() void LoginHandler::getRegistrationDetails() { // Not supported, so move on - state = STATE_REGISTER; + Client::setState(STATE_REGISTER); } void LoginHandler::loginAccount(LoginData *loginData) @@ -250,7 +251,7 @@ void LoginHandler::chooseServer(unsigned int server) charServer.hostname = ipToString(mWorlds[server]->address); charServer.port = mWorlds[server]->port; - state = STATE_UPDATE; + Client::setState(STATE_UPDATE); } void LoginHandler::registerAccount(LoginData *loginData) diff --git a/src/net/logindata.h b/src/net/logindata.h index 5a96db20..9bbeed4f 100644 --- a/src/net/logindata.h +++ b/src/net/logindata.h @@ -28,8 +28,9 @@ #include <string> -struct LoginData +class LoginData { +public: std::string username; std::string password; std::string newPassword; diff --git a/src/net/manaserv/beinghandler.cpp b/src/net/manaserv/beinghandler.cpp index 86f86d3f..bab5471b 100644 --- a/src/net/manaserv/beinghandler.cpp +++ b/src/net/manaserv/beinghandler.cpp @@ -23,13 +23,12 @@ #include "being.h" #include "beingmanager.h" +#include "client.h" #include "game.h" #include "localplayer.h" #include "log.h" -#include "main.h" #include "npc.h" #include "particle.h" -#include "sound.h" #include "gui/okdialog.h" @@ -103,10 +102,10 @@ Vector BeingHandler::giveSpeedInPixelsPerTicks(float speedInTilesPerSeconds) { speedInTicks.x = speedInTilesPerSeconds * (float)map->getTileWidth() - / 1000 * (float)MILLISECONDS_IN_A_TICK; + / 1000 * (float) MILLISECONDS_IN_A_TICK; speedInTicks.y = speedInTilesPerSeconds * (float)map->getTileHeight() - / 1000 * (float)MILLISECONDS_IN_A_TICK; + / 1000 * (float) MILLISECONDS_IN_A_TICK; } } diff --git a/src/net/manaserv/charhandler.cpp b/src/net/manaserv/charhandler.cpp index 14d2b11f..4b574821 100644 --- a/src/net/manaserv/charhandler.cpp +++ b/src/net/manaserv/charhandler.cpp @@ -21,10 +21,9 @@ #include "net/manaserv/charhandler.h" -#include "game.h" +#include "client.h" #include "localplayer.h" #include "log.h" -#include "main.h" #include "gui/charcreatedialog.h" #include "gui/okdialog.h" @@ -236,14 +235,14 @@ void CharHandler::handleCharacterSelectResponse(Net::MessageIn &msg) mCachedCharacterInfos.clear(); updateCharacters(); - state = STATE_CONNECT_GAME; + Client::setState(STATE_CONNECT_GAME); } else if (errMsg == ERRMSG_FAILURE) { errorMessage = _("No gameservers are available."); delete_all(mCharacters); mCharacters.clear(); - state = STATE_ERROR; + Client::setState(STATE_ERROR); } } @@ -280,7 +279,7 @@ void CharHandler::requestCharacters() else { // The characters are already there, continue to character selection - state = STATE_CHAR_SELECT; + Client::setState(STATE_CHAR_SELECT); } } diff --git a/src/net/manaserv/chathandler.cpp b/src/net/manaserv/chathandler.cpp index d6da557d..a452281f 100644 --- a/src/net/manaserv/chathandler.cpp +++ b/src/net/manaserv/chathandler.cpp @@ -23,10 +23,9 @@ #include "being.h" #include "beingmanager.h" +#include "client.h" #include "channel.h" #include "channelmanager.h" -#include "game.h" -#include "main.h" #include "gui/chat.h" @@ -136,7 +135,7 @@ void ChatHandler::handleMessage(Net::MessageIn &msg) errorMessage = "Chatserver: Unknown error"; break; } - state = STATE_ERROR; + Client::setState(STATE_ERROR); } } break; diff --git a/src/net/manaserv/gamehandler.cpp b/src/net/manaserv/gamehandler.cpp index a7d979a1..dd6120ae 100644 --- a/src/net/manaserv/gamehandler.cpp +++ b/src/net/manaserv/gamehandler.cpp @@ -21,8 +21,8 @@ #include "net/manaserv/gamehandler.h" +#include "client.h" #include "localplayer.h" -#include "main.h" #include "net/manaserv/chathandler.h" #include "net/manaserv/connection.h" @@ -63,7 +63,7 @@ void GameHandler::handleMessage(Net::MessageIn &msg) \ if (!netToken.empty()) { - state = STATE_SWITCH_CHARACTER; + Client::setState(STATE_SWITCH_CHARACTER); } else { @@ -82,7 +82,7 @@ void GameHandler::handleMessage(Net::MessageIn &msg) errorMessage = "Gameserver: Unknown error"; break; } - state = STATE_ERROR; + Client::setState(STATE_ERROR); } } break; diff --git a/src/net/manaserv/generalhandler.cpp b/src/net/manaserv/generalhandler.cpp index 9f14fd38..171ca214 100644 --- a/src/net/manaserv/generalhandler.cpp +++ b/src/net/manaserv/generalhandler.cpp @@ -21,7 +21,7 @@ #include "net/manaserv/generalhandler.h" -#include "main.h" +#include "client.h" #include "gui/changeemaildialog.h" #include "gui/charselectdialog.h" @@ -147,11 +147,11 @@ void GeneralHandler::flushNetwork() { flush(); - if (state == STATE_SWITCH_CHARACTER && + if (Client::getState() == STATE_SWITCH_CHARACTER && Net::getLoginHandler()->isConnected()) { loginHandler->reconnect(); - state = STATE_GET_CHARACTERS; + Client::setState(STATE_GET_CHARACTERS); } } diff --git a/src/net/manaserv/loginhandler.cpp b/src/net/manaserv/loginhandler.cpp index a8395204..cbc8e510 100644 --- a/src/net/manaserv/loginhandler.cpp +++ b/src/net/manaserv/loginhandler.cpp @@ -21,7 +21,7 @@ #include "net/manaserv/loginhandler.h" -#include "main.h" +#include "client.h" #include "net/logindata.h" @@ -75,7 +75,7 @@ void LoginHandler::handleMessage(Net::MessageIn &msg) // Successful login if (errMsg == ERRMSG_OK) { - state = STATE_CHAR_SELECT; + Client::setState(STATE_CHAR_SELECT); } // Login failed else @@ -95,7 +95,7 @@ void LoginHandler::handleMessage(Net::MessageIn &msg) errorMessage = _("Unknown error."); break; } - state = STATE_ERROR; + Client::setState(STATE_ERROR); } } break; @@ -106,7 +106,7 @@ void LoginHandler::handleMessage(Net::MessageIn &msg) // Successful pass change if (errMsg == ERRMSG_OK) { - state = STATE_CHANGEPASSWORD_SUCCESS; + Client::setState(STATE_CHANGEPASSWORD_SUCCESS); } // pass change failed else @@ -126,7 +126,7 @@ void LoginHandler::handleMessage(Net::MessageIn &msg) errorMessage = _("Unknown error."); break; } - state = STATE_ACCOUNTCHANGE_ERROR; + Client::setState(STATE_ACCOUNTCHANGE_ERROR); } } break; @@ -137,7 +137,7 @@ void LoginHandler::handleMessage(Net::MessageIn &msg) // Successful pass change if (errMsg == ERRMSG_OK) { - state = STATE_CHANGEEMAIL_SUCCESS; + Client::setState(STATE_CHANGEEMAIL_SUCCESS); } // pass change failed else @@ -160,7 +160,7 @@ void LoginHandler::handleMessage(Net::MessageIn &msg) errorMessage = _("Unknown error."); break; } - state = STATE_ACCOUNTCHANGE_ERROR; + Client::setState(STATE_ACCOUNTCHANGE_ERROR); } } break; @@ -185,7 +185,7 @@ void LoginHandler::handleMessage(Net::MessageIn &msg) errorMessage = "Accountserver: Unknown error"; break; } - state = STATE_ERROR; + Client::setState(STATE_ERROR); } } break; @@ -195,7 +195,7 @@ void LoginHandler::handleMessage(Net::MessageIn &msg) // Successful unregistration if (errMsg == ERRMSG_OK) { - state = STATE_UNREGISTER; + Client::setState(STATE_UNREGISTER); } // Unregistration failed else @@ -210,7 +210,7 @@ void LoginHandler::handleMessage(Net::MessageIn &msg) errorMessage = "Accountserver: Unknown error"; break; } - state = STATE_ACCOUNTCHANGE_ERROR; + Client::setState(STATE_ACCOUNTCHANGE_ERROR); } } break; @@ -228,7 +228,7 @@ void LoginHandler::handleMessage(Net::MessageIn &msg) printf("%s: %s\n", captchaURL.c_str(), captchaInstructions.c_str()); - state = STATE_REGISTER; + Client::setState(STATE_REGISTER); } else { @@ -237,7 +237,7 @@ void LoginHandler::handleMessage(Net::MessageIn &msg) if (errorMessage.empty()) errorMessage = _("Client registration is not allowed. " "Please contact server administration."); - state = STATE_LOGIN_ERROR; + Client::setState(STATE_LOGIN_ERROR); } } break; @@ -252,7 +252,7 @@ void LoginHandler::handleLoginResponse(Net::MessageIn &msg) { readUpdateHost(msg); // No worlds atm, but future use :-D - state = STATE_WORLD_SELECT; + Client::setState(STATE_WORLD_SELECT); } else { @@ -278,7 +278,7 @@ void LoginHandler::handleLoginResponse(Net::MessageIn &msg) errorMessage = _("Unknown error."); break; } - state = STATE_LOGIN_ERROR; + Client::setState(STATE_LOGIN_ERROR); } } @@ -289,7 +289,7 @@ void LoginHandler::handleRegisterResponse(Net::MessageIn &msg) if (errMsg == ERRMSG_OK) { readUpdateHost(msg); - state = STATE_WORLD_SELECT; + Client::setState(STATE_WORLD_SELECT); } else { @@ -315,7 +315,7 @@ void LoginHandler::handleRegisterResponse(Net::MessageIn &msg) errorMessage = _("Unknown error."); break; } - state = STATE_LOGIN_ERROR; + Client::setState(STATE_LOGIN_ERROR); } } @@ -342,9 +342,9 @@ void LoginHandler::disconnect() { accountServerConnection->disconnect(); - if (state == STATE_CONNECT_GAME) + if (Client::getState() == STATE_CONNECT_GAME) { - state = STATE_GAME; + Client::setState(STATE_GAME); } } diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp index a78afa8a..3a5d68a2 100644 --- a/src/net/manaserv/playerhandler.cpp +++ b/src/net/manaserv/playerhandler.cpp @@ -22,6 +22,7 @@ #include "net/manaserv/playerhandler.h" #include "net/manaserv/beinghandler.h" +#include "client.h" #include "effectmanager.h" #include "game.h" #include "localplayer.h" @@ -41,9 +42,6 @@ #include "net/manaserv/messageout.h" #include "net/manaserv/protocol.h" -/** @see in game.cpp */ -extern const int MILLISECONDS_IN_A_TICK; - /** * Max. distance we are willing to scroll after a teleport; * everything beyond will reset the port hard. |