SESSION.H 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. /*
  2. ** Command & Conquer(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. * Project Name : Command & Conquer *
  21. * *
  22. * File Name : SESSION.H *
  23. * *
  24. * Programmer : Bill R. Randolph *
  25. * *
  26. * Start Date : 11/30/95 *
  27. * *
  28. * Last Update : November 30, 1995 [BRR] *
  29. * *
  30. * The purpose of this class is to contain those variables & routines *
  31. * specifically related to a multiplayer game. *
  32. * *
  33. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  34. #ifndef SESSION_H
  35. #define SESSION_H
  36. #include "ipxaddr.h"
  37. #include "msglist.h"
  38. #include "connect.h"
  39. //---------------------------------------------------------------------------
  40. // Forward declarations
  41. //---------------------------------------------------------------------------
  42. class AircraftClass;
  43. class AnimClass;
  44. class BuildingClass;
  45. class BulletClass;
  46. class InfantryClass;
  47. class UnitClass;
  48. class PhoneEntryClass;
  49. class CellClass;
  50. //---------------------------------------------------------------------------
  51. // Defines
  52. //---------------------------------------------------------------------------
  53. //...........................................................................
  54. // Various limiting values
  55. //...........................................................................
  56. #define MAX_PLAYERS 6 // max # of players we can have
  57. #define MPLAYER_BUILD_LEVEL_MAX 7 // max build level in multiplay
  58. #define MAX_MPLAYER_COLORS 6 // max # of colors
  59. //...........................................................................
  60. // Max sizes of packets we want to send
  61. // The IPX packet's size is IPX's max size (546), rounded down to accommodate
  62. // the max number of events possible.
  63. //...........................................................................
  64. #define MAX_IPX_PACKET_SIZE (((546 - sizeof(CommHeaderType)) / \
  65. sizeof(EventClass) ) * sizeof(EventClass))
  66. #define MAX_SERIAL_PACKET_SIZE 200
  67. //...........................................................................
  68. // Max length of player names fields; attempt to use the constant for the
  69. // HouseClass, if it's been defined; otherwise, define it myself.
  70. //...........................................................................
  71. #ifdef HOUSE_NAME_MAX
  72. #define MPLAYER_NAME_MAX HOUSE_NAME_MAX
  73. #else
  74. #define MPLAYER_NAME_MAX 12 // max length of a player's name
  75. #endif
  76. //...........................................................................
  77. // Values to control the multiplayer score screen
  78. //...........................................................................
  79. #define MAX_MULTI_NAMES 8 // max # names (rows) on the score screen
  80. #define MAX_MULTI_GAMES 4 // max # games (columns) on the score screen
  81. //...........................................................................
  82. // Min value for MaxAhead, for both net & modem; only applies for
  83. // COMM_PROTOCOL_MULTI_E_COMP.
  84. //...........................................................................
  85. #define MODEM_MIN_MAX_AHEAD 5
  86. #define NETWORK_MIN_MAX_AHEAD 2
  87. //...........................................................................
  88. // Send period (in frames) for COMM_PROTOCOL_MULTI_E_COMP and above
  89. //...........................................................................
  90. #define DEFAULT_FRAME_SEND_RATE 3
  91. //...........................................................................
  92. // Modem-specific constants
  93. //...........................................................................
  94. #define PORTBUF_MAX 5 // dialog field sizes
  95. #define IRQBUF_MAX 3
  96. #define BAUDBUF_MAX 7
  97. #define INITSTRBUF_MAX 41
  98. #define CWAITSTRBUF_MAX 16
  99. #define CREDITSBUF_MAX 5
  100. #define PACKET_TIMING_TIMEOUT 40 // ticks b/w sending a timing packet
  101. //---------------------------------------------------------------------------
  102. // Enums
  103. //---------------------------------------------------------------------------
  104. //...........................................................................
  105. // Types of games; used to tell which protocol we're using
  106. //...........................................................................
  107. typedef enum GameEnum {
  108. GAME_NORMAL, // not multiplayer
  109. GAME_MODEM, // modem game
  110. GAME_NULL_MODEM, // NULL-modem
  111. GAME_IPX, // IPX Network game
  112. GAME_INTERNET // Winsock game
  113. } GameType;
  114. //...........................................................................
  115. // Various Modem-specific enums
  116. //...........................................................................
  117. typedef enum DetectPortType {
  118. PORT_VALID = 0,
  119. PORT_INVALID,
  120. PORT_IRQ_INUSE
  121. } DetectPortType;
  122. typedef enum DialStatusType {
  123. DIAL_CONNECTED = 0,
  124. DIAL_NO_CARRIER,
  125. DIAL_BUSY,
  126. DIAL_ERROR,
  127. DIAL_CANCELED
  128. } DialStatusType;
  129. typedef enum DialMethodType {
  130. DIAL_TOUCH_TONE = 0,
  131. DIAL_PULSE,
  132. DIAL_METHODS
  133. } DialMethodType;
  134. typedef enum CallWaitStringType {
  135. CALL_WAIT_TONE_1 = 0,
  136. CALL_WAIT_TONE_2,
  137. CALL_WAIT_PULSE,
  138. CALL_WAIT_CUSTOM,
  139. CALL_WAIT_STRINGS_NUM
  140. } CallWaitStringType;
  141. typedef enum ModemGameType {
  142. MODEM_NULL_HOST = 0,
  143. MODEM_NULL_JOIN,
  144. MODEM_DIALER,
  145. MODEM_ANSWERER,
  146. INTERNET_HOST = MODEM_NULL_HOST,
  147. INTERNET_JOIN = MODEM_NULL_JOIN
  148. } ModemGameType;
  149. //...........................................................................
  150. // Commands sent over the serial Global Channel
  151. //...........................................................................
  152. typedef enum SerialCommandType {
  153. SERIAL_CONNECT = 100, // Are you there? Hello? McFly?
  154. SERIAL_GAME_OPTIONS = 101, // Hey, dudes, here's some new game options
  155. SERIAL_SIGN_OFF = 102, // Bogus, dudes, my boss is coming; I'm outta here!
  156. SERIAL_GO = 103, // OK, dudes, jump into the game loop!
  157. SERIAL_MESSAGE = 104, // Here's a message
  158. SERIAL_TIMING = 105, // timimg packet
  159. SERIAL_SCORE_SCREEN = 106, // player at score screen
  160. SERIAL_LOADGAME = 107, // Start the game, loading a saved game first
  161. SERIAL_LAST_COMMAND // last command
  162. } SerialCommandType;
  163. //...........................................................................
  164. // Commands sent over the network Global Channel
  165. //...........................................................................
  166. typedef enum NetCommandType {
  167. NET_QUERY_GAME, // Hey, what games are out there?
  168. NET_ANSWER_GAME, // Yo, Here's my game's name!
  169. NET_QUERY_PLAYER, // Hey, what players are in this game?
  170. NET_ANSWER_PLAYER, // Yo, I'm in that game!
  171. NET_CHAT_ANNOUNCE, // I'm at the chat screen
  172. NET_CHAT_REQUEST, // Respond with a CHAT_ANNOUNCE, please.
  173. NET_QUERY_JOIN, // Hey guys, can I play too?
  174. NET_CONFIRM_JOIN, // Well, OK, if you really want to.
  175. NET_REJECT_JOIN, // No, you can't join; sorry, dude.
  176. NET_GAME_OPTIONS, // Hey, dudes, here's some new game options
  177. NET_SIGN_OFF, // Bogus, dudes, my boss is coming; I'm outta here!
  178. NET_GO, // OK, jump into the game loop!
  179. NET_MESSAGE, // Here's a message
  180. NET_PING, // I'm pinging you to take a time measurement
  181. NET_LOADGAME, // start a game by loading a saved game
  182. } NetCommandType;
  183. //---------------------------------------------------------------------------
  184. // Structures
  185. //---------------------------------------------------------------------------
  186. //...........................................................................
  187. // An entry on the score screen is defined by this structure
  188. //...........................................................................
  189. typedef struct {
  190. char Name[MPLAYER_NAME_MAX];
  191. int Wins;
  192. int Kills[MAX_MULTI_GAMES];
  193. int Color;
  194. } MPlayerScoreType;
  195. //...........................................................................
  196. // Settings for the serial port
  197. //...........................................................................
  198. typedef struct {
  199. int Port;
  200. int IRQ;
  201. int Baud;
  202. DialMethodType DialMethod;
  203. int InitStringIndex;
  204. int CallWaitStringIndex;
  205. char CallWaitString[ CWAITSTRBUF_MAX ];
  206. } SerialSettingsType;
  207. //...........................................................................
  208. // This is a "node", used for the lists of available games & players. The
  209. // 'Game' structure is used for games; the 'Player' structure for players.
  210. //...........................................................................
  211. typedef struct NodeNameTag {
  212. char Name[MPLAYER_NAME_MAX]; // player or game name
  213. IPXAddressClass Address;
  214. union {
  215. struct {
  216. unsigned char IsOpen; // is the game open?
  217. unsigned long LastTime; // last time we heard from this guy
  218. } Game;
  219. struct {
  220. HousesType House; // "ActLike" House of this player
  221. unsigned char Color; // Color of this player
  222. HousesType ID; // Actual House of this player
  223. } Player;
  224. struct {
  225. unsigned long LastTime; // last time we heard from this guy
  226. unsigned char LastChance; // we're about to remove him from the list
  227. unsigned char Color; // chat player's color
  228. } Chat;
  229. };
  230. } NodeNameType;
  231. //...........................................................................
  232. // Packet sent over the serial Global Channel
  233. //...........................................................................
  234. typedef struct {
  235. SerialCommandType Command; // One of the enum's defined above
  236. char Name[MPLAYER_NAME_MAX]; // Player or Game Name
  237. unsigned long MinVersion; // min version this game supports
  238. unsigned long MaxVersion; // max version this game supports
  239. HousesType House; // player's House
  240. unsigned char Color; // player's color or SIGNOFF ID
  241. unsigned char Scenario; // Scenario #
  242. unsigned int Credits; // player's credits
  243. unsigned int IsBases : 1; // 1 = bases are allowed
  244. unsigned int IsTiberium : 1; // 1 = tiberium is allowed
  245. unsigned int IsGoodies : 1; // 1 = goodies are allowed
  246. unsigned int IsGhosties : 1; // 1 = ghosts are allowed
  247. unsigned char BuildLevel; // buildable level
  248. unsigned char UnitCount; // max # units
  249. int Seed; // random number seed
  250. SpecialClass Special; // command-line options
  251. unsigned int GameSpeed; // Game Speed
  252. unsigned long ResponseTime; // packet response time
  253. char Message[COMPAT_MESSAGE_LENGTH]; // inter-player message
  254. unsigned char ID; // unique ID of sender of message
  255. } SerialPacketType;
  256. //...........................................................................
  257. // Packet sent over the network Global Channel
  258. //...........................................................................
  259. typedef struct {
  260. NetCommandType Command; // One of the enum's defined above
  261. char Name[MPLAYER_NAME_MAX]; // Player or Game Name
  262. union {
  263. struct {
  264. unsigned int IsOpen : 1; // 1 = game is open for joining
  265. } GameInfo;
  266. struct {
  267. HousesType House; // player's House
  268. unsigned int Color; // player's color
  269. unsigned long NameCRC; // CRC of player's game's name
  270. unsigned long MinVersion; // game's min supported version
  271. unsigned long MaxVersion; // game's max supported version
  272. } PlayerInfo;
  273. struct {
  274. unsigned char Scenario; // Scenario #
  275. unsigned int Credits; // player's credits
  276. unsigned int IsBases : 1; // 1 = bases are allowed
  277. unsigned int IsTiberium : 1; // 1 = tiberium is allowed
  278. unsigned int IsGoodies : 1; // 1 = goodies are allowed
  279. unsigned int IsGhosties : 1; // 1 = ghosts are allowed
  280. unsigned char BuildLevel; // buildable level
  281. unsigned char UnitCount; // max # units
  282. int Seed; // random number seed
  283. SpecialClass Special; // command-line options
  284. unsigned int GameSpeed; // Game Speed
  285. unsigned long Version; // version # common to all players
  286. } ScenarioInfo;
  287. struct {
  288. char Buf[COMPAT_MESSAGE_LENGTH]; // inter-user message
  289. unsigned char Color; // color of sender of message
  290. unsigned long NameCRC; // CRC of sender's Game Name
  291. } Message;
  292. struct {
  293. int OneWay; // one-way response time
  294. } ResponseTime;
  295. struct {
  296. int Why; // why were we rejected from the game?
  297. } Reject;
  298. struct {
  299. unsigned long ID; // unique ID for this chat node
  300. unsigned char Color; // my color
  301. } Chat;
  302. };
  303. } GlobalPacketType;
  304. //...........................................................................
  305. // For finding sync bugs; filled in by the engine when certain conditions
  306. // are met; the pointers allow examination of objects in the debugger.
  307. //...........................................................................
  308. typedef struct {
  309. union {
  310. AircraftClass *Aircraft;
  311. AnimClass *Anim;
  312. BuildingClass *Building;
  313. BulletClass *Bullet;
  314. InfantryClass *Infantry;
  315. UnitClass *Unit;
  316. void *All;
  317. } Ptr;
  318. } TrapObjectType;
  319. typedef struct {
  320. int ScenarioIndex;
  321. int Bases;
  322. int Credits;
  323. int Tiberium;
  324. int Goodies;
  325. int Ghosts;
  326. int UnitCount;
  327. } GameOptionsType;
  328. //---------------------------------------------------------------------------
  329. // Class Definition
  330. //---------------------------------------------------------------------------
  331. class SessionClass
  332. {
  333. //------------------------------------------------------------------------
  334. // Public interface
  335. //------------------------------------------------------------------------
  336. public:
  337. //.....................................................................
  338. // Constructor/Destructor
  339. //.....................................................................
  340. SessionClass(void);
  341. ~SessionClass(void);
  342. //.....................................................................
  343. // Initialization
  344. //.....................................................................
  345. void One_Time(void);
  346. void Init(void);
  347. //.....................................................................
  348. // Reads/writes to the INI file
  349. //.....................................................................
  350. void Read_MultiPlayer_Settings (void);
  351. void Write_MultiPlayer_Settings (void);
  352. void Read_Scenario_Descriptions (void);
  353. void Free_Scenario_Descriptions(void);
  354. //.....................................................................
  355. // Utility functions
  356. //.....................................................................
  357. int Create_Connections(void);
  358. bool Am_I_Master(void);
  359. unsigned long Compute_Unique_ID(void);
  360. //.....................................................................
  361. // File I/O
  362. //.....................................................................
  363. int Save(FileClass &file);
  364. int Load(FileClass &file);
  365. //.....................................................................
  366. // Debugging / Sync Bugs
  367. //.....................................................................
  368. void Trap_Object(void);
  369. //---------------------------------------------------------------------
  370. // Public Data
  371. //---------------------------------------------------------------------
  372. //.....................................................................
  373. // The type of session being played
  374. //.....................................................................
  375. GameType Type;
  376. //.....................................................................
  377. // The current communications protocol
  378. //.....................................................................
  379. CommProtocolType CommProtocol;
  380. //.....................................................................
  381. // Game options
  382. //.....................................................................
  383. GameOptionsType Options;
  384. //.....................................................................
  385. // Unique workstation ID, for detecting my own packets
  386. //.....................................................................
  387. unsigned long UniqueID;
  388. //.....................................................................
  389. // Player's local options
  390. //.....................................................................
  391. char Handle[MPLAYER_NAME_MAX]; // player name
  392. int PrefColor; // preferred color index
  393. int ColorIdx; // actual color index
  394. HousesType House; // GDI / NOD
  395. int Blitz; // 1 = AI blitzes
  396. int ObiWan; // 1 = player can see all
  397. int Solo; // 1 = player can play alone
  398. //.....................................................................
  399. // Max allowable # of players & actual # of (human) players
  400. //.....................................................................
  401. int MaxPlayers;
  402. int NumPlayers;
  403. //.....................................................................
  404. // Frame-sync'ing timing variables
  405. // 'MaxAhead' is the number of frames ahead of this one to execute
  406. // a given packet. It's set by the RESPONSE_TIME event.
  407. // 'FrameSendRate' is the # frames between data packets
  408. // 'FrameRateDelay' is the time ticks to wait between frames, for
  409. // smoothing.
  410. //.....................................................................
  411. unsigned long MaxAhead;
  412. unsigned long FrameSendRate;
  413. unsigned long FrameRateDelay;
  414. //.....................................................................
  415. // This flag is set when we've loaded a multiplayer game.
  416. //.....................................................................
  417. int LoadGame;
  418. //.....................................................................
  419. // This flag is set when the modem game saves the game due to a lost
  420. // connection.
  421. //.....................................................................
  422. int EmergencySave;
  423. //.....................................................................
  424. // List of scenarios & their file numbers
  425. //.....................................................................
  426. DynamicVectorClass <char *> Scenarios;
  427. DynamicVectorClass <int> Filenum;
  428. //.....................................................................
  429. // This is the multiplayer messaging system
  430. //.....................................................................
  431. MessageListClass Messages;
  432. IPXAddressClass MessageAddress;
  433. char LastMessage[MAX_MESSAGE_LENGTH];
  434. int WWChat : 1; // 1 = go into special WW Chat mode
  435. //.....................................................................
  436. // This is the multiplayer scorekeeping system
  437. //.....................................................................
  438. MPlayerScoreType Score[MAX_MULTI_NAMES];
  439. int GamesPlayed; // # games played this run
  440. int NumScores; // # active entries in MPlayerScore
  441. int Winner; // index of winner of last game
  442. int CurGame; // index of current game being played
  443. //.....................................................................
  444. // Static arrays
  445. //.....................................................................
  446. static int GColors[];
  447. static int TColors[];
  448. static char Descriptions[100][40];
  449. static int CountMin[2];
  450. static int CountMax[2];
  451. static char * GlobalPacketNames[];
  452. static char * SerialPacketNames[];
  453. //.....................................................................
  454. // For Recording & Playing back a file
  455. //.....................................................................
  456. CCFileClass RecordFile;
  457. int Record : 1;
  458. int Play : 1;
  459. int Attract : 1;
  460. //.....................................................................
  461. // IPX-specific variables
  462. //.....................................................................
  463. int IsBridge; // 1 = we're crossing a bridge
  464. IPXAddressClass BridgeNet; // address of bridge
  465. bool NetStealth; // makes us invisible
  466. bool NetProtect; // keeps others from messaging us
  467. bool NetOpen; // 1 = game is open for joining
  468. char GameName[MPLAYER_NAME_MAX]; // game's name
  469. GlobalPacketType GPacket; // global packet
  470. int GPacketlen; // global packet length
  471. IPXAddressClass GAddress; // address of sender
  472. unsigned short GProductID; // product ID of sender
  473. char MetaPacket[MAX_IPX_PACKET_SIZE]; // packet building buffer
  474. int MetaSize; // size of MetaPacket
  475. DynamicVectorClass <NodeNameType *> Games; // list of games
  476. DynamicVectorClass <NodeNameType *> Players; // list of players
  477. DynamicVectorClass <NodeNameType *> Chat; // list of chat nodes
  478. //.....................................................................
  479. // Modem-specific variables
  480. //.....................................................................
  481. bool ModemService : 1; // 1 = service modem in Call_Back
  482. int CurPhoneIdx; // phone listing index
  483. SerialSettingsType SerialDefaults; // default serial settings
  484. ModemGameType ModemType; // caller or answerer?
  485. DynamicVectorClass<PhoneEntryClass *> PhoneBook;
  486. DynamicVectorClass <char *> InitStrings;
  487. static char * DialMethodCheck[ DIAL_METHODS ];
  488. static char * CallWaitStrings[ CALL_WAIT_STRINGS_NUM ];
  489. //.....................................................................
  490. // For finding Sync Bugs
  491. //.....................................................................
  492. long TrapFrame;
  493. RTTIType TrapObjType;
  494. TrapObjectType TrapObject;
  495. COORD TrapCoord;
  496. void * TrapThis;
  497. CellClass * TrapCell;
  498. int TrapCheckHeap;
  499. };
  500. #endif // SESSION_H
  501. /*************************** end of session.h ******************************/