ChatServer.cpp 128 KB

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