2
0

NetPacksBase.h 1.9 KB

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