diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index 7a5d58c1b..34d53895e 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -63,6 +63,7 @@ double MAX_CLIENT_WAIT_SECONDS_FOR_PAUSE = 1; ServerInterface::ServerInterface() : GameNetworkInterface() { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); gameHasBeenInitiated = false; + exitServer = false; gameSettingsUpdateCount = 0; currentFrameCount = 0; gameStartTime = 0; @@ -79,7 +80,7 @@ ServerInterface::ServerInterface() : GameNetworkInterface() { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] enabledThreadedClientCommandBroadcast = %d, maxFrameCountLagAllowed = %f, maxFrameCountLagAllowedEver = %f, maxClientLagTimeAllowed = %f\n",__FILE__,__FUNCTION__,__LINE__,enabledThreadedClientCommandBroadcast,maxFrameCountLagAllowed,maxFrameCountLagAllowedEver,maxClientLagTimeAllowed); - for(int i= 0; iisConnected() == true) { result = true; @@ -331,7 +333,7 @@ bool ServerInterface::hasClientConnection() { int ServerInterface::getConnectedSlotCount() { int connectedSlotCount= 0; - for(int i= 0; i &socketTriggeredList) { //update all slots - for(int i= 0; i < GameConstants::maxPlayers; ++i) { + for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) { MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(i)); ConnectionSlot* connectionSlot= slots[i]; if(connectionSlot != NULL && connectionSlot->getSocket() != NULL && @@ -556,7 +558,7 @@ void ServerInterface::updateSocketTriggeredList(std::map & } void ServerInterface::validateConnectedClients() { - for(int i= 0; i slotsCompleted; for(bool threadsDone = false; - threadsDone == false && difftime(time(NULL),waitForThreadElapsed) < MAX_SLOT_THREAD_WAIT_TIME;) { + exitServer == false && threadsDone == false && + difftime(time(NULL),waitForThreadElapsed) < MAX_SLOT_THREAD_WAIT_TIME;) { threadsDone = true; // Examine all threads for completion of delegation - for(int i= 0; i< GameConstants::maxPlayers; ++i) { + for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) { MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(i)); ConnectionSlot* connectionSlot = slots[i]; if(connectionSlot != NULL && mapSlotSignalledList[i] == true && @@ -662,10 +665,11 @@ void ServerInterface::update() { //std::map slotsWarnedAndRetried; std::map slotsWarnedList; for(bool threadsDone = false; - threadsDone == false && difftime(time(NULL),waitForThreadElapsed) < MAX_SLOT_THREAD_WAIT_TIME;) { + exitServer == false && threadsDone == false && + difftime(time(NULL),waitForThreadElapsed) < MAX_SLOT_THREAD_WAIT_TIME;) { threadsDone = true; // Examine all threads for completion of delegation - for(int i= 0; i< GameConstants::maxPlayers; ++i) { + for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) { MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(i)); ConnectionSlot* connectionSlot = slots[i]; if(connectionSlot != NULL && mapSlotSignalledList[i] == true && @@ -740,13 +744,13 @@ void ServerInterface::update() { // Step #4 dispatch network commands to the pending list so that they are done in proper order if(gameHasBeenInitiated == true) { - for(int i= 0; i< GameConstants::maxPlayers; ++i) { + for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) { MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(i)); ConnectionSlot* connectionSlot= slots[i]; if(connectionSlot != NULL && connectionSlot->isConnected() == true) { vector pendingList = connectionSlot->getPendingNetworkCommandList(true); if(pendingList.size() > 0) { - for(int idx = 0; idx < pendingList.size(); ++idx) { + for(int idx = 0; exitServer == false && idx < pendingList.size(); ++idx) { NetworkCommand &cmd = pendingList[idx]; this->requestCommand(&cmd); } @@ -757,13 +761,15 @@ void ServerInterface::update() { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #5\n",__FILE__,__FUNCTION__,__LINE__); // Step #5 dispatch pending chat messages - for(int i= 0; i< GameConstants::maxPlayers; ++i) { + for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) { MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(i)); ConnectionSlot* connectionSlot= slots[i]; if(connectionSlot != NULL && connectionSlot->getChatTextList().empty() == false) { try { - for(int chatIdx = 0; slots[i] != NULL && chatIdx < connectionSlot->getChatTextList().size(); chatIdx++) { + for(int chatIdx = 0; + exitServer == false && slots[i] != NULL && + chatIdx < connectionSlot->getChatTextList().size(); chatIdx++) { connectionSlot= slots[i]; if(connectionSlot != NULL) { ChatMsgInfo msg(connectionSlot->getChatTextList()[chatIdx]); @@ -974,10 +980,10 @@ void ServerInterface::waitUntilReady(Checksum* checksum) { chrono.start(); //wait until we get a ready message from all clients - while(allReady == false) { + while(exitServer == false && allReady == false) { vector waitingForHosts; allReady= true; - for(int i= 0; iisConnected() == true) { @@ -1044,7 +1050,7 @@ void ServerInterface::waitUntilReady(Checksum* checksum) { try { //send ready message after, so clients start delayed - for(int i= 0; i < GameConstants::maxPlayers; ++i) { + for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) { MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(i)); ConnectionSlot* connectionSlot= slots[i]; if(connectionSlot != NULL && connectionSlot->isConnected() == true) { @@ -1107,7 +1113,7 @@ string ServerInterface::getNetworkStatus() { //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - for(int i= 0; i eventList; - for(int i= 0; i slotsCompleted; - for(bool threadsDone = false; threadsDone == false;) { + for(bool threadsDone = false; exitServer == false && threadsDone == false;) { threadsDone = true; // Examine all threads for completion of delegation - for(int i= 0; i< GameConstants::maxPlayers; ++i) { + for(int i = 0; exitServer == false && i < GameConstants::maxPlayers; ++i) { MutexSafeWrapper safeMutexSlot(NULL,intToStr(__LINE__) + "_" + intToStr(i)); if(i != lockedSlotIndex) { safeMutexSlot.setMutex(&slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(i)); @@ -1295,7 +1301,7 @@ void ServerInterface::broadcastMessage(const NetworkMessage* networkMessage, int } } else { - for(int i= 0; iisConnected() == false); @@ -1387,7 +1393,7 @@ void ServerInterface::updateListen() { int ServerInterface::getOpenSlotCount() { int openSlotCount= 0; - for(int i= 0; iisConnected() == false); @@ -1417,7 +1423,7 @@ void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool wai while(gotAckFromAllClients == false && difftime(time(NULL),tStart) <= 5) { gotAckFromAllClients = true; - for(int i= 0; iisConnected()) { @@ -1431,7 +1437,7 @@ void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool wai } } - for(int i= 0; iisConnected()) { @@ -1449,7 +1455,7 @@ void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool wai bool gotAckFromAllClients = false; while(gotAckFromAllClients == false && difftime(time(NULL),tStart) <= 5) { gotAckFromAllClients = true; - for(int i= 0; iisConnected()) { @@ -1515,7 +1521,7 @@ std::map ServerInterface::publishToMasterserver() { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); - for(int i= 0; i < GameConstants::maxPlayers; ++i) { + for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) { MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(i)); if(slots[i] != NULL) { slotCountUsed++; diff --git a/source/glest_game/network/server_interface.h b/source/glest_game/network/server_interface.h index b7880bcf8..69709098b 100644 --- a/source/glest_game/network/server_interface.h +++ b/source/glest_game/network/server_interface.h @@ -54,6 +54,7 @@ private: bool needToRepublishToMasterserver; Shared::PlatformCommon::FTPServerThread *ftpServer; + bool exitServer; public: ServerInterface();