diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 620a94f0..4abc8123 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -44,7 +44,7 @@ static const int MAX_PING_LAG_COUNT = 6; static const double REPROMPT_DOWNLOAD_SECONDS = 7; //static const string ITEM_MISSING = "***missing***"; // above replaced with Lang::getInstance().getString("DataMissing","",true) -const int HEADLESSSERVER_BROADCAST_SETTINGS_SECONDS = 4; +const int HEADLESSSERVER_BROADCAST_SETTINGS_SECONDS = 2; static const char *HEADLESS_SAVED_GAME_FILENAME = "lastHeadlessGameSettings.mgg"; const int mapPreviewTexture_X = 5; @@ -81,6 +81,7 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM needToBroadcastServerSettings=false; broadcastServerSettingsDelayTimer=0; lastGameSettingsReceivedCount=0; + noReceiveTimer=time(NULL)-100; // old but inititialized ( must be an "old" time ) soundConnectionCount=0; @@ -132,6 +133,9 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM settingsReceivedFromServer=false; initialSettingsReceivedFromServer=false; + validOriginalGameSettings=false; + validDisplayedGamesettings=false; + returnMenuInfo=joinMenuInfo; Lang &lang= Lang::getInstance(); @@ -1531,6 +1535,7 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){ switchSetupRequestFlagType, lang.getLanguage()); switchSetupRequestFlagType= ssrft_None; + noReceiveTimer=time(NULL); } break; } @@ -1724,14 +1729,17 @@ void MenuStateConnectedGame::broadCastGameSettingsToHeadlessServer(bool forceNow } } - GameSettings gameSettings = *clientInterface->getGameSettings(); - loadGameSettings(&gameSettings); + if(validDisplayedGamesettings){ + loadGameSettings(&displayedGamesettings); - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("broadcast settings:\n%s\n",gameSettings.toString().c_str()); - //printf("Client sending map [%s] admin key [%d]\n",gameSettings.getMap().c_str(),gameSettings.getMasterserver_admin()); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("broadcast settings:\n%s\n",displayedGamesettings.toString().c_str()); - clientInterface->broadcastGameSetup(&gameSettings); + //printf("Client sending map [%s] admin key [%d]\n",gameSettings.getMap().c_str(),gameSettings.getMasterserver_admin()); + + clientInterface->broadcastGameSetup(&displayedGamesettings); + noReceiveTimer=time(NULL); + } } } @@ -2510,10 +2518,8 @@ void MenuStateConnectedGame::render() { delete factionVideo; factionVideo = NULL; - NetworkManager &networkManager= NetworkManager::getInstance(); - ClientInterface* clientInterface= networkManager.getClientInterface(); - if(clientInterface != NULL) { - initFactionPreview(clientInterface->getGameSettings()); + if(validDisplayedGamesettings) { + initFactionPreview(&displayedGamesettings); } } } @@ -2827,6 +2833,21 @@ void MenuStateConnectedGame::update() { //printf("#2 admin key [%d] client key [%d]\n",settings->getMasterserver_admin(),clientInterface->getSessionKey()); broadCastGameSettingsToHeadlessServer(false); + bool notCurrentlySwitching=(( difftime((long int) time(NULL), broadcastServerSettingsDelayTimer)) >= HEADLESSSERVER_BROADCAST_SETTINGS_SECONDS ); + bool receiveAllowedNow=difftime((long int) time(NULL), noReceiveTimer) > 2 ; + bool newMessage= lastGameSettingsReceivedCount < clientInterface->getGameSettingsReceivedCount(); + if (validDisplayedGamesettings == false + || ( notCurrentlySwitching + && newMessage + && receiveAllowedNow )) { + + //printf("I take the whole settings top broadcastDelay=%d noReceiveTimer=%d\n", (int)difftime((long int) time(NULL), broadcastServerSettingsDelayTimer),(int)difftime((long int) time(NULL), noReceiveTimer)); + + displayedGamesettings = *(clientInterface->getGameSettings()); + originalGamesettings = displayedGamesettings; + validDisplayedGamesettings = true; + } + checkBoxAllowNativeLanguageTechtree.setEditable(isHeadlessAdmin()); checkBoxAllowNativeLanguageTechtree.setEnabled(isHeadlessAdmin()); @@ -2874,7 +2895,7 @@ void MenuStateConnectedGame::update() { MutexSafeWrapper safeMutexFTPProgress((ftpClientThread != NULL ? ftpClientThread->getProgressMutex() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); if(fileFTPProgressList.empty() == true) { Lang &lang= Lang::getInstance(); - const vector languageList = clientInterface->getGameSettings()->getUniqueNetworkPlayerLanguages(); + const vector languageList = displayedGamesettings.getUniqueNetworkPlayerLanguages(); for(unsigned int i = 0; i < languageList.size(); ++i) { clientInterface->sendTextMessage(lang.getString("ConnectionTimedOut",languageList[i]) + " : " + doubleToStr(clientInterface->getLastPingLag(),2),-1,false,languageList[i]); sleep(1); @@ -2887,13 +2908,6 @@ void MenuStateConnectedGame::update() { pingCount++; if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } - } - - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); - if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); - - //update status label - if(clientInterface != NULL && clientInterface->isConnected()) { buttonDisconnect.setText(lang.getString("Disconnect")); if(clientInterface->getAllowDownloadDataSynch() == false) { @@ -2905,64 +2919,63 @@ void MenuStateConnectedGame::update() { label = label + ", " + clientInterface->getVersionString(); - const GameSettings *gameSettings = clientInterface->getGameSettings(); if(clientInterface->getAllowGameDataSynchCheck() == false && - gameSettings->getTileset() != "" && - gameSettings->getTech() != "" && - gameSettings->getMap() != "") { + displayedGamesettings.getTileset() != "" && + displayedGamesettings.getTech() != "" && + displayedGamesettings.getMap() != "") { Config &config = Config::getInstance(); MutexSafeWrapper safeMutexFTPProgress(ftpClientThread != NULL ? ftpClientThread->getProgressMutex() : NULL,string(__FILE__) + "_" + intToStr(__LINE__)); uint32 tilesetCRC = lastCheckedCRCTilesetValue; - if(lastCheckedCRCTilesetName != gameSettings->getTileset() && - gameSettings->getTileset() != "") { - //console.addLine("Checking tileset CRC [" + gameSettings->getTileset() + "]"); - tilesetCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTilesets,""), string("/") + gameSettings->getTileset() + string("/*"), ".xml", NULL); - if(tilesetCRC == 0 || tilesetCRC != gameSettings->getTilesetCRC()) { - tilesetCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTilesets,""), string("/") + gameSettings->getTileset() + string("/*"), ".xml", NULL, true); + if(lastCheckedCRCTilesetName != displayedGamesettings.getTileset() && + displayedGamesettings.getTileset() != "") { + //console.addLine("Checking tileset CRC [" + displayedGamesettings.getTileset() + "]"); + tilesetCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTilesets,""), string("/") + displayedGamesettings.getTileset() + string("/*"), ".xml", NULL); + if(tilesetCRC == 0 || tilesetCRC != displayedGamesettings.getTilesetCRC()) { + tilesetCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTilesets,""), string("/") + displayedGamesettings.getTileset() + string("/*"), ".xml", NULL, true); } // Test data synch //tilesetCRC++; lastCheckedCRCTilesetValue = tilesetCRC; - lastCheckedCRCTilesetName = gameSettings->getTileset(); + lastCheckedCRCTilesetName = displayedGamesettings.getTileset(); } uint32 techCRC = lastCheckedCRCTechtreeValue; - if(lastCheckedCRCTechtreeName != gameSettings->getTech() && - gameSettings->getTech() != "") { - //console.addLine("Checking techtree CRC [" + gameSettings->getTech() + "]"); - techCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), string("/") + gameSettings->getTech() + string("/*"), ".xml", NULL); - //clientInterface->sendTextMessage("#1 TechCRC = " + intToStr(techCRC) + " remoteCRC = " + intToStr(gameSettings->getTechCRC()),-1, true, ""); + if(lastCheckedCRCTechtreeName != displayedGamesettings.getTech() && + displayedGamesettings.getTech() != "") { + //console.addLine("Checking techtree CRC [" + displayedGamesettings.getTech() + "]"); + techCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), string("/") + displayedGamesettings.getTech() + string("/*"), ".xml", NULL); + //clientInterface->sendTextMessage("#1 TechCRC = " + intToStr(techCRC) + " remoteCRC = " + intToStr(displayedGamesettings.getTechCRC()),-1, true, ""); - if(techCRC == 0 || techCRC != gameSettings->getTechCRC()) { - techCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), string("/") + gameSettings->getTech() + string("/*"), ".xml", NULL, true); - //clientInterface->sendTextMessage("#2 TechCRC = " + intToStr(techCRC) + " remoteCRC = " + intToStr(gameSettings->getTechCRC()),-1, true, ""); + if(techCRC == 0 || techCRC != displayedGamesettings.getTechCRC()) { + techCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), string("/") + displayedGamesettings.getTech() + string("/*"), ".xml", NULL, true); + //clientInterface->sendTextMessage("#2 TechCRC = " + intToStr(techCRC) + " remoteCRC = " + intToStr(displayedGamesettings.getTechCRC()),-1, true, ""); } - if(techCRC != 0 && techCRC != gameSettings->getTechCRC() && + if(techCRC != 0 && techCRC != displayedGamesettings.getTechCRC() && listBoxTechTree.getSelectedItemIndex() >= 0 && listBoxTechTree.getSelectedItem() != Lang::getInstance().getString("DataMissing","",true)) { //time_t now = time(NULL); - time_t lastUpdateDate = getFolderTreeContentsCheckSumRecursivelyLastGenerated(config.getPathListForType(ptTechs,""), string("/") + gameSettings->getTech() + string("/*"), ".xml"); + time_t lastUpdateDate = getFolderTreeContentsCheckSumRecursivelyLastGenerated(config.getPathListForType(ptTechs,""), string("/") + displayedGamesettings.getTech() + string("/*"), ".xml"); const time_t REFRESH_CRC_DAY_SECONDS = 60 * 60 * 1; if( lastUpdateDate <= 0 || difftime((long int)time(NULL),lastUpdateDate) >= REFRESH_CRC_DAY_SECONDS) { - techCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), string("/") + gameSettings->getTech() + string("/*"), ".xml", NULL, true); - //clientInterface->sendTextMessage("#3 TechCRC = " + intToStr(techCRC) + " remoteCRC = " + intToStr(gameSettings->getTechCRC()),-1, true, ""); + techCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), string("/") + displayedGamesettings.getTech() + string("/*"), ".xml", NULL, true); + //clientInterface->sendTextMessage("#3 TechCRC = " + intToStr(techCRC) + " remoteCRC = " + intToStr(displayedGamesettings.getTechCRC()),-1, true, ""); } } // Test data synch //techCRC++; lastCheckedCRCTechtreeValue = techCRC; - lastCheckedCRCTechtreeName = gameSettings->getTech(); + lastCheckedCRCTechtreeName = displayedGamesettings.getTech(); - loadFactions(gameSettings,false); + loadFactions(&displayedGamesettings,false); factionCRCList.clear(); for(unsigned int factionIdx = 0; factionIdx < factionFiles.size(); ++factionIdx) { string factionName = factionFiles[factionIdx]; @@ -2972,28 +2985,28 @@ void MenuStateConnectedGame::update() { uint32 factionCRC = 0; //time_t now = time(NULL); - time_t lastUpdateDate = getFolderTreeContentsCheckSumRecursivelyLastGenerated(config.getPathListForType(ptTechs,""), "/" + gameSettings->getTech() + "/factions/" + factionName + "/*", ".xml"); + time_t lastUpdateDate = getFolderTreeContentsCheckSumRecursivelyLastGenerated(config.getPathListForType(ptTechs,""), "/" + displayedGamesettings.getTech() + "/factions/" + factionName + "/*", ".xml"); const time_t REFRESH_CRC_DAY_SECONDS = 60 * 60 * 24; if( lastUpdateDate <= 0 || difftime((long int)time(NULL),lastUpdateDate) >= REFRESH_CRC_DAY_SECONDS || - (techCRC != 0 && techCRC != gameSettings->getTechCRC())) { - factionCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), "/" + gameSettings->getTech() + "/factions/" + factionName + "/*", ".xml", NULL, true); + (techCRC != 0 && techCRC != displayedGamesettings.getTechCRC())) { + factionCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), "/" + displayedGamesettings.getTech() + "/factions/" + factionName + "/*", ".xml", NULL, true); } else { - factionCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), "/" + gameSettings->getTech() + "/factions/" + factionName + "/*", ".xml", NULL); + factionCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), "/" + displayedGamesettings.getTech() + "/factions/" + factionName + "/*", ".xml", NULL); } if(factionCRC == 0) { - factionCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), "/" + gameSettings->getTech() + "/factions/" + factionName + "/*", ".xml", NULL, true); + factionCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), "/" + displayedGamesettings.getTech() + "/factions/" + factionName + "/*", ".xml", NULL, true); } if(factionCRC != 0) { - vector > serverFactionCRCList = gameSettings->getFactionCRCList(); + vector > serverFactionCRCList = displayedGamesettings.getFactionCRCList(); for(unsigned int factionIdx1 = 0; factionIdx1 < serverFactionCRCList.size(); ++factionIdx1) { pair &serverFaction = serverFactionCRCList[factionIdx1]; if(serverFaction.first == factionName) { if(serverFaction.second != factionCRC) { - factionCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), "/" + gameSettings->getTech() + "/factions/" + factionName + "/*", ".xml", NULL, true); + factionCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), "/" + displayedGamesettings.getTech() + "/factions/" + factionName + "/*", ".xml", NULL, true); } break; } @@ -3006,10 +3019,10 @@ void MenuStateConnectedGame::update() { } uint32 mapCRC = lastCheckedCRCMapValue; - if(lastCheckedCRCMapName != gameSettings->getMap() && - gameSettings->getMap() != "") { + if(lastCheckedCRCMapName != displayedGamesettings.getMap() && + displayedGamesettings.getMap() != "") { Checksum checksum; - string file = Config::getMapPath(gameSettings->getMap(),"",false); + string file = Config::getMapPath(displayedGamesettings.getMap(),"",false); //console.addLine("Checking map CRC [" + file + "]"); checksum.addFile(file); mapCRC = checksum.getSum(); @@ -3017,22 +3030,23 @@ void MenuStateConnectedGame::update() { //mapCRC++; lastCheckedCRCMapValue = mapCRC; - lastCheckedCRCMapName = gameSettings->getMap(); + lastCheckedCRCMapName = displayedGamesettings.getMap(); } safeMutexFTPProgress.ReleaseLock(); - bool dataSynchMismatch = ((mapCRC != 0 && mapCRC != gameSettings->getMapCRC()) || - (tilesetCRC != 0 && tilesetCRC != gameSettings->getTilesetCRC()) || - (techCRC != 0 && techCRC != gameSettings->getTechCRC())); + bool dataSynchMismatch = ((mapCRC != 0 && mapCRC != displayedGamesettings.getMapCRC()) || + (tilesetCRC != 0 && tilesetCRC != displayedGamesettings.getTilesetCRC()) || + (techCRC != 0 && techCRC != displayedGamesettings.getTechCRC())); - //if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\nmapCRC [%d] gameSettings->getMapCRC() [%d]\ntilesetCRC [%d] gameSettings->getTilesetCRC() [%d]\ntechCRC [%d] gameSettings->getTechCRC() [%d]\n",mapCRC,gameSettings->getMapCRC(),tilesetCRC,gameSettings->getTilesetCRC(),techCRC,gameSettings->getTechCRC()); + //if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\nmapCRC [%d] displayedGamesettings.getMapCRC() [%d]\ntilesetCRC [%d] displayedGamesettings.getTilesetCRC() [%d]\ntechCRC [%d] displayedGamesettings.getTechCRC() [%d]\n",mapCRC,displayedGamesettings.getMapCRC(),tilesetCRC,displayedGamesettings.getTilesetCRC(),techCRC,displayedGamesettings.getTechCRC()); - if(dataSynchMismatch == true) { - //printf("Data not synched: lmap %u rmap: %u ltile: %d rtile: %u ltech: %u rtech: %u\n",mapCRC,gameSettings->getMapCRC(),tilesetCRC,gameSettings->getTilesetCRC(),techCRC,gameSettings->getTechCRC()); + if(dataSynchMismatch == true && + ( difftime((long int)time(NULL),broadcastServerSettingsDelayTimer) >= HEADLESSSERVER_BROADCAST_SETTINGS_SECONDS)) { + //printf("Data not synched: lmap %u rmap: %u ltile: %d rtile: %u ltech: %u rtech: %u\n",mapCRC,displayedGamesettings.getMapCRC(),tilesetCRC,displayedGamesettings.getTilesetCRC(),techCRC,displayedGamesettings.getTechCRC()); string labelSynch = lang.getString("DataNotSynchedTitle"); - if(mapCRC != 0 && mapCRC != gameSettings->getMapCRC() && + if(mapCRC != 0 && mapCRC != displayedGamesettings.getMapCRC() && listBoxMap.getSelectedItemIndex() >= 0 && listBoxMap.getSelectedItem() != Lang::getInstance().getString("DataMissing","",true)) { labelSynch = labelSynch + " " + lang.getString("Map"); @@ -3051,7 +3065,7 @@ void MenuStateConnectedGame::update() { } } - if(tilesetCRC != 0 && tilesetCRC != gameSettings->getTilesetCRC() && + if(tilesetCRC != 0 && tilesetCRC != displayedGamesettings.getTilesetCRC() && listBoxTileset.getSelectedItemIndex() >= 0 && listBoxTileset.getSelectedItem() != Lang::getInstance().getString("DataMissing","",true)) { labelSynch = labelSynch + " " + lang.getString("Tileset"); @@ -3069,7 +3083,7 @@ void MenuStateConnectedGame::update() { } } - if(techCRC != 0 && techCRC != gameSettings->getTechCRC() && + if(techCRC != 0 && techCRC != displayedGamesettings.getTechCRC() && listBoxTechTree.getSelectedItemIndex() >= 0 && listBoxTechTree.getSelectedItem() != Lang::getInstance().getString("DataMissing","",true)) { labelSynch = labelSynch + " " + lang.getString("TechTree"); @@ -3092,7 +3106,7 @@ void MenuStateConnectedGame::update() { string mismatchedFactionText = ""; vector mismatchedFactionTextList; - vector > serverFactionCRCList = gameSettings->getFactionCRCList(); + vector > serverFactionCRCList = displayedGamesettings.getFactionCRCList(); for(unsigned int factionIdx = 0; factionIdx < serverFactionCRCList.size(); ++factionIdx) { pair &serverFaction = serverFactionCRCList[factionIdx]; @@ -3332,18 +3346,67 @@ void MenuStateConnectedGame::update() { if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); try { - if(clientInterface->getGameSettingsReceived() && + if(clientInterface->getGameSettingsReceived() && validDisplayedGamesettings && lastGameSettingsReceivedCount != clientInterface->getGameSettingsReceivedCount()) { - broadCastGameSettingsToHeadlessServer(needToBroadcastServerSettings); - lastGameSettingsReceivedCount = clientInterface->getGameSettingsReceivedCount(); bool errorOnMissingData = (clientInterface->getAllowGameDataSynchCheck() == false); - GameSettings *gameSettings = clientInterface->getGameSettingsPtr(); - //printf("Menu got new settings thisfactionindex = %d startlocation: %d control = %d\n",gameSettings->getThisFactionIndex(),clientInterface->getGameSettings()->getStartLocationIndex(clientInterface->getGameSettings()->getThisFactionIndex()),gameSettings->getFactionControl(clientInterface->getGameSettings()->getThisFactionIndex())); - if ( difftime((long int)time(NULL),broadcastServerSettingsDelayTimer) >= HEADLESSSERVER_BROADCAST_SETTINGS_SECONDS){ - setupUIFromGameSettings(gameSettings, errorOnMissingData); + const GameSettings *receivedGameSettings= clientInterface->getGameSettings(); + + //printf("Menu got new settings thisfactionindex = %d startlocation: %d control = %d\n",displayedGamesettings.getThisFactionIndex(),clientInterface->getGameSettings()->getStartLocationIndex(clientInterface->getGameSettings()->getThisFactionIndex()),displayedGamesettings.getFactionControl(clientInterface->getGameSettings()->getThisFactionIndex())); + if ( difftime((long int)time(NULL),noReceiveTimer) < 3 || difftime((long int)time(NULL),broadcastServerSettingsDelayTimer) < HEADLESSSERVER_BROADCAST_SETTINGS_SECONDS){ + // copy my current settings in UI to displayedSettings; + loadGameSettings(&displayedGamesettings); + // check if there are any changed fields from others clients + if(isHeadlessAdmin()){ + //printf("I am headless admin and will restore only some parts\n"); + // only copy those parts which are editable by normal clients + for (int i=0;igetFactionCount();i++){ + if(displayedGamesettings.getFactionControl(i)==ctNetwork){ + if(originalGamesettings.getTeam(i)==displayedGamesettings.getTeam(i)){ + displayedGamesettings.setTeam(i,receivedGameSettings->getTeam(i)); + originalGamesettings.setTeam(i,receivedGameSettings->getTeam(i)); + } + if(originalGamesettings.getFactionTypeName(i)==displayedGamesettings.getFactionTypeName(i)){ + displayedGamesettings.setFactionTypeName(i,receivedGameSettings->getFactionTypeName(i)); + originalGamesettings.setFactionTypeName(i,receivedGameSettings->getFactionTypeName(i)); + } + displayedGamesettings.setNetworkPlayerGameStatus(i,receivedGameSettings->getNetworkPlayerGameStatus(i)); + originalGamesettings.setNetworkPlayerGameStatus(i,receivedGameSettings->getNetworkPlayerGameStatus(i)); + displayedGamesettings.setNetworkPlayerName(i,receivedGameSettings->getNetworkPlayerName(i)); + originalGamesettings.setNetworkPlayerName(i,receivedGameSettings->getNetworkPlayerName(i)); + } + } + } + else{ + //printf("I am client and restore everything but not my line\n"); + // copy all received fields just not those which are editable for normal client + //store my changes + int i=clientInterface->getPlayerIndex(); + int team=displayedGamesettings.getTeam(i); + string faction=displayedGamesettings.getFactionTypeName(i); + int status=displayedGamesettings.getNetworkPlayerGameStatus(i); + string networkPlayerName=displayedGamesettings.getNetworkPlayerName(i); + displayedGamesettings=*receivedGameSettings; + originalGamesettings=*receivedGameSettings; + + displayedGamesettings.setTeam(i,team); + originalGamesettings.setTeam(i,team); + displayedGamesettings.setFactionTypeName(i,faction); + originalGamesettings.setFactionTypeName(i,faction); + displayedGamesettings.setNetworkPlayerGameStatus(i,status); + originalGamesettings.setNetworkPlayerGameStatus(i,status); + displayedGamesettings.setNetworkPlayerName(i,networkPlayerName); + originalGamesettings.setNetworkPlayerName(i,networkPlayerName); + + } + setupUIFromGameSettings(&displayedGamesettings, errorOnMissingData); } + else { + // do nothing + setupUIFromGameSettings(&displayedGamesettings, errorOnMissingData); + } + broadCastGameSettingsToHeadlessServer(needToBroadcastServerSettings); } // check if we are joining an in progress game @@ -3490,12 +3553,11 @@ void MenuStateConnectedGame::update() { // check for need to switch music on again if(clientInterface != NULL) { - GameSettings *gameSettings = clientInterface->getGameSettingsPtr(); int currentConnectionCount=0; for(int i=0; i < GameConstants::maxPlayers; ++i) { - if(gameSettings->getFactionControl(i)==ctNetwork && - gameSettings->getNetworkPlayerName(i) != "" && - gameSettings->getNetworkPlayerName(i) != GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME) + if(displayedGamesettings.getFactionControl(i)==ctNetwork && + displayedGamesettings.getNetworkPlayerName(i) != "" && + displayedGamesettings.getNetworkPlayerName(i) != GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME) { currentConnectionCount++; } @@ -3828,13 +3890,14 @@ bool MenuStateConnectedGame::loadMapInfo(string file, MapInfo *mapInfo, bool loa Lang &lang= Lang::getInstance(); if(MapPreview::loadMapInfo(file, mapInfo, lang.getString("MaxPlayers"),lang.getString("Size"),true) == true) { for(int i = 0; i < GameConstants::maxPlayers; ++i) { - labelPlayers[i].setVisible(i+1 <= mapInfo->players); - labelPlayerNames[i].setVisible(i+1 <= mapInfo->players); - listBoxControls[i].setVisible(i+1 <= mapInfo->players); - listBoxRMultiplier[i].setVisible(i+1 <= mapInfo->players); - listBoxFactions[i].setVisible(i+1 <= mapInfo->players); - listBoxTeams[i].setVisible(i+1 <= mapInfo->players); - labelNetStatus[i].setVisible(i+1 <= mapInfo->players); + bool visible=i+1 <= mapInfo->players; + labelPlayers[i].setVisible(visible); + labelPlayerNames[i].setVisible(visible); + listBoxControls[i].setVisible(visible); + listBoxRMultiplier[i].setVisible(visible); + listBoxFactions[i].setVisible(visible); + listBoxTeams[i].setVisible(visible); + labelNetStatus[i].setVisible(visible); } // Not painting properly so this is on hold @@ -4401,6 +4464,7 @@ void MenuStateConnectedGame::setupUIFromGameSettings(GameSettings *gameSettings, throw megaglest_runtime_error("gameSettings == NULL"); } + checkBoxScenario.setValue((gameSettings->getScenario() != "")); if(checkBoxScenario.getValue() == true) { int originalFOWValue = listBoxFogOfWar.getSelectedItemIndex(); @@ -4441,8 +4505,8 @@ void MenuStateConnectedGame::setupUIFromGameSettings(GameSettings *gameSettings, //listBoxMap.setItems(formattedPlayerSortedMaps[gameSettings.getMapFilterIndex()]); //printf("A gameSettings->getTileset() [%s]\n",gameSettings->getTileset().c_str()); - if(getMissingTilesetFromFTPServerInProgress == false && - gameSettings->getTileset() != "") { + if ( getMissingTilesetFromFTPServerInProgress == false + && gameSettings->getTileset() != "") { // tileset tilesets = tilesetFiles; std::for_each(tilesets.begin(), tilesets.end(), FormatString()); @@ -4602,6 +4666,7 @@ void MenuStateConnectedGame::setupUIFromGameSettings(GameSettings *gameSettings, loadFactions(gameSettings,false); } + if(getMissingMapFromFTPServerInProgress == false && gameSettings->getMap() != "") { // map @@ -4714,6 +4779,8 @@ void MenuStateConnectedGame::setupUIFromGameSettings(GameSettings *gameSettings, checkBoxAllowTeamResourceSharing.setValue(false); } + checkBoxAllowNativeLanguageTechtree.setValue(gameSettings->getNetworkAllowNativeLanguageTechtree()); + // Control for(int i=0; igetFactionControl(i),errorOnMissingData); listBoxRMultiplier[slot].setSelectedItemIndex(gameSettings->getResourceMultiplierIndex(i),errorOnMissingData); - listBoxTeams[slot].setSelectedItemIndex(gameSettings->getTeam(i),errorOnMissingData); listBoxFactions[slot].setSelectedItem(formatString(gameSettings->getFactionTypeName(i)),false); + if( gameSettings->getFactionControl(i) == ctNetwork || gameSettings->getFactionControl(i) == ctNetworkUnassigned) { labelNetStatus[slot].setText(gameSettings->getNetworkPlayerName(i)); @@ -4821,13 +4888,12 @@ void MenuStateConnectedGame::setupUIFromGameSettings(GameSettings *gameSettings, labelPlayerNames[slot].setText(gameSettings->getNetworkPlayerName(i)); } } - - settingsReceivedFromServer=true; - initialSettingsReceivedFromServer=true; - - needToSetChangedGameSettings = true; - lastSetChangedGameSettings = time(NULL); } + settingsReceivedFromServer=true; + initialSettingsReceivedFromServer=true; + + needToSetChangedGameSettings = true; + lastSetChangedGameSettings = time(NULL); } if(enableFactionTexturePreview == true) { @@ -4845,7 +4911,6 @@ void MenuStateConnectedGame::setupUIFromGameSettings(GameSettings *gameSettings, } } - checkBoxAllowNativeLanguageTechtree.setValue(gameSettings->getNetworkAllowNativeLanguageTechtree()); } void MenuStateConnectedGame::initFactionPreview(const GameSettings *gameSettings) { @@ -4956,6 +5021,7 @@ void MenuStateConnectedGame::RestoreLastGameSettings() { needToBroadcastServerSettings=true; broadcastServerSettingsDelayTimer=time(NULL); + noReceiveTimer=time(NULL); } diff --git a/source/glest_game/menu/menu_state_connected_game.h b/source/glest_game/menu/menu_state_connected_game.h index d0fca6cc..f8a1380f 100644 --- a/source/glest_game/menu/menu_state_connected_game.h +++ b/source/glest_game/menu/menu_state_connected_game.h @@ -238,9 +238,17 @@ private: time_t broadcastServerSettingsDelayTimer; int lastGameSettingsReceivedCount; + time_t noReceiveTimer; + bool launchingNewGame; std::auto_ptr techTree; + GameSettings originalGamesettings; + bool validOriginalGameSettings; + GameSettings displayedGamesettings; + bool validDisplayedGamesettings; + + public: MenuStateConnectedGame(Program *program, MainMenu *mainMenu, JoinMenu joinMenuInfo=jmSimple, bool openNetworkSlots= false); diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 5a22c621..2a6abb10 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -172,6 +172,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, needToSetChangedGameSettings = false; needToRepublishToMasterserver = false; needToBroadcastServerSettings = false; + lastGameSettingsreceivedCount = -1; showMasterserverError = false; tMasterserverErrorElapsed = 0; masterServererErrorToShow = "---"; @@ -2439,7 +2440,8 @@ void MenuStateCustomGame::update() { if(this->autoloadScenarioName != "") { listBoxScenario.setSelectedItem(formatString(this->autoloadScenarioName),false); - + lastSetChangedGameSettings = time(NULL); + lastGameSettingsreceivedCount=serverInterface->getGameSettingsUpdateCount(); if(listBoxScenario.getSelectedItem() != formatString(this->autoloadScenarioName)) { mainMessageBoxState=1; showMessageBox( "Could not find scenario name: " + formatString(this->autoloadScenarioName), "Scenario Missing", false); @@ -2845,7 +2847,15 @@ void MenuStateCustomGame::update() { if(needToPublishDelayed == false || headlessServerMode == true) { bool broadCastSettings = (difftime((long int)time(NULL),lastSetChangedGameSettings) >= BROADCAST_SETTINGS_SECONDS); - //printf("broadCastSettings = %d\n",broadCastSettings); + if(headlessServerMode==true){ + // publish settings directly when we receive them + ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface(); + if(lastGameSettingsreceivedCountgetGameSettingsUpdateCount()){ + needToBroadcastServerSettings=true; + lastSetChangedGameSettings = time(NULL); + lastGameSettingsreceivedCount=serverInterface->getGameSettingsUpdateCount(); + } + } if(broadCastSettings == true) { needToBroadcastServerSettings=true; @@ -3342,7 +3352,7 @@ void MenuStateCustomGame::simpleTaskForClients(BaseThread *callingThread) { } ServerInterface *serverInterface= NetworkManager::getInstance().getServerInterface(false); if(serverInterface != NULL) { - + lastGameSettingsreceivedCount++; if(this->headlessServerMode == false || (serverInterface->getGameSettingsUpdateCount() <= lastMasterServerSettingsUpdateCount)) { GameSettings gameSettings; loadGameSettings(&gameSettings); diff --git a/source/glest_game/menu/menu_state_custom_game.h b/source/glest_game/menu/menu_state_custom_game.h index b2eb4264..54b6f4db 100644 --- a/source/glest_game/menu/menu_state_custom_game.h +++ b/source/glest_game/menu/menu_state_custom_game.h @@ -220,6 +220,8 @@ private: string gameUUID; + int lastGameSettingsreceivedCount; + public: MenuStateCustomGame(Program *program, MainMenu *mainMenu , bool openNetworkSlots= false, ParentMenuState parentMenuState=pNewGame,