1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Revert "attempt to run server in a separate app"

This reverts commit 99fe55b295ad95033626c15011cfe49779269156.
This commit is contained in:
Andrey Filipenkov 2022-07-26 16:16:37 +03:00
parent e61e283b75
commit de05479532
3 changed files with 45 additions and 9 deletions

View File

@ -23,7 +23,10 @@
#ifdef VCMI_ANDROID
#include "../lib/CAndroidVMHelper.h"
#elif !defined(VCMI_IOS)
#elif defined(VCMI_IOS)
#include "../server/CVCMIServer.h"
// todo ios
#else
#include "../lib/Interprocess.h"
#endif
#include "../lib/CConfigHandler.h"
@ -182,7 +185,18 @@ void CServerHandler::startLocalServerAndConnect()
envHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "startServer", true);
}
#elif defined(VCMI_IOS)
// todo ios
// todo ios: hide keyboard
logNetwork->info("[ios] create server thread");
boost::condition_variable cond;
threadRunLocalServer = std::make_shared<boost::thread>([&cond, this] {
setThreadName("CVCMIServer");
CVCMIServer::create(&cond);
// todo ios copypaste
threadRunLocalServer.reset();
CSH->campaignServerRestartLock.setn(false);
});
// threadRunLocalServer->detach();
logNetwork->info("[ios] detach server thread");
#else
threadRunLocalServer = std::make_shared<boost::thread>(&CServerHandler::threadRunServer, this); //runs server executable;
#endif
@ -201,6 +215,13 @@ void CServerHandler::startLocalServerAndConnect()
androidTestServerReadyFlag = false;
#elif defined(VCMI_IOS)
// todo ios
{
boost::mutex m;
boost::unique_lock<boost::mutex> lock{m};
logNetwork->info("[ios] wait for server");
cond.wait(lock);
logNetwork->info("[ios] server ready");
}
#else
if(shm)
shm->sr->waitTillReady();

View File

@ -112,8 +112,8 @@ public:
}
};
std::string NAME_AFFIX = "server";
std::string NAME = GameConstants::VCMI_VERSION + std::string(" (") + NAME_AFFIX + ')';
std::string SERVER_NAME_AFFIX = "server";
std::string SERVER_NAME = GameConstants::VCMI_VERSION + std::string(" (") + SERVER_NAME_AFFIX + ')';
CVCMIServer::CVCMIServer(boost::program_options::variables_map & opts)
: port(3030), io(std::make_shared<boost::asio::io_service>()), state(EServerState::LOBBY), cmdLineOptions(opts), currentClientId(1), currentPlayerId(1), restartGameplay(false)
@ -291,7 +291,7 @@ void CVCMIServer::connectionAccepted(const boost::system::error_code & ec)
try
{
logNetwork->info("We got a new connection! :)");
auto c = std::make_shared<CConnection>(upcomingConnection, NAME, uuid);
auto c = std::make_shared<CConnection>(upcomingConnection, SERVER_NAME, uuid);
upcomingConnection.reset();
connections.insert(c);
c->handler = std::make_shared<boost::thread>(&CVCMIServer::threadHandleClient, this, c);
@ -918,9 +918,14 @@ int main(int argc, char * argv[])
console = new CConsoleHandler();
CBasicLogConfigurator logConfig(VCMIDirs::get().userLogsPath() / "VCMI_Server_log.txt", console);
logConfig.configureDefault();
logGlobal->info(NAME);
logGlobal->info(SERVER_NAME);
boost::program_options::variables_map opts;
boost::program_options::variables_map opts;
#ifdef VCMI_IOS
argc = 1;
boost::condition_variable * cond = reinterpret_cast<boost::condition_variable *>(argv[1]);
cond->notify_one();
#else
handleCommandOptions(argc, argv, opts);
preinitDLL(console);
settings.init();
@ -928,6 +933,7 @@ int main(int argc, char * argv[])
loadDLLClasses();
srand((ui32)time(nullptr));
#endif
try
{
boost::asio::io_service io_service;
@ -967,10 +973,17 @@ int main(int argc, char * argv[])
return 0;
}
#if defined(VCMI_ANDROID) || defined(VCMI_IOS)
#ifdef VCMI_ANDROID
void CVCMIServer::create()
{
const char * foo[1] = {"android-server"};
main(1, const_cast<char **>(foo));
}
#elif defined(VCMI_IOS)
void CVCMIServer::create(boost::condition_variable * cond)
{
const auto executablePath = VCMIDirs::get().serverPath();
void *argv[] = {const_cast<char *>(executablePath.c_str()), cond};
main(2, reinterpret_cast<char **>(argv));
}
#endif

View File

@ -106,7 +106,9 @@ public:
ui8 getIdOfFirstUnallocatedPlayer() const;
#if defined(VCMI_ANDROID) || defined(VCMI_IOS)
#ifdef VCMI_ANDROID
static void create();
#elif defined(VCMI_IOS)
static void create(boost::condition_variable * cond);
#endif
};