From c8cdca22fde89f17b6d130808d618b7f79761708 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 19 Feb 2013 22:00:15 +0000 Subject: [PATCH] - some code cleanup and try to improve joining in progress game performance --- source/glest_game/game/game.cpp | 71 ++++--- source/glest_game/network/connection_slot.cpp | 7 +- source/glest_game/network/connection_slot.h | 12 ++ .../glest_game/network/server_interface.cpp | 192 ++++++------------ source/glest_game/network/server_interface.h | 54 ++--- 5 files changed, 136 insertions(+), 200 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 0a2ce1a84..77ddce327 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -1949,18 +1949,27 @@ void Game::update() { //printf("#2 Data synch: lmap %u ltile: %d ltech: %u\n",server->gameSettings.getMapCRC(),server->gameSettings.getTilesetCRC(),server->gameSettings.getTechCRC()); server->broadcastGameSetup(&server->gameSettings,true); - server->setPauseForInGameConnection(false); + for(int i = 0; i < world.getFactionCount(); ++i) { + Faction *faction = world.getFaction(i); + ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex()); + if(slot != NULL && slot->getPauseForInGameConnection() == true) { + slot->setPauseForInGameConnection(false); + } + } } else if(server->getStartInGameConnectionLaunch() == true) { //printf("^^^ getStartInGameConnectionLaunch triggered!\n"); - server->setStartInGameConnectionLaunch(false); + //server->setStartInGameConnectionLaunch(false); Lang &lang= Lang::getInstance(); bool pauseAndSaveGameForNewClient = false; for(int i = 0; i < world.getFactionCount(); ++i) { Faction *faction = world.getFaction(i); ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex()); + if(slot != NULL && slot->getStartInGameConnectionLaunch() == true) { + slot->setStartInGameConnectionLaunch(false); + } if(slot != NULL && slot->getJoinGameInProgress() == true) { //printf("$$$ signalling client to start game [deleting AI player] factionIndex: %d slot: %d startlocation: %d!\n",i,slot->getPlayerIndex(),faction->getStartLocationIndex()); @@ -1996,47 +2005,47 @@ void Game::update() { else if(paused == true && pauseStateChanged == true) { pauseStateChanged = false; - //NetworkManager &networkManager= NetworkManager::getInstance(); - //NetworkRole role = networkManager.getNetworkRole(); + bool saveNetworkGame = false; - //if(role == nrServer) { - bool saveNetworkGame = false; + ServerInterface *server = NetworkManager::getInstance().getServerInterface(); + for(int i = 0; i < world.getFactionCount(); ++i) { + Faction *faction = world.getFaction(i); + ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex()); + if(slot != NULL && slot->getJoinGameInProgress() == true) { + saveNetworkGame = true; + break; + } + } + + if(saveNetworkGame == true) { + //printf("Saved network game to disk\n"); + + string file = this->saveGame(GameConstants::saveNetworkGameFileServer,"temp/"); + char szBuf[8096]=""; + Lang &lang= Lang::getInstance(); + snprintf(szBuf,8096,lang.get("GameSaved","",true).c_str(),file.c_str()); + console.addLine(szBuf); - ServerInterface *server = NetworkManager::getInstance().getServerInterface(); for(int i = 0; i < world.getFactionCount(); ++i) { Faction *faction = world.getFaction(i); ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex()); if(slot != NULL && slot->getJoinGameInProgress() == true) { - saveNetworkGame = true; - break; + NetworkMessageReady networkMessageReady(0); + slot->sendMessage(&networkMessageReady); } } - - if(saveNetworkGame == true) { - //printf("Saved network game to disk\n"); - - string file = this->saveGame(GameConstants::saveNetworkGameFileServer,"temp/"); - char szBuf[8096]=""; - Lang &lang= Lang::getInstance(); - snprintf(szBuf,8096,lang.get("GameSaved","",true).c_str(),file.c_str()); - console.addLine(szBuf); - - for(int i = 0; i < world.getFactionCount(); ++i) { - Faction *faction = world.getFaction(i); - ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex()); - if(slot != NULL && slot->getJoinGameInProgress() == true) { - - NetworkMessageReady networkMessageReady(0); - slot->sendMessage(&networkMessageReady); - } - } - } - //} + } } else if(server->getUnPauseForInGameConnection() == true && paused == true) { //printf("^^^ getUnPauseForInGameConnection triggered!\n"); - server->setUnPauseForInGameConnection(false); + for(int i = 0; i < world.getFactionCount(); ++i) { + Faction *faction = world.getFaction(i); + ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex()); + if(slot != NULL && slot->getUnPauseForInGameConnection() == true) { + slot->setUnPauseForInGameConnection(false); + } + } commander.tryResumeGame(false); //return; } diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index 9f26ff4be..72cbbbb4e 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -272,6 +272,7 @@ ConnectionSlot::ConnectionSlot(ServerInterface* serverInterface, int playerIndex this->lastReceiveCommandListTime = 0; this->receivedNetworkGameStatus = false; this->canAcceptConnections = true; + this->startInGameConnectionLaunch = false; this->skipLagCheck = false; this->joinGameInProgress = false; @@ -861,7 +862,7 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { //this->skipLagCheck = true; //this->joinGameInProgress = true; setJoinGameInProgressFlags(); - serverInterface->setPauseForInGameConnection(true); + this->setPauseForInGameConnection(true); //printf("Got intro from client sending game settings..\n"); } @@ -962,7 +963,7 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { this->serverInterface->gameSettings.setNetworkPlayerName(factionIndex,this->name); this->serverInterface->broadcastGameSetup(&this->serverInterface->gameSettings, true); - this->serverInterface->setStartInGameConnectionLaunch(true); + this->setStartInGameConnectionLaunch(true); } } } @@ -1241,7 +1242,7 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { } // unpause the game else { - serverInterface->setUnPauseForInGameConnection(true); + this->setUnPauseForInGameConnection(true); } break; } diff --git a/source/glest_game/network/connection_slot.h b/source/glest_game/network/connection_slot.h index f6ac87405..9cce8c801 100644 --- a/source/glest_game/network/connection_slot.h +++ b/source/glest_game/network/connection_slot.h @@ -141,11 +141,23 @@ private: string playerLanguage; bool canAcceptConnections; + bool startInGameConnectionLaunch; + bool pauseForInGameConnection; + bool unPauseForInGameConnection; public: ConnectionSlot(ServerInterface* serverInterface, int playerIndex); ~ConnectionSlot(); + bool getStartInGameConnectionLaunch() const { return startInGameConnectionLaunch; } + void setStartInGameConnectionLaunch(bool value) { startInGameConnectionLaunch = value; } + + bool getPauseForInGameConnection() const { return pauseForInGameConnection; } + void setPauseForInGameConnection(bool value) { pauseForInGameConnection = value; } + + bool getUnPauseForInGameConnection() const { return unPauseForInGameConnection; } + void setUnPauseForInGameConnection(bool value) { unPauseForInGameConnection = value; } + bool getSkipLagCheck() const { return skipLagCheck; } bool getJoinGameInProgress() const { return joinGameInProgress; } diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index 39772672a..610c64aeb 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -11,7 +11,6 @@ #include "server_interface.h" -//#include #include #include "platform_util.h" @@ -52,9 +51,7 @@ ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); allowInGameConnections = false; - pauseForInGameConnection = false; - unPauseForInGameConnection = false; - gameStarted = false; + gameLaunched = false; serverSynchAccessor = new Mutex(); switchSetupRequestsSynchAccessor = new Mutex(); @@ -81,7 +78,6 @@ ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() { inBroadcastMessage = false; lastGlobalLagCheckTime = 0; masterserverAdminRequestLaunch = false; - startInGameConnectionLaunch = false; // This is an admin port listening only on the localhost intended to // give current connection status info @@ -120,23 +116,6 @@ ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() { serverSocket.setBindPort(Config::getInstance().getInt("PortServer", intToStr(GameConstants::serverPort).c_str())); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); -/* - Config &config = Config::getInstance(); - vector results; - set allMaps; - findAll(config.getPathListForType(ptMaps), "*.gbm", results, true, false); - copy(results.begin(), results.end(), std::inserter(allMaps, allMaps.begin())); - results.clear(); - findAll(config.getPathListForType(ptMaps), "*.mgm", results, true, false); - copy(results.begin(), results.end(), std::inserter(allMaps, allMaps.begin())); - results.clear(); - if (allMaps.empty()) { - throw megaglest_runtime_error("No maps were found!"); - } - copy(allMaps.begin(), allMaps.end(), std::back_inserter(results)); - mapFiles = results; -*/ - Config &config = Config::getInstance(); vector results; string scenarioDir = ""; @@ -151,8 +130,6 @@ ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() { copy(allMaps.begin(), allMaps.end(), std::back_inserter(results)); mapFiles = results; - - //tileset listBox results.clear(); findDirs(config.getPathListForType(ptTilesets), results); if (results.empty()) { @@ -160,7 +137,6 @@ ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() { } tilesetFiles= results; - //tech Tree listBox results.clear(); findDirs(config.getPathListForType(ptTechs), results); if(results.empty()) { @@ -569,14 +545,9 @@ void ServerInterface::removeSlot(int playerIndex, int lockedSlotIndex) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex); if(notifyDisconnect == true) { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex); - //string sMsg = szBuf; - //sendTextMessage(sMsg,-1, true, lockedSlotIndex); - //const vector languageList = this->gameSettings.getUniqueNetworkPlayerLanguages(); for(unsigned int j = 0; j < languageList.size(); ++j) { bool localEcho = lang.isLanguageLocal(languageList[j]); queueTextMessage(msgList[j],-1, localEcho, languageList[j]); - - //printf("j = %d [%s] localEcho = %d [%s]\n",j,msgList[j].c_str(),localEcho,languageList[j].c_str()); } } if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex); @@ -641,86 +612,6 @@ int64 ServerInterface::getNextEventId() { return nextEventId; } -void ServerInterface::slotUpdateTask(ConnectionSlotEvent *event) { -// if(event != NULL) { -// if(event->eventType == eSendSocketData) { -// if(event->connectionSlot != NULL) { -// event->connectionSlot->sendMessage(event->networkMessage); -// } -// } -// else if(event->eventType == eReceiveSocketData) { -// //updateSlot(event); -// if(event->connectionSlot != NULL) { -// event->connectionSlot->updateSlot(event); -// } -// } -// else { -// if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); -// } -// } -} - -//void ServerInterface::updateSlot(ConnectionSlotEvent *event) { -// Chrono chrono; -// if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start(); -// -// if(event != NULL) { -// bool &socketTriggered = event->socketTriggered; -// bool checkForNewClients = true; -// -// // Safety check since we can experience a disconnect and the slot is NULL -// ConnectionSlot *connectionSlot = NULL; -// MutexSafeWrapper safeMutexSlot(NULL); -// if(event->triggerId >= 0 && event->triggerId < GameConstants::maxPlayers) { -// -// //printf("===> START slot %d [%d][%p] - About to updateSlot\n",event->triggerId,event->eventId,slots[event->triggerId]); -// -// safeMutexSlot.setMutex(slotAccessorMutexes[event->triggerId],CODE_AT_LINE_X(event->triggerId)); -// connectionSlot = slots[event->triggerId]; -// } -// else { -// if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR CONDITION, event->triggerId = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,event->triggerId); -// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] ERROR CONDITION, event->triggerId = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,event->triggerId); -// } -// -// if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); -// -// //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] MUTEX LOCK held for msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); -// -// if(connectionSlot != NULL && -// (gameHasBeenInitiated == false || -// (connectionSlot->getSocket() != NULL && socketTriggered == true))) { -// if(connectionSlot->isConnected() == false || socketTriggered == true) { -// //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] MUTEX LOCK held for msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); -// -// //safeMutexSlot.ReleaseLock(true); -// connectionSlot->update(checkForNewClients,event->triggerId); -// -// if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); -// -// //chrono.start(); -// //safeMutexSlot.Lock(); -// //connectionSlot = slots[event->triggerId]; -// -// //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] MUTEX LOCK held for msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); -// -// // This means no clients are trying to connect at the moment -// if(connectionSlot != NULL && connectionSlot->getSocket() == NULL) { -// checkForNewClients = false; -// } -// } -// //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] MUTEX LOCK held for msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); -// } -// safeMutexSlot.ReleaseLock(); -// -// if(event->triggerId >= 0 && event->triggerId < GameConstants::maxPlayers) { -// //printf("===> END slot %d - About to updateSlot\n",event->triggerId); -// } -// } -// if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"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 %lld msecs\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); -//} - std::pair ServerInterface::clientLagCheck(ConnectionSlot *connectionSlot, bool skipNetworkBroadCast) { Chrono chrono; if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start(); @@ -728,16 +619,6 @@ std::pair ServerInterface::clientLagCheck(ConnectionSlot *connectionS std::pair clientLagExceededOrWarned = std::make_pair(false, false); static bool alreadyInLagCheck = false; -// { -// if(connectionSlot != NULL && connectionSlot->isConnected() == true) { -// double clientLag = this->getCurrentFrameCount() - connectionSlot->getCurrentFrameCount(); -// double clientLagCount = (gameSettings.getNetworkFramePeriod() > 0 ? (clientLag / gameSettings.getNetworkFramePeriod()) : 0); -// double clientLagTime = difftime(time(NULL),connectionSlot->getLastReceiveCommandListTime()); -// -// printf("\n\nmaxClientLagTimeAllowedEver [%f] - [%f] alreadyInLagCheck = %d\n\n",maxClientLagTimeAllowedEver,clientLagTime,alreadyInLagCheck); -// } -// } - if(alreadyInLagCheck == true || (connectionSlot != NULL && (connectionSlot->getSkipLagCheck() == true || connectionSlot->getConnectHasHandshaked() == false))) { @@ -1067,6 +948,7 @@ void ServerInterface::checkForCompletedClients(std::map & mapSlotSigna ConnectionSlot* connectionSlot = slots[i]; if(connectionSlot != NULL && mapSlotSignalledList[i] == true && + connectionSlot->getJoinGameInProgress() == false && slotsCompleted.find(i) == slotsCompleted.end()) { try { @@ -2258,14 +2140,14 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) { } } - gameStarted = true; + gameLaunched = true; } if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); return bOkToStart; } void ServerInterface::checkListenerSlots() { - if(gameStarted == true && allowInGameConnections == true) { + if(gameLaunched == true && allowInGameConnections == true) { bool useInGameBlockingClientSockets = Config::getInstance().getBool("EnableInGameBlockingSockets","true"); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); @@ -2277,16 +2159,22 @@ void ServerInterface::checkListenerSlots() { if(connectionSlot == NULL && gameSettings.getFactionControl(factionIndex) != ctClosed && gameSettings.getFactionControl(factionIndex) != ctHuman) { - //printf("Opening slot for in game connections for slot: %d, faction: %d\n",i,factionIndex); - if(connectionSlot == NULL) { - addSlot(i); - connectionSlot = slots[i]; - if(useInGameBlockingClientSockets == true) { - connectionSlot->getSocket()->setBlock(true); - } + printf("Opening slot for in game connections, slot: %d, factionindex: %d name: %s\n",i,factionIndex,gameSettings.getFactionTypeName(factionIndex).c_str()); + + addSlot(i); + connectionSlot = slots[i]; + if(useInGameBlockingClientSockets == true) { + connectionSlot->getSocket()->setBlock(true); } connectionSlot->setCanAcceptConnections(true); } + else if(connectionSlot != NULL && + connectionSlot->getCanAcceptConnections() == false && + connectionSlot->isConnected() == false && + gameSettings.getFactionControl(factionIndex) != ctClosed && + gameSettings.getFactionControl(factionIndex) != ctHuman) { + this->removeSlot(i); + } } } if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] needToRepublishToMasterserver = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,needToRepublishToMasterserver); @@ -2868,7 +2756,6 @@ std::string ServerInterface::DumpStatsToLog(bool dumpToStringOnly) const { return result; } - void ServerInterface::notifyBadClientConnectAttempt(string ipAddress) { //printf("In [%s::%s Line: %d] ipAddress [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ipAddress.c_str()); @@ -2914,6 +2801,51 @@ void ServerInterface::notifyBadClientConnectAttempt(string ipAddress) { //printf("In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); } +bool ServerInterface::getStartInGameConnectionLaunch() { + 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->getStartInGameConnectionLaunch() == true) { + result = true; + break; + } + } + } + return result; +} + +bool ServerInterface::getPauseForInGameConnection() { + 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->getPauseForInGameConnection() == true) { + result = true; + break; + } + } + } + return result; +} + +bool ServerInterface::getUnPauseForInGameConnection() { + 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; + } + } + } + return result; +} + void ServerInterface::saveGame(XmlNode *rootNode) { std::map mapTagReplacements; XmlNode *serverInterfaceNode = rootNode->addChild("ServerInterface"); diff --git a/source/glest_game/network/server_interface.h b/source/glest_game/network/server_interface.h index 7ef6aaee8..2842d815b 100644 --- a/source/glest_game/network/server_interface.h +++ b/source/glest_game/network/server_interface.h @@ -29,8 +29,6 @@ using Shared::Platform::ServerSocket; namespace Shared { namespace PlatformCommon { class FTPServerThread; }} -//using Shared::PlatformCommon::FTPServerThread; - namespace Glest{ namespace Game{ // ===================================================== @@ -56,8 +54,6 @@ private: Mutex *slotAccessorMutexes[GameConstants::maxPlayers]; ServerSocket serverSocket; - bool gameHasBeenInitiated; - int gameSettingsUpdateCount; Mutex *switchSetupRequestsSynchAccessor; SwitchSetupRequest* switchSetupRequests[GameConstants::maxPlayers]; @@ -98,11 +94,11 @@ private: ServerSocket *serverSocketAdmin; MasterSlaveThreadController masterController; + bool gameHasBeenInitiated; + int gameSettingsUpdateCount; + bool allowInGameConnections; - bool pauseForInGameConnection; - bool startInGameConnectionLaunch; - bool unPauseForInGameConnection; - bool gameStarted; + bool gameLaunched; public: ServerInterface(bool publishEnabled); @@ -110,23 +106,14 @@ public: virtual Socket* getSocket(bool mutexLock=true) {return &serverSocket;} - //const virtual Socket *getSocket() const { - // return &serverSocket; - //} - time_t getGameStartTime() const { return gameStartTime; } bool getAllowInGameConnections() const { return allowInGameConnections; } void setAllowInGameConnections(bool value) { allowInGameConnections = value; } - bool getStartInGameConnectionLaunch() const { return startInGameConnectionLaunch; } - void setStartInGameConnectionLaunch(bool value) { startInGameConnectionLaunch = value; } - - bool getPauseForInGameConnection() const { return pauseForInGameConnection; } - void setPauseForInGameConnection(bool value) { pauseForInGameConnection = value; } - - bool getUnPauseForInGameConnection() const { return unPauseForInGameConnection; } - void setUnPauseForInGameConnection(bool value) { unPauseForInGameConnection = value; } + bool getStartInGameConnectionLaunch(); + bool getPauseForInGameConnection(); + bool getUnPauseForInGameConnection(); virtual void close(); virtual void update(); @@ -179,54 +166,49 @@ public: void setMasterserverAdminRequestLaunch(bool value) { masterserverAdminRequestLaunch = value; } void updateListen(); - virtual bool getConnectHasHandshaked() const - { + virtual bool getConnectHasHandshaked() const { return false; } - virtual void slotUpdateTask(ConnectionSlotEvent *event); + virtual void slotUpdateTask(ConnectionSlotEvent *event) { }; bool hasClientConnection(); bool isClientConnected(int index); - int getCurrentFrameCount() const - { + int getCurrentFrameCount() const { return currentFrameCount; } std::pair clientLagCheck(ConnectionSlot *connectionSlot, bool skipNetworkBroadCast = false); bool signalClientReceiveCommands(ConnectionSlot *connectionSlot, int slotIndex, bool socketTriggered, ConnectionSlotEvent & event); void updateSocketTriggeredList(std::map & socketTriggeredList); - bool isPortBound() const - { + bool isPortBound() const { return serverSocket.isPortBound(); } - int getBindPort() const - { + int getBindPort() const { return serverSocket.getBindPort(); } - void broadcastPing(NetworkMessagePing *networkMessage, int excludeSlot = -1) - { + void broadcastPing(NetworkMessagePing *networkMessage, int excludeSlot = -1) { this->broadcastMessage(networkMessage, excludeSlot); } void queueBroadcastMessage(NetworkMessage *networkMessage, int excludeSlot = -1); virtual string getHumanPlayerName(int index = -1); virtual int getHumanPlayerIndex() const; - bool getNeedToRepublishToMasterserver() const - { + bool getNeedToRepublishToMasterserver() const { return needToRepublishToMasterserver; } - void setNeedToRepublishToMasterserver(bool value) - { + void setNeedToRepublishToMasterserver(bool value) { needToRepublishToMasterserver = value; } void setPublishEnabled(bool value); - bool getGameHasBeenInitiated() const { return gameHasBeenInitiated; } + bool getGameHasBeenInitiated() const { + return gameHasBeenInitiated; + } public: Mutex *getServerSynchAccessor() {