diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index bd5e86cbc..cb172235c 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -317,6 +317,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){ CoreData &coreData= CoreData::getInstance(); SoundRenderer &soundRenderer= SoundRenderer::getInstance(); ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface(); + if(mainMessageBox.getEnabled()){ int button= 1; if(mainMessageBox.mouseClick(x, y, button)) @@ -359,6 +360,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); // Send the game settings to each client if we have at least one networked client + MutexSafeWrapper safeMutex(&masterServerThreadAccessor); if( hasNetworkGameSettings() == true && needToSetChangedGameSettings == true) { @@ -418,6 +420,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){ ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface(); serverInterface->setGameSettings(&gameSettings,false); + MutexSafeWrapper safeMutex(&masterServerThreadAccessor); needToRepublishToMasterserver = true; if(hasNetworkGameSettings() == true) @@ -429,6 +432,8 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){ else if(listBoxMap.mouseClick(x, y)){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s\n", mapFiles[listBoxMap.getSelectedItemIndex()].c_str()); + MutexSafeWrapper safeMutex(&masterServerThreadAccessor); + loadMapInfo(Map::getMapPath(mapFiles[listBoxMap.getSelectedItemIndex()]), &mapInfo); labelMapInfo.setText(mapInfo.desc); updateControlers(); @@ -442,6 +447,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){ } } else if (listBoxFogOfWar.mouseClick(x, y)) { + MutexSafeWrapper safeMutex(&masterServerThreadAccessor); needToRepublishToMasterserver = true; if(hasNetworkGameSettings() == true) @@ -451,6 +457,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){ } } else if (listBoxEnableObserverMode.mouseClick(x, y)) { + MutexSafeWrapper safeMutex(&masterServerThreadAccessor); needToRepublishToMasterserver = true; if(hasNetworkGameSettings() == true) @@ -460,6 +467,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){ } } else if (listBoxEnableServerControlledAI.mouseClick(x, y)&&listBoxEnableServerControlledAI.getEditable()) { + MutexSafeWrapper safeMutex(&masterServerThreadAccessor); needToRepublishToMasterserver = true; if(hasNetworkGameSettings() == true) @@ -469,6 +477,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){ } } else if(listBoxTileset.mouseClick(x, y)){ + MutexSafeWrapper safeMutex(&masterServerThreadAccessor); needToRepublishToMasterserver = true; if(hasNetworkGameSettings() == true) @@ -480,6 +489,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){ else if(listBoxTechTree.mouseClick(x, y)){ reloadFactions(); + MutexSafeWrapper safeMutex(&masterServerThreadAccessor); needToRepublishToMasterserver = true; if(hasNetworkGameSettings() == true) @@ -489,13 +499,13 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){ } } else if(listBoxPublishServer.mouseClick(x, y)&&listBoxPublishServer.getEditable()){ + MutexSafeWrapper safeMutex(&masterServerThreadAccessor); needToRepublishToMasterserver = true; soundRenderer.playFx(coreData.getClickSoundC()); } - else - { - for(int i=0; ihasClientConnection() == true) { //printf("Sending game settings broadcast since we have at least 1 client connected'\n"); @@ -996,6 +1024,8 @@ void MenuStateCustomGame::simpleTask() { void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + MutexSafeWrapper safeMutex(&masterServerThreadAccessor); + int factionCount= 0; ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface(); @@ -1054,6 +1084,8 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) { //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] gameSettings->getTech() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getTech().c_str()); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] gameSettings->getMap() = [%s]\n",__FILE__,__FUNCTION__,gameSettings->getMap().c_str()); + safeMutex.ReleaseLock(false); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); } diff --git a/source/glest_game/menu/menu_state_custom_game.h b/source/glest_game/menu/menu_state_custom_game.h index 29a72e9d2..638ad23ff 100644 --- a/source/glest_game/menu/menu_state_custom_game.h +++ b/source/glest_game/menu/menu_state_custom_game.h @@ -69,6 +69,7 @@ private: bool needToBroadcastServerSettings; string publishToServerInfo; SimpleTaskThread *publishToMasterserverThread; + Mutex masterServerThreadAccessor; bool parentMenuIsMs; int soundConnectionCount; diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index 6b7b30cef..7409aba43 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -694,6 +694,7 @@ bool ServerInterface::launchGame(const GameSettings* gameSettings){ void ServerInterface::broadcastGameSetup(const GameSettings* gameSettings) { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + MutexSafeWrapper safeMutex(&serverSynchAccessor); NetworkMessageLaunch networkMessageLaunch(gameSettings,nmtBroadCastSetup); broadcastMessage(&networkMessageLaunch); @@ -860,6 +861,8 @@ void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool wai { SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START gameSettingsUpdateCount = %d, waitForClientAck = %d\n",__FILE__,__FUNCTION__,gameSettingsUpdateCount,waitForClientAck); + MutexSafeWrapper safeMutex(&serverSynchAccessor); + if(getAllowGameDataSynchCheck() == true) { if(waitForClientAck == true && gameSettingsUpdateCount > 0) diff --git a/source/shared_lib/include/platform/sdl/thread.h b/source/shared_lib/include/platform/sdl/thread.h index 27eedd048..83149f179 100644 --- a/source/shared_lib/include/platform/sdl/thread.h +++ b/source/shared_lib/include/platform/sdl/thread.h @@ -69,17 +69,23 @@ public: MutexSafeWrapper(Mutex *mutex) { this->mutex = mutex; - if(this->mutex != NULL) { - this->mutex->p(); - } + Lock(); } ~MutexSafeWrapper() { ReleaseLock(); } - void ReleaseLock() { + + void Lock() { + if(this->mutex != NULL) { + this->mutex->p(); + } + } + void ReleaseLock(bool keepMutex=false) { if(this->mutex != NULL) { this->mutex->v(); - this->mutex = NULL; + if(keepMutex == false) { + this->mutex = NULL; + } } } };