CnC_Remastered_Collection

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

TCPIP.H (8030B)


      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  **   C O N F I D E N T I A L --- W E S T W O O D    S T U D I O S        **
     19  ***************************************************************************
     20  *                                                                         *
     21  *                 Project Name : Command & Conquer                        *
     22  *                                                                         *
     23  *                    File Name : TCPIP.CPP                                *
     24  *                                                                         *
     25  *                   Programmer : Steve Tall                               *
     26  *                                                                         *
     27  *                   Start Date : March 11th, 1996                         *
     28  *                                                                         *
     29  *                  Last Update : March 11th, 1996 [ST]                    *
     30  *                                                                         *
     31  *-------------------------------------------------------------------------*
     32  *                                                                         *
     33  *                                                                         *
     34  *                                                                         *
     35  *-------------------------------------------------------------------------*
     36  * Functions:                                                              *
     37  *                                                                         *
     38  *                                                                         *
     39  *                                                                         *
     40  *                                                                         *
     41  *                                                                         *
     42  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     43 
     44 extern bool Server;
     45 
     46 #define FORCE_WINSOCK				1
     47 
     48 #define WINSOCK_MINOR_VER		1
     49 #define WINSOCK_MAJOR_VER		1
     50 #define PORTNUM						0x1000
     51 #define UDP_PORT					0x1001
     52 #define WS_INTERNET_BUFFER_LEN  1024
     53 #define WS_NUM_TX_BUFFERS		16		//Must be a power of 2
     54 #define WS_NUM_RX_BUFFERS		16		//MUst be a power of 2
     55 #define WS_RECEIVE_BUFFER_LEN	1024
     56 //#define WS_IN_BUFFER_LEN			8192
     57 //#define WS_OUT_BUFFER_LEN		8192
     58 
     59 #define PLANET_WESTWOOD_HANDLE_MAX 20
     60 #define PLANET_WESTWOOD_PASSWORD_MAX 20
     61 #define IP_ADDRESS_MAX 40
     62 #define PORT_NUMBER_MAX 6
     63 
     64 //...........................................................................
     65 // Custom messages: WM_USER + 1 to WM_USER + 100
     66 // These will be sent to the dialog procedure, for display only.
     67 //...........................................................................
     68 #define	WM_UPDATE_STATUS		(WM_USER + 1)	// update status text
     69 #define	WM_UPDATE_CLIENTS		(WM_USER + 2)	// update client list box
     70 #define	WM_UPDATE_MESSAGE		(WM_USER + 3)	// update received message list
     71 
     72 //...........................................................................
     73 // Messages for Async processing.
     74 //...........................................................................
     75 #define	WM_ACCEPT				(WM_USER + 101)	// client wants to connect
     76 #define	WM_HOSTBYADDRESS		(WM_USER + 102)	// async get host by address
     77 #define	WM_HOSTBYNAME			(WM_USER + 103)	// async get host by name
     78 #define	WM_ASYNCEVENT			(WM_USER + 104)	// other Async event
     79 #define	WM_UDPASYNCEVENT		(WM_USER + 105)	// UDP socket Async event
     80 
     81 
     82 #define	VSS_ID					-1			// ID of the VSS connection.
     83 
     84 class TcpipManagerClass {
     85 
     86 	public:
     87 
     88 		TcpipManagerClass(void);
     89 		~TcpipManagerClass(void);
     90 
     91 		BOOL Init(void);
     92 		void Start_Server(void);
     93 		void Start_Client(void);
     94 		void Close_Socket(SOCKET s);
     95 	 	void Message_Handler(HWND window, UINT message, UINT wParam, LONG lParam);
     96 		void Copy_To_In_Buffer(int bytes);
     97 		int  Read(void *buffer, int buffer_len);
     98 		void Write(void *buffer, int buffer_len);
     99 		BOOL Add_Client(void);
    100 		void Close(void);
    101 		void Set_Host_Address(char *address);
    102 		void Set_Protocol_UDP(BOOL state);
    103 		void Clear_Socket_Error(SOCKET socket);
    104 
    105 		inline BOOL Get_Connected(void) {return (Connected);}
    106 
    107 		typedef enum ConnectStatusEnum {
    108 			CONNECTED_OK = 0,
    109 			NOT_CONNECTING,
    110 			CONNECTING,
    111 			UNABLE_TO_CONNECT_TO_SERVER,
    112 			CONTACTING_SERVER,
    113 			SERVER_ADDRESS_LOOKUP_FAILED,
    114 			RESOLVING_HOST_ADDRESS,
    115 			UNABLE_TO_ACCEPT_CLIENT,
    116 			UNABLE_TO_CONNECT,
    117 			CONNECTION_LOST
    118 		} ConnectStatusEnum;
    119 
    120 		inline ConnectStatusEnum Get_Connection_Status(void) {return (ConnectStatus);}
    121 
    122 	private:
    123 
    124 		//...........................................................................
    125 		// This structure defines all the info we need about a host
    126 		//...........................................................................
    127 		typedef struct {
    128 			struct in_addr Addr;					// address
    129 			char DotAddr[16];						// decimal-dot address string
    130 			char Name[255];						// character-string name
    131 		} HostType;
    132 
    133 		typedef struct {
    134 			char	Buffer[WS_INTERNET_BUFFER_LEN];
    135 			int	DataLength;
    136 			bool	InUse:1;
    137 		} InternetBufferType;
    138 
    139 
    140 		BOOL 					WinsockInitialised;
    141 		WSADATA				WinsockInfo;
    142 		SOCKET				ListenSocket;
    143 		SOCKET				ConnectSocket;
    144 		SOCKET				UDPSocket;
    145 		IN_ADDR				ClientIPAddress;
    146 		HANDLE				Async;
    147 		char					HostBuff[MAXGETHOSTSTRUCT];
    148 		char					ClientName[128];
    149 		char					ReceiveBuffer[WS_RECEIVE_BUFFER_LEN];
    150 		//char					InBuffer[WS_IN_BUFFER_LEN];
    151 		//int					InBufferHead;
    152 		//int					InBufferTail;
    153 		//char					OutBuffer[WS_OUT_BUFFER_LEN];
    154 		//int					OutBufferHead;
    155 		//int					OutBufferTail;
    156 		BOOL					IsServer;
    157 		BOOL					Connected;
    158 		HostType				Server;
    159 		char					HostAddress[IP_ADDRESS_MAX];
    160 		ConnectStatusEnum ConnectStatus;
    161 		BOOL					UseUDP;
    162 		IN_ADDR				UDPIPAddress;
    163 		int					SocketReceiveBuffer;
    164 		int					SocketSendBuffer;
    165 		InternetBufferType ReceiveBuffers[WS_NUM_TX_BUFFERS];
    166 		InternetBufferType TransmitBuffers[WS_NUM_RX_BUFFERS];
    167 		int					TXBufferHead;
    168 		int					TXBufferTail;
    169 		int					RXBufferHead;
    170 		int					RXBufferTail;
    171 
    172 };
    173 
    174 
    175 extern TcpipManagerClass Winsock;
    176 
    177 extern char PlanetWestwoodIPAddress[IP_ADDRESS_MAX];
    178 extern long PlanetWestwoodPortNumber;
    179 extern bool PlanetWestwoodIsHost;
    180 extern int  Read_Game_Options(char *);
    181 extern bool UseVirtualSubnetServer;
    182 extern int  InternetMaxPlayers;
    183 
    184 
    185 #define TXT_WINSOCK_CONNECTING							4567+13
    186 #define TXT_WINSOCK_NOT_CONNECTING					4567+14
    187 #define TXT_WINSOCK_UNABLE_TO_CONNECT_TO_SERVER	4567+15
    188 #define TXT_WINSOCK_CONTACTING_SERVER				4567+16
    189 #define TXT_WINSOCK_SERVER_ADDRESS_LOOKUP_FAILED	4567+17
    190 #define TXT_WINSOCK_UNABLE_TO_ACCEPT_CLIENT		4567+18
    191 #define TXT_WINSOCK_UNABLE_TO_CONNECT				4567+19
    192 #define TXT_WINSOCK_CONNECTION_LOST					4567+20
    193 #define TXT_WINSOCK_RESOLVING_HOST_ADDRESS			4567+21
    194 
    195 
    196 #if (0)
    197 
    198 
    199 struct tag tGameStatisticsStruct{
    200 	char	WinnersName[20];
    201 	char	LosersName[20];
    202 	int	WinnersTeam;
    203 	int	LosersTeam;
    204 	int	WinnersCredits;
    205 	int	LosersCredits;
    206 	int	WinnersKills;
    207 	int	LosersKills;
    208 	int	ScenarioPlayed;
    209 	int	GameTimeElapsed;
    210 	int	VersionNumber;
    211 	char	TimeDateStamp[12];
    212 } GameStatisticsStruct;
    213 
    214 
    215 
    216 
    217 
    218 extern GameStatisticsStruct GameStatistics;
    219 
    220 #endif	//(0)
    221 
    222