CnC_Remastered_Collection

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

WSPROTO.H (6346B)


      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  ***              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               ***
     18  ***********************************************************************************************
     19  *                                                                                             *
     20  *                 Project Name : Command & Conquer                                            *
     21  *                                                                                             *
     22  *                     $Archive:: /Sun/WSProto.h                                              $*
     23  *                                                                                             *
     24  *                      $Author:: Joe_b                                                       $*
     25  *                                                                                             *
     26  *                     $Modtime:: 8/12/97 5:42p                                               $*
     27  *                                                                                             *
     28  *                    $Revision:: 4                                                          $*
     29  *                                                                                             *
     30  *---------------------------------------------------------------------------------------------*
     31  * Functions:                                                                                  *
     32  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     33 
     34 #ifndef WSPROTO_H
     35 #define WSPROTO_H
     36 
     37 #include	"_WSProto.h"
     38 
     39 /*
     40 ** Include standard Winsock 1.0 header file.
     41 */
     42 #include	<winsock.h>
     43 
     44 /*
     45 ** Misc defines
     46 */
     47 #define WINSOCK_MINOR_VER		1			// Version of Winsock
     48 #define WINSOCK_MAJOR_VER		1        // 	that we require
     49 
     50 //#define WS_RECEIVE_BUFFER_LEN	32768		// Length of our temporary receive buffer. Needs to be more that the max packet size which is about 550 bytes.
     51 //#define SOCKET_BUFFER_SIZE		32768		// Length of winsocks internal buffer.
     52 #define WS_RECEIVE_BUFFER_LEN	1024		// Length of our temporary receive buffer.
     53 #define SOCKET_BUFFER_SIZE		1024*128	// Length of winsocks internal buffer.
     54 
     55 #define PLANET_WESTWOOD_HANDLE_MAX 20	// Max length of a WChat handle
     56 
     57 /*
     58 ** Define events for Winsock callbacks
     59 */
     60 #define WM_IPXASYNCEVENT		(WM_USER + 115)	// IPX socket Async event
     61 #define WM_UDPASYNCEVENT		(WM_USER + 116)	// UDP socket Async event
     62 
     63 
     64 /*
     65 ** Enum to identify the protocols supported by the Winsock interface.
     66 */
     67 typedef enum tProtocolEnum {
     68 	PROTOCOL_NONE,
     69 	PROTOCOL_IPX,
     70 	PROTOCOL_UDP
     71 } ProtocolEnum;
     72 
     73 
     74 
     75 /*
     76 **
     77 ** Class to interface with Winsock. This interface only supports connectionless packet protocols
     78 ** like UDP & IPX. Connection orientated or streaming protocols like TCP are not supported by this
     79 ** class.
     80 **
     81 */
     82 class WinsockInterfaceClass {
     83 
     84 	public:
     85 
     86 		WinsockInterfaceClass(void);
     87 		virtual ~WinsockInterfaceClass(void);
     88 
     89 		bool Init(void);
     90 		void Close(void);
     91 
     92 
     93 		virtual void Close_Socket(void);
     94 		virtual int  Read(void *buffer, int &buffer_len, void *address, int &address_len);
     95 		virtual void WriteTo (void *buffer, int buffer_len, void *address);
     96 		virtual void Broadcast (void *buffer, int buffer_len);
     97 		virtual void Discard_In_Buffers (void);
     98 		virtual void Discard_Out_Buffers (void);
     99 		virtual bool Start_Listening (void);
    100 		virtual void Stop_Listening (void);
    101 		virtual void Clear_Socket_Error(SOCKET socket);
    102 		virtual bool Set_Socket_Options ( void );
    103 		virtual void Set_Broadcast_Address ( void * ) {};
    104 
    105 		virtual ProtocolEnum Get_Protocol (void) {
    106 			return (PROTOCOL_NONE);
    107 		};
    108 
    109 		virtual int Protocol_Event_Message (void) {
    110 			return (0);
    111 		};
    112 
    113 		virtual bool Open_Socket ( SOCKET ) {
    114 			return (false);
    115 		};
    116 
    117 	 	virtual long Message_Handler(HWND, UINT, UINT, LONG) {
    118 			return (1);
    119 		}
    120 
    121 
    122 		typedef enum ConnectStatusEnum {
    123 			CONNECTED_OK = 0,
    124 			NOT_CONNECTING,
    125 			CONNECTING,
    126 			UNABLE_TO_CONNECT_TO_SERVER,
    127 			CONTACTING_SERVER,
    128 			SERVER_ADDRESS_LOOKUP_FAILED,
    129 			RESOLVING_HOST_ADDRESS,
    130 			UNABLE_TO_ACCEPT_CLIENT,
    131 			UNABLE_TO_CONNECT,
    132 			CONNECTION_LOST
    133 		} ConnectStatusEnum;
    134 
    135 		inline ConnectStatusEnum Get_Connection_Status(void) {return (ConnectStatus);}
    136 
    137 	protected:
    138 
    139 		/*
    140 		** This struct contains the information needed for each incoming and outgoing packet.
    141 		** It acts as a temporary control for these packets.
    142 		*/
    143 		typedef struct tWinsockBufferType {
    144 			unsigned char		Address [64];	// Address. IN_ADDR, IPXAddressClass etc.
    145 			int					BufferLen;		// Length of data in buffer
    146 			bool					IsBroadcast;	// Flag to broadcast this packet
    147 			unsigned char		Buffer[1024];	// Buffer to store packet in.
    148 		} WinsockBufferType;
    149 
    150 		/*
    151 		** Array of buffers to temporarily store incoming and outgoing packets.
    152 		*/
    153 		DynamicVectorClass <WinsockBufferType *> InBuffers;
    154 		DynamicVectorClass <WinsockBufferType *> OutBuffers;
    155 
    156 
    157 		/*
    158 		** Is Winsock present and initialised?
    159 		*/
    160 		bool 					WinsockInitialised;
    161 
    162 		/*
    163 		** Socket that communications will take place over.
    164 		*/
    165 		SOCKET				Socket;
    166 
    167 		/*
    168 		** Async object required for callbacks to our message handler.
    169 		*/
    170 		HANDLE				ASync;
    171 
    172 		/*
    173 		** Temporary receive buffer to use when querying Winsock for incoming packets.
    174 		*/
    175 		unsigned char		ReceiveBuffer[WS_RECEIVE_BUFFER_LEN];
    176 
    177 		/*
    178 		** Current connection status.
    179 		*/
    180 		ConnectStatusEnum	ConnectStatus;
    181 };
    182 
    183 
    184 
    185 
    186 
    187 
    188 
    189 #endif	//WSPROTO_H