NetPacksLobby.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /*
  2. * NetPacksLobby.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 "NetPacksBase.h"
  12. #include "StartInfo.h"
  13. class CServerHandler;
  14. class CVCMIServer;
  15. VCMI_LIB_NAMESPACE_BEGIN
  16. class CCampaignState;
  17. class CMapInfo;
  18. struct StartInfo;
  19. class CMapGenOptions;
  20. struct ClientPlayer;
  21. struct DLL_LINKAGE CLobbyPackToPropagate : public CPackForLobby
  22. {
  23. };
  24. struct DLL_LINKAGE CLobbyPackToServer : public CPackForLobby
  25. {
  26. virtual bool isForServer() const override;
  27. };
  28. struct DLL_LINKAGE LobbyClientConnected : public CLobbyPackToPropagate
  29. {
  30. // Set by client before sending pack to server
  31. std::string uuid;
  32. std::vector<std::string> names;
  33. StartInfo::EMode mode = StartInfo::INVALID;
  34. // Changed by server before announcing pack
  35. int clientId = -1;
  36. int hostClientId = -1;
  37. virtual void visitTyped(ICPackVisitor & visitor) override;
  38. template <typename Handler> void serialize(Handler & h, const int version)
  39. {
  40. h & uuid;
  41. h & names;
  42. h & mode;
  43. h & clientId;
  44. h & hostClientId;
  45. }
  46. };
  47. struct DLL_LINKAGE LobbyClientDisconnected : public CLobbyPackToPropagate
  48. {
  49. int clientId;
  50. bool shutdownServer = false;
  51. virtual void visitTyped(ICPackVisitor & visitor) override;
  52. template <typename Handler> void serialize(Handler &h, const int version)
  53. {
  54. h & clientId;
  55. h & shutdownServer;
  56. }
  57. };
  58. struct DLL_LINKAGE LobbyChatMessage : public CLobbyPackToPropagate
  59. {
  60. std::string playerName, message;
  61. virtual void visitTyped(ICPackVisitor & visitor) override;
  62. template <typename Handler> void serialize(Handler &h, const int version)
  63. {
  64. h & playerName;
  65. h & message;
  66. }
  67. };
  68. struct DLL_LINKAGE LobbyGuiAction : public CLobbyPackToPropagate
  69. {
  70. enum EAction : ui8 {
  71. NONE, NO_TAB, OPEN_OPTIONS, OPEN_SCENARIO_LIST, OPEN_RANDOM_MAP_OPTIONS
  72. } action = NONE;
  73. virtual void visitTyped(ICPackVisitor & visitor) override;
  74. template <typename Handler> void serialize(Handler &h, const int version)
  75. {
  76. h & action;
  77. }
  78. };
  79. struct DLL_LINKAGE LobbyEndGame : public CLobbyPackToPropagate
  80. {
  81. bool closeConnection = false, restart = false;
  82. virtual void visitTyped(ICPackVisitor & visitor) override;
  83. template <typename Handler> void serialize(Handler &h, const int version)
  84. {
  85. h & closeConnection;
  86. h & restart;
  87. }
  88. };
  89. struct DLL_LINKAGE LobbyStartGame : public CLobbyPackToPropagate
  90. {
  91. // Set by server
  92. std::shared_ptr<StartInfo> initializedStartInfo = nullptr;
  93. CGameState * initializedGameState = nullptr;
  94. int clientId = -1; //-1 means to all clients
  95. virtual void visitTyped(ICPackVisitor & visitor) override;
  96. template <typename Handler> void serialize(Handler &h, const int version)
  97. {
  98. h & clientId;
  99. h & initializedStartInfo;
  100. bool sps = h.smartPointerSerialization;
  101. h.smartPointerSerialization = true;
  102. h & initializedGameState;
  103. h.smartPointerSerialization = sps;
  104. }
  105. };
  106. struct DLL_LINKAGE LobbyChangeHost : public CLobbyPackToPropagate
  107. {
  108. int newHostConnectionId = -1;
  109. virtual void visitTyped(ICPackVisitor & visitor) override;
  110. template <typename Handler> void serialize(Handler & h, const int version)
  111. {
  112. h & newHostConnectionId;
  113. }
  114. };
  115. struct DLL_LINKAGE LobbyUpdateState : public CLobbyPackToPropagate
  116. {
  117. LobbyState state;
  118. bool hostChanged = false; // Used on client-side only
  119. virtual void visitTyped(ICPackVisitor & visitor) override;
  120. template <typename Handler> void serialize(Handler &h, const int version)
  121. {
  122. h & state;
  123. }
  124. };
  125. struct DLL_LINKAGE LobbySetMap : public CLobbyPackToServer
  126. {
  127. std::shared_ptr<CMapInfo> mapInfo;
  128. std::shared_ptr<CMapGenOptions> mapGenOpts;
  129. LobbySetMap() : mapInfo(nullptr), mapGenOpts(nullptr) {}
  130. virtual void visitTyped(ICPackVisitor & visitor) override;
  131. template <typename Handler> void serialize(Handler &h, const int version)
  132. {
  133. h & mapInfo;
  134. h & mapGenOpts;
  135. }
  136. };
  137. struct DLL_LINKAGE LobbySetCampaign : public CLobbyPackToServer
  138. {
  139. std::shared_ptr<CCampaignState> ourCampaign;
  140. virtual void visitTyped(ICPackVisitor & visitor) override;
  141. template <typename Handler> void serialize(Handler &h, const int version)
  142. {
  143. h & ourCampaign;
  144. }
  145. };
  146. struct DLL_LINKAGE LobbySetCampaignMap : public CLobbyPackToServer
  147. {
  148. int mapId = -1;
  149. virtual void visitTyped(ICPackVisitor & visitor) override;
  150. template <typename Handler> void serialize(Handler &h, const int version)
  151. {
  152. h & mapId;
  153. }
  154. };
  155. struct DLL_LINKAGE LobbySetCampaignBonus : public CLobbyPackToServer
  156. {
  157. int bonusId = -1;
  158. virtual void visitTyped(ICPackVisitor & visitor) override;
  159. template <typename Handler> void serialize(Handler &h, const int version)
  160. {
  161. h & bonusId;
  162. }
  163. };
  164. struct DLL_LINKAGE LobbyChangePlayerOption : public CLobbyPackToServer
  165. {
  166. enum EWhat : ui8 {UNKNOWN, TOWN, HERO, BONUS};
  167. ui8 what = UNKNOWN;
  168. si8 direction = 0; //-1 or +1
  169. PlayerColor color = PlayerColor::CANNOT_DETERMINE;
  170. virtual void visitTyped(ICPackVisitor & visitor) override;
  171. template <typename Handler> void serialize(Handler &h, const int version)
  172. {
  173. h & what;
  174. h & direction;
  175. h & color;
  176. }
  177. };
  178. struct DLL_LINKAGE LobbySetPlayer : public CLobbyPackToServer
  179. {
  180. PlayerColor clickedColor = PlayerColor::CANNOT_DETERMINE;
  181. virtual void visitTyped(ICPackVisitor & visitor) override;
  182. template <typename Handler> void serialize(Handler &h, const int version)
  183. {
  184. h & clickedColor;
  185. }
  186. };
  187. struct DLL_LINKAGE LobbySetTurnTime : public CLobbyPackToServer
  188. {
  189. ui8 turnTime = 0;
  190. virtual void visitTyped(ICPackVisitor & visitor) override;
  191. template <typename Handler> void serialize(Handler &h, const int version)
  192. {
  193. h & turnTime;
  194. }
  195. };
  196. struct DLL_LINKAGE LobbySetDifficulty : public CLobbyPackToServer
  197. {
  198. ui8 difficulty = 0;
  199. virtual void visitTyped(ICPackVisitor & visitor) override;
  200. template <typename Handler> void serialize(Handler &h, const int version)
  201. {
  202. h & difficulty;
  203. }
  204. };
  205. struct DLL_LINKAGE LobbyForceSetPlayer : public CLobbyPackToServer
  206. {
  207. ui8 targetConnectedPlayer = -1;
  208. PlayerColor targetPlayerColor = PlayerColor::CANNOT_DETERMINE;
  209. virtual void visitTyped(ICPackVisitor & visitor) override;
  210. template <typename Handler> void serialize(Handler & h, const int version)
  211. {
  212. h & targetConnectedPlayer;
  213. h & targetPlayerColor;
  214. }
  215. };
  216. struct DLL_LINKAGE LobbyShowMessage : public CLobbyPackToPropagate
  217. {
  218. std::string message;
  219. virtual void visitTyped(ICPackVisitor & visitor) override;
  220. template <typename Handler> void serialize(Handler & h, const int version)
  221. {
  222. h & message;
  223. }
  224. };
  225. VCMI_LIB_NAMESPACE_END