Client.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #include "../global.h"
  3. #include <boost/thread.hpp>
  4. struct StartInfo;
  5. class CGameState;
  6. class CGameInterface;
  7. class CConnection;
  8. class CCallback;
  9. class CClient;
  10. void processCommand(const std::string &message, CClient *&client);
  11. namespace boost
  12. {
  13. class mutex;
  14. class condition_variable;
  15. }
  16. template <typename T>
  17. struct CSharedCond
  18. {
  19. boost::mutex *mx;
  20. boost::condition_variable *cv;
  21. T *res;
  22. CSharedCond(T*R)
  23. {
  24. res = R;
  25. mx = new boost::mutex;
  26. cv = new boost::condition_variable;
  27. }
  28. ~CSharedCond()
  29. {
  30. delete res;
  31. delete mx;
  32. delete cv;
  33. }
  34. };
  35. class CClient
  36. {
  37. CCallback *cb;
  38. CGameState *gs;
  39. std::map<ui8,CGameInterface *> playerint;
  40. CConnection *serv;
  41. void waitForMoveAndSend(int color);
  42. public:
  43. CClient(void);
  44. CClient(CConnection *con, StartInfo *si);
  45. ~CClient(void);
  46. void close();
  47. void save(const std::string & fname);
  48. void process(int what);
  49. void run();
  50. friend class CCallback; //handling players actions
  51. friend class CScriptCallback; //for objects scripts
  52. friend void processCommand(const std::string &message, CClient *&client); //handling console
  53. };