MainClient.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. #include "MainClient.h"
  2. #include <Klient.h>
  3. #include "Keys.h"
  4. #include "ErhaltungClient.h"
  5. #include "PatchClient.h"
  6. #include "NewsClient.h"
  7. #include "RegisterServer.h"
  8. #include "LoginClient.h"
  9. #include "ShopClient.h"
  10. #include "ChatClient.h"
  11. #include "AnmeldungClient.h"
  12. #include "MinigameClient.h"
  13. #include "InformationClient.h"
  14. using namespace KSGClient;
  15. // Inhalt der MainClient Klasse
  16. // Konstruktor
  17. MainClient::MainClient()
  18. : ReferenceCounter()
  19. {
  20. port = 0;
  21. cId = 0;
  22. k = 0;
  23. key = 0;
  24. keyLen = 0;
  25. }
  26. MainClient::MainClient(const char* ip, unsigned short port, int klientId, const char* key, unsigned char keyLen)
  27. : ReferenceCounter()
  28. {
  29. this->ip = ip;
  30. this->port = port;
  31. cId = klientId;
  32. k = 0;
  33. this->keyLen = keyLen;
  34. this->key = new char[keyLen];
  35. memcpy(this->key, key, keyLen);
  36. }
  37. // Destruktor
  38. MainClient::~MainClient()
  39. {
  40. if (k)
  41. disconnect();
  42. delete[]key;
  43. }
  44. // Meldet den neuen Client beim Serversystem an. Durch diesen Vorgang erhält der Client eine Id und den Port und die Ip Addresse des Main Servers
  45. bool MainClient::registerSSL(const char* ip, unsigned short port)
  46. {
  47. cs.lock();
  48. if (cId)
  49. {
  50. cs.unlock();
  51. return 0;
  52. }
  53. Network::SSLKlient* klientSSL = new Network::SSLKlient();
  54. int l = 0;
  55. if (!klientSSL->verbinde(port, ip))
  56. {
  57. err = "error while trying to connect to Main SSL Server";
  58. klientSSL->release();
  59. cs.unlock();
  60. return 0;
  61. }
  62. klientSSL->sende("\1", 5);
  63. char byte = 0;
  64. klientSSL->getNachricht(&byte, 1);
  65. if (byte == 3)
  66. {
  67. klientSSL->getNachricht(&byte, 1);
  68. char* message = new char[byte + 1];
  69. message[byte] = 0;
  70. klientSSL->getNachricht(message, byte);
  71. err = "error while register new client server returned: ";
  72. err += message;
  73. delete[]message;
  74. klientSSL->sende("\3", 1);
  75. klientSSL->getNachricht(&byte, 1);
  76. klientSSL->trenne();
  77. klientSSL->release();
  78. cs.unlock();
  79. return 0;
  80. }
  81. if (byte == 1)
  82. {
  83. klientSSL->getNachricht((char*)&this->port, 4);
  84. klientSSL->getNachricht((char*)&cId, 4);
  85. klientSSL->getNachricht((char*)&keyLen, 1);
  86. this->ip = ip;
  87. if (keyLen)
  88. {
  89. key = new char[keyLen];
  90. klientSSL->getNachricht(key, keyLen);
  91. }
  92. }
  93. klientSSL->sende("\3", 1);
  94. klientSSL->getNachricht(&byte, 1);
  95. klientSSL->trenne();
  96. klientSSL->release();
  97. cs.unlock();
  98. return 1;
  99. }
  100. // Verbindet den Client mit dem Server
  101. // Wird automatisch aufgerufen, falls eine Methode aufgerufen wird, die eine Verbindung erfordert. In diesem Fall wird die Verbindung auch automatisch wieder getrennt.
  102. bool MainClient::connect()
  103. {
  104. cs.lock();
  105. if (k)
  106. {
  107. cs.unlock();
  108. return 1;
  109. }
  110. k = new Network::Klient();
  111. int l = 0;
  112. char* key;
  113. Keys::getServerKey(&key, l, Keys::MAIN, Keys::SENDEN);
  114. k->setSendeKey(key, l);
  115. delete[] key;
  116. Keys::getServerKey(&key, l, Keys::MAIN, Keys::EMPFANGEN);
  117. k->setEmpfangKey(key, l);
  118. delete[] key;
  119. if (!k->verbinde(port, ip))
  120. {
  121. err = "error while trying to connect to Main Server";
  122. k = (Network::Klient*)k->release();
  123. cs.unlock();
  124. return 0;
  125. }
  126. k->sende("\0", 1); // Verschlüsselung aktivieren
  127. k->sendeEncrypted("\1", 1);
  128. k->sendeEncrypted((char*)&cId, 4);
  129. char serverReturn = 0;
  130. k->getNachrichtEncrypted(&serverReturn, 1);
  131. if (serverReturn == 3)
  132. {
  133. k->getNachrichtEncrypted(&serverReturn, 1);
  134. char* message = new char[serverReturn + 1];
  135. message[serverReturn] = 0;
  136. k->getNachrichtEncrypted(message, serverReturn);
  137. err = "error while trying to identify registered client server returned: ";
  138. err += message;
  139. delete[] message;
  140. k->sendeEncrypted("\3", 1);
  141. k->getNachrichtEncrypted(&serverReturn, 1);
  142. k->trenne();
  143. k = (Network::Klient*)k->release();
  144. cs.unlock();
  145. return 0;
  146. }
  147. else
  148. {
  149. k->setSendeKey(this->key, keyLen);
  150. k->setEmpfangKey(this->key, keyLen);
  151. cs.unlock();
  152. return 1;
  153. }
  154. }
  155. // Erzeugt einen Erhaltungs Server Client
  156. // Gibt bei misserfolg 0 zurück
  157. ErhaltungServerClient* MainClient::createErhaltungServerClient()
  158. {
  159. cs.lock();
  160. bool connected = k != 0;
  161. if (!connected)
  162. connect();
  163. if (!k)
  164. {
  165. cs.unlock();
  166. return 0;
  167. }
  168. k->sendeEncrypted("\6\x8", 2);
  169. char byte = 0;
  170. k->getNachrichtEncrypted(&byte, 1);
  171. if (byte == 2)
  172. {
  173. unsigned char lsIp[4];
  174. k->getNachrichtEncrypted((char*)lsIp, 4);
  175. unsigned short lsPort = 0;
  176. k->getNachrichtEncrypted((char*)&lsPort, 2);
  177. Framework::Text ipT;
  178. ipT += (int)lsIp[0];
  179. ipT += ".";
  180. ipT += (int)lsIp[1];
  181. ipT += ".";
  182. ipT += (int)lsIp[2];
  183. ipT += ".";
  184. ipT += (int)lsIp[3];
  185. if (!connected)
  186. disconnect();
  187. cs.unlock();
  188. return new ErhaltungClient(cId, lsPort, ipT, key, keyLen);
  189. }
  190. else if (byte == 3)
  191. {
  192. k->getNachrichtEncrypted(&byte, 1);
  193. char* f = new char[byte + 1];
  194. f[byte] = 0;
  195. k->getNachrichtEncrypted(f, byte);
  196. err = "error while requesting ErhaltungServer server returned: ";
  197. err += f;
  198. delete[]f;
  199. }
  200. if (!connected)
  201. disconnect();
  202. cs.unlock();
  203. return 0;
  204. }
  205. // Erzeugt einen Patch Server Client
  206. // Gibt bei misserfolg 0 zurück
  207. PatchServerClient* MainClient::createPatchServerClient()
  208. {
  209. cs.lock();
  210. bool connected = k != 0;
  211. if (!connected)
  212. connect();
  213. if (!k)
  214. {
  215. cs.unlock();
  216. return 0;
  217. }
  218. k->sendeEncrypted("\6\2", 2);
  219. char byte = 0;
  220. k->getNachrichtEncrypted(&byte, 1);
  221. if (byte == 2)
  222. {
  223. unsigned char lsIp[4];
  224. k->getNachrichtEncrypted((char*)lsIp, 4);
  225. unsigned short lsPort = 0;
  226. k->getNachrichtEncrypted((char*)&lsPort, 2);
  227. Framework::Text ipT;
  228. ipT += (int)lsIp[0];
  229. ipT += ".";
  230. ipT += (int)lsIp[1];
  231. ipT += ".";
  232. ipT += (int)lsIp[2];
  233. ipT += ".";
  234. ipT += (int)lsIp[3];
  235. if (!connected)
  236. disconnect();
  237. cs.unlock();
  238. return new PatchClient(cId, lsPort, ipT, key, keyLen);
  239. }
  240. else if (byte == 3)
  241. {
  242. k->getNachrichtEncrypted(&byte, 1);
  243. char* f = new char[byte + 1];
  244. f[byte] = 0;
  245. k->getNachrichtEncrypted(f, byte);
  246. err = "error while requesting PatchServer server returned: ";
  247. err += f;
  248. delete[]f;
  249. }
  250. if (!connected)
  251. disconnect();
  252. cs.unlock();
  253. return 0;
  254. }
  255. // Erzeugt einen News Server Client
  256. // Gibt bei misserfolg 0 zurück
  257. NewsServerClient* MainClient::createNewsServerClient()
  258. {
  259. cs.lock();
  260. bool connected = k != 0;
  261. if (!connected)
  262. connect();
  263. if (!k)
  264. {
  265. cs.unlock();
  266. return 0;
  267. }
  268. k->sendeEncrypted("\6\x9", 2);
  269. char byte = 0;
  270. k->getNachrichtEncrypted(&byte, 1);
  271. if (byte == 2)
  272. {
  273. unsigned char lsIp[4];
  274. k->getNachrichtEncrypted((char*)lsIp, 4);
  275. unsigned short lsPort = 0;
  276. k->getNachrichtEncrypted((char*)&lsPort, 2);
  277. Framework::Text ipT;
  278. ipT += (int)lsIp[0];
  279. ipT += ".";
  280. ipT += (int)lsIp[1];
  281. ipT += ".";
  282. ipT += (int)lsIp[2];
  283. ipT += ".";
  284. ipT += (int)lsIp[3];
  285. if (!connected)
  286. disconnect();
  287. cs.unlock();
  288. return new NewsClient(cId, lsPort, ipT, key, keyLen);
  289. }
  290. else if (byte == 3)
  291. {
  292. k->getNachrichtEncrypted(&byte, 1);
  293. char* f = new char[byte + 1];
  294. f[byte] = 0;
  295. k->getNachrichtEncrypted(f, byte);
  296. err = "error while requesting NewsServer server returned: ";
  297. err += f;
  298. delete[]f;
  299. }
  300. if (!connected)
  301. disconnect();
  302. cs.unlock();
  303. return 0;
  304. }
  305. // Erzeugt einen Register Server Client
  306. // Gibt bei misserfolg 0 zurück
  307. RegisterServerClient* MainClient::createRegisterServerClient()
  308. {
  309. cs.lock();
  310. bool connected = k != 0;
  311. if (!connected)
  312. connect();
  313. if (!k)
  314. {
  315. cs.unlock();
  316. return 0;
  317. }
  318. k->sendeEncrypted("\6\1", 2);
  319. char byte = 0;
  320. k->getNachrichtEncrypted(&byte, 1);
  321. if (byte == 2)
  322. {
  323. unsigned char lsIp[4];
  324. k->getNachrichtEncrypted((char*)lsIp, 4);
  325. unsigned short lsPort = 0;
  326. k->getNachrichtEncrypted((char*)&lsPort, 2);
  327. Framework::Text ipT;
  328. ipT += (int)lsIp[0];
  329. ipT += ".";
  330. ipT += (int)lsIp[1];
  331. ipT += ".";
  332. ipT += (int)lsIp[2];
  333. ipT += ".";
  334. ipT += (int)lsIp[3];
  335. if (!connected)
  336. disconnect();
  337. cs.unlock();
  338. return new RegisterClient(cId, lsPort, ipT, key, keyLen);
  339. }
  340. else if (byte == 3)
  341. {
  342. k->getNachrichtEncrypted(&byte, 1);
  343. char* f = new char[byte + 1];
  344. f[byte] = 0;
  345. k->getNachrichtEncrypted(f, byte);
  346. err = "error while requesting RegisterServer server returned: ";
  347. err += f;
  348. delete[]f;
  349. }
  350. if (!connected)
  351. disconnect();
  352. cs.unlock();
  353. return 0;
  354. }
  355. // Erzeugt einen Login Server Client
  356. // Gibt bei misserfolg 0 zurück
  357. LoginServerClient* MainClient::createLoginServerClient()
  358. {
  359. cs.lock();
  360. bool connected = k != 0;
  361. if (!connected)
  362. connect();
  363. if (!k)
  364. {
  365. cs.unlock();
  366. return 0;
  367. }
  368. k->sendeEncrypted("\6\3", 2);
  369. char byte = 0;
  370. k->getNachrichtEncrypted(&byte, 1);
  371. if (byte == 2)
  372. {
  373. unsigned char lsIp[4];
  374. k->getNachrichtEncrypted((char*)lsIp, 4);
  375. unsigned short lsPort = 0;
  376. k->getNachrichtEncrypted((char*)&lsPort, 2);
  377. Framework::Text ipT;
  378. ipT += (int)lsIp[0];
  379. ipT += ".";
  380. ipT += (int)lsIp[1];
  381. ipT += ".";
  382. ipT += (int)lsIp[2];
  383. ipT += ".";
  384. ipT += (int)lsIp[3];
  385. if (!connected)
  386. disconnect();
  387. cs.unlock();
  388. return new LoginClient(cId, lsPort, ipT, key, keyLen);
  389. }
  390. else if (byte == 3)
  391. {
  392. k->getNachrichtEncrypted(&byte, 1);
  393. char* f = new char[byte + 1];
  394. f[byte] = 0;
  395. k->getNachrichtEncrypted(f, byte);
  396. err = "error while requesting LoginServer server returned: ";
  397. err += f;
  398. delete[]f;
  399. }
  400. if (!connected)
  401. disconnect();
  402. cs.unlock();
  403. return 0;
  404. }
  405. // Erzeugt einen Information Server Client
  406. // Gibt bei misserfolg 0 zurück
  407. InformationServerClient* MainClient::createInformationServerClient()
  408. {
  409. cs.lock();
  410. bool connected = k != 0;
  411. if (!connected)
  412. connect();
  413. if (!k)
  414. {
  415. cs.unlock();
  416. return 0;
  417. }
  418. k->sendeEncrypted("\6\4", 2);
  419. char byte = 0;
  420. k->getNachrichtEncrypted(&byte, 1);
  421. if (byte == 2)
  422. {
  423. unsigned char lsIp[4];
  424. k->getNachrichtEncrypted((char*)lsIp, 4);
  425. unsigned short lsPort = 0;
  426. k->getNachrichtEncrypted((char*)&lsPort, 2);
  427. Framework::Text ipT;
  428. ipT += (int)lsIp[0];
  429. ipT += ".";
  430. ipT += (int)lsIp[1];
  431. ipT += ".";
  432. ipT += (int)lsIp[2];
  433. ipT += ".";
  434. ipT += (int)lsIp[3];
  435. if (!connected)
  436. disconnect();
  437. cs.unlock();
  438. return new InformationClient(cId, lsPort, ipT, key, keyLen);
  439. }
  440. else if (byte == 3)
  441. {
  442. k->getNachrichtEncrypted(&byte, 1);
  443. char* f = new char[byte + 1];
  444. f[byte] = 0;
  445. k->getNachrichtEncrypted(f, byte);
  446. err = "error while requesting InformationServer server returned: ";
  447. err += f;
  448. delete[]f;
  449. }
  450. if (!connected)
  451. disconnect();
  452. cs.unlock();
  453. return 0;
  454. }
  455. // Erzeugt einen Chat Server Client
  456. // Gibt bei misserfolg 0 zurück
  457. ChatServerClient* MainClient::createChatServerClient()
  458. {
  459. cs.lock();
  460. bool connected = k != 0;
  461. if (!connected)
  462. connect();
  463. if (!k)
  464. {
  465. cs.unlock();
  466. return 0;
  467. }
  468. k->sendeEncrypted("\6\5", 2);
  469. char byte = 0;
  470. k->getNachrichtEncrypted(&byte, 1);
  471. if (byte == 2)
  472. {
  473. unsigned char lsIp[4];
  474. k->getNachrichtEncrypted((char*)lsIp, 4);
  475. unsigned short lsPort = 0;
  476. k->getNachrichtEncrypted((char*)&lsPort, 2);
  477. Framework::Text ipT;
  478. ipT += (int)lsIp[0];
  479. ipT += ".";
  480. ipT += (int)lsIp[1];
  481. ipT += ".";
  482. ipT += (int)lsIp[2];
  483. ipT += ".";
  484. ipT += (int)lsIp[3];
  485. if (!connected)
  486. disconnect();
  487. cs.unlock();
  488. return new ChatClient(cId, lsPort, ipT, key, keyLen);
  489. }
  490. else if (byte == 3)
  491. {
  492. k->getNachrichtEncrypted(&byte, 1);
  493. char* f = new char[byte + 1];
  494. f[byte] = 0;
  495. k->getNachrichtEncrypted(f, byte);
  496. err = "error while requesting ChatServer server returned: ";
  497. err += f;
  498. delete[]f;
  499. }
  500. if (!connected)
  501. disconnect();
  502. cs.unlock();
  503. return 0;
  504. }
  505. // Erzeugt einen Shop Server Client
  506. // Gibt bei misserfolg 0 zurück
  507. ShopServerClient* MainClient::createShopServerClient()
  508. {
  509. cs.lock();
  510. bool connected = k != 0;
  511. if (!connected)
  512. connect();
  513. if (!k)
  514. {
  515. cs.unlock();
  516. return 0;
  517. }
  518. k->sendeEncrypted("\6\7", 2);
  519. char byte = 0;
  520. k->getNachrichtEncrypted(&byte, 1);
  521. if (byte == 2)
  522. {
  523. unsigned char lsIp[4];
  524. k->getNachrichtEncrypted((char*)lsIp, 4);
  525. unsigned short lsPort = 0;
  526. k->getNachrichtEncrypted((char*)&lsPort, 2);
  527. Framework::Text ipT;
  528. ipT += (int)lsIp[0];
  529. ipT += ".";
  530. ipT += (int)lsIp[1];
  531. ipT += ".";
  532. ipT += (int)lsIp[2];
  533. ipT += ".";
  534. ipT += (int)lsIp[3];
  535. if (!connected)
  536. disconnect();
  537. cs.unlock();
  538. return new ShopClient(cId, lsPort, ipT, key, keyLen);
  539. }
  540. else if (byte == 3)
  541. {
  542. k->getNachrichtEncrypted(&byte, 1);
  543. char* f = new char[byte + 1];
  544. f[byte] = 0;
  545. k->getNachrichtEncrypted(f, byte);
  546. err = "error while requesting ShopServer server returned: ";
  547. err += f;
  548. delete[]f;
  549. }
  550. if (!connected)
  551. disconnect();
  552. cs.unlock();
  553. return 0;
  554. }
  555. // Erzeugt einen Anmeldung Server Client
  556. // Gibt bei misserfolg 0 zurück
  557. AnmeldungServerClient* MainClient::createAnmeldungServerClient()
  558. {
  559. cs.lock();
  560. bool connected = k != 0;
  561. if (!connected)
  562. connect();
  563. if (!k)
  564. {
  565. cs.unlock();
  566. return 0;
  567. }
  568. k->sendeEncrypted("\6\6", 2);
  569. char byte = 0;
  570. k->getNachrichtEncrypted(&byte, 1);
  571. if (byte == 2)
  572. {
  573. unsigned char lsIp[4];
  574. k->getNachrichtEncrypted((char*)lsIp, 4);
  575. unsigned short lsPort = 0;
  576. k->getNachrichtEncrypted((char*)&lsPort, 2);
  577. Framework::Text ipT;
  578. ipT += (int)lsIp[0];
  579. ipT += ".";
  580. ipT += (int)lsIp[1];
  581. ipT += ".";
  582. ipT += (int)lsIp[2];
  583. ipT += ".";
  584. ipT += (int)lsIp[3];
  585. if (!connected)
  586. disconnect();
  587. cs.unlock();
  588. return new AnmeldungClient(cId, lsPort, ipT, key, keyLen);
  589. }
  590. else if (byte == 3)
  591. {
  592. k->getNachrichtEncrypted(&byte, 1);
  593. char* f = new char[byte + 1];
  594. f[byte] = 0;
  595. k->getNachrichtEncrypted(f, byte);
  596. err = "error while requesting AnmeldungServer server returned: ";
  597. err += f;
  598. delete[]f;
  599. }
  600. if (!connected)
  601. disconnect();
  602. cs.unlock();
  603. return 0;
  604. }
  605. // Erzeugt einen Minigame Server Client
  606. // Gibt bei misserfolg 0 zurück
  607. MinigameServerClient* MainClient::createMinigameServerClient()
  608. {
  609. cs.lock();
  610. bool connected = k != 0;
  611. if (!connected)
  612. connect();
  613. if (!k)
  614. {
  615. cs.unlock();
  616. return 0;
  617. }
  618. k->sendeEncrypted("\6\xA", 2);
  619. char byte = 0;
  620. k->getNachrichtEncrypted(&byte, 1);
  621. if (byte == 2)
  622. {
  623. unsigned char lsIp[4];
  624. k->getNachrichtEncrypted((char*)lsIp, 4);
  625. unsigned short lsPort = 0;
  626. k->getNachrichtEncrypted((char*)&lsPort, 2);
  627. Framework::Text ipT;
  628. ipT += (int)lsIp[0];
  629. ipT += ".";
  630. ipT += (int)lsIp[1];
  631. ipT += ".";
  632. ipT += (int)lsIp[2];
  633. ipT += ".";
  634. ipT += (int)lsIp[3];
  635. if (!connected)
  636. disconnect();
  637. cs.unlock();
  638. return new MinigameClient(cId, lsPort, ipT, key, keyLen);
  639. }
  640. else if (byte == 3)
  641. {
  642. k->getNachrichtEncrypted(&byte, 1);
  643. char* f = new char[byte + 1];
  644. f[byte] = 0;
  645. k->getNachrichtEncrypted(f, byte);
  646. err = "error while requesting MinigameServer server returned: ";
  647. err += f;
  648. delete[]f;
  649. }
  650. if (!connected)
  651. disconnect();
  652. cs.unlock();
  653. return 0;
  654. }
  655. // Trennt die Verbindung zum Server. Muss nur aufgerufen werden, wenn vorher manuell connect aufgerufen wurde
  656. bool MainClient::disconnect()
  657. {
  658. cs.lock();
  659. if (!k)
  660. {
  661. cs.unlock();
  662. return 1;
  663. }
  664. char serverReturn = 0;
  665. k->sendeEncrypted("\3", 1);
  666. k->getNachrichtEncrypted(&serverReturn, 1);
  667. k->trenne();
  668. k = (Network::Klient*)k->release();
  669. cs.unlock();
  670. return 1;
  671. }
  672. // Meldet den Client vom Server ab. Alle zuvor von diesem Client erzeugten Clients werden durch diesen Vorgang unbrauchbar
  673. bool MainClient::unregister()
  674. {
  675. cs.lock();
  676. bool connected = k != 0;
  677. if (!connected)
  678. connect();
  679. if (!k)
  680. {
  681. cs.unlock();
  682. return 0;
  683. }
  684. k->sendeEncrypted("\7", 1);
  685. char serverReturn = 0;
  686. k->getNachrichtEncrypted(&serverReturn, 1);
  687. if (serverReturn == 3)
  688. {
  689. k->getNachrichtEncrypted(&serverReturn, 1);
  690. char* message = new char[serverReturn + 1];
  691. message[serverReturn] = 0;
  692. k->getNachrichtEncrypted(message, serverReturn);
  693. err = "error while trying to unregistere client server returned: ";
  694. err += message;
  695. delete[] message;
  696. if (!connected)
  697. disconnect();
  698. cs.unlock();
  699. return 0;
  700. }
  701. disconnect();
  702. cId = 0;
  703. delete key;
  704. key = 0;
  705. keyLen = 0;
  706. port = 0;
  707. ip = "";
  708. cs.unlock();
  709. return 1;
  710. }
  711. // Gibt die dem Client zugewiesene Id zurück.
  712. // sollte erst nach dem Aufruf von registerSSL verwendet werden.
  713. int MainClient::getClientId() const
  714. {
  715. return cId;
  716. }
  717. // Gibt die Ip Adresse des dem Client zugewiesenen Main Servers zurück.
  718. // sollte erst nach dem Aufruf von registerSSL verwendet werden.
  719. const char* MainClient::getServerIp() const
  720. {
  721. return ip.getText();
  722. }
  723. // Gibt den Port des dem Client zugewiesenen Main Servers zurück.
  724. // sollte erst nach dem Aufruf von registerSSL verwendet werden.
  725. unsigned short MainClient::getServerPort() const
  726. {
  727. return port;
  728. }
  729. // Gibt den Zeiger auf den Schlüssel zurück
  730. // sollte erst nach dem Aufruf von registerSSL verwendet werden.
  731. const char* MainClient::zKey() const
  732. {
  733. return key;
  734. }
  735. // Gibt die Länge des Schlüssels zurück
  736. // sollte erst nach dem Aufruf von registerSSL verwendet werden.
  737. unsigned char MainClient::getKeyLen() const
  738. {
  739. return keyLen;
  740. }
  741. // gibt den Letzten Fehlertext zuück
  742. // sollte erst aufgerufen werden, nachdem eine andere aufgerufene Methode fehlgeschlagen ist
  743. const char* MainClient::getLetzterFehler() const
  744. {
  745. return err;
  746. }