diff --git a/client/CMT.cpp b/client/CMT.cpp index 2cb3349f1..874a8203f 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -1265,6 +1265,7 @@ static void handleEvent(SDL_Event & ev) break; case EUserEvent::CAMPAIGN_START_SCENARIO: { + CSH->campaignServerRestartLock.set(true); CSH->endGameplay(); auto ourCampaign = std::shared_ptr(reinterpret_cast(ev.user.data1)); auto & epilogue = ourCampaign->camp->scenarios[ourCampaign->mapsConquered.back()].epilog; @@ -1281,7 +1282,7 @@ static void handleEvent(SDL_Event & ev) } else { - boost::this_thread::sleep(boost::posix_time::milliseconds(1000)); //TODO: thread sync and execute this after server closes + CSH->campaignServerRestartLock.waitUntil(false); finisher(); } } diff --git a/client/CServerHandler.cpp b/client/CServerHandler.cpp index 450fbdf2b..9fddf66b0 100644 --- a/client/CServerHandler.cpp +++ b/client/CServerHandler.cpp @@ -101,7 +101,7 @@ public: extern std::string NAME; CServerHandler::CServerHandler() - : state(EClientState::NONE), mx(std::make_shared()), client(nullptr), loadMode(0), campaignStateToSend(nullptr) + : state(EClientState::NONE), mx(std::make_shared()), client(nullptr), loadMode(0), campaignStateToSend(nullptr), campaignServerRestartLock(false) { uuid = boost::uuids::to_string(boost::uuids::random_generator()()); applier = std::make_shared>(); @@ -692,6 +692,7 @@ void CServerHandler::threadRunServer() logNetwork->error("Check %s for more info", logName); } threadRunLocalServer.reset(); + CSH->campaignServerRestartLock.setn(false); #endif } diff --git a/client/CServerHandler.h b/client/CServerHandler.h index acb3c22d4..03ac005ed 100644 --- a/client/CServerHandler.h +++ b/client/CServerHandler.h @@ -12,6 +12,7 @@ #include "../lib/CStopWatch.h" #include "../lib/StartInfo.h" +#include "../lib/CondSh.h" struct SharedMemory; class CConnection; @@ -95,6 +96,8 @@ public: std::shared_ptr c; CClient * client; + CondSh campaignServerRestartLock; + CServerHandler(); void resetStateForLobby(const StartInfo::EMode mode, const std::vector * names = nullptr);