ChatServer.cpp 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389
  1. #include "ChatServer.h"
  2. #include <iostream>
  3. #include <Globals.h>
  4. #ifndef WIN32
  5. #include <unistd.h>
  6. #define Sleep( x ) usleep( (x) * 1000 )
  7. #endif
  8. // Inhalt der ChatServer Klasse aus ChatServer.h
  9. // Konstruktor
  10. ChatServer::ChatServer(InitDatei* zIni)
  11. : Thread()
  12. {
  13. Network::Start(100);
  14. std::cout << "CS: Verbindung mit Datenbank wird hergestellt...\n";
  15. db = new CSDatenbank(zIni);
  16. klients = new RCArray< CSKlient >();
  17. empfangen = 0;
  18. gesendet = 0;
  19. fehler = new Text();
  20. ini = dynamic_cast<InitDatei*>(zIni->getThis());
  21. id = (int)*zIni->zWert("ServerId");
  22. server = new Server();
  23. aServer = new SSLServer();
  24. aServer->setPrivateKeyPassword(zIni->zWert("SSLPasswort")->getText());
  25. aServer->setCertificateFile(zIni->zWert("SSLCert")->getText());
  26. aServer->setPrivateKeyFile(zIni->zWert("SSLKey")->getText());
  27. std::cout << "CS: Starten des Admin Servers...\n";
  28. if (!aServer->verbinde((unsigned short)TextZuInt(ini->zWert("AdminServerPort")->getText(), 10), 10))
  29. {
  30. std::cout << "CS: Der Admin Server konnte nicht gestartet werden. Das Programm wird beendet.\n";
  31. exit(1);
  32. }
  33. db->setServerStatus(id, 2);
  34. end = 0;
  35. nichtPausiert = 0;
  36. if (zIni->zWert("Aktiv")->istGleich("TRUE"))
  37. {
  38. serverStarten();
  39. serverFortsetzen();
  40. }
  41. }
  42. // Destruktor
  43. ChatServer::~ChatServer()
  44. {
  45. fehler->release();
  46. server->trenne();
  47. server->release();
  48. aServer->trenne();
  49. aServer->release();
  50. ini->release();
  51. db->release();
  52. if (klients)
  53. klients->release();
  54. }
  55. // nicht constant
  56. void ChatServer::runn()
  57. {
  58. while (!end && aServer->isConnected())
  59. {
  60. SSLSKlient* klient;
  61. klient = aServer->getKlient();
  62. if (end && klient)
  63. {
  64. klient->trenne();
  65. klient = (SSLSKlient*)klient->release();
  66. Sleep(1000);
  67. return;
  68. }
  69. if (!klient)
  70. continue;
  71. CSAKlient* clHandle = new CSAKlient(klient, dynamic_cast<ChatServer*>(getThis()));
  72. clHandle->start();
  73. }
  74. }
  75. void ChatServer::thread()
  76. {
  77. while (server->isConnected())
  78. {
  79. SKlient* klient;
  80. klient = server->getKlient();
  81. if (!klient)
  82. continue;
  83. Framework::getThreadRegister()->cleanUpClosedThreads();
  84. CSKlient* clHandle = new CSKlient(klient, dynamic_cast<ChatServer*>(getThis()));
  85. cs.lock();
  86. klients->add(clHandle);
  87. cs.unlock();
  88. clHandle->start();
  89. }
  90. }
  91. void ChatServer::close()
  92. {
  93. db->setServerStatus(id, 1);
  94. server->trenne();
  95. #ifdef WIN32
  96. warteAufThread(1000);
  97. #endif
  98. cs.lock();
  99. for (CSKlient* client : *klients)
  100. client->absturz();
  101. klients = (RCArray<CSKlient> *)klients->release();
  102. cs.unlock();
  103. ende();
  104. run = 0;
  105. end = 1;
  106. Klient* klient = new Klient();
  107. klient->verbinde(aServer->getPort(), "127.0.0.1");
  108. Sleep(500);
  109. aServer->trenne();
  110. klient->release();
  111. }
  112. bool ChatServer::serverStarten()
  113. {
  114. if (nichtPausiert)
  115. {
  116. fehler->setText("Der Server konnte nicht gestartet werden: Der Server läuft bereits.");
  117. return 0;
  118. }
  119. if (server)
  120. server->release();
  121. server = new Server();
  122. if (server->verbinde((unsigned short)TextZuInt(ini->zWert("ServerPort")->getText(), 10), 10))
  123. {
  124. nichtPausiert = 1;
  125. start();
  126. return 1;
  127. }
  128. else
  129. {
  130. serverBeenden();
  131. fehler->setText("Der Server konnte nicht gestartet werden: Eventuell ist der Port in benutzung.");
  132. return 0;
  133. }
  134. }
  135. bool ChatServer::serverPause()
  136. {
  137. if (!nichtPausiert)
  138. {
  139. fehler->setText("Der Server konnte nicht pausiert werden: Der Server läuft nicht.");
  140. return 0;
  141. }
  142. if (!db->setServerStatus(id, 2))
  143. {
  144. fehler->setText("Der Server konnte nicht pausiert werden: ");
  145. fehler->append(db->getLetzterFehler());
  146. return 0;
  147. }
  148. return 1;
  149. }
  150. bool ChatServer::serverFortsetzen()
  151. {
  152. if (!nichtPausiert)
  153. {
  154. fehler->setText("Der Server konnte nicht fortgesetzt werden: Der Server läuft nicht.");
  155. return 0;
  156. }
  157. if (!db->setServerStatus(id, 3))
  158. {
  159. fehler->setText("Der Server konnte nicht fortgesetzt werden: ");
  160. fehler->append(db->getLetzterFehler());
  161. return 0;
  162. }
  163. return 1;
  164. }
  165. bool ChatServer::serverBeenden()
  166. {
  167. if (!nichtPausiert)
  168. {
  169. fehler->setText("Der Server konnte nicht beendet werden: Der Server läuft nicht.");
  170. return 0;
  171. }
  172. if (db->serverIstNichtPausiert(id))
  173. {
  174. fehler->setText("Der Server konnte nicht beendet werden: Der Server muss erst pausiert werden.");
  175. return 0;
  176. }
  177. nichtPausiert = 0;
  178. ende();
  179. if (server)
  180. server->trenne();
  181. return 1;
  182. }
  183. bool ChatServer::setMaxKlients(int mc)
  184. {
  185. if (!db->setMaxClients(id, mc))
  186. {
  187. fehler->setText("Die maximale Anzahl der Clients konnte nicht gesetzt werden:\n");
  188. fehler->append(db->getLetzterFehler());
  189. return 0;
  190. }
  191. ini->setWert("MaxClients", Text() += mc);
  192. return 1;
  193. }
  194. bool ChatServer::absturzKlient(int klientId)
  195. {
  196. bool gefunden = 0;
  197. cs.lock();
  198. for (int i = 0; i < klients->getEintragAnzahl(); i++)
  199. {
  200. if (klients->z(i)->getKlientNummer() == klientId)
  201. {
  202. klients->z(i)->absturz();
  203. klients->remove(i);
  204. gefunden = 1;
  205. i--;
  206. }
  207. }
  208. cs.unlock();
  209. return gefunden;
  210. }
  211. bool ChatServer::removeAccount(int accId)
  212. {
  213. bool gefunden = 0;
  214. cs.lock();
  215. for (int i = 0; i < klients->getEintragAnzahl(); i++)
  216. {
  217. if (klients->z(i)->getAccountId() == accId)
  218. {
  219. klients->remove(i);
  220. gefunden = 1;
  221. i--;
  222. }
  223. }
  224. cs.unlock();
  225. return gefunden;
  226. }
  227. bool ChatServer::removeKlient(int klientId)
  228. {
  229. bool gefunden = 0;
  230. cs.lock();
  231. for (int i = 0; i < klients->getEintragAnzahl(); i++)
  232. {
  233. if (klients->z(i)->getKlientNummer() == klientId)
  234. {
  235. klients->z(i)->trenne();
  236. klients->remove(i);
  237. gefunden = 1;
  238. i--;
  239. }
  240. }
  241. cs.unlock();
  242. return gefunden;
  243. }
  244. bool ChatServer::removeKlient(CSKlient* zKlient)
  245. {
  246. bool gefunden = 0;
  247. cs.lock();
  248. for (int i = 0; i < klients->getEintragAnzahl(); i++)
  249. {
  250. if (klients->z(i) == zKlient)
  251. {
  252. klients->z(i)->trenne();
  253. klients->remove(i);
  254. gefunden = 1;
  255. break;
  256. }
  257. }
  258. cs.unlock();
  259. return gefunden;
  260. }
  261. void ChatServer::addGesendet(int bytes)
  262. {
  263. gesendet += bytes;
  264. }
  265. void ChatServer::addEmpfangen(int bytes)
  266. {
  267. empfangen += bytes;
  268. }
  269. int ChatServer::getKlientStatus(int klientNummer, CSKlient* zKlient)
  270. {
  271. bool empf = 0;
  272. bool send = 0;
  273. cs.lock();
  274. for (int i = 0; i < klients->getEintragAnzahl(); i++)
  275. {
  276. if (klients->z(i)->getKlientNummer() == klientNummer && klients->z(i) != zKlient)
  277. {
  278. if (klients->z(i)->istEmpfang())
  279. empf = 1;
  280. else
  281. send = 1;
  282. }
  283. }
  284. cs.unlock();
  285. if (!empf)
  286. return 0;
  287. if (!send)
  288. return 1;
  289. return 2;
  290. }
  291. CSKlient* ChatServer::zSendeKlient(int accountId)
  292. {
  293. CSKlient* ret = 0;
  294. cs.lock();
  295. for (int i = 0; i < klients->getEintragAnzahl(); i++)
  296. {
  297. if (klients->z(i)->getAccountId() == accountId && !klients->z(i)->istEmpfang())
  298. {
  299. ret = klients->z(i);
  300. break;
  301. }
  302. }
  303. cs.unlock();
  304. return ret;
  305. }
  306. // constant
  307. bool ChatServer::istAn() const
  308. {
  309. return db->serverIstNichtPausiert(id);
  310. }
  311. Server* ChatServer::zServer() const
  312. {
  313. return server;
  314. }
  315. CSDatenbank* ChatServer::zDB() const
  316. {
  317. return db;
  318. }
  319. bool ChatServer::hatClients() const
  320. {
  321. return klients->hat(0);
  322. }
  323. int ChatServer::getId() const
  324. {
  325. return id;
  326. }
  327. const char* ChatServer::getLetzterFehler() const
  328. {
  329. return fehler->getText();
  330. }
  331. // Inhalt der CSAKlient Klasse aus ChatServer.h
  332. // Konstruktor
  333. CSAKlient::CSAKlient(SSLSKlient* klient, ChatServer* cs)
  334. : Thread()
  335. {
  336. this->klient = klient;
  337. name = new Text("");
  338. passwort = new Text("");
  339. adminId = 0;
  340. this->cs = cs;
  341. }
  342. // Destruktor
  343. CSAKlient::~CSAKlient()
  344. {
  345. klient->trenne();
  346. klient->release();
  347. cs->release();
  348. name->release();
  349. passwort->release();
  350. }
  351. // nicht constant
  352. void CSAKlient::thread()
  353. {
  354. while (1)
  355. {
  356. char c = 0;
  357. if (!klient->getNachricht(&c, 1))
  358. break;
  359. else
  360. {
  361. bool br = 0;
  362. switch (c)
  363. {
  364. case 1: // Login
  365. if (1)
  366. {
  367. klient->sende("\1", 1);
  368. unsigned char nLen = 0;
  369. klient->getNachricht((char*)&nLen, 1);
  370. char* n = new char[nLen + 1];
  371. n[(int)nLen] = 0;
  372. if (nLen)
  373. klient->getNachricht(n, nLen);
  374. unsigned char pLen = 0;
  375. klient->getNachricht((char*)&pLen, 1);
  376. char* p = new char[pLen + 1];
  377. p[(int)pLen] = 0;
  378. if (pLen)
  379. klient->getNachricht(p, pLen);
  380. int adminId = cs->zDB()->istAdministrator(n, p);
  381. if (adminId)
  382. {
  383. klient->sende("\1", 1);
  384. name->setText(n);
  385. passwort->setText(p);
  386. this->adminId = adminId;
  387. }
  388. else
  389. errorZuKlient("Falsche Kombination aus Name und Passwort.");
  390. delete[] n;
  391. delete[] p;
  392. }
  393. break;
  394. case 2: // Logout
  395. adminId = 0;
  396. name->setText("");
  397. passwort->setText("");
  398. klient->sende("\1", 1);
  399. break;
  400. case 3: // Trennen
  401. br = 1;
  402. klient->sende("\1", 1);
  403. break;
  404. case 4: // Server starten
  405. if (!adminId)
  406. errorZuKlient("Du musst dich einloggen.");
  407. else
  408. {
  409. if (cs->zDB()->adminHatRecht(adminId, Admin_Recht::CSStarten))
  410. {
  411. if (!cs->serverStarten())
  412. {
  413. Text* err = new Text();
  414. err->append(cs->getLetzterFehler());
  415. errorZuKlient(err->getText());
  416. err->release();
  417. }
  418. else
  419. klient->sende("\1", 1);
  420. }
  421. else
  422. errorZuKlient("Du bist nicht berechtigt den Server zu starten.");
  423. }
  424. break;
  425. case 5: // Server beenden
  426. if (!adminId)
  427. errorZuKlient("Du musst dich einloggen.");
  428. else
  429. {
  430. if (cs->zDB()->adminHatRecht(adminId, Admin_Recht::CSBeenden))
  431. {
  432. if (cs->serverBeenden())
  433. klient->sende("\1", 1);
  434. else
  435. {
  436. Text* err = new Text();
  437. err->append(cs->getLetzterFehler());
  438. errorZuKlient(err->getText());
  439. err->release();
  440. }
  441. }
  442. else
  443. errorZuKlient("Du bist nicht berechtigt den Server zu beenden.");
  444. }
  445. break;
  446. case 6: // Programm Schließen
  447. if (!adminId)
  448. errorZuKlient("Du musst dich einloggen.");
  449. else
  450. {
  451. bool ok = 0;
  452. if (cs->isRunning())
  453. {
  454. if (cs->zDB()->adminHatRecht(adminId, Admin_Recht::CSBeenden))
  455. {
  456. if (cs->serverBeenden())
  457. ok = 1;
  458. else
  459. {
  460. Text* err = new Text();
  461. err->append(cs->getLetzterFehler());
  462. errorZuKlient(err->getText());
  463. err->release();
  464. }
  465. }
  466. else
  467. errorZuKlient("Du bist nicht berechtigt den Server zu beenden.");
  468. }
  469. else
  470. ok = 1;
  471. if (ok && cs->hatClients())
  472. {
  473. errorZuKlient("Es sind noch Klients Online. Bitte versuche es später erneut.");
  474. break;
  475. }
  476. if (ok)
  477. {
  478. klient->sende("\1", 1);
  479. std::cout << "CS: Der Server wird von Benutzer " << adminId << " heruntergefahren.\n";
  480. cs->close();
  481. br = 1;
  482. }
  483. }
  484. break;
  485. case 7: // Progtamm abstürzen
  486. if (!adminId)
  487. errorZuKlient("Du musst dich einloggen.");
  488. else
  489. {
  490. bool ok = 0;
  491. if (cs->isRunning())
  492. {
  493. if (cs->zDB()->adminHatRecht(adminId, Admin_Recht::CSBeenden))
  494. {
  495. cs->serverBeenden();
  496. ok = 1;
  497. }
  498. else
  499. errorZuKlient("Du bist nicht berechtigt den Server zu beenden.");
  500. }
  501. else
  502. ok = 1;
  503. if (ok)
  504. {
  505. klient->sende("\1", 1);
  506. std::cout << "CS: Der Server wurde von Benutzer " << adminId << " terminiert.\n";
  507. cs->close();
  508. br = 1;
  509. }
  510. }
  511. break;
  512. case 8: // Status Frage
  513. if (1)
  514. {
  515. char status = 0;
  516. if (cs->isRunning())
  517. {
  518. status = 1;
  519. if (cs->istAn())
  520. status = 2;
  521. }
  522. klient->sende("\1", 1);
  523. klient->sende(&status, 1);
  524. }
  525. break;
  526. case 9: // Server pausieren
  527. if (!adminId)
  528. errorZuKlient("Du musst dich einloggen.");
  529. else
  530. {
  531. klient->sende("\1", 1);
  532. char pause = 0;
  533. klient->getNachricht(&pause, 1);
  534. if (cs->zDB()->adminHatRecht(adminId, Admin_Recht::CSPausieren))
  535. {
  536. bool ok = 0;
  537. if (pause)
  538. ok = cs->serverPause();
  539. else
  540. ok = cs->serverFortsetzen();
  541. if (ok)
  542. klient->sende("\1", 1);
  543. else
  544. {
  545. Text* err = new Text();
  546. err->append(cs->getLetzterFehler());
  547. errorZuKlient(err->getText());
  548. err->release();
  549. }
  550. }
  551. else
  552. {
  553. if (pause)
  554. errorZuKlient("Du bist nicht berechtigt den Server zu pausieren.");
  555. else
  556. errorZuKlient("Du bist nicht berechtigt den Server fortzusetzen.");
  557. }
  558. }
  559. break;
  560. case 0xA: // maximale Anzahl der Clients setzen
  561. if (!adminId)
  562. errorZuKlient("Du musst dich einloggen.");
  563. else
  564. {
  565. klient->sende("\1", 1);
  566. int maxC = 0;
  567. klient->getNachricht((char*)&maxC, 4);
  568. if (cs->zDB()->adminHatRecht(adminId, Admin_Recht::CSMCChange))
  569. {
  570. if (cs->setMaxKlients(maxC))
  571. klient->sende("\1", 1);
  572. else
  573. {
  574. Text* err = new Text();
  575. err->append(cs->getLetzterFehler());
  576. errorZuKlient(err->getText());
  577. err->release();
  578. }
  579. }
  580. else
  581. errorZuKlient("Du bist nicht berechtigt die maximale Anzahl der Clients zu verändern.");
  582. }
  583. break;
  584. case 0xC: // klient absturtz
  585. if (1)
  586. {
  587. klient->sende("\1", 1);
  588. int klientId = 0;
  589. klient->getNachricht((char*)&klientId, 4);
  590. if (klientId && cs->absturzKlient(klientId))
  591. klient->sende("\1", 1);
  592. else
  593. klient->sende("\0", 1);
  594. }
  595. break;
  596. default:
  597. errorZuKlient("Unbekannte Nachricht!");
  598. break;
  599. }
  600. if (br)
  601. break;
  602. cs->addEmpfangen(klient->getDownloadBytes(1));
  603. cs->addGesendet(klient->getUploadBytes(1));
  604. }
  605. }
  606. cs->addEmpfangen(klient->getDownloadBytes(1));
  607. cs->addGesendet(klient->getUploadBytes(1));
  608. delete this;
  609. }
  610. void CSAKlient::errorZuKlient(const char* nachricht) const // sendet eine Fehlernachricht zum Klient
  611. {
  612. klient->sende("\3", 1);
  613. char len = (char)textLength(nachricht);
  614. klient->sende(&len, 1);
  615. klient->sende(nachricht, len);
  616. }
  617. // Inhalt der CSKlient aus ChatServer.h
  618. // Konstruktor
  619. CSKlient::CSKlient(SKlient* klient, ChatServer* cs)
  620. : Thread()
  621. {
  622. this->klient = klient;
  623. unsigned char key[20] = { 78, 20, 190, 133, 10, 175, 51, 96, 62, 1, 180, 194, 126, 50, 211, 154, 105, 227, 22, 101 };
  624. klient->setSendeKey((char*)key, 20);
  625. klient->setEmpfangKey((char*)key, 20);
  626. klientNummer = 0;
  627. this->cs = cs;
  628. accountId = 0;
  629. empfangen = 1;
  630. }
  631. // Destruktor
  632. CSKlient::~CSKlient()
  633. {
  634. cs->addEmpfangen(klient->getDownloadBytes(1));
  635. cs->addGesendet(klient->getUploadBytes(1));
  636. klient->release();
  637. cs->release();
  638. }
  639. // nicht constant
  640. void CSKlient::lock()
  641. {
  642. ts.lock();
  643. }
  644. void CSKlient::unlock()
  645. {
  646. ts.unlock();
  647. }
  648. void CSKlient::absturz()
  649. {
  650. #ifdef WIN32
  651. if (GetCurrentThreadId() != GetThreadId(getThreadHandle()))
  652. ende();
  653. #else
  654. ende();
  655. #endif
  656. klient->trenne();
  657. if (empfangen)
  658. {
  659. cs->zDB()->unregisterKlient(klientNummer, cs->getId());
  660. MSGWeiterleitung* weiter = new MSGWeiterleitung(dynamic_cast<ChatServer*>(cs->getThis()));
  661. weiter->accountOffline(accountId);
  662. delete weiter;
  663. }
  664. }
  665. void CSKlient::thread()
  666. {
  667. int unbekannt = 0;
  668. while (1)
  669. {
  670. char c = 0;
  671. if (!klient->getNachrichtEncrypted(&c, 1))
  672. break;
  673. else
  674. {
  675. bool br = 0;
  676. switch (c)
  677. {
  678. case 1: // Klient identifikation
  679. klient->getNachrichtEncrypted((char*)&klientNummer, 4);
  680. if (!cs->zDB()->proveKlient(klientNummer, cs->getId()))
  681. {
  682. klientNummer = 0;
  683. errorZuKlient("Du bist nicht für diesen Server eingetragen");
  684. }
  685. if (klientNummer)
  686. {
  687. accountId = cs->zDB()->getKlientAccountId(klientNummer);
  688. if (!accountId)
  689. {
  690. errorZuKlient("Du bist nicht online");
  691. klientNummer = 0;
  692. }
  693. else
  694. {
  695. int status = cs->getKlientStatus(klientNummer, this);
  696. if (status == 2)
  697. {
  698. klientNummer = 0;
  699. accountId = 0;
  700. errorZuKlient("Diese Klient Nummer ist bereits verbunden");
  701. }
  702. else
  703. {
  704. Text* key = cs->zDB()->getKlientKey(klientNummer);
  705. if (!key)
  706. errorZuKlient("Es konnte kein Schlüssel ermittelt werden.");
  707. else
  708. {
  709. klient->sendeEncrypted("\1", 1);
  710. klient->setEmpfangKey(*key, key->getLength());
  711. klient->setSendeKey(*key, key->getLength());
  712. key->release();
  713. if (status == 1)
  714. {
  715. empfangen = 0;
  716. MSGWeiterleitung* weiter = new MSGWeiterleitung(dynamic_cast<ChatServer*>(cs->getThis()));
  717. weiter->accountOnline(accountId);
  718. delete weiter;
  719. br = 1;
  720. }
  721. }
  722. }
  723. }
  724. }
  725. break;
  726. case 2: // Main / Erhaltung Server message
  727. if (1)
  728. {
  729. char befehl = 0;
  730. klient->getNachrichtEncrypted(&befehl, 1);
  731. switch (befehl)
  732. {
  733. case 2: // klient absturtz
  734. if (1)
  735. {
  736. int klientId = 0;
  737. klient->getNachrichtEncrypted((char*)&klientId, 4);
  738. if (klientId && cs->absturzKlient(klientId))
  739. klient->sendeEncrypted("\1", 1);
  740. else
  741. klient->sendeEncrypted("\0", 1);
  742. }
  743. break;
  744. default:
  745. errorZuKlient("Befehl nicht bekannt!");
  746. break;
  747. }
  748. }
  749. break;
  750. case 3: // Verbindungsende
  751. if (1)
  752. {
  753. lock();
  754. klient->sendeEncrypted("\1", 1);
  755. unlock();
  756. br = 1;
  757. }
  758. break;
  759. case 4: // unregister Klient
  760. if (!klientNummer)
  761. {
  762. klient->sendeEncrypted("\0", 1);
  763. CSKlient* c = cs->zSendeKlient(accountId);
  764. if (c)
  765. c->errorZuKlient("Du bist nicht Identifiziert.");
  766. break;
  767. }
  768. cs->zDB()->unregisterKlient(klientNummer, cs->getId());
  769. klient->sendeEncrypted("\1", 1);
  770. break;
  771. case 5: // Server message
  772. if (1)
  773. {
  774. char byte = 0;
  775. char res = 1;
  776. klient->getNachrichtEncrypted(&byte, 1);
  777. switch (byte)
  778. {
  779. case 1: // kick Klient
  780. if (1)
  781. {
  782. klient->sendeEncrypted("\1", 1);
  783. int id = 0;
  784. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&id, 4));
  785. CSKlient* c = cs->zSendeKlient(id);
  786. if (c)
  787. {
  788. c->kick();
  789. cs->absturzKlient(c->getKlientNummer());
  790. }
  791. cs->removeAccount(id);
  792. }
  793. break;
  794. case 2: // Account kommt online
  795. if (1)
  796. {
  797. klient->sendeEncrypted("\1", 1);
  798. int accId = 0;
  799. int freundId = 0;
  800. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&accId, 4));
  801. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&freundId, 4));
  802. CSKlient* klient = cs->zSendeKlient(freundId);
  803. if (klient)
  804. res = (char)(res & (char)klient->freundOnline(accId));
  805. else
  806. res = 0;
  807. }
  808. break;
  809. case 3: // Account geht offline
  810. if (1)
  811. {
  812. klient->sendeEncrypted("\1", 1);
  813. int accId = 0;
  814. int freundId = 0;
  815. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&accId, 4));
  816. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&freundId, 4));
  817. CSKlient* klient = cs->zSendeKlient(freundId);
  818. if (klient)
  819. res = (char)(res & (char)klient->freundOffline(accId));
  820. else
  821. res = 0;
  822. }
  823. break;
  824. case 4: // Chat nachricht
  825. if (1)
  826. {
  827. klient->sendeEncrypted("\1", 1);
  828. int vonAcc = 0;
  829. int zuAcc = 0;
  830. unsigned char len = 0;
  831. char* nachricht = 0;
  832. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&vonAcc, 4));
  833. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&zuAcc, 4));
  834. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&len, 1));
  835. if (len)
  836. {
  837. nachricht = new char[len + 1];
  838. nachricht[(int)len] = 0;
  839. res = (char)(res & (char)klient->getNachrichtEncrypted(nachricht, len));
  840. CSKlient* klient = cs->zSendeKlient(zuAcc);
  841. if (klient)
  842. res = (char)(res & (char)klient->nachricht(vonAcc, nachricht));
  843. else
  844. res = 0;
  845. }
  846. delete[]nachricht;
  847. }
  848. break;
  849. case 5: // Gruppe einladung
  850. if (1)
  851. {
  852. klient->sendeEncrypted("\1", 1);
  853. int vonAcc = 0;
  854. int zuAcc = 0;
  855. int gruppeId = 0;
  856. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&zuAcc, 4));
  857. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&vonAcc, 4));
  858. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&gruppeId, 4));
  859. CSKlient* klient = cs->zSendeKlient(zuAcc);
  860. if (klient)
  861. res = (char)(res & (char)klient->gruppeEinladung(vonAcc, gruppeId));
  862. else
  863. res = 0;
  864. }
  865. break;
  866. case 6: // Account Status ändert sich
  867. if (1)
  868. {
  869. klient->sendeEncrypted("\1", 1);
  870. int accId = 0;
  871. int freundId = 0;
  872. unsigned char len = 0;
  873. char* status = 0;
  874. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&accId, 4));
  875. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&freundId, 4));
  876. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&len, 1));
  877. if (len)
  878. {
  879. status = new char[len + 1];
  880. status[(int)len] = 0;
  881. res = (char)(res & (char)klient->getNachrichtEncrypted(status, len));
  882. CSKlient* klient = cs->zSendeKlient(freundId);
  883. if (klient)
  884. res = (char)(res & (char)klient->accountStatusChange(accId, status));
  885. else
  886. res = 0;
  887. }
  888. delete[]status;
  889. }
  890. break;
  891. case 7: // Account Name ändert sich
  892. if (1)
  893. {
  894. klient->sendeEncrypted("\1", 1);
  895. int accId = 0;
  896. int freundId = 0;
  897. unsigned char len = 0;
  898. char* name = 0;
  899. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&accId, 4));
  900. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&freundId, 4));
  901. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&len, 1));
  902. if (len)
  903. {
  904. name = new char[len + 1];
  905. name[(int)len] = 0;
  906. res = (char)(res & (char)klient->getNachrichtEncrypted(name, len));
  907. CSKlient* klient = cs->zSendeKlient(freundId);
  908. if (klient)
  909. res = (char)(res & (char)klient->accountNameChange(accId, name));
  910. else
  911. res = 0;
  912. }
  913. delete[]name;
  914. }
  915. break;
  916. case 8: // Kein Freund mehr
  917. if (1)
  918. {
  919. klient->sendeEncrypted("\1", 1);
  920. int accId = 0;
  921. int freundId = 0;
  922. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&accId, 4));
  923. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&freundId, 4));
  924. CSKlient* klient = cs->zSendeKlient(freundId);
  925. if (klient)
  926. res = (char)(res & (char)klient->keinFreundMehr(accId));
  927. else
  928. res = 0;
  929. }
  930. break;
  931. case 9: // Freundesanfrage
  932. if (1)
  933. {
  934. klient->sendeEncrypted("\1", 1);
  935. int accId = 0;
  936. int freundId = 0;
  937. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&accId, 4));
  938. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&freundId, 4));
  939. CSKlient* klient = cs->zSendeKlient(freundId);
  940. if (klient)
  941. res = (char)(res & (char)klient->freundesAnfrage(accId));
  942. else
  943. res = 0;
  944. }
  945. break;
  946. case 0xA: // Neuer Freund
  947. if (1)
  948. {
  949. klient->sendeEncrypted("\1", 1);
  950. int accId = 0;
  951. int freundId = 0;
  952. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&accId, 4));
  953. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&freundId, 4));
  954. CSKlient* klient = cs->zSendeKlient(freundId);
  955. if (klient)
  956. res = (char)(res & (char)klient->neuerFreund(accountId));
  957. else
  958. res = 0;
  959. }
  960. break;
  961. case 0xB: // Einladung zum Chatroom
  962. if (1)
  963. {
  964. klient->sendeEncrypted("\1", 1);
  965. int vonAcc = 0;
  966. int zuAcc = 0;
  967. int chatroomId = 0;
  968. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&vonAcc, 4));
  969. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&zuAcc, 4));
  970. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&chatroomId, 4));
  971. CSKlient* klient = cs->zSendeKlient(zuAcc);
  972. if (klient)
  973. res = (char)(res & (char)klient->einladungZumChatroom(vonAcc, chatroomId));
  974. else
  975. res = 0;
  976. }
  977. break;
  978. case 0xC: // Spieler betritt Chatroom
  979. if (1)
  980. {
  981. klient->sendeEncrypted("\1", 1);
  982. int accId = 0;
  983. int zuAcc = 0;
  984. int chatroomId = 0;
  985. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&accId, 4));
  986. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&zuAcc, 4));
  987. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&chatroomId, 4));
  988. CSKlient* klient = cs->zSendeKlient(zuAcc);
  989. if (klient)
  990. res = (char)(res & (char)klient->spielerBetrittChatroom(chatroomId, accId));
  991. else
  992. res = 0;
  993. }
  994. break;
  995. case 0xD: // Chatroom nachricht
  996. if (1)
  997. {
  998. klient->sendeEncrypted("\1", 1);
  999. int vonAcc = 0;
  1000. int zuAcc = 0;
  1001. int chatroomId = 0;
  1002. unsigned char len = 0;
  1003. char* nachricht = 0;
  1004. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&vonAcc, 4));
  1005. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&zuAcc, 4));
  1006. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&chatroomId, 4));
  1007. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&len, 1));
  1008. if (len)
  1009. {
  1010. nachricht = new char[len + 1];
  1011. nachricht[(int)len] = 0;
  1012. res = (char)(res & (char)klient->getNachrichtEncrypted(nachricht, len));
  1013. CSKlient* klient = cs->zSendeKlient(zuAcc);
  1014. if (klient)
  1015. res = (char)(res & (char)klient->chatroomNachricht(chatroomId, vonAcc, nachricht));
  1016. else
  1017. res = 0;
  1018. }
  1019. delete[]nachricht;
  1020. }
  1021. break;
  1022. case 0xE: // Spieler verlässt Chatroom
  1023. if (1)
  1024. {
  1025. klient->sendeEncrypted("\1", 1);
  1026. int accId = 0;
  1027. int zuAcc = 0;
  1028. int chatroomId = 0;
  1029. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&accId, 4));
  1030. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&zuAcc, 4));
  1031. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&chatroomId, 4));
  1032. CSKlient* klient = cs->zSendeKlient(zuAcc);
  1033. if (klient)
  1034. res = (char)(res & (char)klient->spielerLeavesChatroom(chatroomId, accId));
  1035. else
  1036. res = 0;
  1037. }
  1038. break;
  1039. case 0xF: // Freund Einladung abgelehnt
  1040. if (1)
  1041. {
  1042. klient->sendeEncrypted("\1", 1);
  1043. int accId = 0;
  1044. int freundId = 0;
  1045. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&accId, 4));
  1046. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&freundId, 4));
  1047. CSKlient* klient = cs->zSendeKlient(freundId);
  1048. if (klient)
  1049. res = (char)(res & (char)klient->freundesAnfrageAbgelehnt(accId));
  1050. else
  1051. res = 0;
  1052. }
  1053. break;
  1054. case 0x10: // Chatroom Einladungabgelehnt
  1055. if (1)
  1056. {
  1057. klient->sendeEncrypted("\1", 1);
  1058. int accId = 0;
  1059. int zuAcc = 0;
  1060. int chatroomId = 0;
  1061. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&accId, 4));
  1062. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&zuAcc, 4));
  1063. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&chatroomId, 4));
  1064. CSKlient* klient = cs->zSendeKlient(zuAcc);
  1065. if (klient)
  1066. res = (char)(res & (char)klient->einladungZumChatroomAbgelehnt(accId, chatroomId));
  1067. else
  1068. res = 0;
  1069. }
  1070. break;
  1071. case 0x11: // Fehler
  1072. if (1)
  1073. {
  1074. klient->sendeEncrypted("\1", 1);
  1075. int zuAcc = 0;
  1076. unsigned char len = 0;
  1077. char* nachricht = 0;
  1078. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&zuAcc, 4));
  1079. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&len, 1));
  1080. if (len)
  1081. {
  1082. nachricht = new char[len + 1];
  1083. nachricht[(int)len] = 0;
  1084. res = (char)(res & (char)klient->getNachrichtEncrypted(nachricht, len));
  1085. CSKlient* klient = cs->zSendeKlient(zuAcc);
  1086. if (klient)
  1087. res = (char)(res & (char)klient->errorZuKlient(nachricht));
  1088. else
  1089. res = 0;
  1090. }
  1091. delete[]nachricht;
  1092. }
  1093. break;
  1094. case 0x12: // Chatroom Admin
  1095. if (1)
  1096. {
  1097. klient->sendeEncrypted("\1", 1);
  1098. int zuAcc = 0;
  1099. int chatroomId = 0;
  1100. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&zuAcc, 4));
  1101. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&chatroomId, 4));
  1102. CSKlient* klient = cs->zSendeKlient(zuAcc);
  1103. if (klient)
  1104. res = (char)(res & (char)klient->chatroomAdmin(chatroomId));
  1105. else
  1106. res = 0;
  1107. }
  1108. break;
  1109. case 0x13: // Chatroom Kick
  1110. if (1)
  1111. {
  1112. klient->sendeEncrypted("\1", 1);
  1113. int zuAcc = 0;
  1114. int chatroomId = 0;
  1115. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&zuAcc, 4));
  1116. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&chatroomId, 4));
  1117. CSKlient* klient = cs->zSendeKlient(zuAcc);
  1118. if (klient)
  1119. res = (char)(res & (char)klient->chatroomKick(chatroomId));
  1120. else
  1121. res = 0;
  1122. }
  1123. break;
  1124. case 0x14: // spieler betritt gruppe
  1125. if (1)
  1126. {
  1127. klient->sendeEncrypted("\1", 1);
  1128. int zuAcc = 0;
  1129. int accountId = 0;
  1130. int gruppeId = 0;
  1131. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&zuAcc, 4));
  1132. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&accountId, 4));
  1133. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&gruppeId, 4));
  1134. CSKlient* klient = cs->zSendeKlient(zuAcc);
  1135. if (klient)
  1136. res = (char)(res & (char)klient->spielerBertittGruppe(accountId, gruppeId));
  1137. else
  1138. res = 0;
  1139. }
  1140. break;
  1141. case 0x15: // spieler verlässt gruppe
  1142. if (1)
  1143. {
  1144. klient->sendeEncrypted("\1", 1);
  1145. int zuAcc = 0;
  1146. int accountId = 0;
  1147. int gruppeId = 0;
  1148. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&zuAcc, 4));
  1149. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&accountId, 4));
  1150. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&gruppeId, 4));
  1151. CSKlient* klient = cs->zSendeKlient(zuAcc);
  1152. if (klient)
  1153. res = (char)(res & (char)klient->spielerLeavesGruppe(accountId, gruppeId));
  1154. else
  1155. res = 0;
  1156. }
  1157. break;
  1158. case 0x16: // kick spieler aus gruppe
  1159. if (1)
  1160. {
  1161. klient->sendeEncrypted("\1", 1);
  1162. int zuAcc = 0;
  1163. int gruppeId = 0;
  1164. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&zuAcc, 4));
  1165. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&gruppeId, 4));
  1166. CSKlient* klient = cs->zSendeKlient(zuAcc);
  1167. if (klient)
  1168. res = (char)(res & (char)klient->kickAusGruppe(gruppeId));
  1169. else
  1170. res = 0;
  1171. }
  1172. break;
  1173. case 0x17: // gruppe angemeldet
  1174. if (1)
  1175. {
  1176. klient->sendeEncrypted("\1", 1);
  1177. int zuAcc = 0;
  1178. int gruppeId = 0;
  1179. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&zuAcc, 4));
  1180. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&gruppeId, 4));
  1181. CSKlient* klient = cs->zSendeKlient(zuAcc);
  1182. if (klient)
  1183. res = (char)(res & (char)klient->gruppeAnmelden(gruppeId));
  1184. else
  1185. res = 0;
  1186. }
  1187. break;
  1188. case 0x18: // gruppe abgemeldet
  1189. if (1)
  1190. {
  1191. klient->sendeEncrypted("\1", 1);
  1192. int zuAcc = 0;
  1193. int gruppeId = 0;
  1194. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&zuAcc, 4));
  1195. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&gruppeId, 4));
  1196. CSKlient* klient = cs->zSendeKlient(zuAcc);
  1197. if (klient)
  1198. res = (char)(res & (char)klient->gruppeAbmelden(gruppeId));
  1199. else
  1200. res = 0;
  1201. }
  1202. break;
  1203. case 0x19: // gruppe nachricht
  1204. if (1)
  1205. {
  1206. klient->sendeEncrypted("\1", 1);
  1207. int zuAcc = 0;
  1208. int gruppeId = 0;
  1209. unsigned char len;
  1210. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&zuAcc, 4));
  1211. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&gruppeId, 4));
  1212. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&len, 1));
  1213. char* nachricht = new char[len + 1];
  1214. nachricht[(int)len] = 0;
  1215. if (len)
  1216. res = (char)(res & (char)klient->getNachrichtEncrypted(nachricht, len));
  1217. CSKlient* klient = cs->zSendeKlient(zuAcc);
  1218. if (klient)
  1219. res = (char)(res & (char)klient->gruppeNachricht(gruppeId, nachricht));
  1220. else
  1221. res = 0;
  1222. delete[]nachricht;
  1223. }
  1224. break;
  1225. case 0x1A: // gruppe spiel starten
  1226. if (1)
  1227. {
  1228. klient->sendeEncrypted("\1", 1);
  1229. int zuAcc = 0;
  1230. int gruppeId = 0;
  1231. char starten;
  1232. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&zuAcc, 4));
  1233. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&gruppeId, 4));
  1234. res = (char)(res & (char)klient->getNachrichtEncrypted(&starten, 1));
  1235. CSKlient* klient = cs->zSendeKlient(zuAcc);
  1236. if (klient)
  1237. res = (char)(res & (char)klient->gruppeSpielStarten(gruppeId, starten == 1));
  1238. else
  1239. res = 0;
  1240. }
  1241. break;
  1242. case 0x1B: // gruppe admin
  1243. if (1)
  1244. {
  1245. klient->sendeEncrypted("\1", 1);
  1246. int zuAcc = 0;
  1247. int adminId = 0;
  1248. int gruppeId = 0;
  1249. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&zuAcc, 4));
  1250. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&adminId, 4));
  1251. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&gruppeId, 4));
  1252. CSKlient* klient = cs->zSendeKlient(zuAcc);
  1253. if (klient)
  1254. res = (char)(res & (char)klient->setGruppeAdmin(gruppeId, adminId));
  1255. else
  1256. res = 0;
  1257. }
  1258. break;
  1259. case 0x1C: // gruppe Einladung abgelehnt
  1260. if (1)
  1261. {
  1262. klient->sendeEncrypted("\1", 1);
  1263. int zuAcc = 0;
  1264. int accountId = 0;
  1265. int gruppeId = 0;
  1266. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&zuAcc, 4));
  1267. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&accountId, 4));
  1268. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&gruppeId, 4));
  1269. CSKlient* klient = cs->zSendeKlient(zuAcc);
  1270. if (klient)
  1271. res = (char)(res & (char)klient->gruppeEinladungAbgelehnt(gruppeId, accountId));
  1272. else
  1273. res = 0;
  1274. }
  1275. break;
  1276. case 0x1D: // Spiel Server verbindungs aufforderung
  1277. if (1)
  1278. {
  1279. klient->sendeEncrypted("\1", 1);
  1280. int zuAcc = 0;
  1281. unsigned short port;
  1282. unsigned char* ip = new unsigned char[4];
  1283. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&zuAcc, 4));
  1284. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&port, 2));
  1285. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)ip, 4));
  1286. CSKlient* klient = cs->zSendeKlient(zuAcc);
  1287. if (klient)
  1288. res = (char)(res & (char)klient->spielServerVerbindungsAnfrage(port, ip));
  1289. else
  1290. res = 0;
  1291. delete[] ip;
  1292. }
  1293. break;
  1294. case 0x1E: // gruppe einladung Abbrechen
  1295. if (1)
  1296. {
  1297. klient->sendeEncrypted("\1", 1);
  1298. int zuAcc = 0;
  1299. int gruppeId = 0;
  1300. int accountId = 0;
  1301. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&zuAcc, 4));
  1302. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&gruppeId, 4));
  1303. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&accountId, 4));
  1304. CSKlient* klient = cs->zSendeKlient(zuAcc);
  1305. if (klient)
  1306. res = (char)(res & (char)klient->gruppeEinladungAbgebrochen(gruppeId, accountId));
  1307. else
  1308. res = 0;
  1309. }
  1310. break;
  1311. case 0x1F: // gruppe einladung Neu
  1312. if (1)
  1313. {
  1314. klient->sendeEncrypted("\1", 1);
  1315. int zuAcc = 0;
  1316. int gruppeId = 0;
  1317. int accountId = 0;
  1318. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&zuAcc, 4));
  1319. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&gruppeId, 4));
  1320. res = (char)(res & (char)klient->getNachrichtEncrypted((char*)&accountId, 4));
  1321. CSKlient* klient = cs->zSendeKlient(zuAcc);
  1322. if (klient)
  1323. res = (char)(res & (char)klient->gruppeEinladungNeu(gruppeId, accountId));
  1324. else
  1325. res = 0;
  1326. }
  1327. break;
  1328. default:
  1329. res = 0;
  1330. break;
  1331. }
  1332. klient->sendeEncrypted(&res, 1);
  1333. }
  1334. break;
  1335. case 6: // Chat Nachricht
  1336. if (1)
  1337. {
  1338. if (!accountId || !klientNummer)
  1339. {
  1340. klient->sendeEncrypted("\0", 1);
  1341. CSKlient* c = cs->zSendeKlient(accountId);
  1342. if (c)
  1343. c->errorZuKlient("Du bist nicht identifiziert.");
  1344. break;
  1345. }
  1346. klient->sendeEncrypted("\1", 1);
  1347. int zuAccount = 0;
  1348. unsigned char len = 0;
  1349. char* nachricht = 0;
  1350. klient->getNachrichtEncrypted((char*)&zuAccount, 4);
  1351. klient->getNachrichtEncrypted((char*)&len, 1);
  1352. if (len)
  1353. {
  1354. nachricht = new char[len + 1];
  1355. nachricht[(int)len] = 0;
  1356. klient->getNachrichtEncrypted(nachricht, len);
  1357. MSGWeiterleitung* weiter = new MSGWeiterleitung(dynamic_cast<ChatServer*>(cs->getThis()));
  1358. if (!weiter->chatNachricht(accountId, zuAccount, nachricht))
  1359. {
  1360. cs->zDB()->speicherChatNachricht(accountId, zuAccount, nachricht);
  1361. CSKlient* c = cs->zSendeKlient(accountId);
  1362. if (c)
  1363. c->errorZuKlient("Der Account ist momentan nicht erreichbar.");
  1364. }
  1365. delete weiter;
  1366. delete[]nachricht;
  1367. }
  1368. }
  1369. break;
  1370. case 8: // Account Name ändern
  1371. if (1)
  1372. {
  1373. if (!accountId || !klientNummer)
  1374. {
  1375. klient->sendeEncrypted("\0", 1);
  1376. CSKlient* c = cs->zSendeKlient(accountId);
  1377. if (c)
  1378. c->errorZuKlient("Du bist nicht identifiziert.");
  1379. break;
  1380. }
  1381. klient->sendeEncrypted("\1", 1);
  1382. unsigned char len;
  1383. char* name;
  1384. klient->getNachrichtEncrypted((char*)&len, 1);
  1385. if (len)
  1386. {
  1387. name = new char[len + 1];
  1388. name[(int)len] = 0;
  1389. klient->getNachrichtEncrypted(name, len);
  1390. if (cs->zDB()->accountNameChange(accountId, name))
  1391. {
  1392. klient->sendeEncrypted("\1", 1);
  1393. MSGWeiterleitung* weiter = new MSGWeiterleitung(dynamic_cast<ChatServer*>(cs->getThis()));
  1394. weiter->accountNameChange(accountId, name);
  1395. delete weiter;
  1396. }
  1397. else
  1398. {
  1399. klient->sendeEncrypted("\0", 1);
  1400. CSKlient* c = cs->zSendeKlient(accountId);
  1401. if (c)
  1402. c->errorZuKlient("Beim ändern des Namens ist ein Fehler aufgetreten.");
  1403. }
  1404. delete[]name;
  1405. }
  1406. }
  1407. break;
  1408. case 9: // Freundschaft beenden
  1409. if (1)
  1410. {
  1411. if (!accountId || !klientNummer)
  1412. {
  1413. klient->sendeEncrypted("\0", 1);
  1414. CSKlient* c = cs->zSendeKlient(accountId);
  1415. if (c)
  1416. c->errorZuKlient("Du bist nicht identifiziert.");
  1417. break;
  1418. }
  1419. klient->sendeEncrypted("\1", 1);
  1420. int freundId = 0;
  1421. klient->getNachrichtEncrypted((char*)&freundId, 4);
  1422. if (cs->zDB()->beendeFreundschaft(accountId, freundId))
  1423. {
  1424. klient->sendeEncrypted("\1", 1);
  1425. MSGWeiterleitung* weiter = new MSGWeiterleitung(dynamic_cast<ChatServer*>(cs->getThis()));
  1426. weiter->accountKeinFreundMehr(accountId, freundId);
  1427. weiter->accountKeinFreundMehr(freundId, accountId);
  1428. delete weiter;
  1429. }
  1430. else
  1431. {
  1432. klient->sendeEncrypted("\0", 1);
  1433. CSKlient* c = cs->zSendeKlient(accountId);
  1434. if (c)
  1435. c->errorZuKlient("Die Freundschaft konnte nicht beendet werden.");
  1436. }
  1437. }
  1438. break;
  1439. case 0xA: // Freundschaftsanfrage senden
  1440. if (1)
  1441. {
  1442. if (!accountId || !klientNummer)
  1443. {
  1444. klient->sendeEncrypted("\0", 1);
  1445. CSKlient* c = cs->zSendeKlient(accountId);
  1446. if (c)
  1447. c->errorZuKlient("Du bist nicht identifiziert.");
  1448. break;
  1449. }
  1450. klient->sendeEncrypted("\1", 1);
  1451. int freundId = 0;
  1452. klient->getNachrichtEncrypted((char*)&freundId, 4);
  1453. if (cs->zDB()->proveFreundschaftsAnfrage(accountId, freundId))
  1454. {
  1455. MSGWeiterleitung* weiter = new MSGWeiterleitung(dynamic_cast<ChatServer*>(cs->getThis()));
  1456. if (!weiter->freundesAnfrage(accountId, freundId))
  1457. cs->zDB()->saveFreundschaftsAnfrage(accountId, freundId);
  1458. klient->sendeEncrypted("\1", 1);
  1459. delete weiter;
  1460. }
  1461. else
  1462. {
  1463. klient->sendeEncrypted("\0", 1);
  1464. CSKlient* c = cs->zSendeKlient(accountId);
  1465. if (c)
  1466. c->errorZuKlient("Diesem Account konnte keine Freundschaftsanfrage gesendet werden.");
  1467. }
  1468. }
  1469. break;
  1470. case 0xB: // Freundschaftsanfrage beantworten
  1471. if (1)
  1472. {
  1473. if (!accountId || !klientNummer)
  1474. {
  1475. klient->sendeEncrypted("\0", 1);
  1476. CSKlient* c = cs->zSendeKlient(accountId);
  1477. if (c)
  1478. c->errorZuKlient("Du bist nicht identifiziert.");
  1479. break;
  1480. }
  1481. klient->sendeEncrypted("\1", 1);
  1482. int zuAccount = 0;
  1483. char ok = 0;
  1484. klient->getNachrichtEncrypted((char*)&zuAccount, 4);
  1485. klient->getNachrichtEncrypted(&ok, 1);
  1486. MSGWeiterleitung* weiter = new MSGWeiterleitung(dynamic_cast<ChatServer*>(cs->getThis()));
  1487. if (!ok)
  1488. {
  1489. weiter->freundEinladungAbgelehnt(accountId, zuAccount);
  1490. klient->sendeEncrypted("\1", 1);
  1491. }
  1492. else
  1493. {
  1494. if (cs->zDB()->neueFreundschaft(accountId, zuAccount))
  1495. {
  1496. weiter->neuerFreund(accountId, zuAccount);
  1497. weiter->neuerFreund(zuAccount, accountId);
  1498. if (cs->zDB()->accountIstOnline(zuAccount))
  1499. {
  1500. weiter->accountOnline(zuAccount);
  1501. weiter->accountOnline(accountId);
  1502. }
  1503. klient->sendeEncrypted("\1", 1);
  1504. }
  1505. else
  1506. {
  1507. klient->sendeEncrypted("\0", 1);
  1508. CSKlient* c = cs->zSendeKlient(accountId);
  1509. if (c)
  1510. c->errorZuKlient("Fehler beim erstellen der neuen Freundschaft.");
  1511. weiter->fehler(zuAccount, "Fehler beim erstellen der neuen Freundschaft.");
  1512. }
  1513. }
  1514. delete weiter;
  1515. }
  1516. break;
  1517. case 0xC: // Chatroom erstellen
  1518. if (1)
  1519. {
  1520. if (!accountId || !klientNummer)
  1521. {
  1522. klient->sendeEncrypted("\0", 1);
  1523. CSKlient* c = cs->zSendeKlient(accountId);
  1524. if (c)
  1525. c->errorZuKlient("Du bist nicht identifiziert.");
  1526. break;
  1527. }
  1528. klient->sendeEncrypted("\1", 1);
  1529. unsigned char nLen = 0;
  1530. char* name = 0;
  1531. klient->getNachrichtEncrypted((char*)&nLen, 1);
  1532. if (nLen)
  1533. {
  1534. name = new char[nLen + 1];
  1535. name[(int)nLen] = 0;
  1536. klient->getNachrichtEncrypted(name, nLen);
  1537. }
  1538. if (!name)
  1539. {
  1540. klient->sendeEncrypted("\0", 1);
  1541. CSKlient* c = cs->zSendeKlient(accountId);
  1542. if (c)
  1543. c->errorZuKlient("Du musst einen Namen eingeben.");
  1544. }
  1545. else
  1546. {
  1547. klient->sendeEncrypted("\1", 1);
  1548. int id = cs->zDB()->chatroomErstellen(accountId, name);
  1549. klient->sendeEncrypted((char*)&id, 4);
  1550. if (!id)
  1551. {
  1552. CSKlient* c = cs->zSendeKlient(accountId);
  1553. if (c)
  1554. c->errorZuKlient("Das Chatroom konnte nicht erstellt werden.");
  1555. }
  1556. else
  1557. {
  1558. CSKlient* c = cs->zSendeKlient(accountId);
  1559. if (c)
  1560. {
  1561. c->spielerBetrittChatroom(id, accountId);
  1562. c->chatroomAdmin(id);
  1563. }
  1564. }
  1565. }
  1566. delete[]name;
  1567. }
  1568. break;
  1569. case 0xD: // Zum Chatroom einladen
  1570. if (1)
  1571. {
  1572. if (!accountId || !klientNummer)
  1573. {
  1574. klient->sendeEncrypted("\0", 1);
  1575. CSKlient* c = cs->zSendeKlient(accountId);
  1576. if (c)
  1577. c->errorZuKlient("Du bist nicht identifiziert.");
  1578. break;
  1579. }
  1580. klient->sendeEncrypted("\1", 1);
  1581. int zuAccountId = 0;
  1582. int chatroomId = 0;
  1583. klient->getNachrichtEncrypted((char*)&zuAccountId, 4);
  1584. klient->getNachrichtEncrypted((char*)&chatroomId, 4);
  1585. if (cs->zDB()->proveChatroomEinladung(accountId, zuAccountId, chatroomId))
  1586. {
  1587. MSGWeiterleitung* weiter = new MSGWeiterleitung(dynamic_cast<ChatServer*>(cs->getThis()));
  1588. if (weiter->einladungZumChatroom(accountId, zuAccountId, chatroomId))
  1589. klient->sendeEncrypted("\1", 1);
  1590. else
  1591. {
  1592. klient->sendeEncrypted("\0", 1);
  1593. if (weiter->getLetzterFehler())
  1594. {
  1595. CSKlient* c = cs->zSendeKlient(accountId);
  1596. if (c)
  1597. c->errorZuKlient(weiter->getLetzterFehler());
  1598. }
  1599. }
  1600. delete weiter;
  1601. }
  1602. else
  1603. {
  1604. klient->sendeEncrypted("\0", 1);
  1605. CSKlient* c = cs->zSendeKlient(accountId);
  1606. if (c)
  1607. c->errorZuKlient("Der Account konnte nicht eingeladen werden.");
  1608. }
  1609. }
  1610. break;
  1611. case 0xE: // Chatroom einladung ablehnen
  1612. if (1)
  1613. {
  1614. if (!accountId || !klientNummer)
  1615. {
  1616. klient->sendeEncrypted("\0", 1);
  1617. CSKlient* c = cs->zSendeKlient(accountId);
  1618. if (c)
  1619. c->errorZuKlient("Du bist nicht identifiziert.");
  1620. break;
  1621. }
  1622. klient->sendeEncrypted("\1", 1);
  1623. int zuAccountId = 0;
  1624. int chatroomId = 0;
  1625. klient->getNachrichtEncrypted((char*)&zuAccountId, 4);
  1626. klient->getNachrichtEncrypted((char*)&chatroomId, 4);
  1627. MSGWeiterleitung* weiter = new MSGWeiterleitung(dynamic_cast<ChatServer*>(cs->getThis()));
  1628. weiter->chatroomEinladungAbgelehnt(accountId, chatroomId, zuAccountId);
  1629. delete weiter;
  1630. klient->sendeEncrypted("\1", 1);
  1631. }
  1632. break;
  1633. case 0xF: // Chatroom betreten
  1634. if (1)
  1635. {
  1636. if (!accountId || !klientNummer)
  1637. {
  1638. klient->sendeEncrypted("\0", 1);
  1639. CSKlient* c = cs->zSendeKlient(accountId);
  1640. if (c)
  1641. c->errorZuKlient("Du bist nicht identifiziert.");
  1642. break;
  1643. }
  1644. klient->sendeEncrypted("\1", 1);
  1645. int chatroomId = 0;
  1646. klient->getNachrichtEncrypted((char*)&chatroomId, 4);
  1647. if (cs->zDB()->chatroomBeitreten(accountId, chatroomId))
  1648. {
  1649. MSGWeiterleitung* weiter = new MSGWeiterleitung(dynamic_cast<ChatServer*>(cs->getThis()));
  1650. weiter->spielerBetrittChatroom(accountId, chatroomId);
  1651. delete weiter;
  1652. klient->sendeEncrypted("\1", 1);
  1653. Array< int >* accounts = new Array< int >();
  1654. int anzahl = cs->zDB()->getChatroomAccount(chatroomId, accounts);
  1655. CSKlient* c = cs->zSendeKlient(accountId);
  1656. if (c)
  1657. {
  1658. if (!c->spielerImChatroom(chatroomId, (char)anzahl, accounts))
  1659. c->errorZuKlient("Fehler beim senden der momentanen Spieler im Chatroom.");
  1660. }
  1661. accounts->release();
  1662. }
  1663. else
  1664. klient->sendeEncrypted("\0", 1);
  1665. }
  1666. break;
  1667. case 0x10: // Chatroom Nachricht
  1668. if (1)
  1669. {
  1670. if (!accountId || !klientNummer)
  1671. {
  1672. klient->sendeEncrypted("\0", 1);
  1673. CSKlient* c = cs->zSendeKlient(accountId);
  1674. if (c)
  1675. c->errorZuKlient("Du bist nicht identifiziert.");
  1676. break;
  1677. }
  1678. klient->sendeEncrypted("\1", 1);
  1679. int chatroomId = 0;
  1680. unsigned char len = 0;
  1681. char* nachricht = 0;
  1682. klient->getNachrichtEncrypted((char*)&chatroomId, 4);
  1683. klient->getNachrichtEncrypted((char*)&len, 1);
  1684. if (len)
  1685. {
  1686. nachricht = new char[len + 1];
  1687. nachricht[(int)len] = 0;
  1688. klient->getNachrichtEncrypted(nachricht, len);
  1689. Text* message = cs->zDB()->getAccountRufName(accountId);
  1690. message->append(": ");
  1691. message->append(nachricht);
  1692. MSGWeiterleitung* weiter = new MSGWeiterleitung(dynamic_cast<ChatServer*>(cs->getThis()));
  1693. if (weiter->chatroomNachricht(accountId, message->getText(), chatroomId))
  1694. klient->sendeEncrypted("\1", 1);
  1695. else
  1696. {
  1697. klient->sendeEncrypted("\0", 1);
  1698. if (weiter->getLetzterFehler())
  1699. {
  1700. CSKlient* c = cs->zSendeKlient(accountId);
  1701. if (c)
  1702. c->errorZuKlient(weiter->getLetzterFehler());
  1703. }
  1704. }
  1705. message->release();
  1706. delete weiter;
  1707. delete[]nachricht;
  1708. }
  1709. else
  1710. klient->sendeEncrypted("\0", 1);
  1711. }
  1712. break;
  1713. case 0x11: // Chatroom verlassen
  1714. if (1)
  1715. {
  1716. if (!accountId || !klientNummer)
  1717. {
  1718. klient->sendeEncrypted("\0", 1);
  1719. CSKlient* c = cs->zSendeKlient(accountId);
  1720. if (c)
  1721. c->errorZuKlient("Du bist nicht identifiziert.");
  1722. break;
  1723. }
  1724. klient->sendeEncrypted("\1", 1);
  1725. int chatroomId = 0;
  1726. klient->getNachrichtEncrypted((char*)&chatroomId, 4);
  1727. int aktion = cs->zDB()->chatroomVerlassen(accountId, chatroomId);
  1728. if (!aktion)
  1729. klient->sendeEncrypted("\0", 1);
  1730. else
  1731. {
  1732. if (aktion == 3)
  1733. {
  1734. MSGWeiterleitung* weiter = new MSGWeiterleitung(dynamic_cast<ChatServer*>(cs->getThis()));
  1735. weiter->chatroomAdmin(chatroomId, cs->zDB()->getChatroomAdmin(chatroomId));
  1736. delete weiter;
  1737. }
  1738. if (aktion != 2)
  1739. {
  1740. MSGWeiterleitung* weiter = new MSGWeiterleitung(dynamic_cast<ChatServer*>(cs->getThis()));
  1741. weiter->spielerLeavestChatroom(accountId, chatroomId);
  1742. delete weiter;
  1743. }
  1744. klient->sendeEncrypted("\1", 1);
  1745. }
  1746. }
  1747. break;
  1748. case 0x12: // Chatroom Kick
  1749. if (1)
  1750. {
  1751. if (!accountId || !klientNummer)
  1752. {
  1753. klient->sendeEncrypted("\0", 1);
  1754. CSKlient* c = cs->zSendeKlient(accountId);
  1755. if (c)
  1756. c->errorZuKlient("Du bist nicht identifiziert.");
  1757. break;
  1758. }
  1759. klient->sendeEncrypted("\1", 1);
  1760. int chatroomId = 0;
  1761. int accountId = 0;
  1762. klient->getNachrichtEncrypted((char*)&chatroomId, 4);
  1763. klient->getNachrichtEncrypted((char*)&accountId, 4);
  1764. if (accountId == (int)this->accountId)
  1765. {
  1766. klient->sendeEncrypted("\0", 1);
  1767. CSKlient* c = cs->zSendeKlient(accountId);
  1768. if (c)
  1769. c->errorZuKlient("Du kannst dich selbst nicht kicken.");
  1770. break;
  1771. }
  1772. if (cs->zDB()->getChatroomAdmin(chatroomId) == (int)this->accountId)
  1773. {
  1774. if (cs->zDB()->chatroomVerlassen(accountId, chatroomId))
  1775. {
  1776. MSGWeiterleitung* weiter = new MSGWeiterleitung(dynamic_cast<ChatServer*>(cs->getThis()));
  1777. weiter->chatroomKick(chatroomId, accountId);
  1778. weiter->spielerLeavestChatroom(accountId, chatroomId);
  1779. delete weiter;
  1780. klient->sendeEncrypted("\1", 1);
  1781. }
  1782. else
  1783. {
  1784. klient->sendeEncrypted("\0", 1);
  1785. CSKlient* c = cs->zSendeKlient(accountId);
  1786. if (c)
  1787. c->errorZuKlient("Der Spieler konnte nicht entfernt werden.");
  1788. }
  1789. }
  1790. else
  1791. {
  1792. klient->sendeEncrypted("\0", 1);
  1793. CSKlient* c = cs->zSendeKlient(accountId);
  1794. if (c)
  1795. c->errorZuKlient("Du bist nicht der Administrator dieses Chatrooms.");
  1796. }
  1797. }
  1798. break;
  1799. case 0x13: // Anfrage nach Freundes Liste
  1800. if (1)
  1801. {
  1802. klient->sendeEncrypted("\1", 1);
  1803. Array< int >* freundId = new Array< int >();
  1804. int anz = cs->zDB()->getAccountFreunde(accountId, freundId);
  1805. CSKlient* c = cs->zSendeKlient(accountId);
  1806. if (c)
  1807. c->freunde((char)anz, freundId);
  1808. freundId->release();
  1809. freundId = new Array< int >();
  1810. anz = cs->zDB()->getAccountOnlineFreunde(accountId, freundId);
  1811. for (int i = 0; i < anz; i++)
  1812. {
  1813. if (c)
  1814. c->freundOnline(freundId->get(i));
  1815. }
  1816. freundId->release();
  1817. }
  1818. break;
  1819. case 0x14: // Anfrage nach chat nachrichten in abwesenheit
  1820. if (1)
  1821. {
  1822. klient->sendeEncrypted("\1", 1);
  1823. Array< int >* vonAccount = new Array< int >();
  1824. RCArray< Text >* nachricht = new RCArray< Text >();
  1825. int anzahl = cs->zDB()->getChatNachrichten(accountId, vonAccount, nachricht);
  1826. CSKlient* c = cs->zSendeKlient(accountId);
  1827. if (c)
  1828. {
  1829. for (int i = 0; i < anzahl; i++)
  1830. c->nachricht(vonAccount->get(i), nachricht->z(i)->getText());
  1831. }
  1832. vonAccount->leeren();
  1833. nachricht->release();
  1834. anzahl = cs->zDB()->getFreundschaftsAnfragen(accountId, vonAccount);
  1835. if (c)
  1836. {
  1837. for (int i = 0; i < anzahl; i++)
  1838. c->freundesAnfrage(vonAccount->get(i));
  1839. }
  1840. vonAccount->release();
  1841. }
  1842. break;
  1843. case 0x15: // ping
  1844. if (1)
  1845. {
  1846. if (!klientNummer)
  1847. {
  1848. errorZuKlient("Du bist nicht Identifiziert.");
  1849. break;
  1850. }
  1851. klient->sendeEncrypted("\1", 1);
  1852. CSKlient* c = cs->zSendeKlient(accountId);
  1853. if (c)
  1854. c->keepAlive();
  1855. }
  1856. break;
  1857. default:
  1858. unbekannt++;
  1859. errorZuKlient("Unbekannte Nachricht!");
  1860. break;
  1861. }
  1862. if (br || unbekannt >= 10)
  1863. break;
  1864. cs->addEmpfangen(klient->getDownloadBytes(1));
  1865. cs->addGesendet(klient->getUploadBytes(1));
  1866. }
  1867. }
  1868. cs->addEmpfangen(klient->getDownloadBytes(1));
  1869. cs->addGesendet(klient->getUploadBytes(1));
  1870. if (empfangen)
  1871. {
  1872. trenne();
  1873. if (klientNummer)
  1874. {
  1875. if (accountId)
  1876. {
  1877. MSGWeiterleitung* weiter = new MSGWeiterleitung(dynamic_cast<ChatServer*>(cs->getThis()));
  1878. weiter->accountOffline(accountId);
  1879. delete weiter;
  1880. }
  1881. cs->removeKlient(klientNummer);
  1882. }
  1883. else
  1884. cs->removeKlient(this);
  1885. }
  1886. }
  1887. bool CSKlient::kick()
  1888. {
  1889. lock();
  1890. if (empfangen)
  1891. {
  1892. klient->trenne();
  1893. warteAufThread(100);
  1894. ende();
  1895. MSGWeiterleitung* weiter = new MSGWeiterleitung(dynamic_cast<ChatServer*>(cs->getThis()));
  1896. weiter->accountOffline(accountId);
  1897. delete weiter;
  1898. }
  1899. else
  1900. {
  1901. klient->sendeEncrypted("\1", 1);
  1902. Sleep(100);
  1903. klient->trenne();
  1904. }
  1905. unlock();
  1906. return 1;
  1907. }
  1908. bool CSKlient::nachricht(int vonAccount, const char* txt)
  1909. {
  1910. if (empfangen)
  1911. return 0;
  1912. char len = (char)textLength(txt);
  1913. if (len)
  1914. {
  1915. lock();
  1916. klient->sendeEncrypted("\4", 1);
  1917. klient->sendeEncrypted((char*)&vonAccount, 4);
  1918. klient->sendeEncrypted(&len, 1);
  1919. klient->sendeEncrypted(txt, len);
  1920. unlock();
  1921. }
  1922. cs->addEmpfangen(klient->getDownloadBytes(1));
  1923. cs->addGesendet(klient->getUploadBytes(1));
  1924. return 1;
  1925. }
  1926. bool CSKlient::gruppeEinladung(int vonAccount, int gruppeId)
  1927. {
  1928. if (empfangen)
  1929. return 0;
  1930. lock();
  1931. klient->sendeEncrypted("\5", 1);
  1932. klient->sendeEncrypted((char*)&vonAccount, 4);
  1933. klient->sendeEncrypted((char*)&gruppeId, 4);
  1934. unlock();
  1935. cs->addEmpfangen(klient->getDownloadBytes(1));
  1936. cs->addGesendet(klient->getUploadBytes(1));
  1937. return 1;
  1938. }
  1939. bool CSKlient::accountStatusChange(int account, const char* status)
  1940. {
  1941. if (empfangen)
  1942. return 0;
  1943. char len = (char)(status ? textLength(status) : 0);
  1944. if (len)
  1945. {
  1946. lock();
  1947. klient->sendeEncrypted("\6", 1);
  1948. klient->sendeEncrypted((char*)&account, 4);
  1949. klient->sendeEncrypted(&len, 1);
  1950. klient->sendeEncrypted(status, len);
  1951. unlock();
  1952. }
  1953. cs->addEmpfangen(klient->getDownloadBytes(1));
  1954. cs->addGesendet(klient->getUploadBytes(1));
  1955. return 1;
  1956. }
  1957. bool CSKlient::accountNameChange(int account, const char* name)
  1958. {
  1959. if (empfangen)
  1960. return 0;
  1961. char len = (char)(name ? textLength(name) : 0);
  1962. if (len)
  1963. {
  1964. lock();
  1965. klient->sendeEncrypted("\7", 1);
  1966. klient->sendeEncrypted((char*)&account, 4);
  1967. klient->sendeEncrypted(&len, 1);
  1968. klient->sendeEncrypted(name, len);
  1969. unlock();
  1970. }
  1971. cs->addEmpfangen(klient->getDownloadBytes(1));
  1972. cs->addGesendet(klient->getUploadBytes(1));
  1973. return 1;
  1974. }
  1975. bool CSKlient::keinFreundMehr(int account)
  1976. {
  1977. if (empfangen)
  1978. return 0;
  1979. lock();
  1980. klient->sendeEncrypted("\x8", 1);
  1981. klient->sendeEncrypted((char*)&account, 4);
  1982. unlock();
  1983. cs->addEmpfangen(klient->getDownloadBytes(1));
  1984. cs->addGesendet(klient->getUploadBytes(1));
  1985. return 1;
  1986. }
  1987. bool CSKlient::freundesAnfrage(int vonAccount)
  1988. {
  1989. if (empfangen)
  1990. return 0;
  1991. lock();
  1992. klient->sendeEncrypted("\x9", 1);
  1993. klient->sendeEncrypted((char*)&vonAccount, 4);
  1994. unlock();
  1995. cs->addEmpfangen(klient->getDownloadBytes(1));
  1996. cs->addGesendet(klient->getUploadBytes(1));
  1997. return 1;
  1998. }
  1999. bool CSKlient::neuerFreund(int account)
  2000. {
  2001. if (empfangen)
  2002. return 0;
  2003. lock();
  2004. klient->sendeEncrypted("\xA", 1);
  2005. klient->sendeEncrypted((char*)&account, 4);
  2006. unlock();
  2007. cs->addEmpfangen(klient->getDownloadBytes(1));
  2008. cs->addGesendet(klient->getUploadBytes(1));
  2009. return 1;
  2010. }
  2011. bool CSKlient::freundesAnfrageAbgelehnt(int account)
  2012. {
  2013. if (empfangen)
  2014. return 0;
  2015. lock();
  2016. klient->sendeEncrypted("\xB", 1);
  2017. klient->sendeEncrypted((char*)&account, 4);
  2018. unlock();
  2019. cs->addEmpfangen(klient->getDownloadBytes(1));
  2020. cs->addGesendet(klient->getUploadBytes(1));
  2021. return 1;
  2022. }
  2023. bool CSKlient::einladungZumChatroom(int vonAccount, int chatroomId)
  2024. {
  2025. if (empfangen)
  2026. return 0;
  2027. lock();
  2028. klient->sendeEncrypted("\xC", 1);
  2029. klient->sendeEncrypted((char*)&vonAccount, 4);
  2030. klient->sendeEncrypted((char*)&chatroomId, 4);
  2031. unlock();
  2032. cs->addEmpfangen(klient->getDownloadBytes(1));
  2033. cs->addGesendet(klient->getUploadBytes(1));
  2034. return 1;
  2035. }
  2036. bool CSKlient::einladungZumChatroomAbgelehnt(int account, int chatroomId)
  2037. {
  2038. if (empfangen)
  2039. return 0;
  2040. lock();
  2041. klient->sendeEncrypted("\xD", 1);
  2042. klient->sendeEncrypted((char*)&account, 4);
  2043. klient->sendeEncrypted((char*)&chatroomId, 4);
  2044. unlock();
  2045. cs->addEmpfangen(klient->getDownloadBytes(1));
  2046. cs->addGesendet(klient->getUploadBytes(1));
  2047. return 1;
  2048. }
  2049. bool CSKlient::spielerBetrittChatroom(int chatroomId, int account)
  2050. {
  2051. if (empfangen)
  2052. return 0;
  2053. lock();
  2054. klient->sendeEncrypted("\xE", 1);
  2055. klient->sendeEncrypted((char*)&chatroomId, 4);
  2056. klient->sendeEncrypted((char*)&account, 4);
  2057. unlock();
  2058. cs->addEmpfangen(klient->getDownloadBytes(1));
  2059. cs->addGesendet(klient->getUploadBytes(1));
  2060. return 1;
  2061. }
  2062. bool CSKlient::chatroomNachricht(int chatroomId, int vonAccount, const char* nachricht)
  2063. {
  2064. if (empfangen)
  2065. return 0;
  2066. char len = (char)(nachricht ? textLength(nachricht) : 0);
  2067. if (len)
  2068. {
  2069. lock();
  2070. klient->sendeEncrypted("\xF", 1);
  2071. klient->sendeEncrypted((char*)&chatroomId, 4);
  2072. klient->sendeEncrypted((char*)&vonAccount, 4);
  2073. klient->sendeEncrypted(&len, 1);
  2074. klient->sendeEncrypted(nachricht, len);
  2075. unlock();
  2076. }
  2077. cs->addEmpfangen(klient->getDownloadBytes(1));
  2078. cs->addGesendet(klient->getUploadBytes(1));
  2079. return 1;
  2080. }
  2081. bool CSKlient::spielerLeavesChatroom(int chatroomId, int accountId)
  2082. {
  2083. if (empfangen)
  2084. return 0;
  2085. lock();
  2086. klient->sendeEncrypted("\x10", 1);
  2087. klient->sendeEncrypted((char*)&chatroomId, 4);
  2088. klient->sendeEncrypted((char*)&accountId, 4);
  2089. unlock();
  2090. cs->addEmpfangen(klient->getDownloadBytes(1));
  2091. cs->addGesendet(klient->getUploadBytes(1));
  2092. return 1;
  2093. }
  2094. bool CSKlient::freunde(char anzahl, Array< int >* zAccountId)
  2095. {
  2096. if (empfangen)
  2097. return 0;
  2098. lock();
  2099. klient->sendeEncrypted("\x11", 1);
  2100. klient->sendeEncrypted(&anzahl, 1);
  2101. for (int i = 0; i < anzahl; i++)
  2102. {
  2103. int accId = zAccountId->get(i);
  2104. klient->sendeEncrypted((char*)&accId, 4);
  2105. }
  2106. unlock();
  2107. cs->addEmpfangen(klient->getDownloadBytes(1));
  2108. cs->addGesendet(klient->getUploadBytes(1));
  2109. return 1;
  2110. }
  2111. bool CSKlient::spielerImChatroom(int chatroomId, char anzahl, Array< int >* zAccountId)
  2112. {
  2113. if (empfangen)
  2114. return 0;
  2115. lock();
  2116. klient->sendeEncrypted("\x12", 1);
  2117. klient->sendeEncrypted((char*)&chatroomId, 4);
  2118. klient->sendeEncrypted(&anzahl, 1);
  2119. for (int i = 0; i < anzahl; i++)
  2120. {
  2121. int accId = zAccountId->get(i);
  2122. klient->sendeEncrypted((char*)&accId, 4);
  2123. }
  2124. unlock();
  2125. cs->addEmpfangen(klient->getDownloadBytes(1));
  2126. cs->addGesendet(klient->getUploadBytes(1));
  2127. return 1;
  2128. }
  2129. bool CSKlient::freundOnline(int accountId)
  2130. {
  2131. if (empfangen)
  2132. return 0;
  2133. lock();
  2134. klient->sendeEncrypted("\x13", 1);
  2135. klient->sendeEncrypted((char*)&accountId, 4);
  2136. unlock();
  2137. cs->addEmpfangen(klient->getDownloadBytes(1));
  2138. cs->addGesendet(klient->getUploadBytes(1));
  2139. return 1;
  2140. }
  2141. bool CSKlient::freundOffline(int accountId)
  2142. {
  2143. if (empfangen)
  2144. return 0;
  2145. lock();
  2146. klient->sendeEncrypted("\x14", 1);
  2147. klient->sendeEncrypted((char*)&accountId, 4);
  2148. unlock();
  2149. cs->addEmpfangen(klient->getDownloadBytes(1));
  2150. cs->addGesendet(klient->getUploadBytes(1));
  2151. return 1;
  2152. }
  2153. bool CSKlient::chatroomAdmin(int chatroomId)
  2154. {
  2155. if (empfangen)
  2156. return 0;
  2157. lock();
  2158. klient->sendeEncrypted("\x15", 1);
  2159. klient->sendeEncrypted((char*)&chatroomId, 4);
  2160. unlock();
  2161. cs->addEmpfangen(klient->getDownloadBytes(1));
  2162. cs->addGesendet(klient->getUploadBytes(1));
  2163. return 1;
  2164. }
  2165. bool CSKlient::chatroomKick(int chatroomId)
  2166. {
  2167. if (empfangen)
  2168. return 0;
  2169. lock();
  2170. klient->sendeEncrypted("\x16", 1);
  2171. klient->sendeEncrypted((char*)&chatroomId, 4);
  2172. unlock();
  2173. cs->addEmpfangen(klient->getDownloadBytes(1));
  2174. cs->addGesendet(klient->getUploadBytes(1));
  2175. return 1;
  2176. }
  2177. bool CSKlient::spielerBertittGruppe(int accountId, int gruppeId)
  2178. {
  2179. if (empfangen)
  2180. return 0;
  2181. lock();
  2182. klient->sendeEncrypted("\x17", 1);
  2183. klient->sendeEncrypted((char*)&accountId, 4);
  2184. klient->sendeEncrypted((char*)&gruppeId, 4);
  2185. unlock();
  2186. cs->addEmpfangen(klient->getDownloadBytes(1));
  2187. cs->addGesendet(klient->getUploadBytes(1));
  2188. return 1;
  2189. }
  2190. bool CSKlient::spielerLeavesGruppe(int accountId, int gruppeId)
  2191. {
  2192. if (empfangen)
  2193. return 0;
  2194. lock();
  2195. klient->sendeEncrypted("\x18", 1);
  2196. klient->sendeEncrypted((char*)&accountId, 4);
  2197. klient->sendeEncrypted((char*)&gruppeId, 4);
  2198. unlock();
  2199. cs->addEmpfangen(klient->getDownloadBytes(1));
  2200. cs->addGesendet(klient->getUploadBytes(1));
  2201. return 1;
  2202. }
  2203. bool CSKlient::gruppeNachricht(int gruppeId, char* nachricht)
  2204. {
  2205. if (empfangen)
  2206. return 0;
  2207. char len = (char)textLength(nachricht);
  2208. if (!len)
  2209. return 1;
  2210. lock();
  2211. klient->sendeEncrypted("\x19", 1);
  2212. klient->sendeEncrypted((char*)&gruppeId, 4);
  2213. klient->sendeEncrypted(&len, 1);
  2214. klient->sendeEncrypted(nachricht, len);
  2215. unlock();
  2216. cs->addEmpfangen(klient->getDownloadBytes(1));
  2217. cs->addGesendet(klient->getUploadBytes(1));
  2218. return 1;
  2219. }
  2220. bool CSKlient::gruppeAnmelden(int gruppeId)
  2221. {
  2222. if (empfangen)
  2223. return 0;
  2224. lock();
  2225. klient->sendeEncrypted("\x1A", 1);
  2226. klient->sendeEncrypted((char*)&gruppeId, 4);
  2227. unlock();
  2228. cs->addEmpfangen(klient->getDownloadBytes(1));
  2229. cs->addGesendet(klient->getUploadBytes(1));
  2230. return 1;
  2231. }
  2232. bool CSKlient::gruppeAbmelden(int gruppeId)
  2233. {
  2234. if (empfangen)
  2235. return 0;
  2236. lock();
  2237. klient->sendeEncrypted("\x1B", 1);
  2238. klient->sendeEncrypted((char*)&gruppeId, 4);
  2239. unlock();
  2240. cs->addEmpfangen(klient->getDownloadBytes(1));
  2241. cs->addGesendet(klient->getUploadBytes(1));
  2242. return 1;
  2243. }
  2244. bool CSKlient::gruppeSpielStarten(int gruppeId, bool starten)
  2245. {
  2246. if (empfangen)
  2247. return 0;
  2248. lock();
  2249. klient->sendeEncrypted("\x1C", 1);
  2250. klient->sendeEncrypted((char*)&gruppeId, 4);
  2251. if (starten)
  2252. klient->sendeEncrypted("\1", 1);
  2253. else
  2254. klient->sendeEncrypted("\0", 1);
  2255. unlock();
  2256. cs->addEmpfangen(klient->getDownloadBytes(1));
  2257. cs->addGesendet(klient->getUploadBytes(1));
  2258. return 1;
  2259. }
  2260. bool CSKlient::setGruppeAdmin(int gruppeId, int adminId)
  2261. {
  2262. if (empfangen)
  2263. return 0;
  2264. lock();
  2265. klient->sendeEncrypted("\x1E", 1);
  2266. klient->sendeEncrypted((char*)&gruppeId, 4);
  2267. klient->sendeEncrypted((char*)&adminId, 4);
  2268. unlock();
  2269. cs->addEmpfangen(klient->getDownloadBytes(1));
  2270. cs->addGesendet(klient->getUploadBytes(1));
  2271. return 1;
  2272. }
  2273. bool CSKlient::kickAusGruppe(int gruppeId)
  2274. {
  2275. if (empfangen)
  2276. return 0;
  2277. lock();
  2278. klient->sendeEncrypted("\x1D", 1);
  2279. klient->sendeEncrypted((char*)&gruppeId, 4);
  2280. unlock();
  2281. cs->addEmpfangen(klient->getDownloadBytes(1));
  2282. cs->addGesendet(klient->getUploadBytes(1));
  2283. return 1;
  2284. }
  2285. bool CSKlient::gruppeEinladungAbgelehnt(int gruppeId, int accountId)
  2286. {
  2287. if (empfangen)
  2288. return 0;
  2289. lock();
  2290. klient->sendeEncrypted("\x1F", 1);
  2291. klient->sendeEncrypted((char*)&gruppeId, 4);
  2292. klient->sendeEncrypted((char*)&accountId, 4);
  2293. unlock();
  2294. cs->addEmpfangen(klient->getDownloadBytes(1));
  2295. cs->addGesendet(klient->getUploadBytes(1));
  2296. return 1;
  2297. }
  2298. bool CSKlient::spielServerVerbindungsAnfrage(unsigned short port, unsigned char* ip)
  2299. {
  2300. if (empfangen)
  2301. return 0;
  2302. lock();
  2303. klient->sendeEncrypted("\x20", 1);
  2304. klient->sendeEncrypted((char*)&port, 2);
  2305. klient->sendeEncrypted((char*)ip, 4);
  2306. unlock();
  2307. cs->addEmpfangen(klient->getDownloadBytes(1));
  2308. cs->addGesendet(klient->getUploadBytes(1));
  2309. return 1;
  2310. }
  2311. bool CSKlient::gruppeEinladungAbgebrochen(int gruppeId, int accountId)
  2312. {
  2313. if (empfangen)
  2314. return 0;
  2315. lock();
  2316. klient->sendeEncrypted("\x21", 1);
  2317. klient->sendeEncrypted((char*)&gruppeId, 4);
  2318. klient->sendeEncrypted((char*)&accountId, 4);
  2319. unlock();
  2320. cs->addEmpfangen(klient->getDownloadBytes(1));
  2321. cs->addGesendet(klient->getUploadBytes(1));
  2322. return 1;
  2323. }
  2324. bool CSKlient::gruppeEinladungNeu(int gruppeId, int accountId)
  2325. {
  2326. if (empfangen)
  2327. return 0;
  2328. lock();
  2329. klient->sendeEncrypted("\x22", 1);
  2330. klient->sendeEncrypted((char*)&gruppeId, 4);
  2331. klient->sendeEncrypted((char*)&accountId, 4);
  2332. unlock();
  2333. cs->addEmpfangen(klient->getDownloadBytes(1));
  2334. cs->addGesendet(klient->getUploadBytes(1));
  2335. return 1;
  2336. }
  2337. bool CSKlient::errorZuKlient(const char* nachricht) // sendet eine Fehlernachricht zum Klient
  2338. {
  2339. char len = (char)textLength(nachricht);
  2340. if (len)
  2341. {
  2342. lock();
  2343. klient->sendeEncrypted("\3", 1);
  2344. klient->sendeEncrypted(&len, 1);
  2345. klient->sendeEncrypted(nachricht, len);
  2346. unlock();
  2347. }
  2348. cs->addEmpfangen(klient->getDownloadBytes(1));
  2349. cs->addGesendet(klient->getUploadBytes(1));
  2350. return 1;
  2351. }
  2352. bool CSKlient::keepAlive() // erhält die Verbindung aufrecht
  2353. {
  2354. char res = 0;
  2355. lock();
  2356. klient->sendeEncrypted("\x23", 1);
  2357. klient->getNachrichtEncrypted(&res, 1);
  2358. unlock();
  2359. return res == 1;
  2360. }
  2361. void CSKlient::trenne()
  2362. {
  2363. klient->trenne();
  2364. }
  2365. // constant
  2366. int CSKlient::getKlientNummer() const
  2367. {
  2368. return klientNummer;
  2369. }
  2370. int CSKlient::getAccountId() const
  2371. {
  2372. return accountId;
  2373. }
  2374. bool CSKlient::istEmpfang() const
  2375. {
  2376. return empfangen;
  2377. }
  2378. // Inhalt der MSGWeiterleitung Klasse aus ChatServer.h
  2379. // Konstruktor
  2380. MSGWeiterleitung::MSGWeiterleitung(ChatServer* cs)
  2381. {
  2382. klient = 0;
  2383. this->cs = cs;
  2384. letzterFehler = new Text("");
  2385. }
  2386. // Destruktor
  2387. MSGWeiterleitung::~MSGWeiterleitung()
  2388. {
  2389. if (klient)
  2390. {
  2391. klient->trenne();
  2392. klient->release();
  2393. }
  2394. letzterFehler->release();
  2395. cs->release();
  2396. }
  2397. // nicht constant
  2398. bool MSGWeiterleitung::kickKlient(int accountId)
  2399. {
  2400. bool ret = 1;
  2401. int server = cs->zDB()->getChatServerId(accountId);
  2402. if (server == cs->getId())
  2403. {
  2404. CSKlient* klient = cs->zSendeKlient(accountId);
  2405. if (klient)
  2406. {
  2407. ret = klient->kick();
  2408. klient->trenne();
  2409. }
  2410. ret = ret & cs->removeAccount(accountId);
  2411. }
  2412. else
  2413. {
  2414. char* ip = 0;
  2415. unsigned short port = 0;
  2416. ret = cs->zDB()->getChatServerIpPort(server, &port, &ip);
  2417. if (ip)
  2418. {
  2419. klient = new Klient();
  2420. unsigned char key[20] = { 78, 20, 190, 133, 10, 175, 51, 96, 62, 1, 180, 194, 126, 50, 211, 154, 105, 227, 22, 101 };
  2421. klient->setSendeKey((char*)key, 20);
  2422. klient->setEmpfangKey((char*)key, 20);
  2423. ret = ret & klient->verbinde(port, ip);
  2424. ret = ret & klient->sendeEncrypted("\5\1", 2);
  2425. char res = 0;
  2426. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  2427. if (res)
  2428. {
  2429. ret = ret & klient->sendeEncrypted((char*)&accountId, 4);
  2430. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  2431. }
  2432. ret = (char)ret & res;
  2433. cs->addEmpfangen(klient->getDownloadBytes(1));
  2434. cs->addGesendet(klient->getUploadBytes(1));
  2435. klient->trenne();
  2436. klient = (Klient*)klient->release();
  2437. }
  2438. delete[]ip;
  2439. }
  2440. if (!ret)
  2441. letzterFehler->setText("Der Account ist nicht erreichbar");
  2442. return ret;
  2443. }
  2444. bool MSGWeiterleitung::accountOnline(int accountId)
  2445. {
  2446. bool ret = 1;
  2447. Array< int >* accId = new Array< int >();
  2448. int anzahl = cs->zDB()->getAccountOnlineFreunde(accountId, accId);
  2449. for (int i = 0; i < anzahl; i++)
  2450. {
  2451. int account = accId->get(i);
  2452. int server = cs->zDB()->getChatServerId(account);
  2453. if (server == cs->getId())
  2454. {
  2455. CSKlient* klient = cs->zSendeKlient(account);
  2456. if (klient)
  2457. ret = ret & klient->freundOnline(accountId);
  2458. else
  2459. ret = 0;
  2460. }
  2461. else
  2462. {
  2463. char* ip = 0;
  2464. unsigned short port = 0;
  2465. ret = ret & cs->zDB()->getChatServerIpPort(server, &port, &ip);
  2466. if (ip)
  2467. {
  2468. klient = new Klient();
  2469. unsigned char key[20] = { 78, 20, 190, 133, 10, 175, 51, 96, 62, 1, 180, 194, 126, 50, 211, 154, 105, 227, 22, 101 };
  2470. klient->setSendeKey((char*)key, 20);
  2471. klient->setEmpfangKey((char*)key, 20);
  2472. ret = ret & klient->verbinde(port, ip);
  2473. ret = ret & klient->sendeEncrypted("\5\2", 2);
  2474. char res = 0;
  2475. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  2476. if (res)
  2477. {
  2478. ret = ret & klient->sendeEncrypted((char*)&accountId, 4);
  2479. ret = ret & klient->sendeEncrypted((char*)&account, 4);
  2480. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  2481. }
  2482. ret = (char)ret & res;
  2483. cs->addEmpfangen(klient->getDownloadBytes(1));
  2484. cs->addGesendet(klient->getUploadBytes(1));
  2485. klient->trenne();
  2486. klient = (Klient*)klient->release();
  2487. }
  2488. delete[]ip;
  2489. }
  2490. }
  2491. accId->release();
  2492. if (!ret)
  2493. letzterFehler->setText("Einer oder mehr Accounts konnen nicht erreicht werden");
  2494. return ret;
  2495. }
  2496. bool MSGWeiterleitung::accountOffline(int accountId)
  2497. {
  2498. bool ret = 1;
  2499. Array< int >* accId = new Array< int >();
  2500. int anzahl = cs->zDB()->getAccountOnlineFreunde(accountId, accId);
  2501. for (int i = 0; i < anzahl; i++)
  2502. {
  2503. int account = accId->get(i);
  2504. int server = cs->zDB()->getChatServerId(account);
  2505. if (server == cs->getId())
  2506. {
  2507. CSKlient* klient = cs->zSendeKlient(account);
  2508. if (klient)
  2509. ret = ret & klient->freundOffline(accountId);
  2510. else
  2511. ret = 0;
  2512. }
  2513. else
  2514. {
  2515. char* ip = 0;
  2516. unsigned short port = 0;
  2517. ret = ret & cs->zDB()->getChatServerIpPort(server, &port, &ip);
  2518. if (ip)
  2519. {
  2520. klient = new Klient();
  2521. unsigned char key[20] = { 78, 20, 190, 133, 10, 175, 51, 96, 62, 1, 180, 194, 126, 50, 211, 154, 105, 227, 22, 101 };
  2522. klient->setSendeKey((char*)key, 20);
  2523. klient->setEmpfangKey((char*)key, 20);
  2524. ret = ret & klient->verbinde(port, ip);
  2525. ret = ret & klient->sendeEncrypted("\5\3", 2);
  2526. char res = 0;
  2527. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  2528. if (res)
  2529. {
  2530. ret = ret & klient->sendeEncrypted((char*)&accountId, 4);
  2531. ret = ret & klient->sendeEncrypted((char*)&account, 4);
  2532. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  2533. }
  2534. ret = (char)ret & res;
  2535. cs->addEmpfangen(klient->getDownloadBytes(1));
  2536. cs->addGesendet(klient->getUploadBytes(1));
  2537. klient->trenne();
  2538. klient = (Klient*)klient->release();
  2539. }
  2540. delete[]ip;
  2541. }
  2542. }
  2543. accId->release();
  2544. if (!ret)
  2545. letzterFehler->setText("Einer oder mehr Accounts konnen nicht erreicht werden");
  2546. return ret;
  2547. }
  2548. bool MSGWeiterleitung::chatNachricht(int vonAccount, int zuAccount, const char* nachricht)
  2549. {
  2550. bool ret = 1;
  2551. char len = (char)textLength(nachricht);
  2552. if (!len)
  2553. return 1;
  2554. int server = cs->zDB()->getChatServerId(zuAccount);
  2555. if (server == cs->getId())
  2556. {
  2557. CSKlient* klient = cs->zSendeKlient(zuAccount);
  2558. if (klient)
  2559. ret = klient->nachricht(vonAccount, nachricht);
  2560. else
  2561. ret = 0;
  2562. }
  2563. else
  2564. {
  2565. char* ip = 0;
  2566. unsigned short port = 0;
  2567. ret = cs->zDB()->getChatServerIpPort(server, &port, &ip);
  2568. if (ip)
  2569. {
  2570. klient = new Klient();
  2571. unsigned char key[20] = { 78, 20, 190, 133, 10, 175, 51, 96, 62, 1, 180, 194, 126, 50, 211, 154, 105, 227, 22, 101 };
  2572. klient->setSendeKey((char*)key, 20);
  2573. klient->setEmpfangKey((char*)key, 20);
  2574. ret = ret & klient->verbinde(port, ip);
  2575. ret = ret & klient->sendeEncrypted("\5\4", 2);
  2576. char res = 0;
  2577. ret = ret & klient->getNachrichtEncrypted((char*)&res, 1);
  2578. if (res)
  2579. {
  2580. ret = ret & klient->sendeEncrypted((char*)&vonAccount, 4);
  2581. ret = ret & klient->sendeEncrypted((char*)&zuAccount, 4);
  2582. ret = ret & klient->sendeEncrypted(&len, 1);
  2583. ret = ret & klient->sendeEncrypted((char*)nachricht, len);
  2584. ret = ret & klient->getNachrichtEncrypted((char*)&res, 1);
  2585. }
  2586. ret = (char)ret & res;
  2587. cs->addEmpfangen(klient->getDownloadBytes(1));
  2588. cs->addGesendet(klient->getUploadBytes(1));
  2589. klient->trenne();
  2590. klient = (Klient*)klient->release();
  2591. }
  2592. delete[]ip;
  2593. }
  2594. if (!ret)
  2595. letzterFehler->setText("Der Account konnte nicht erreicht werden. Die Nachricht wird zugestellt, sobald es möglich ist.");
  2596. return ret;
  2597. }
  2598. bool MSGWeiterleitung::accountStatusChange(int accountId, const char* status)
  2599. {
  2600. bool ret = 1;
  2601. char len = (char)textLength(status);
  2602. if (!len)
  2603. return 1;
  2604. Array< int >* accId = new Array< int >();
  2605. int anzahl = cs->zDB()->getAccountOnlineFreunde(accountId, accId);
  2606. for (int i = 0; i < anzahl; i++)
  2607. {
  2608. int account = accId->get(i);
  2609. int server = cs->zDB()->getChatServerId(account);
  2610. if (server == cs->getId())
  2611. {
  2612. CSKlient* klient = cs->zSendeKlient(account);
  2613. if (klient)
  2614. ret = ret & klient->accountStatusChange(accountId, status);
  2615. else
  2616. ret = 0;
  2617. }
  2618. else
  2619. {
  2620. char* ip = 0;
  2621. unsigned short port = 0;
  2622. ret = ret & cs->zDB()->getChatServerIpPort(server, &port, &ip);
  2623. if (ip)
  2624. {
  2625. klient = new Klient();
  2626. unsigned char key[20] = { 78, 20, 190, 133, 10, 175, 51, 96, 62, 1, 180, 194, 126, 50, 211, 154, 105, 227, 22, 101 };
  2627. klient->setSendeKey((char*)key, 20);
  2628. klient->setEmpfangKey((char*)key, 20);
  2629. ret = ret & klient->verbinde(port, ip);
  2630. ret = ret & klient->sendeEncrypted("\5\6", 2);
  2631. char res = 0;
  2632. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  2633. if (res)
  2634. {
  2635. ret = ret & klient->sendeEncrypted((char*)&accountId, 4);
  2636. ret = ret & klient->sendeEncrypted((char*)&account, 4);
  2637. ret = ret & klient->sendeEncrypted((char*)&len, 1);
  2638. ret = ret & klient->sendeEncrypted((char*)status, len);
  2639. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  2640. }
  2641. ret = (char)ret & res;
  2642. cs->addEmpfangen(klient->getDownloadBytes(1));
  2643. cs->addGesendet(klient->getUploadBytes(1));
  2644. klient->trenne();
  2645. klient = (Klient*)klient->release();
  2646. }
  2647. delete[]ip;
  2648. }
  2649. }
  2650. accId->release();
  2651. if (!ret)
  2652. letzterFehler->setText("Einer oder mehr Accounts konnen nicht erreicht werden");
  2653. return ret;
  2654. }
  2655. bool MSGWeiterleitung::accountNameChange(int accountId, const char* name)
  2656. {
  2657. bool ret = 1;
  2658. char len = (char)textLength(name);
  2659. if (!name)
  2660. return 1;
  2661. Array< int >* accId = new Array< int >();
  2662. int anzahl = cs->zDB()->getAccountOnlineFreunde(accountId, accId);
  2663. for (int i = 0; i < anzahl; i++)
  2664. {
  2665. int account = accId->get(i);
  2666. int server = cs->zDB()->getChatServerId(account);
  2667. if (server == cs->getId())
  2668. {
  2669. CSKlient* klient = cs->zSendeKlient(account);
  2670. if (klient)
  2671. ret = ret & klient->accountNameChange(accountId, name);
  2672. else
  2673. ret = 0;
  2674. }
  2675. else
  2676. {
  2677. char* ip = 0;
  2678. unsigned short port = 0;
  2679. ret = ret & cs->zDB()->getChatServerIpPort(server, &port, &ip);
  2680. if (ip)
  2681. {
  2682. klient = new Klient();
  2683. unsigned char key[20] = { 78, 20, 190, 133, 10, 175, 51, 96, 62, 1, 180, 194, 126, 50, 211, 154, 105, 227, 22, 101 };
  2684. klient->setSendeKey((char*)key, 20);
  2685. klient->setEmpfangKey((char*)key, 20);
  2686. ret = ret & klient->verbinde(port, ip);
  2687. ret = ret & klient->sendeEncrypted("\5\7", 2);
  2688. char res = 0;
  2689. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  2690. if (res)
  2691. {
  2692. ret = ret & klient->sendeEncrypted((char*)&accountId, 4);
  2693. ret = ret & klient->sendeEncrypted((char*)&account, 4);
  2694. ret = ret & klient->sendeEncrypted((char*)&len, 1);
  2695. ret = ret & klient->sendeEncrypted((char*)name, len);
  2696. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  2697. }
  2698. ret = (char)ret & res;
  2699. cs->addEmpfangen(klient->getDownloadBytes(1));
  2700. cs->addGesendet(klient->getUploadBytes(1));
  2701. klient->trenne();
  2702. klient = (Klient*)klient->release();
  2703. }
  2704. delete[]ip;
  2705. }
  2706. }
  2707. accId->release();
  2708. if (!ret)
  2709. letzterFehler->setText("Einer oder mehr Accounts konnen nicht erreicht werden");
  2710. return ret;
  2711. }
  2712. bool MSGWeiterleitung::accountKeinFreundMehr(int accountId, int zielAccountId)
  2713. {
  2714. bool ret = 1;
  2715. int server = cs->zDB()->getChatServerId(zielAccountId);
  2716. if (server == cs->getId())
  2717. {
  2718. CSKlient* klient = cs->zSendeKlient(zielAccountId);
  2719. if (klient)
  2720. ret = ret & klient->keinFreundMehr(accountId);
  2721. else
  2722. ret = 0;
  2723. }
  2724. else
  2725. {
  2726. char* ip = 0;
  2727. unsigned short port = 0;
  2728. ret = cs->zDB()->getChatServerIpPort(server, &port, &ip);
  2729. if (ip)
  2730. {
  2731. klient = new Klient();
  2732. unsigned char key[20] = { 78, 20, 190, 133, 10, 175, 51, 96, 62, 1, 180, 194, 126, 50, 211, 154, 105, 227, 22, 101 };
  2733. klient->setSendeKey((char*)key, 20);
  2734. klient->setEmpfangKey((char*)key, 20);
  2735. ret = ret & klient->verbinde(port, ip);
  2736. ret = ret & klient->sendeEncrypted("\5\x8", 2);
  2737. char res = 0;
  2738. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  2739. if (res)
  2740. {
  2741. ret = ret & klient->sendeEncrypted((char*)&accountId, 4);
  2742. ret = ret & klient->sendeEncrypted((char*)&zielAccountId, 4);
  2743. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  2744. }
  2745. ret = (char)ret & res;
  2746. cs->addEmpfangen(klient->getDownloadBytes(1));
  2747. cs->addGesendet(klient->getUploadBytes(1));
  2748. klient->trenne();
  2749. klient = (Klient*)klient->release();
  2750. }
  2751. delete[]ip;
  2752. }
  2753. if (!ret)
  2754. letzterFehler->setText("Der Account konnte nicht erreicht werden");
  2755. return ret;
  2756. }
  2757. bool MSGWeiterleitung::freundesAnfrage(int vonAccountId, int zuAccountId)
  2758. {
  2759. bool ret = 1;
  2760. int server = cs->zDB()->getChatServerId(zuAccountId);
  2761. if (server == cs->getId())
  2762. {
  2763. CSKlient* klient = cs->zSendeKlient(zuAccountId);
  2764. if (klient)
  2765. ret = ret & klient->freundesAnfrage(vonAccountId);
  2766. else
  2767. ret = 0;
  2768. }
  2769. else
  2770. {
  2771. char* ip = 0;
  2772. unsigned short port = 0;
  2773. ret = cs->zDB()->getChatServerIpPort(server, &port, &ip);
  2774. if (ip)
  2775. {
  2776. klient = new Klient();
  2777. unsigned char key[20] = { 78, 20, 190, 133, 10, 175, 51, 96, 62, 1, 180, 194, 126, 50, 211, 154, 105, 227, 22, 101 };
  2778. klient->setSendeKey((char*)key, 20);
  2779. klient->setEmpfangKey((char*)key, 20);
  2780. ret = ret & klient->verbinde(port, ip);
  2781. ret = ret & klient->sendeEncrypted("\5\x9", 2);
  2782. char res = 0;
  2783. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  2784. if (res)
  2785. {
  2786. ret = ret & klient->sendeEncrypted((char*)&vonAccountId, 4);
  2787. ret = ret & klient->sendeEncrypted((char*)&zuAccountId, 4);
  2788. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  2789. }
  2790. ret = (char)ret & res;
  2791. cs->addEmpfangen(klient->getDownloadBytes(1));
  2792. cs->addGesendet(klient->getUploadBytes(1));
  2793. klient->trenne();
  2794. klient = (Klient*)klient->release();
  2795. }
  2796. delete[]ip;
  2797. }
  2798. if (!ret)
  2799. letzterFehler->setText("Der Account konnte nicht erreicht werden");
  2800. return ret;
  2801. }
  2802. bool MSGWeiterleitung::neuerFreund(int accountId, int zuAccountId)
  2803. {
  2804. bool ret = 1;
  2805. int server = cs->zDB()->getChatServerId(zuAccountId);
  2806. if (server == cs->getId())
  2807. {
  2808. CSKlient* klient = cs->zSendeKlient(zuAccountId);
  2809. if (klient)
  2810. ret = ret & klient->neuerFreund(accountId);
  2811. else
  2812. ret = 0;
  2813. }
  2814. else
  2815. {
  2816. char* ip = 0;
  2817. unsigned short port = 0;
  2818. ret = cs->zDB()->getChatServerIpPort(server, &port, &ip);
  2819. if (ip)
  2820. {
  2821. klient = new Klient();
  2822. unsigned char key[20] = { 78, 20, 190, 133, 10, 175, 51, 96, 62, 1, 180, 194, 126, 50, 211, 154, 105, 227, 22, 101 };
  2823. klient->setSendeKey((char*)key, 20);
  2824. klient->setEmpfangKey((char*)key, 20);
  2825. ret = ret & klient->verbinde(port, ip);
  2826. ret = ret & klient->sendeEncrypted("\5\xA", 2);
  2827. char res = 0;
  2828. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  2829. if (res)
  2830. {
  2831. ret = ret & klient->sendeEncrypted((char*)&accountId, 4);
  2832. ret = ret & klient->sendeEncrypted((char*)&zuAccountId, 4);
  2833. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  2834. }
  2835. ret = (char)ret & res;
  2836. cs->addEmpfangen(klient->getDownloadBytes(1));
  2837. cs->addGesendet(klient->getUploadBytes(1));
  2838. klient->trenne();
  2839. klient = (Klient*)klient->release();
  2840. }
  2841. delete[]ip;
  2842. }
  2843. if (!ret)
  2844. letzterFehler->setText("Der Account konnte nicht erreicht werden");
  2845. return ret;
  2846. }
  2847. bool MSGWeiterleitung::einladungZumChatroom(int vonAccountId, int zuAccountId, int chatroomId)
  2848. {
  2849. bool ret = 1;
  2850. int server = cs->zDB()->getChatServerId(zuAccountId);
  2851. if (server == cs->getId())
  2852. {
  2853. CSKlient* klient = cs->zSendeKlient(zuAccountId);
  2854. if (klient)
  2855. ret = ret & klient->einladungZumChatroom(vonAccountId, chatroomId);
  2856. else
  2857. ret = 0;
  2858. }
  2859. else
  2860. {
  2861. char* ip = 0;
  2862. unsigned short port = 0;
  2863. ret = cs->zDB()->getChatServerIpPort(server, &port, &ip);
  2864. if (ip)
  2865. {
  2866. klient = new Klient();
  2867. unsigned char key[20] = { 78, 20, 190, 133, 10, 175, 51, 96, 62, 1, 180, 194, 126, 50, 211, 154, 105, 227, 22, 101 };
  2868. klient->setSendeKey((char*)key, 20);
  2869. klient->setEmpfangKey((char*)key, 20);
  2870. ret = ret & klient->verbinde(port, ip);
  2871. ret = ret & klient->sendeEncrypted("\5\xB", 2);
  2872. char res = 0;
  2873. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  2874. if (res)
  2875. {
  2876. ret = ret & klient->sendeEncrypted((char*)&vonAccountId, 4);
  2877. ret = ret & klient->sendeEncrypted((char*)&zuAccountId, 4);
  2878. ret = ret & klient->sendeEncrypted((char*)&chatroomId, 4);
  2879. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  2880. }
  2881. ret = (char)ret & res;
  2882. cs->addEmpfangen(klient->getDownloadBytes(1));
  2883. cs->addGesendet(klient->getUploadBytes(1));
  2884. klient->trenne();
  2885. klient = (Klient*)klient->release();
  2886. }
  2887. delete[]ip;
  2888. }
  2889. if (!ret)
  2890. letzterFehler->setText("Der Account konnte nicht erreicht werden");
  2891. return ret;
  2892. }
  2893. bool MSGWeiterleitung::spielerBetrittChatroom(int accountId, int chatroomId)
  2894. {
  2895. bool ret = 1;
  2896. Array< int >* accId = new Array< int >();
  2897. int anzahl = cs->zDB()->getChatroomAccount(chatroomId, accId);
  2898. for (int i = 0; i < anzahl; i++)
  2899. {
  2900. int account = accId->get(i);
  2901. if (account == accountId)
  2902. continue;
  2903. int server = cs->zDB()->getChatServerId(account);
  2904. if (server == cs->getId())
  2905. {
  2906. CSKlient* klient = cs->zSendeKlient(account);
  2907. if (klient)
  2908. ret = ret & klient->spielerBetrittChatroom(chatroomId, accountId);
  2909. else
  2910. ret = 0;
  2911. }
  2912. else
  2913. {
  2914. char* ip = 0;
  2915. unsigned short port = 0;
  2916. ret = ret & cs->zDB()->getChatServerIpPort(server, &port, &ip);
  2917. if (ip)
  2918. {
  2919. klient = new Klient();
  2920. unsigned char key[20] = { 78, 20, 190, 133, 10, 175, 51, 96, 62, 1, 180, 194, 126, 50, 211, 154, 105, 227, 22, 101 };
  2921. klient->setSendeKey((char*)key, 20);
  2922. klient->setEmpfangKey((char*)key, 20);
  2923. ret = ret & klient->verbinde(port, ip);
  2924. ret = ret & klient->sendeEncrypted("\5\xC", 2);
  2925. char res = 0;
  2926. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  2927. if (res)
  2928. {
  2929. ret = ret & klient->sendeEncrypted((char*)&accountId, 4);
  2930. ret = ret & klient->sendeEncrypted((char*)&account, 4);
  2931. ret = ret & klient->sendeEncrypted((char*)&chatroomId, 4);
  2932. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  2933. }
  2934. ret = (char)ret & res;
  2935. cs->addEmpfangen(klient->getDownloadBytes(1));
  2936. cs->addGesendet(klient->getUploadBytes(1));
  2937. klient->trenne();
  2938. klient = (Klient*)klient->release();
  2939. }
  2940. delete[]ip;
  2941. }
  2942. }
  2943. accId->release();
  2944. if (!ret)
  2945. letzterFehler->setText("Einer oder mehr Accounts konnen nicht erreicht werden");
  2946. return ret;
  2947. }
  2948. bool MSGWeiterleitung::chatroomNachricht(int vonAccount, const char* nachricht, int chatroomId)
  2949. {
  2950. bool ret = 1;
  2951. char len = (char)textLength(nachricht);
  2952. if (!len)
  2953. return 1;
  2954. Array< int >* accId = new Array< int >();
  2955. int anzahl = cs->zDB()->getChatroomAccount(chatroomId, accId);
  2956. for (int i = 0; i < anzahl; i++)
  2957. {
  2958. int account = accId->get(i);
  2959. int server = cs->zDB()->getChatServerId(account);
  2960. if (server == cs->getId())
  2961. {
  2962. CSKlient* klient = cs->zSendeKlient(account);
  2963. if (klient)
  2964. ret = ret & klient->chatroomNachricht(chatroomId, vonAccount, nachricht);
  2965. else
  2966. ret = 0;
  2967. }
  2968. else
  2969. {
  2970. char* ip = 0;
  2971. unsigned short port = 0;
  2972. ret = ret & cs->zDB()->getChatServerIpPort(server, &port, &ip);
  2973. if (ip)
  2974. {
  2975. klient = new Klient();
  2976. unsigned char key[20] = { 78, 20, 190, 133, 10, 175, 51, 96, 62, 1, 180, 194, 126, 50, 211, 154, 105, 227, 22, 101 };
  2977. klient->setSendeKey((char*)key, 20);
  2978. klient->setEmpfangKey((char*)key, 20);
  2979. ret = ret & klient->verbinde(port, ip);
  2980. ret = ret & klient->sendeEncrypted("\5\xD", 2);
  2981. char res = 0;
  2982. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  2983. if (res)
  2984. {
  2985. ret = ret & klient->sendeEncrypted((char*)&vonAccount, 4);
  2986. ret = ret & klient->sendeEncrypted((char*)&account, 4);
  2987. ret = ret & klient->sendeEncrypted((char*)&chatroomId, 4);
  2988. ret = ret & klient->sendeEncrypted(&len, 1);
  2989. ret = ret & klient->sendeEncrypted((char*)nachricht, len);
  2990. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  2991. }
  2992. ret = (char)ret & res;
  2993. cs->addEmpfangen(klient->getDownloadBytes(1));
  2994. cs->addGesendet(klient->getUploadBytes(1));
  2995. klient->trenne();
  2996. klient = (Klient*)klient->release();
  2997. }
  2998. delete[]ip;
  2999. }
  3000. }
  3001. accId->release();
  3002. if (!ret)
  3003. letzterFehler->setText("Einer oder mehr Accounts konnen nicht erreicht werden");
  3004. return ret;
  3005. }
  3006. bool MSGWeiterleitung::spielerLeavestChatroom(int accountId, int chatroomId)
  3007. {
  3008. bool ret = 1;
  3009. Array< int >* accId = new Array< int >();
  3010. int anzahl = cs->zDB()->getChatroomAccount(chatroomId, accId);
  3011. for (int i = 0; i < anzahl; i++)
  3012. {
  3013. int account = accId->get(i);
  3014. int server = cs->zDB()->getChatServerId(account);
  3015. if (server == cs->getId())
  3016. {
  3017. CSKlient* klient = cs->zSendeKlient(account);
  3018. if (klient)
  3019. ret = ret & klient->spielerLeavesChatroom(chatroomId, accountId);
  3020. else
  3021. ret = 0;
  3022. }
  3023. else
  3024. {
  3025. char* ip = 0;
  3026. unsigned short port = 0;
  3027. ret = ret & cs->zDB()->getChatServerIpPort(server, &port, &ip);
  3028. if (ip)
  3029. {
  3030. klient = new Klient();
  3031. unsigned char key[20] = { 78, 20, 190, 133, 10, 175, 51, 96, 62, 1, 180, 194, 126, 50, 211, 154, 105, 227, 22, 101 };
  3032. klient->setSendeKey((char*)key, 20);
  3033. klient->setEmpfangKey((char*)key, 20);
  3034. ret = ret & klient->verbinde(port, ip);
  3035. ret = ret & klient->sendeEncrypted("\5\xE", 2);
  3036. char res = 0;
  3037. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  3038. if (res)
  3039. {
  3040. ret = ret & klient->sendeEncrypted((char*)&accountId, 4);
  3041. ret = ret & klient->sendeEncrypted((char*)&account, 4);
  3042. ret = ret & klient->sendeEncrypted((char*)&chatroomId, 4);
  3043. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  3044. }
  3045. ret = (char)ret & res;
  3046. cs->addEmpfangen(klient->getDownloadBytes(1));
  3047. cs->addGesendet(klient->getUploadBytes(1));
  3048. klient->trenne();
  3049. klient = (Klient*)klient->release();
  3050. }
  3051. delete[]ip;
  3052. }
  3053. }
  3054. accId->release();
  3055. if (!ret)
  3056. letzterFehler->setText("Einer oder mehr Accounts konnen nicht erreicht werden");
  3057. return ret;
  3058. }
  3059. bool MSGWeiterleitung::freundEinladungAbgelehnt(int accountId, int zuAccountId)
  3060. {
  3061. bool ret = 1;
  3062. int server = cs->zDB()->getChatServerId(zuAccountId);
  3063. if (server == cs->getId())
  3064. {
  3065. CSKlient* klient = cs->zSendeKlient(zuAccountId);
  3066. if (klient)
  3067. ret = ret & klient->freundesAnfrageAbgelehnt(accountId);
  3068. else
  3069. ret = 0;
  3070. }
  3071. else
  3072. {
  3073. char* ip = 0;
  3074. unsigned short port = 0;
  3075. ret = cs->zDB()->getChatServerIpPort(server, &port, &ip);
  3076. if (ip)
  3077. {
  3078. klient = new Klient();
  3079. unsigned char key[20] = { 78, 20, 190, 133, 10, 175, 51, 96, 62, 1, 180, 194, 126, 50, 211, 154, 105, 227, 22, 101 };
  3080. klient->setSendeKey((char*)key, 20);
  3081. klient->setEmpfangKey((char*)key, 20);
  3082. ret = ret & klient->verbinde(port, ip);
  3083. ret = ret & klient->sendeEncrypted("\5\xF", 2);
  3084. char res = 0;
  3085. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  3086. if (res)
  3087. {
  3088. ret = ret & klient->sendeEncrypted((char*)&accountId, 4);
  3089. ret = ret & klient->sendeEncrypted((char*)&zuAccountId, 4);
  3090. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  3091. }
  3092. ret = (char)ret & res;
  3093. cs->addEmpfangen(klient->getDownloadBytes(1));
  3094. cs->addGesendet(klient->getUploadBytes(1));
  3095. klient->trenne();
  3096. klient = (Klient*)klient->release();
  3097. }
  3098. delete[]ip;
  3099. }
  3100. if (!ret)
  3101. letzterFehler->setText("Der Account konnte nicht erreicht werden");
  3102. return ret;
  3103. }
  3104. bool MSGWeiterleitung::chatroomEinladungAbgelehnt(int accountId, int chatroomId, int zuAccountId)
  3105. {
  3106. bool ret = 1;
  3107. int server = cs->zDB()->getChatServerId(zuAccountId);
  3108. if (server == cs->getId())
  3109. {
  3110. CSKlient* klient = cs->zSendeKlient(zuAccountId);
  3111. if (klient)
  3112. ret = ret & klient->einladungZumChatroomAbgelehnt(accountId, chatroomId);
  3113. else
  3114. ret = 0;
  3115. }
  3116. else
  3117. {
  3118. char* ip = 0;
  3119. unsigned short port = 0;
  3120. ret = cs->zDB()->getChatServerIpPort(server, &port, &ip);
  3121. if (ip)
  3122. {
  3123. klient = new Klient();
  3124. unsigned char key[20] = { 78, 20, 190, 133, 10, 175, 51, 96, 62, 1, 180, 194, 126, 50, 211, 154, 105, 227, 22, 101 };
  3125. klient->setSendeKey((char*)key, 20);
  3126. klient->setEmpfangKey((char*)key, 20);
  3127. ret = ret & klient->verbinde(port, ip);
  3128. ret = ret & klient->sendeEncrypted("\5\x10", 2);
  3129. char res = 0;
  3130. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  3131. if (res)
  3132. {
  3133. ret = ret & klient->sendeEncrypted((char*)&accountId, 4);
  3134. ret = ret & klient->sendeEncrypted((char*)&zuAccountId, 4);
  3135. ret = ret & klient->sendeEncrypted((char*)&chatroomId, 4);
  3136. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  3137. }
  3138. ret = (char)ret & res;
  3139. cs->addEmpfangen(klient->getDownloadBytes(1));
  3140. cs->addGesendet(klient->getUploadBytes(1));
  3141. klient->trenne();
  3142. klient = (Klient*)klient->release();
  3143. }
  3144. delete[]ip;
  3145. }
  3146. if (!ret)
  3147. letzterFehler->setText("Der Account konnte nicht erreicht werden");
  3148. return ret;
  3149. }
  3150. bool MSGWeiterleitung::fehler(int zuAccountId, const char* fehler)
  3151. {
  3152. bool ret = 1;
  3153. char len = (char)textLength(fehler);
  3154. if (!len)
  3155. return 1;
  3156. int server = cs->zDB()->getChatServerId(zuAccountId);
  3157. if (server == cs->getId())
  3158. {
  3159. CSKlient* klient = cs->zSendeKlient(zuAccountId);
  3160. if (klient)
  3161. ret = ret & klient->errorZuKlient(fehler);
  3162. else
  3163. ret = 0;
  3164. }
  3165. else
  3166. {
  3167. char* ip = 0;
  3168. unsigned short port = 0;
  3169. ret = cs->zDB()->getChatServerIpPort(server, &port, &ip);
  3170. if (ip)
  3171. {
  3172. klient = new Klient();
  3173. unsigned char key[20] = { 78, 20, 190, 133, 10, 175, 51, 96, 62, 1, 180, 194, 126, 50, 211, 154, 105, 227, 22, 101 };
  3174. klient->setSendeKey((char*)key, 20);
  3175. klient->setEmpfangKey((char*)key, 20);
  3176. ret = ret & klient->verbinde(port, ip);
  3177. ret = ret & klient->sendeEncrypted("\5\x11", 2);
  3178. char res = 0;
  3179. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  3180. if (res)
  3181. {
  3182. ret = ret & klient->sendeEncrypted((char*)&zuAccountId, 4);
  3183. ret = ret & klient->sendeEncrypted(&len, 1);
  3184. ret = ret & klient->sendeEncrypted((char*)&fehler, len);
  3185. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  3186. }
  3187. ret = (char)ret & res;
  3188. cs->addEmpfangen(klient->getDownloadBytes(1));
  3189. cs->addGesendet(klient->getUploadBytes(1));
  3190. klient->trenne();
  3191. klient = (Klient*)klient->release();
  3192. }
  3193. delete[]ip;
  3194. }
  3195. if (!ret)
  3196. letzterFehler->setText("Der Account konnte nicht erreicht werden");
  3197. return ret;
  3198. }
  3199. bool MSGWeiterleitung::chatroomAdmin(int chatroomId, int zuAccountId)
  3200. {
  3201. bool ret = 1;
  3202. int server = cs->zDB()->getChatServerId(zuAccountId);
  3203. if (server == cs->getId())
  3204. {
  3205. CSKlient* klient = cs->zSendeKlient(zuAccountId);
  3206. if (klient)
  3207. ret = ret & klient->chatroomAdmin(chatroomId);
  3208. else
  3209. ret = 0;
  3210. }
  3211. else
  3212. {
  3213. char* ip = 0;
  3214. unsigned short port = 0;
  3215. ret = cs->zDB()->getChatServerIpPort(server, &port, &ip);
  3216. if (ip)
  3217. {
  3218. klient = new Klient();
  3219. unsigned char key[20] = { 78, 20, 190, 133, 10, 175, 51, 96, 62, 1, 180, 194, 126, 50, 211, 154, 105, 227, 22, 101 };
  3220. klient->setSendeKey((char*)key, 20);
  3221. klient->setEmpfangKey((char*)key, 20);
  3222. ret = ret & klient->verbinde(port, ip);
  3223. ret = ret & klient->sendeEncrypted("\5\x12", 2);
  3224. char res = 0;
  3225. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  3226. if (res)
  3227. {
  3228. ret = ret & klient->sendeEncrypted((char*)&zuAccountId, 4);
  3229. ret = ret & klient->sendeEncrypted((char*)&chatroomId, 4);
  3230. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  3231. }
  3232. ret = (char)ret & res;
  3233. cs->addEmpfangen(klient->getDownloadBytes(1));
  3234. cs->addGesendet(klient->getUploadBytes(1));
  3235. klient->trenne();
  3236. klient = (Klient*)klient->release();
  3237. }
  3238. delete[]ip;
  3239. }
  3240. if (!ret)
  3241. letzterFehler->setText("Der Account konnte nicht erreicht werden");
  3242. return ret;
  3243. }
  3244. bool MSGWeiterleitung::chatroomKick(int chatroomId, int accountId)
  3245. {
  3246. bool ret = 1;
  3247. int server = cs->zDB()->getChatServerId(accountId);
  3248. if (server == cs->getId())
  3249. {
  3250. CSKlient* klient = cs->zSendeKlient(accountId);
  3251. if (klient)
  3252. ret = ret & klient->chatroomKick(chatroomId);
  3253. else
  3254. ret = 0;
  3255. }
  3256. else
  3257. {
  3258. char* ip = 0;
  3259. unsigned short port = 0;
  3260. ret = cs->zDB()->getChatServerIpPort(server, &port, &ip);
  3261. if (ip)
  3262. {
  3263. klient = new Klient();
  3264. unsigned char key[20] = { 78, 20, 190, 133, 10, 175, 51, 96, 62, 1, 180, 194, 126, 50, 211, 154, 105, 227, 22, 101 };
  3265. klient->setSendeKey((char*)key, 20);
  3266. klient->setEmpfangKey((char*)key, 20);
  3267. ret = ret & klient->verbinde(port, ip);
  3268. ret = ret & klient->sendeEncrypted("\5\x13", 2);
  3269. char res = 0;
  3270. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  3271. if (res)
  3272. {
  3273. ret = ret & klient->sendeEncrypted((char*)&accountId, 4);
  3274. ret = ret & klient->sendeEncrypted((char*)&chatroomId, 4);
  3275. ret = ret & klient->getNachrichtEncrypted(&res, 1);
  3276. }
  3277. ret = (char)ret & res;
  3278. cs->addEmpfangen(klient->getDownloadBytes(1));
  3279. cs->addGesendet(klient->getUploadBytes(1));
  3280. klient->trenne();
  3281. klient = (Klient*)klient->release();
  3282. }
  3283. delete[]ip;
  3284. }
  3285. if (!ret)
  3286. letzterFehler->setText("Der Account konnte nicht erreicht werden");
  3287. return ret;
  3288. }
  3289. // constant
  3290. const char* MSGWeiterleitung::getLetzterFehler()
  3291. {
  3292. return letzterFehler->getText();
  3293. }