CServerHandler.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. /*
  2. * CServerHandler.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "CServerHandler.h"
  12. #include "Client.h"
  13. #include "CGameInfo.h"
  14. #include "CPlayerInterface.h"
  15. #include "gui/CGuiHandler.h"
  16. #include "lobby/CSelectionBase.h"
  17. #include "lobby/CLobbyScreen.h"
  18. #include "mainmenu/CMainMenu.h"
  19. #ifndef VCMI_ANDROID
  20. #include "../lib/Interprocess.h"
  21. #else
  22. #include "../lib/CAndroidVMHelper.h"
  23. #endif
  24. #include "../lib/CConfigHandler.h"
  25. #include "../lib/CGeneralTextHandler.h"
  26. #include "../lib/CThreadHelper.h"
  27. #include "../lib/NetPacks.h"
  28. #include "../lib/StartInfo.h"
  29. #include "../lib/VCMIDirs.h"
  30. #include "../lib/mapping/CCampaignHandler.h"
  31. #include "../lib/mapping/CMap.h"
  32. #include "../lib/mapping/CMapInfo.h"
  33. #include "../lib/mapObjects/MiscObjects.h"
  34. #include "../lib/rmg/CMapGenOptions.h"
  35. #include "../lib/registerTypes/RegisterTypes.h"
  36. #include "../lib/serializer/Connection.h"
  37. #include "../lib/serializer/CMemorySerializer.h"
  38. #include <boost/uuid/uuid.hpp>
  39. #include <boost/uuid/uuid_io.hpp>
  40. #include <boost/uuid/uuid_generators.hpp>
  41. template<typename T> class CApplyOnLobby;
  42. #ifdef VCMI_ANDROID
  43. extern std::atomic_bool androidTestServerReadyFlag;
  44. #endif
  45. class CBaseForLobbyApply
  46. {
  47. public:
  48. virtual bool applyOnLobbyHandler(CServerHandler * handler, void * pack) const = 0;
  49. virtual void applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler, void * pack) const = 0;
  50. virtual ~CBaseForLobbyApply(){};
  51. template<typename U> static CBaseForLobbyApply * getApplier(const U * t = nullptr)
  52. {
  53. return new CApplyOnLobby<U>();
  54. }
  55. };
  56. template<typename T> class CApplyOnLobby : public CBaseForLobbyApply
  57. {
  58. public:
  59. bool applyOnLobbyHandler(CServerHandler * handler, void * pack) const override
  60. {
  61. T * ptr = static_cast<T *>(pack);
  62. logNetwork->trace("\tImmidiately apply on lobby: %s", typeList.getTypeInfo(ptr)->name());
  63. return ptr->applyOnLobbyHandler(handler);
  64. }
  65. void applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler, void * pack) const override
  66. {
  67. T * ptr = static_cast<T *>(pack);
  68. logNetwork->trace("\tApply on lobby from queue: %s", typeList.getTypeInfo(ptr)->name());
  69. ptr->applyOnLobbyScreen(lobby, handler);
  70. }
  71. };
  72. template<> class CApplyOnLobby<CPack>: public CBaseForLobbyApply
  73. {
  74. public:
  75. bool applyOnLobbyHandler(CServerHandler * handler, void * pack) const override
  76. {
  77. logGlobal->error("Cannot apply plain CPack!");
  78. assert(0);
  79. return false;
  80. }
  81. void applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler, void * pack) const override
  82. {
  83. logGlobal->error("Cannot apply plain CPack!");
  84. assert(0);
  85. }
  86. };
  87. extern std::string NAME;
  88. CServerHandler::CServerHandler()
  89. : state(EClientState::NONE), mx(std::make_shared<boost::recursive_mutex>()), client(nullptr), loadMode(0), campaignStateToSend(nullptr)
  90. {
  91. uuid = boost::uuids::to_string(boost::uuids::random_generator()());
  92. applier = std::make_shared<CApplier<CBaseForLobbyApply>>();
  93. registerTypesLobbyPacks(*applier);
  94. }
  95. void CServerHandler::resetStateForLobby(const StartInfo::EMode mode, const std::vector<std::string> * names)
  96. {
  97. hostClientId = -1;
  98. state = EClientState::NONE;
  99. th = make_unique<CStopWatch>();
  100. packsForLobbyScreen.clear();
  101. c.reset();
  102. si = std::make_shared<StartInfo>();
  103. playerNames.clear();
  104. si->difficulty = 1;
  105. si->mode = mode;
  106. myNames.clear();
  107. if(names && !names->empty()) //if have custom set of player names - use it
  108. myNames = *names;
  109. else
  110. myNames.push_back(settings["general"]["playerName"].String());
  111. #ifndef VCMI_ANDROID
  112. shm.reset();
  113. if(!settings["session"]["disable-shm"].Bool())
  114. {
  115. std::string sharedMemoryName = "vcmi_memory";
  116. if(settings["session"]["enable-shm-uuid"].Bool())
  117. {
  118. //used or automated testing when multiple clients start simultaneously
  119. sharedMemoryName += "_" + uuid;
  120. }
  121. try
  122. {
  123. shm = std::make_shared<SharedMemory>(sharedMemoryName, true);
  124. }
  125. catch(...)
  126. {
  127. shm.reset();
  128. logNetwork->error("Cannot open interprocess memory. Continue without it...");
  129. }
  130. }
  131. #endif
  132. }
  133. void CServerHandler::startLocalServerAndConnect()
  134. {
  135. if(threadRunLocalServer)
  136. threadRunLocalServer->join();
  137. th->update();
  138. #ifdef VCMI_ANDROID
  139. CAndroidVMHelper envHelper;
  140. envHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "startServer", true);
  141. envHelper.Detach();
  142. #else
  143. threadRunLocalServer = std::make_shared<boost::thread>(&CServerHandler::threadRunServer, this); //runs server executable;
  144. #endif
  145. logNetwork->trace("Setting up thread calling server: %d ms", th->getDiff());
  146. th->update();
  147. #ifndef VCMI_ANDROID
  148. if(shm)
  149. shm->sr->waitTillReady();
  150. #else
  151. logNetwork->info("waiting for server");
  152. while(!androidTestServerReadyFlag.load())
  153. {
  154. logNetwork->info("still waiting...");
  155. boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
  156. }
  157. logNetwork->info("waiting for server finished...");
  158. androidTestServerReadyFlag = false;
  159. #endif
  160. logNetwork->trace("Waiting for server: %d ms", th->getDiff());
  161. th->update(); //put breakpoint here to attach to server before it does something stupid
  162. #ifndef VCMI_ANDROID
  163. justConnectToServer(settings["server"]["server"].String(), shm ? shm->sr->port : 0);
  164. #else
  165. justConnectToServer(settings["server"]["server"].String());
  166. #endif
  167. logNetwork->trace("\tConnecting to the server: %d ms", th->getDiff());
  168. }
  169. void CServerHandler::justConnectToServer(const std::string & addr, const ui16 port)
  170. {
  171. state = EClientState::CONNECTING;
  172. while(!c && state != EClientState::CONNECTION_CANCELLED)
  173. {
  174. try
  175. {
  176. logNetwork->info("Establishing connection...");
  177. c = std::make_shared<CConnection>(
  178. addr.size() ? addr : settings["server"]["server"].String(),
  179. port ? port : getDefaultPort(),
  180. NAME, uuid);
  181. }
  182. catch(...)
  183. {
  184. logNetwork->error("\nCannot establish connection! Retrying within 1 second");
  185. boost::this_thread::sleep(boost::posix_time::seconds(1));
  186. }
  187. }
  188. if(state == EClientState::CONNECTION_CANCELLED)
  189. logNetwork->info("Connection aborted by player!");
  190. else
  191. c->handler = std::make_shared<boost::thread>(&CServerHandler::threadHandleConnection, this);
  192. }
  193. void CServerHandler::applyPacksOnLobbyScreen()
  194. {
  195. if(!c || !c->handler)
  196. return;
  197. boost::unique_lock<boost::recursive_mutex> lock(*mx);
  198. while(!packsForLobbyScreen.empty())
  199. {
  200. CPackForLobby * pack = packsForLobbyScreen.front();
  201. packsForLobbyScreen.pop_front();
  202. CBaseForLobbyApply * apply = applier->getApplier(typeList.getTypeID(pack)); //find the applier
  203. apply->applyOnLobbyScreen(static_cast<CLobbyScreen *>(SEL), this, pack);
  204. GH.totalRedraw();
  205. delete pack;
  206. }
  207. }
  208. void CServerHandler::stopServerConnection()
  209. {
  210. if(c->handler)
  211. {
  212. while(!c->handler->timed_join(boost::posix_time::milliseconds(50)))
  213. applyPacksOnLobbyScreen();
  214. c->handler->join();
  215. }
  216. }
  217. std::set<PlayerColor> CServerHandler::getHumanColors()
  218. {
  219. return clientHumanColors(c->connectionID);
  220. }
  221. PlayerColor CServerHandler::myFirstColor() const
  222. {
  223. return clientFirstColor(c->connectionID);
  224. }
  225. bool CServerHandler::isMyColor(PlayerColor color) const
  226. {
  227. return isClientColor(c->connectionID, color);
  228. }
  229. ui8 CServerHandler::myFirstId() const
  230. {
  231. return clientFirstId(c->connectionID);
  232. }
  233. bool CServerHandler::isServerLocal() const
  234. {
  235. if(threadRunLocalServer)
  236. return true;
  237. return false;
  238. }
  239. bool CServerHandler::isHost() const
  240. {
  241. return c && hostClientId == c->connectionID;
  242. }
  243. bool CServerHandler::isGuest() const
  244. {
  245. return !c || hostClientId != c->connectionID;
  246. }
  247. ui16 CServerHandler::getDefaultPort()
  248. {
  249. if(settings["session"]["serverport"].Integer())
  250. return settings["session"]["serverport"].Integer();
  251. else
  252. return settings["server"]["port"].Integer();
  253. }
  254. std::string CServerHandler::getDefaultPortStr()
  255. {
  256. return boost::lexical_cast<std::string>(getDefaultPort());
  257. }
  258. void CServerHandler::sendClientConnecting() const
  259. {
  260. LobbyClientConnected lcc;
  261. lcc.uuid = uuid;
  262. lcc.names = myNames;
  263. lcc.mode = si->mode;
  264. sendLobbyPack(lcc);
  265. }
  266. void CServerHandler::sendClientDisconnecting()
  267. {
  268. // FIXME: This is workaround needed to make sure client not trying to sent anything to non existed server
  269. if(state == EClientState::DISCONNECTING)
  270. return;
  271. state = EClientState::DISCONNECTING;
  272. LobbyClientDisconnected lcd;
  273. lcd.clientId = c->connectionID;
  274. logNetwork->info("Connection has been requested to be closed.");
  275. if(isServerLocal())
  276. {
  277. lcd.shutdownServer = true;
  278. logNetwork->info("Sent closing signal to the server");
  279. }
  280. else
  281. {
  282. logNetwork->info("Sent leaving signal to the server");
  283. }
  284. sendLobbyPack(lcd);
  285. }
  286. void CServerHandler::setCampaignState(std::shared_ptr<CCampaignState> newCampaign)
  287. {
  288. state = EClientState::LOBBY_CAMPAIGN;
  289. LobbySetCampaign lsc;
  290. lsc.ourCampaign = newCampaign;
  291. sendLobbyPack(lsc);
  292. }
  293. void CServerHandler::setCampaignMap(int mapId) const
  294. {
  295. if(state == EClientState::GAMEPLAY) // FIXME: UI shouldn't sent commands in first place
  296. return;
  297. LobbySetCampaignMap lscm;
  298. lscm.mapId = mapId;
  299. sendLobbyPack(lscm);
  300. }
  301. void CServerHandler::setCampaignBonus(int bonusId) const
  302. {
  303. if(state == EClientState::GAMEPLAY) // FIXME: UI shouldn't sent commands in first place
  304. return;
  305. LobbySetCampaignBonus lscb;
  306. lscb.bonusId = bonusId;
  307. sendLobbyPack(lscb);
  308. }
  309. void CServerHandler::setMapInfo(std::shared_ptr<CMapInfo> to, std::shared_ptr<CMapGenOptions> mapGenOpts) const
  310. {
  311. LobbySetMap lsm;
  312. lsm.mapInfo = to;
  313. lsm.mapGenOpts = mapGenOpts;
  314. sendLobbyPack(lsm);
  315. }
  316. void CServerHandler::setPlayer(PlayerColor color) const
  317. {
  318. LobbySetPlayer lsp;
  319. lsp.clickedColor = color;
  320. sendLobbyPack(lsp);
  321. }
  322. void CServerHandler::setPlayerOption(ui8 what, ui8 dir, PlayerColor player) const
  323. {
  324. LobbyChangePlayerOption lcpo;
  325. lcpo.what = what;
  326. lcpo.direction = dir;
  327. lcpo.color = player;
  328. sendLobbyPack(lcpo);
  329. }
  330. void CServerHandler::setDifficulty(int to) const
  331. {
  332. LobbySetDifficulty lsd;
  333. lsd.difficulty = to;
  334. sendLobbyPack(lsd);
  335. }
  336. void CServerHandler::setTurnLength(int npos) const
  337. {
  338. vstd::amin(npos, GameConstants::POSSIBLE_TURNTIME.size() - 1);
  339. LobbySetTurnTime lstt;
  340. lstt.turnTime = GameConstants::POSSIBLE_TURNTIME[npos];
  341. sendLobbyPack(lstt);
  342. }
  343. void CServerHandler::sendMessage(const std::string & txt) const
  344. {
  345. std::istringstream readed;
  346. readed.str(txt);
  347. std::string command;
  348. readed >> command;
  349. if(command == "!passhost")
  350. {
  351. std::string id;
  352. readed >> id;
  353. if(id.length())
  354. {
  355. LobbyChangeHost lch;
  356. lch.newHostConnectionId = boost::lexical_cast<int>(id);
  357. sendLobbyPack(lch);
  358. }
  359. }
  360. else if(command == "!forcep")
  361. {
  362. std::string connectedId, playerColorId;
  363. readed >> connectedId;
  364. readed >> playerColorId;
  365. if(connectedId.length(), playerColorId.length())
  366. {
  367. ui8 connected = boost::lexical_cast<int>(connectedId);
  368. auto color = PlayerColor(boost::lexical_cast<int>(playerColorId));
  369. if(color.isValidPlayer() && playerNames.find(connected) != playerNames.end())
  370. {
  371. LobbyForceSetPlayer lfsp;
  372. lfsp.targetConnectedPlayer = connected;
  373. lfsp.targetPlayerColor = color;
  374. sendLobbyPack(lfsp);
  375. }
  376. }
  377. }
  378. else
  379. {
  380. LobbyChatMessage lcm;
  381. lcm.message = txt;
  382. lcm.playerName = playerNames.find(myFirstId())->second.name;
  383. sendLobbyPack(lcm);
  384. }
  385. }
  386. void CServerHandler::sendGuiAction(ui8 action) const
  387. {
  388. LobbyGuiAction lga;
  389. lga.action = static_cast<LobbyGuiAction::EAction>(action);
  390. sendLobbyPack(lga);
  391. }
  392. void CServerHandler::sendStartGame(bool allowOnlyAI) const
  393. {
  394. verifyStateBeforeStart(allowOnlyAI ? true : settings["session"]["onlyai"].Bool());
  395. LobbyStartGame lsg;
  396. sendLobbyPack(lsg);
  397. }
  398. void CServerHandler::startGameplay()
  399. {
  400. if(CMM)
  401. CMM->disable();
  402. client = new CClient();
  403. switch(si->mode)
  404. {
  405. case StartInfo::NEW_GAME:
  406. client->newGame();
  407. break;
  408. case StartInfo::CAMPAIGN:
  409. client->newGame();
  410. break;
  411. case StartInfo::LOAD_GAME:
  412. client->loadGame();
  413. break;
  414. default:
  415. throw std::runtime_error("Invalid mode");
  416. }
  417. // After everything initialized we can accept CPackToClient netpacks
  418. c->enterGameplayConnectionMode(client->gameState());
  419. state = EClientState::GAMEPLAY;
  420. }
  421. void CServerHandler::endGameplay(bool closeConnection)
  422. {
  423. client->endGame();
  424. vstd::clear_pointer(client);
  425. if(closeConnection)
  426. {
  427. // Game is ending
  428. // Tell the network thread to reach a stable state
  429. CSH->sendClientDisconnecting();
  430. logNetwork->info("Closed connection.");
  431. }
  432. if(CMM)
  433. {
  434. GH.curInt = CMM;
  435. CMM->enable();
  436. }
  437. else
  438. {
  439. GH.curInt = CMainMenu::create();
  440. }
  441. }
  442. void CServerHandler::startCampaignScenario(std::shared_ptr<CCampaignState> cs)
  443. {
  444. SDL_Event event;
  445. event.type = SDL_USEREVENT;
  446. event.user.code = EUserEvent::CAMPAIGN_START_SCENARIO;
  447. if(cs)
  448. event.user.data1 = CMemorySerializer::deepCopy(*cs.get()).release();
  449. else
  450. event.user.data1 = CMemorySerializer::deepCopy(*si->campState.get()).release();
  451. SDL_PushEvent(&event);
  452. }
  453. int CServerHandler::howManyPlayerInterfaces()
  454. {
  455. int playerInts = 0;
  456. for(auto pint : client->playerint)
  457. {
  458. if(dynamic_cast<CPlayerInterface *>(pint.second.get()))
  459. playerInts++;
  460. }
  461. return playerInts;
  462. }
  463. ui8 CServerHandler::getLoadMode()
  464. {
  465. if(state == EClientState::GAMEPLAY)
  466. {
  467. if(si->campState)
  468. return ELoadMode::CAMPAIGN;
  469. for(auto pn : playerNames)
  470. {
  471. if(pn.second.connection != c->connectionID)
  472. return ELoadMode::MULTI;
  473. }
  474. return ELoadMode::SINGLE;
  475. }
  476. return loadMode;
  477. }
  478. void CServerHandler::debugStartTest(std::string filename, bool save)
  479. {
  480. logGlobal->info("Starting debug test with file: %s", filename);
  481. auto mapInfo = std::make_shared<CMapInfo>();
  482. if(save)
  483. {
  484. resetStateForLobby(StartInfo::LOAD_GAME);
  485. mapInfo->saveInit(ResourceID(filename, EResType::CLIENT_SAVEGAME));
  486. screenType = ESelectionScreen::loadGame;
  487. }
  488. else
  489. {
  490. resetStateForLobby(StartInfo::NEW_GAME);
  491. mapInfo->mapInit(filename);
  492. screenType = ESelectionScreen::newGame;
  493. }
  494. if(settings["session"]["donotstartserver"].Bool())
  495. justConnectToServer("127.0.0.1", 3030);
  496. else
  497. startLocalServerAndConnect();
  498. while(!settings["session"]["headless"].Bool() && !dynamic_cast<CLobbyScreen *>(GH.topInt()))
  499. boost::this_thread::sleep(boost::posix_time::milliseconds(50));
  500. while(!mi || mapInfo->fileURI != CSH->mi->fileURI)
  501. {
  502. setMapInfo(mapInfo);
  503. boost::this_thread::sleep(boost::posix_time::milliseconds(50));
  504. }
  505. // "Click" on color to remove us from it
  506. setPlayer(myFirstColor());
  507. while(myFirstColor() != PlayerColor::CANNOT_DETERMINE)
  508. boost::this_thread::sleep(boost::posix_time::milliseconds(50));
  509. while(true)
  510. {
  511. try
  512. {
  513. sendStartGame();
  514. break;
  515. }
  516. catch(...)
  517. {
  518. }
  519. boost::this_thread::sleep(boost::posix_time::milliseconds(50));
  520. }
  521. }
  522. void CServerHandler::threadHandleConnection()
  523. {
  524. setThreadName("CServerHandler::threadHandleConnection");
  525. c->enterLobbyConnectionMode();
  526. try
  527. {
  528. sendClientConnecting();
  529. while(c->connected)
  530. {
  531. while(state == EClientState::STARTING)
  532. boost::this_thread::sleep(boost::posix_time::milliseconds(10));
  533. CPack * pack = c->retrievePack();
  534. if(state == EClientState::DISCONNECTING)
  535. {
  536. // FIXME: server shouldn't really send netpacks after it's tells client to disconnect
  537. // Though currently they'll be delivered and might cause crash.
  538. vstd::clear_pointer(pack);
  539. }
  540. else if(auto lobbyPack = dynamic_cast<CPackForLobby *>(pack))
  541. {
  542. if(applier->getApplier(typeList.getTypeID(pack))->applyOnLobbyHandler(this, pack))
  543. {
  544. if(!settings["session"]["headless"].Bool())
  545. {
  546. boost::unique_lock<boost::recursive_mutex> lock(*mx);
  547. packsForLobbyScreen.push_back(lobbyPack);
  548. }
  549. }
  550. }
  551. else if(auto clientPack = dynamic_cast<CPackForClient *>(pack))
  552. {
  553. client->handlePack(clientPack);
  554. }
  555. }
  556. }
  557. //catch only asio exceptions
  558. catch(const boost::system::system_error & e)
  559. {
  560. if(state == EClientState::DISCONNECTING)
  561. {
  562. logNetwork->info("Successfully closed connection to server, ending listening thread!");
  563. }
  564. else
  565. {
  566. logNetwork->error("Lost connection to server, ending listening thread!");
  567. logNetwork->error(e.what());
  568. if(client)
  569. {
  570. CGuiHandler::pushSDLEvent(SDL_USEREVENT, EUserEvent::RETURN_TO_MAIN_MENU);
  571. }
  572. else
  573. {
  574. auto lcd = new LobbyClientDisconnected();
  575. lcd->clientId = c->connectionID;
  576. boost::unique_lock<boost::recursive_mutex> lock(*mx);
  577. packsForLobbyScreen.push_back(lcd);
  578. }
  579. }
  580. }
  581. catch(...)
  582. {
  583. handleException();
  584. throw;
  585. }
  586. }
  587. void CServerHandler::threadRunServer()
  588. {
  589. #ifndef VCMI_ANDROID
  590. setThreadName("CServerHandler::threadRunServer");
  591. const std::string logName = (VCMIDirs::get().userCachePath() / "server_log.txt").string();
  592. std::string comm = VCMIDirs::get().serverPath().string()
  593. + " --port=" + getDefaultPortStr()
  594. + " --run-by-client"
  595. + " --uuid=" + uuid;
  596. if(shm)
  597. {
  598. comm += " --enable-shm";
  599. if(settings["session"]["enable-shm-uuid"].Bool())
  600. comm += " --enable-shm-uuid";
  601. }
  602. comm += " > \"" + logName + '\"';
  603. int result = std::system(comm.c_str());
  604. if (result == 0)
  605. {
  606. logNetwork->info("Server closed correctly");
  607. }
  608. else
  609. {
  610. logNetwork->error("Error: server failed to close correctly or crashed!");
  611. logNetwork->error("Check %s for more info", logName);
  612. }
  613. threadRunLocalServer.reset();
  614. #endif
  615. }
  616. void CServerHandler::sendLobbyPack(const CPackForLobby & pack) const
  617. {
  618. if(state != EClientState::STARTING)
  619. c->sendPack(&pack);
  620. }