TCPIP.H (7663B)
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 /* $Header: /CounterStrike/TCPIP.H 1 3/03/97 10:25a Joe_bostic $ */ 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 #ifdef WIN32 45 46 #ifndef WOLAPI_INTEGRATION 47 extern bool Server; 48 #endif 49 50 #define FORCE_WINSOCK 1 51 52 #define WINSOCK_MINOR_VER 1 53 #define WINSOCK_MAJOR_VER 1 54 #define PORTNUM 0x1000 55 #define UDP_PORT 0x1001 56 #define WS_INTERNET_BUFFER_LEN 1024 57 #define WS_NUM_TX_BUFFERS 16 //Must be a power of 2 58 #define WS_NUM_RX_BUFFERS 16 //MUst be a power of 2 59 #define WS_RECEIVE_BUFFER_LEN 1024 60 //#define WS_IN_BUFFER_LEN 8192 61 //#define WS_OUT_BUFFER_LEN 8192 62 63 #define PLANET_WESTWOOD_HANDLE_MAX 20 64 #define PLANET_WESTWOOD_PASSWORD_MAX 20 65 #define IP_ADDRESS_MAX 40 66 #define PORT_NUMBER_MAX 6 67 68 //........................................................................... 69 // Custom messages: WM_USER + 1 to WM_USER + 100 70 // These will be sent to the dialog procedure, for display only. 71 //........................................................................... 72 #define WM_UPDATE_STATUS (WM_USER + 1) // update status text 73 #define WM_UPDATE_CLIENTS (WM_USER + 2) // update client list box 74 #define WM_UPDATE_MESSAGE (WM_USER + 3) // update received message list 75 76 //........................................................................... 77 // Messages for Async processing. 78 //........................................................................... 79 #define WM_ACCEPT (WM_USER + 101) // client wants to connect 80 #define WM_HOSTBYADDRESS (WM_USER + 102) // async get host by address 81 #define WM_HOSTBYNAME (WM_USER + 103) // async get host by name 82 #define WM_ASYNCEVENT (WM_USER + 104) // other Async event 83 #define WM_UDPASYNCEVENT (WM_USER + 105) // UDP socket Async event 84 85 86 class TcpipManagerClass { 87 88 public: 89 90 TcpipManagerClass(void); 91 ~TcpipManagerClass(void); 92 93 BOOL Init(void); 94 void Start_Server(void); 95 void Start_Client(void); 96 void Close_Socket(SOCKET s); 97 void Message_Handler(HWND window, UINT message, UINT wParam, LONG lParam); 98 void Copy_To_In_Buffer(int bytes); 99 int Read(void *buffer, int buffer_len); 100 void Write(void *buffer, int buffer_len); 101 BOOL Add_Client(void); 102 void Close(void); 103 void Set_Host_Address(char *address); 104 void Set_Protocol_UDP(BOOL state); 105 void Clear_Socket_Error(SOCKET socket); 106 107 inline BOOL Get_Connected(void) {return (Connected);} 108 109 typedef enum ConnectStatusEnum { 110 CONNECTED_OK = 0, 111 NOT_CONNECTING, 112 CONNECTING, 113 UNABLE_TO_CONNECT_TO_SERVER, 114 CONTACTING_SERVER, 115 SERVER_ADDRESS_LOOKUP_FAILED, 116 RESOLVING_HOST_ADDRESS, 117 UNABLE_TO_ACCEPT_CLIENT, 118 UNABLE_TO_CONNECT, 119 CONNECTION_LOST 120 } ConnectStatusEnum; 121 122 inline ConnectStatusEnum Get_Connection_Status(void) {return (ConnectStatus);} 123 124 private: 125 126 //........................................................................... 127 // This structure defines all the info we need about a host 128 //........................................................................... 129 typedef struct { 130 struct in_addr Addr; // address 131 char DotAddr[16]; // decimal-dot address string 132 char Name[255]; // character-string name 133 } HostType; 134 135 typedef struct { 136 char Buffer[WS_INTERNET_BUFFER_LEN]; 137 int DataLength; 138 bool InUse:1; 139 } InternetBufferType; 140 141 142 BOOL WinsockInitialised; 143 WSADATA WinsockInfo; 144 SOCKET ListenSocket; 145 SOCKET ConnectSocket; 146 SOCKET UDPSocket; 147 IN_ADDR ClientIPAddress; 148 HANDLE Async; 149 char HostBuff[MAXGETHOSTSTRUCT]; 150 char ClientName[128]; 151 char ReceiveBuffer[WS_RECEIVE_BUFFER_LEN]; 152 //char InBuffer[WS_IN_BUFFER_LEN]; 153 //int InBufferHead; 154 //int InBufferTail; 155 //char OutBuffer[WS_OUT_BUFFER_LEN]; 156 //int OutBufferHead; 157 //int OutBufferTail; 158 BOOL IsServer; 159 BOOL Connected; 160 HostType Server; 161 char HostAddress[IP_ADDRESS_MAX]; 162 ConnectStatusEnum ConnectStatus; 163 BOOL UseUDP; 164 IN_ADDR UDPIPAddress; 165 int SocketReceiveBuffer; 166 int SocketSendBuffer; 167 InternetBufferType ReceiveBuffers[WS_NUM_TX_BUFFERS]; 168 InternetBufferType TransmitBuffers[WS_NUM_RX_BUFFERS]; 169 int TXBufferHead; 170 int TXBufferTail; 171 int RXBufferHead; 172 int RXBufferTail; 173 174 }; 175 176 177 extern TcpipManagerClass Winsock; 178 179 extern char PlanetWestwoodIPAddress[IP_ADDRESS_MAX]; 180 extern long PlanetWestwoodPortNumber; 181 extern bool PlanetWestwoodIsHost; 182 extern int Read_Game_Options(char *); 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 197 #endif //WIN32