From cd4b68c034f1ef53cd27c2e81d14b886fa06406c Mon Sep 17 00:00:00 2001 From: Andrey Filipenkov Date: Thu, 28 Jul 2022 12:40:06 +0300 Subject: [PATCH] fix repeated launches of single player now server actually terminates --- client/CServerHandler.cpp | 2 +- server/CVCMIServer.cpp | 22 ++++++++++++++-------- server/CVCMIServer.h | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/client/CServerHandler.cpp b/client/CServerHandler.cpp index e3f1127c3..d2bc4218a 100644 --- a/client/CServerHandler.cpp +++ b/client/CServerHandler.cpp @@ -190,7 +190,7 @@ void CServerHandler::startLocalServerAndConnect() boost::condition_variable cond; threadRunLocalServer = std::make_shared([&cond, this] { setThreadName("CVCMIServer"); - CVCMIServer::create(&cond); + CVCMIServer::create(&cond, uuid); // todo ios copypaste threadRunLocalServer.reset(); CSH->campaignServerRestartLock.setn(false); diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index 2bccd81df..1598c78f1 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -855,8 +855,11 @@ void handleLinuxSignal(int sig) static void handleCommandOptions(int argc, char * argv[], boost::program_options::variables_map & options) { -#ifndef VCMI_IOS namespace po = boost::program_options; +#ifdef VCMI_IOS + options.emplace("run-by-client", po::variable_value{true, true}); + options.emplace("uuid", po::variable_value{std::string{argv[1]}, true}); +#else po::options_description opts("Allowed options"); opts.add_options() ("help,h", "display help and exit") @@ -878,8 +881,11 @@ static void handleCommandOptions(int argc, char * argv[], boost::program_options std::cerr << "Failure during parsing command-line options:\n" << e.what() << std::endl; } } +#endif po::notify(options); + +#ifndef VCMI_IOS if(options.count("help")) { auto time = std::time(0); @@ -916,7 +922,6 @@ int main(int argc, char * argv[]) signal(SIGSEGV, handleLinuxSignal); #endif - // todo ios: double console log in single-process mode. Why removing the lines below breaks connecting to local server?! console = new CConsoleHandler(); CBasicLogConfigurator logConfig(VCMIDirs::get().userLogsPath() / "VCMI_Server_log.txt", console); logConfig.configureDefault(); @@ -932,8 +937,7 @@ int main(int argc, char * argv[]) srand((ui32)time(nullptr)); #ifdef VCMI_IOS - argc = 1; - boost::condition_variable * cond = reinterpret_cast(argv[1]); + boost::condition_variable * cond = reinterpret_cast(argv[0]); cond->notify_one(); #endif @@ -983,10 +987,12 @@ void CVCMIServer::create() main(1, const_cast(foo)); } #elif defined(VCMI_IOS) -void CVCMIServer::create(boost::condition_variable * cond) +void CVCMIServer::create(boost::condition_variable * cond, const std::string & uuid) { - const auto executablePath = VCMIDirs::get().serverPath(); - void *argv[] = {const_cast(executablePath.c_str()), cond}; - main(2, reinterpret_cast(argv)); + const std::initializer_list argv = { + cond, + uuid.c_str(), + }; + main(argv.size(), reinterpret_cast(const_cast(argv.begin()))); } #endif diff --git a/server/CVCMIServer.h b/server/CVCMIServer.h index 80c5b9f39..55ad15542 100644 --- a/server/CVCMIServer.h +++ b/server/CVCMIServer.h @@ -109,6 +109,6 @@ public: #ifdef VCMI_ANDROID static void create(); #elif defined(VCMI_IOS) - static void create(boost::condition_variable * cond); + static void create(boost::condition_variable * cond, const std::string & uuid); #endif };