CMT.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. // CMT.cpp : Defines the entry point for the console application.
  2. //
  3. #include "../stdafx.h"
  4. #include <cmath>
  5. #include <string>
  6. #include <vector>
  7. #include <queue>
  8. #include <cmath>
  9. #include <boost/algorithm/string.hpp>
  10. #include <boost/filesystem/operations.hpp>
  11. #include <boost/thread.hpp>
  12. #include <SDL_mixer.h>
  13. #include "SDL_Extensions.h"
  14. #include "SDL_framerate.h"
  15. #include "CGameInfo.h"
  16. #include "mapHandler.h"
  17. #include "../global.h"
  18. #include "CPreGame.h"
  19. #include "CCastleInterface.h"
  20. #include "../CConsoleHandler.h"
  21. #include "CCursorHandler.h"
  22. #include "../lib/CGameState.h"
  23. #include "../CCallback.h"
  24. #include "CPlayerInterface.h"
  25. #include "CAdvmapInterface.h"
  26. #include "../hch/CBuildingHandler.h"
  27. #include "../hch/CVideoHandler.h"
  28. #include "../hch/CHeroHandler.h"
  29. #include "../hch/CCreatureHandler.h"
  30. #include "../hch/CSpellHandler.h"
  31. #include "../hch/CMusicHandler.h"
  32. #include "../hch/CVideoHandler.h"
  33. #include "../hch/CLodHandler.h"
  34. #include "../hch/CDefHandler.h"
  35. #include "../hch/CAmbarCendamo.h"
  36. #include "../hch/CGeneralTextHandler.h"
  37. #include "Graphics.h"
  38. #include "Client.h"
  39. #include "CConfigHandler.h"
  40. #include "../lib/Connection.h"
  41. #include "../lib/VCMI_Lib.h"
  42. #include "../lib/VCMIDirs.h"
  43. #include <cstdlib>
  44. #include "../lib/NetPacks.h"
  45. #include "CMessage.h"
  46. #ifdef _WIN32
  47. #include "SDL_syswm.h"
  48. #endif
  49. #if __MINGW32__
  50. #undef main
  51. #endif
  52. /*
  53. * CMT.cpp, part of VCMI engine
  54. *
  55. * Authors: listed in file AUTHORS in main folder
  56. *
  57. * License: GNU General Public License v2.0 or later
  58. * Full text of license available in license.txt file, in main folder
  59. *
  60. */
  61. std::string NAME_AFFIX = "client";
  62. std::string NAME = NAME_VER + std::string(" (") + NAME_AFFIX + ')'; //application name
  63. CGuiHandler GH;
  64. static CClient *client;
  65. SDL_Surface *screen = NULL, //main screen surface
  66. *screen2 = NULL,//and hlp surface (used to store not-active interfaces layer)
  67. *screenBuf = screen; //points to screen (if only advmapint is present) or screen2 (else) - should be used when updating controls which are not regularly redrawed
  68. static boost::thread *mainGUIThread;
  69. SystemOptions GDefaultOptions;
  70. VCMIDirs GVCMIDirs;
  71. std::queue<SDL_Event*> events;
  72. boost::mutex eventsM;
  73. static bool gOnlyAI = false;
  74. static bool setResolution = false; //set by event handling thread after resolution is adjusted
  75. void processCommand(const std::string &message);
  76. static void setScreenRes(int w, int h, int bpp, bool fullscreen);
  77. void dispose();
  78. void playIntro();
  79. static void listenForEvents();
  80. #ifndef _WIN32
  81. #ifndef _GNU_SOURCE
  82. #define _GNU_SOURCE
  83. #endif
  84. #include <getopt.h>
  85. #endif
  86. void init()
  87. {
  88. timeHandler tmh, pomtime;
  89. #if SDL_BYTEORDER == SDL_BIG_ENDIAN
  90. int rmask = 0xff000000;int gmask = 0x00ff0000;int bmask = 0x0000ff00;int amask = 0x000000ff;
  91. #else
  92. int rmask = 0x000000ff; int gmask = 0x0000ff00; int bmask = 0x00ff0000; int amask = 0xff000000;
  93. #endif
  94. CSDL_Ext::std32bppSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 1, 32, rmask, gmask, bmask, amask);
  95. tlog0 << "\tInitializing minors: " << pomtime.getDif() << std::endl;
  96. {
  97. //read system options
  98. CLoadFile settings(GVCMIDirs.UserPath + "/config/sysopts.bin", false);
  99. if(settings.sfile)
  100. {
  101. settings >> GDefaultOptions;
  102. }
  103. else //file not found (probably, may be also some kind of access problem
  104. {
  105. tlog2 << "Warning: Cannot read system options, default settings will be used.\n";
  106. //Try to create file
  107. tlog2 << "VCMI will try to save default system options...\n";
  108. GDefaultOptions.settingsChanged();
  109. }
  110. }
  111. THC tlog0<<"\tLoading default system settings: "<<pomtime.getDif()<<std::endl;
  112. //initializing audio
  113. // Note: because of interface button range, volume can only be a
  114. // multiple of 11, from 0 to 99.
  115. CGI->soundh = new CSoundHandler;
  116. CGI->soundh->init();
  117. CGI->soundh->setVolume(GDefaultOptions.soundVolume);
  118. CGI->musich = new CMusicHandler;
  119. //CGI->musich->init();
  120. //CGI->musich->setVolume(GDefaultOptions.musicVolume);
  121. tlog0<<"\tInitializing sound: "<<pomtime.getDif()<<std::endl;
  122. tlog0<<"Initializing screen and sound handling: "<<tmh.getDif()<<std::endl;
  123. initDLL(::console,logfile);
  124. CGI->setFromLib();
  125. CGI->soundh->initCreaturesSounds(CGI->creh->creatures);
  126. CGI->soundh->initSpellsSounds(CGI->spellh->spells);
  127. tlog0<<"Initializing VCMI_Lib: "<<tmh.getDif()<<std::endl;
  128. pomtime.getDif();
  129. CGI->curh = new CCursorHandler;
  130. CGI->curh->initCursor();
  131. CGI->curh->show();
  132. tlog0<<"Screen handler: "<<pomtime.getDif()<<std::endl;
  133. pomtime.getDif();
  134. graphics = new Graphics();
  135. graphics->loadHeroAnims();
  136. tlog0<<"\tMain graphics: "<<tmh.getDif()<<std::endl;
  137. tlog0<<"Initializing game graphics: "<<tmh.getDif()<<std::endl;
  138. CMessage::init();
  139. tlog0<<"Message handler: "<<tmh.getDif()<<std::endl;
  140. //CPG = new CPreGame(); //main menu and submenus
  141. //tlog0<<"Initialization CPreGame (together): "<<tmh.getDif()<<std::endl;
  142. }
  143. #ifndef _WIN32
  144. static void prog_version(void)
  145. {
  146. printf("%s\n", NAME_VER);
  147. printf(" data directory: %s\n", DATA_DIR);
  148. printf(" library directory: %s\n", LIB_DIR);
  149. printf(" binary directory: %s\n", BIN_DIR);
  150. }
  151. static void prog_help(const char *progname)
  152. {
  153. printf("%s - A Heroes of Might and Magic 3 clone\n", NAME_VER);
  154. printf("Copyright (C) 2007-2010 VCMI dev team - see AUTHORS file\n");
  155. printf("This is free software; see the source for copying conditions. There is NO\n");
  156. printf("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
  157. printf("\n");
  158. printf("Usage:\n");
  159. printf(" -h, --help display this help and exit\n");
  160. printf(" -v, --version display version information and exit\n");
  161. }
  162. #endif
  163. #ifdef _WIN32
  164. int _tmain(int argc, _TCHAR* argv[])
  165. #else
  166. int main(int argc, char** argv)
  167. #endif
  168. {
  169. #ifndef _WIN32
  170. struct option long_options[] = {
  171. { "help", 0, NULL, 'h' },
  172. { "version", 0, NULL, 'v' },
  173. { NULL, 0, NULL, 0 }
  174. };
  175. while(1) {
  176. int c;
  177. int option_index;
  178. c = getopt_long (argc, argv, "hv",
  179. long_options, &option_index);
  180. if (c == EOF)
  181. break;
  182. else if (c == '?')
  183. return -1;
  184. switch(c) {
  185. case 'h':
  186. prog_help(argv[0]);
  187. return 0;
  188. break;
  189. case 'v':
  190. prog_version();
  191. return 0;
  192. break;
  193. }
  194. }
  195. if (optind < argc) {
  196. printf ("Extra arguments: %s\n", argv[optind++]);
  197. return 1;
  198. }
  199. #endif
  200. //Set environment vars to make window centered. Sometimes work, sometimes not. :/
  201. putenv("SDL_VIDEO_WINDOW_POS");
  202. putenv("SDL_VIDEO_CENTERED=1");
  203. tlog0 << "Starting... " << std::endl;
  204. timeHandler total, pomtime;
  205. std::cout.flags(std::ios::unitbuf);
  206. logfile = new std::ofstream("VCMI_Client_log.txt");
  207. console = new CConsoleHandler;
  208. *console->cb = boost::bind(&processCommand, _1);
  209. console->start();
  210. atexit(dispose);
  211. tlog0 <<"Creating console and logfile: "<<pomtime.getDif() << std::endl;
  212. conf.init();
  213. tlog0 <<"Loading settings: "<<pomtime.getDif() << std::endl;
  214. tlog0 << NAME << std::endl;
  215. srand ( time(NULL) );
  216. //CPG=NULL;
  217. CGI = new CGameInfo; //contains all global informations about game (texts, lodHandlers, map handler itp.)
  218. if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO))
  219. {
  220. tlog1<<"Something was wrong: "<< SDL_GetError() << std::endl;
  221. exit(-1);
  222. }
  223. atexit(SDL_Quit);
  224. setScreenRes(800,600,conf.cc.bpp,conf.cc.fullscreen);
  225. tlog0 <<"\tInitializing screen: "<<pomtime.getDif() << std::endl;
  226. // Initialize video
  227. CGI->videoh = new CVideoPlayer;
  228. tlog0<<"\tInitializing video: "<<pomtime.getDif()<<std::endl;
  229. //we can properly play intro only in the main thread, so we have to move loading to the separate thread
  230. boost::thread loading(init);
  231. playIntro();
  232. SDL_FillRect(screen,NULL,0);
  233. SDL_Flip(screen);
  234. loading.join();
  235. tlog0<<"Initialization of VCMI (together): "<<total.getDif()<<std::endl;
  236. CGI->musich->playMusic(musicBase::mainMenu, -1);
  237. GH.curInt = new CGPreGame; //will set CGP pointer to itself
  238. mainGUIThread = new boost::thread(&CGuiHandler::run, boost::ref(GH));
  239. listenForEvents();
  240. return 0;
  241. }
  242. void processCommand(const std::string &message)
  243. {
  244. std::istringstream readed;
  245. readed.str(message);
  246. std::string cn; //command name
  247. readed >> cn;
  248. int3 src, dst;
  249. // int heronum;//TODO use me
  250. int3 dest;
  251. if(LOCPLINT && LOCPLINT->cingconsole)
  252. LOCPLINT->cingconsole->print(message);
  253. if(message==std::string("die, fool"))
  254. exit(EXIT_SUCCESS);
  255. else if(cn==std::string("activate"))
  256. {
  257. int what;
  258. readed >> what;
  259. switch (what)
  260. {
  261. case 0:
  262. GH.topInt()->activate();
  263. break;
  264. case 1:
  265. adventureInt->activate();
  266. break;
  267. case 2:
  268. LOCPLINT->castleInt->activate();
  269. break;
  270. }
  271. }
  272. else if(cn=="redraw")
  273. {
  274. GH.totalRedraw();
  275. }
  276. else if(cn=="screen")
  277. {
  278. tlog0 << "Screenbuf points to ";
  279. if(screenBuf == screen)
  280. tlog1 << "screen";
  281. else if(screenBuf == screen2)
  282. tlog1 << "screen2";
  283. else
  284. tlog1 << "?!?";
  285. tlog1 << std::endl;
  286. SDL_SaveBMP(screen, "Screen_c.bmp");
  287. SDL_SaveBMP(screen2, "Screen2_c.bmp");
  288. }
  289. else if(cn=="save")
  290. {
  291. std::string fname;
  292. readed >> fname;
  293. client->save(fname);
  294. }
  295. //else if(cn=="list")
  296. //{
  297. // if(CPG)
  298. // for(int i = 0; i < CPG->ourScenSel->mapsel.ourGames.size(); i++)
  299. // tlog0 << i << ".\t" << CPG->ourScenSel->mapsel.ourGames[i]->filename << std::endl;
  300. //}
  301. else if(cn=="load")
  302. {
  303. // TODO: this code should end the running game and manage to call startGame instead
  304. std::string fname;
  305. readed >> fname;
  306. client->loadGame(fname);
  307. }
  308. //else if(cn=="ln")
  309. //{
  310. // int num;
  311. // readed >> num;
  312. // std::string &name = CPG->ourScenSel->mapsel.ourGames[num]->filename;
  313. // client->load(name.substr(0, name.size()-6));
  314. //}
  315. else if(cn=="resolution" || cn == "r")
  316. {
  317. if(LOCPLINT)
  318. {
  319. tlog1 << "Resolution can be set only before starting the game.\n";
  320. return;
  321. }
  322. std::map<std::pair<int,int>, config::GUIOptions >::iterator j;
  323. int i=1, hlp=1;
  324. tlog4 << "Available screen resolutions:\n";
  325. for(j=conf.guiOptions.begin(); j!=conf.guiOptions.end(); j++)
  326. tlog4 << i++ <<". " << j->first.first << " x " << j->first.second << std::endl;
  327. tlog4 << "Type number from 1 to " << i-1 << " to set appropriate resolution or 0 to cancel.\n";
  328. std::cin >> i;
  329. if(i < 0 || i > conf.guiOptions.size() || std::cin.bad() || std::cin.fail())
  330. {
  331. std::cin.clear();
  332. tlog1 << "Invalid resolution ID! Not a number between 0 and " << conf.guiOptions.size() << ". No settings changed.\n";
  333. }
  334. else if(!i)
  335. {
  336. return;
  337. }
  338. else
  339. {
  340. for(j=conf.guiOptions.begin(); j!=conf.guiOptions.end() && hlp++<i; j++); //move j to the i-th resolution info
  341. conf.cc.resx = j->first.first;
  342. conf.cc.resy = j->first.second;
  343. tlog0 << "Screen resolution set to " << conf.cc.resx << " x " << conf.cc.resy <<". It will be aplied when the game starts.\n";
  344. }
  345. }
  346. else if(message=="get txt")
  347. {
  348. boost::filesystem::create_directory("Extracted_txts");
  349. tlog0<<"Command accepted. Opening .lod file...\t";
  350. CLodHandler * txth = new CLodHandler;
  351. txth->init(std::string(DATA_DIR "/Data/H3bitmap.lod"),"");
  352. tlog0<<"done.\nScanning .lod file\n";
  353. int curp=0;
  354. std::string pattern = ".TXT", pom;
  355. for(int i=0;i<txth->entries.size(); i++)
  356. {
  357. pom = txth->entries[i].nameStr;
  358. if(boost::algorithm::find_last(pom,pattern))
  359. {
  360. txth->extractFile(std::string(DATA_DIR "/Extracted_txts/")+pom,pom);
  361. }
  362. if(i%8) continue;
  363. int p2 = ((float)i/(float)txth->entries.size())*(float)100;
  364. if(p2!=curp)
  365. {
  366. curp = p2;
  367. tlog0<<"\r"<<curp<<"%";
  368. }
  369. }
  370. tlog0<<"\rExtracting done :)\n";
  371. }
  372. else if(cn=="crash")
  373. {
  374. int *ptr = NULL;
  375. *ptr = 666;
  376. //disaster!
  377. }
  378. else if(cn == "onlyai")
  379. {
  380. gOnlyAI = true;
  381. }
  382. else if(client && client->serv && client->serv->connected) //send to server
  383. {
  384. PlayerMessage pm(LOCPLINT->playerID,message);
  385. *client->serv << &pm;
  386. }
  387. }
  388. //plays intro, ends when intro is over or button has been pressed (handles events)
  389. void playIntro()
  390. {
  391. if(CGI->videoh->openAndPlayVideo("3DOLOGO.SMK", 60, 40, screen, true))
  392. {
  393. CGI->videoh->openAndPlayVideo("AZVS.SMK", 60, 80, screen, true);
  394. }
  395. }
  396. void dispose()
  397. {
  398. delete logfile;
  399. if (console)
  400. delete console;
  401. }
  402. static void setScreenRes(int w, int h, int bpp, bool fullscreen)
  403. {
  404. // VCMI will only work with 3 or 4 bytes per pixel
  405. if (bpp < 24) bpp = 24;
  406. if (bpp > 32) bpp = 32;
  407. // Try to use the best screen depth for the display
  408. int suggestedBpp = SDL_VideoModeOK(w, h, bpp, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0));
  409. if(suggestedBpp == 0)
  410. {
  411. tlog1 << "Error: SDL says that " << w << "x" << h << " resolution is not available!\n";
  412. return;
  413. }
  414. bool bufOnScreen = (screenBuf == screen);
  415. if(suggestedBpp != bpp)
  416. {
  417. tlog2 << "Warning: SDL says that " << bpp << "bpp is wrong and suggests " << suggestedBpp << std::endl;
  418. }
  419. if(screen) //screen has been already initialized
  420. SDL_QuitSubSystem(SDL_INIT_VIDEO);
  421. SDL_InitSubSystem(SDL_INIT_VIDEO);
  422. if((screen = SDL_SetVideoMode(w, h, suggestedBpp, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0))) == NULL)
  423. {
  424. tlog1 << "Requested screen resolution is not available (" << w << "x" << h << "x" << suggestedBpp << "bpp)\n";
  425. throw "Requested screen resolution is not available\n";
  426. }
  427. tlog0 << "New screen flags: " << screen->flags << std::endl;
  428. if(screen2)
  429. SDL_FreeSurface(screen2);
  430. screen2 = CSDL_Ext::copySurface(screen);
  431. SDL_EnableUNICODE(1);
  432. SDL_WM_SetCaption(NAME.c_str(),""); //set window title
  433. SDL_ShowCursor(SDL_DISABLE);
  434. SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
  435. #ifdef _WIN32
  436. SDL_SysWMinfo wm;
  437. SDL_VERSION(&wm.version);
  438. int getwm = SDL_GetWMInfo(&wm);
  439. if(getwm == 1)
  440. {
  441. int sw = GetSystemMetrics(SM_CXSCREEN),
  442. sh = GetSystemMetrics(SM_CYSCREEN);
  443. RECT curpos;
  444. GetWindowRect(wm.window,&curpos);
  445. int ourw = curpos.right - curpos.left,
  446. ourh = curpos.bottom - curpos.top;
  447. SetWindowPos(wm.window, 0, (sw - ourw)/2, (sh - ourh)/2, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
  448. }
  449. else
  450. {
  451. tlog3 << "Something went wrong, getwm=" << getwm << std::endl;
  452. tlog3 << "SDL says: " << SDL_GetError() << std::endl;
  453. tlog3 << "Window won't be centered.\n";
  454. }
  455. #endif
  456. //TODO: centering game window on other platforms (or does the environment do their job correctly there?)
  457. screenBuf = bufOnScreen ? screen : screen2;
  458. }
  459. static void listenForEvents()
  460. {
  461. while(1) //main SDL events loop
  462. {
  463. SDL_Event *ev = new SDL_Event();
  464. //tlog0 << "Waiting... ";
  465. int ret = SDL_WaitEvent(ev);
  466. //tlog0 << "got " << (int)ev->type;
  467. if (ret == 0 || (ev->type==SDL_QUIT) ||
  468. (ev->type == SDL_KEYDOWN && ev->key.keysym.sym==SDLK_F4 && (ev->key.keysym.mod & KMOD_ALT)))
  469. {
  470. if (client)
  471. client->stop();
  472. if (mainGUIThread)
  473. {
  474. GH.terminate = true;
  475. mainGUIThread->join();
  476. delete mainGUIThread;
  477. mainGUIThread = NULL;
  478. }
  479. delete console;
  480. console = NULL;
  481. SDL_Delay(750);
  482. SDL_Quit();
  483. tlog0 << "Ending...\n";
  484. break;
  485. }
  486. else if(LOCPLINT && ev->type == SDL_KEYDOWN && ev->key.keysym.sym==SDLK_F4)
  487. {
  488. boost::unique_lock<boost::recursive_mutex> lock(*LOCPLINT->pim);
  489. bool full = !(screen->flags&SDL_FULLSCREEN);
  490. setScreenRes(conf.cc.resx,conf.cc.resy,conf.cc.bpp,full);
  491. GH.totalRedraw();
  492. delete ev;
  493. continue;
  494. }
  495. else if(ev->type == SDL_USEREVENT && ev->user.code == 1)
  496. {
  497. setScreenRes(conf.cc.resx,conf.cc.resy,conf.cc.bpp,conf.cc.fullscreen);
  498. setResolution = true;
  499. delete ev;
  500. continue;
  501. }
  502. else if (ev->type == SDL_USEREVENT && ev->user.code == 2) //something want to quit to main menu
  503. {
  504. client->stop();
  505. delete client;
  506. client = NULL;
  507. delete ev;
  508. GH.curInt = CGP;
  509. GH.defActionsDef = 63;
  510. continue;
  511. }
  512. //tlog0 << " pushing ";
  513. eventsM.lock();
  514. events.push(ev);
  515. eventsM.unlock();
  516. //tlog0 << " done\n";
  517. }
  518. }
  519. void startGame(StartInfo * options)
  520. {
  521. GH.curInt =NULL;
  522. if(gOnlyAI)
  523. {
  524. for (size_t i =0; i < options->playerInfos.size(); i++)
  525. {
  526. options->playerInfos[i].human = false;
  527. }
  528. }
  529. if(screen->w != conf.cc.resx || screen->h != conf.cc.resy)
  530. {
  531. //push special event to order event reading thread to change resolution
  532. SDL_Event ev;
  533. ev.type = SDL_USEREVENT;
  534. ev.user.code = 1;
  535. SDL_PushEvent(&ev);
  536. }
  537. else
  538. setResolution = true;
  539. client = new CClient;
  540. switch(options->mode) //new game
  541. {
  542. case 0:
  543. case 2:
  544. client->newGame(NULL, options);
  545. break;
  546. case 1:
  547. std::string fname = options->mapname;
  548. boost::algorithm::erase_last(fname,".vlgm1");
  549. client->loadGame(fname);
  550. break;
  551. }
  552. CGI->musich->stopMusic();
  553. //allow event handling thread change resolution
  554. eventsM.unlock();
  555. while(!setResolution) boost::this_thread::sleep(boost::posix_time::milliseconds(50));
  556. eventsM.lock();
  557. client->connectionHandler = new boost::thread(&CClient::run, client);
  558. }