TCPIP.H 7.5 KB

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