CServerHandler.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  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.reset(new 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. client = new CClient();
  395. switch(si->mode)
  396. {
  397. case StartInfo::NEW_GAME:
  398. client->newGame();
  399. break;
  400. case StartInfo::CAMPAIGN:
  401. client->newGame();
  402. break;
  403. case StartInfo::LOAD_GAME:
  404. client->loadGame();
  405. break;
  406. default:
  407. throw std::runtime_error("Invalid mode");
  408. }
  409. // After everything initialized we can accept CPackToClient netpacks
  410. c->enterGameplayConnectionMode(client->gameState());
  411. state = EClientState::GAMEPLAY;
  412. }
  413. void CServerHandler::endGameplay(bool closeConnection)
  414. {
  415. client->endGame();
  416. vstd::clear_pointer(client);
  417. // Game is ending
  418. // Tell the network thread to reach a stable state
  419. CSH->sendClientDisconnecting();
  420. logNetwork->info("Closed connection.");
  421. }
  422. void CServerHandler::startCampaignScenario(std::shared_ptr<CCampaignState> cs)
  423. {
  424. SDL_Event event;
  425. event.type = SDL_USEREVENT;
  426. event.user.code = EUserEvent::CAMPAIGN_START_SCENARIO;
  427. if(cs)
  428. event.user.data1 = CMemorySerializer::deepCopy(*cs.get()).release();
  429. else
  430. event.user.data1 = CMemorySerializer::deepCopy(*si->campState.get()).release();
  431. SDL_PushEvent(&event);
  432. }
  433. int CServerHandler::howManyPlayerInterfaces()
  434. {
  435. int playerInts = 0;
  436. for(auto pint : client->playerint)
  437. {
  438. if(dynamic_cast<CPlayerInterface *>(pint.second.get()))
  439. playerInts++;
  440. }
  441. return playerInts;
  442. }
  443. ui8 CServerHandler::getLoadMode()
  444. {
  445. if(state == EClientState::GAMEPLAY)
  446. {
  447. if(si->campState)
  448. return ELoadMode::CAMPAIGN;
  449. for(auto pn : playerNames)
  450. {
  451. if(pn.second.connection != c->connectionID)
  452. return ELoadMode::MULTI;
  453. }
  454. return ELoadMode::SINGLE;
  455. }
  456. return loadMode;
  457. }
  458. void CServerHandler::debugStartTest(std::string filename, bool save)
  459. {
  460. logGlobal->info("Starting debug test with file: %s", filename);
  461. auto mapInfo = std::make_shared<CMapInfo>();
  462. if(save)
  463. {
  464. resetStateForLobby(StartInfo::LOAD_GAME);
  465. mapInfo->saveInit(ResourceID(filename, EResType::CLIENT_SAVEGAME));
  466. screenType = ESelectionScreen::loadGame;
  467. }
  468. else
  469. {
  470. resetStateForLobby(StartInfo::NEW_GAME);
  471. mapInfo->mapInit(filename);
  472. screenType = ESelectionScreen::newGame;
  473. }
  474. if(settings["session"]["donotstartserver"].Bool())
  475. justConnectToServer("127.0.0.1", 3030);
  476. else
  477. startLocalServerAndConnect();
  478. while(!settings["session"]["headless"].Bool() && !dynamic_cast<CLobbyScreen *>(GH.topInt()))
  479. boost::this_thread::sleep(boost::posix_time::milliseconds(50));
  480. while(!mi || mapInfo->fileURI != CSH->mi->fileURI)
  481. {
  482. setMapInfo(mapInfo);
  483. boost::this_thread::sleep(boost::posix_time::milliseconds(50));
  484. }
  485. // "Click" on color to remove us from it
  486. setPlayer(myFirstColor());
  487. while(myFirstColor() != PlayerColor::CANNOT_DETERMINE)
  488. boost::this_thread::sleep(boost::posix_time::milliseconds(50));
  489. while(true)
  490. {
  491. try
  492. {
  493. sendStartGame();
  494. break;
  495. }
  496. catch(...)
  497. {
  498. }
  499. boost::this_thread::sleep(boost::posix_time::milliseconds(50));
  500. }
  501. }
  502. void CServerHandler::threadHandleConnection()
  503. {
  504. setThreadName("CServerHandler::threadHandleConnection");
  505. c->enterLobbyConnectionMode();
  506. try
  507. {
  508. sendClientConnecting();
  509. while(c->connected)
  510. {
  511. while(state == EClientState::STARTING)
  512. boost::this_thread::sleep(boost::posix_time::milliseconds(10));
  513. CPack * pack = c->retrievePack();
  514. if(state == EClientState::DISCONNECTING)
  515. {
  516. // FIXME: server shouldn't really send netpacks after it's tells client to disconnect
  517. // Though currently they'll be delivered and might cause crash.
  518. vstd::clear_pointer(pack);
  519. }
  520. else if(auto lobbyPack = dynamic_cast<CPackForLobby *>(pack))
  521. {
  522. if(applier->getApplier(typeList.getTypeID(pack))->applyOnLobbyHandler(this, pack))
  523. {
  524. if(!settings["session"]["headless"].Bool())
  525. {
  526. boost::unique_lock<boost::recursive_mutex> lock(*mx);
  527. packsForLobbyScreen.push_back(lobbyPack);
  528. }
  529. }
  530. }
  531. else if(auto clientPack = dynamic_cast<CPackForClient *>(pack))
  532. {
  533. client->handlePack(clientPack);
  534. }
  535. }
  536. }
  537. //catch only asio exceptions
  538. catch(const boost::system::system_error & e)
  539. {
  540. if(state == EClientState::DISCONNECTING)
  541. {
  542. logNetwork->info("Successfully closed connection to server, ending listening thread!");
  543. }
  544. else
  545. {
  546. logNetwork->error("Lost connection to server, ending listening thread!");
  547. logNetwork->error(e.what());
  548. if(client)
  549. {
  550. CGuiHandler::pushSDLEvent(SDL_USEREVENT, EUserEvent::RETURN_TO_MAIN_MENU);
  551. }
  552. else
  553. {
  554. auto lcd = new LobbyClientDisconnected();
  555. lcd->clientId = c->connectionID;
  556. boost::unique_lock<boost::recursive_mutex> lock(*mx);
  557. packsForLobbyScreen.push_back(lcd);
  558. }
  559. }
  560. }
  561. catch(...)
  562. {
  563. handleException();
  564. throw;
  565. }
  566. }
  567. void CServerHandler::threadRunServer()
  568. {
  569. #ifndef VCMI_ANDROID
  570. setThreadName("CServerHandler::threadRunServer");
  571. const std::string logName = (VCMIDirs::get().userCachePath() / "server_log.txt").string();
  572. std::string comm = VCMIDirs::get().serverPath().string()
  573. + " --port=" + getDefaultPortStr()
  574. + " --run-by-client"
  575. + " --uuid=" + uuid;
  576. if(shm)
  577. {
  578. comm += " --enable-shm";
  579. if(settings["session"]["enable-shm-uuid"].Bool())
  580. comm += " --enable-shm-uuid";
  581. }
  582. comm += " > \"" + logName + '\"';
  583. int result = std::system(comm.c_str());
  584. if (result == 0)
  585. {
  586. logNetwork->info("Server closed correctly");
  587. }
  588. else
  589. {
  590. logNetwork->error("Error: server failed to close correctly or crashed!");
  591. logNetwork->error("Check %s for more info", logName);
  592. }
  593. threadRunLocalServer.reset();
  594. #endif
  595. }
  596. void CServerHandler::sendLobbyPack(const CPackForLobby & pack) const
  597. {
  598. if(state != EClientState::STARTING)
  599. c->sendPack(&pack);
  600. }