SpielServer.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #ifndef SpielServer_H
  2. #define SpielServer_H
  3. #include <Server.h>
  4. #include <Thread.h>
  5. #include <Datei.h>
  6. #include <Text.h>
  7. #include "SSKlientV.h"
  8. #include <InitDatei.h>
  9. #ifdef WIN32
  10. #include "SpielErstellt/SpielErstellt.h"
  11. #include "Spiel/Spiel.h"
  12. #include "../Datenbank/Datenbank.h"
  13. #include "Historie/HistorieSender.h"
  14. #else
  15. #include "SpielErstellt.h"
  16. #include "Spiel.h"
  17. #include "Datenbank.h"
  18. #include "HistorieSender.h"
  19. #endif
  20. using namespace Framework;
  21. using namespace Network;
  22. class SSKlient;
  23. class SpielServer : public Thread
  24. {
  25. private:
  26. HistorieSender* historieS;
  27. Server* server;
  28. SSLServer* aServer;
  29. InitDatei* ini;
  30. SSDatenbank* db;
  31. CRITICAL_SECTION cs;
  32. SpielFinden* startSpielThread;
  33. RCArray< SpielErstellt >* erstellt;
  34. RCArray< Spiel >* spiele;
  35. RCArray< SSKlient >* klients;
  36. Array< int >* spielHistorieId;
  37. Text* fehler;
  38. int id;
  39. bool nichtPausiert;
  40. int empfangen;
  41. int gesendet;
  42. bool end;
  43. public:
  44. // Konstruktor
  45. SpielServer(InitDatei* zIni);
  46. // Destruktor
  47. virtual ~SpielServer();
  48. // nicht constant
  49. void lock();
  50. void unlock();
  51. void runn();
  52. virtual void thread();
  53. void close();
  54. bool serverStarten();
  55. bool serverPause();
  56. bool serverFortsetzen();
  57. bool serverBeenden();
  58. bool setMaxSpiele(int ms);
  59. void addSpielErstellt(SpielErstellt* erstellt);
  60. void SpielErstelltAbbruch(int spielErstelltId);
  61. void removeSpielErstellt(int id);
  62. bool registerKlient(SSKlient* klient);
  63. bool absturzKlient(int klientId);
  64. bool verteileKlient(SSKlient* klient);
  65. void unregisterKlient(SSKlient* zKlient);
  66. void klientsMM(SSKlient* k);
  67. void addSpiel(Spiel* spiel);
  68. void removeSpiel(int spielId);
  69. void addGesendet(int bytes);
  70. void addEmpfangen(int bytes);
  71. void addSpielHistorieId(int id);
  72. bool hatSpielHistorieId(int id);
  73. void removeSpielHistorieId(int id);
  74. // conatant
  75. bool istAn() const;
  76. Server* zServer() const;
  77. SSDatenbank* zDB() const;
  78. InitDatei* zInit() const;
  79. bool hatClients() const;
  80. int getId() const;
  81. const char* getLetzterFehler() const;
  82. const char* getIp() const;
  83. int getPort() const;
  84. };
  85. class SSAKlient : public Thread
  86. {
  87. private:
  88. SSLSKlient* klient;
  89. Text* name;
  90. Text* passwort;
  91. int adminId;
  92. SpielServer* ss;
  93. int version;
  94. public:
  95. // Konstruktor
  96. SSAKlient(SSLSKlient* klient, SpielServer* ss);
  97. // Destruktor
  98. virtual ~SSAKlient();
  99. // nicht constant
  100. void thread();
  101. void sendeVerzeichnisAnKlient(const char* pfad, int);
  102. void errorZuKlient(const char* nachricht) const; // sendet eine Fehlernachricht zum AKlient
  103. };
  104. class SSKlient : public SSKlientV
  105. {
  106. private:
  107. SKlient* empfangen;
  108. SKlient* senden;
  109. unsigned int klientNummer;
  110. SpielServer* ss;
  111. int accountId;
  112. bool termThread;
  113. bool verbunden;
  114. SpielErstellt* zErstellt;
  115. Spiel* zSpiel;
  116. CRITICAL_SECTION cs;
  117. public:
  118. // Konstruktor
  119. SSKlient(SKlient* klient, SpielServer* ss);
  120. // Destruktor
  121. virtual ~SSKlient() override;
  122. // nicht constant
  123. void lock();
  124. void unlock();
  125. void absturz();
  126. void setSpielErstellt(SpielErstellt* zErstellt);
  127. void setSpiel(Spiel* zSpiel);
  128. virtual void nichtTrennen() override;
  129. void spielGefunden(int karteId);
  130. void zeitVerbleibend(char sekunden);
  131. void erstellungAbgebrochen(const char* grund);
  132. void backInWarteschlange(char st, char min, char sec);
  133. void erstellungFortsetzen();
  134. void erstellungInitialisierung(SpielerTeamStruktur* sts);
  135. void erstellungAddSpieler(int accountId);
  136. void erstellungRemoveSpieler(int accountId);
  137. void erstellungSpielerTeam(int accountId, int spielerNummer);
  138. void erstellungChatNachricht(const char* nachricht);
  139. void spielLadenBeginn();
  140. void spielLadenSpielerAdd(int accId, int spielerNumer);
  141. void spielLadenSetSpielerProzent(int accId, int prozent);
  142. void spielLadenSetSpielerPing(int accId, int ping);
  143. virtual double ping() override;
  144. void spielLadenFertig();
  145. virtual void spielNachricht(short len, const char* bytes) override;
  146. virtual void statistikNachricht(short len, const char* bytes) override;
  147. bool keepAlive();
  148. virtual void trenne() override;
  149. void setSenden(SSKlient* klient);
  150. virtual void thread() override;
  151. virtual void errorZuKlientEmpfang(const char* nachricht) override; // sendet eine Fehlernachricht zum Klient
  152. virtual void errorZuKlientSende(const char* nachricht) override;
  153. // const
  154. virtual int getAccountId() const override;
  155. int getKlientNummer() const;
  156. SKlient* getKlient() const;
  157. };
  158. #endif