Klient.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #include "Spieler.h"
  2. #include "SSKlient.h"
  3. #include <Text.h>
  4. // Inhalt der Klient Klasse aus Klient.h
  5. // Konstruktor
  6. Klient::Klient(SSKlientV* klient)
  7. : ReferenceCounter()
  8. {
  9. this->klient = klient;
  10. }
  11. // Destruktor
  12. Klient::~Klient()
  13. {
  14. if (klient)
  15. klient->release();
  16. }
  17. // nicht constant
  18. void Klient::offline()
  19. {
  20. klient = (SSKlientV*)klient->release();
  21. }
  22. void Klient::online(SSKlientV* zKlient)
  23. {
  24. if (klient)
  25. klient = (SSKlientV*)klient->release();
  26. klient = dynamic_cast<SSKlientV*>(zKlient->getThis());
  27. }
  28. void Klient::sendeInit(RCArray< Spieler >* zSpieler, __int64 seed)
  29. {
  30. if (!klient)
  31. return;
  32. short len = (short)(2 + zSpieler->getEintragAnzahl() * 8 + 8);
  33. char* bytes = new char[len];
  34. *(char*)(bytes) = 0x1;
  35. *(char*)(bytes + 1) = (char)zSpieler->getEintragAnzahl();
  36. for (int i = 0; i < zSpieler->getEintragAnzahl(); i++)
  37. {
  38. *(int*)(bytes + 2 + i * 8) = zSpieler->z(i)->getId();
  39. *(int*)(bytes + 6 + i * 8) = zSpieler->z(i)->getAccountId();
  40. }
  41. *(__int64*)(bytes + 2 + zSpieler->getEintragAnzahl() * 8) = seed;
  42. klient->spielNachricht(len, bytes);
  43. delete[] bytes;
  44. }
  45. void Klient::sendeSpielerNummer(int sNum)
  46. {
  47. if (!klient)
  48. return;
  49. short len = 5;
  50. char* bytes = new char[len];
  51. *(char*)(bytes) = 0x2;
  52. *(int*)(bytes + 1) = sNum;
  53. klient->spielNachricht(len, bytes);
  54. delete[] bytes;
  55. }
  56. void Klient::sendeStart()
  57. {
  58. if (!klient)
  59. return;
  60. char b = 0x3;
  61. klient->spielNachricht(1, &b);
  62. }
  63. void Klient::sendeTastaturStatus(int spielerId, char taste, bool aktiv)
  64. {
  65. if (!klient)
  66. return;
  67. short len = 7;
  68. char* bytes = new char[len];
  69. *(char*)(bytes) = 0x4;
  70. *(char*)(bytes + 1) = taste;
  71. *(char*)(bytes + 2) = (char)aktiv;
  72. *(int*)(bytes + 3) = spielerId;
  73. klient->spielNachricht(len, bytes);
  74. delete[] bytes;
  75. }
  76. void Klient::sendeSpielEnde(char gewonnen)
  77. {
  78. if (!klient)
  79. return;
  80. short len = 2;
  81. char* bytes = new char[len];
  82. *(char*)(bytes) = 0x5;
  83. *(char*)(bytes + 1) = gewonnen;
  84. klient->spielNachricht(len, bytes);
  85. delete[] bytes;
  86. }
  87. void Klient::sendeTick()
  88. {
  89. if (!klient)
  90. return;
  91. char b = 0x6;
  92. klient->spielNachricht(1, &b);
  93. }
  94. void Klient::sendeChatNachricht(const char* txt)
  95. {
  96. if (!klient)
  97. return;
  98. short len = (short)(1 + textLength(txt));
  99. char* bytes = new char[len];
  100. *(char*)(bytes) = 0x7;
  101. for (int i = 1; i < len; i++)
  102. bytes[i] = txt[i - 1];
  103. klient->spielNachricht(len, bytes);
  104. delete[] bytes;
  105. }
  106. void Klient::sendeStatistikChatNachricht(int vonAccount, const char* txt)
  107. {
  108. if (!klient)
  109. return;
  110. short len = (short)(5 + textLength(txt));
  111. char* bytes = new char[len];
  112. *(char*)(bytes) = 3;
  113. *(int*)(bytes + 1) = vonAccount;
  114. for (int i = 5; i < len; i++)
  115. bytes[i] = txt[i - 5];
  116. klient->statistikNachricht(len, bytes);
  117. delete[] bytes;
  118. }
  119. void Klient::sendeStatistikSpielerOffline(int account)
  120. {
  121. if (!klient)
  122. return;
  123. char* bytes = new char[5];
  124. *(char*)(bytes) = 4;
  125. *(int*)(bytes + 1) = account;
  126. klient->statistikNachricht(5, bytes);
  127. delete[] bytes;
  128. }
  129. void Klient::sendeSpielerStatistik(Spieler* zS)
  130. {
  131. if (!zS || !klient)
  132. return;
  133. char snl = (char)textLength(zS->getName());
  134. char tnl = (char)zS->zTeam()->getName().getLength();
  135. int len = 55 + snl + tnl;
  136. char* bytes = new char[len];
  137. bytes[0] = 0;
  138. *(int*)(bytes + 1) = zS->getId();
  139. *(char*)(bytes + 5) = snl;
  140. for (int i = 0; i < snl; i++)
  141. bytes[i + 6] = zS->getName()[i];
  142. *(char*)(bytes + 6 + snl) = tnl;
  143. for (int i = 0; i < tnl; i++)
  144. bytes[i + 7 + snl] = zS->zTeam()->getName()[i];
  145. *(int*)(bytes + 7 + snl + tnl) = zS->getFarbe();
  146. *(int*)(bytes + 11 + snl + tnl) = zS->zTeam()->getFarbe();
  147. *(int*)(bytes + 15 + snl + tnl) = (int)zS->getErlittenerSchaden();
  148. *(int*)(bytes + 19 + snl + tnl) = (int)zS->getGemachterSchaden();
  149. *(int*)(bytes + 23 + snl + tnl) = (int)zS->getGeheiltesLeben();
  150. *(int*)(bytes + 27 + snl + tnl) = zS->getGeschossen();
  151. *(int*)(bytes + 31 + snl + tnl) = zS->getTreffer();
  152. *(int*)(bytes + 35 + snl + tnl) = zS->getPunkte();
  153. *(int*)(bytes + 39 + snl + tnl) = zS->getKills();
  154. *(int*)(bytes + 43 + snl + tnl) = zS->getTode();
  155. *(int*)(bytes + 47 + snl + tnl) = zS->getItemsAufgehoben();
  156. *(int*)(bytes + 51 + snl + tnl) = zS->getItemsVerwendet();
  157. klient->statistikNachricht((short)len, bytes);
  158. delete[] bytes;
  159. }
  160. void Klient::sendeTeamStatistik(Team* zS)
  161. {
  162. if (!zS || !klient)
  163. return;
  164. char tnl = (char)zS->getName().getLength();
  165. int len = 22 + tnl;
  166. char* bytes = new char[len];
  167. bytes[0] = 1;
  168. *(int*)(bytes + 1) = zS->getTeamNummer();
  169. *(char*)(bytes + 5) = tnl;
  170. for (int i = 0; i < tnl; i++)
  171. bytes[i + 6] = zS->getName()[i];
  172. *(int*)(bytes + 6 + tnl) = zS->getFarbe();
  173. *(int*)(bytes + 10 + tnl) = zS->getPunkte();
  174. *(int*)(bytes + 14 + tnl) = zS->getKills();
  175. *(int*)(bytes + 18 + tnl) = zS->getTode();
  176. klient->statistikNachricht((short)len, bytes);
  177. delete[] bytes;
  178. }
  179. void Klient::sendeStatistikLadenFertig()
  180. {
  181. if (!klient)
  182. return;
  183. char byte = 2;
  184. klient->statistikNachricht(1, &byte);
  185. }
  186. // constant
  187. bool Klient::istOnline() const
  188. {
  189. return klient != 0;
  190. }