From 8f98dbe566adf1ba45eef17ea2aef786e3be622b Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 20 Mar 2012 20:31:41 +0000 Subject: [PATCH] - attempt to add code to NOT allow new connections on a slot that is no longer an open slot --- .../menu/menu_state_custom_game.cpp | 30 ++++++++++++------- source/glest_game/network/connection_slot.cpp | 3 +- source/glest_game/network/connection_slot.h | 5 ++++ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 9a7fb0ce..948aeefd 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -3535,19 +3535,27 @@ void MenuStateCustomGame::updateNetworkSlots() { listBoxControls[i].setSelectedItemIndex(ctCpu); } } - if(serverInterface->getSlot(i) != NULL && - listBoxControls[i].getSelectedItemIndex() != ctNetwork) { - if(serverInterface->getSlot(i)->isConnected() == true) { - if(listBoxControls[i].getSelectedItemIndex() != ctNetworkUnassigned) { - listBoxControls[i].setSelectedItemIndex(ctNetworkUnassigned); + ConnectionSlot *slot = serverInterface->getSlot(i); + if(slot != NULL) { + if(listBoxControls[i].getSelectedItemIndex() != ctNetwork) { + if(slot->getCanAcceptConnections() == true) { + slot->setCanAcceptConnections(false); + } + if(slot->isConnected() == true) { + if(listBoxControls[i].getSelectedItemIndex() != ctNetworkUnassigned) { + listBoxControls[i].setSelectedItemIndex(ctNetworkUnassigned); + } + } + else { + serverInterface->removeSlot(i); + + if(listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned) { + listBoxControls[i].setSelectedItemIndex(ctClosed); + } } } - else { - serverInterface->removeSlot(i); - - if(listBoxControls[i].getSelectedItemIndex() == ctNetworkUnassigned) { - listBoxControls[i].setSelectedItemIndex(ctClosed); - } + else if(slot->getCanAcceptConnections() == false) { + slot->setCanAcceptConnections(true); } } } diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index b464de8f..b88c43b9 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -257,6 +257,7 @@ ConnectionSlot::ConnectionSlot(ServerInterface* serverInterface, int playerIndex this->gotLagCountWarning = false; this->lastReceiveCommandListTime = 0; this->receivedNetworkGameStatus = false; + this->canAcceptConnections = true; this->setSocket(NULL); this->slotThreadWorker = NULL; @@ -366,7 +367,7 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { this->setReceivedDataSynchCheck(false); // Is the listener socket ready to be read? - if(checkForNewClients == true) { + if(checkForNewClients == true && this->canAcceptConnections == true) { //if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis()); diff --git a/source/glest_game/network/connection_slot.h b/source/glest_game/network/connection_slot.h index 037139c7..59353523 100644 --- a/source/glest_game/network/connection_slot.h +++ b/source/glest_game/network/connection_slot.h @@ -133,6 +133,8 @@ private: int playerStatus; string playerLanguage; + bool canAcceptConnections; + public: ConnectionSlot(ServerInterface* serverInterface, int playerIndex); ~ConnectionSlot(); @@ -197,6 +199,9 @@ public: PLATFORM_SOCKET getSocketId(); + void setCanAcceptConnections(bool value) { canAcceptConnections = value; } + bool getCanAcceptConnections() const { return canAcceptConnections; } + protected: Mutex * getServerSynchAccessor();