NetPacksBase.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * NetPacksBase.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../constants/EntityIdentifiers.h"
  12. #include "../serializer/Serializeable.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class CGameState;
  15. class ICPackVisitor;
  16. struct DLL_LINKAGE CPack : public Serializeable
  17. {
  18. CPack() = default;
  19. virtual ~CPack() = default;
  20. template <typename Handler> void serialize(Handler &h)
  21. {
  22. logNetwork->error("CPack serialized... this should not happen!");
  23. throw std::runtime_error("CPack serialized... this should not happen!");
  24. }
  25. void visit(ICPackVisitor & cpackVisitor);
  26. protected:
  27. /// For basic types of netpacks hierarchy like CPackForClient. Called first.
  28. virtual void visitBasic(ICPackVisitor & cpackVisitor);
  29. /// For leaf types of netpacks hierarchy. Called after visitBasic.
  30. virtual void visitTyped(ICPackVisitor & cpackVisitor);
  31. };
  32. struct DLL_LINKAGE CPackForClient : public CPack
  33. {
  34. protected:
  35. void visitBasic(ICPackVisitor & cpackVisitor) override;
  36. };
  37. struct DLL_LINKAGE Query : public CPackForClient
  38. {
  39. QueryID queryID; // equals to -1 if it is not an actual query (and should not be answered)
  40. };
  41. struct PackForClientBattle : public CPackForClient
  42. {
  43. BattleID battleID;
  44. void visitTyped(ICPackVisitor & visitor) override;
  45. };
  46. struct DLL_LINKAGE CPackForServer : public CPack
  47. {
  48. mutable PlayerColor player = PlayerColor::NEUTRAL;
  49. mutable uint32_t requestID = 0;
  50. template <typename Handler> void serialize(Handler &h)
  51. {
  52. h & player;
  53. h & requestID;
  54. }
  55. protected:
  56. void visitBasic(ICPackVisitor & cpackVisitor) override;
  57. };
  58. struct DLL_LINKAGE CPackForLobby : public CPack
  59. {
  60. virtual bool isForServer() const;
  61. protected:
  62. void visitBasic(ICPackVisitor & cpackVisitor) override;
  63. };
  64. VCMI_LIB_NAMESPACE_END