diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index ed59b981..5aa343cd 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -64,6 +64,12 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM getMissingTilesetFromFTPServerInProgress = false; getMissingTechtreeFromFTPServer = ""; getMissingTechtreeFromFTPServerInProgress = false; + lastCheckedCRCTilesetName = ""; + lastCheckedCRCTechtreeName = ""; + lastCheckedCRCMapName = ""; + lastCheckedCRCTilesetValue = -1; + lastCheckedCRCTechtreeValue = -1; + lastCheckedCRCMapValue = -1; currentFactionLogo = ""; factionTexture=NULL; @@ -971,24 +977,48 @@ void MenuStateConnectedGame::update() { label = label + ", " + clientInterface->getVersionString(); - if(clientInterface->getAllowGameDataSynchCheck() == false) { + const GameSettings *gameSettings = clientInterface->getGameSettings(); + if(clientInterface->getAllowGameDataSynchCheck() == false && + gameSettings->getTileset() != "" && + gameSettings->getTech() != "" && + gameSettings->getMap() != "") { Config &config = Config::getInstance(); + MutexSafeWrapper safeMutexFTPProgress(ftpClientThread != NULL ? ftpClientThread->getProgressMutex() : NULL,string(__FILE__) + "_" + intToStr(__LINE__)); - const GameSettings *gameSettings = clientInterface->getGameSettings(); - int32 tilesetCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTilesets,""), string("/") + gameSettings->getTileset() + string("/*"), ".xml", NULL); - // Test data synch - //tilesetCRC++; - int32 techCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), string("/") + gameSettings->getTech() + string("/*"), ".xml", NULL); - // Test data synch - //techCRC++; + int32 tilesetCRC = lastCheckedCRCTilesetValue; + if(lastCheckedCRCTilesetName != gameSettings->getTileset()) { + console.addLine("Checking tileset CRC " + gameSettings->getTileset() + "]"); + tilesetCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTilesets,""), string("/") + gameSettings->getTileset() + string("/*"), ".xml", NULL); + // Test data synch + //tilesetCRC++; + lastCheckedCRCTilesetValue = tilesetCRC; + lastCheckedCRCTilesetName = gameSettings->getTileset(); + } - Checksum checksum; - string file = Map::getMapPath(gameSettings->getMap(),"",false); - checksum.addFile(file); - int32 mapCRC = checksum.getSum(); - // Test data synch - //mapCRC++; + int32 techCRC = lastCheckedCRCTechtreeValue; + if(lastCheckedCRCTechtreeName != gameSettings->getTech()) { + console.addLine("Checking techtree CRC " + gameSettings->getTech() + "]"); + techCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), string("/") + gameSettings->getTech() + string("/*"), ".xml", NULL); + // Test data synch + //techCRC++; + lastCheckedCRCTechtreeValue = techCRC; + lastCheckedCRCTechtreeName = gameSettings->getTech(); + } + + int32 mapCRC = lastCheckedCRCMapValue; + if(lastCheckedCRCMapName != gameSettings->getMap()) { + Checksum checksum; + string file = Map::getMapPath(gameSettings->getMap(),"",false); + console.addLine("Checking map CRC " + file + "]"); + checksum.addFile(file); + mapCRC = checksum.getSum(); + // Test data synch + //mapCRC++; + + lastCheckedCRCMapValue = mapCRC; + lastCheckedCRCMapName = gameSettings->getMap(); + } safeMutexFTPProgress.ReleaseLock(); bool dataSynchMismatch = ((mapCRC != 0 && mapCRC != gameSettings->getMapCRC()) || @@ -2025,6 +2055,7 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName, FTP_Client // Clear the CRC file Cache Checksum::clearFileCache(); + lastCheckedCRCMapValue = -1; NetworkManager &networkManager= NetworkManager::getInstance(); ClientInterface* clientInterface= networkManager.getClientInterface(); @@ -2090,7 +2121,7 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName, FTP_Client // Refresh CRC Config &config = Config::getInstance(); - int32 tilesetCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTilesets,""), string("/") + gameSettings->getTileset() + string("/*"), ".xml", NULL); + lastCheckedCRCTilesetValue = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTilesets,""), string("/") + gameSettings->getTileset() + string("/*"), ".xml", NULL); safeMutexFTPProgress.ReleaseLock(); // END @@ -2148,7 +2179,7 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName, FTP_Client // Refresh CRC Config &config = Config::getInstance(); - int32 techCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), string("/") + gameSettings->getTech() + string("/*"), ".xml", NULL); + lastCheckedCRCTechtreeValue = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), string("/") + gameSettings->getTech() + string("/*"), ".xml", NULL); safeMutexFTPProgress.ReleaseLock(); // END diff --git a/source/glest_game/menu/menu_state_connected_game.h b/source/glest_game/menu/menu_state_connected_game.h index 67228464..341caef6 100644 --- a/source/glest_game/menu/menu_state_connected_game.h +++ b/source/glest_game/menu/menu_state_connected_game.h @@ -158,6 +158,13 @@ private: string getMissingTechtreeFromFTPServer; bool getMissingTechtreeFromFTPServerInProgress; + string lastCheckedCRCTilesetName; + string lastCheckedCRCTechtreeName; + string lastCheckedCRCMapName; + int32 lastCheckedCRCTilesetValue; + int32 lastCheckedCRCTechtreeValue; + int32 lastCheckedCRCMapValue; + std::map > fileFTPProgressList; public: diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index ba85c545..c842d1ed 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -65,6 +65,13 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b needToPublishDelayed=false; mapPublishingDelayTimer=time(NULL); + lastCheckedCRCTilesetName = ""; + lastCheckedCRCTechtreeName = ""; + lastCheckedCRCMapName = ""; + lastCheckedCRCTilesetValue = -1; + lastCheckedCRCTechtreeValue = -1; + lastCheckedCRCMapValue = -1; + publishToMasterserverThread = NULL; Lang &lang= Lang::getInstance(); NetworkManager &networkManager= NetworkManager::getInstance(); @@ -2221,19 +2228,37 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) { gameSettings->setNetworkFramePeriod(config.getInt("NetworkSendFrameCount","20")); gameSettings->setNetworkPauseGameForLaggedClients(((listBoxNetworkPauseGameForLaggedClients.getSelectedItemIndex() != 0))); - int32 tilesetCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTilesets,""), string("/") + gameSettings->getTileset() + string("/*"), ".xml", NULL); - gameSettings->setTilesetCRC(tilesetCRC); + if( gameSettings->getTileset() != "") { + if(lastCheckedCRCTilesetName != gameSettings->getTileset()) { + console.addLine("Checking tileset CRC " + gameSettings->getTileset() + "]"); + lastCheckedCRCTilesetValue = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTilesets,""), string("/") + gameSettings->getTileset() + string("/*"), ".xml", NULL); + lastCheckedCRCTilesetName = gameSettings->getTileset(); + } + gameSettings->setTilesetCRC(lastCheckedCRCTilesetValue); + } if(config.getBool("DisableServerLobbyTechtreeCRCCheck","false") == false) { - int32 techCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), "/" + gameSettings->getTech() + "/*", ".xml", NULL); - gameSettings->setTechCRC(techCRC); + if(gameSettings->getTech() != "") { + if(lastCheckedCRCTechtreeName != gameSettings->getTech()) { + console.addLine("Checking techtree CRC " + gameSettings->getTech() + "]"); + lastCheckedCRCTechtreeValue = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), "/" + gameSettings->getTech() + "/*", ".xml", NULL); + lastCheckedCRCTechtreeName = gameSettings->getTech(); + } + gameSettings->setTechCRC(lastCheckedCRCTechtreeValue); + } } - Checksum checksum; - string file = Map::getMapPath(gameSettings->getMap(),"",false); - checksum.addFile(file); - int32 mapCRC = checksum.getSum(); - gameSettings->setMapCRC(mapCRC); + if(gameSettings->getMap() != "") { + if(lastCheckedCRCMapName != gameSettings->getMap()) { + Checksum checksum; + string file = Map::getMapPath(gameSettings->getMap(),"",false); + console.addLine("Checking map CRC " + file + "]"); + checksum.addFile(file); + lastCheckedCRCMapValue = checksum.getSum(); + lastCheckedCRCMapName = gameSettings->getMap(); + } + gameSettings->setMapCRC(lastCheckedCRCMapValue); + } SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); } diff --git a/source/glest_game/menu/menu_state_custom_game.h b/source/glest_game/menu/menu_state_custom_game.h index af7ead66..c4cc2d18 100644 --- a/source/glest_game/menu/menu_state_custom_game.h +++ b/source/glest_game/menu/menu_state_custom_game.h @@ -148,6 +148,13 @@ private: float rMultiplierOffset; bool hasCheckedForUPNP; + string lastCheckedCRCTilesetName; + string lastCheckedCRCTechtreeName; + string lastCheckedCRCMapName; + int32 lastCheckedCRCTilesetValue; + int32 lastCheckedCRCTechtreeValue; + int32 lastCheckedCRCMapValue; + public: MenuStateCustomGame(Program *program, MainMenu *mainMenu ,bool openNetworkSlots= false, bool parentMenuIsMasterserver=false, bool autostart=false); virtual ~MenuStateCustomGame(); diff --git a/source/glest_game/menu/menu_state_join_game.cpp b/source/glest_game/menu/menu_state_join_game.cpp index 2167b554..9d2b3940 100644 --- a/source/glest_game/menu/menu_state_join_game.cpp +++ b/source/glest_game/menu/menu_state_join_game.cpp @@ -557,10 +557,11 @@ void MenuStateJoinGame::connectToServer() { for(time_t elapsedWait = time(NULL); clientInterface->getIntroDone() == false && clientInterface->isConnected() && - difftime(time(NULL),elapsedWait) <= 3;) { + difftime(time(NULL),elapsedWait) <= 5;) { if(clientInterface->isConnected()) { //update lobby clientInterface->updateLobby(); + sleep(0); } } if( clientInterface->isConnected() == true && diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp index e22704ba..888e6390 100644 --- a/source/shared_lib/sources/platform/common/platform_common.cpp +++ b/source/shared_lib/sources/platform/common/platform_common.cpp @@ -575,6 +575,7 @@ void clearFolderTreeContentsCheckSum(vector paths, string pathSearchStri //finds all filenames like path and gets their checksum of all files combined int32 getFolderTreeContentsCheckSumRecursively(vector paths, string pathSearchString, const string filterFileExt, Checksum *recursiveChecksum) { //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n-------------- In [%s::%s Line: %d] Calculating CRC for [%s] -----------\n",__FILE__,__FUNCTION__,__LINE__,pathSearchString.c_str()); std::pair cacheKeys = getFolderTreeContentsCheckSumCacheKey(paths, pathSearchString, filterFileExt); string cacheLookupId = cacheKeys.first;