TCPIP.H 7.8 KB

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