diff options
Diffstat (limited to 'src/client.cpp')
-rw-r--r-- | src/client.cpp | 65 |
1 files changed, 48 insertions, 17 deletions
diff --git a/src/client.cpp b/src/client.cpp index 03fbc184..cab9e3da 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -22,6 +22,8 @@ #include "client.h" #include "main.h" +std::string errorMessage; + #include "chatlogger.h" #include "configuration.h" #include "emoteshortcut.h" @@ -90,7 +92,6 @@ #include <guichan/exception.hpp> // TODO: Get rid of these globals -std::string errorMessage; LoginData loginData; Config config; /**< Global settings (config.xml) */ @@ -166,7 +167,6 @@ void FpsManager::limitFps(int fpsLimit) mBaseTicks = ticks; } - Client *Client::mInstance = nullptr; Client::Client(const Options &options): @@ -384,6 +384,7 @@ Client::Client(const Options &options): if (mState != STATE_ERROR) { + logger->log("Processing state %d", mState); // Debug state transition // If a server was passed on the command line, or branding // provides a server and a blank server list, we skip the // server selection dialog. @@ -443,6 +444,12 @@ int Client::exec() while (mState != STATE_EXIT) { + if (mState < 0 || mState > STATE_FORCE_QUIT) { + logger->log("Invalid state detected: %d", mState); + errorMessage = "Invalid client state detected"; + mState = STATE_ERROR; + continue; + } // Handle SDL events SDL_Event event; while (SDL_PollEvent(&event)) @@ -457,7 +464,7 @@ int Client::exec() switch (event.window.event) { case SDL_WINDOWEVENT_SIZE_CHANGED: handleWindowSizeChanged(event.window.data1, - event.window.data2); + event.window.data2); break; } break; @@ -545,6 +552,19 @@ void Client::update() } // TODO: Add connect timeouts + static Uint32 connectStartTime = 0; + if (mState == STATE_CONNECT_SERVER || mState == STATE_LOGIN_ATTEMPT) { + if (connectStartTime == 0) { + connectStartTime = SDL_GetTicks(); + } else if (SDL_GetTicks() - connectStartTime > 15000) { // 15-second timeout + logger->log("Connection timeout in state %d", mState); + errorMessage = "Connection to server timed out"; + mState = STATE_ERROR; + connectStartTime = 0; + } + } else { + connectStartTime = 0; // Reset on state change + } if (mState == STATE_CONNECT_GAME && Net::getGameHandler()->isConnected()) { @@ -951,12 +971,23 @@ void Client::update() case STATE_EXIT: logger->log("State: EXIT"); + // Clean up network resources and downloads + Net::getLoginHandler()->disconnect(); + Net::getGameHandler()->disconnect(); + if (mCurrentDialog && dynamic_cast<UpdaterWindow*>(mCurrentDialog)) { + static_cast<UpdaterWindow*>(mCurrentDialog)->cancelDownloads(); + logger->log("Canceled active downloads during exit"); + } + if (mCurrentDialog) { + delete mCurrentDialog; + mCurrentDialog = nullptr; + } break; case STATE_FORCE_QUIT: logger->log("State: FORCE QUIT"); mState = STATE_EXIT; - break; + break; case STATE_ERROR: logger->log("State: ERROR"); @@ -1055,11 +1086,10 @@ void Client::initRootDir() } #endif } - -/** - * Initializes the home directory. On UNIX and FreeBSD, ~/.mana is used. On - * Windows and other systems we use the current working directory. - */ +-/** +- * Initializes the home directory. On UNIX and FreeBSD, ~/.mana is used. On +- * Windows and other systems we use the current working directory. +- */ void Client::initHomeDir() { mLocalDataDir = mOptions.localDataDir; @@ -1109,9 +1139,9 @@ void Client::initHomeDir() } } -/** - * Initialize configuration. - */ +-/** +- * Initialize configuration. +- */ void Client::initConfiguration() { // Fill configuration with defaults @@ -1126,10 +1156,11 @@ void Client::initConfiguration() logger->log("Couldn't read configuration file: %s", configPath.c_str()); } -/** - * Parse the update host and determine the updates directory - * Then verify that the directory exists (creating if needed). - */ +-/** +- * Parse the update host and determine the updates directory +- * Then verify that the directory exists (creating if needed). +- */ + bool Client::initUpdatesDir() { // Determine which source to use for the update host @@ -1286,4 +1317,4 @@ bool Client::hasInputFocus() bool Client::hasMouseFocus() { return SDL_GetWindowFlags(getVideo().window()) & SDL_WINDOW_MOUSE_FOCUS; -} +}
\ No newline at end of file |