ChatServer.cpp 94 KB

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