NetPacksBase.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 CConnection;
  16. class ICPackVisitor;
  17. struct DLL_LINKAGE CPack : public Serializeable
  18. {
  19. CPack() = default;
  20. virtual ~CPack() = default;
  21. template <typename Handler> void serialize(Handler &h)
  22. {
  23. logNetwork->error("CPack serialized... this should not happen!");
  24. throw std::runtime_error("CPack serialized... this should not happen!");
  25. }
  26. void visit(ICPackVisitor & cpackVisitor);
  27. protected:
  28. /// For basic types of netpacks hierarchy like CPackForClient. Called first.
  29. virtual void visitBasic(ICPackVisitor & cpackVisitor);
  30. /// For leaf types of netpacks hierarchy. Called after visitBasic.
  31. virtual void visitTyped(ICPackVisitor & cpackVisitor);
  32. };
  33. struct DLL_LINKAGE CPackForClient : public CPack
  34. {
  35. protected:
  36. void visitBasic(ICPackVisitor & cpackVisitor) override;
  37. };
  38. struct DLL_LINKAGE Query : public CPackForClient
  39. {
  40. QueryID queryID; // equals to -1 if it is not an actual query (and should not be answered)
  41. };
  42. struct PackForClientBattle : public CPackForClient
  43. {
  44. BattleID battleID;
  45. void visitTyped(ICPackVisitor & visitor) override;
  46. };
  47. struct DLL_LINKAGE CPackForServer : public CPack
  48. {
  49. mutable PlayerColor player = PlayerColor::NEUTRAL;
  50. mutable uint32_t requestID = 0;
  51. template <typename Handler> void serialize(Handler &h)
  52. {
  53. h & player;
  54. h & requestID;
  55. }
  56. protected:
  57. void visitBasic(ICPackVisitor & cpackVisitor) override;
  58. };
  59. struct DLL_LINKAGE CPackForLobby : public CPack
  60. {
  61. virtual bool isForServer() const;
  62. protected:
  63. void visitBasic(ICPackVisitor & cpackVisitor) override;
  64. };
  65. VCMI_LIB_NAMESPACE_END