NetCommandMsg.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. //------------------------------------------------------------------------------------
  24. // The CommandMsg class is a linked-list wrapper around GameMessage objects that
  25. // are queued up to execute at a later time
  26. #pragma once
  27. #ifndef __NETCOMMANDMSG_H
  28. #define __NETCOMMANDMSG_H
  29. #include "Lib/BaseType.h"
  30. #include "GameNetwork/NetworkDefs.h"
  31. #include "Common/UnicodeString.h"
  32. //-----------------------------------------------------------------------------
  33. class NetCommandMsg : public MemoryPoolObject
  34. {
  35. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetCommandMsg, "NetCommandMsg")
  36. public:
  37. NetCommandMsg();
  38. //virtual ~NetCommandMsg();
  39. inline UnsignedInt GetTimestamp() { return m_timestamp; }
  40. inline void SetTimestamp(UnsignedInt timestamp) { m_timestamp = timestamp; }
  41. inline void setExecutionFrame(UnsignedInt frame) { m_executionFrame = frame; }
  42. inline void setPlayerID(UnsignedInt playerID) { m_playerID = playerID; }
  43. inline void setID(UnsignedShort id) { m_id = id; }
  44. inline UnsignedInt getExecutionFrame() { return m_executionFrame; }
  45. inline UnsignedInt getPlayerID() { return m_playerID; }
  46. inline UnsignedShort getID() { return m_id; }
  47. inline void setNetCommandType(NetCommandType type) { m_commandType = type; }
  48. inline NetCommandType getNetCommandType() { return m_commandType; }
  49. virtual Int getSortNumber();
  50. void attach();
  51. void detach();
  52. // For debugging purposes
  53. virtual AsciiString getContentsAsAsciiString(void) { return AsciiString::TheEmptyString; }
  54. protected:
  55. UnsignedInt m_timestamp;
  56. UnsignedInt m_executionFrame;
  57. UnsignedInt m_playerID;
  58. UnsignedShort m_id;
  59. NetCommandType m_commandType;
  60. Int m_referenceCount;
  61. };
  62. //-----------------------------------------------------------------------------
  63. /**
  64. * The NetGameCommandMsg is the NetCommandMsg representation of a GameMessage
  65. */
  66. class NetGameCommandMsg : public NetCommandMsg
  67. {
  68. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetGameCommandMsg, "NetGameCommandMsg")
  69. public:
  70. NetGameCommandMsg();
  71. NetGameCommandMsg(GameMessage *msg);
  72. //virtual ~NetGameCommandMsg();
  73. GameMessage *constructGameMessage();
  74. void addArgument(const GameMessageArgumentDataType type, GameMessageArgumentType arg);
  75. void setGameMessageType(GameMessage::Type type);
  76. // For debugging purposes
  77. virtual AsciiString getContentsAsAsciiString(void);
  78. protected:
  79. Int m_numArgs;
  80. Int m_argSize;
  81. GameMessage::Type m_type;
  82. GameMessageArgument *m_argList, *m_argTail;
  83. };
  84. //-----------------------------------------------------------------------------
  85. /**
  86. * The NetAckBothCommandMsg is the NetCommandMsg representation of the combination of a
  87. * stage 1 ack and a stage 2 ack.
  88. */
  89. class NetAckBothCommandMsg : public NetCommandMsg
  90. {
  91. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetAckBothCommandMsg, "NetAckBothCommandMsg")
  92. public:
  93. NetAckBothCommandMsg(NetCommandMsg *msg);
  94. NetAckBothCommandMsg();
  95. //virtual ~NetAckBothCommandMsg();
  96. UnsignedShort getCommandID();
  97. void setCommandID(UnsignedShort commandID);
  98. UnsignedByte getOriginalPlayerID();
  99. void setOriginalPlayerID(UnsignedByte originalPlayerID);
  100. virtual Int getSortNumber();
  101. protected:
  102. UnsignedShort m_commandID;
  103. UnsignedByte m_originalPlayerID;
  104. };
  105. //-----------------------------------------------------------------------------
  106. /**
  107. * The NetAckStage1CommandMsg is the NetCommandMsg representation of an ack message for the initial
  108. * recipient.
  109. */
  110. class NetAckStage1CommandMsg : public NetCommandMsg
  111. {
  112. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetAckStage1CommandMsg, "NetAckStage1CommandMsg")
  113. public:
  114. NetAckStage1CommandMsg(NetCommandMsg *msg);
  115. NetAckStage1CommandMsg();
  116. //virtual ~NetAckStage1CommandMsg();
  117. UnsignedShort getCommandID();
  118. void setCommandID(UnsignedShort commandID);
  119. UnsignedByte getOriginalPlayerID();
  120. void setOriginalPlayerID(UnsignedByte originalPlayerID);
  121. virtual Int getSortNumber();
  122. protected:
  123. UnsignedShort m_commandID;
  124. UnsignedByte m_originalPlayerID;
  125. };
  126. //-----------------------------------------------------------------------------
  127. /**
  128. * The NetAckStage2CommandMsg is the NetCommandMsg representation of an ack message for all eventual
  129. * recipients. (when this is returned, all the players in the relay mask have received the packet)
  130. */
  131. class NetAckStage2CommandMsg : public NetCommandMsg
  132. {
  133. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetAckStage2CommandMsg, "NetAckStage2CommandMsg")
  134. public:
  135. NetAckStage2CommandMsg(NetCommandMsg *msg);
  136. NetAckStage2CommandMsg();
  137. //virtual ~NetAckStage2CommandMsg();
  138. UnsignedShort getCommandID();
  139. void setCommandID(UnsignedShort commandID);
  140. UnsignedByte getOriginalPlayerID();
  141. void setOriginalPlayerID(UnsignedByte originalPlayerID);
  142. virtual Int getSortNumber();
  143. protected:
  144. UnsignedShort m_commandID;
  145. UnsignedByte m_originalPlayerID;
  146. };
  147. //-----------------------------------------------------------------------------
  148. class NetFrameCommandMsg : public NetCommandMsg
  149. {
  150. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetFrameCommandMsg, "NetFrameCommandMsg")
  151. public:
  152. NetFrameCommandMsg();
  153. //virtual ~NetFrameCommandMsg();
  154. void setCommandCount(UnsignedShort commandCount);
  155. UnsignedShort getCommandCount();
  156. protected:
  157. UnsignedShort m_commandCount;
  158. };
  159. //-----------------------------------------------------------------------------
  160. class NetPlayerLeaveCommandMsg : public NetCommandMsg
  161. {
  162. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetPlayerLeaveCommandMsg, "NetPlayerLeaveCommandMsg")
  163. public:
  164. NetPlayerLeaveCommandMsg();
  165. //virtual ~NetPlayerLeaveCommandMsg();
  166. UnsignedByte getLeavingPlayerID();
  167. void setLeavingPlayerID(UnsignedByte id);
  168. protected:
  169. UnsignedByte m_leavingPlayerID;
  170. };
  171. //-----------------------------------------------------------------------------
  172. class NetRunAheadMetricsCommandMsg : public NetCommandMsg
  173. {
  174. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetRunAheadMetricsCommandMsg, "NetRunAheadMetricsCommandMsg")
  175. public:
  176. NetRunAheadMetricsCommandMsg();
  177. //virtual ~NetRunAheadMetricsCommandMsg();
  178. Real getAverageLatency();
  179. void setAverageLatency(Real avgLat);
  180. Int getAverageFps();
  181. void setAverageFps(Int fps);
  182. protected:
  183. Real m_averageLatency;
  184. Int m_averageFps;
  185. };
  186. //-----------------------------------------------------------------------------
  187. class NetRunAheadCommandMsg : public NetCommandMsg
  188. {
  189. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetRunAheadCommandMsg, "NetRunAheadCommandMsg")
  190. public:
  191. NetRunAheadCommandMsg();
  192. //virtual ~NetRunAheadCommandMsg();
  193. UnsignedShort getRunAhead();
  194. void setRunAhead(UnsignedShort runAhead);
  195. UnsignedByte getFrameRate();
  196. void setFrameRate(UnsignedByte frameRate);
  197. protected:
  198. UnsignedShort m_runAhead;
  199. UnsignedByte m_frameRate;
  200. };
  201. //-----------------------------------------------------------------------------
  202. class NetDestroyPlayerCommandMsg : public NetCommandMsg
  203. {
  204. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetDestroyPlayerCommandMsg, "NetDestroyPlayerCommandMsg")
  205. public:
  206. NetDestroyPlayerCommandMsg();
  207. //virtual ~NetDestroyPlayerCommandMsg();
  208. UnsignedInt getPlayerIndex();
  209. void setPlayerIndex(UnsignedInt playerIndex);
  210. protected:
  211. UnsignedInt m_playerIndex;
  212. };
  213. //-----------------------------------------------------------------------------
  214. class NetKeepAliveCommandMsg : public NetCommandMsg
  215. {
  216. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetKeepAliveCommandMsg, "NetKeepAliveCommandMsg")
  217. public:
  218. NetKeepAliveCommandMsg();
  219. //virtual ~NetKeepAliveCommandMsg();
  220. };
  221. //-----------------------------------------------------------------------------
  222. class NetDisconnectKeepAliveCommandMsg : public NetCommandMsg
  223. {
  224. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetDisconnectKeepAliveCommandMsg, "NetDisconnectKeepAliveCommandMsg")
  225. public:
  226. NetDisconnectKeepAliveCommandMsg();
  227. //virtual ~NetDisconnectKeepAliveCommandMsg();
  228. };
  229. //-----------------------------------------------------------------------------
  230. class NetDisconnectPlayerCommandMsg : public NetCommandMsg
  231. {
  232. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetDisconnectPlayerCommandMsg, "NetDisconnectPlayerCommandMsg")
  233. public:
  234. NetDisconnectPlayerCommandMsg();
  235. //virtual ~NetDisconnectPlayerCommandMsg();
  236. UnsignedByte getDisconnectSlot();
  237. void setDisconnectSlot(UnsignedByte slot);
  238. UnsignedInt getDisconnectFrame();
  239. void setDisconnectFrame(UnsignedInt frame);
  240. protected:
  241. UnsignedByte m_disconnectSlot;
  242. UnsignedInt m_disconnectFrame;
  243. };
  244. //-----------------------------------------------------------------------------
  245. class NetPacketRouterQueryCommandMsg : public NetCommandMsg
  246. {
  247. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetPacketRouterQueryCommandMsg, "NetPacketRouterQueryCommandMsg")
  248. public:
  249. NetPacketRouterQueryCommandMsg();
  250. //virtual ~NetPacketRouterQueryCommandMsg();
  251. };
  252. //-----------------------------------------------------------------------------
  253. class NetPacketRouterAckCommandMsg : public NetCommandMsg
  254. {
  255. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetPacketRouterAckCommandMsg, "NetPacketRouterAckCommandMsg")
  256. public:
  257. NetPacketRouterAckCommandMsg();
  258. //virtual ~NetPacketRouterAckCommandMsg();
  259. };
  260. //-----------------------------------------------------------------------------
  261. class NetDisconnectChatCommandMsg : public NetCommandMsg
  262. {
  263. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetDisconnectChatCommandMsg, "NetDisconnectChatCommandMsg")
  264. public:
  265. NetDisconnectChatCommandMsg();
  266. //virtual ~NetDisconnectChatCommandMsg();
  267. UnicodeString getText();
  268. void setText(UnicodeString text);
  269. protected:
  270. UnicodeString m_text;
  271. };
  272. //-----------------------------------------------------------------------------
  273. class NetChatCommandMsg : public NetCommandMsg
  274. {
  275. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetChatCommandMsg, "NetChatCommandMsg")
  276. public:
  277. NetChatCommandMsg();
  278. //virtual ~NetChatCommandMsg();
  279. UnicodeString getText();
  280. void setText(UnicodeString text);
  281. Int getPlayerMask( void );
  282. void setPlayerMask( Int playerMask );
  283. protected:
  284. UnicodeString m_text;
  285. Int m_playerMask;
  286. };
  287. //-----------------------------------------------------------------------------
  288. class NetDisconnectVoteCommandMsg : public NetCommandMsg
  289. {
  290. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetDisconnectVoteCommandMsg, "NetDisconnectVoteCommandMsg")
  291. public:
  292. NetDisconnectVoteCommandMsg();
  293. //virtual ~NetDisconnectVoteCommandMsg();
  294. UnsignedByte getSlot();
  295. void setSlot(UnsignedByte slot);
  296. UnsignedInt getVoteFrame();
  297. void setVoteFrame(UnsignedInt voteFrame);
  298. protected:
  299. UnsignedByte m_slot;
  300. UnsignedInt m_voteFrame;
  301. };
  302. //-----------------------------------------------------------------------------
  303. class NetProgressCommandMsg: public NetCommandMsg
  304. {
  305. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetProgressCommandMsg, "NetProgressCommandMsg")
  306. public:
  307. NetProgressCommandMsg( void );
  308. //virtual ~NetProgressCommandMsg( void );
  309. UnsignedByte getPercentage();
  310. void setPercentage( UnsignedByte percent );
  311. protected:
  312. UnsignedByte m_percent;
  313. };
  314. //-----------------------------------------------------------------------------
  315. class NetWrapperCommandMsg : public NetCommandMsg
  316. {
  317. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetWrapperCommandMsg, "NetWrapperCommandMsg")
  318. public:
  319. NetWrapperCommandMsg( void );
  320. //virtual ~NetWrapperCommandMsg();
  321. UnsignedByte * getData();
  322. void setData(UnsignedByte *data, UnsignedInt dataLength);
  323. UnsignedInt getChunkNumber();
  324. void setChunkNumber(UnsignedInt chunkNumber);
  325. UnsignedInt getNumChunks();
  326. void setNumChunks(UnsignedInt numChunks);
  327. UnsignedInt getDataLength();
  328. UnsignedInt getTotalDataLength();
  329. void setTotalDataLength(UnsignedInt totalDataLength);
  330. UnsignedInt getDataOffset();
  331. void setDataOffset(UnsignedInt offset);
  332. UnsignedShort getWrappedCommandID();
  333. void setWrappedCommandID(UnsignedShort wrappedCommandID);
  334. private:
  335. UnsignedByte *m_data;
  336. // using UnsignedInt's so we can send around files of effectively unlimited size easily
  337. UnsignedInt m_dataLength;
  338. UnsignedInt m_dataOffset;
  339. UnsignedInt m_totalDataLength;
  340. UnsignedInt m_chunkNumber;
  341. UnsignedInt m_numChunks;
  342. UnsignedShort m_wrappedCommandID;
  343. };
  344. //-----------------------------------------------------------------------------
  345. class NetFileCommandMsg : public NetCommandMsg
  346. {
  347. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetFileCommandMsg, "NetFileCommandMsg")
  348. public:
  349. NetFileCommandMsg();
  350. //virtual ~NetFileCommandMsg();
  351. AsciiString getRealFilename();
  352. void setRealFilename(AsciiString filename);
  353. AsciiString getPortableFilename() { return m_portableFilename; }
  354. void setPortableFilename(AsciiString filename) { m_portableFilename = filename; }
  355. UnsignedInt getFileLength();
  356. UnsignedByte * getFileData();
  357. void setFileData(UnsignedByte *data, UnsignedInt dataLength);
  358. protected:
  359. AsciiString m_portableFilename;
  360. UnsignedByte *m_data;
  361. UnsignedInt m_dataLength;
  362. };
  363. //-----------------------------------------------------------------------------
  364. class NetFileAnnounceCommandMsg : public NetCommandMsg
  365. {
  366. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetFileAnnounceCommandMsg, "NetFileAnnounceCommandMsg")
  367. public:
  368. NetFileAnnounceCommandMsg();
  369. //virtual ~NetFileAnnounceCommandMsg();
  370. AsciiString getRealFilename();
  371. void setRealFilename(AsciiString filename);
  372. AsciiString getPortableFilename() { return m_portableFilename; }
  373. void setPortableFilename(AsciiString filename) { m_portableFilename = filename; }
  374. UnsignedShort getFileID();
  375. void setFileID(UnsignedShort fileID);
  376. UnsignedByte getPlayerMask(void);
  377. void setPlayerMask(UnsignedByte playerMask);
  378. protected:
  379. AsciiString m_portableFilename;
  380. UnsignedShort m_fileID;
  381. UnsignedByte m_playerMask;
  382. };
  383. //-----------------------------------------------------------------------------
  384. class NetFileProgressCommandMsg : public NetCommandMsg
  385. {
  386. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetFileProgressCommandMsg, "NetFileProgressCommandMsg")
  387. public:
  388. NetFileProgressCommandMsg();
  389. //virtual ~NetFileProgressCommandMsg();
  390. UnsignedShort getFileID();
  391. void setFileID(UnsignedShort val);
  392. Int getProgress();
  393. void setProgress(Int val);
  394. protected:
  395. UnsignedShort m_fileID;
  396. Int m_progress;
  397. };
  398. //-----------------------------------------------------------------------------
  399. class NetDisconnectFrameCommandMsg : public NetCommandMsg
  400. {
  401. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetDisconnectFrameCommandMsg, "NetDisconnectFrameCommandMsg")
  402. public:
  403. NetDisconnectFrameCommandMsg();
  404. UnsignedInt getDisconnectFrame();
  405. void setDisconnectFrame(UnsignedInt disconnectFrame);
  406. protected:
  407. UnsignedInt m_disconnectFrame;
  408. };
  409. //-----------------------------------------------------------------------------
  410. class NetDisconnectScreenOffCommandMsg : public NetCommandMsg
  411. {
  412. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetDisconnectScreenOffCommandMsg, "NetDisconnectScreenOffCommandMsg")
  413. public:
  414. NetDisconnectScreenOffCommandMsg();
  415. UnsignedInt getNewFrame();
  416. void setNewFrame(UnsignedInt newFrame);
  417. protected:
  418. UnsignedInt m_newFrame;
  419. };
  420. //-----------------------------------------------------------------------------
  421. class NetFrameResendRequestCommandMsg : public NetCommandMsg
  422. {
  423. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(NetFrameResendRequestCommandMsg, "NetFrameResendRequestCommandMsg")
  424. public:
  425. NetFrameResendRequestCommandMsg();
  426. UnsignedInt getFrameToResend();
  427. void setFrameToResend(UnsignedInt frame);
  428. protected:
  429. UnsignedInt m_frameToResend;
  430. };
  431. #endif