1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-19 21:10:12 +02:00

fix repeated launches of single player

now server actually terminates
This commit is contained in:
Andrey Filipenkov 2022-07-28 12:40:06 +03:00
parent b7bc8495d8
commit cd4b68c034
3 changed files with 16 additions and 10 deletions

View File

@ -190,7 +190,7 @@ void CServerHandler::startLocalServerAndConnect()
boost::condition_variable cond; boost::condition_variable cond;
threadRunLocalServer = std::make_shared<boost::thread>([&cond, this] { threadRunLocalServer = std::make_shared<boost::thread>([&cond, this] {
setThreadName("CVCMIServer"); setThreadName("CVCMIServer");
CVCMIServer::create(&cond); CVCMIServer::create(&cond, uuid);
// todo ios copypaste // todo ios copypaste
threadRunLocalServer.reset(); threadRunLocalServer.reset();
CSH->campaignServerRestartLock.setn(false); CSH->campaignServerRestartLock.setn(false);

View File

@ -855,8 +855,11 @@ void handleLinuxSignal(int sig)
static void handleCommandOptions(int argc, char * argv[], boost::program_options::variables_map & options) static void handleCommandOptions(int argc, char * argv[], boost::program_options::variables_map & options)
{ {
#ifndef VCMI_IOS
namespace po = boost::program_options; 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"); po::options_description opts("Allowed options");
opts.add_options() opts.add_options()
("help,h", "display help and exit") ("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; std::cerr << "Failure during parsing command-line options:\n" << e.what() << std::endl;
} }
} }
#endif
po::notify(options); po::notify(options);
#ifndef VCMI_IOS
if(options.count("help")) if(options.count("help"))
{ {
auto time = std::time(0); auto time = std::time(0);
@ -916,7 +922,6 @@ int main(int argc, char * argv[])
signal(SIGSEGV, handleLinuxSignal); signal(SIGSEGV, handleLinuxSignal);
#endif #endif
// todo ios: double console log in single-process mode. Why removing the lines below breaks connecting to local server?!
console = new CConsoleHandler(); console = new CConsoleHandler();
CBasicLogConfigurator logConfig(VCMIDirs::get().userLogsPath() / "VCMI_Server_log.txt", console); CBasicLogConfigurator logConfig(VCMIDirs::get().userLogsPath() / "VCMI_Server_log.txt", console);
logConfig.configureDefault(); logConfig.configureDefault();
@ -932,8 +937,7 @@ int main(int argc, char * argv[])
srand((ui32)time(nullptr)); srand((ui32)time(nullptr));
#ifdef VCMI_IOS #ifdef VCMI_IOS
argc = 1; boost::condition_variable * cond = reinterpret_cast<boost::condition_variable *>(argv[0]);
boost::condition_variable * cond = reinterpret_cast<boost::condition_variable *>(argv[1]);
cond->notify_one(); cond->notify_one();
#endif #endif
@ -983,10 +987,12 @@ void CVCMIServer::create()
main(1, const_cast<char **>(foo)); main(1, const_cast<char **>(foo));
} }
#elif defined(VCMI_IOS) #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(); const std::initializer_list<const void *> argv = {
void *argv[] = {const_cast<char *>(executablePath.c_str()), cond}; cond,
main(2, reinterpret_cast<char **>(argv)); uuid.c_str(),
};
main(argv.size(), reinterpret_cast<char **>(const_cast<void **>(argv.begin())));
} }
#endif #endif

View File

@ -109,6 +109,6 @@ public:
#ifdef VCMI_ANDROID #ifdef VCMI_ANDROID
static void create(); static void create();
#elif defined(VCMI_IOS) #elif defined(VCMI_IOS)
static void create(boost::condition_variable * cond); static void create(boost::condition_variable * cond, const std::string & uuid);
#endif #endif
}; };