CServerHandler.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  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. {
  140. CAndroidVMHelper envHelper;
  141. envHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "startServer", true);
  142. }
  143. #else
  144. threadRunLocalServer = std::make_shared<boost::thread>(&CServerHandler::threadRunServer, this); //runs server executable;
  145. #endif
  146. logNetwork->trace("Setting up thread calling server: %d ms", th->getDiff());
  147. th->update();
  148. #ifndef VCMI_ANDROID
  149. if(shm)
  150. shm->sr->waitTillReady();
  151. #else
  152. logNetwork->info("waiting for server");
  153. while(!androidTestServerReadyFlag.load())
  154. {
  155. logNetwork->info("still waiting...");
  156. boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
  157. }
  158. logNetwork->info("waiting for server finished...");
  159. androidTestServerReadyFlag = false;
  160. #endif
  161. logNetwork->trace("Waiting for server: %d ms", th->getDiff());
  162. th->update(); //put breakpoint here to attach to server before it does something stupid
  163. #ifndef VCMI_ANDROID
  164. justConnectToServer(settings["server"]["server"].String(), shm ? shm->sr->port : 0);
  165. #else
  166. justConnectToServer(settings["server"]["server"].String());
  167. #endif
  168. logNetwork->trace("\tConnecting to the server: %d ms", th->getDiff());
  169. }
  170. void CServerHandler::justConnectToServer(const std::string & addr, const ui16 port)
  171. {
  172. state = EClientState::CONNECTING;
  173. while(!c && state != EClientState::CONNECTION_CANCELLED)
  174. {
  175. try
  176. {
  177. logNetwork->info("Establishing connection...");
  178. c = std::make_shared<CConnection>(
  179. addr.size() ? addr : settings["server"]["server"].String(),
  180. port ? port : getDefaultPort(),
  181. NAME, uuid);
  182. }
  183. catch(...)
  184. {
  185. logNetwork->error("\nCannot establish connection! Retrying within 1 second");
  186. boost::this_thread::sleep(boost::posix_time::seconds(1));
  187. }
  188. }
  189. if(state == EClientState::CONNECTION_CANCELLED)
  190. logNetwork->info("Connection aborted by player!");
  191. else
  192. c->handler = std::make_shared<boost::thread>(&CServerHandler::threadHandleConnection, this);
  193. }
  194. void CServerHandler::applyPacksOnLobbyScreen()
  195. {
  196. if(!c || !c->handler)
  197. return;
  198. boost::unique_lock<boost::recursive_mutex> lock(*mx);
  199. while(!packsForLobbyScreen.empty())
  200. {
  201. CPackForLobby * pack = packsForLobbyScreen.front();
  202. packsForLobbyScreen.pop_front();
  203. CBaseForLobbyApply * apply = applier->getApplier(typeList.getTypeID(pack)); //find the applier
  204. apply->applyOnLobbyScreen(static_cast<CLobbyScreen *>(SEL), this, pack);
  205. GH.totalRedraw();
  206. delete pack;
  207. }
  208. }
  209. void CServerHandler::stopServerConnection()
  210. {
  211. if(c->handler)
  212. {
  213. while(!c->handler->timed_join(boost::posix_time::milliseconds(50)))
  214. applyPacksOnLobbyScreen();
  215. c->handler->join();
  216. }
  217. }
  218. std::set<PlayerColor> CServerHandler::getHumanColors()
  219. {
  220. return clientHumanColors(c->connectionID);
  221. }
  222. PlayerColor CServerHandler::myFirstColor() const
  223. {
  224. return clientFirstColor(c->connectionID);
  225. }
  226. bool CServerHandler::isMyColor(PlayerColor color) const
  227. {
  228. return isClientColor(c->connectionID, color);
  229. }
  230. ui8 CServerHandler::myFirstId() const
  231. {
  232. return clientFirstId(c->connectionID);
  233. }
  234. bool CServerHandler::isServerLocal() const
  235. {
  236. if(threadRunLocalServer)
  237. return true;
  238. return false;
  239. }
  240. bool CServerHandler::isHost() const
  241. {
  242. return c && hostClientId == c->connectionID;
  243. }
  244. bool CServerHandler::isGuest() const
  245. {
  246. return !c || hostClientId != c->connectionID;
  247. }
  248. ui16 CServerHandler::getDefaultPort()
  249. {
  250. if(settings["session"]["serverport"].Integer())
  251. return settings["session"]["serverport"].Integer();
  252. else
  253. return settings["server"]["port"].Integer();
  254. }
  255. std::string CServerHandler::getDefaultPortStr()
  256. {
  257. return boost::lexical_cast<std::string>(getDefaultPort());
  258. }
  259. void CServerHandler::sendClientConnecting() const
  260. {
  261. LobbyClientConnected lcc;
  262. lcc.uuid = uuid;
  263. lcc.names = myNames;
  264. lcc.mode = si->mode;
  265. sendLobbyPack(lcc);
  266. }
  267. void CServerHandler::sendClientDisconnecting()
  268. {
  269. // FIXME: This is workaround needed to make sure client not trying to sent anything to non existed server
  270. if(state == EClientState::DISCONNECTING)
  271. return;
  272. state = EClientState::DISCONNECTING;
  273. LobbyClientDisconnected lcd;
  274. lcd.clientId = c->connectionID;
  275. logNetwork->info("Connection has been requested to be closed.");
  276. if(isServerLocal())
  277. {
  278. lcd.shutdownServer = true;
  279. logNetwork->info("Sent closing signal to the server");
  280. }
  281. else
  282. {
  283. logNetwork->info("Sent leaving signal to the server");
  284. }
  285. sendLobbyPack(lcd);
  286. }
  287. void CServerHandler::setCampaignState(std::shared_ptr<CCampaignState> newCampaign)
  288. {
  289. state = EClientState::LOBBY_CAMPAIGN;
  290. LobbySetCampaign lsc;
  291. lsc.ourCampaign = newCampaign;
  292. sendLobbyPack(lsc);
  293. }
  294. void CServerHandler::setCampaignMap(int mapId) const
  295. {
  296. if(state == EClientState::GAMEPLAY) // FIXME: UI shouldn't sent commands in first place
  297. return;
  298. LobbySetCampaignMap lscm;
  299. lscm.mapId = mapId;
  300. sendLobbyPack(lscm);
  301. }
  302. void CServerHandler::setCampaignBonus(int bonusId) const
  303. {
  304. if(state == EClientState::GAMEPLAY) // FIXME: UI shouldn't sent commands in first place
  305. return;
  306. LobbySetCampaignBonus lscb;
  307. lscb.bonusId = bonusId;
  308. sendLobbyPack(lscb);
  309. }
  310. void CServerHandler::setMapInfo(std::shared_ptr<CMapInfo> to, std::shared_ptr<CMapGenOptions> mapGenOpts) const
  311. {
  312. LobbySetMap lsm;
  313. lsm.mapInfo = to;
  314. lsm.mapGenOpts = mapGenOpts;
  315. sendLobbyPack(lsm);
  316. }
  317. void CServerHandler::setPlayer(PlayerColor color) const
  318. {
  319. LobbySetPlayer lsp;
  320. lsp.clickedColor = color;
  321. sendLobbyPack(lsp);
  322. }
  323. void CServerHandler::setPlayerOption(ui8 what, ui8 dir, PlayerColor player) const
  324. {
  325. LobbyChangePlayerOption lcpo;
  326. lcpo.what = what;
  327. lcpo.direction = dir;
  328. lcpo.color = player;
  329. sendLobbyPack(lcpo);
  330. }
  331. void CServerHandler::setDifficulty(int to) const
  332. {
  333. LobbySetDifficulty lsd;
  334. lsd.difficulty = to;
  335. sendLobbyPack(lsd);
  336. }
  337. void CServerHandler::setTurnLength(int npos) const
  338. {
  339. vstd::amin(npos, GameConstants::POSSIBLE_TURNTIME.size() - 1);
  340. LobbySetTurnTime lstt;
  341. lstt.turnTime = GameConstants::POSSIBLE_TURNTIME[npos];
  342. sendLobbyPack(lstt);
  343. }
  344. void CServerHandler::sendMessage(const std::string & txt) const
  345. {
  346. std::istringstream readed;
  347. readed.str(txt);
  348. std::string command;
  349. readed >> command;
  350. if(command == "!passhost")
  351. {
  352. std::string id;
  353. readed >> id;
  354. if(id.length())
  355. {
  356. LobbyChangeHost lch;
  357. lch.newHostConnectionId = boost::lexical_cast<int>(id);
  358. sendLobbyPack(lch);
  359. }
  360. }
  361. else if(command == "!forcep")
  362. {
  363. std::string connectedId, playerColorId;
  364. readed >> connectedId;
  365. readed >> playerColorId;
  366. if(connectedId.length(), playerColorId.length())
  367. {
  368. ui8 connected = boost::lexical_cast<int>(connectedId);
  369. auto color = PlayerColor(boost::lexical_cast<int>(playerColorId));
  370. if(color.isValidPlayer() && playerNames.find(connected) != playerNames.end())
  371. {
  372. LobbyForceSetPlayer lfsp;
  373. lfsp.targetConnectedPlayer = connected;
  374. lfsp.targetPlayerColor = color;
  375. sendLobbyPack(lfsp);
  376. }
  377. }
  378. }
  379. else
  380. {
  381. LobbyChatMessage lcm;
  382. lcm.message = txt;
  383. lcm.playerName = playerNames.find(myFirstId())->second.name;
  384. sendLobbyPack(lcm);
  385. }
  386. }
  387. void CServerHandler::sendGuiAction(ui8 action) const
  388. {
  389. LobbyGuiAction lga;
  390. lga.action = static_cast<LobbyGuiAction::EAction>(action);
  391. sendLobbyPack(lga);
  392. }
  393. void CServerHandler::sendStartGame(bool allowOnlyAI) const
  394. {
  395. verifyStateBeforeStart(allowOnlyAI ? true : settings["session"]["onlyai"].Bool());
  396. LobbyStartGame lsg;
  397. sendLobbyPack(lsg);
  398. }
  399. void CServerHandler::startGameplay()
  400. {
  401. if(CMM)
  402. CMM->disable();
  403. client = new CClient();
  404. switch(si->mode)
  405. {
  406. case StartInfo::NEW_GAME:
  407. client->newGame();
  408. break;
  409. case StartInfo::CAMPAIGN:
  410. client->newGame();
  411. break;
  412. case StartInfo::LOAD_GAME:
  413. client->loadGame();
  414. break;
  415. default:
  416. throw std::runtime_error("Invalid mode");
  417. }
  418. // After everything initialized we can accept CPackToClient netpacks
  419. c->enterGameplayConnectionMode(client->gameState());
  420. state = EClientState::GAMEPLAY;
  421. }
  422. void CServerHandler::endGameplay(bool closeConnection, bool restart)
  423. {
  424. client->endGame();
  425. vstd::clear_pointer(client);
  426. if(closeConnection)
  427. {
  428. // Game is ending
  429. // Tell the network thread to reach a stable state
  430. CSH->sendClientDisconnecting();
  431. logNetwork->info("Closed connection.");
  432. }
  433. if(!restart)
  434. {
  435. if(CMM)
  436. {
  437. GH.curInt = CMM.get();
  438. CMM->enable();
  439. }
  440. else
  441. {
  442. GH.curInt = CMainMenu::create().get();
  443. }
  444. }
  445. }
  446. void CServerHandler::startCampaignScenario(std::shared_ptr<CCampaignState> cs)
  447. {
  448. SDL_Event event;
  449. event.type = SDL_USEREVENT;
  450. event.user.code = EUserEvent::CAMPAIGN_START_SCENARIO;
  451. if(cs)
  452. event.user.data1 = CMemorySerializer::deepCopy(*cs.get()).release();
  453. else
  454. event.user.data1 = CMemorySerializer::deepCopy(*si->campState.get()).release();
  455. SDL_PushEvent(&event);
  456. }
  457. int CServerHandler::howManyPlayerInterfaces()
  458. {
  459. int playerInts = 0;
  460. for(auto pint : client->playerint)
  461. {
  462. if(dynamic_cast<CPlayerInterface *>(pint.second.get()))
  463. playerInts++;
  464. }
  465. return playerInts;
  466. }
  467. ui8 CServerHandler::getLoadMode()
  468. {
  469. if(state == EClientState::GAMEPLAY)
  470. {
  471. if(si->campState)
  472. return ELoadMode::CAMPAIGN;
  473. for(auto pn : playerNames)
  474. {
  475. if(pn.second.connection != c->connectionID)
  476. return ELoadMode::MULTI;
  477. }
  478. return ELoadMode::SINGLE;
  479. }
  480. return loadMode;
  481. }
  482. void CServerHandler::debugStartTest(std::string filename, bool save)
  483. {
  484. logGlobal->info("Starting debug test with file: %s", filename);
  485. auto mapInfo = std::make_shared<CMapInfo>();
  486. if(save)
  487. {
  488. resetStateForLobby(StartInfo::LOAD_GAME);
  489. mapInfo->saveInit(ResourceID(filename, EResType::CLIENT_SAVEGAME));
  490. screenType = ESelectionScreen::loadGame;
  491. }
  492. else
  493. {
  494. resetStateForLobby(StartInfo::NEW_GAME);
  495. mapInfo->mapInit(filename);
  496. screenType = ESelectionScreen::newGame;
  497. }
  498. if(settings["session"]["donotstartserver"].Bool())
  499. justConnectToServer("127.0.0.1", 3030);
  500. else
  501. startLocalServerAndConnect();
  502. while(!settings["session"]["headless"].Bool() && !dynamic_cast<CLobbyScreen *>(GH.topInt().get()))
  503. boost::this_thread::sleep(boost::posix_time::milliseconds(50));
  504. while(!mi || mapInfo->fileURI != CSH->mi->fileURI)
  505. {
  506. setMapInfo(mapInfo);
  507. boost::this_thread::sleep(boost::posix_time::milliseconds(50));
  508. }
  509. // "Click" on color to remove us from it
  510. setPlayer(myFirstColor());
  511. while(myFirstColor() != PlayerColor::CANNOT_DETERMINE)
  512. boost::this_thread::sleep(boost::posix_time::milliseconds(50));
  513. while(true)
  514. {
  515. try
  516. {
  517. sendStartGame();
  518. break;
  519. }
  520. catch(...)
  521. {
  522. }
  523. boost::this_thread::sleep(boost::posix_time::milliseconds(50));
  524. }
  525. }
  526. void CServerHandler::threadHandleConnection()
  527. {
  528. setThreadName("CServerHandler::threadHandleConnection");
  529. c->enterLobbyConnectionMode();
  530. try
  531. {
  532. sendClientConnecting();
  533. while(c->connected)
  534. {
  535. while(state == EClientState::STARTING)
  536. boost::this_thread::sleep(boost::posix_time::milliseconds(10));
  537. CPack * pack = c->retrievePack();
  538. if(state == EClientState::DISCONNECTING)
  539. {
  540. // FIXME: server shouldn't really send netpacks after it's tells client to disconnect
  541. // Though currently they'll be delivered and might cause crash.
  542. vstd::clear_pointer(pack);
  543. }
  544. else if(auto lobbyPack = dynamic_cast<CPackForLobby *>(pack))
  545. {
  546. if(applier->getApplier(typeList.getTypeID(pack))->applyOnLobbyHandler(this, pack))
  547. {
  548. if(!settings["session"]["headless"].Bool())
  549. {
  550. boost::unique_lock<boost::recursive_mutex> lock(*mx);
  551. packsForLobbyScreen.push_back(lobbyPack);
  552. }
  553. }
  554. }
  555. else if(auto clientPack = dynamic_cast<CPackForClient *>(pack))
  556. {
  557. client->handlePack(clientPack);
  558. }
  559. }
  560. }
  561. //catch only asio exceptions
  562. catch(const boost::system::system_error & e)
  563. {
  564. if(state == EClientState::DISCONNECTING)
  565. {
  566. logNetwork->info("Successfully closed connection to server, ending listening thread!");
  567. }
  568. else
  569. {
  570. logNetwork->error("Lost connection to server, ending listening thread!");
  571. logNetwork->error(e.what());
  572. if(client)
  573. {
  574. CGuiHandler::pushSDLEvent(SDL_USEREVENT, EUserEvent::RETURN_TO_MAIN_MENU);
  575. }
  576. else
  577. {
  578. auto lcd = new LobbyClientDisconnected();
  579. lcd->clientId = c->connectionID;
  580. boost::unique_lock<boost::recursive_mutex> lock(*mx);
  581. packsForLobbyScreen.push_back(lcd);
  582. }
  583. }
  584. }
  585. catch(...)
  586. {
  587. handleException();
  588. throw;
  589. }
  590. }
  591. void CServerHandler::threadRunServer()
  592. {
  593. #ifndef VCMI_ANDROID
  594. setThreadName("CServerHandler::threadRunServer");
  595. const std::string logName = (VCMIDirs::get().userCachePath() / "server_log.txt").string();
  596. std::string comm = VCMIDirs::get().serverPath().string()
  597. + " --port=" + getDefaultPortStr()
  598. + " --run-by-client"
  599. + " --uuid=" + uuid;
  600. if(shm)
  601. {
  602. comm += " --enable-shm";
  603. if(settings["session"]["enable-shm-uuid"].Bool())
  604. comm += " --enable-shm-uuid";
  605. }
  606. comm += " > \"" + logName + '\"';
  607. int result = std::system(comm.c_str());
  608. if (result == 0)
  609. {
  610. logNetwork->info("Server closed correctly");
  611. }
  612. else
  613. {
  614. logNetwork->error("Error: server failed to close correctly or crashed!");
  615. logNetwork->error("Check %s for more info", logName);
  616. }
  617. threadRunLocalServer.reset();
  618. #endif
  619. }
  620. void CServerHandler::sendLobbyPack(const CPackForLobby & pack) const
  621. {
  622. if(state != EClientState::STARTING)
  623. c->sendPack(&pack);
  624. }