From c14c9ebc2d3fd615b5827a3eff362c6f2dce95f7 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Wed, 19 Dec 2012 19:55:49 +0000 Subject: [PATCH] - attempt to fix the segfault reported by tomreyn when headless admin disconnects from the server --- source/glest_game/network/server_interface.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index 35629317..108ace7f 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -1361,7 +1361,7 @@ void ServerInterface::update() { int iFirstConnectedSlot = -1; for(int i= 0; i < GameConstants::maxPlayers; ++i) { MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[i],CODE_AT_LINE_X(i)); - if(slots[i] != NULL) { + if(slots[i] != NULL && slots[i]->isConnected() == true) { if(iFirstConnectedSlot < 0) { iFirstConnectedSlot = i; } @@ -1375,13 +1375,17 @@ void ServerInterface::update() { if(foundAdminSlot == false && iFirstConnectedSlot >= 0) { printf("Switching masterserver admin to slot#%d...\n",iFirstConnectedSlot); - string sMsg = "Switching player to admin mode: " + slots[iFirstConnectedSlot]->getName(); - sendTextMessage(sMsg,-1, true,""); + MutexSafeWrapper safeMutexSlot(slotAccessorMutexes[iFirstConnectedSlot],CODE_AT_LINE_X(iFirstConnectedSlot)); + if(slots[iFirstConnectedSlot] != NULL) { + string sMsg = "Switching player to admin mode: " + slots[iFirstConnectedSlot]->getName(); + sendTextMessage(sMsg,-1, true,""); - this->gameSettings.setMasterserver_admin(slots[iFirstConnectedSlot]->getSessionKey()); - this->gameSettings.setMasterserver_admin_faction_index(slots[iFirstConnectedSlot]->getPlayerIndex()); + this->gameSettings.setMasterserver_admin(slots[iFirstConnectedSlot]->getSessionKey()); + this->gameSettings.setMasterserver_admin_faction_index(slots[iFirstConnectedSlot]->getPlayerIndex()); - this->broadcastGameSetup(&this->gameSettings); + safeMutexSlot.ReleaseLock(); + this->broadcastGameSetup(&this->gameSettings); + } } } //printf("\nServerInterface::update -- G\n");