| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066 |
- //
- // Copyright 2020 Electronic Arts Inc.
- //
- // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
- // software: you can redistribute it and/or modify it under the terms of
- // the GNU General Public License as published by the Free Software Foundation,
- // either version 3 of the License, or (at your option) any later version.
- // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
- // in the hope that it will be useful, but with permitted additional restrictions
- // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
- // distributed with this program. You should have received a copy of the
- // GNU General Public License along with permitted additional restrictions
- // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
- /* $Header: /CounterStrike/IPXMGR.CPP 3 10/13/97 2:20p Steve_t $ */
- /***************************************************************************
- ** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S **
- ***************************************************************************
- * *
- * Project Name : Command & Conquer *
- * *
- * File Name : IPXMGR.CPP *
- * *
- * Programmer : Bill Randolph *
- * *
- * Start Date : December 20, 1994 *
- * *
- * Last Update : May 4, 1995 [BRR] *
- * *
- *-------------------------------------------------------------------------*
- * Functions: *
- * IPXManagerClass::IPXManagerClass -- class constructor *
- * IPXManagerClass::~IPXManagerClass -- class destructor *
- * IPXManagerClass::Init -- initialization routine *
- * IPXManagerClass::Is_IPX -- tells if IPX is installed or not *
- * IPXManagerClass::Set_Timing -- sets timing for all connections *
- * IPXManagerClass::Create_Connection -- creates a new connection *
- * IPXManagerClass::Delete_Connection -- deletes a connection *
- * IPXManagerClass::Num_Connections -- gets the # of connections *
- * IPXManagerClass::Connection_ID -- gets the given connection's ID *
- * IPXManagerClass::Connection_Name -- gets name for given connection *
- * IPXManagerClass::Connection_Address -- retrieves connection's address *
- * IPXManagerClass::Connection_Index -- gets given connection's index *
- * IPXManagerClass::Set_Connection_Parms -- sets connection's name & id *
- * IPXManagerClass::Send_Global_Message -- sends a Global Message *
- * IPXManagerClass::Get_Global_Message -- polls the Global Message queue *
- * IPXManagerClass::Send_Private_Message -- Sends a Private Message *
- * IPXManagerClass::Get_Private_Message -- Polls Private Message queue *
- * IPXManagerClass::Service -- main polling routine for IPX Connections *
- * IPXManagerClass::Get_Bad_Connection -- returns bad connection ID *
- * IPXManagerClass::Global_Num_Send -- gets # entries in send queue *
- * IPXManagerClass::Global_Num_Receive -- gets # entries in recv queue *
- * IPXManagerClass::Private_Num_Send -- gets # entries in send queue *
- * IPXManagerClass::Private_Num_Receive -- gets # entries in recv queue *
- * IPXManagerClass::Set_Bridge -- prepares to cross a bridge *
- * IPXManagerClass::Set_Socket -- sets socket ID for all connections *
- * IPXManagerClass::Response_Time -- Returns largest Avg Response Time *
- * IPXManagerClass::Global_Response_Time -- Returns Avg Response Time *
- * IPXManagerClass::Reset_Response_Time -- Reset response time *
- * IPXManagerClass::Oldest_Send -- gets ptr to oldest send buf *
- * IPXManagerClass::Mono_Debug_Print -- debug output routine *
- * IPXManagerClass::Alloc_RealMode_Mem -- allocates real-mode memory *
- * IPXManagerClass::Free_RealMode_Mem -- frees real-mode memory *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "function.h"
- #include <stdio.h>
- //#include <mem.h> PG
- //#include <i86.h> PG
- #include "ipxmgr.h"
- #include "wwlib32.h" // to enable mono output
- #ifdef WINSOCK_IPX
- #include "WSProto.h"
- #include "WSPIPX.h"
- #else //WINSOCK_IPX
- #include "ipx95.h"
- #ifdef WIN32
- #include "tcpip.h"
- #else
- #include "fakesock.h"
- #endif //WIN32
- #endif //WINSOCK_IPX
- // Turn off "expression is not meaningful".
- //#pragma warning 628 9
- //#include "WolDebug.h"
- /***************************************************************************
- * IPXManagerClass::IPXManagerClass -- class constructor *
- * *
- * INPUT: *
- * glb_maxlen Global Channel maximum packet length *
- * pvt_maxlen Private Channel maximum packet length *
- * socket socket ID to use *
- * product_id a unique numerical ID for this product *
- * *
- * OUTPUT: *
- * none. *
- * *
- * WARNINGS: *
- * The socket number is byte-swapped, since IPX requires socket ID's *
- * to be stored high/low. *
- * *
- * HISTORY: *
- * 12/20/1994 BR : Created. *
- *=========================================================================*/
- IPXManagerClass::IPXManagerClass (int glb_maxlen, int pvt_maxlen,
- int glb_num_packets, int pvt_num_packets, unsigned short socket,
- unsigned short product_id)
- {
- int i;
- #ifdef WINSOCK_IPX
- /*
- ** Find out if Packet protocol services are available through Winsock.
- */
- if ( PacketTransport ) {
- delete PacketTransport;
- PacketTransport = NULL;
- }
- PacketTransport = new WinsockInterfaceClass;
- assert ( PacketTransport != NULL );
- if ( PacketTransport->Init() ){
- IPXStatus = 1;
- }else{
- IPXStatus = 0;
- }
- delete PacketTransport;
- PacketTransport = NULL;
- #else //WINSOCK_IPX
- //------------------------------------------------------------------------
- // Initialize data members
- //------------------------------------------------------------------------
- //........................................................................
- // IPXStatus = 1 if IPX is installed, 0 if not
- //........................................................................
- if (IPX_SPX_Installed()==0) {
- IPXStatus = 0;
- }
- else {
- IPXStatus = 1;
- }
- #endif //WINSOCK_IPX
- //........................................................................
- // Set listening state flag to off
- //........................................................................
- Listening = 0;
- //........................................................................
- // No memory has been alloc'd yet
- //........................................................................
- RealMemAllocd = 0;
- //........................................................................
- // Set max packet sizes, for allocating real-mode memory
- //........................................................................
- Glb_MaxPacketLen = glb_maxlen;
- Glb_NumPackets = glb_num_packets;
- Pvt_MaxPacketLen = pvt_maxlen;
- Pvt_NumPackets = pvt_num_packets;
- //........................................................................
- // Save the app's product ID
- //........................................................................
- ProductID = product_id;
- //........................................................................
- // Save our socket ID number
- //........................................................................
- Socket = (unsigned short)( (((unsigned long)socket & 0x00ff) << 8) |
- (((unsigned long)socket & 0xff00) >> 8));
- //------------------------------------------------------------------------
- // Get the user's IPX local connection number
- //------------------------------------------------------------------------
- ConnectionNum = 0;
- #ifndef WINSOCK_IPX
- if (IPXStatus) {
- ConnectionNum = IPX_Get_Connection_Number();
- }
- #endif //WINSOCK_IPX
- //------------------------------------------------------------------------
- // Init connection states
- //------------------------------------------------------------------------
- NumConnections = 0;
- CurConnection = 0;
- for (i = 0; i < CONNECT_MAX; i++) {
- Connection[i] = 0;
- }
- GlobalChannel = 0;
- SendOverflows = 0;
- ReceiveOverflows = 0;
- BadConnection = CONNECTION_NONE;
- //------------------------------------------------------------------------
- // Init timing parameters
- //------------------------------------------------------------------------
- RetryDelta = 2; // 2 ticks between retries
- MaxRetries = -1; // disregard # retries
- Timeout = 60; // report bad connection after 1 second
- } /* end of IPXManagerClass */
- /***************************************************************************
- * IPXManagerClass::~IPXManagerClass -- class destructor *
- * *
- * INPUT: *
- * none. *
- * *
- * OUTPUT: *
- * none. *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 12/20/1994 BR : Created. *
- *=========================================================================*/
- IPXManagerClass::~IPXManagerClass()
- {
- int i;
- //------------------------------------------------------------------------
- // Stop all IPX events
- //------------------------------------------------------------------------
- if (Listening) {
- IPXConnClass::Stop_Listening();
- Listening = 0;
- }
- //------------------------------------------------------------------------
- // Free all protected-mode memory
- //------------------------------------------------------------------------
- if (GlobalChannel) {
- delete GlobalChannel;
- GlobalChannel = 0;
- }
- for (i = 0; i < NumConnections; i++) {
- delete Connection[i];
- Connection[i] = 0;
- }
- NumConnections = 0;
- //------------------------------------------------------------------------
- // Free all real-mode memory
- //------------------------------------------------------------------------
- if (RealMemAllocd) {
- Free_RealMode_Mem();
- RealMemAllocd = 0;
- }
- #ifdef FIXIT_CSII // checked - ajw 9/28/98
- #ifdef WIN32
- #ifndef WINSOCK_IPX
- //PG Unload_IPX_Dll();
- #endif
- #endif
- #endif
- } /* end of ~IPXManagerClass */
- /***************************************************************************
- * IPXManagerClass::Init -- initialization routine *
- * *
- * This routine allocates memory, & initializes variables *
- * *
- * INPUT: *
- * none. *
- * *
- * OUTPUT: *
- * 1 = OK, 0 = error *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 12/20/1994 BR : Created. *
- *=========================================================================*/
- int IPXManagerClass::Init()
- {
- int i;
- if (Session.Type != GAME_INTERNET) {
- //------------------------------------------------------------------------
- // Error if IPX not installed
- //------------------------------------------------------------------------
- if (!IPXStatus) {
- return(0);
- }
- //------------------------------------------------------------------------
- // Stop Listening
- //------------------------------------------------------------------------
- if (Listening) {
- IPXConnClass::Stop_Listening();
- Listening = 0;
- }
- //------------------------------------------------------------------------
- // Free Real-mode memory
- //------------------------------------------------------------------------
- if (RealMemAllocd) {
- Free_RealMode_Mem();
- RealMemAllocd = 0;
- }
- } else {
- /*
- ** Pretend IPX is available for Internet games whether it is or not
- */
- IPXStatus = 1;
- }
- //------------------------------------------------------------------------
- // Free protected-mode memory
- //------------------------------------------------------------------------
- if (GlobalChannel) {
- delete GlobalChannel;
- GlobalChannel = 0;
- }
- for (i = 0; i < NumConnections; i++) {
- delete Connection[i];
- Connection[i] = 0;
- }
- NumConnections = 0;
- if (Session.Type != GAME_INTERNET) {
- //------------------------------------------------------------------------
- // Allocate real-mode memory
- //------------------------------------------------------------------------
- if (!Alloc_RealMode_Mem()) return(0);
- RealMemAllocd = 1;
- }
- //------------------------------------------------------------------------
- // Allocate the Global Channel
- //------------------------------------------------------------------------
- GlobalChannel = new IPXGlobalConnClass (Glb_NumPackets, Glb_NumPackets,
- Glb_MaxPacketLen, ProductID);
- if (!GlobalChannel) {
- return(0);
- }
- GlobalChannel->Init();
- GlobalChannel->Set_Retry_Delta (RetryDelta);
- GlobalChannel->Set_Max_Retries (MaxRetries);
- GlobalChannel->Set_TimeOut (Timeout);
- //------------------------------------------------------------------------
- // Configure the IPX Connections
- //------------------------------------------------------------------------
- IPXConnClass::Configure(Socket, ConnectionNum, ListenECB, SendECB,
- FirstHeaderBuf, SendHeader, FirstDataBuf, SendBuf, Handler, PacketLen);
- //------------------------------------------------------------------------
- // Start Listening
- //------------------------------------------------------------------------
- if (Session.Type != GAME_INTERNET) {
- if (!IPXConnClass::Start_Listening()) return(0);
- }
- Listening = 1;
- return(1);
- } /* end of Init */
- /***************************************************************************
- * IPXManagerClass::Is_IPX -- tells if IPX is installed or not *
- * *
- * INPUT: *
- * none. *
- * *
- * OUTPUT: *
- * 1 = IPX is installed; 0 = isn't *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 12/20/1994 BR : Created. *
- *=========================================================================*/
- int IPXManagerClass::Is_IPX(void)
- {
- return(IPXStatus);
- } /* end of Is_IPX */
- /***************************************************************************
- * IPXManagerClass::Set_Timing -- sets timing for all connections *
- * *
- * This will set the timing parameters for all existing connections, and *
- * all connections created from now on. This allows an application to *
- * measure the Response_Time while running, and adjust timing accordingly. *
- * *
- * INPUT: *
- * retrydelta value to set for retry delta *
- * maxretries value to set for max # retries *
- * timeout value to set for connection timeout *
- * *
- * OUTPUT: *
- * none. *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 07/02/1995 BR : Created. *
- *=========================================================================*/
- void IPXManagerClass::Set_Timing (unsigned long retrydelta,
- unsigned long maxretries, unsigned long timeout)
- {
- int i;
- RetryDelta = retrydelta;
- MaxRetries = maxretries;
- Timeout = timeout;
- if (GlobalChannel) {
- GlobalChannel->Set_Retry_Delta (RetryDelta);
- GlobalChannel->Set_Max_Retries (MaxRetries);
- GlobalChannel->Set_TimeOut (Timeout);
- }
- for (i = 0; i < NumConnections; i++) {
- Connection[i]->Set_Retry_Delta (RetryDelta);
- Connection[i]->Set_Max_Retries (MaxRetries);
- Connection[i]->Set_TimeOut (Timeout);
- }
- } /* end of Set_Timing */
- /***************************************************************************
- * IPXManagerClass::Create_Connection -- creates a new connection *
- * *
- * INPUT: *
- * id application-specific numerical ID for this connection *
- * node ptr to IPXNodeIDType (name & address) *
- * address IPX address for this connection *
- * *
- * OUTPUT: *
- * 1 = OK, 0 = error *
- * *
- * WARNINGS: *
- * Never create a connection with an 'id' of -1. *
- * *
- * HISTORY: *
- * 12/20/1994 BR : Created. *
- *=========================================================================*/
- int IPXManagerClass::Create_Connection(int id, char *name,
- IPXAddressClass *address)
- {
- //------------------------------------------------------------------------
- // Error if IPX not installed
- //------------------------------------------------------------------------
- if (!IPXStatus) {
- return(0);
- }
- //------------------------------------------------------------------------
- // Error if no more room
- //------------------------------------------------------------------------
- if (NumConnections==CONNECT_MAX) {
- return(0);
- }
- //------------------------------------------------------------------------
- // Create new connection
- //------------------------------------------------------------------------
- Connection[NumConnections] = new IPXConnClass(Pvt_NumPackets,
- Pvt_NumPackets, Pvt_MaxPacketLen, ProductID, address, id, name);
- if (!Connection[NumConnections]) {
- return(0);
- }
- Connection[NumConnections]->Init ();
- Connection[NumConnections]->Set_Retry_Delta (RetryDelta);
- Connection[NumConnections]->Set_Max_Retries (MaxRetries);
- Connection[NumConnections]->Set_TimeOut (Timeout);
- NumConnections++;
- return(1);
- } /* end of Create_Connection */
- /***************************************************************************
- * IPXManagerClass::Delete_Connection -- deletes a connection *
- * *
- * INPUT: *
- * id ID of connection to delete *
- * *
- * OUTPUT: *
- * 1 = OK, 0 = error *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 12/20/1994 BR : Created. *
- *=========================================================================*/
- int IPXManagerClass::Delete_Connection(int id)
- {
- int i,j;
- //------------------------------------------------------------------------
- // Error if IPX not installed
- //------------------------------------------------------------------------
- if (!IPXStatus) {
- return(0);
- }
- //------------------------------------------------------------------------
- // Error if no connections to delete
- //------------------------------------------------------------------------
- if (NumConnections==0) {
- return(0);
- }
- //------------------------------------------------------------------------
- // Loop through all connections
- //------------------------------------------------------------------------
- for (i = 0; i < NumConnections; i++) {
- //.....................................................................
- // If a match, delete it
- //.....................................................................
- if (Connection[i]->ID==id) {
- delete Connection[i];
- //..................................................................
- // Move array elements back one index
- //..................................................................
- for (j = i; j < NumConnections - 1; j++) {
- Connection[j] = Connection[j+1];
- }
- //..................................................................
- // Adjust counters
- //..................................................................
- NumConnections--;
- if (CurConnection >= NumConnections)
- CurConnection = 0;
- return(1);
- }
- }
- //------------------------------------------------------------------------
- // No match; error
- //------------------------------------------------------------------------
- return(0);
- } /* end of Delete_Connection */
- /***************************************************************************
- * IPXManagerClass::Num_Connections -- gets the # of connections *
- * *
- * INPUT: *
- * none. *
- * *
- * OUTPUT: *
- * # of connections *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 01/25/1995 BR : Created. *
- *=========================================================================*/
- int IPXManagerClass::Num_Connections(void)
- {
- return(NumConnections);
- } /* end of Num_Connections */
- /***************************************************************************
- * IPXManagerClass::Connection_ID -- gets the given connection's ID *
- * *
- * INPUT: *
- * index index of connection to retrieve *
- * *
- * OUTPUT: *
- * ID for that connection, CONNECTION_NONE if invalid index *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 01/25/1995 BR : Created. *
- *=========================================================================*/
- int IPXManagerClass::Connection_ID(int index)
- {
- if (index >= 0 && index < NumConnections) {
- return(Connection[index]->ID);
- }
- else {
- return(CONNECTION_NONE);
- }
- } /* end of Connection_ID */
- /***************************************************************************
- * IPXManagerClass::Connection_Name -- retrieves name for given connection *
- * *
- * INPUT: *
- * id ID of connection to get name of *
- * *
- * OUTPUT: *
- * ptr to connection's name, NULL if not found *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 01/19/1995 BR : Created. *
- *=========================================================================*/
- char *IPXManagerClass::Connection_Name(int id)
- {
- int i;
- for (i = 0; i < NumConnections; i++) {
- if (Connection[i]->ID==id) {
- return(Connection[i]->Name);
- }
- }
- return(NULL);
- } /* end of Connection_Name */
- /***************************************************************************
- * IPXManagerClass::Connection_Address -- retrieves connection's address *
- * *
- * INPUT: *
- * id ID of connection to get address for *
- * *
- * OUTPUT: *
- * pointer to IXPAddressClass, NULL if not found *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 01/19/1995 BR : Created. *
- *=========================================================================*/
- IPXAddressClass * IPXManagerClass::Connection_Address(int id)
- {
- int i;
- for (i = 0; i < NumConnections; i++) {
- if (Connection[i]->ID==id) {
- return(&Connection[i]->Address);
- }
- }
- return(NULL);
- } /* end of Connection_Address */
- /***************************************************************************
- * IPXManagerClass::Connection_Index -- gets given connection's index *
- * *
- * INPUT: *
- * ID to retrieve index for *
- * *
- * OUTPUT: *
- * index for this connection, CONNECTION_NONE if not found *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 01/25/1995 BR : Created. *
- *=========================================================================*/
- int IPXManagerClass::Connection_Index(int id)
- {
- int i;
- for (i = 0; i < NumConnections; i++) {
- if (Connection[i]->ID==id) {
- return(i);
- }
- }
- return(CONNECTION_NONE);
- } /* end of Connection_Index */
- /***************************************************************************
- * IPXManagerClass::Set_Connection_Parms -- sets connection's name & id *
- * *
- * INPUT: *
- * index connection index *
- * id new connection ID *
- * name new connection name *
- * *
- * OUTPUT: *
- * none. *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 01/25/1995 BR : Created. *
- *=========================================================================*/
- void IPXManagerClass::Set_Connection_Parms(int index, int id, char *name)
- {
- if (index >= NumConnections)
- return;
- Connection[index]->ID = id;
- strcpy(Connection[index]->Name,name);
- } /* end of Set_Connection_Parms */
- /***************************************************************************
- * IPXManagerClass::Send_Global_Message -- sends a Global Message *
- * *
- * INPUT: *
- * buf buffer to send *
- * buflen length of buf *
- * ack_req 1 = ACK required; 0 = no ACK required *
- * address address to send to; NULL = broadcast *
- * *
- * OUTPUT: *
- * 1 = OK, 0 = error *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 01/25/1995 BR : Created. *
- *=========================================================================*/
- int IPXManagerClass::Send_Global_Message(void *buf, int buflen,
- int ack_req, IPXAddressClass *address)
- {
- int rc;
- //------------------------------------------------------------------------
- // Error if IPX not installed or not Listening
- //------------------------------------------------------------------------
- if (!IPXStatus || !Listening) return(0);
- rc = GlobalChannel->Send_Packet (buf, buflen, address, ack_req);
- if (!rc) {
- SendOverflows++;
- }
- return(rc);
- } /* end of Send_Global_Message */
- /***************************************************************************
- * IPXManagerClass::Get_Global_Message -- polls the Global Message queue *
- * *
- * INPUT: *
- * buf buffer to store received packet *
- * buflen length of data placed in 'buf' *
- * address IPX address of sender *
- * product_id product ID of sender *
- * *
- * OUTPUT: *
- * 1 = OK, 0 = error *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 01/25/1995 BR : Created. *
- *=========================================================================*/
- int IPXManagerClass::Get_Global_Message(void *buf, int *buflen,
- IPXAddressClass *address, unsigned short *product_id)
- {
- //------------------------------------------------------------------------
- // Error if IPX not installed or not Listening
- //------------------------------------------------------------------------
- if (!IPXStatus || !Listening) return(0);
- return(GlobalChannel->Get_Packet (buf, buflen, address, product_id));
- } /* end of Get_Global_Message */
- /***************************************************************************
- * IPXManagerClass::Send_Private_Message -- Sends a Private Message *
- * *
- * INPUT: *
- * buf buffer to send *
- * buflen length of 'buf' *
- * conn_id connection ID to send to (CONNECTION_NONE = all) *
- * ack_req 1 = ACK required; 0 = no ACK required *
- * *
- * OUTPUT: *
- * 1 = OK, 0 = error *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 01/25/1995 BR : Created. *
- *=========================================================================*/
- int IPXManagerClass::Send_Private_Message(void *buf, int buflen, int ack_req,
- int conn_id)
- {
- int i; // loop counter
- int connect_idx; // index of channel to send to, if specified
- //------------------------------------------------------------------------
- // Error if IPX not installed or not Listening
- //------------------------------------------------------------------------
- if (!IPXStatus || !Listening || (NumConnections==0)) {
- return(0);
- }
- //------------------------------------------------------------------------
- // Send the message to all connections
- //------------------------------------------------------------------------
- if (conn_id==CONNECTION_NONE) {
- //.....................................................................
- // Check for room in all connections
- //.....................................................................
- for (i = 0; i < NumConnections; i++) {
- if (Connection[i]->Queue->Num_Send() ==
- Connection[i]->Queue->Max_Send()) {
- SendOverflows++;
- return(0);
- }
- }
- //.....................................................................
- // Send packet to all connections
- //.....................................................................
- for (i = 0; i < NumConnections; i++) {
- Connection[i]->Send_Packet (buf, buflen, ack_req);
- }
- return(1);
- }
- //------------------------------------------------------------------------
- // Send the message to the specified connection
- //------------------------------------------------------------------------
- else {
- connect_idx = Connection_Index (conn_id);
- if (connect_idx == CONNECTION_NONE) {
- SendOverflows++;
- return(0);
- }
- //.....................................................................
- // Check for room in the connection
- //.....................................................................
- if (Connection[connect_idx]->Queue->Num_Send() ==
- Connection[connect_idx]->Queue->Max_Send()) {
- SendOverflows++;
- return(0);
- }
- //.....................................................................
- // Send the packet to that connection
- //.....................................................................
- Connection[connect_idx]->Send_Packet (buf, buflen, ack_req);
- return(1);
- }
- } /* end of Send_Private_Message */
- /***************************************************************************
- * IPXManagerClass::Get_Private_Message -- Polls the Private Message queue *
- * *
- * INPUT: *
- * buf buffer to store incoming packet *
- * buflen length of data placed in 'buf' *
- * conn_id filled in with connection ID of sender *
- * *
- * OUTPUT: *
- * 1 = OK, 0 = error *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 01/25/1995 BR : Created. *
- *=========================================================================*/
- int IPXManagerClass::Get_Private_Message(void *buf, int *buflen, int *conn_id)
- {
- int i;
- int rc;
- int c_id;
- //------------------------------------------------------------------------
- // Error if IPX not installed or not Listening
- //------------------------------------------------------------------------
- if (!IPXStatus || !Listening || (NumConnections==0)) {
- return(0);
- }
- //------------------------------------------------------------------------
- // Safety check: ensure CurConnection is in range.
- //------------------------------------------------------------------------
- if (CurConnection >= NumConnections) {
- CurConnection = 0;
- }
- //------------------------------------------------------------------------
- // Scan all connections for a received packet, starting with 'CurConnection'
- //------------------------------------------------------------------------
- for (i = 0; i < NumConnections; i++) {
- //.....................................................................
- // Check this connection for a packet
- //.....................................................................
- rc = Connection[CurConnection]->Get_Packet (buf, buflen);
- c_id = Connection[CurConnection]->ID;
- //.....................................................................
- // Increment CurConnection to the next connection index
- //.....................................................................
- CurConnection++;
- if (CurConnection >= NumConnections) {
- CurConnection = 0;
- }
- //.....................................................................
- // If we got a packet, return the connection ID
- //.....................................................................
- if (rc) {
- (*conn_id) = c_id;
- return(1);
- }
- }
- return(0);
- } /* end of Get_Private_Message */
- /***************************************************************************
- * IPXManagerClass::Service -- main polling routine for IPX Connections *
- * *
- * INPUT: *
- * none. *
- * *
- * OUTPUT: *
- * 1 = OK, 0 = error *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 01/25/1995 BR : Created. *
- *=========================================================================*/
- int IPXManagerClass::Service(void)
- {
- int rc = 1;
- int i;
- CommHeaderType *packet;
- int packetlen;
- IPXAddressClass address;
- #ifdef WINSOCK_IPX
- unsigned char temp_receive_buffer[1024];
- int temp_receive_buffer_len;
- int temp_address_len;
- char temp_address [128];
- if ( PacketTransport ) {
- do {
- temp_receive_buffer_len = sizeof (temp_receive_buffer);
- temp_address_len = sizeof (temp_address);
- packetlen = PacketTransport->Read ( temp_receive_buffer, temp_receive_buffer_len, temp_address, temp_address_len );
- if ( packetlen ) {
- CurDataBuf = (char*)temp_receive_buffer;
- address = *((IPXAddressClass*) temp_address);
- packet = (CommHeaderType *)CurDataBuf;
- if (packet->MagicNumber == GlobalChannel->Magic_Num()) {
- /*
- ** Put the packet in the Global Queue
- */
- if (!GlobalChannel->Receive_Packet (packet, packetlen, &address))
- ReceiveOverflows++;
- } else {
- if (packet->MagicNumber == ProductID) {
- /*
- ** Find the Private Queue that this packet is for
- */
- bool found_address = false;
- for (i = 0; i < NumConnections; i++) {
- if (Connection[i]->Address == address) {
- found_address = true;
- if (!Connection[i]->Receive_Packet (packet, packetlen))
- ReceiveOverflows++;
- break;
- }
- }
- if( Session.Type == GAME_INTERNET )
- {
- /*
- ** This packet came from an unknown source. If it looks like one of our players
- ** packets then it might be from a player whos IP has changed.
- */
- if (!found_address) {
- if (packet->Code == ConnectionClass::PACKET_DATA_NOACK){
- /*
- ** Magic number and packet code are valid. It's probably a C&C packet.
- */
- EventClass *event = (EventClass*) (((char*) packet) + sizeof (CommHeaderType));
- /*
- ** If this is a framesync packet then grab the address and match it to an existing player.
- */
- if (event->Type == EventClass::FRAMESYNC) {
- int id = event->ID;
- assert (id != PlayerPtr->ID);
- for ( int i=1 ; i<Session.Players.Count() ; i++) {
- if (Session.Players[i]->Player.ID == id) {
- int iConnectionIndex = Connection_Index(id);
- if( iConnectionIndex != CONNECTION_NONE ) // (else Create_Connections() has not yet been called)
- {
- /*
- ** Found a likely candidate. Update his address. It should be OK to drop this
- ** packet since it's a framesync packet and will will pick up the next one.
- */
- Session.Players[i]->Address = address;
- Connection[iConnectionIndex]->Address = address;
- }
- break;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- } while (packetlen);
- }
- #else //WINSOCK_IPX
- #ifdef WIN32
- unsigned char temp_receive_buffer[1024];
- int recv_length;
- if (Winsock.Get_Connected() || Special.IsFromWChat) {
- if (!Winsock.Get_Connected()) return (0);
- /*
- ** This is an internet connection so get the packets from winsock
- */
- while ((recv_length = Winsock.Read(temp_receive_buffer, 1024))!=0) {
- CurHeaderBuf = NULL;
- CurDataBuf = (char*)&temp_receive_buffer[0];
- /*.....................................................................
- Compute the length of the packet (byte-swap the length in the IPX hdr)
- .....................................................................*/
- packetlen = recv_length;
- /*.....................................................................
- Extract the sender's address from the IPX header
- .....................................................................*/
- address.Set_Address (CurHeaderBuf);
- /*.....................................................................
- Examine the Magic Number of the received packet to determine if this
- packet goes into the Global Queue, or into one of the Private Queues
- .....................................................................*/
- packet = (CommHeaderType *)CurDataBuf;
- if (packet->MagicNumber == GlobalChannel->Magic_Num()) {
- /*..................................................................
- Put the packet in the Global Queue
- ..................................................................*/
- if (!GlobalChannel->Receive_Packet (packet, packetlen, &address))
- ReceiveOverflows++;
- } else {
- if (packet->MagicNumber == ProductID) {
- /*..................................................................
- Find the Private Queue that this packet is for
- ..................................................................*/
- for (i = 0; i < NumConnections; i++) {
- if (Connection[i]->Address == address) {
- if (!Connection[i]->Receive_Packet (packet, packetlen))
- ReceiveOverflows++;
- break;
- }
- }
- }
- }
- }
- } else {
- #if(0)//PG
- while (IPX_Get_Outstanding_Buffer95(&temp_receive_buffer[0])) {
- CurHeaderBuf = (IPXHEADER*)&temp_receive_buffer[0];
- CurDataBuf = (char*)&temp_receive_buffer[sizeof(IPXHeaderType)];
- /*.....................................................................
- Compute the length of the packet (byte-swap the length in the IPX hdr)
- .....................................................................*/
- packetlen = ((CurHeaderBuf->Length & 0xff) << 8) |
- (CurHeaderBuf->Length >> 8);
- packetlen -= sizeof(IPXHeaderType);
- /*.....................................................................
- Extract the sender's address from the IPX header
- .....................................................................*/
- address.Set_Address (CurHeaderBuf);
- /*.....................................................................
- Examine the Magic Number of the received packet to determine if this
- packet goes into the Global Queue, or into one of the Private Queues
- .....................................................................*/
- packet = (CommHeaderType *)CurDataBuf;
- if (packet->MagicNumber == GlobalChannel->Magic_Num()) {
- /*..................................................................
- Put the packet in the Global Queue
- ..................................................................*/
- if (!GlobalChannel->Receive_Packet (packet, packetlen, &address))
- ReceiveOverflows++;
- } else {
- if (packet->MagicNumber == ProductID) {
- /*..................................................................
- Find the Private Queue that this packet is for
- ..................................................................*/
- for (i = 0; i < NumConnections; i++) {
- if (Connection[i]->Address == address) {
- if (!Connection[i]->Receive_Packet (packet, packetlen))
- ReceiveOverflows++;
- break;
- }
- }
- }
- }
- }
- #endif
- }
- #else //WIN32
- //------------------------------------------------------------------------
- // Error if IPX not installed or not Listening
- //------------------------------------------------------------------------
- if (!IPXStatus || !Listening) {
- return(0);
- }
- //------------------------------------------------------------------------
- // Loop until there are no more packets to process.
- //------------------------------------------------------------------------
- while (1) {
- //.....................................................................
- // Check the BufferFlags for the "current" buffer; if it's empty,
- // break; out of the loop.
- //.....................................................................
- if (BufferFlags[CurIndex]==0) {
- break;
- }
- //.....................................................................
- // Compute the length of the packet (byte-swap the length in the IPX hdr)
- //.....................................................................
- packetlen = ((CurHeaderBuf->Length & 0xff) << 8) |
- (CurHeaderBuf->Length >> 8);
- packetlen -= sizeof(IPXHeaderType);
- //.....................................................................
- // Extract the sender's address from the IPX header
- //.....................................................................
- address.Set_Address (CurHeaderBuf);
- //.....................................................................
- // Examine the Magic Number of the received packet to determine if this
- // packet goes into the Global Queue, or into one of the Private Queues
- //.....................................................................
- packet = (CommHeaderType *)CurDataBuf;
- if (packet->MagicNumber == GlobalChannel->Magic_Num()) {
- //..................................................................
- // Put the packet in the Global Queue
- //..................................................................
- if (!GlobalChannel->Receive_Packet (packet, packetlen, &address)) {
- ReceiveOverflows++;
- }
- }
- //.....................................................................
- // Find the Private Queue that this packet is for
- //.....................................................................
- else if (packet->MagicNumber == ProductID) {
- for (i = 0; i < NumConnections; i++) {
- if (Connection[i]->Address == address) {
- if (!Connection[i]->Receive_Packet (packet, packetlen)) {
- ReceiveOverflows++;
- }
- break;
- }
- }
- }
- //.....................................................................
- // Set the current BufferFlags to 0 (since we've cleaned out this buffer)
- //.....................................................................
- BufferFlags[CurIndex] = 0;
- //.....................................................................
- // Go to the next packet buffer
- //.....................................................................
- CurIndex++;
- CurHeaderBuf = (IPXHeaderType *)(((char *)CurHeaderBuf) + FullPacketLen);
- CurDataBuf = ((char *)CurDataBuf) + FullPacketLen;
- if (CurIndex >= NumBufs) {
- CurHeaderBuf = FirstHeaderBuf;
- CurDataBuf = FirstDataBuf;
- CurIndex = 0;
- }
- }
- #endif //WIN32
- #endif //WINSOCK_IPX
- //------------------------------------------------------------------------
- // Service all connections. If a connection reports that it's gone "bad",
- // report an error to the caller. If it's the Global Channel, un-queue the
- // send entry that's holding things up. This will keep the Global Channel
- // from being clogged by one un-ACK'd outgoing packet.
- //------------------------------------------------------------------------
- if (GlobalChannel) {
- if (!GlobalChannel->Service()) {
- GlobalChannel->Queue->UnQueue_Send (NULL, NULL, 0);
- rc = 0;
- }
- }
- for (i = 0; i < NumConnections; i++) {
- if (!Connection[i]->Service()) {
- rc = 0;
- BadConnection = Connection[i]->ID;
- }
- }
- if (rc) {
- BadConnection = CONNECTION_NONE;
- }
- return(rc);
- } /* end of Service */
- /***************************************************************************
- * IPXManagerClass::Get_Bad_Connection -- returns bad connection ID *
- * *
- * INPUT: *
- * none. *
- * *
- * OUTPUT: *
- * ID of bad connection; CONNECTION_NONE if none. *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 05/04/1995 BRR : Created. *
- *=========================================================================*/
- int IPXManagerClass::Get_Bad_Connection(void)
- {
- return(BadConnection);
- } /* end of Get_Bad_Connection */
- /***************************************************************************
- * IPXManagerClass::Global_Num_Send -- reports # entries in send queue *
- * *
- * INPUT: *
- * none. *
- * *
- * OUTPUT: *
- * # entries in the Global Send Queue *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 01/25/1995 BR : Created. *
- *=========================================================================*/
- int IPXManagerClass::Global_Num_Send(void)
- {
- //------------------------------------------------------------------------
- // Error if IPX not installed or not Listening
- //------------------------------------------------------------------------
- if (!IPXStatus || !Listening) {
- return(0);
- }
- return(GlobalChannel->Queue->Num_Send());
- } /* end of Global_Num_Send */
- /***************************************************************************
- * IPXManagerClass::Global_Num_Receive -- reports # entries in recv queue *
- * *
- * INPUT: *
- * none. *
- * *
- * OUTPUT: *
- * # entries in the Global Receive Queue *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 01/25/1995 BR : Created. *
- *=========================================================================*/
- int IPXManagerClass::Global_Num_Receive(void)
- {
- //------------------------------------------------------------------------
- // Error if IPX not installed or not Listening
- //------------------------------------------------------------------------
- if (!IPXStatus || !Listening) {
- return(0);
- }
- return(GlobalChannel->Queue->Num_Receive());
- } /* end of Global_Num_Receive */
- /***************************************************************************
- * IPXManagerClass::Private_Num_Send -- reports # entries in send queue *
- * *
- * INPUT: *
- * # entries in the Private Send Queue *
- * *
- * OUTPUT: *
- * 1 = OK, 0 = error *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 01/25/1995 BR : Created. *
- *=========================================================================*/
- int IPXManagerClass::Private_Num_Send(int id)
- {
- int i;
- int maxnum;
- //------------------------------------------------------------------------
- // Error if IPX not installed or not Listening
- //------------------------------------------------------------------------
- if (!IPXStatus || !Listening || (NumConnections==0)) {
- return(0);
- }
- //------------------------------------------------------------------------
- // If connection ID specified, return that connection's # of packets
- //------------------------------------------------------------------------
- if (id != CONNECTION_NONE) {
- i = Connection_Index(id);
- if (i != CONNECTION_NONE) {
- return(Connection[i]->Queue->Num_Send());
- }
- else {
- return(0);
- }
- }
- //------------------------------------------------------------------------
- // Otherwise, return the max # of all connections
- //------------------------------------------------------------------------
- else {
- maxnum = 0;
- for (i = 0; i < NumConnections; i++) {
- if (Connection[i]->Queue->Num_Send() > maxnum) {
- maxnum = Connection[i]->Queue->Num_Send();
- }
- }
- return(maxnum);
- }
- } /* end of Private_Num_Send */
- /***************************************************************************
- * IPXManagerClass::Private_Num_Receive -- reports # entries in recv queue *
- * *
- * INPUT: *
- * id ID of connection to query *
- * *
- * OUTPUT: *
- * # entries in the Private Receive Queue *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 01/25/1995 BR : Created. *
- *=========================================================================*/
- int IPXManagerClass::Private_Num_Receive(int id)
- {
- int i;
- int maxnum;
- //------------------------------------------------------------------------
- // Error if IPX not installed or not Listening
- //------------------------------------------------------------------------
- if (!IPXStatus || !Listening || (NumConnections==0))
- return(0);
- //------------------------------------------------------------------------
- // If connection ID specified, return that connection's # of packets
- //------------------------------------------------------------------------
- if (id != CONNECTION_NONE) {
- i = Connection_Index(id);
- if (i != CONNECTION_NONE) {
- return(Connection[i]->Queue->Num_Receive());
- }
- else {
- return(0);
- }
- }
- //------------------------------------------------------------------------
- // Otherwise, return the max # of all connections
- //------------------------------------------------------------------------
- else {
- maxnum = 0;
- for (i = 0; i < NumConnections; i++) {
- if (Connection[i]->Queue->Num_Receive() > maxnum) {
- maxnum = Connection[i]->Queue->Num_Receive();
- }
- }
- return(maxnum);
- }
- } /* end of Private_Num_Receive */
- /***************************************************************************
- * IPXManagerClass::Set_Socket -- sets socket ID for all connections *
- * *
- * INPUT: *
- * socket new socket ID to use *
- * *
- * OUTPUT: *
- * none. *
- * *
- * WARNINGS: *
- * Do not call this function after communications have started; you *
- * must call it before calling Init(). *
- * The socket number is byte-swapped, since IPX requires socket ID's *
- * to be stored high/low. *
- * *
- * HISTORY: *
- * 01/25/1995 BR : Created. *
- *=========================================================================*/
- void IPXManagerClass::Set_Socket(unsigned short socket)
- {
- Socket = (unsigned short)( (((unsigned long)socket & 0x00ff) << 8) |
- (((unsigned long)socket & 0xff00) >> 8));
- } /* end of Set_Socket */
- /***************************************************************************
- * IPXManagerClass::Response_Time -- Returns largest Avg Response Time *
- * *
- * INPUT: *
- * none. *
- * *
- * OUTPUT: *
- * largest avg response time *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 05/04/1995 BRR : Created. *
- *=========================================================================*/
- unsigned long IPXManagerClass::Response_Time(void)
- {
- unsigned long resp;
- unsigned long maxresp = 0;
- int i;
- for (i = 0; i < NumConnections; i++) {
- resp = Connection[i]->Queue->Avg_Response_Time();
- if (resp > maxresp) {
- maxresp = resp;
- }
- }
- return(maxresp);
- } /* end of Response_Time */
- /***************************************************************************
- * IPXManagerClass::Global_Response_Time -- Returns Avg Response Time *
- * *
- * INPUT: *
- * none. *
- * *
- * OUTPUT: *
- * avg global channel response time *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 05/04/1995 BRR : Created. *
- *=========================================================================*/
- unsigned long IPXManagerClass::Global_Response_Time(void)
- {
- if (GlobalChannel) {
- return (GlobalChannel->Queue->Avg_Response_Time());
- }
- else {
- return (0);
- }
- } /* end of Global_Response_Time */
- /***************************************************************************
- * IPXManagerClass::Reset_Response_Time -- Reset response time *
- * *
- * INPUT: *
- * none. *
- * *
- * OUTPUT: *
- * none. *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 05/04/1995 BRR : Created. *
- *=========================================================================*/
- void IPXManagerClass::Reset_Response_Time(void)
- {
- int i;
- for (i = 0; i < NumConnections; i++) {
- Connection[i]->Queue->Reset_Response_Time();
- }
- if (GlobalChannel)
- GlobalChannel->Queue->Reset_Response_Time();
- } /* end of Reset_Response_Time */
- /***************************************************************************
- * IPXManagerClass::Oldest_Send -- gets ptr to oldest send buf *
- * *
- * INPUT: *
- * none. *
- * *
- * OUTPUT: *
- * buf ptr *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 05/04/1995 BRR : Created. *
- *=========================================================================*/
- void * IPXManagerClass::Oldest_Send(void)
- {
- int i,j;
- unsigned long time;
- unsigned long mintime = 0xffffffff;
- SendQueueType *send_entry; // ptr to send entry header
- CommHeaderType *packet;
- void *buf = NULL;
- for (i = 0; i < NumConnections; i++) {
- send_entry = NULL;
- for (j = 0; j < Connection[i]->Queue->Num_Send(); j++) {
- send_entry = Connection[i]->Queue->Get_Send(j);
- if (send_entry) {
- packet = (CommHeaderType *)send_entry->Buffer;
- if (packet->Code == ConnectionClass::PACKET_DATA_ACK &&
- send_entry->IsACK == 0) {
- break;
- }
- else {
- send_entry = NULL;
- }
- }
- }
- if (send_entry!=NULL) {
- time = send_entry->FirstTime;
- if (time < mintime) {
- mintime = time;
- buf = send_entry->Buffer;
- }
- }
- }
- return(buf);
- } /* end of Oldest_Send */
- /***************************************************************************
- * IPXManagerClass::Set_Bridge -- prepares to cross a bridge *
- * *
- * This routine is designed to prevent the connection from having to *
- * call Get_Local_Target, except the minimum number of times, since that *
- * routine is buggy & goes away for long periods sometimes. *
- * *
- * INPUT: *
- * bridge network number of the destination bridge *
- * *
- * OUTPUT: *
- * none *
- * *
- * WARNINGS: *
- * none *
- * *
- * HISTORY: *
- * 07/06/1995 BRR : Created. *
- *=========================================================================*/
- void IPXManagerClass::Set_Bridge(NetNumType bridge)
- {
- if (GlobalChannel) {
- GlobalChannel->Set_Bridge(bridge);
- }
- } /* end of Set_Bridge */
- /***************************************************************************
- * IPXManagerClass::Configure_Debug -- sets up special debug values *
- * *
- * Mono_Debug_Print2() can look into a packet to pull out a particular *
- * ID, and can print both that ID and a string corresponding to *
- * that ID. This routine configures these values so it can find *
- * and decode the ID. This ID is used in addition to the normal *
- * CommHeaderType values. *
- * *
- * INPUT: *
- * index connection index to configure (-1 = Global Channel) *
- * type_offset ID's byte offset into packet *
- * type_size size of ID, in bytes; 0 if none *
- * names ptr to array of names; use ID as an index into this *
- * namestart numerical value of 1st name in the array *
- * namecount # in the names array; 0 if none. *
- * *
- * OUTPUT: *
- * none. *
- * *
- * WARNINGS: *
- * Names shouldn't be longer than 12 characters. *
- * *
- * HISTORY: *
- * 05/31/1995 BRR : Created. *
- *=========================================================================*/
- void IPXManagerClass::Configure_Debug(int index, int type_offset,
- int type_size, char **names, int namestart, int namecount)
- {
- if (index == -1) {
- GlobalChannel->Queue->Configure_Debug (type_offset, type_size, names,
- namestart, namecount);
- }
- else if (Connection[index]) {
- Connection[index]->Queue->Configure_Debug (type_offset, type_size, names,
- namestart, namecount);
- }
- } /* end of Configure_Debug */
- /***************************************************************************
- * IPXManagerClass::Mono_Debug_Print -- debug output routine *
- * *
- * INPUT: *
- * index index of connection to display (-1 = Global Channel) *
- * refresh 1 = complete screen refresh *
- * *
- * OUTPUT: *
- * 1 = OK, 0 = error *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 01/25/1995 BR : Created. *
- *=========================================================================*/
- void IPXManagerClass::Mono_Debug_Print(int index, int refresh)
- {
- #ifdef WWLIB32_H
- char txt[80];
- int i;
- if (index == -1)
- GlobalChannel->Queue->Mono_Debug_Print (refresh);
- else if (Connection[index])
- Connection[index]->Queue->Mono_Debug_Print (refresh);
- if (refresh) {
- Mono_Set_Cursor (20,1);
- Mono_Printf ("IPX Queue:");
- Mono_Set_Cursor (9,2);
- Mono_Printf ("Average Response Time:");
- Mono_Set_Cursor (43,1);
- Mono_Printf ("Send Overflows:");
- Mono_Set_Cursor (40,2);
- Mono_Printf ("Receive Overflows:");
- }
- Mono_Set_Cursor (32,1);
- Mono_Printf ("%d",index);
- Mono_Set_Cursor (32,2);
- if (index == -1) {
- Mono_Printf ("%d ", GlobalChannel->Queue->Avg_Response_Time());
- }
- else {
- Mono_Printf ("%d ", Connection[index]->Queue->Avg_Response_Time());
- }
- Mono_Set_Cursor (59,1);
- Mono_Printf ("%d ", SendOverflows);
- Mono_Set_Cursor (59,2);
- Mono_Printf ("%d ", ReceiveOverflows);
- for (i = 0; i < NumBufs; i++) {
- if (BufferFlags[i]) {
- txt[i] = 'X';
- }
- else {
- txt[i] = '_';
- }
- }
- txt[i] = 0;
- Mono_Set_Cursor ((80-NumBufs)/2,3);
- Mono_Printf ("%s",txt);
- #else
- index = index;
- refresh = refresh;
- #endif
- } /* end of Mono_Debug_Print */
- /***************************************************************************
- * IPXManagerClass::Alloc_RealMode_Mem -- allocates real-mode memory *
- * *
- * INPUT: *
- * none. *
- * *
- * OUTPUT: *
- * 1 = OK, 0 = error *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 12/20/1994 BR : Created. *
- *=========================================================================*/
- int IPXManagerClass::Alloc_RealMode_Mem(void)
- {
- #ifdef WIN32
- return (1);
- #else
- union REGS regs;
- struct SREGS sregs;
- int size; // required size of allocation
- unsigned char *realmode; // start addresses of real-mode data
- int realmodelen; // length of real-mode data
- unsigned long func_val;
- char *p; // for parsing buffer
- int i;
- //------------------------------------------------------------------------
- // Compute # of buffers we need to allocate, & the max size of each one
- //------------------------------------------------------------------------
- NumBufs = Glb_NumPackets + (Pvt_NumPackets * CONNECT_MAX);
- PacketLen = Glb_MaxPacketLen + sizeof (GlobalHeaderType);
- if (Pvt_MaxPacketLen + sizeof (CommHeaderType) > PacketLen)
- PacketLen = Pvt_MaxPacketLen + sizeof (CommHeaderType);
- FullPacketLen = PacketLen + sizeof(IPXHeaderType);
- //------------------------------------------------------------------------
- // Compute the size of everything we'll ever need, allocate it in one big
- // chunk. The memory is used as follows:
- // - Real-mode assembly IPX callback routine, plus its data,
- // (which includes the ListenECB)
- // - Array of IPX Packet buffers (IPXHeader plus data buffer)
- // - SendECB: ECB for sending
- // - SendHeader: IPX Header for sending
- // - SendBuf: Packet buffer for sending
- // - BufferFlags: 1 byte for each incoming packet buffer; 1=in use, 0=free
- //------------------------------------------------------------------------
- realmode = (unsigned char *)Get_RM_IPX_Address();
- realmodelen = Get_RM_IPX_Size();
- size = realmodelen + // assembly routine & its data
- (FullPacketLen * NumBufs) + // array of packet buffers
- sizeof(ECBType) + // SendECB
- FullPacketLen + // SendHeader & SendBuf
- NumBufs; // BufferFlags
- if (size > 65535) {
- return(0);
- }
- //------------------------------------------------------------------------
- // Allocate DOS memory for the ECB, IPXHeader & packet buffers:
- // AX = 0x100
- // BX = # paragraphs to allocate
- // - if Success, AX = real-mode segment, DX = selector
- // - if Failure, carry flag is set
- //------------------------------------------------------------------------
- memset (®s, 0 ,sizeof(regs));
- segread (&sregs);
- regs.x.eax = DPMI_ALLOC_DOS_MEM; // DPMI function to call
- regs.x.ebx = ((size + 15) >> 4); // # paragraphs to allocate
- int386x (DPMI_INT, ®s, ®s, &sregs); // allocate the memory
- //------------------------------------------------------------------------
- // If the carry flag is set, DPMI is indicating an error.
- //------------------------------------------------------------------------
- if (regs.x.cflag) {
- return(0);
- }
- //------------------------------------------------------------------------
- // Save the values of the returned segment & selector
- //------------------------------------------------------------------------
- Selector = regs.w.dx;
- Segment = regs.w.ax;
- RealMemSize = size;
- RealModeData = (RealModeDataType *)(((long)Segment) << 4);
- //------------------------------------------------------------------------
- // Lock the memory (since we're servicing interrupts with it)
- // AX = 0x600
- // BX:CX = starting linear address of memory to lock
- // SI:DI = size of region to lock (in bytes)
- // - If Failure, carry flag is set.
- //------------------------------------------------------------------------
- memset (®s, 0 ,sizeof(regs));
- segread (&sregs);
- regs.x.eax = DPMI_LOCK_MEM; // DPMI function to call
- regs.x.ebx = ((long)RealModeData & 0xffff0000) >> 16;
- regs.x.ecx = ((long)RealModeData & 0x0000ffff);
- regs.x.esi = ((long)RealMemSize & 0xffff0000) >> 16;
- regs.x.edi = ((long)RealMemSize & 0x0000ffff);
- int386x (DPMI_INT, ®s, ®s, &sregs); // call DPMI
- //------------------------------------------------------------------------
- // If the carry flag is set, DPMI is indicating an error.
- //------------------------------------------------------------------------
- if (regs.x.cflag) {
- memset (®s, 0 ,sizeof(regs));
- segread (&sregs);
- regs.x.eax = DPMI_FREE_DOS_MEM; // DPMI function to call
- regs.x.edx = Selector; // ptr to free
- int386x (DPMI_INT, ®s, ®s, &sregs); // free the memory
- return(0);
- }
- //------------------------------------------------------------------------
- // Copy the Real-mode code into our memory buffer
- //------------------------------------------------------------------------
- p = (char *)(((long)Segment) << 4);
- memcpy (p,realmode,realmodelen);
- p += realmodelen;
- //------------------------------------------------------------------------
- // Compute & save the entry point for the real-mode packet handler
- //------------------------------------------------------------------------
- func_val = (unsigned long)RealModeData;
- Handler = (((func_val & 0xffff0) << 12) |
- ((func_val & 0x000f) + RealModeData->FuncOffset));
- //------------------------------------------------------------------------
- // Fill in buffer pointers
- //------------------------------------------------------------------------
- ListenECB = &(RealModeData->ListenECB);
- FirstHeaderBuf = (IPXHeaderType *)p;
- FirstDataBuf = (((char *)FirstHeaderBuf) + sizeof(IPXHeaderType));
- CurIndex = 0;
- CurHeaderBuf = FirstHeaderBuf;
- CurDataBuf = FirstDataBuf;
- p += FullPacketLen * NumBufs;
- SendECB = (ECBType *)p;
- p += sizeof (ECBType);
- SendHeader = (IPXHeaderType *)p;
- p += sizeof (IPXHeaderType);
- SendBuf = (char *)p;
- p += PacketLen;
- BufferFlags = (char *)p;
- //------------------------------------------------------------------------
- // Fill in the real-mode routine's data (The ECB will be filled in when we
- // command IPX to Listen).
- //------------------------------------------------------------------------
- RealModeData->NumBufs = (short)NumBufs;
- RealModeData->BufferFlags = (char *)
- ((((long)BufferFlags & 0xffff0) << 12) |
- ((long)BufferFlags & 0x0000f));
- RealModeData->PacketSize = (short)FullPacketLen;
- RealModeData->FirstPacketBuf = (IPXHeaderType *)
- ((((long)FirstHeaderBuf & 0xffff0) << 12) |
- ((long)FirstHeaderBuf & 0x0000f));
- RealModeData->CurIndex = 0;
- RealModeData->CurPacketBuf = RealModeData->FirstPacketBuf;
- RealModeData->Semaphore = 0;
- RealModeData->ReEntrantCount = 0;
- //------------------------------------------------------------------------
- // Init state of all buffers to empty
- //------------------------------------------------------------------------
- for (i = 0; i < NumBufs; i++) {
- BufferFlags[i] = 0;
- }
- //------------------------------------------------------------------------
- // Check the start & end markers in the real-mode memory area
- //------------------------------------------------------------------------
- if (RealModeData->Marker1 != 0x1111 ||
- RealModeData->Marker2 != 0x2222) {
- Free_RealMode_Mem();
- return(0);
- }
- else {
- return(1);
- }
- #endif //WIN32
- } /* end of Alloc_Realmode_Mem */
- /***************************************************************************
- * IPXManagerClass::Free_RealMode_Mem -- frees real-mode memory *
- * *
- * INPUT: *
- * none. *
- * *
- * OUTPUT: *
- * 1 = OK, 0 = error *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 12/20/1994 BR : Created. *
- *=========================================================================*/
- int IPXManagerClass::Free_RealMode_Mem(void)
- {
- #ifdef WIN32
- return (1);
- #else //WIN32
- union REGS regs;
- struct SREGS sregs;
- int rc = 1;
- //------------------------------------------------------------------------
- // Unlock the memory
- //------------------------------------------------------------------------
- memset (®s, 0 ,sizeof(regs));
- segread (&sregs);
- regs.x.eax = DPMI_UNLOCK_MEM; // DPMI function to call
- regs.x.ebx = ((long)RealModeData & 0xffff0000) >> 16;
- regs.x.ecx = ((long)RealModeData & 0x0000ffff);
- regs.x.esi = ((long)RealMemSize & 0xffff0000) >> 16;
- regs.x.edi = ((long)RealMemSize & 0x0000ffff);
- int386x (DPMI_INT, ®s, ®s, &sregs); // call DPMI
- //------------------------------------------------------------------------
- // If the carry flag is set, DPMI is indicating an error.
- //------------------------------------------------------------------------
- if (regs.x.cflag) {
- rc = 0;
- }
- //------------------------------------------------------------------------
- // Free DOS memory
- //------------------------------------------------------------------------
- memset (®s, 0 ,sizeof(regs));
- segread (&sregs);
- regs.x.eax = DPMI_FREE_DOS_MEM; // DPMI function to call
- regs.x.edx = Selector; // ptr to free
- int386x (DPMI_INT, ®s, ®s, &sregs); // free the memory
- return(rc);
- #endif //WIN32
- } /* end of Free_Realmode_Mem */
- /*************************** end of ipxmgr.cpp *****************************/
|