TCPIP.H 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. ** Command & Conquer Red Alert(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. /* $Header: /CounterStrike/TCPIP.H 1 3/03/97 10:25a Joe_bostic $ */
  19. /***************************************************************************
  20. ** 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 **
  21. ***************************************************************************
  22. * *
  23. * Project Name : Command & Conquer *
  24. * *
  25. * File Name : TCPIP.CPP *
  26. * *
  27. * Programmer : Steve Tall *
  28. * *
  29. * Start Date : March 11th, 1996 *
  30. * *
  31. * Last Update : March 11th, 1996 [ST] *
  32. * *
  33. *-------------------------------------------------------------------------*
  34. * *
  35. * *
  36. * *
  37. *-------------------------------------------------------------------------*
  38. * Functions: *
  39. * *
  40. * *
  41. * *
  42. * *
  43. * *
  44. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  45. #ifdef WIN32
  46. #ifndef WOLAPI_INTEGRATION
  47. extern bool Server;
  48. #endif
  49. #define FORCE_WINSOCK 1
  50. #define WINSOCK_MINOR_VER 1
  51. #define WINSOCK_MAJOR_VER 1
  52. #define PORTNUM 0x1000
  53. #define UDP_PORT 0x1001
  54. #define WS_INTERNET_BUFFER_LEN 1024
  55. #define WS_NUM_TX_BUFFERS 16 //Must be a power of 2
  56. #define WS_NUM_RX_BUFFERS 16 //MUst be a power of 2
  57. #define WS_RECEIVE_BUFFER_LEN 1024
  58. //#define WS_IN_BUFFER_LEN 8192
  59. //#define WS_OUT_BUFFER_LEN 8192
  60. #define PLANET_WESTWOOD_HANDLE_MAX 20
  61. #define PLANET_WESTWOOD_PASSWORD_MAX 20
  62. #define IP_ADDRESS_MAX 40
  63. #define PORT_NUMBER_MAX 6
  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. // Messages for Async processing.
  73. //...........................................................................
  74. #define WM_ACCEPT (WM_USER + 101) // client wants to connect
  75. #define WM_HOSTBYADDRESS (WM_USER + 102) // async get host by address
  76. #define WM_HOSTBYNAME (WM_USER + 103) // async get host by name
  77. #define WM_ASYNCEVENT (WM_USER + 104) // other Async event
  78. #define WM_UDPASYNCEVENT (WM_USER + 105) // UDP socket Async event
  79. class TcpipManagerClass {
  80. public:
  81. TcpipManagerClass(void);
  82. ~TcpipManagerClass(void);
  83. BOOL Init(void);
  84. void Start_Server(void);
  85. void Start_Client(void);
  86. void Close_Socket(SOCKET s);
  87. void Message_Handler(HWND window, UINT message, UINT wParam, LONG lParam);
  88. void Copy_To_In_Buffer(int bytes);
  89. int Read(void *buffer, int buffer_len);
  90. void Write(void *buffer, int buffer_len);
  91. BOOL Add_Client(void);
  92. void Close(void);
  93. void Set_Host_Address(char *address);
  94. void Set_Protocol_UDP(BOOL state);
  95. void Clear_Socket_Error(SOCKET socket);
  96. inline BOOL Get_Connected(void) {return (Connected);}
  97. typedef enum ConnectStatusEnum {
  98. CONNECTED_OK = 0,
  99. NOT_CONNECTING,
  100. CONNECTING,
  101. UNABLE_TO_CONNECT_TO_SERVER,
  102. CONTACTING_SERVER,
  103. SERVER_ADDRESS_LOOKUP_FAILED,
  104. RESOLVING_HOST_ADDRESS,
  105. UNABLE_TO_ACCEPT_CLIENT,
  106. UNABLE_TO_CONNECT,
  107. CONNECTION_LOST
  108. } ConnectStatusEnum;
  109. inline ConnectStatusEnum Get_Connection_Status(void) {return (ConnectStatus);}
  110. private:
  111. //...........................................................................
  112. // This structure defines all the info we need about a host
  113. //...........................................................................
  114. typedef struct {
  115. struct in_addr Addr; // address
  116. char DotAddr[16]; // decimal-dot address string
  117. char Name[255]; // character-string name
  118. } HostType;
  119. typedef struct {
  120. char Buffer[WS_INTERNET_BUFFER_LEN];
  121. int DataLength;
  122. bool InUse:1;
  123. } InternetBufferType;
  124. BOOL WinsockInitialised;
  125. WSADATA WinsockInfo;
  126. SOCKET ListenSocket;
  127. SOCKET ConnectSocket;
  128. SOCKET UDPSocket;
  129. IN_ADDR ClientIPAddress;
  130. HANDLE Async;
  131. char HostBuff[MAXGETHOSTSTRUCT];
  132. char ClientName[128];
  133. char ReceiveBuffer[WS_RECEIVE_BUFFER_LEN];
  134. //char InBuffer[WS_IN_BUFFER_LEN];
  135. //int InBufferHead;
  136. //int InBufferTail;
  137. //char OutBuffer[WS_OUT_BUFFER_LEN];
  138. //int OutBufferHead;
  139. //int OutBufferTail;
  140. BOOL IsServer;
  141. BOOL Connected;
  142. HostType Server;
  143. char HostAddress[IP_ADDRESS_MAX];
  144. ConnectStatusEnum ConnectStatus;
  145. BOOL UseUDP;
  146. IN_ADDR UDPIPAddress;
  147. int SocketReceiveBuffer;
  148. int SocketSendBuffer;
  149. InternetBufferType ReceiveBuffers[WS_NUM_TX_BUFFERS];
  150. InternetBufferType TransmitBuffers[WS_NUM_RX_BUFFERS];
  151. int TXBufferHead;
  152. int TXBufferTail;
  153. int RXBufferHead;
  154. int RXBufferTail;
  155. };
  156. extern TcpipManagerClass Winsock;
  157. extern char PlanetWestwoodIPAddress[IP_ADDRESS_MAX];
  158. extern long PlanetWestwoodPortNumber;
  159. extern bool PlanetWestwoodIsHost;
  160. extern int Read_Game_Options(char *);
  161. #define TXT_WINSOCK_CONNECTING 4567+13
  162. #define TXT_WINSOCK_NOT_CONNECTING 4567+14
  163. #define TXT_WINSOCK_UNABLE_TO_CONNECT_TO_SERVER 4567+15
  164. #define TXT_WINSOCK_CONTACTING_SERVER 4567+16
  165. #define TXT_WINSOCK_SERVER_ADDRESS_LOOKUP_FAILED 4567+17
  166. #define TXT_WINSOCK_UNABLE_TO_ACCEPT_CLIENT 4567+18
  167. #define TXT_WINSOCK_UNABLE_TO_CONNECT 4567+19
  168. #define TXT_WINSOCK_CONNECTION_LOST 4567+20
  169. #define TXT_WINSOCK_RESOLVING_HOST_ADDRESS 4567+21
  170. #endif //WIN32