ChatServer.h 5.2 KB

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