From f84cf5c216867c709ee75a0ce4c53e3493eb9283 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sun, 26 May 2013 03:35:31 +0000 Subject: [PATCH] attempt to fix resume game --- .../menu/menu_state_connected_game.cpp | 28 ++++++++++++++---- .../glest_game/network/server_interface.cpp | 29 +++++++++++++++---- source/glest_game/network/server_interface.h | 2 ++ 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 89aded94..27b1c5ad 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -1178,8 +1178,7 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){ Lang &lang= Lang::getInstance(); string advanceToItemStartingWith = ""; - if(!mainMessageBox.getEnabled()) - { + if(mainMessageBox.getEnabled() == false) { if(Shared::Platform::Window::isKeyStateModPressed(KMOD_SHIFT) == true) { wchar_t lastKey = Shared::Platform::Window::extractLastKeyPressed(); //printf("lastKey = %d [%c]\n",lastKey,lastKey); @@ -1443,9 +1442,11 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){ return; } - if (initialSettingsReceivedFromServer == false) return; + if (initialSettingsReceivedFromServer == false) { + return; + } - if(activeInputLabel!=NULL && !(activeInputLabel->mouseClick(x,y))){ + if(activeInputLabel != NULL && activeInputLabel->mouseClick(x,y) == false){ setActiveInputLabel(NULL); } @@ -1608,8 +1609,21 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){ if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); - PlayNow(true); - return; + uint32 tilesetCRC = lastCheckedCRCTilesetValue; + uint32 techCRC = lastCheckedCRCTechtreeValue; + uint32 mapCRC = lastCheckedCRCMapValue; + const GameSettings *gameSettings = clientInterface->getGameSettings(); + + bool dataSynchMismatch = ((mapCRC != 0 && mapCRC != gameSettings->getMapCRC()) || + (tilesetCRC != 0 && tilesetCRC != gameSettings->getTilesetCRC()) || + (techCRC != 0 && techCRC != gameSettings->getTechCRC())); + if(dataSynchMismatch == false) { + PlayNow(true); + return; + } + else { + showMessageBox("You cannot start the game because\none or more clients do not have the same game data!", "Data Mismatch Error", false); + } } } } @@ -1891,11 +1905,13 @@ void MenuStateConnectedGame::PlayNow(bool saveGame) { clientInterface->sendTextMessage(szMsg,-1, localEcho,languageList[i]); } + launchingNewGame = true; clientInterface->broadcastGameStart(&gameSettings); } return; } else { + launchingNewGame = true; broadCastGameSettingsToHeadlessServer(needToBroadcastServerSettings); clientInterface->broadcastGameStart(&gameSettings); } diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index d22d0e58..5c95f431 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -71,6 +71,7 @@ ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() { gameSettingsUpdateCount = 0; currentFrameCount = 0; gameStartTime = 0; + resumeGameStartTime = 0; publishToMasterserverThread = NULL; lastMasterserverHeartbeatTime = 0; needToRepublishToMasterserver = false; @@ -633,8 +634,11 @@ std::pair ServerInterface::clientLagCheck(ConnectionSlot *connectionS try { alreadyInLagCheck = true; - if(gameStartTime > 0 && - difftime((long int)time(NULL),gameStartTime) >= LAG_CHECK_GRACE_PERIOD) { + if((gameStartTime > 0 && + difftime((long int)time(NULL),gameStartTime) >= LAG_CHECK_GRACE_PERIOD) && + (resumeGameStartTime == 0 || + (resumeGameStartTime > 0 && + difftime((long int)time(NULL),resumeGameStartTime) >= LAG_CHECK_GRACE_PERIOD))) { if(connectionSlot != NULL && connectionSlot->isConnected() == true) { double clientLag = this->getCurrentFrameCount() - connectionSlot->getCurrentFrameCount(); double clientLagCount = (gameSettings.getNetworkFramePeriod() > 0 ? (clientLag / gameSettings.getNetworkFramePeriod()) : 0); @@ -2958,17 +2962,32 @@ bool ServerInterface::getPauseForInGameConnection() { } bool ServerInterface::getUnPauseForInGameConnection() { + + bool allResumeClientsReady = false; bool result = false; for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) { if(slots[i] != NULL) { MutexSafeWrapper safeMutex(slotAccessorMutexes[i],CODE_AT_LINE_X(i)); ConnectionSlot *slot = slots[i]; - if(slot->getUnPauseForInGameConnection() == true) { - result = true; - break; + if(slot->isConnected() == true) { + if(slot->isReady() == true) { + result = true; + if(slot->getUnPauseForInGameConnection() == false) { + result = false; + break; + } + } + else { + result = false; + break; + } } } } + if(allResumeClientsReady == true) { + resumeGameStartTime = time(NULL); + result = true; + } return result; } diff --git a/source/glest_game/network/server_interface.h b/source/glest_game/network/server_interface.h index 12499485..bd373231 100644 --- a/source/glest_game/network/server_interface.h +++ b/source/glest_game/network/server_interface.h @@ -101,6 +101,8 @@ private: bool gameLaunched; time_t lastListenerSlotCheckTime; + time_t resumeGameStartTime; + public: ServerInterface(bool publishEnabled); virtual ~ServerInterface();