WSPROTO.H 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. /***********************************************************************************************
  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. * $Archive:: /Sun/WSProto.h $*
  25. * *
  26. * $Author:: Joe_b $*
  27. * *
  28. * $Modtime:: 8/12/97 5:42p $*
  29. * *
  30. * $Revision:: 4 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef WSPROTO_H
  36. #define WSPROTO_H
  37. #include "_WSProto.h"
  38. /*
  39. ** Include standard Winsock 1.0 header file.
  40. */
  41. #include <winsock.h>
  42. /*
  43. ** Misc defines
  44. */
  45. #define WINSOCK_MINOR_VER 1 // Version of Winsock
  46. #define WINSOCK_MAJOR_VER 1 // that we require
  47. //#define WS_RECEIVE_BUFFER_LEN 32768 // Length of our temporary receive buffer. Needs to be more that the max packet size which is about 550 bytes.
  48. //#define SOCKET_BUFFER_SIZE 32768 // Length of winsocks internal buffer.
  49. #define WS_RECEIVE_BUFFER_LEN 1024 // Length of our temporary receive buffer.
  50. #define SOCKET_BUFFER_SIZE 1024*128 // Length of winsocks internal buffer.
  51. #define PLANET_WESTWOOD_HANDLE_MAX 20 // Max length of a WChat handle
  52. /*
  53. ** Define events for Winsock callbacks
  54. */
  55. #define WM_IPXASYNCEVENT (WM_USER + 115) // IPX socket Async event
  56. #define WM_UDPASYNCEVENT (WM_USER + 116) // UDP socket Async event
  57. /*
  58. ** Enum to identify the protocols supported by the Winsock interface.
  59. */
  60. typedef enum tProtocolEnum {
  61. PROTOCOL_NONE,
  62. PROTOCOL_IPX,
  63. PROTOCOL_UDP
  64. } ProtocolEnum;
  65. /*
  66. **
  67. ** Class to interface with Winsock. This interface only supports connectionless packet protocols
  68. ** like UDP & IPX. Connection orientated or streaming protocols like TCP are not supported by this
  69. ** class.
  70. **
  71. */
  72. class WinsockInterfaceClass {
  73. public:
  74. WinsockInterfaceClass(void);
  75. virtual ~WinsockInterfaceClass(void);
  76. bool Init(void);
  77. void Close(void);
  78. virtual void Close_Socket(void);
  79. virtual int Read(void *buffer, int &buffer_len, void *address, int &address_len);
  80. virtual void WriteTo (void *buffer, int buffer_len, void *address);
  81. virtual void Broadcast (void *buffer, int buffer_len);
  82. virtual void Discard_In_Buffers (void);
  83. virtual void Discard_Out_Buffers (void);
  84. virtual bool Start_Listening (void);
  85. virtual void Stop_Listening (void);
  86. virtual void Clear_Socket_Error(SOCKET socket);
  87. virtual bool Set_Socket_Options ( void );
  88. virtual void Set_Broadcast_Address ( void * ) {};
  89. virtual ProtocolEnum Get_Protocol (void) {
  90. return (PROTOCOL_NONE);
  91. };
  92. virtual int Protocol_Event_Message (void) {
  93. return (0);
  94. };
  95. virtual bool Open_Socket ( SOCKET ) {
  96. return (false);
  97. };
  98. virtual long Message_Handler(HWND, UINT, UINT, LONG) {
  99. return (1);
  100. }
  101. typedef enum ConnectStatusEnum {
  102. CONNECTED_OK = 0,
  103. NOT_CONNECTING,
  104. CONNECTING,
  105. UNABLE_TO_CONNECT_TO_SERVER,
  106. CONTACTING_SERVER,
  107. SERVER_ADDRESS_LOOKUP_FAILED,
  108. RESOLVING_HOST_ADDRESS,
  109. UNABLE_TO_ACCEPT_CLIENT,
  110. UNABLE_TO_CONNECT,
  111. CONNECTION_LOST
  112. } ConnectStatusEnum;
  113. inline ConnectStatusEnum Get_Connection_Status(void) {return (ConnectStatus);}
  114. protected:
  115. /*
  116. ** This struct contains the information needed for each incoming and outgoing packet.
  117. ** It acts as a temporary control for these packets.
  118. */
  119. typedef struct tWinsockBufferType {
  120. unsigned char Address [64]; // Address. IN_ADDR, IPXAddressClass etc.
  121. int BufferLen; // Length of data in buffer
  122. bool IsBroadcast; // Flag to broadcast this packet
  123. unsigned char Buffer[1024]; // Buffer to store packet in.
  124. } WinsockBufferType;
  125. /*
  126. ** Array of buffers to temporarily store incoming and outgoing packets.
  127. */
  128. DynamicVectorClass <WinsockBufferType *> InBuffers;
  129. DynamicVectorClass <WinsockBufferType *> OutBuffers;
  130. /*
  131. ** Is Winsock present and initialised?
  132. */
  133. bool WinsockInitialised;
  134. /*
  135. ** Socket that communications will take place over.
  136. */
  137. SOCKET Socket;
  138. /*
  139. ** Async object required for callbacks to our message handler.
  140. */
  141. HANDLE ASync;
  142. /*
  143. ** Temporary receive buffer to use when querying Winsock for incoming packets.
  144. */
  145. unsigned char ReceiveBuffer[WS_RECEIVE_BUFFER_LEN];
  146. /*
  147. ** Current connection status.
  148. */
  149. ConnectStatusEnum ConnectStatus;
  150. };
  151. #endif //WSPROTO_H