IPXMGR.H 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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/IPXMGR.H 1 3/03/97 10:24a 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 : IPXMGR.H *
  22. * *
  23. * Programmer : Bill Randolph *
  24. * *
  25. * Start Date : December 19, 1994 *
  26. * *
  27. * Last Update : April 3, 1995 [BR] *
  28. * *
  29. *-------------------------------------------------------------------------*
  30. * *
  31. * This is the Connection Manager for IPX network communications. It *
  32. * creates, manages, & orchestrates multiple IPX connections, as well as *
  33. * the "global" connection ("Global Channel"), which can talk to any *
  34. * system on the net. *
  35. * *
  36. * Use the Global Channel to query systems for their names, ID's, & *
  37. * IPX addresses. Then, create a Private Connection with each system *
  38. * that joins your game, and use the Private Channel to send game packets *
  39. * (the private channel will perform somewhat faster, & gives you better *
  40. * control than the Global Channel; it can detect retries, and the Global *
  41. * Channel can't). *
  42. * *
  43. * HOW THIS CLASS WORKS: *
  44. * This class has to set up an IPX Event Service Routine in low (DOS) *
  45. * memory. So, it uses DPMI to allocate & lock a chunk of DOS memory; *
  46. * this memory is used for all incoming packet buffers, the outgoing *
  47. * packet buffer, and the actual code for the event handler. The real- *
  48. * mode handler code & this class share a portion of memory that's mapped *
  49. * into a "RealModeDataType" structure. As packets come in, the handler *
  50. * points IPX to the next available packet buffer & restarts listening; *
  51. * it sets a flag to tell this class that a packet is present at that *
  52. * buffer slot. This class must read all the packets & determine which *
  53. * connection they go with (the Global Channel, or one of the Private *
  54. * Channels). This parsing is done in the Service routine for this class. *
  55. * *
  56. * Constructor: Just inits some variables, checks to see if IPX is there *
  57. * Destructor: Complete shutdown; stops IPX listening, frees all memory *
  58. * Init: Should only be called once (but can be called more); *
  59. * allocates all memory, creates the Global Channel *
  60. * connection, starts IPX listening. By not placing this *
  61. * step in the constructor, the app can control when *
  62. * listening actually starts; also, you don't get a bunch *
  63. * of allocations just by declaring an IPXManagerClass *
  64. * instance. You have to call Init() for the allocations *
  65. * to occur. *
  66. * Connection utilities: Create & manage Private Connections. Each *
  67. * connection has its own IPX address, numerical ID, and *
  68. * character name (presumably the name of the other *
  69. * player). *
  70. * Send/Get_Global_Message: adds a packet to the Global Connection queue, *
  71. * or reads from the queue. The caller should check the *
  72. * ProductID value from returned packets to be sure it's *
  73. * talking to the right product. *
  74. * Send/Get_Private_Message: adds a packet to a Private Connection queue, *
  75. * or reads from the queue *
  76. * Service: Checks the Real-Mode-Memory packet array to see if any *
  77. * new packets have come in; if they have, it parses them *
  78. * & distributes them to the right connection queue. The *
  79. * queue's Service routine handles ACK'ing or Resending *
  80. * packets. *
  81. * *
  82. * Here's a memory map of the Real-Mode memory block. 'N' is the number *
  83. * of packet buffers allocated in low memory: *
  84. * *
  85. * ---------------------------------- *
  86. * | Shared-memory data | *
  87. * |--------------------------------| *
  88. * | Real-mode event handler code | *
  89. * |--------------------------------| *
  90. * | IPX Header & Packet Buffer 0 | *
  91. * |--------------------------------| *
  92. * | IPX Header & Packet Buffer 1 | *
  93. * |--------------------------------| *
  94. * | IPX Header & Packet Buffer 2 | *
  95. * |--------------------------------| *
  96. * | . . . | *
  97. * |--------------------------------| *
  98. * | IPX Header & Packet Buffer N | *
  99. * |--------------------------------| *
  100. * | Send Event Control Block | *
  101. * |--------------------------------| *
  102. * | Send IPX Header | *
  103. * |--------------------------------| *
  104. * | Send Packet Buffer | *
  105. * |--------------------------------| *
  106. * | Flags Array [N] | *
  107. * ---------------------------------- *
  108. * *
  109. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  110. #ifndef IPXMANAGER_H
  111. #define IPXMANAGER_H
  112. /*
  113. ********************************* Includes **********************************
  114. */
  115. #include "ipxconn.h"
  116. #include "ipxgconn.h"
  117. #include "ipxaddr.h"
  118. #include "connmgr.h"
  119. /*
  120. ********************************** Defines **********************************
  121. */
  122. /*---------------------------------------------------------------------------
  123. This is Virgin Interactive Entertainment's registered socket ID.
  124. ---------------------------------------------------------------------------*/
  125. #define VIRGIN_SOCKET 0x8813
  126. /*---------------------------------------------------------------------------
  127. This is the maximum number of IPX connections supported. Just change this
  128. value to support more.
  129. ---------------------------------------------------------------------------*/
  130. #define CONNECT_MAX 7
  131. /*---------------------------------------------------------------------------
  132. These routines report the location & length of the real-mode routine, as
  133. it's stored in protected-mode memory.
  134. ---------------------------------------------------------------------------*/
  135. extern "C" {
  136. void * __cdecl Get_RM_IPX_Address(void);
  137. long __cdecl Get_RM_IPX_Size(void);
  138. }
  139. /*
  140. ***************************** Class Declaration *****************************
  141. */
  142. class IPXManagerClass : public ConnManClass
  143. {
  144. /*
  145. ---------------------------- Public Interface ----------------------------
  146. */
  147. public:
  148. /*.....................................................................
  149. Constructor/destructor.
  150. .....................................................................*/
  151. IPXManagerClass (int glb_maxlen, int pvt_maxlen, int glb_num_packets,
  152. int pvt_num_packets, unsigned short socket, unsigned short product_id);
  153. virtual ~IPXManagerClass (); // stop listening
  154. /*.....................................................................
  155. Initialization routines.
  156. .....................................................................*/
  157. int Init (void);
  158. int Is_IPX(void);
  159. virtual void Set_Timing (unsigned long retrydelta, unsigned long maxretries,
  160. unsigned long timeout);
  161. void Set_Bridge(NetNumType bridge);
  162. /*.....................................................................
  163. These routines control creation of the "Connections" (data queues) for
  164. each remote system.
  165. .....................................................................*/
  166. int Create_Connection(int id, char *name, IPXAddressClass *address);
  167. int Delete_Connection(int id);
  168. virtual int Num_Connections(void);
  169. virtual int Connection_ID(int index);
  170. char *Connection_Name(int id);
  171. IPXAddressClass * Connection_Address(int id);
  172. virtual int Connection_Index(int id);
  173. void Set_Connection_Parms(int index, int id, char *name);
  174. /*.....................................................................
  175. This is how the application sends & receives messages.
  176. .....................................................................*/
  177. int Send_Global_Message (void *buf, int buflen, int ack_req = 0,
  178. IPXAddressClass *address = NULL);
  179. int Get_Global_Message (void *buf, int *buflen, IPXAddressClass *address,
  180. unsigned short *product_id);
  181. virtual int Send_Private_Message (void *buf, int buflen,
  182. int ack_req = 1, int conn_id = CONNECTION_NONE);
  183. virtual int Get_Private_Message (void *buf, int *buflen, int *conn_id);
  184. /*.....................................................................
  185. The main polling routine; should be called as often as possible.
  186. .....................................................................*/
  187. virtual int Service (void);
  188. /*.....................................................................
  189. This routine reports which connection has an error on it.
  190. .....................................................................*/
  191. int Get_Bad_Connection(void);
  192. /*.....................................................................
  193. Queue utility routines. The application can determine how many
  194. messages are in the send/receive queues.
  195. .....................................................................*/
  196. virtual int Global_Num_Send(void);
  197. virtual int Global_Num_Receive(void);
  198. virtual int Private_Num_Send(int id = CONNECTION_NONE);
  199. virtual int Private_Num_Receive(int id = CONNECTION_NONE);
  200. /*.....................................................................
  201. This routine changes the socket ID assigned the IPX Manager when it
  202. was constructed. Do not call this function after calling Init()!
  203. The Socket ID should be known by both ends of the communications before
  204. any packets are sent.
  205. .....................................................................*/
  206. void Set_Socket(unsigned short socket);
  207. /*.....................................................................
  208. Routines to return the largest average queue response time, and to
  209. reset the response time for all queues.
  210. .....................................................................*/
  211. virtual unsigned long Response_Time(void);
  212. unsigned long Global_Response_Time(void);
  213. virtual void Reset_Response_Time(void);
  214. /*.....................................................................
  215. This routine returns a pointer to the oldest non-ACK'd buffer I've sent.
  216. .....................................................................*/
  217. void * Oldest_Send(void);
  218. /*.....................................................................
  219. Debug routines
  220. .....................................................................*/
  221. virtual void Configure_Debug(int index, int type_offset, int type_size,
  222. char **names, int namestart, int namecount);
  223. virtual void Mono_Debug_Print(int index, int refresh = 0);
  224. /*
  225. --------------------------- Private Interface ----------------------------
  226. */
  227. private:
  228. /*.....................................................................
  229. These routines allocate & free the DOS Real-mode memory block.
  230. .....................................................................*/
  231. int Alloc_RealMode_Mem(void);
  232. int Free_RealMode_Mem(void);
  233. /*.....................................................................
  234. Misc variables
  235. .....................................................................*/
  236. unsigned int IPXStatus : 1; // 0 = no IPX, 1 = IPX found
  237. unsigned int Listening : 1; // 1 = Listening is on
  238. unsigned int RealMemAllocd : 1; // 1 = Real-mode memory has been alloc'd
  239. /*.....................................................................
  240. Packet Sizes, used for allocating real-mode memory
  241. .....................................................................*/
  242. int Glb_MaxPacketLen; // Global Channel maximum packet size
  243. int Glb_NumPackets; // # Global send/receive packets
  244. int Pvt_MaxPacketLen; // Private Channel maximum packet size
  245. int Pvt_NumPackets; // # Private send/receive packets
  246. /*.....................................................................
  247. The ProductID is used in the Global Channel's packet header, and it's
  248. used for the Private Channels' Magic Number.
  249. .....................................................................*/
  250. unsigned short ProductID; // product ID
  251. /*.....................................................................
  252. The Socket ID, and local Novell Connection Number
  253. .....................................................................*/
  254. unsigned short Socket; // Our socket ID for sending/receiving
  255. int ConnectionNum; // local connection #, 0=not logged in
  256. /*.....................................................................
  257. Array of connection queues
  258. .....................................................................*/
  259. IPXConnClass * Connection[CONNECT_MAX]; // array of connection object ptrs
  260. int NumConnections; // # connection objects in use
  261. IPXGlobalConnClass *GlobalChannel; // the Global Channel
  262. /*.....................................................................
  263. Current queue for polling for received packets
  264. .....................................................................*/
  265. int CurConnection;
  266. /*.....................................................................
  267. Timing parameters for all connections
  268. .....................................................................*/
  269. unsigned long RetryDelta;
  270. unsigned long MaxRetries;
  271. unsigned long Timeout;
  272. /*---------------------------------------------------------------------
  273. Real-mode memory pointers and such
  274. ---------------------------------------------------------------------*/
  275. /*.....................................................................
  276. This is a structure that mirrors data in real-mode memory:
  277. .....................................................................*/
  278. typedef struct {
  279. short Marker1; // the byte ID marker
  280. ECBType ListenECB; // the Listening ECB
  281. short NumBufs; // # of buffers we're giving to the handler
  282. char *BufferFlags; // array of buffer-avail flags
  283. short PacketSize; // size of packet including IPX header
  284. IPXHeaderType *FirstPacketBuf; // ptr to 1st packet buffer
  285. short CurIndex; // handler's current packet index
  286. IPXHeaderType *CurPacketBuf; // handler's current packet buf
  287. short FuncOffset; // contains offset of code
  288. char Semaphore; // prevents re-entrancy
  289. short ReEntrantCount; // times we've been called re-entrantly
  290. short StackPtr; // real-mode stack pointer
  291. short StackSeg; // real-mode stack segment
  292. short StackPtr_int; // internal stack pointer
  293. short StackSeg_int; // internal stack segment
  294. short StackCheck; // stack check value (0x1234)
  295. short Stack[256]; // actual stack space
  296. short StackSpace; // label for top of stack
  297. short Marker2; // the byte ID marker
  298. } RealModeDataType;
  299. /*.....................................................................
  300. The number & size of packet buffers in low memory
  301. .....................................................................*/
  302. int NumBufs; // # packet buffers allocated
  303. int PacketLen; // size of packet without IPX header
  304. int FullPacketLen; // size of packet including IPX header
  305. /*.....................................................................
  306. Selector & Segment of the DOS allocation;
  307. Size of the allocation;
  308. Ptr to the real-mode assembly data area
  309. .....................................................................*/
  310. unsigned short Selector; // selector of DOS allocation pointer
  311. unsigned short Segment; // real-mode segment of DOS allocation
  312. int RealMemSize; // size of real mode memory allocated
  313. RealModeDataType *RealModeData; // assembly routine & its data
  314. /*.....................................................................
  315. This is a real-mode pointer to the address of the real-mode assembly
  316. entry point.
  317. .....................................................................*/
  318. long Handler;
  319. /*.....................................................................
  320. Event Control Block for listening; contained within the real-mode
  321. assembly routine's data area
  322. .....................................................................*/
  323. ECBType *ListenECB; // ECB for listening
  324. /*.....................................................................
  325. ptr to the 1st header & data buffers in the packet buffer array
  326. .....................................................................*/
  327. IPXHeaderType *FirstHeaderBuf; // array of packet headers & buffers
  328. char *FirstDataBuf; // 1st data buffer area
  329. /*.....................................................................
  330. Current packet index & ptrs for parsing packets
  331. .....................................................................*/
  332. int CurIndex; // Current packet index, for reading
  333. IPXHeaderType *CurHeaderBuf; // Current packet ptr, for reading
  334. char *CurDataBuf; // Current actual data ptr
  335. /*.....................................................................
  336. ECB, header, & buffer for sending
  337. .....................................................................*/
  338. ECBType *SendECB; // ECB for sending
  339. IPXHeaderType *SendHeader; // Header for sending
  340. char *SendBuf; // buffer for sending
  341. /*.....................................................................
  342. Flags indicating whether a buffer contains data or not (1 = full)
  343. The IPXManager must clear this flag; the real-mode routine will set it.
  344. .....................................................................*/
  345. char *BufferFlags; // array of rx-buffer-avail flags
  346. /*.....................................................................
  347. Various Statistics
  348. .....................................................................*/
  349. int SendOverflows;
  350. int ReceiveOverflows;
  351. int BadConnection;
  352. };
  353. #endif
  354. /*************************** end of ipxmgr.h *******************************/