diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 905b1a2c7..e3eba0c9e 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -2467,12 +2467,16 @@ void CPlayerInterface::showShipyardDialogOrProblemPopup(const IShipyard *obj) void CPlayerInterface::requestReturningToMainMenu(bool won) { - CSH->state = EClientState::DISCONNECTING; CCS->soundh->ambientStopAllChannels(); if(won && cb->getStartInfo()->campState) + { + CSH->state = EClientState::DISCONNECTING; // do not close server, it's not intended for campaign continuation CSH->startCampaignScenario(cb->getStartInfo()->campState); + } else + { sendCustomEvent(EUserEvent::RETURN_TO_MAIN_MENU); + } } void CPlayerInterface::sendCustomEvent( int code ) diff --git a/client/CServerHandler.cpp b/client/CServerHandler.cpp index a81a94487..450fbdf2b 100644 --- a/client/CServerHandler.cpp +++ b/client/CServerHandler.cpp @@ -495,6 +495,7 @@ void CServerHandler::endGameplay(bool closeConnection, bool restart) { if(CMM) { + GH.terminate_cond->setn(false); GH.curInt = CMM.get(); CMM->enable(); } @@ -644,6 +645,7 @@ void CServerHandler::threadHandleConnection() logNetwork->error(e.what()); if(client) { + state = EClientState::DISCONNECTING; CGuiHandler::pushSDLEvent(SDL_USEREVENT, EUserEvent::RETURN_TO_MAIN_MENU); } else diff --git a/client/mainmenu/CMainMenu.cpp b/client/mainmenu/CMainMenu.cpp index 58bef9650..692402598 100644 --- a/client/mainmenu/CMainMenu.cpp +++ b/client/mainmenu/CMainMenu.cpp @@ -352,7 +352,7 @@ std::shared_ptr CMainMenu::create() if(!CMM) CMM = std::shared_ptr(new CMainMenu()); - GH.terminate_cond->set(false); + GH.terminate_cond->setn(false); return CMM; } diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index de87a368a..730ddba96 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -191,6 +191,8 @@ void CVCMIServer::run() { gh->run(si->mode == StartInfo::LOAD_GAME); } + while(state == EServerState::GAMEPLAY_ENDED) + boost::this_thread::sleep(boost::posix_time::milliseconds(50)); } void CVCMIServer::threadAnnounceLobby()