123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- #include "Spieler.h"
- #include "SSKlient.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::sendeInit( RCArray< Spieler > *zSpieler, int spielZeit )
- {
- if( !klient )
- return;
- short len = (short)( 6 + zSpieler->getEintragAnzahl() * 8 );
- char *bytes = new char[ len ];
- *(int*)bytes = spielZeit;
- *(char*)( bytes + 4 ) = 6;
- *(char*)( bytes + 5 ) = (char)zSpieler->getEintragAnzahl();
- for( int i = 0; i < zSpieler->getEintragAnzahl(); i++ )
- {
- *(int*)( bytes + 6 + i * 8 ) = zSpieler->z( i )->getSpielerNummer();
- *(int*)( bytes + 10 + i * 8 ) = zSpieler->z( i )->getAccountId();
- }
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeSpielerNummer( int sNum, int spielZeit )
- {
- if( !klient )
- return;
- short len = 9;
- char *bytes = new char[ len ];
- *(int*)bytes = spielZeit;
- *(char*)( bytes + 4 ) = 9;
- *(int*)( bytes + 5 ) = sNum;
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeStart( int spielZeit )
- {
- if( !klient )
- return;
- short len = 5;
- char *bytes = new char[ len ];
- *(int*)bytes = spielZeit;
- *(char*)( bytes + 4 ) = 0xA;
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeTastaturStatus( int spielerId, TastaturStatus ts, bool aktiv, int spielZeit )
- {
- if( !klient )
- return;
- short len = 9;
- char *bytes = new char[ len ];
- *(int*)bytes = spielZeit;
- *(char*)( bytes + 4 ) = (char)( (char)ts * 2 + (char)!aktiv );
- *(int*)( bytes + 5 ) = spielerId;
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeSkillNachricht( int sNum, char art, int spielZeit )
- {
- if( !klient )
- return;
- short len = 10;
- char *bytes = new char[ len ];
- *(int*)bytes = spielZeit;
- *(char*)( bytes + 4 ) = 0xC;
- *(int*)( bytes + 5 ) = sNum;
- *(char*)( bytes + 9 ) = art;
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeAsteroid( int id, Vertex pos, Vertex speed, float rot, float rotS, int index, int spielZeit )
- {
- if( !klient )
- return;
- short len = 37;
- char *bytes = new char[ len ];
- *(int*)bytes = spielZeit;
- *(char*)( bytes + 4 ) = 0x11;
- *(int*)( bytes + 5 ) = id;
- *(float*)( bytes + 9 ) = pos.x;
- *(float*)( bytes + 13 ) = pos.y;
- *(float*)( bytes + 17 ) = speed.x;
- *(float*)( bytes + 21 ) = speed.y;
- *(float*)( bytes + 25 ) = rot;
- *(float*)( bytes + 29 ) = rotS;
- *(int*)( bytes + 33 ) = index;
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeSchuss( int id, int sNum, Vertex pos, Vertex speed, double intensity, int spielZeit )
- {
- if( !klient )
- return;
- short len = 37;
- char *bytes = new char[ len ];
- *(int*)bytes = spielZeit;
- *(char*)( bytes + 4 ) = 0xD;
- *(int*)( bytes + 5 ) = id;
- *(int*)( bytes + 9 ) = sNum;
- *(float*)( bytes + 13 ) = pos.x;
- *(float*)( bytes + 17 ) = pos.y;
- *(float*)( bytes + 21 ) = speed.x;
- *(float*)( bytes + 25 ) = speed.y;
- *(double*)( bytes + 29 ) = intensity;
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendePixel( int asteroid, int pixelId, int spielZeit )
- {
- if( !klient )
- return;
- short len = 13;
- char *bytes = new char[ len ];
- *(int*)bytes = spielZeit;
- *(char*)( bytes + 4 ) = 0x13;
- *(int*)( bytes + 5 ) = asteroid;
- *(int*)( bytes + 9 ) = pixelId;
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeEp( int pixelId, int spielerId, int spielZeit )
- {
- if( !klient )
- return;
- short len = 13;
- char *bytes = new char[ len ];
- *(int*)bytes = spielZeit;
- *(char*)( bytes + 4 ) = 0x14;
- *(int*)( bytes + 5 ) = pixelId;
- *(int*)( bytes + 9 ) = spielerId;
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeTreffer( int id, int sNum, int spielZeit )
- {
- if( !klient )
- return;
- short len = 13;
- char *bytes = new char[ len ];
- *(int*)bytes = spielZeit;
- *(char*)( bytes + 4 ) = 0xE;
- *(int*)( bytes + 5 ) = id;
- *(int*)( bytes + 9 ) = sNum;
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeAsteroidTreffer( int asteroidId, int newAsteroidId, int schussId, Vertex pos, __int64 seed, int spielZeit )
- {
- if( !klient )
- return;
- short len = 33;
- char *bytes = new char[ len ];
- *(int*)bytes = spielZeit;
- *(char*)( bytes + 4 ) = 0x12;
- *(int*)( bytes + 5 ) = schussId;
- *(int*)( bytes + 9 ) = asteroidId;
- *(float*)( bytes + 13 ) = pos.x;
- *(float*)( bytes + 17 ) = pos.y;
- *(__int64*)( bytes + 21 ) = seed;
- *(int*)( bytes + 29 ) = newAsteroidId;
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeWiederbelebung( int sNum, int spielZeit )
- {
- if( !klient )
- return;
- short len = 9;
- char *bytes = new char[ len ];
- *(int*)bytes = spielZeit;
- *(char*)( bytes + 4 ) = 0xF;
- *(int*)( bytes + 5 ) = sNum;
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeTod( int sNum, int killSNum, int spielZeit )
- {
- if( !klient )
- return;
- short len = 13;
- char *bytes = new char[ len ];
- *(int*)bytes = spielZeit;
- *(char*)( bytes + 4 ) = 0x10;
- *(int*)( bytes + 5 ) = sNum;
- *(int*)( bytes + 9 ) = killSNum;
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeSpielEnde( char gewonnen, int spielZeit )
- {
- if( !klient )
- return;
- short len = 6;
- char *bytes = new char[ len ];
- *(int*)bytes = spielZeit;
- *(char*)( bytes + 4 ) = 0xB;
- *(char*)( bytes + 5 ) = gewonnen;
- klient->spielNachricht( len, bytes );
- delete[] bytes;
- }
- void Klient::sendeChatNachricht( char *txt, int spielZeit )
- {
- if( !klient )
- return;
- short len = (short)( 5 + textLength( txt ) );
- char *bytes = new char[ len ];
- *(int*)bytes = spielZeit;
- *(char*)( bytes + 4 ) = 0x8;
- for( int i = 5; i < len; i++ )
- bytes[ i ] = txt[ i - 5 ];
- klient->spielNachricht( len, 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 ) = 3;
- *(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 ) = 4;
- *(int*)( bytes + 1 ) = account;
- klient->statistikNachricht( 5, bytes );
- delete[] bytes;
- }
- void Klient::sendeSpielerStatistik( SpielerStatistik *zS )
- {
- if( !zS || !klient )
- return;
- char snl = (char)zS->zSpielerName()->getLength();
- char tnl = (char)zS->zTeamName()->getLength();
- int len = 55 + snl + tnl;
- char *bytes = new char[ len ];
- bytes[ 0 ] = 0;
- *(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->getSchadenBekommen();
- *(int*)( bytes + 19 + snl + tnl ) = zS->getSchadenGemacht();
- *(int*)( bytes + 23 + snl + tnl ) = zS->getTreibstoffVerbraucht();
- *(int*)( bytes + 27 + snl + tnl ) = zS->getShots();
- *(int*)( bytes + 31 + snl + tnl ) = zS->getTreffer();
- *(int*)( bytes + 35 + snl + tnl ) = zS->getPunkte();
- *(int*)( bytes + 39 + snl + tnl ) = zS->getKills();
- *(int*)( bytes + 43 + snl + tnl ) = zS->getTode();
- *(int*)( bytes + 47 + snl + tnl ) = zS->getZeitAmLeben();
- *(int*)( bytes + 51 + snl + tnl ) = zS->getZeitTod();
- klient->statistikNachricht( (short)len, bytes );
- delete[] bytes;
- }
- void Klient::sendeTeamStatistik( TeamStatistik *zS )
- {
- if( !zS || !klient )
- return;
- char tnl = (char)zS->zTeamName()->getLength();
- int len = 43 + tnl;
- char *bytes = new char[ len ];
- bytes[ 0 ] = 1;
- *(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->getSchadenBekommen();
- *(int*)( bytes + 14 + tnl ) = zS->getSchadenGemacht();
- *(int*)( bytes + 18 + tnl ) = zS->getTreibstoffVerbraucht();
- *(int*)( bytes + 22 + tnl ) = zS->getShots();
- *(int*)( bytes + 26 + tnl ) = zS->getTreffer();
- *(int*)( bytes + 30 + tnl ) = zS->getPunkte();
- *(int*)( bytes + 34 + tnl ) = zS->getKills();
- *(int*)( bytes + 38 + tnl ) = zS->getTode();
- *( bytes + 42 + tnl ) = (char)zS->hatGewonnen();
- klient->statistikNachricht( (short)len, bytes );
- delete[] bytes;
- }
- void Klient::sendeStatistikLadenFertig()
- {
- if( !klient )
- return;
- char byte = 2;
- klient->statistikNachricht( 1, &byte );
- }
- // constant
- bool Klient::istOnline() const
- {
- return klient != 0;
- }
- // reference Counting
- Klient *Klient::getThis()
- {
- ref++;
- return this;
- }
- Klient *Klient::release()
- {
- ref--;
- if( !ref )
- delete this;
- return 0;
- }
|