CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

SESSION.H (22884B)


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