NetworkDefs.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. #pragma once
  24. #ifndef __NETWORKDEFS_H
  25. #define __NETWORKDEFS_H
  26. #include "Lib/BaseType.h"
  27. #include "Common/MessageStream.h"
  28. static const Int WOL_NAME_LEN = 64;
  29. /// Max number of commands per frame
  30. static const Int MAX_COMMANDS = 256;
  31. extern Int MAX_FRAMES_AHEAD;
  32. extern Int MIN_RUNAHEAD;
  33. // FRAME_DATA_LENGTH needs to be MAX_FRAMES_AHEAD+1 because a player on a different
  34. // computer can send commands for a frame that is one beyond twice the max runahead.
  35. extern Int FRAME_DATA_LENGTH;
  36. extern Int FRAMES_TO_KEEP;
  37. // This is the connection numbering: 1-8 are for players, 9 is a broadcast con.
  38. enum ConnectionNumbers
  39. {
  40. MAX_PLAYER = 7, // The index of the highest possible player number. This is 0 based, so the most players allowed in a game is MAX_PLAYER+1.
  41. NUM_CONNECTIONS
  42. };
  43. static const Int MAX_SLOTS = MAX_PLAYER+1;
  44. // UDP (8 bytes) + IP header (28 bytes) = 36 bytes total. We want a total packet size of 512, so 512 - 36 = 476
  45. static const Int MAX_PACKET_SIZE = 476;
  46. /**
  47. * Command packet - contains frame #, total # of commands, and each command. This is what gets sent
  48. * to each player every frame
  49. */
  50. #define MAX_MESSAGE_LEN 1024
  51. #define MAX_MESSAGES 128
  52. static const Int numCommandsPerCommandPacket = (MAX_MESSAGE_LEN - sizeof(UnsignedInt) - sizeof(UnsignedShort))/sizeof(GameMessage);
  53. #pragma pack(push, 1)
  54. struct CommandPacket
  55. {
  56. UnsignedInt m_frame;
  57. UnsignedShort m_numCommands;
  58. unsigned char m_commands[numCommandsPerCommandPacket * sizeof(GameMessage)];
  59. };
  60. #pragma pack(pop)
  61. #define MAX_TRANSPORT_STATISTICS_SECONDS 30
  62. #pragma pack(push, 1)
  63. struct TransportMessageHeader
  64. {
  65. UnsignedInt crc; ///< packet-level CRC (must be first in packet)
  66. UnsignedShort magic; ///< Magic number identifying Generals packets
  67. // Int id;
  68. // NetMessageFlags flags;
  69. };
  70. #pragma pack(pop)
  71. /**
  72. * Transport message - encapsulating info kept by the transport layer about each
  73. * packet. These structs make up the in/out buffers at the transport layer.
  74. */
  75. #pragma pack(push, 1)
  76. struct TransportMessage
  77. {
  78. TransportMessageHeader header;
  79. UnsignedByte data[MAX_MESSAGE_LEN];
  80. Int length;
  81. UnsignedInt addr;
  82. UnsignedShort port;
  83. };
  84. #pragma pack(pop)
  85. #if defined(_DEBUG) || defined(_INTERNAL)
  86. #pragma pack(push, 1)
  87. struct DelayedTransportMessage
  88. {
  89. UnsignedInt deliveryTime;
  90. TransportMessage message;
  91. };
  92. #pragma pack(pop)
  93. #endif
  94. /**
  95. * Message types
  96. */
  97. enum NetMessageFlag {
  98. MSG_ACK = 1,
  99. MSG_NEEDACK = 2,
  100. MSG_SEQUENCED = 4,
  101. MSG_SUPERCEDING = 8
  102. };
  103. typedef UnsignedByte NetMessageFlags;
  104. enum NetCommandType {
  105. NETCOMMANDTYPE_UNKNOWN = -1,
  106. NETCOMMANDTYPE_ACKBOTH = 0,
  107. NETCOMMANDTYPE_ACKSTAGE1,
  108. NETCOMMANDTYPE_ACKSTAGE2,
  109. NETCOMMANDTYPE_FRAMEINFO,
  110. NETCOMMANDTYPE_GAMECOMMAND,
  111. NETCOMMANDTYPE_PLAYERLEAVE,
  112. NETCOMMANDTYPE_RUNAHEADMETRICS,
  113. NETCOMMANDTYPE_RUNAHEAD,
  114. NETCOMMANDTYPE_DESTROYPLAYER,
  115. NETCOMMANDTYPE_KEEPALIVE,
  116. NETCOMMANDTYPE_DISCONNECTCHAT,
  117. NETCOMMANDTYPE_CHAT,
  118. NETCOMMANDTYPE_MANGLERQUERY,
  119. NETCOMMANDTYPE_MANGLERRESPONSE,
  120. NETCOMMANDTYPE_PROGRESS,
  121. NETCOMMANDTYPE_LOADCOMPLETE,
  122. NETCOMMANDTYPE_TIMEOUTSTART,
  123. NETCOMMANDTYPE_WRAPPER, // A wrapper command that holds a command thats too big to fit in a single packet.
  124. NETCOMMANDTYPE_FILE,
  125. NETCOMMANDTYPE_FILEANNOUNCE,
  126. NETCOMMANDTYPE_FILEPROGRESS,
  127. NETCOMMANDTYPE_FRAMERESENDREQUEST,
  128. // Disconnect menu command section.
  129. NETCOMMANDTYPE_DISCONNECTSTART,
  130. NETCOMMANDTYPE_DISCONNECTKEEPALIVE,
  131. NETCOMMANDTYPE_DISCONNECTPLAYER,
  132. NETCOMMANDTYPE_PACKETROUTERQUERY,
  133. NETCOMMANDTYPE_PACKETROUTERACK,
  134. NETCOMMANDTYPE_DISCONNECTVOTE,
  135. NETCOMMANDTYPE_DISCONNECTFRAME,
  136. NETCOMMANDTYPE_DISCONNECTSCREENOFF,
  137. NETCOMMANDTYPE_DISCONNECTEND,
  138. NETCOMMANDTYPE_MAX
  139. };
  140. enum NetLocalStatus {
  141. NETLOCALSTATUS_PREGAME = 0,
  142. NETLOCALSTATUS_INGAME,
  143. NETLOCALSTATUS_LEAVING,
  144. NETLOCALSTATUS_LEFT,
  145. NETLOCALSTATUS_POSTGAME
  146. };
  147. enum PlayerLeaveCode {
  148. PLAYERLEAVECODE_CLIENT = 0,
  149. PLAYERLEAVECODE_LOCAL,
  150. PLAYERLEAVECODE_PACKETROUTER,
  151. PLAYERLEAVECODE_UNKNOWN
  152. };
  153. // Magic number for identifying a Generals packet.
  154. static const UnsignedShort GENERALS_MAGIC_NUMBER = 0xF00D;
  155. // The number of fps history entries.
  156. //static const Int NETWORK_FPS_HISTORY_LENGTH = 30;
  157. // The number of ping history entries.
  158. //static const Int NETWORK_LATENCY_HISTORY_LENGTH = 200;
  159. // The number of miliseconds between run ahead metrics things
  160. //static const Int NETWORK_RUN_AHEAD_METRICS_TIME = 5000;
  161. // The number of cushion values to keep.
  162. //static const Int NETWORK_CUSHION_HISTORY_LENGTH = 10;
  163. // The amount of slack in the run ahead value. This is the percentage of the calculated run ahead that is added.
  164. //static const Int NETWORK_RUN_AHEAD_SLACK = 20;
  165. // The number of seconds between when the connections to each player send a keep-alive packet.
  166. // This should be less than 30 just to keep firewall ports open.
  167. //static const Int NETWORK_KEEPALIVE_DELAY = 20;
  168. // The number of milliseconds between when the game gets stuck on a frame for a network stall and
  169. // and when the disconnect dialog comes up.
  170. //static const Int NETWORK_DISCONNECT_TIME = 5000;
  171. // The number of miliseconds between when a player's last disconnect keep alive command
  172. // was recieved and when they are considered disconnected from the game.
  173. //static const Int NETWORK_PLAYER_TIMEOUT_TIME = 60000;
  174. // The base port number used for the transport socket. A players slot number is added to this
  175. // value to get their actual port number.
  176. static const Int NETWORK_BASE_PORT_NUMBER = 8088;
  177. // the singleton
  178. class NetworkInterface;
  179. extern NetworkInterface *TheNetwork;
  180. #endif