Client.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. #include "CMusicHandler.h"
  2. #include "../lib/CCampaignHandler.h"
  3. #include "../CCallback.h"
  4. #include "../CConsoleHandler.h"
  5. #include "CGameInfo.h"
  6. #include "../lib/CGameState.h"
  7. #include "CPlayerInterface.h"
  8. #include "../StartInfo.h"
  9. #include "../lib/BattleState.h"
  10. #include "../lib/CArtHandler.h"
  11. #include "../lib/CDefObjInfoHandler.h"
  12. #include "../lib/CGeneralTextHandler.h"
  13. #include "../lib/CHeroHandler.h"
  14. #include "../lib/CTownHandler.h"
  15. #include "../lib/CObjectHandler.h"
  16. #include "../lib/CBuildingHandler.h"
  17. #include "../lib/CSpellHandler.h"
  18. #include "../lib/Connection.h"
  19. #include "../lib/Interprocess.h"
  20. #include "../lib/NetPacks.h"
  21. #include "../lib/VCMI_Lib.h"
  22. #include "../lib/map.h"
  23. #include "mapHandler.h"
  24. #include "CConfigHandler.h"
  25. #include "Client.h"
  26. #include "GUIBase.h"
  27. #include <boost/bind.hpp>
  28. #include <boost/foreach.hpp>
  29. #include <boost/thread.hpp>
  30. #include <boost/thread/shared_mutex.hpp>
  31. #include <boost/lexical_cast.hpp>
  32. #include <sstream>
  33. #include "CPreGame.h"
  34. #include "CBattleInterface.h"
  35. #include "../CThreadHelper.h"
  36. #include "../lib/ERMScriptModule.h"
  37. #define NOT_LIB
  38. #include "../lib/RegisterTypes.cpp"
  39. extern std::string NAME;
  40. namespace intpr = boost::interprocess;
  41. /*
  42. * Client.cpp, part of VCMI engine
  43. *
  44. * Authors: listed in file AUTHORS in main folder
  45. *
  46. * License: GNU General Public License v2.0 or later
  47. * Full text of license available in license.txt file, in main folder
  48. *
  49. */
  50. template <typename T> class CApplyOnCL;
  51. class CBaseForCLApply
  52. {
  53. public:
  54. virtual void applyOnClAfter(CClient *cl, void *pack) const =0;
  55. virtual void applyOnClBefore(CClient *cl, void *pack) const =0;
  56. virtual ~CBaseForCLApply(){}
  57. template<typename U> static CBaseForCLApply *getApplier(const U * t=NULL)
  58. {
  59. return new CApplyOnCL<U>;
  60. }
  61. };
  62. template <typename T> class CApplyOnCL : public CBaseForCLApply
  63. {
  64. public:
  65. void applyOnClAfter(CClient *cl, void *pack) const
  66. {
  67. T *ptr = static_cast<T*>(pack);
  68. ptr->applyCl(cl);
  69. }
  70. void applyOnClBefore(CClient *cl, void *pack) const
  71. {
  72. T *ptr = static_cast<T*>(pack);
  73. ptr->applyFirstCl(cl);
  74. }
  75. };
  76. static CApplier<CBaseForCLApply> *applier = NULL;
  77. void CClient::init()
  78. {
  79. hotSeat = false;
  80. connectionHandler = NULL;
  81. pathInfo = NULL;
  82. applier = new CApplier<CBaseForCLApply>;
  83. registerTypes2(*applier);
  84. IObjectInterface::cb = this;
  85. serv = NULL;
  86. gs = NULL;
  87. cb = NULL;
  88. erm = NULL;
  89. terminate = false;
  90. }
  91. CClient::CClient(void)
  92. :waitingRequest(false)
  93. {
  94. init();
  95. }
  96. CClient::CClient(CConnection *con, StartInfo *si)
  97. :waitingRequest(false)
  98. {
  99. init();
  100. newGame(con,si);
  101. }
  102. CClient::~CClient(void)
  103. {
  104. delete pathInfo;
  105. delete applier;
  106. }
  107. void CClient::waitForMoveAndSend(int color)
  108. {
  109. try
  110. {
  111. assert(vstd::contains(battleints, color));
  112. BattleAction ba = battleints[color]->activeStack(gs->curB->getStack(gs->curB->activeStack, false));
  113. *serv << &MakeAction(ba);
  114. return;
  115. }HANDLE_EXCEPTION
  116. tlog1 << "We should not be here!" << std::endl;
  117. }
  118. void CClient::run()
  119. {
  120. setThreadName(-1, "CClient::run");
  121. try
  122. {
  123. CPack *pack = NULL;
  124. while(!terminate)
  125. {
  126. pack = serv->retreivePack(); //get the package from the server
  127. if (terminate)
  128. {
  129. delete pack;
  130. pack = NULL;
  131. break;
  132. }
  133. handlePack(pack);
  134. pack = NULL;
  135. }
  136. }
  137. catch (const std::exception& e)
  138. {
  139. tlog3 << "Lost connection to server, ending listening thread!\n";
  140. tlog1 << e.what() << std::endl;
  141. if(!terminate) //rethrow (-> boom!) only if closing connection was unexpected
  142. {
  143. tlog1 << "Something wrong, lost connection while game is still ongoing...\n";
  144. throw;
  145. }
  146. }
  147. }
  148. void CClient::save(const std::string & fname)
  149. {
  150. if(gs->curB)
  151. {
  152. tlog1 << "Game cannot be saved during battle!\n";
  153. return;
  154. }
  155. *serv << &SaveGame(fname);
  156. }
  157. #include <fstream>
  158. void initVillagesCapitols(Mapa * map)
  159. {
  160. std::ifstream ifs(DATA_DIR "/config/townsDefs.txt");
  161. int ccc;
  162. ifs>>ccc;
  163. for(int i=0;i<ccc*2;i++)
  164. {
  165. const CGDefInfo *n;
  166. if(i<ccc)
  167. {
  168. n = CGI->state->villages[i];
  169. map->defy.push_back(CGI->state->forts[i]);
  170. }
  171. else
  172. n = CGI->state->capitols[i%ccc];
  173. ifs >> const_cast<CGDefInfo*>(n)->name;
  174. if(!n)
  175. tlog1 << "*HUGE* Warning - missing town def for " << i << std::endl;
  176. else
  177. map->defy.push_back(const_cast<CGDefInfo*>(n));
  178. }
  179. }
  180. void CClient::endGame( bool closeConnection /*= true*/ )
  181. {
  182. // Game is ending
  183. // Tell the network thread to reach a stable state
  184. if(closeConnection)
  185. stopConnection();
  186. tlog0 << "Closed connection." << std::endl;
  187. GH.curInt = NULL;
  188. LOCPLINT->terminate_cond.setn(true);
  189. LOCPLINT->pim->lock();
  190. tlog0 << "\n\nEnding current game!" << std::endl;
  191. if(GH.topInt())
  192. GH.topInt()->deactivate();
  193. GH.listInt.clear();
  194. GH.objsToBlit.clear();
  195. GH.statusbar = NULL;
  196. tlog0 << "Removed GUI." << std::endl;
  197. delete CGI->mh;
  198. const_cast<CGameInfo*>(CGI)->mh = NULL;
  199. const_cast<CGameInfo*>(CGI)->state.dellNull();
  200. tlog0 << "Deleted mapHandler and gameState." << std::endl;
  201. CPlayerInterface * oldInt = LOCPLINT;
  202. LOCPLINT = NULL;
  203. oldInt->pim->unlock();
  204. while (!playerint.empty())
  205. {
  206. CGameInterface *pint = playerint.begin()->second;
  207. playerint.erase(playerint.begin());
  208. delete pint;
  209. }
  210. BOOST_FOREACH(CCallback *cb, callbacks)
  211. {
  212. delete cb;
  213. }
  214. tlog0 << "Deleted playerInts." << std::endl;
  215. tlog0 << "Client stopped." << std::endl;
  216. }
  217. void CClient::loadGame( const std::string & fname )
  218. {
  219. tlog0 <<"\n\nLoading procedure started!\n\n";
  220. CServerHandler sh;
  221. sh.startServer();
  222. timeHandler tmh;
  223. {
  224. char sig[8];
  225. CMapHeader dum;
  226. const_cast<CGameInfo*>(CGI)->mh = new CMapHandler();
  227. StartInfo *si;
  228. CLoadFile lf(fname + ".vlgm1");
  229. lf >> sig >> dum >> si;
  230. tlog0 <<"Reading save signature: "<<tmh.getDif()<<std::endl;
  231. lf >> *VLC;
  232. const_cast<CGameInfo*>(CGI)->setFromLib();
  233. tlog0 <<"Reading handlers: "<<tmh.getDif()<<std::endl;
  234. lf >> gs;
  235. tlog0 <<"Reading gamestate: "<<tmh.getDif()<<std::endl;
  236. const_cast<CGameInfo*>(CGI)->state = gs;
  237. const_cast<CGameInfo*>(CGI)->mh->map = gs->map;
  238. pathInfo = new CPathsInfo(int3(gs->map->width, gs->map->height, gs->map->twoLevel+1));
  239. CGI->mh->init();
  240. initVillagesCapitols(gs->map);
  241. tlog0 <<"Initing maphandler: "<<tmh.getDif()<<std::endl;
  242. }
  243. serv = sh.connectToServer();
  244. serv->addStdVecItems(gs);
  245. tmh.update();
  246. ui8 pom8;
  247. *serv << ui8(3) << ui8(1); //load game; one client
  248. *serv << fname;
  249. *serv >> pom8;
  250. if(pom8)
  251. throw "Server cannot open the savegame!";
  252. else
  253. tlog0 << "Server opened savegame properly.\n";
  254. *serv << ui32(gs->scenarioOps->playerInfos.size()+1); //number of players + neutral
  255. for(std::map<int, PlayerSettings>::iterator it = gs->scenarioOps->playerInfos.begin();
  256. it != gs->scenarioOps->playerInfos.end(); ++it)
  257. {
  258. *serv << ui8(it->first); //players
  259. }
  260. *serv << ui8(255); // neutrals
  261. tlog0 <<"Sent info to server: "<<tmh.getDif()<<std::endl;
  262. {
  263. CLoadFile lf(fname + ".vcgm1");
  264. lf >> *this;
  265. }
  266. }
  267. void CClient::newGame( CConnection *con, StartInfo *si )
  268. {
  269. enum {SINGLE, HOST, GUEST} networkMode = SINGLE;
  270. std::set<ui8> myPlayers;
  271. if (con == NULL)
  272. {
  273. CServerHandler sh;
  274. serv = sh.connectToServer();
  275. }
  276. else
  277. {
  278. serv = con;
  279. networkMode = (con->connectionID == 1) ? HOST : GUEST;
  280. }
  281. for(std::map<int, PlayerSettings>::iterator it =si->playerInfos.begin();
  282. it != si->playerInfos.end(); ++it)
  283. {
  284. if((networkMode == SINGLE) //single - one client has all player
  285. || (networkMode != SINGLE && serv->connectionID == it->second.human) //multi - client has only "its players"
  286. || (networkMode == HOST && it->second.human == false)) //multi - host has all AI players
  287. {
  288. myPlayers.insert(ui8(it->first)); //add player
  289. }
  290. }
  291. if(networkMode != GUEST)
  292. myPlayers.insert(255); //neutral
  293. timeHandler tmh;
  294. const_cast<CGameInfo*>(CGI)->state = new CGameState();
  295. tlog0 <<"\tGamestate: "<<tmh.getDif()<<std::endl;
  296. CConnection &c(*serv);
  297. ////////////////////////////////////////////////////
  298. if(networkMode == SINGLE)
  299. {
  300. ui8 pom8;
  301. c << ui8(2) << ui8(1); //new game; one client
  302. c << *si;
  303. c >> pom8;
  304. if(pom8)
  305. throw "Server cannot open the map!";
  306. else
  307. tlog0 << "Server opened map properly.\n";
  308. }
  309. c << myPlayers;
  310. ui32 seed, sum;
  311. c >> si >> sum >> seed;
  312. tlog0 <<"\tSending/Getting info to/from the server: "<<tmh.getDif()<<std::endl;
  313. tlog0 << "\tUsing random seed: "<<seed << std::endl;
  314. gs = const_cast<CGameInfo*>(CGI)->state;
  315. gs->scenarioOps = si;
  316. gs->init(si, sum, seed);
  317. tlog0 <<"Initializing GameState (together): "<<tmh.getDif()<<std::endl;
  318. if(gs->map)
  319. {
  320. const_cast<CGameInfo*>(CGI)->mh = new CMapHandler();
  321. CGI->mh->map = gs->map;
  322. tlog0 <<"Creating mapHandler: "<<tmh.getDif()<<std::endl;
  323. CGI->mh->init();
  324. initVillagesCapitols(gs->map);
  325. pathInfo = new CPathsInfo(int3(gs->map->width, gs->map->height, gs->map->twoLevel+1));
  326. tlog0 <<"Initializing mapHandler (together): "<<tmh.getDif()<<std::endl;
  327. }
  328. int humanPlayers = 0;
  329. for(std::map<int, PlayerSettings>::iterator it = gs->scenarioOps->playerInfos.begin();
  330. it != gs->scenarioOps->playerInfos.end(); ++it)//initializing interfaces for players
  331. {
  332. ui8 color = it->first;
  333. gs->currentPlayer = color;
  334. if(!vstd::contains(myPlayers, color))
  335. continue;
  336. if(si->mode != StartInfo::DUEL)
  337. {
  338. CCallback *cb = new CCallback(gs,color,this);
  339. if(!it->second.human)
  340. {
  341. playerint[color] = static_cast<CGameInterface*>(CAIHandler::getNewAI(conf.cc.defaultPlayerAI));
  342. }
  343. else
  344. {
  345. playerint[color] = new CPlayerInterface(color);
  346. humanPlayers++;
  347. }
  348. battleints[color] = playerint[color];
  349. playerint[color]->init(cb);
  350. }
  351. else
  352. {
  353. CBattleCallback * cbc = new CBattleCallback(gs, color, this);
  354. battleints[color] = CAIHandler::getNewBattleAI("StupidAI");
  355. battleints[color]->init(cbc);
  356. }
  357. }
  358. if(si->mode == StartInfo::DUEL)
  359. {
  360. CPlayerInterface *p = new CPlayerInterface(-1);
  361. p->observerInDuelMode = true;
  362. battleints[254] = playerint[254] = p;
  363. GH.curInt = p;
  364. p->init(new CCallback(gs, -1, this));
  365. battleStarted(gs->curB);
  366. }
  367. else
  368. {
  369. loadNeutralBattleAI();
  370. }
  371. serv->addStdVecItems(const_cast<CGameInfo*>(CGI)->state);
  372. hotSeat = (humanPlayers > 1);
  373. erm = getERMModule();
  374. privilagedGameEventReceivers.push_back(erm);
  375. privilagedBattleEventReceivers.push_back(erm);
  376. icb = this;
  377. acb = this;
  378. erm->init();
  379. }
  380. template <typename Handler>
  381. void CClient::serialize( Handler &h, const int version )
  382. {
  383. h & hotSeat;
  384. if(h.saving)
  385. {
  386. ui8 players = playerint.size();
  387. h & players;
  388. for(std::map<ui8,CGameInterface *>::iterator i = playerint.begin(); i != playerint.end(); i++)
  389. {
  390. h & i->first & i->second->dllName;
  391. i->second->serialize(h,version);
  392. }
  393. }
  394. else
  395. {
  396. ui8 players;
  397. h & players;
  398. for(int i=0; i < players; i++)
  399. {
  400. std::string dllname;
  401. ui8 pid;
  402. h & pid & dllname;
  403. CGameInterface *nInt = NULL;
  404. if(dllname.length())
  405. {
  406. if(pid == 255)
  407. {
  408. CBattleCallback * cbc = new CBattleCallback(gs, pid, this);
  409. CBattleGameInterface *cbgi = CAIHandler::getNewBattleAI(dllname);
  410. battleints[pid] = cbgi;
  411. cbgi->init(cb);
  412. //TODO? consider serialization
  413. continue;
  414. }
  415. else
  416. nInt = CAIHandler::getNewAI(dllname);
  417. }
  418. else
  419. nInt = new CPlayerInterface(pid);
  420. CCallback *callback = new CCallback(gs,pid,this);
  421. callbacks.insert(callback);
  422. battleints[pid] = playerint[pid] = nInt;
  423. nInt->init(callback);
  424. nInt->serialize(h, version);
  425. }
  426. if(!vstd::contains(battleints, NEUTRAL_PLAYER))
  427. loadNeutralBattleAI();
  428. }
  429. }
  430. void CClient::handlePack( CPack * pack )
  431. {
  432. CBaseForCLApply *apply = applier->apps[typeList.getTypeID(pack)]; //find the applier
  433. if(apply)
  434. {
  435. apply->applyOnClBefore(this,pack);
  436. tlog5 << "\tMade first apply on cl\n";
  437. gs->apply(pack);
  438. tlog5 << "\tApplied on gs\n";
  439. apply->applyOnClAfter(this,pack);
  440. tlog5 << "\tMade second apply on cl\n";
  441. }
  442. else
  443. {
  444. tlog1 << "Message cannot be applied, cannot find applier!\n";
  445. }
  446. delete pack;
  447. }
  448. void CClient::updatePaths()
  449. {
  450. const CGHeroInstance *h = getSelectedHero();
  451. if (h)//if we have selected hero...
  452. gs->calculatePaths(h, *pathInfo);
  453. }
  454. void CClient::finishCampaign( CCampaignState * camp )
  455. {
  456. }
  457. void CClient::proposeNextMission( CCampaignState * camp )
  458. {
  459. GH.pushInt(new CBonusSelection(camp));
  460. GH.curInt = CGP;
  461. }
  462. void CClient::stopConnection()
  463. {
  464. terminate = true;
  465. if (serv) //request closing connection
  466. {
  467. tlog0 << "Connection has been requested to be closed.\n";
  468. boost::unique_lock<boost::mutex>(*serv->wmx);
  469. *serv << &CloseServer();
  470. tlog0 << "Sent closing signal to the server\n";
  471. }
  472. if(connectionHandler)//end connection handler
  473. {
  474. if(connectionHandler->get_id() != boost::this_thread::get_id())
  475. connectionHandler->join();
  476. tlog0 << "Connection handler thread joined" << std::endl;
  477. delete connectionHandler;
  478. connectionHandler = NULL;
  479. }
  480. if (serv) //and delete connection
  481. {
  482. serv->close();
  483. delete serv;
  484. serv = NULL;
  485. tlog3 << "Our socket has been closed." << std::endl;
  486. }
  487. }
  488. void CClient::battleStarted(const BattleInfo * info)
  489. {
  490. CPlayerInterface * att, * def;
  491. if(vstd::contains(playerint, info->sides[0]) && playerint[info->sides[0]]->human)
  492. att = static_cast<CPlayerInterface*>( playerint[info->sides[0]] );
  493. else
  494. att = NULL;
  495. if(vstd::contains(playerint, info->sides[1]) && playerint[info->sides[1]]->human)
  496. def = static_cast<CPlayerInterface*>( playerint[info->sides[1]] );
  497. else
  498. def = NULL;
  499. new CBattleInterface(info->belligerents[0], info->belligerents[1], info->heroes[0], info->heroes[1], Rect((conf.cc.resx - 800)/2, (conf.cc.resy - 600)/2, 800, 600), att, def);
  500. if(vstd::contains(battleints,info->sides[0]))
  501. battleints[info->sides[0]]->battleStart(info->belligerents[0], info->belligerents[1], info->tile, info->heroes[0], info->heroes[1], 0);
  502. if(vstd::contains(battleints,info->sides[1]))
  503. battleints[info->sides[1]]->battleStart(info->belligerents[0], info->belligerents[1], info->tile, info->heroes[0], info->heroes[1], 1);
  504. if(vstd::contains(battleints,254))
  505. battleints[254]->battleStart(info->belligerents[0], info->belligerents[1], info->tile, info->heroes[0], info->heroes[1], 1);
  506. }
  507. void CClient::loadNeutralBattleAI()
  508. {
  509. battleints[255] = CAIHandler::getNewBattleAI(conf.cc.defaultBattleAI);
  510. battleints[255]->init(new CBattleCallback(gs, 255, this));
  511. }
  512. void CClient::commitPackage( CPackForClient *pack )
  513. {
  514. CommitPackage cp;
  515. cp.freePack = false;
  516. cp.packToCommit = pack;
  517. *serv << &cp;
  518. }
  519. int CClient::getLocalPlayer() const
  520. {
  521. if(LOCPLINT)
  522. return LOCPLINT->playerID;
  523. return getCurrentPlayer();
  524. }
  525. template void CClient::serialize( CISer<CLoadFile> &h, const int version );
  526. template void CClient::serialize( COSer<CSaveFile> &h, const int version );
  527. void CServerHandler::startServer()
  528. {
  529. th.update();
  530. serverThread = new boost::thread(&CServerHandler::callServer, this); //runs server executable;
  531. if(verbose)
  532. tlog0 << "Setting up thread calling server: " << th.getDif() << std::endl;
  533. }
  534. void CServerHandler::waitForServer()
  535. {
  536. if(!serverThread)
  537. startServer();
  538. th.update();
  539. intpr::scoped_lock<intpr::interprocess_mutex> slock(shared->sr->mutex);
  540. while(!shared->sr->ready)
  541. {
  542. shared->sr->cond.wait(slock);
  543. }
  544. if(verbose)
  545. tlog0 << "Waiting for server: " << th.getDif() << std::endl;
  546. }
  547. CConnection * CServerHandler::connectToServer()
  548. {
  549. if(!shared->sr->ready)
  550. waitForServer();
  551. th.update();
  552. CConnection *ret = justConnectToServer(conf.cc.server, port);
  553. if(verbose)
  554. tlog0<<"\tConnecting to the server: "<<th.getDif()<<std::endl;
  555. return ret;
  556. }
  557. CServerHandler::CServerHandler(bool runServer /*= false*/)
  558. {
  559. serverThread = NULL;
  560. shared = NULL;
  561. port = boost::lexical_cast<std::string>(conf.cc.port);
  562. verbose = false;
  563. boost::interprocess::shared_memory_object::remove("vcmi_memory"); //if the application has previously crashed, the memory may not have been removed. to avoid problems - try to destroy it
  564. try
  565. {
  566. shared = new SharedMem();
  567. } HANDLE_EXCEPTIONC(tlog1 << "Cannot open interprocess memory: ";)
  568. }
  569. CServerHandler::~CServerHandler()
  570. {
  571. delete shared;
  572. delete serverThread; //detaches, not kills thread
  573. }
  574. void CServerHandler::callServer()
  575. {
  576. setThreadName(-1, "CServerHandler::callServer");
  577. std::string comm = std::string(BIN_DIR PATH_SEPARATOR SERVER_NAME " ") + port + " > server_log.txt";
  578. std::system(comm.c_str());
  579. tlog0 << "Server finished\n";
  580. }
  581. CConnection * CServerHandler::justConnectToServer(const std::string &host, const std::string &port)
  582. {
  583. CConnection *ret = NULL;
  584. while(!ret)
  585. {
  586. try
  587. {
  588. tlog0 << "Establishing connection...\n";
  589. ret = new CConnection( host.size() ? host : conf.cc.server,
  590. port.size() ? port : boost::lexical_cast<std::string>(conf.cc.port),
  591. NAME);
  592. }
  593. catch(...)
  594. {
  595. tlog1 << "\nCannot establish connection! Retrying within 2 seconds" << std::endl;
  596. SDL_Delay(2000);
  597. }
  598. }
  599. return ret;
  600. }