IPXMGR.H 19 KB

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