CGameHandler.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #include "../global.h"
  3. #include <set>
  4. #include "../CGameState.h"
  5. #include "../lib/Connection.h"
  6. class CVCMIServer;
  7. class CGameState;
  8. //class CConnection;
  9. struct StartInfo;
  10. class CCPPObjectScript;
  11. class CScriptCallback;
  12. template <typename T> struct CPack;
  13. class CGameHandler
  14. {
  15. CGameState *gs;
  16. std::set<CCPPObjectScript *> cppscripts; //C++ scripts
  17. //std::map<int, std::map<std::string, CObjectScript*> > objscr; //non-C++ scripts
  18. CVCMIServer *s;
  19. std::map<int,CConnection*> connections;
  20. std::set<CConnection*> conns;
  21. void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * script);
  22. public:
  23. CGameHandler(void);
  24. ~CGameHandler(void);
  25. void init(StartInfo *si, int Seed);
  26. void handleConnection(std::set<int> players, CConnection &c);
  27. template <typename T>void sendToAllClients(CPack<T> * info)
  28. {
  29. for(std::set<CConnection*>::iterator i=conns.begin(); i!=conns.end();i++)
  30. {
  31. (*i)->rmx->lock();
  32. **i << info->getType() << *info->This();
  33. (*i)->rmx->unlock();
  34. }
  35. }
  36. template <typename T>void sendAndApply(CPack<T> * info)
  37. {
  38. gs->apply(info);
  39. sendToAllClients(info);
  40. }
  41. void run();
  42. void newTurn();
  43. friend class CVCMIServer;
  44. friend class CScriptCallback;
  45. };