123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497 |
- #include "Klient.h"
- #include "Spieler.h"
- #include <Text.h>
- // Inhalt der Klient Klasse aus Klient.h
- // Konstruktor
- Klient::Klient( SSKlientV *klient )
- {
- this->klient = klient;
- ref = 1;
- }
- // Destruktor
- Klient::~Klient()
- {
- if( klient )
- klient->release();
- }
- // nicht constant
- void Klient::offline()
- {
- klient = klient->release();
- }
- void Klient::online( SSKlientV *zKlient )
- {
- if( klient )
- klient = klient->release();
- klient = zKlient->getThis();
- }
- void Klient::sendeSpielerNummer( int sNum, double spielZeit )
- {
- if( !klient )
- return;
- short len = 13;
- char *bytes = new char[ len ];
- *(double*)bytes = spielZeit;
- *(char*)( bytes + 8 ) = 0;
- *(int*)( bytes + 9 ) = sNum;
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeInitSpieler( int anzahl, RCArray< Spieler > *zSpieler, double spielZeit )
- {
- if( !klient )
- return;
- short len = (short)( 13 + 20 * anzahl );
- char *bytes = new char[ len ];
- *(double*)bytes = spielZeit;
- *(char*)( bytes + 8 ) = 1;
- *(int*)( bytes + 9 ) = anzahl;
- for( int i = 0; i < anzahl; i++ )
- {
- *(int*)( bytes + i * 20 + 13 ) = zSpieler->z( i )->getSpielerNummer();
- *(int*)( bytes + i * 20 + 17 ) = zSpieler->z( i )->getSpielerTeam();
- *(int*)( bytes + i * 20 + 21 ) = zSpieler->z( i )->getSpielerFarbe();
- *(int*)( bytes + i * 20 + 25 ) = zSpieler->z( i )->getTeamFarbe();
- *(int*)( bytes + i * 20 + 29 ) = zSpieler->z( i )->getAccountId();
- }
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeSpielerPosition( Spieler *zSpieler, double spielZeit )
- {
- if( !klient )
- return;
- short len = 29;
- char *bytes = new char[ len ];
- *(double*)bytes = spielZeit;
- *(char*)( bytes + 8 ) = 2;
- *(int*)( bytes + 9 ) = zSpieler->getSpielerNummer();
- *(double*)( bytes + 13 ) = zSpieler->getX();
- *(double*)( bytes + 21 ) = zSpieler->getY();
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeKammeraSize( int br, int hi, double spielZeit )
- {
- if( !klient )
- return;
- short len = 17;
- char *bytes = new char[ len ];
- *(double*)bytes = spielZeit;
- *(char*)( bytes + 8 ) = 3;
- *(int*)( bytes + 9 ) = br;
- *(int*)( bytes + 13 ) = hi;
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeStart( double spielZeit )
- {
- if( !klient )
- return;
- short len = 9;
- char *bytes = new char[ len ];
- *(double*)bytes = spielZeit;
- *(char*)( bytes + 8 ) = 4;
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeSpielerTod( Spieler *zSpieler, double spielZeit )
- {
- if( !klient )
- return;
- short len = 13;
- char *bytes = new char[ len ];
- *(double*)bytes = spielZeit;
- *(char*)( bytes + 8 ) = 5;
- *(int*)( bytes + 9 ) = zSpieler->getSpielerNummer();
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeSpielEnde( char gewonnen, double spielZeit )
- {
- if( !klient )
- return;
- short len = 10;
- char *bytes = new char[ len ];
- *(double*)bytes = spielZeit;
- *(char*)( bytes + 8 ) = 6;
- *(char*)( bytes + 9 ) = gewonnen;
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeSpielerGeschwindigkeit( Spieler *zSpieler, double spielZeit )
- {
- if( !klient )
- return;
- short len = 29;
- char *bytes = new char[ len ];
- *(double*)bytes = spielZeit;
- *(char*)( bytes + 8 ) = 7;
- *(int*)( bytes + 9 ) = zSpieler->getSpielerNummer();
- *(double*)( bytes + 13 ) = zSpieler->getSpeedX();
- *(double*)( bytes + 21 ) = zSpieler->getSpeedY();
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeSpielerWendigkeit( Spieler *zSpieler, double spielZeit )
- {
- if( !klient )
- return;
- short len = 21;
- char *bytes = new char[ len ];
- *(double*)bytes = spielZeit;
- *(char*)( bytes + 8 ) = 8;
- *(int*)( bytes + 9 ) = zSpieler->getSpielerNummer();
- *(double*)( bytes + 13 ) = zSpieler->getKurve();
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeSpielerKurve( int sNum, char kurve, double spielZeit )
- {
- if( !klient )
- return;
- short len = 14;
- char *bytes = new char[ len ];
- *(double*)bytes = spielZeit;
- *(char*)( bytes + 8 ) = 9;
- *(int*)( bytes + 9 ) = sNum;
- bytes[ 13 ] = kurve;
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeKartenSize( int br, int hi, double spielZeit )
- {
- if( !klient )
- return;
- short len = 17;
- char *bytes = new char[ len ];
- *(double*)bytes = spielZeit;
- *(char*)( bytes + 8 ) = 0xA;
- *(int*)( bytes + 9 ) = br;
- *(int*)( bytes + 13 ) = hi;
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeChatNachricht( char *txt, double spielZeit )
- {
- if( !klient )
- return;
- short len = (short)( 9 + textLength( txt ) );
- char *bytes = new char[ len ];
- *(double*)bytes = spielZeit;
- *(char*)( bytes + 8 ) = 0xB;
- for( int i = 9; i < len; i++ )
- bytes[ i ] = txt[ i - 9 ];
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeLinienUnterbrechung( int sNum, bool unterbrochen, double spielZeit )
- {
- if( !klient )
- return;
- char *bytes = new char[ 14 ];
- *(double*)bytes = spielZeit;
- *(char*)( bytes + 8 ) = 0xC;
- *(int*)( bytes + 9 ) = sNum;
- *( bytes + 13 ) = (char)unterbrochen;
- klient->spielNachricht( 14, bytes );
- delete[] bytes;
- }
- void Klient::sendeTeamMaxPunkte( int team, int mP, double spielZeit )
- {
- if( !klient )
- return;
- char *bytes = new char[ 17 ];
- *(double*)bytes = spielZeit;
- *(char*)( bytes + 8 ) = 0xD;
- *(int*)( bytes + 9 ) = team;
- *(int*)( bytes + 13 ) = mP;
- klient->spielNachricht( 17, bytes );
- delete[] bytes;
- }
- void Klient::sendeTeamPunkte( int team, int p, double spielZeit )
- {
- if( !klient )
- return;
- char *bytes = new char[ 17 ];
- *(double*)bytes = spielZeit;
- *(char*)( bytes + 8 ) = 0xE;
- *(int*)( bytes + 9 ) = team;
- *(int*)( bytes + 13 ) = p;
- klient->spielNachricht( 17, bytes );
- delete[] bytes;
- }
- void Klient::sendeSpielerPunkte( int sNum, int p, double spielZeit )
- {
- if( !klient )
- return;
- char *bytes = new char[ 17 ];
- *(double*)bytes = spielZeit;
- *(char*)( bytes + 8 ) = 0xF;
- *(int*)( bytes + 9 ) = sNum;
- *(int*)( bytes + 13 ) = p;
- klient->spielNachricht( 17, bytes );
- delete[] bytes;
- }
- void Klient::sendeTeamTod( int team, double spielZeit )
- {
- if( !klient )
- return;
- char *bytes = new char[ 13 ];
- *(double*)bytes = spielZeit;
- *(char*)( bytes + 8 ) = 0x10;
- *(int*)( bytes + 9 ) = team;
- klient->spielNachricht( 13, bytes );
- delete[] bytes;
- }
- void Klient::sendeTeamName( int team, char *name )
- {
- if( !klient )
- return;
- int nL = textLength( name );
- char *bytes = new char[ 13 + nL ];
- *(double*)bytes = 0;
- *(char*)( bytes + 8 ) = 0x13;
- *(int*)( bytes + 9 ) = team;
- memcpy( bytes + 13, name, nL );
- klient->spielNachricht( (short)( 13 + nL ), bytes );
- delete[] bytes;
- }
- void Klient::sendeRundenEnde( int winTeam, double spielZeit )
- {
- if( !klient )
- return;
- char *bytes = new char[ 13 ];
- *(double*)bytes = spielZeit;
- *(char*)( bytes + 8 ) = 0x11;
- *(int*)( bytes + 9 ) = winTeam;
- klient->spielNachricht( 13, bytes );
- delete[] bytes;
- }
- void Klient::sendeZeitVerbleibend( int sekunden, double spielZeit )
- {
- if( !klient )
- return;
- char *bytes = new char[ 13 ];
- *(double*)bytes = spielZeit;
- *(char*)( bytes + 8 ) = 0x12;
- *(int*)( bytes + 9 ) = sekunden;
- klient->spielNachricht( 13, bytes );
- delete[] bytes;
- }
- void Klient::sendeStatistikChatNachricht( int vonAccount, char *txt )
- {
- if( !klient )
- return;
- short len = (short)( 5 + textLength( txt ) );
- char *bytes = new char[ len ];
- *(char*)( bytes ) = 8;
- *(int*)( bytes + 1 ) = vonAccount;
- for( int i = 5; i < len; i++ )
- bytes[ i ] = txt[ i - 5 ];
- klient->statistikNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeStatistikSpielerOffline( int account )
- {
- if( !klient )
- return;
- char *bytes = new char[ 5 ];
- *(char*)( bytes ) = 9;
- *(int*)( bytes + 1 ) = account;
- klient->statistikNachricht( 5, bytes );
- delete[] bytes;
- }
- void Klient::sendeGesamtSpielerStatistik( GesamtSpielerStatistik *zS )
- {
- if( !zS || !klient )
- return;
- char snl = (char)zS->zSpielerName()->getLength();
- char tnl = (char)zS->zTeamName()->getLength();
- int len = 43 + snl + tnl;
- char *bytes = new char[ len ];
- bytes[ 0 ] = 2;
- *(int*)( bytes + 1 ) = zS->getSpielerNummer();
- *(char*)( bytes + 5 ) = (char)zS->zSpielerName()->getLength();
- for( int i = 0; i < snl; i++ )
- bytes[ i + 6 ] = zS->zSpielerName()->getText()[ i ];
- *(char*)( bytes + 6 + snl ) = tnl;
- for( int i = 0; i < tnl; i++ )
- bytes[ i + 7 + snl ] = zS->zTeamName()->getText()[ i ];
- *(int*)( bytes + 7 + snl + tnl ) = zS->getSpielerFarbe();
- *(int*)( bytes + 11 + snl + tnl ) = zS->getTeamFarbe();
- *(int*)( bytes + 15 + snl + tnl ) = zS->getGewonneneRunden();
- *(int*)( bytes + 19 + snl + tnl ) = zS->getPunkte();
- *(int*)( bytes + 23 + snl + tnl ) = zS->getLinienLength();
- *(int*)( bytes + 27 + snl + tnl ) = zS->getZeitAmLeben();
- *(int*)( bytes + 31 + snl + tnl ) = zS->getZeitTod();
- *(int*)( bytes + 35 + snl + tnl ) = zS->getKills();
- *(int*)( bytes + 39 + snl + tnl ) = zS->getTode();
- klient->statistikNachricht( (short)len, bytes );
- delete[] bytes;
- }
- void Klient::sendeGesamtTeamStatistik( GesamtTeamStatistik *zS )
- {
- if( !zS || !klient )
- return;
- char tnl = (char)zS->zTeamName()->getLength();
- int len = 30 + tnl;
- char *bytes = new char[ len ];
- bytes[ 0 ] = 3;
- *(int*)( bytes + 1 ) = zS->getTeamNummer();
- *(char*)( bytes + 5 ) = tnl;
- for( int i = 0; i < tnl; i++ )
- bytes[ i + 6 ] = zS->zTeamName()->getText()[ i ];
- *(int*)( bytes + 6 + tnl ) = zS->getTeamFarbe();
- *(int*)( bytes + 10 + tnl ) = zS->getGewonneneRunden();
- *(int*)( bytes + 14 + tnl ) = zS->getPunkte();
- *(int*)( bytes + 18 + tnl ) = zS->getLinienLength();
- *(int*)( bytes + 22 + tnl ) = zS->getKills();
- *(int*)( bytes + 26 + tnl ) = zS->getTode();
- klient->statistikNachricht( (short)len, bytes );
- delete[] bytes;
- }
- void Klient::sendeRundeStatistik( RundenRundenStatistik *zS )
- {
- if( !zS || !klient )
- return;
- char *bytes = new char[ 25 ];
- bytes[ 0 ] = 4;
- *(int*)( bytes + 1 ) = zS->getRundenNummer();
- *(int*)( bytes + 5 ) = zS->getRundenDauer();
- *(int*)( bytes + 9 ) = zS->getSiegerTeam();
- *(int*)( bytes + 13 ) = zS->getSpielFeldNutzung();
- *(int*)( bytes + 17 ) = zS->zRundenBild()->getBreite();
- *(int*)( bytes + 21 ) = zS->zRundenBild()->getHeight();
- klient->statistikNachricht( 25, bytes );
- delete[] bytes;
- Bild *zB = zS->zRundenBild();
- int pixel = zB->getBreite() * zB->getHeight();
- while( pixel )
- {
- int pStart = zB->getBreite() * zB->getHeight() - pixel;
- int pLen = pixel > 200 ? 200 : pixel;
- char *bytes = new char[ 13 + pLen * 4 ];
- bytes[ 0 ] = 5;
- *(int*)( bytes + 1 ) = zS->getRundenNummer();
- *(int*)( bytes + 5 ) = pStart;
- *(int*)( bytes + 9 ) = pLen;
- for( int i = 0; i < pLen; i++ )
- *(int*)( bytes + 13 + i * 4 ) = zB->getBuffer()[ pStart + i ];
- klient->statistikNachricht( (short)( 13 + pLen * 4 ), bytes );
- delete[] bytes;
- pixel -= pLen;
- }
- int anz = zS->getSpielerAnzahl();
- for( int i = 0; i < anz; i++ )
- sendeRundeSpielerStatistik( zS->zSpielerStatistik( i ), zS->getRundenNummer() );
- anz = zS->getTeamAnzahl();
- for( int i = 0; i < anz; i++ )
- sendeRundeTeamStatistik( zS->zTeamStatistik( i ), zS->getRundenNummer() );
- }
- void Klient::sendeRundeSpielerStatistik( RundenSpielerStatistik *zS, int runde )
- {
- if( !zS || !klient )
- return;
- char snl = (char)zS->zSpielerName()->getLength();
- char tnl = (char)zS->zTeamName()->getLength();
- int len = 31 + snl + tnl;
- char *bytes = new char[ len ];
- bytes[ 0 ] = 6;
- *(int*)( bytes + 1 ) = runde;
- *(int*)( bytes + 5 ) = zS->getSpielerNummer();
- *(char*)( bytes + 9 ) = snl;
- for( int i = 0; i < snl; i++ )
- bytes[ i + 10 ] = zS->zSpielerName()->getText()[ i ];
- *(char*)( bytes + 10 + snl ) = tnl;
- for( int i = 0; i < tnl; i++ )
- bytes[ i + 11 + snl ] = zS->zTeamName()->getText()[ i ];
- *(int*)( bytes + 11 + snl + tnl ) = zS->getSpielerFarbe();
- *(int*)( bytes + 15 + snl + tnl ) = zS->getTeamFarbe();
- *(int*)( bytes + 19 + snl + tnl ) = zS->getLinienLength();
- *(int*)( bytes + 23 + snl + tnl ) = zS->getKills();
- *(int*)( bytes + 27 + snl + tnl ) = zS->getTodesZeit();
- klient->statistikNachricht( (short)len, bytes );
- delete[] bytes;
- }
- void Klient::sendeRundeTeamStatistik( RundenTeamStatistik *zS, int runde )
- {
- if( !zS || !klient )
- return;
- char tnl = (char)zS->zTeamName()->getLength();
- int len = 27 + tnl;
- char *bytes = new char[ len ];
- bytes[ 0 ] = 7;
- *(int*)( bytes + 1 ) = runde;
- *(int*)( bytes + 5 ) = zS->getTeamNummer();
- *(char*)( bytes + 9 ) = tnl;
- for( int i = 0; i < tnl; i++ )
- bytes[ i + 10 ] = zS->zTeamName()->getText()[ i ];
- *(int*)( bytes + 10 + tnl ) = zS->getTeamFarbe();
- *(char*)( bytes + 14 + tnl ) = (char)zS->getErgebnis();
- *(int*)( bytes + 15 + tnl ) = zS->getLinienLength();
- *(int*)( bytes + 19 + tnl ) = zS->getKills();
- *(int*)( bytes + 23 + tnl ) = zS->getTode();
- klient->statistikNachricht( (short)len, bytes );
- delete[] bytes;
- }
- void Klient::sendeStatistikLadenFertig()
- {
- if( !klient )
- return;
- char byte = 1;
- klient->statistikNachricht( 1, &byte );
- }
- // constant
- bool Klient::istOnline() const
- {
- return klient != 0;
- }
- // reference Counting
- Klient *Klient::getThie()
- {
- ref++;
- return this;
- }
- Klient *Klient::release()
- {
- ref--;
- if( !ref )
- delete this;
- return 0;
- }
|