Client.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. #include "Client.h"
  2. #include "../lib/Connection.h"
  3. #include "../StartInfo.h"
  4. #include "../map.h"
  5. #include "../CGameState.h"
  6. #include "../CGameInfo.h"
  7. #include "../mapHandler.h"
  8. #include "../CCallback.h"
  9. #include "../CPlayerInterface.h"
  10. #include "../CConsoleHandler.h"
  11. #include "../lib/NetPacks.h"
  12. #include <boost/bind.hpp>
  13. #include <boost/thread.hpp>
  14. #include <boost/foreach.hpp>
  15. #include "../hch/CObjectHandler.h"
  16. #include "../hch/CGeneralTextHandler.h"
  17. #include "../hch/CArtHandler.h"
  18. #include <boost/thread/shared_mutex.hpp>
  19. #include "../lib/VCMI_Lib.h"
  20. CSharedCond<std::set<IPack*> > mess(new std::set<IPack*>);
  21. std::string toString(MetaString &ms)
  22. {
  23. std::string ret;
  24. for(int i=0;i<ms.message.size();i++)
  25. {
  26. if(ms.message[i]>0)
  27. {
  28. ret += ms.strings[ms.message[i]-1];
  29. }
  30. else
  31. {
  32. std::vector<std::string> *vec;
  33. int type = ms.texts[-ms.message[i]-1].first,
  34. ser = ms.texts[-ms.message[i]-1].second;
  35. if(type == 5)
  36. {
  37. ret += CGI->arth->artifacts[ser].name;
  38. continue;
  39. }
  40. else if(type == 7)
  41. {
  42. ret += CGI->creh->creatures[ser].namePl;
  43. continue;
  44. }
  45. else if(type == 9)
  46. {
  47. ret += CGI->objh->mines[ser].first;
  48. continue;
  49. }
  50. else if(type == 10)
  51. {
  52. ret += CGI->objh->mines[ser].second;
  53. continue;
  54. }
  55. else
  56. {
  57. switch(type)
  58. {
  59. case 1:
  60. vec = &CGI->generaltexth->allTexts;
  61. break;
  62. case 2:
  63. vec = &CGI->objh->xtrainfo;
  64. break;
  65. case 3:
  66. vec = &CGI->objh->names;
  67. break;
  68. case 4:
  69. vec = &CGI->objh->restypes;
  70. break;
  71. case 6:
  72. vec = &CGI->generaltexth->arraytxt;
  73. break;
  74. case 8:
  75. vec = &CGI->objh->creGens;
  76. break;
  77. case 11:
  78. vec = &CGI->objh->advobtxt;
  79. break;
  80. case 12:
  81. vec = &CGI->generaltexth->artifEvents;
  82. break;
  83. }
  84. ret += (*vec)[ser];
  85. }
  86. }
  87. }
  88. for(int i=0;i<ms.replacements.size();i++)
  89. {
  90. ret.replace(ret.find("%s"),2,ms.replacements[i]);
  91. }
  92. return ret;
  93. }
  94. CClient::CClient(void)
  95. {
  96. }
  97. CClient::CClient(CConnection *con, StartInfo *si)
  98. :serv(con)
  99. {
  100. timeHandler tmh;
  101. CGI->state = new CGameState();
  102. tlog0 <<"\tGamestate: "<<tmh.getDif()<<std::endl;
  103. CConnection &c(*con);
  104. ////////////////////////////////////////////////////
  105. ui8 pom8;
  106. c << ui8(2) << ui8(1); //new game; one client
  107. c << *si;
  108. c >> pom8;
  109. if(pom8) throw "Server cannot open the map!";
  110. c << ui8(si->playerInfos.size());
  111. for(int i=0;i<si->playerInfos.size();i++)
  112. c << ui8(si->playerInfos[i].color);
  113. ui32 seed, sum;
  114. std::string mapname;
  115. c >> mapname >> sum >> seed;
  116. tlog0 <<"\tSending/Getting info to/from the server: "<<tmh.getDif()<<std::endl;
  117. Mapa * mapa = new Mapa(mapname);
  118. tlog0 <<"Reading and detecting map file (together): "<<tmh.getDif()<<std::endl;
  119. tlog0 << "\tServer checksum for "<<mapname <<": "<<sum << std::endl;
  120. tlog0 << "\tOur checksum for the map: "<< mapa->checksum << std::endl;
  121. if(mapa->checksum != sum)
  122. {
  123. tlog1 << "Wrong map checksum!!!" << std::endl;
  124. #ifndef __GNUC__
  125. throw std::exception("Wrong checksum");
  126. #else
  127. throw std::exception();
  128. #endif
  129. }
  130. tlog0 << "\tUsing random seed: "<<seed << std::endl;
  131. gs = CGI->state;
  132. gs->scenarioOps = si;
  133. gs->init(si,mapa,seed);
  134. CGI->mh = new CMapHandler();
  135. tlog0 <<"Initializing GameState (together): "<<tmh.getDif()<<std::endl;
  136. CGI->mh->map = mapa;
  137. tlog0 <<"Creating mapHandler: "<<tmh.getDif()<<std::endl;
  138. CGI->mh->init();
  139. tlog0 <<"Initializing mapHandler (together): "<<tmh.getDif()<<std::endl;
  140. for (int i=0; i<CGI->state->scenarioOps->playerInfos.size();i++) //initializing interfaces
  141. {
  142. ui8 color = gs->scenarioOps->playerInfos[i].color;
  143. CCallback *cb = new CCallback(gs,color,this);
  144. if(!gs->scenarioOps->playerInfos[i].human)
  145. {
  146. playerint[color] = static_cast<CGameInterface*>(CAIHandler::getNewAI(cb,"EmptyAI.dll"));
  147. }
  148. else
  149. {
  150. gs->currentPlayer = color;
  151. playerint[color] = new CPlayerInterface(color,i);
  152. playerint[color]->init(cb);
  153. }
  154. }
  155. //cb = CGI->consoleh->cb = new CCallback(gs,-1,this);
  156. }
  157. CClient::~CClient(void)
  158. {
  159. }
  160. void CClient::process(int what)
  161. {
  162. static BattleAction curbaction;
  163. switch (what)
  164. {
  165. case 100: //one of our interaces has turn
  166. {
  167. ui8 player;
  168. *serv >> player;//who?
  169. tlog5 << "It's turn of "<<(unsigned)player<<" player."<<std::endl;
  170. boost::thread(boost::bind(&CGameInterface::yourTurn,playerint[player]));
  171. break;
  172. }
  173. case 101:
  174. {
  175. NewTurn n;
  176. *serv >> n;
  177. tlog5 << "New day: "<<(unsigned)n.day<<". Applying changes... ";
  178. gs->apply(&n);
  179. tlog5 << "done!"<<std::endl;
  180. break;
  181. }
  182. case 102: //set resource amount
  183. {
  184. SetResource sr;
  185. *serv >> sr;
  186. tlog5 << "Set amount of "<<CGI->objh->restypes[sr.resid]
  187. << " of player "<<(unsigned)sr.player <<" to "<<sr.val<<std::endl;
  188. gs->apply(&sr);
  189. playerint[sr.player]->receivedResource(sr.resid,sr.val);
  190. break;
  191. }
  192. case 103: //show info dialog
  193. {
  194. InfoWindow iw;
  195. *serv >> iw;
  196. std::vector<Component*> comps;
  197. for(int i=0;i<iw.components.size();i++)
  198. comps.push_back(&iw.components[i]);
  199. std::string str = toString(iw.text);
  200. playerint[iw.player]->showInfoDialog(str,comps);
  201. break;
  202. }
  203. case 104:
  204. {
  205. SetResources sr;
  206. *serv >> sr;
  207. tlog5 << "Set amount of resources of player "<<(unsigned)sr.player<<std::endl;
  208. gs->apply(&sr);
  209. playerint[sr.player]->receivedResource(-1,-1);
  210. break;
  211. }
  212. case 105:
  213. {
  214. SetPrimSkill sps;
  215. *serv >> sps;
  216. tlog5 << "Changing hero primary skill"<<std::endl;
  217. gs->apply(&sps);
  218. playerint[gs->getHero(sps.id)->tempOwner]->heroPrimarySkillChanged(gs->getHero(sps.id),sps.which,sps.val);
  219. break;
  220. }
  221. case 106:
  222. {
  223. SetSecSkill sr;
  224. *serv >> sr;
  225. tlog5 << "Changing hero secondary skill"<<std::endl;
  226. gs->apply(&sr);
  227. //TODO? - maybe inform interfaces
  228. break;
  229. }
  230. case 107:
  231. {
  232. ShowInInfobox sii;
  233. *serv >> sii;
  234. SComponent sc(sii.c);
  235. sc.description = toString(sii.text);
  236. if(playerint[sii.player]->human)
  237. static_cast<CPlayerInterface*>(playerint[sii.player])->showComp(sc);
  238. break;
  239. }
  240. case 108:
  241. {
  242. HeroVisitCastle vc;
  243. *serv >> vc;
  244. gs->apply(&vc);
  245. if(vc.start() && !vc.garrison() && vstd::contains(playerint,gs->getHero(vc.hid)->tempOwner))
  246. {
  247. playerint[gs->getHero(vc.hid)->tempOwner]->heroVisitsTown(gs->getHero(vc.hid),gs->getTown(vc.tid));
  248. }
  249. break;
  250. }
  251. case 109:
  252. {
  253. ChangeSpells vc;
  254. *serv >> vc;
  255. tlog5 << "Changing spells of hero "<<vc.hid<<std::endl;
  256. gs->apply(&vc);
  257. break;
  258. }
  259. case 500:
  260. {
  261. RemoveObject rh;
  262. *serv >> rh;
  263. CGObjectInstance *obj = gs->map->objects[rh.id];
  264. CGI->mh->removeObject(obj);
  265. gs->apply(&rh);
  266. if(obj->ID == 34)
  267. {
  268. CGHeroInstance *h = static_cast<CGHeroInstance*>(obj);
  269. tlog5 << "Removing hero with id = "<<(unsigned)rh.id<<std::endl;
  270. playerint[h->tempOwner]->heroKilled(h);
  271. }
  272. break;
  273. }
  274. case 501: //hero movement response - we have to notify interfaces and callback
  275. {
  276. TryMoveHero *th = new TryMoveHero; //will be deleted by callback after processing
  277. *serv >> *th;
  278. tlog5 << "HeroMove: id="<<th->id<<"\tResult: "<<(unsigned)th->result<<"\tPosition "<<th->end<<std::endl;
  279. HeroMoveDetails hmd(th->start,th->end,static_cast<CGHeroInstance*>(gs->map->objects[th->id]));
  280. hmd.style = th->result-1;
  281. hmd.successful = th->result;
  282. if(th->result>1)
  283. CGI->mh->removeObject(hmd.ho);
  284. gs->apply(th);
  285. if(th->result>1)
  286. CGI->mh->printObject(hmd.ho);
  287. int player = gs->map->objects[th->id]->getOwner();
  288. if(playerint[player])
  289. {
  290. for(std::set<int3>::iterator i=th->fowRevealed.begin(); i != th->fowRevealed.end(); i++)
  291. playerint[player]->tileRevealed(*i);
  292. //std::for_each(th->fowRevealed.begin(),th->fowRevealed.end(),boost::bind(&CGameInterface::tileRevealed,playerint[player],_1));
  293. }
  294. //notify interfacesabout move
  295. for(std::map<ui8, CGameInterface*>::iterator i=playerint.begin();i!=playerint.end();i++)
  296. {
  297. if(gs->players[i->first].fogOfWarMap[th->start.x-1][th->start.y][th->start.z] || gs->players[i->first].fogOfWarMap[th->end.x-1][th->end.y][th->end.z])
  298. {
  299. i->second->heroMoved(hmd);
  300. }
  301. }
  302. //add info for callback
  303. if(th->result<2)
  304. {
  305. mess.mx->lock();
  306. mess.res->insert(th);
  307. mess.mx->unlock();
  308. mess.cv->notify_all();
  309. }
  310. break;
  311. }
  312. case 502:
  313. {
  314. SetGarrisons sg;
  315. *serv >> sg;
  316. tlog5 << "Setting garrisons." << std::endl;
  317. gs->apply(&sg);
  318. for(std::map<ui32,CCreatureSet>::iterator i = sg.garrs.begin(); i!=sg.garrs.end(); i++)
  319. playerint[gs->map->objects[i->first]->tempOwner]->garrisonChanged(gs->map->objects[i->first]);
  320. break;
  321. }
  322. case 503:
  323. {
  324. //SetStrInfo ssi;
  325. //*serv >> ssi;
  326. //gs->apply(&ssi);
  327. //TODO: notify interfaces
  328. break;
  329. }
  330. case 504:
  331. {
  332. NewStructures ns;
  333. *serv >> ns;
  334. CGTownInstance *town = static_cast<CGTownInstance*>(gs->map->objects[ns.tid]);
  335. tlog5 << "New structure(s) in " << ns.tid <<" " << town->name << " - " << *ns.bid.begin() << std::endl;
  336. gs->apply(&ns);
  337. BOOST_FOREACH(si32 bid, ns.bid)
  338. {
  339. if(bid==13) //for or capitol
  340. {
  341. town->defInfo = gs->capitols[town->subID];
  342. }
  343. if(bid ==7)
  344. {
  345. town->defInfo = gs->forts[town->subID];
  346. }
  347. playerint[town->tempOwner]->buildChanged(town,bid,1);
  348. }
  349. break;
  350. }
  351. case 506:
  352. {
  353. SetAvailableCreatures ns;
  354. *serv >> ns;
  355. tlog5 << "Setting available creatures in " << ns.tid << std::endl;
  356. gs->apply(&ns);
  357. CGTownInstance *t = gs->getTown(ns.tid);
  358. if(vstd::contains(playerint,t->tempOwner))
  359. playerint[t->tempOwner]->availableCreaturesChanged(t);
  360. break;
  361. }
  362. case 508:
  363. {
  364. SetHeroesInTown inTown;
  365. *serv >> inTown;
  366. tlog5 << "Setting heroes in town " << inTown.tid << std::endl;
  367. gs->apply(&inTown);
  368. CGTownInstance *t = gs->getTown(inTown.tid);
  369. if(vstd::contains(playerint,t->tempOwner))
  370. playerint[t->tempOwner]->heroInGarrisonChange(t);
  371. break;
  372. }
  373. case 509:
  374. {
  375. SetHeroArtifacts sha;
  376. *serv >> sha;
  377. tlog5 << "Setting artifacts of hero " << sha.hid << std::endl;
  378. gs->apply(&sha);
  379. CGHeroInstance *t = gs->getHero(sha.hid);
  380. if(vstd::contains(playerint,t->tempOwner))
  381. playerint[t->tempOwner]->heroArtifactSetChanged(t);
  382. break;
  383. }
  384. case 1001:
  385. {
  386. SetObjectProperty sop;
  387. *serv >> sop;
  388. tlog5 << "Setting " << (unsigned)sop.what << " property of " << sop.id <<" object to "<<sop.val<<std::endl;
  389. gs->apply(&sop);
  390. break;
  391. }
  392. case 1002:
  393. {
  394. SetHoverName shn;
  395. *serv >> shn;
  396. tlog5 << "Setting a name of " << shn.id <<" object to "<< toString(shn.name) <<std::endl;
  397. gs->mx->lock();
  398. gs->map->objects[shn.id]->hoverName = toString(shn.name);
  399. gs->mx->unlock();
  400. break;
  401. }
  402. case 2000:
  403. {
  404. HeroLevelUp bs;
  405. *serv >> bs;
  406. tlog5 << "Hero levels up!" <<std::endl;
  407. gs->apply(&bs);
  408. CGHeroInstance *h = gs->getHero(bs.heroid);
  409. if(vstd::contains(playerint,h->tempOwner))
  410. {
  411. boost::function<void(ui32)> callback = boost::function<void(ui32)>(boost::bind(&CCallback::selectionMade,LOCPLINT->cb,_1,bs.id));
  412. playerint[h->tempOwner]->heroGotLevel((const CGHeroInstance *)h,(int)bs.primskill,bs.skills, callback);
  413. }
  414. break;
  415. }
  416. case 2001:
  417. {
  418. SelectionDialog sd;
  419. *serv >> sd;
  420. tlog5 << "Showing selection dialog " <<std::endl;
  421. std::vector<Component*> comps;
  422. for(int i=0;i<sd.components.size();i++)
  423. comps.push_back(&sd.components[i]);
  424. std::string str = toString(sd.text);
  425. playerint[sd.player]->showSelDialog(str,comps,sd.id);
  426. break;
  427. }
  428. case 2002:
  429. {
  430. YesNoDialog ynd;
  431. *serv >> ynd;
  432. tlog5 << "Showing yes/no dialog " <<std::endl;
  433. std::vector<Component*> comps;
  434. for(int i=0;i<ynd.components.size();i++)
  435. comps.push_back(&ynd.components[i]);
  436. std::string str = toString(ynd.text);
  437. playerint[ynd.player]->showYesNoDialog(str,comps,ynd.id);
  438. break;
  439. }
  440. case 3000:
  441. {
  442. BattleStart bs;
  443. *serv >> bs; //uses new to allocate memory for battleInfo - must be deleted when battle is over
  444. tlog5 << "Starting battle!" <<std::endl;
  445. gs->apply(&bs);
  446. if(playerint.find(gs->curB->side1) != playerint.end())
  447. playerint[gs->curB->side1]->battleStart(&gs->curB->army1, &gs->curB->army2, gs->curB->tile, gs->getHero(gs->curB->hero1), gs->getHero(gs->curB->hero2), 0);
  448. if(playerint.find(gs->curB->side2) != playerint.end())
  449. playerint[gs->curB->side2]->battleStart(&gs->curB->army1, &gs->curB->army2, gs->curB->tile, gs->getHero(gs->curB->hero1), gs->getHero(gs->curB->hero2), 1);
  450. break;
  451. }
  452. case 3001:
  453. {
  454. BattleNextRound bnr;
  455. *serv >> bnr;
  456. tlog5 << "Round nr " << bnr.round <<std::endl;
  457. gs->apply(&bnr);
  458. //tell players about next round
  459. if(playerint.find(gs->curB->side1) != playerint.end())
  460. playerint[gs->curB->side1]->battleNewRound(bnr.round);
  461. if(playerint.find(gs->curB->side2) != playerint.end())
  462. playerint[gs->curB->side2]->battleNewRound(bnr.round);
  463. break;
  464. }
  465. case 3002:
  466. {
  467. BattleSetActiveStack sas;
  468. *serv >> sas;
  469. tlog5 << "Active stack: " << sas.stack <<std::endl;
  470. gs->apply(&sas);
  471. int owner = gs->curB->getStack(sas.stack)->owner;
  472. if(owner >= PLAYER_LIMIT) //ugly workaround to skip neutral creatures - should be replaced with AI
  473. {
  474. BattleAction ba;
  475. ba.stackNumber = sas.stack;
  476. ba.actionType = 3;
  477. *serv << ui16(3002) << ba;
  478. }
  479. else
  480. {
  481. boost::thread(boost::bind(&CClient::waitForMoveAndSend,this,owner));
  482. }
  483. break;
  484. }
  485. case 3003:
  486. {
  487. BattleResult br;
  488. *serv >> br;
  489. tlog5 << "Battle ends. Winner: " << (unsigned)br.winner<< ". Type of end: "<< (unsigned)br.result <<std::endl;
  490. if(playerint.find(gs->curB->side1) != playerint.end())
  491. playerint[gs->curB->side1]->battleEnd(&br);
  492. if(playerint.find(gs->curB->side2) != playerint.end())
  493. playerint[gs->curB->side2]->battleEnd(&br);
  494. gs->apply(&br);
  495. break;
  496. }
  497. case 3004:
  498. {
  499. BattleStackMoved br;
  500. *serv >> br;
  501. tlog5 << "Stack "<<br.stack <<" moves to the tile "<<br.tile<<std::endl;
  502. if(playerint.find(gs->curB->side1) != playerint.end())
  503. playerint[gs->curB->side1]->battleStackMoved(br.stack,br.tile);
  504. if(playerint.find(gs->curB->side2) != playerint.end())
  505. playerint[gs->curB->side2]->battleStackMoved(br.stack,br.tile);
  506. gs->apply(&br);
  507. break;
  508. }
  509. case 3005:
  510. {
  511. BattleStackAttacked bsa;
  512. *serv >> bsa;
  513. gs->apply(&bsa);
  514. if(playerint.find(gs->curB->side1) != playerint.end())
  515. playerint[gs->curB->side1]->battleStackAttacked(&bsa);
  516. if(playerint.find(gs->curB->side2) != playerint.end())
  517. playerint[gs->curB->side2]->battleStackAttacked(&bsa);
  518. break;
  519. }
  520. case 3006:
  521. {
  522. BattleAttack ba;
  523. *serv >> ba;
  524. tlog5 << "Stack: " << ba.stackAttacking << " is attacking stack "<< ba.bsa.stackAttacked <<std::endl;
  525. if(playerint.find(gs->curB->side1) != playerint.end())
  526. playerint[gs->curB->side1]->battleAttack(&ba);
  527. if(playerint.find(gs->curB->side2) != playerint.end())
  528. playerint[gs->curB->side2]->battleAttack(&ba);
  529. gs->apply(&ba);
  530. if(playerint.find(gs->curB->side1) != playerint.end())
  531. playerint[gs->curB->side1]->battleStackAttacked(&ba.bsa);
  532. if(playerint.find(gs->curB->side2) != playerint.end())
  533. playerint[gs->curB->side2]->battleStackAttacked(&ba.bsa);
  534. break;
  535. }
  536. case 3007:
  537. {
  538. *serv >> curbaction;
  539. tlog5 << "Action started. ID: " << (int)curbaction.actionType << ". Destination: "<< curbaction.destinationTile <<std::endl;
  540. if(playerint.find(gs->curB->side1) != playerint.end())
  541. playerint[gs->curB->side1]->actionStarted(&curbaction);
  542. if(playerint.find(gs->curB->side2) != playerint.end())
  543. playerint[gs->curB->side2]->actionStarted(&curbaction);
  544. break;
  545. }
  546. case 3008:
  547. {
  548. tlog5 << "Action ended!\n";
  549. if(!gs->curB)
  550. {
  551. tlog2 << "There is no battle state!\n";
  552. break;
  553. }
  554. if(playerint.find(gs->curB->side1) != playerint.end())
  555. playerint[gs->curB->side1]->actionFinished(&curbaction);
  556. if(playerint.find(gs->curB->side2) != playerint.end())
  557. playerint[gs->curB->side2]->actionFinished(&curbaction);
  558. break;
  559. }
  560. case 3009:
  561. {
  562. tlog5 << "Spell casted!\n";
  563. SpellCasted sc;
  564. *serv >> sc;
  565. gs->apply(&sc);
  566. //todo - apply
  567. if(playerint.find(gs->curB->side1) != playerint.end())
  568. playerint[gs->curB->side1]->battleSpellCasted(&sc);
  569. if(playerint.find(gs->curB->side2) != playerint.end())
  570. playerint[gs->curB->side2]->battleSpellCasted(&sc);
  571. break;
  572. }
  573. case 9999:
  574. break;
  575. default:
  576. throw std::string("Not supported server message!");
  577. break;
  578. }
  579. }
  580. void CClient::waitForMoveAndSend(int color)
  581. {
  582. try
  583. {
  584. BattleAction ba = playerint[color]->activeStack(gs->curB->activeStack);
  585. *serv << ui16(3002) << ba;
  586. return;
  587. }HANDLE_EXCEPTION
  588. tlog1 << "We should not be here!" << std::endl;
  589. }
  590. void CClient::run()
  591. {
  592. try
  593. {
  594. ui16 typ;
  595. while(1)
  596. {
  597. *serv >> typ;
  598. process(typ);
  599. }
  600. } HANDLE_EXCEPTION
  601. }
  602. void CClient::close()
  603. {
  604. tlog3 << "Connection has been requested to be closed.\n";
  605. boost::unique_lock<boost::mutex>(*serv->wmx);
  606. *serv << ui16(99);
  607. tlog3 << "Sended closing signal to the server\n";
  608. serv->close();
  609. tlog3 << "Our socket has been closed.\n";
  610. }