CServerHandler.cpp 17 KB

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