From a3ec4650c4adec64b781d9a4fbf81f31912bfab7 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 16 Jul 2010 16:53:19 +0000 Subject: [PATCH] - moved pause for lagged clients option to custom game menu - bugfix to ignore 0.* ip addresses --- source/glest_game/game/game_settings.h | 5 ++ .../menu/menu_state_custom_game.cpp | 48 ++++++++++++++----- .../glest_game/menu/menu_state_custom_game.h | 3 ++ .../glest_game/network/server_interface.cpp | 13 ++--- .../sources/platform/posix/socket.cpp | 4 +- 5 files changed, 54 insertions(+), 19 deletions(-) diff --git a/source/glest_game/game/game_settings.h b/source/glest_game/game/game_settings.h index dbf36801..47ac085b 100644 --- a/source/glest_game/game/game_settings.h +++ b/source/glest_game/game/game_settings.h @@ -50,6 +50,7 @@ private: bool enableObserverModeAtEndGame; bool enableServerControlledAI; int networkFramePeriod; + bool networkPauseGameForLaggedClients; public: @@ -59,6 +60,7 @@ public: enableObserverModeAtEndGame = false; enableServerControlledAI = false; networkFramePeriod = GameConstants::networkFramePeriod; + networkPauseGameForLaggedClients = false; for(int i = 0; i < GameConstants::maxPlayers; ++i) { factionTypeNames[i] = ""; @@ -105,6 +107,7 @@ public: bool getEnableObserverModeAtEndGame() const {return enableObserverModeAtEndGame;} bool getEnableServerControlledAI() const {return enableServerControlledAI;} int getNetworkFramePeriod() const {return networkFramePeriod; } + bool getNetworkPauseGameForLaggedClients() const {return networkPauseGameForLaggedClients; } //set void setDescription(const string& description) {this->description= description;} @@ -130,6 +133,7 @@ public: void setEnableObserverModeAtEndGame(bool value) {this->enableObserverModeAtEndGame = value;} void setEnableServerControlledAI(bool value) {this->enableServerControlledAI = value;} void setNetworkFramePeriod(int value) {this->networkFramePeriod = value; } + void setNetworkPauseGameForLaggedClients(bool value) {this->networkPauseGameForLaggedClients = value; } string toString() const { string result = ""; @@ -160,6 +164,7 @@ public: result += "enableObserverModeAtEndGame = " + intToStr(enableObserverModeAtEndGame) + "\n"; result += "enableServerControlledAI = " + intToStr(enableServerControlledAI) + "\n"; result += "networkFramePeriod = " + intToStr(networkFramePeriod) + "\n"; + result += "networkPauseGameForLaggedClients = " + intToStr(networkPauseGameForLaggedClients) + "\n"; return result; } diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 7bf2de84..d248c929 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -226,6 +226,14 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b listBoxNetworkFramePeriod.pushBackItem("40"); listBoxNetworkFramePeriod.setSelectedItem("20"); + // Network Frame Period + labelNetworkPauseGameForLaggedClients.init(550, networkHeadPos, 80); + labelNetworkPauseGameForLaggedClients.setText(lang.get("NetworkPauseGameForLaggedClients")); + listBoxNetworkPauseGameForLaggedClients.init(560, networkPos, 80); + listBoxNetworkPauseGameForLaggedClients.pushBackItem(lang.get("No")); + listBoxNetworkPauseGameForLaggedClients.pushBackItem(lang.get("Yes")); + listBoxNetworkPauseGameForLaggedClients.setSelectedItem(lang.get("No")); + // Enable Server Controlled AI labelEnableServerControlledAI.init(690, networkHeadPos, 80); @@ -590,6 +598,10 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){ MutexSafeWrapper safeMutex(&masterServerThreadAccessor); soundRenderer.playFx(coreData.getClickSoundC()); } + else if(listBoxNetworkPauseGameForLaggedClients.mouseClick(x, y)){ + MutexSafeWrapper safeMutex(&masterServerThreadAccessor); + soundRenderer.playFx(coreData.getClickSoundC()); + } else { for(int i=0; igetSwitchSetupRequests(); @@ -856,20 +873,20 @@ void MenuStateCustomGame::update() { } } - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] mapInfo.players = %d\n",__FILE__,__FUNCTION__,__LINE__,mapInfo.players); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] mapInfo.players = %d\n",__FILE__,__FUNCTION__,__LINE__,mapInfo.players); for(int i= 0; igetSlot(i); assert(connectionSlot!=NULL); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); hasOneNetworkSlotOpen=true; @@ -961,7 +978,7 @@ void MenuStateCustomGame::update() { } } - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); bool checkDataSynch = (serverInterface->getAllowGameDataSynchCheck() == true && //haveAtLeastOneNetworkClientConnected == true && @@ -977,7 +994,7 @@ void MenuStateCustomGame::update() { needToSetChangedGameSettings = false; } - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); if(hasOneNetworkSlotOpen) { //listBoxPublishServer.setSelectedItemIndex(0); @@ -1035,7 +1052,7 @@ void MenuStateCustomGame::update() { } soundConnectionCount = currentConnectionCount; - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); } catch(const std::exception &ex) { char szBuf[1024]=""; @@ -1045,7 +1062,7 @@ void MenuStateCustomGame::update() { showGeneralError=true; generalErrorToShow = szBuf; } - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); } void MenuStateCustomGame::publishToMasterserver() @@ -1263,6 +1280,7 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) { gameSettings->setFactionCount(factionCount); gameSettings->setEnableServerControlledAI(listBoxEnableServerControlledAI.getSelectedItemIndex() == 0); gameSettings->setNetworkFramePeriod((listBoxNetworkFramePeriod.getSelectedItemIndex()+1)*10); + gameSettings->setNetworkPauseGameForLaggedClients((listBoxNetworkPauseGameForLaggedClients.getSelectedItemIndex())); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] gameSettings->getTileset() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getTileset().c_str()); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] gameSettings->getTech() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getTech().c_str()); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] gameSettings->getMap() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getMap().c_str()); @@ -1300,6 +1318,7 @@ void MenuStateCustomGame::saveGameSettingsToFile(std::string fileName) { saveGameFile << "EnableObserverModeAtEndGame=" << gameSettings.getEnableObserverModeAtEndGame() << std::endl; saveGameFile << "EnableServerControlledAI=" << gameSettings.getEnableServerControlledAI() << std::endl; saveGameFile << "NetworkFramePeriod=" << gameSettings.getNetworkFramePeriod() << std::endl; + saveGameFile << "NetworkPauseGameForLaggedClients=" << gameSettings.getNetworkPauseGameForLaggedClients() << std::endl; saveGameFile << "ExternalPortNumber=" << listBoxPublishServerExternalPort.getSelectedItem() << std::endl; saveGameFile << "FactionThisFactionIndex=" << gameSettings.getThisFactionIndex() << std::endl; @@ -1351,6 +1370,7 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName) gameSettings.setEnableObserverModeAtEndGame(properties.getBool("EnableObserverModeAtEndGame")); gameSettings.setEnableServerControlledAI(properties.getBool("EnableServerControlledAI","false")); gameSettings.setNetworkFramePeriod(properties.getInt("NetworkFramePeriod",intToStr(GameConstants::networkFramePeriod).c_str())/10*10); + gameSettings.setNetworkPauseGameForLaggedClients(properties.getBool("NetworkPauseGameForLaggedClients","false")); gameSettings.setThisFactionIndex(properties.getInt("FactionThisFactionIndex")); gameSettings.setFactionCount(properties.getInt("FactionCount")); @@ -1402,6 +1422,10 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + listBoxNetworkPauseGameForLaggedClients.setSelectedItemIndex(gameSettings.getNetworkPauseGameForLaggedClients()); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + reloadFactions(); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d] gameSettings.getFactionCount() = %d\n",__FILE__,__FUNCTION__,__LINE__,gameSettings.getFactionCount()); diff --git a/source/glest_game/menu/menu_state_custom_game.h b/source/glest_game/menu/menu_state_custom_game.h index 61c4bf23..7cc5dfec 100644 --- a/source/glest_game/menu/menu_state_custom_game.h +++ b/source/glest_game/menu/menu_state_custom_game.h @@ -69,6 +69,9 @@ private: GraphicListBox listBoxNetworkFramePeriod; GraphicLabel labelNetworkFramePeriod; + GraphicLabel labelNetworkPauseGameForLaggedClients; + GraphicListBox listBoxNetworkPauseGameForLaggedClients; + bool needToSetChangedGameSettings; time_t lastSetChangedGameSettings; diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index c7c0eaff..fb5ca25f 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -46,7 +46,7 @@ double maxClientLagTimeAllowed = 20; // 65% of max we warn all users about the lagged client double warnFrameCountLagPercent = 0.65; // Should we wait for lagged clients instead of disconnect them? -bool pauseGameForLaggedClients = false; +//bool pauseGameForLaggedClients = false; // Seconds grace period before we start checking LAG double LAG_CHECK_GRACE_PERIOD = 15; @@ -61,8 +61,9 @@ ServerInterface::ServerInterface(){ maxFrameCountLagAllowed = Config::getInstance().getInt("MaxFrameCountLagAllowed",intToStr(maxFrameCountLagAllowed).c_str()); maxClientLagTimeAllowed = Config::getInstance().getInt("MaxClientLagTimeAllowed",intToStr(maxClientLagTimeAllowed).c_str()); warnFrameCountLagPercent = Config::getInstance().getFloat("WarnFrameCountLagPercent",doubleToStr(warnFrameCountLagPercent).c_str()); - pauseGameForLaggedClients = Config::getInstance().getFloat("PauseGameForLaggedClients",boolToStr(pauseGameForLaggedClients).c_str()); - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] enabledThreadedClientCommandBroadcast = %d, maxFrameCountLagAllowed = %f, maxClientLagTimeAllowed = %f, pauseGameForLaggedClients = %d\n",__FILE__,__FUNCTION__,__LINE__,enabledThreadedClientCommandBroadcast,maxFrameCountLagAllowed,maxClientLagTimeAllowed,pauseGameForLaggedClients); + //pauseGameForLaggedClients = Config::getInstance().getFloat("PauseGameForLaggedClients",boolToStr(pauseGameForLaggedClients).c_str()); + //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] enabledThreadedClientCommandBroadcast = %d, maxFrameCountLagAllowed = %f, maxClientLagTimeAllowed = %f, pauseGameForLaggedClients = %d\n",__FILE__,__FUNCTION__,__LINE__,enabledThreadedClientCommandBroadcast,maxFrameCountLagAllowed,maxClientLagTimeAllowed,pauseGameForLaggedClients); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] enabledThreadedClientCommandBroadcast = %d, maxFrameCountLagAllowed = %f, maxClientLagTimeAllowed = %f\n",__FILE__,__FUNCTION__,__LINE__,enabledThreadedClientCommandBroadcast,maxFrameCountLagAllowed,maxClientLagTimeAllowed); for(int i= 0; iclose(); } } @@ -481,7 +482,7 @@ void ServerInterface::update() { // If the client has exceeded lag and the server wants // to pause while they catch up, re-trigger the // client reader thread - if(clientLagExceeded == true && pauseGameForLaggedClients == true) { + if(clientLagExceeded == true && gameSettings.getNetworkPauseGameForLaggedClients() == true) { bool socketTriggered = (connectionSlot != NULL && connectionSlot->getSocket() != NULL ? socketTriggeredList[connectionSlot->getSocket()->getSocketId()] : false); ConnectionSlotEvent &event = eventList[i]; signalClientReceiveCommands(connectionSlot,i,socketTriggered,event); diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index ee1e3e4f..2dc3724b 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -618,7 +618,9 @@ std::vector Socket::getLocalIPAddressList() { //printf("%s\n",myhostaddr); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] myhostaddr = [%s]\n",__FILE__,__FUNCTION__,__LINE__,myhostaddr); - if(strlen(myhostaddr) > 0 && strncmp(myhostaddr,"127.",4) != 0) { + if(strlen(myhostaddr) > 0 && + strncmp(myhostaddr,"127.",4) != 0 && + strncmp(myhostaddr,"0.",2) != 0) { ipList.push_back(myhostaddr); } ipIdx++;