NetPacksBase.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. /// <summary>
  29. /// For basic types of netpacks hierarchy like CPackForClient. Called first.
  30. /// </summary>
  31. virtual void visitBasic(ICPackVisitor & cpackVisitor);
  32. /// <summary>
  33. /// For leaf types of netpacks hierarchy. Called after visitBasic.
  34. /// </summary>
  35. virtual void visitTyped(ICPackVisitor & cpackVisitor);
  36. };
  37. struct DLL_LINKAGE CPackForClient : public CPack
  38. {
  39. virtual void applyGs(CGameState * gs) = 0;
  40. protected:
  41. void visitBasic(ICPackVisitor & cpackVisitor) override;
  42. };
  43. struct DLL_LINKAGE Query : public CPackForClient
  44. {
  45. QueryID queryID; // equals to -1 if it is not an actual query (and should not be answered)
  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