TENMGR.CPP 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118
  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. * *
  16. * Project Name : Command & Conquer *
  17. * *
  18. * File Name : TENMGR.CPP *
  19. * *
  20. * Programmer : Bill R. Randolph *
  21. * *
  22. * Start Date : 06/26/96 *
  23. * *
  24. * Last Update : July 22, 1996 [BRR] *
  25. * *
  26. *-------------------------------------------------------------------------*
  27. * Functions: *
  28. * TenConnManClass::TenConnManClass -- Class constructor *
  29. * TenConnManClass::~TenConnManClass -- Class destructor *
  30. * TenConnManClass::Init -- Inits TEN *
  31. * TenConnManClass::Service -- Service routine *
  32. * TenConnManClass::Send_Private_Message -- Sends a "private" message *
  33. * TenConnManClass::Get_Private_Message -- Gets the next private message *
  34. * TenConnManClass::Send_Global_Message -- Sends a "global" message *
  35. * TenConnManClass::Get_Global_Message -- Gets next global message *
  36. * TenConnManClass::Num_Connections -- Reports # connections *
  37. * TenConnManClass::Connection_ID -- Reports a connection's ID *
  38. * TenConnManClass::Connection_Index -- Gets a connection's index *
  39. * TenConnManClass::Create_Connection -- Creates a new connection *
  40. * TenConnManClass::Delete_Connection -- Deletes a connection *
  41. * TenConnManClass::Connection_Name -- Reports a connection's name *
  42. * TenConnManClass::Connection_Address -- Gets a connection's "address" *
  43. * TenConnManClass::Global_Num_Send -- Reports # outgoing packets *
  44. * TenConnManClass::Global_Num_Receive -- Reports # incoming packets *
  45. * TenConnManClass::Private_Num_Send -- Reports # outgoing packets *
  46. * TenConnManClass::Private_Num_Receive -- Reports # incoming packets *
  47. * TenConnManClass::Flush_All -- Flushes all packets *
  48. * TenConnManClass::Reset_Response_Time -- Does nothing *
  49. * TenConnManClass::Response_Time -- Reports response time *
  50. * TenConnManClass::Set_Timing -- Does nothing *
  51. * TenConnManClass::Configure_Debug -- Does nothing *
  52. * TenConnManClass::Mono_Debug_Print -- Does nothing *
  53. * terminateApp -- Callback: app terminates on error *
  54. * debugMessage -- outputs debug message *
  55. * doAlert -- Outputs debug message *
  56. * doPregameHook -- Callback: game is starting *
  57. * doIncomingPacket -- Callback: packet has arrived *
  58. * doPlayerJoins -- Callback: player joins *
  59. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  60. #include "function.h"
  61. #ifdef WIN32
  62. #define WINDOWS
  63. #endif
  64. #if(TEN)
  65. #include "ten.h"
  66. //**************************************************************************
  67. // Constants
  68. //
  69. const unsigned char kGlobalChannelFlag = 0x80;
  70. const int kMaxPlayers = 8;
  71. //**************************************************************************
  72. // Functions
  73. //
  74. static void terminateApp(void);
  75. static void debugMessage(int msgLevel, char *msg);
  76. static void doAlert(int, int, char *);
  77. static void doPregameHook(char * joinType, char *, char *,
  78. char *, char *, char *);
  79. void doIncomingPacket(int addr, void *buf, size_t size);
  80. void doPlayerEntered(int pid, int isYou, char *, char *, char *, long , char *);
  81. //**************************************************************************
  82. // Globals
  83. //
  84. static int IgnoreIncoming = 0;
  85. /***************************************************************************
  86. * TenConnManClass::TenConnManClass -- Class constructor *
  87. * *
  88. * INPUT: *
  89. * none. *
  90. * *
  91. * OUTPUT: *
  92. * none. *
  93. * *
  94. * WARNINGS: *
  95. * none. *
  96. * *
  97. * HISTORY: *
  98. * 07/22/1996 BRR : Created. *
  99. *=========================================================================*/
  100. TenConnManClass::TenConnManClass(void)
  101. {
  102. int i;
  103. IsHost = 0;
  104. GlobalQueue = new CommBufferClass(1, 50, sizeof(GlobalPacketType), 4);
  105. PrivateQueue = new CommBufferClass(1, 50, Session.TenSize, 4);
  106. NumConnections = 0;
  107. for (i = 0; i < MAX_PLAYERS; i++) {
  108. Connections[i] = 0;
  109. ID[i] = 0;
  110. Names[i][0] = 0;
  111. }
  112. } // end of TenConnManClass
  113. /***************************************************************************
  114. * TenConnManClass::~TenConnManClass -- Class destructor *
  115. * *
  116. * INPUT: *
  117. * none. *
  118. * *
  119. * OUTPUT: *
  120. * none. *
  121. * *
  122. * WARNINGS: *
  123. * none. *
  124. * *
  125. * HISTORY: *
  126. * 07/22/1996 BRR : Created. *
  127. *=========================================================================*/
  128. TenConnManClass::~TenConnManClass()
  129. {
  130. tenArExitArena();
  131. delete GlobalQueue;
  132. delete PrivateQueue;
  133. } // end of ~TenConnManClass
  134. /***************************************************************************
  135. * TenConnManClass::Init -- Inits TEN *
  136. * *
  137. * INPUT: *
  138. * none. *
  139. * *
  140. * OUTPUT: *
  141. * 1. *
  142. * *
  143. * WARNINGS: *
  144. * none. *
  145. * *
  146. * HISTORY: *
  147. * 07/22/1996 BRR : Created. *
  148. *=========================================================================*/
  149. int TenConnManClass::Init(void)
  150. {
  151. //
  152. // set the debugging functions
  153. //
  154. setExitRoutine(terminateApp);
  155. setDebugMsgRoutine(debugMessage);
  156. //
  157. // callback function addresses
  158. //
  159. tenArSetAlertMessageRoutine(doAlert);
  160. tenArSetPregameHookRoutine(doPregameHook);
  161. tenArSetIncomingPacketRoutine(doIncomingPacket);
  162. tenArSetPlayerEnteredRoutine(doPlayerEntered);
  163. verifyNoErr(tenArInitArena("redalt"));
  164. return (1);
  165. } // end of Init
  166. /***************************************************************************
  167. * TenConnManClass::Service -- Service routine *
  168. * *
  169. * INPUT: *
  170. * none. *
  171. * *
  172. * OUTPUT: *
  173. * 1. *
  174. * *
  175. * WARNINGS: *
  176. * none. *
  177. * *
  178. * HISTORY: *
  179. * 07/22/1996 BRR : Created. *
  180. *=========================================================================*/
  181. int TenConnManClass::Service(void)
  182. {
  183. tenArIdleArena();
  184. return (1);
  185. } // Service
  186. /***************************************************************************
  187. * TenConnManClass::Send_Private_Message -- Sends a "private" message *
  188. * *
  189. * If Connection ID is -1, the packet is multicast; otherwise, it's sent *
  190. * to only the specified connection. *
  191. * *
  192. * Private & Global messages are sent via the same mechanism. The only *
  193. * way to tell the difference between them is that the Global Channel *
  194. * packets have the 'kGlobalChannelFlag' bit set in the 1st byte (the *
  195. * "Type" field for EventClass's, and the NetCommand field for Global *
  196. * packets). *
  197. * *
  198. * INPUT: *
  199. * buf packet to send *
  200. * buflen size of packet *
  201. * reliable 1 = must be delivered reliably *
  202. * conn_id connection ID to send to, -1 = all *
  203. * *
  204. * OUTPUT: *
  205. * 1 = OK, 0 = error *
  206. * *
  207. * WARNINGS: *
  208. * none. *
  209. * *
  210. * HISTORY: *
  211. * 07/22/1996 BRR : Created. *
  212. *=========================================================================*/
  213. int TenConnManClass::Send_Private_Message(void *buf, int buflen,
  214. int reliable, int conn_id)
  215. {
  216. int doBroadcast = conn_id == -1;
  217. unsigned char *ucbuf = (unsigned char *)buf;
  218. //
  219. // Ensure the global channel flag isn't set on this outgoing packet
  220. //
  221. (void)verify(!(ucbuf[0] & kGlobalChannelFlag));
  222. if (doBroadcast)
  223. {
  224. if (reliable)
  225. {
  226. verifyNoErr(tenArSendToOtherPlayers(buf, buflen));
  227. }
  228. else
  229. {
  230. verifyNoErr(tenArUnreliableSendToOtherPlayers(buf, buflen));
  231. }
  232. }
  233. else
  234. {
  235. int pid = Connection_Address(conn_id);
  236. (void)verify(pid >= 0 && pid < kMaxPlayers);
  237. if (reliable)
  238. {
  239. verifyNoErr(tenArSendToPlayer(pid, buf, buflen));
  240. }
  241. else
  242. {
  243. verifyNoErr(tenArUnreliableSendToPlayer(pid, buf, buflen));
  244. }
  245. }
  246. return (1);
  247. } // end of Send_Private_Message
  248. /***************************************************************************
  249. * TenConnManClass::Get_Private_Message -- Gets the next private message *
  250. * *
  251. * Retrieves the next-available "private" message, if there is one. *
  252. * *
  253. * INPUT: *
  254. * buf packet retrieved *
  255. * buflen length of packet *
  256. * conn_id ptr to store sender's connection ID *
  257. * *
  258. * OUTPUT: *
  259. * 1 = OK, 0 = error *
  260. * *
  261. * WARNINGS: *
  262. * none. *
  263. * *
  264. * HISTORY: *
  265. * 07/22/1996 BRR : Created. *
  266. *=========================================================================*/
  267. int TenConnManClass::Get_Private_Message(void *buf, int *buflen,
  268. int *conn_id)
  269. {
  270. int addr;
  271. int addrlen;
  272. int i;
  273. if (PrivateQueue->Num_Receive() > 0) {
  274. PrivateQueue->UnQueue_Receive(buf, buflen, 0, &addr, &addrlen);
  275. (void)verify(addrlen == 4);
  276. (*conn_id) = CONNECTION_NONE;
  277. for (i = 0; i < NumConnections; i++) {
  278. if (addr == Connections[i]) {
  279. (*conn_id) = ID[i];
  280. return (1);
  281. }
  282. }
  283. }
  284. return (0);
  285. } // end of Get_Private_Message
  286. /***************************************************************************
  287. * TenConnManClass::Send_Global_Message -- Sends a "global" message *
  288. * *
  289. * INPUT: *
  290. * buf packet to send *
  291. * buflen length of packet *
  292. * reliable 1 = send reliably *
  293. * address address to send to; -1 = broadcast it (for TEN, this *
  294. * means send to all connected players). *
  295. * *
  296. * OUTPUT: *
  297. * 1 = OK, 0 = error *
  298. * *
  299. * WARNINGS: *
  300. * none. *
  301. * *
  302. * HISTORY: *
  303. * 07/22/1996 BRR : Created. *
  304. *=========================================================================*/
  305. int TenConnManClass::Send_Global_Message(void *buf, int buflen,
  306. int reliable, int address)
  307. {
  308. int doBroadcast = address == -1;
  309. unsigned char *ucbuf = (unsigned char *)buf;
  310. //
  311. // Ensure the global channel flag isn't set on this outgoing packet
  312. //
  313. (void)verify(!(ucbuf[0] & kGlobalChannelFlag));
  314. //
  315. // Set the global channel flag for this packet
  316. //
  317. ucbuf[0] |= kGlobalChannelFlag;
  318. if (doBroadcast)
  319. {
  320. if (reliable)
  321. {
  322. verifyNoErr(tenArSendToOtherPlayers(buf, buflen));
  323. }
  324. else
  325. {
  326. verifyNoErr(tenArUnreliableSendToOtherPlayers(buf, buflen));
  327. }
  328. }
  329. else
  330. {
  331. int pid = address;
  332. (void)verify(pid >= 0 && pid < kMaxPlayers);
  333. if (reliable)
  334. {
  335. verifyNoErr(tenArSendToPlayer(pid, buf, buflen));
  336. }
  337. else
  338. {
  339. verifyNoErr(tenArUnreliableSendToPlayer(pid, buf, buflen));
  340. }
  341. }
  342. //
  343. // The caller may re-use this buffer, so clear the global channel flag.
  344. //
  345. ucbuf[0] &= ~kGlobalChannelFlag;
  346. return (1);
  347. } // end of Send_Global_Message
  348. /***************************************************************************
  349. * TenConnManClass::Get_Global_Message -- Gets next global message *
  350. * *
  351. * INPUT: *
  352. * buf buffer to store packet in *
  353. * buflen ptr filled in with packet length *
  354. * address ptr filled in with address (Player ID) of sender *
  355. * *
  356. * OUTPUT: *
  357. * 1 = OK, 0 = error *
  358. * *
  359. * WARNINGS: *
  360. * none. *
  361. * *
  362. * HISTORY: *
  363. * 07/22/1996 BRR : Created. *
  364. *=========================================================================*/
  365. int TenConnManClass::Get_Global_Message(void *buf, int *buflen,
  366. int *address)
  367. {
  368. int addrlen;
  369. if (GlobalQueue->Num_Receive() > 0) {
  370. GlobalQueue->UnQueue_Receive(buf, buflen, 0, address, &addrlen);
  371. (void)verify(addrlen == 4);
  372. return (1);
  373. }
  374. return (0);
  375. } // end of Get_Global_Message
  376. /***************************************************************************
  377. * TenConnManClass::Num_Connections -- Reports # connections *
  378. * *
  379. * INPUT: *
  380. * none. *
  381. * *
  382. * OUTPUT: *
  383. * # connections *
  384. * *
  385. * WARNINGS: *
  386. * *
  387. * *
  388. * HISTORY: *
  389. * 07/22/1996 BRR : Created. *
  390. *=========================================================================*/
  391. int TenConnManClass::Num_Connections(void)
  392. {
  393. return (NumConnections);
  394. } // end of Num_Connections
  395. /***************************************************************************
  396. * TenConnManClass::Connection_ID -- Reports a connection's ID *
  397. * *
  398. * INPUT: *
  399. * index index of connection to report *
  400. * *
  401. * OUTPUT: *
  402. * connection ID for this connection *
  403. * *
  404. * WARNINGS: *
  405. * none. *
  406. * *
  407. * HISTORY: *
  408. * 07/22/1996 BRR : Created. *
  409. *=========================================================================*/
  410. int TenConnManClass::Connection_ID(int index)
  411. {
  412. if (index >= 0 && index < NumConnections) {
  413. return(ID[index]);
  414. } else {
  415. return(CONNECTION_NONE);
  416. }
  417. } // end of Connection_ID
  418. /***************************************************************************
  419. * TenConnManClass::Connection_Index -- Gets a connection's index *
  420. * *
  421. * INPUT: *
  422. * id Connection ID to find index for *
  423. * *
  424. * OUTPUT: *
  425. * index for that connection *
  426. * *
  427. * WARNINGS: *
  428. * none. *
  429. * *
  430. * HISTORY: *
  431. * 07/22/1996 BRR : Created. *
  432. *=========================================================================*/
  433. int TenConnManClass::Connection_Index(int id)
  434. {
  435. int i;
  436. for (i = 0; i < NumConnections; i++) {
  437. if (ID[i] == id) {
  438. return (i);
  439. }
  440. }
  441. return(CONNECTION_NONE);
  442. } // end of Connection_Index
  443. /***************************************************************************
  444. * TenConnManClass::Create_Connection -- Creates a new connection *
  445. * *
  446. * INPUT: *
  447. * id ID of connection *
  448. * name name of connection *
  449. * address TEN address (player ID) to give this connection *
  450. * *
  451. * OUTPUT: *
  452. * 1 = OK, 0 = error
  453. * *
  454. * WARNINGS: *
  455. * none. *
  456. * *
  457. * HISTORY: *
  458. * 07/22/1996 BRR : Created. *
  459. *=========================================================================*/
  460. int TenConnManClass::Create_Connection(int id, char *name, int address)
  461. {
  462. Connections[NumConnections] = address;
  463. ID[NumConnections] = id;
  464. strcpy(Names[NumConnections], name);
  465. NumConnections++;
  466. return (1);
  467. } // end of Create_Connection
  468. /***************************************************************************
  469. * TenConnManClass::Delete_Connection -- Deletes a connection *
  470. * *
  471. * INPUT: *
  472. * id ID for connection to delete *
  473. * *
  474. * OUTPUT: *
  475. * 1 = OK, 0 = error
  476. * *
  477. * WARNINGS: *
  478. * none. *
  479. * *
  480. * HISTORY: *
  481. * 07/22/1996 BRR : Created. *
  482. *=========================================================================*/
  483. int TenConnManClass::Delete_Connection(int id)
  484. {
  485. int i;
  486. int idx = Connection_Index(id);
  487. if (idx == CONNECTION_NONE) {
  488. return 0;
  489. }
  490. for (i = idx; i < NumConnections - 1; i++) {
  491. Connections[i] = Connections[i+1];
  492. ID[i] = ID[i + 1];
  493. strcpy (Names[i], Names[i + 1]);
  494. }
  495. NumConnections--;
  496. return (1);
  497. } // end of Delete_Connection
  498. /***************************************************************************
  499. * TenConnManClass::Connection_Name -- Reports a connection's name *
  500. * *
  501. * INPUT: *
  502. * id ID of connection to report *
  503. * *
  504. * OUTPUT: *
  505. * connection name *
  506. * *
  507. * WARNINGS: *
  508. * none. *
  509. * *
  510. * HISTORY: *
  511. * 07/22/1996 BRR : Created. *
  512. *=========================================================================*/
  513. char * TenConnManClass::Connection_Name(int id)
  514. {
  515. int i;
  516. for (i = 0; i < NumConnections; i++) {
  517. if (ID[i]==id) {
  518. return(Names[i]);
  519. }
  520. }
  521. return(NULL);
  522. } // end of Connection_Name
  523. /***************************************************************************
  524. * TenConnManClass::Connection_Address -- Gets a connection's "address" *
  525. * *
  526. * INPUT: *
  527. * id ID of connection to report *
  528. * *
  529. * OUTPUT: *
  530. * connection "address" (TEN player ID) *
  531. * *
  532. * WARNINGS: *
  533. * none. *
  534. * *
  535. * HISTORY: *
  536. * 07/22/1996 BRR : Created. *
  537. *=========================================================================*/
  538. int TenConnManClass::Connection_Address(int id)
  539. {
  540. int i;
  541. for (i = 0; i < NumConnections; i++) {
  542. if (ID[i]==id) {
  543. return(Connections[i]);
  544. }
  545. }
  546. return(NULL);
  547. } // end of Connection_Address
  548. /***************************************************************************
  549. * TenConnManClass::Global_Num_Send -- Reports # outgoing packets *
  550. * *
  551. * INPUT: *
  552. * none. *
  553. * *
  554. * OUTPUT: *
  555. * 0. *
  556. * *
  557. * WARNINGS: *
  558. * none. *
  559. * *
  560. * HISTORY: *
  561. * 07/22/1996 BRR : Created. *
  562. *=========================================================================*/
  563. int TenConnManClass::Global_Num_Send(void)
  564. {
  565. return(0);
  566. } // end of Global_Num_Send
  567. /***************************************************************************
  568. * TenConnManClass::Global_Num_Receive -- Reports # incoming packets *
  569. * *
  570. * INPUT: *
  571. * none. *
  572. * *
  573. * OUTPUT: *
  574. * # packets waiting to be read *
  575. * *
  576. * WARNINGS: *
  577. * none. *
  578. * *
  579. * HISTORY: *
  580. * 07/22/1996 BRR : Created. *
  581. *=========================================================================*/
  582. int TenConnManClass::Global_Num_Receive(void)
  583. {
  584. return (GlobalQueue->Num_Receive());
  585. } // end of Global_Num_Receive
  586. /***************************************************************************
  587. * TenConnManClass::Private_Num_Send -- Reports # outgoing packets *
  588. * *
  589. * INPUT: *
  590. * none. *
  591. * *
  592. * OUTPUT: *
  593. * 0. *
  594. * *
  595. * WARNINGS: *
  596. * none. *
  597. * *
  598. * HISTORY: *
  599. * 07/22/1996 BRR : Created. *
  600. *=========================================================================*/
  601. int TenConnManClass::Private_Num_Send(int /*id*/)
  602. {
  603. return(0);
  604. } // end of Private_Num_Send
  605. /***************************************************************************
  606. * TenConnManClass::Private_Num_Receive -- Reports # incoming packets *
  607. * *
  608. * INPUT: *
  609. * none. *
  610. * *
  611. * OUTPUT: *
  612. * # packets waiting to be read *
  613. * *
  614. * WARNINGS: *
  615. * none. *
  616. * *
  617. * HISTORY: *
  618. * 07/22/1996 BRR : Created. *
  619. *=========================================================================*/
  620. int TenConnManClass::Private_Num_Receive(int /*id*/)
  621. {
  622. return (PrivateQueue->Num_Receive());
  623. } // end of Private_Num_Receive
  624. /***************************************************************************
  625. * TenConnManClass::Flush_All -- Flushes all packets *
  626. * *
  627. * INPUT: *
  628. * none. *
  629. * *
  630. * OUTPUT: *
  631. * none. *
  632. * *
  633. * WARNINGS: *
  634. * none. *
  635. * *
  636. * HISTORY: *
  637. * 07/22/1996 BRR : Created. *
  638. *=========================================================================*/
  639. void TenConnManClass::Flush_All(void)
  640. {
  641. int i;
  642. int maxqueuesize;
  643. int rc;
  644. //
  645. // Set the max # of packets that Ten will send me during any given
  646. // call to tenArIdleArena() to slightly smaller than my max queue
  647. // size.
  648. //
  649. maxqueuesize = 45;
  650. rc = tenArSetOption(kTenArOptReadQueueSize, &maxqueuesize,
  651. sizeof(maxqueuesize));
  652. verifyNoErr(rc);
  653. //
  654. // Set the flag to tell the doIncomingPacket routine to ignore packets.
  655. // (doIncomingPacket() is called by tenArIdleArena().)
  656. //
  657. IgnoreIncoming = 1;
  658. while (i++ < 1000) {
  659. tenArIdleArena();
  660. if (GlobalQueue->Num_Receive() == 0 &&
  661. PrivateQueue->Num_Receive() == 0) {
  662. break;
  663. }
  664. GlobalQueue->Init();
  665. PrivateQueue->Init();
  666. }
  667. IgnoreIncoming = 0;
  668. } // end of Flush_All
  669. /***************************************************************************
  670. * TenConnManClass::Reset_Response_Time -- Does nothing *
  671. * *
  672. * INPUT: *
  673. * none. *
  674. * *
  675. * OUTPUT: *
  676. * none. *
  677. * *
  678. * WARNINGS: *
  679. * none. *
  680. * *
  681. * HISTORY: *
  682. * 07/22/1996 BRR : Created. *
  683. *=========================================================================*/
  684. void TenConnManClass::Reset_Response_Time(void)
  685. {
  686. //
  687. // (This function intentionally left blank.)
  688. //
  689. } // end of Reset_Response_Time
  690. /***************************************************************************
  691. * TenConnManClass::Response_Time -- Reports response time *
  692. * *
  693. * INPUT: *
  694. * none. *
  695. * *
  696. * OUTPUT: *
  697. * worst-case connection response time (round-trip) *
  698. * *
  699. * WARNINGS: *
  700. * none. *
  701. * *
  702. * HISTORY: *
  703. * 07/22/1996 BRR : Created. *
  704. *=========================================================================*/
  705. unsigned long TenConnManClass::Response_Time(void)
  706. {
  707. return((Session.NetResponseTime * 60) / 1000); // 300 milliseconds one way
  708. } // end of Response_Time
  709. /***************************************************************************
  710. * TenConnManClass::Set_Timing -- Does nothing *
  711. * *
  712. * INPUT: *
  713. * none. *
  714. * *
  715. * OUTPUT: *
  716. * none. *
  717. * *
  718. * WARNINGS: *
  719. * none. *
  720. * *
  721. * HISTORY: *
  722. * 07/22/1996 BRR : Created. *
  723. *=========================================================================*/
  724. void TenConnManClass::Set_Timing(unsigned long /*retrydelta*/,
  725. unsigned long /*maxretries*/, unsigned long /*timeout*/)
  726. {
  727. //
  728. // (This function intentionally left blank.)
  729. //
  730. } // end of Set_Timing
  731. /***************************************************************************
  732. * TenConnManClass::Configure_Debug -- Does nothing *
  733. * *
  734. * INPUT: *
  735. * none. *
  736. * *
  737. * OUTPUT: *
  738. * none. *
  739. * *
  740. * WARNINGS: *
  741. * none. *
  742. * *
  743. * HISTORY: *
  744. * 07/22/1996 BRR : Created. *
  745. *=========================================================================*/
  746. void TenConnManClass::Configure_Debug(int /*index*/, int /*type_offset*/,
  747. int /*type_size*/, char **/*names*/, int /*namestart*/, int /*namecount*/)
  748. {
  749. //
  750. // (This function intentionally left blank.)
  751. //
  752. } // end of Configure_Debug
  753. /***************************************************************************
  754. * TenConnManClass::Mono_Debug_Print -- Does nothing *
  755. * *
  756. * INPUT: *
  757. * none. *
  758. * *
  759. * OUTPUT: *
  760. * none. *
  761. * *
  762. * WARNINGS: *
  763. * none. *
  764. * *
  765. * HISTORY: *
  766. * 07/22/1996 BRR : Created. *
  767. *=========================================================================*/
  768. void TenConnManClass::Mono_Debug_Print(int /*index*/, int /*refresh*/)
  769. {
  770. //
  771. // (This function intentionally left blank.)
  772. //
  773. } // end of Mono_Debug_Print
  774. /***************************************************************************
  775. * terminateApp -- Callback: app terminates on error *
  776. * *
  777. * INPUT: *
  778. * none. *
  779. * *
  780. * OUTPUT: *
  781. * none. *
  782. * *
  783. * WARNINGS: *
  784. * none. *
  785. * *
  786. * HISTORY: *
  787. * 07/22/1996 BRR : Created. *
  788. *=========================================================================*/
  789. static void terminateApp(void)
  790. {
  791. Prog_End();
  792. dprintf("Exiting due to a fatal error.\n");
  793. exit(0);
  794. } // end of terminateApp
  795. /***************************************************************************
  796. * debugMessage -- outputs debug message *
  797. * *
  798. * INPUT: *
  799. * msgLevel not used *
  800. * msg message to print *
  801. * *
  802. * OUTPUT: *
  803. * none. *
  804. * *
  805. * WARNINGS: *
  806. * none. *
  807. * *
  808. * HISTORY: *
  809. * 07/22/1996 BRR : Created. *
  810. *=========================================================================*/
  811. static void debugMessage(int /*msgLevel*/, char *msg)
  812. {
  813. static int recurse = 0;
  814. if (recurse) {
  815. return;
  816. }
  817. recurse = 1;
  818. if (MonoClass::Is_Enabled()) {
  819. Mono_Printf("%s\n",msg);
  820. } else {
  821. //printf("%s\n",msg);
  822. FILE *fp;
  823. fp = fopen("tendebug.log","at");
  824. if (fp) {
  825. fprintf(fp,"%s\n",msg);
  826. fclose(fp);
  827. }
  828. }
  829. if (GameActive) {
  830. WWMessageBox().Process(msg);
  831. }
  832. recurse = 0;
  833. } // end of debugMessage
  834. /***************************************************************************
  835. * doAlert -- Outputs debug message *
  836. * *
  837. * INPUT: *
  838. * msg message to print *
  839. * *
  840. * OUTPUT: *
  841. * none. *
  842. * *
  843. * WARNINGS: *
  844. * none. *
  845. * *
  846. * HISTORY: *
  847. * 07/22/1996 BRR : Created. *
  848. *=========================================================================*/
  849. static void doAlert(int, int, char * msg)
  850. {
  851. static int recurse = 0;
  852. if (recurse) {
  853. return;
  854. }
  855. recurse = 1;
  856. if (MonoClass::Is_Enabled()) {
  857. Mono_Printf("%s\n",msg);
  858. } else {
  859. //printf("%s\n",msg);
  860. FILE *fp;
  861. fp = fopen("tenalert.log","at");
  862. if (fp) {
  863. fprintf(fp,"%s\n",msg);
  864. fclose(fp);
  865. }
  866. }
  867. if (GameActive) {
  868. WWMessageBox().Process(msg);
  869. }
  870. recurse = 0;
  871. } // end of doAlert
  872. /***************************************************************************
  873. * doPregameHook -- Callback: game is starting *
  874. * *
  875. * INPUT: *
  876. * joinType if "create", we're the game host *
  877. * *
  878. * OUTPUT: *
  879. * none. *
  880. * *
  881. * WARNINGS: *
  882. * none. *
  883. * *
  884. * HISTORY: *
  885. * 07/22/1996 BRR : Created. *
  886. *=========================================================================*/
  887. static void doPregameHook(char * joinType, char *, char *,
  888. char *, char *, char *)
  889. {
  890. char typeToken[16];
  891. sscanf(joinType, "%s", typeToken);
  892. if (!strcmp(typeToken, "create")) {
  893. Ten->IsHost = 1;
  894. }
  895. if (Ten->IsHost) {
  896. verifyNoErr(tenArReturnGameOptions(""));
  897. }
  898. verifyNoErr(tenArReturnPlayerOptions(""));
  899. } // end of doPregameHook
  900. /***************************************************************************
  901. * doIncomingPacket -- Callback: packet has arrived *
  902. * *
  903. * INPUT: *
  904. * addr player ID of sender *
  905. * buf buffer containing incoming packet *
  906. * size size of incoming packet *
  907. * *
  908. * OUTPUT: *
  909. * *
  910. * WARNINGS: *
  911. * *
  912. * HISTORY: *
  913. * 07/22/1996 BRR : Created. *
  914. *=========================================================================*/
  915. void doIncomingPacket(int addr, void *buf, size_t size)
  916. {
  917. int rc;
  918. unsigned char *byte;
  919. //
  920. // Check to see if this packet belongs to the Global Channel or not
  921. //
  922. byte = (unsigned char *)buf;
  923. //
  924. // If the global channel flag is set in this packet, queue it onto the
  925. // Global Channel queue. Ignore any errors if "IgnoreIncoming" is set,
  926. // which means we're in the process of flushing the queues.
  927. //
  928. if (byte[0] & kGlobalChannelFlag) {
  929. byte[0] &= (~kGlobalChannelFlag);
  930. rc = Ten->GlobalQueue->Queue_Receive(buf, size, &addr, 4);
  931. if (!IgnoreIncoming) {
  932. (void)verify(rc==1);
  933. }
  934. } else {
  935. rc = Ten->PrivateQueue->Queue_Receive(buf, size, &addr, 4);
  936. if (!IgnoreIncoming) {
  937. (void)verify(rc==1);
  938. }
  939. }
  940. } // end of doIncomingPacket
  941. /***************************************************************************
  942. * doPlayerJoins -- Callback: player joins *
  943. * *
  944. * INPUT: *
  945. * pid player ID of the player joining *
  946. * isYou true = this is you *
  947. * *
  948. * OUTPUT: *
  949. * none. *
  950. * *
  951. * WARNINGS: *
  952. * none. *
  953. * *
  954. * HISTORY: *
  955. * 07/22/1996 BRR : Created. *
  956. *=========================================================================*/
  957. void doPlayerEntered(int pid, int isYou, char * /*options*/,
  958. char */*termOptions*/, char */*address*/, long /*uniqueId*/,
  959. char */*joinType*/)
  960. {
  961. if (isYou) {
  962. Session.TenPlayerID = pid;
  963. }
  964. } // end of doPlayerJoins
  965. #endif //TEN
  966. /************************** end of tenmgr.cpp ******************************/