123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- #include "Spieler.h"
- #include "SSKlient.h"
- #include <Text.h>
- // Inhalt der Klient Klasse aus Klient.h
- // Konstruktor
- Klient::Klient(SSKlientV* klient)
- : ReferenceCounter()
- {
- this->klient = klient;
- }
- // Destruktor
- Klient::~Klient()
- {
- if (klient)
- klient->release();
- }
- // nicht constant
- void Klient::offline()
- {
- klient = (SSKlientV*)klient->release();
- }
- void Klient::online(SSKlientV* zKlient)
- {
- if (klient)
- klient = (SSKlientV*)klient->release();
- klient = dynamic_cast<SSKlientV*>(zKlient->getThis());
- }
- void Klient::sendeInit(RCArray< Spieler >* zSpieler, __int64 seed)
- {
- if (!klient)
- return;
- short len = (short)(2 + zSpieler->getEintragAnzahl() * 8 + 8);
- char* bytes = new char[len];
- *(char*)(bytes) = 0x1;
- *(char*)(bytes + 1) = (char)zSpieler->getEintragAnzahl();
- for (int i = 0; i < zSpieler->getEintragAnzahl(); i++)
- {
- *(int*)(bytes + 2 + i * 8) = zSpieler->z(i)->getId();
- *(int*)(bytes + 6 + i * 8) = zSpieler->z(i)->getAccountId();
- }
- *(__int64*)(bytes + 2 + zSpieler->getEintragAnzahl() * 8) = seed;
- klient->spielNachricht(len, bytes);
- delete[] bytes;
- }
- void Klient::sendeSpielerNummer(int sNum)
- {
- if (!klient)
- return;
- short len = 5;
- char* bytes = new char[len];
- *(char*)(bytes) = 0x2;
- *(int*)(bytes + 1) = sNum;
- klient->spielNachricht(len, bytes);
- delete[] bytes;
- }
- void Klient::sendeStart()
- {
- if (!klient)
- return;
- char b = 0x3;
- klient->spielNachricht(1, &b);
- }
- void Klient::sendeTastaturStatus(int spielerId, char taste, bool aktiv)
- {
- if (!klient)
- return;
- short len = 7;
- char* bytes = new char[len];
- *(char*)(bytes) = 0x4;
- *(char*)(bytes + 1) = taste;
- *(char*)(bytes + 2) = (char)aktiv;
- *(int*)(bytes + 3) = spielerId;
- klient->spielNachricht(len, bytes);
- delete[] bytes;
- }
- void Klient::sendeSpielEnde(char gewonnen)
- {
- if (!klient)
- return;
- short len = 2;
- char* bytes = new char[len];
- *(char*)(bytes) = 0x5;
- *(char*)(bytes + 1) = gewonnen;
- klient->spielNachricht(len, bytes);
- delete[] bytes;
- }
- void Klient::sendeTick()
- {
- if (!klient)
- return;
- char b = 0x6;
- klient->spielNachricht(1, &b);
- }
- void Klient::sendeChatNachricht(const char* txt)
- {
- if (!klient)
- return;
- short len = (short)(1 + textLength(txt));
- char* bytes = new char[len];
- *(char*)(bytes) = 0x7;
- for (int i = 1; i < len; i++)
- bytes[i] = txt[i - 1];
- klient->spielNachricht(len, bytes);
- delete[] bytes;
- }
- void Klient::sendeStatistikChatNachricht(int vonAccount, const 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(Spieler* zS)
- {
- if (!zS || !klient)
- return;
- char snl = (char)textLength(zS->getName());
- char tnl = (char)zS->zTeam()->getName().getLength();
- int len = 55 + snl + tnl;
- char* bytes = new char[len];
- bytes[0] = 0;
- *(int*)(bytes + 1) = zS->getId();
- *(char*)(bytes + 5) = snl;
- for (int i = 0; i < snl; i++)
- bytes[i + 6] = zS->getName()[i];
- *(char*)(bytes + 6 + snl) = tnl;
- for (int i = 0; i < tnl; i++)
- bytes[i + 7 + snl] = zS->zTeam()->getName()[i];
- *(int*)(bytes + 7 + snl + tnl) = zS->getFarbe();
- *(int*)(bytes + 11 + snl + tnl) = zS->zTeam()->getFarbe();
- *(int*)(bytes + 15 + snl + tnl) = (int)zS->getErlittenerSchaden();
- *(int*)(bytes + 19 + snl + tnl) = (int)zS->getGemachterSchaden();
- *(int*)(bytes + 23 + snl + tnl) = (int)zS->getGeheiltesLeben();
- *(int*)(bytes + 27 + snl + tnl) = zS->getGeschossen();
- *(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->getItemsAufgehoben();
- *(int*)(bytes + 51 + snl + tnl) = zS->getItemsVerwendet();
- klient->statistikNachricht((short)len, bytes);
- delete[] bytes;
- }
- void Klient::sendeTeamStatistik(Team* zS)
- {
- if (!zS || !klient)
- return;
- char tnl = (char)zS->getName().getLength();
- int len = 22 + 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->getName()[i];
- *(int*)(bytes + 6 + tnl) = zS->getFarbe();
- *(int*)(bytes + 10 + tnl) = zS->getPunkte();
- *(int*)(bytes + 14 + tnl) = zS->getKills();
- *(int*)(bytes + 18 + tnl) = zS->getTode();
- 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;
- }
|