CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

TENMGR.CPP (48766B)


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