From d08c8300f09cdd2013cd23bea70be242777d13b2 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 21 Aug 2010 01:52:41 +0000 Subject: [PATCH] - more attempts at stability for network games --- source/glest_game/network/connection_slot.cpp | 3 ++- source/glest_game/network/server_interface.cpp | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index da3a6e8ca..26a0fed56 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -608,7 +608,8 @@ bool ConnectionSlot::updateCompleted() { //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex); - bool waitingForThread = (slotThreadWorker->isSignalCompleted() == false && + bool waitingForThread = (slotThreadWorker != NULL && + slotThreadWorker->isSignalCompleted() == false && slotThreadWorker->getQuitStatus() == false && slotThreadWorker->getRunningStatus() == true); diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index 27ed6004b..992e1fdd9 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -101,6 +101,7 @@ void ServerInterface::addSlot(int playerIndex){ assert(playerIndex>=0 && playerIndexisConnected()) { + MutexSafeWrapper safeMutex(&serverSynchAccessor); + if( slots[toPlayerIndex]->isConnected() == false) { //printf(" yes, its free :)\n"); slots[fromPlayerIndex]->setPlayerIndex(toPlayerIndex); slots[toPlayerIndex]->setPlayerIndex(fromPlayerIndex); ConnectionSlot *tmp=slots[toPlayerIndex]; slots[toPlayerIndex]= slots[fromPlayerIndex]; slots[fromPlayerIndex]=tmp; + safeMutex.ReleaseLock(); + PlayerIndexMessage playerIndexMessage(toPlayerIndex); slots[toPlayerIndex]->sendMessage(&playerIndexMessage); result=true; updateListen(); } + else { + safeMutex.ReleaseLock(); + } SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); return result; } @@ -146,6 +155,7 @@ bool ServerInterface::switchSlot(int fromPlayerIndex,int toPlayerIndex){ void ServerInterface::removeSlot(int playerIndex) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex); + MutexSafeWrapper safeMutex(&serverSynchAccessor); // Mention to everyone that this player is disconnected ConnectionSlot *slot = slots[playerIndex]; @@ -171,6 +181,8 @@ void ServerInterface::removeSlot(int playerIndex) { delete slots[playerIndex]; slots[playerIndex]= NULL; + safeMutex.ReleaseLock(); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d playerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex); updateListen();