Server.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #pragma once
  2. #include <InitFile.h>
  3. #ifdef _WINDOWS
  4. # include <Network\Server.h>
  5. #else
  6. # include <Server.h>
  7. #endif
  8. #include <Critical.h>
  9. #include <Text.h>
  10. #include <Thread.h>
  11. using namespace Framework;
  12. using namespace Network;
  13. class FCKlient;
  14. class GameClient;
  15. class FactoryCraftServer : virtual public ReferenceCounter
  16. {
  17. public:
  18. static FactoryCraftServer* INSTANCE;
  19. private:
  20. SSLServer* sslServer;
  21. Server* server;
  22. InitFile* ini;
  23. Critical cs;
  24. RCArray<FCKlient>* klients;
  25. int runningThreads;
  26. int id;
  27. public:
  28. // Konstruktor
  29. FactoryCraftServer(InitFile* zIni);
  30. // Destruktor
  31. virtual ~FactoryCraftServer();
  32. // nicht constant
  33. void run();
  34. void close();
  35. bool removeKlient(FCKlient* zKlient);
  36. bool hatClients() const;
  37. int getUnencryptedPort() const;
  38. };
  39. class FCKlient : public Thread
  40. {
  41. private:
  42. Network::SSLSClient* klient;
  43. Network::SClient* background;
  44. Network::SClient* foreground;
  45. FactoryCraftServer* ls;
  46. GameClient* zGameClient;
  47. NetworkReader* backgroundReader;
  48. NetworkReader* foregroundReader;
  49. NetworkWriter* backgroundWriter;
  50. NetworkWriter* foregroundWriter;
  51. Critical cs;
  52. bool backgroundRunning;
  53. bool foregroundRunning;
  54. Framework::Text authKey;
  55. Framework::Text name;
  56. public:
  57. // Konstruktor
  58. FCKlient(Network::SSLSClient* klient, FactoryCraftServer* ls);
  59. // Destruktor
  60. virtual ~FCKlient();
  61. private:
  62. void onInitialized();
  63. void checkResources(const char* path, RCArray<Text>& filesToTransfer);
  64. public:
  65. void setForegroundClient(Network::SClient* foreground);
  66. void setBackgroundClient(Network::SClient* background);
  67. // nicht constant
  68. void absturz();
  69. void thread();
  70. // constant
  71. NetworkWriter* zBackgroundWriter() const;
  72. NetworkWriter* zForegroundWriter() const;
  73. bool matchAuthKey(char* key, int len) const;
  74. };