TCPIP.H 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. ** Command & Conquer(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. /***************************************************************************
  19. ** 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 **
  20. ***************************************************************************
  21. * *
  22. * Project Name : Command & Conquer *
  23. * *
  24. * File Name : TCPIP.CPP *
  25. * *
  26. * Programmer : Steve Tall *
  27. * *
  28. * Start Date : March 11th, 1996 *
  29. * *
  30. * Last Update : March 11th, 1996 [ST] *
  31. * *
  32. *-------------------------------------------------------------------------*
  33. * *
  34. * *
  35. * *
  36. *-------------------------------------------------------------------------*
  37. * Functions: *
  38. * *
  39. * *
  40. * *
  41. * *
  42. * *
  43. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  44. extern bool Server;
  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. #define VSS_ID -1 // ID of the VSS connection.
  76. class TcpipManagerClass {
  77. public:
  78. TcpipManagerClass(void);
  79. ~TcpipManagerClass(void);
  80. BOOL Init(void);
  81. void Start_Server(void);
  82. void Start_Client(void);
  83. void Close_Socket(SOCKET s);
  84. void Message_Handler(HWND window, UINT message, UINT wParam, LONG lParam);
  85. void Copy_To_In_Buffer(int bytes);
  86. int Read(void *buffer, int buffer_len);
  87. void Write(void *buffer, int buffer_len);
  88. BOOL Add_Client(void);
  89. void Close(void);
  90. void Set_Host_Address(char *address);
  91. void Set_Protocol_UDP(BOOL state);
  92. void Clear_Socket_Error(SOCKET socket);
  93. inline BOOL Get_Connected(void) {return (Connected);}
  94. typedef enum ConnectStatusEnum {
  95. CONNECTED_OK = 0,
  96. NOT_CONNECTING,
  97. CONNECTING,
  98. UNABLE_TO_CONNECT_TO_SERVER,
  99. CONTACTING_SERVER,
  100. SERVER_ADDRESS_LOOKUP_FAILED,
  101. RESOLVING_HOST_ADDRESS,
  102. UNABLE_TO_ACCEPT_CLIENT,
  103. UNABLE_TO_CONNECT,
  104. CONNECTION_LOST
  105. } ConnectStatusEnum;
  106. inline ConnectStatusEnum Get_Connection_Status(void) {return (ConnectStatus);}
  107. private:
  108. //...........................................................................
  109. // This structure defines all the info we need about a host
  110. //...........................................................................
  111. typedef struct {
  112. struct in_addr Addr; // address
  113. char DotAddr[16]; // decimal-dot address string
  114. char Name[255]; // character-string name
  115. } HostType;
  116. typedef struct {
  117. char Buffer[WS_INTERNET_BUFFER_LEN];
  118. int DataLength;
  119. bool InUse:1;
  120. } InternetBufferType;
  121. BOOL WinsockInitialised;
  122. WSADATA WinsockInfo;
  123. SOCKET ListenSocket;
  124. SOCKET ConnectSocket;
  125. SOCKET UDPSocket;
  126. IN_ADDR ClientIPAddress;
  127. HANDLE Async;
  128. char HostBuff[MAXGETHOSTSTRUCT];
  129. char ClientName[128];
  130. char ReceiveBuffer[WS_RECEIVE_BUFFER_LEN];
  131. //char InBuffer[WS_IN_BUFFER_LEN];
  132. //int InBufferHead;
  133. //int InBufferTail;
  134. //char OutBuffer[WS_OUT_BUFFER_LEN];
  135. //int OutBufferHead;
  136. //int OutBufferTail;
  137. BOOL IsServer;
  138. BOOL Connected;
  139. HostType Server;
  140. char HostAddress[IP_ADDRESS_MAX];
  141. ConnectStatusEnum ConnectStatus;
  142. BOOL UseUDP;
  143. IN_ADDR UDPIPAddress;
  144. int SocketReceiveBuffer;
  145. int SocketSendBuffer;
  146. InternetBufferType ReceiveBuffers[WS_NUM_TX_BUFFERS];
  147. InternetBufferType TransmitBuffers[WS_NUM_RX_BUFFERS];
  148. int TXBufferHead;
  149. int TXBufferTail;
  150. int RXBufferHead;
  151. int RXBufferTail;
  152. };
  153. extern TcpipManagerClass Winsock;
  154. extern char PlanetWestwoodIPAddress[IP_ADDRESS_MAX];
  155. extern long PlanetWestwoodPortNumber;
  156. extern bool PlanetWestwoodIsHost;
  157. extern int Read_Game_Options(char *);
  158. extern bool UseVirtualSubnetServer;
  159. extern int InternetMaxPlayers;
  160. #define TXT_WINSOCK_CONNECTING 4567+13
  161. #define TXT_WINSOCK_NOT_CONNECTING 4567+14
  162. #define TXT_WINSOCK_UNABLE_TO_CONNECT_TO_SERVER 4567+15
  163. #define TXT_WINSOCK_CONTACTING_SERVER 4567+16
  164. #define TXT_WINSOCK_SERVER_ADDRESS_LOOKUP_FAILED 4567+17
  165. #define TXT_WINSOCK_UNABLE_TO_ACCEPT_CLIENT 4567+18
  166. #define TXT_WINSOCK_UNABLE_TO_CONNECT 4567+19
  167. #define TXT_WINSOCK_CONNECTION_LOST 4567+20
  168. #define TXT_WINSOCK_RESOLVING_HOST_ADDRESS 4567+21
  169. #if (0)
  170. struct tag tGameStatisticsStruct{
  171. char WinnersName[20];
  172. char LosersName[20];
  173. int WinnersTeam;
  174. int LosersTeam;
  175. int WinnersCredits;
  176. int LosersCredits;
  177. int WinnersKills;
  178. int LosersKills;
  179. int ScenarioPlayed;
  180. int GameTimeElapsed;
  181. int VersionNumber;
  182. char TimeDateStamp[12];
  183. } GameStatisticsStruct;
  184. extern GameStatisticsStruct GameStatistics;
  185. #endif //(0)