NetPacksBase.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. VCMI_LIB_NAMESPACE_BEGIN
  13. class CGameState;
  14. class CConnection;
  15. class ICPackVisitor;
  16. struct DLL_LINKAGE CPack
  17. {
  18. std::shared_ptr<CConnection> c; // Pointer to connection that pack received from
  19. CPack() = default;
  20. virtual ~CPack() = default;
  21. template <typename Handler> void serialize(Handler &h, const int version)
  22. {
  23. logNetwork->error("CPack serialized... this should not happen!");
  24. assert(false && "CPack serialized");
  25. }
  26. void applyGs(CGameState * gs)
  27. {}
  28. void visit(ICPackVisitor & cpackVisitor);
  29. protected:
  30. /// <summary>
  31. /// For basic types of netpacks hierarchy like CPackForClient. Called first.
  32. /// </summary>
  33. virtual void visitBasic(ICPackVisitor & cpackVisitor);
  34. /// <summary>
  35. /// For leaf types of netpacks hierarchy. Called after visitBasic.
  36. /// </summary>
  37. virtual void visitTyped(ICPackVisitor & cpackVisitor);
  38. };
  39. struct DLL_LINKAGE CPackForClient : public CPack
  40. {
  41. protected:
  42. void visitBasic(ICPackVisitor & cpackVisitor) override;
  43. };
  44. struct DLL_LINKAGE Query : public CPackForClient
  45. {
  46. QueryID queryID; // equals to -1 if it is not an actual query (and should not be answered)
  47. };
  48. struct DLL_LINKAGE CPackForServer : public CPack
  49. {
  50. mutable PlayerColor player = PlayerColor::NEUTRAL;
  51. mutable si32 requestID;
  52. template <typename Handler> void serialize(Handler &h, const int version)
  53. {
  54. h & player;
  55. h & requestID;
  56. }
  57. protected:
  58. void visitBasic(ICPackVisitor & cpackVisitor) override;
  59. };
  60. struct DLL_LINKAGE CPackForLobby : public CPack
  61. {
  62. virtual bool isForServer() const;
  63. protected:
  64. void visitBasic(ICPackVisitor & cpackVisitor) override;
  65. };
  66. VCMI_LIB_NAMESPACE_END