WSPROTO.H 6.2 KB

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