ChatServer.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #ifndef ChatServer_H
  2. #define ChatServer_H
  3. #include <Server.h>
  4. #include <Thread.h>
  5. #include <Datei.h>
  6. #include <Text.h>
  7. #include <InitDatei.h>
  8. #include "Datenbank.h"
  9. #include <Klient.h>
  10. using namespace Framework;
  11. using namespace Network;
  12. class CSKlient;
  13. class KlientArray;
  14. class ChatServer : public Thread
  15. {
  16. private:
  17. Server *server;
  18. Server *aServer;
  19. InitDatei *ini;
  20. CSDatenbank *db;
  21. CRITICAL_SECTION cs;
  22. RCArray< CSKlient > *klients;
  23. Text *fehler;
  24. int klientAnzahl;
  25. int id;
  26. bool nichtPausiert;
  27. int empfangen;
  28. int gesendet;
  29. bool end;
  30. int ref;
  31. public:
  32. // Konstruktor
  33. ChatServer( InitDatei *zIni );
  34. // Destruktor
  35. virtual ~ChatServer();
  36. // nicht constant
  37. void runn();
  38. void thread();
  39. void close();
  40. bool serverStarten();
  41. bool serverPause();
  42. bool serverFortsetzen();
  43. bool serverBeenden();
  44. bool setMaxKlients( int mc );
  45. bool absturzKlient( int klientId );
  46. bool removeAccount( int accId );
  47. bool removeKlient( int klientId );
  48. bool removeKlient( CSKlient *zKlient );
  49. void addGesendet( int bytes );
  50. void addEmpfangen( int bytes );
  51. int getKlientStatus( int klientNummer, CSKlient *zKlient );
  52. CSKlient *zSendeKlient( int accountId );
  53. // conatant
  54. bool istAn() const;
  55. Server *zServer() const;
  56. CSDatenbank *zDB() const;
  57. bool hatClients() const;
  58. int getId() const;
  59. char *getLetzterFehler() const;
  60. // Reference Counting
  61. ChatServer *getThis();
  62. ChatServer *release();
  63. };
  64. class CSAKlient : public Thread
  65. {
  66. private:
  67. SKlient *klient;
  68. Text *name;
  69. Text *passwort;
  70. int adminId;
  71. ChatServer *cs;
  72. public:
  73. // Konstruktor
  74. CSAKlient( SKlient *klient, ChatServer *cs );
  75. // Destruktor
  76. virtual ~CSAKlient();
  77. // nicht constant
  78. void thread();
  79. void errorZuKlient( const char *nachricht ) const; // sendet eine Fehlernachricht zum AKlient
  80. };
  81. class CSKlient : public Thread
  82. {
  83. private:
  84. SKlient *klient;
  85. unsigned int klientNummer;
  86. unsigned int accountId;
  87. ChatServer *cs;
  88. CRITICAL_SECTION ts;
  89. bool empfangen;
  90. int ref;
  91. public:
  92. // Konstruktor
  93. CSKlient( SKlient *klient, ChatServer *cs );
  94. // Destruktor
  95. virtual ~CSKlient();
  96. // nicht constant
  97. void lock();
  98. void unlock();
  99. void absturz();
  100. void thread();
  101. bool kick();
  102. bool nachricht( int vonAccount, const char *txt );
  103. bool gruppeEinladung( int vonAccount, int gruppeId );
  104. bool accountStatusChange( int account, const char *status );
  105. bool accountNameChange( int account, const char *name );
  106. bool keinFreundMehr( int account );
  107. bool freundesAnfrage( int vonAccount );
  108. bool neuerFreund( int account );
  109. bool freundesAnfrageAbgelehnt( int account );
  110. bool einladungZumChatroom( int vonAccount, int chatroomId );
  111. bool einladungZumChatroomAbgelehnt( int account, int chatroomId );
  112. bool spielerBetrittChatroom( int chatroomId, int account );
  113. bool chatroomNachricht( int chatroomId, int vonAccount, const char *nachricht );
  114. bool spielerLeavesChatroom( int chatroomId, int accountId );
  115. bool freunde( char anzahl, Array< int > *zAccountId );
  116. bool spielerImChatroom( int chatroomId, char anzahl, Array< int > *zAccountId );
  117. bool freundOnline( int accountId );
  118. bool freundOffline( int accountId );
  119. bool chatroomAdmin( int chatroomId );
  120. bool chatroomKick( int chatroomId );
  121. bool spielerBertittGruppe( int accountId, int gruppeId );
  122. bool spielerLeavesGruppe( int accountId, int gruppeId );
  123. bool gruppeNachricht( int gruppeId, char *nachricht );
  124. bool gruppeAnmelden( int gruppeId );
  125. bool gruppeAbmelden( int gruppeID );
  126. bool gruppeSpielStarten( int gruppeId, bool starten );
  127. bool setGruppeAdmin( int gruppeId, int adminId );
  128. bool kickAusGruppe( int gruppeId );
  129. bool gruppeEinladungAbgelehnt( int gruppeId, int accountId );
  130. bool spielServerVerbindungsAnfrage( unsigned short port, unsigned char *ip );
  131. bool gruppeEinladungAbgebrochen( int gruppeId, int accountId );
  132. bool gruppeEinladungNeu( int gruppeId, int accountId );
  133. bool errorZuKlient( const char *nachricht ); // sendet eine Fehlernachricht zum Klient
  134. bool keepAlive(); // erhält die Verbindung aufrecht
  135. void trenne();
  136. // constant
  137. int getKlientNummer() const;
  138. int getAccountId() const;
  139. bool istEmpfang() const;
  140. // Reference Counting
  141. CSKlient *getThis();
  142. CSKlient *release();
  143. };
  144. class MSGWeiterleitung
  145. {
  146. private:
  147. ChatServer *cs;
  148. Klient *klient;
  149. Text *letzterFehler;
  150. public:
  151. // Konstruktor
  152. MSGWeiterleitung( ChatServer *cs );
  153. // Destruktor
  154. ~MSGWeiterleitung();
  155. // nicht constant
  156. bool kickKlient( int accountId );
  157. bool accountOnline( int accountId );
  158. bool accountOffline( int accountId );
  159. bool chatNachricht( int vonAccount, int zuAccount, const char *nachricht );
  160. bool accountStatusChange( int accountId, const char *status );
  161. bool accountNameChange( int accountId, const char *name );
  162. bool accountKeinFreundMehr( int accountId, int zielAccountId );
  163. bool freundesAnfrage( int vonAccountId, int zuAccountId );
  164. bool neuerFreund( int accountId, int zuAccountId );
  165. bool einladungZumChatroom( int vonAccountId, int zuAccountId, int chatroomId );
  166. bool spielerBetrittChatroom( int accountId, int chatroomId );
  167. bool chatroomNachricht( int vonAccount, const char *nachricht, int chatroomId );
  168. bool spielerLeavestChatroom( int accountId, int chatroomId );
  169. bool freundEinladungAbgelehnt( int accountId, int zuAccountId );
  170. bool chatroomEinladungAbgelehnt( int accountId, int chatroomId, int zuAccountId );
  171. bool chatroomAdmin( int chatroomId, int zuAccountId );
  172. bool chatroomKick( int chatroomId, int accountId );
  173. bool fehler( int zuAccountId, const char *fehler );
  174. // constant
  175. const char *getLetzterFehler();
  176. };
  177. #endif