TENMGR.CPP 48 KB

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