12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234 |
- //-----------------------------------------------------------------------------
- // Copyright (c) 2012 GarageGames, LLC
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- // Server Query States:
- // 1: Master server query status -> wait for master response
- // 2: Master server packet status -> wait for master packets to arrive
- // 3: Server ping status -> wait for servers to respond to pings
- // 4: Server query status -> wait for servers to respond to queries
- // 5: Done
- // Master Server Packets:
- // Header
- // message Message id
- // flags Query flags
- // sequenceNumber Packet sequence id
- // Server Query Filter Packet
- // packetIndex Request specific page # (rest empty)
- // gameType Game type string
- // missionType Mission type string
- // minPlayers At least this many players
- // maxPlayers No more than this many
- // regions Region mask, 0 = all
- // version Server version, 0 = any
- // filterFlags Server flags (dedicated, etc), 0 = any
- // maxBots No more than maxBots
- // minCPUSpeed At least this fast
- // playerCount Buddy list search
- // playerList[playerCount]
- // Master Server Info Packet
- // gameType Game type string
- // missionType Mission type string
- // maxPlayers Max allowed
- // regions Region mask
- // version Server version #
- // infoFlags Server flags (dedicated, etc)
- // numBots Current bot count
- // CPUSpeed Server CPU speed
- // playerCount Current player count
- // playerList[playerCount]
- // Game Info Query Packet
- // gameType Game type string
- // missionType Mission type string
- // missionName You get one guess...
- // satusFlags Dedicated, etc.
- // playerCount Current player count
- // maxPlayers Max allowed
- // numBots Current bot count
- // CPUSpeed Server CPU speed
- // statusString Server info message
- // statusString Server status message
- // Accessed Environment Vars
- // Server::MissionType
- // Server::MissionName
- // Server::GameType
- // Server::ServerType
- // Server::PlayerCount
- // Server::BotCount
- // Server::GuidList[playerCount]
- // Server::Dedicated
- // Server::Status
- // Pref::Server::Name
- // Pref::Server::Password
- // Pref::Server::Info
- // Pref::Server::MaxPlayers
- // Pref::Server::RegionMask
- // Pref::Net::RegionMask
- // Pref::Client::Master[n]
- // Pref::Client::ServerFavoriteCount
- // Pref::Client::ServerFavorite[ServerFavoriteCount]
- //-----------------------------------------------------------------------------
- #include "app/net/serverQuery.h"
- #include "platform/platform.h"
- #include "core/dnet.h"
- #include "core/util/tVector.h"
- #include "core/stream/bitStream.h"
- #include "console/console.h"
- #include "console/simBase.h"
- #include "app/banList.h"
- #include "app/auth.h"
- #include "sim/netConnection.h"
- #include "sim/netInterface.h"
- // cafTODO: breaks T2D
- #include "T3D/gameBase/gameConnection.h"
- // This is basically the server query protocol version now:
- static const char* versionString = "VER1";
- struct MasterInfo
- {
- NetAddress address;
- U32 region;
- };
- Vector<ServerInfo> gServerList(__FILE__, __LINE__);
- static Vector<MasterInfo> gMasterServerList(__FILE__, __LINE__);
- static Vector<NetAddress> gFinishedList(__FILE__, __LINE__); // timed out servers and finished servers go here
- NetAddress gMasterServerQueryAddress;
- bool gServerBrowserDirty = false;
- static const U32 gHeartbeatInterval = 120000;
- static const S32 gMasterServerRetryCount = 3;
- static const S32 gMasterServerTimeout = 2000;
- static const S32 gPacketRetryCount = 4;
- static const S32 gPacketTimeout = 1000;
- static const S32 gMaxConcurrentPings = 10;
- static const S32 gMaxConcurrentQueries = 2;
- static const S32 gPingRetryCount = 4;
- static const S32 gPingTimeout = 800;
- static const S32 gQueryRetryCount = 4;
- static const S32 gQueryTimeout = 1000;
- // State variables:
- static bool sgServerQueryActive = false;
- static S32 gPingSession = 0;
- static S32 gKey = 0;
- static bool gGotFirstListPacket = false;
- // Variables used for the interface:
- static U32 gServerPingCount = 0;
- static U32 gServerQueryCount = 0;
- static U32 gHeartbeatSeq = 0;
- class DemoNetInterface : public NetInterface
- {
- public:
- void handleInfoPacket(const NetAddress *address, U8 packetType, BitStream *stream);
- };
- DemoNetInterface gNetInterface;
- ConsoleFunctionGroupBegin( ServerQuery, "Functions which allow you to query the LAN or a master server for online games.");
- //-----------------------------------------------------------------------------
- struct Ping
- {
- NetAddress address;
- S32 session;
- S32 key;
- U32 time;
- U32 tryCount;
- bool broadcast;
- };
- static Ping gMasterServerPing;
- static Vector<Ping> gPingList(__FILE__, __LINE__);
- static Vector<Ping> gQueryList(__FILE__, __LINE__);
- //-----------------------------------------------------------------------------
- struct PacketStatus
- {
- U16 index;
- S32 key;
- U32 time;
- U32 tryCount;
- PacketStatus() : index( 0 ), key(-1), time(0), tryCount( gPacketRetryCount ) {};
- PacketStatus( U8 _index, S32 _key, U32 _time )
- {
- index = _index;
- key = _key;
- time = _time;
- tryCount = gPacketRetryCount;
- }
- inline U8 getOldIndex() { return (U8)index; }
- inline U16 getIndex() { return index; }
- };
- static Vector<PacketStatus> gPacketStatusList(__FILE__, __LINE__);
- //-----------------------------------------------------------------------------
- struct ServerFilter
- {
- enum Type
- {
- Normal = 0,
- Buddy = 1,
- Offline = 2,
- Favorites = 3,
- };
- enum // Query Flags
- {
- OnlineQuery = 0, // Authenticated with master
- OfflineQuery = BIT(0), // On our own
- NoStringCompress = BIT(1),
- NewStyleResponse = BIT(2), // Include IPV6 servers
- };
- enum // Filter flags:
- {
- Dedicated = BIT(0),
- NotPassworded = BIT(1),
- Linux = BIT(2),
- CurrentVersion = BIT(6)
- };
- enum // Region mask flags
- {
- RegionIsIPV4Address = BIT(30),
- RegionIsIPV6Address = BIT(31),
- RegionAddressMask = RegionIsIPV4Address | RegionIsIPV6Address
- };
-
- //Rearranging the fields according to their sizes
- char* gameType;
- char* missionType;
- U8 queryFlags;
- U8 minPlayers;
- U8 maxPlayers;
- U8 maxBots;
- U8 filterFlags;
- U8 buddyCount;
- U16 minCPU;
- U32 regionMask;
- U32 maxPing;
- U32* buddyList;
- Type type;
- ServerFilter()
- {
- type = Normal;
- queryFlags = NewStyleResponse;
- gameType = NULL;
- missionType = NULL;
- minPlayers = 0;
- maxPlayers = 255;
- maxBots = 16;
- regionMask = 0xFFFFFFFF;
- maxPing = 0;
- filterFlags = 0;
- minCPU = 0;
- buddyCount = 0;
- buddyList = NULL;
- }
- ~ServerFilter()
- {
- if ( gameType )
- dFree( gameType );
- if ( missionType )
- dFree( missionType );
- if ( buddyList )
- dFree( buddyList );
- }
- };
- static ServerFilter sActiveFilter;
- //-----------------------------------------------------------------------------
- // Forward function declarations:
- //-----------------------------------------------------------------------------
- static void pushPingRequest( const NetAddress *addr );
- static void pushPingBroadcast( const NetAddress *addr );
- static void pushServerFavorites();
- static bool pickMasterServer();
- static S32 findPingEntry( Vector<Ping> &v, const NetAddress* addr );
- static bool addressFinished( const NetAddress* addr );
- static ServerInfo* findServerInfo( const NetAddress* addr );
- static ServerInfo* findOrCreateServerInfo( const NetAddress* addr );
- static void removeServerInfo( const NetAddress* addr );
- static void sendPacket( U8 pType, const NetAddress* addr, U32 key, U32 session, U8 flags );
- static void writeCString( BitStream* stream, const char* string );
- static void readCString( BitStream* stream, char* buffer );
- static void writeLongCString( BitStream* stream, const char* string );
- static void readLongCString( BitStream* stream, char* buffer );
- static void processMasterServerQuery( U32 session );
- static void processPingsAndQueries( U32 session, bool schedule = true);
- static void processServerListPackets( U32 session );
- static void processHeartbeat(U32);
- static void updatePingProgress();
- static void updateQueryProgress();
- Vector<MasterInfo>* getMasterServerList();
- bool pickMasterServer();
- void clearServerList();
- //-----------------------------------------------------------------------------
- // Events
- //-----------------------------------------------------------------------------
- //----------------------------------------------------------------
- class ProcessMasterQueryEvent : public SimEvent
- {
- U32 session;
- public:
- ProcessMasterQueryEvent( U32 _session )
- {
- session = _session;
- }
- void process( SimObject *object )
- {
- processMasterServerQuery( session );
- }
- };
- //----------------------------------------------------------------
- class ProcessPingEvent : public SimEvent
- {
- U32 session;
- public:
- ProcessPingEvent( U32 _session )
- {
- session = _session;
- }
- void process( SimObject *object )
- {
- processPingsAndQueries( session );
- }
- };
- //----------------------------------------------------------------
- class ProcessPacketEvent : public SimEvent
- {
- U32 session;
- public:
- ProcessPacketEvent( U32 _session )
- {
- session = _session;
- }
- void process( SimObject *object )
- {
- processServerListPackets( session );
- }
- };
- //----------------------------------------------------------------
- class HeartbeatEvent : public SimEvent
- {
- U32 mSeq;
- public:
- HeartbeatEvent(U32 seq)
- {
- mSeq = seq;
- }
- void process( SimObject *object )
- {
- processHeartbeat(mSeq);
- }
- };
- //-----------------------------------------------------------------------------
- // Public query methods
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- void queryLanServers(U32 port, U8 flags, const char* gameType, const char* missionType,
- U8 minPlayers, U8 maxPlayers, U8 maxBots, U32 regionMask, U32 maxPing, U16 minCPU,
- U8 filterFlags)
- {
- sgServerQueryActive = true;
- pushServerFavorites();
- sActiveFilter.type = ServerFilter::Offline;
- // Clear the filter:
- if ( !sActiveFilter.gameType || dStricmp( sActiveFilter.gameType, "Any" ) != 0 )
- {
- sActiveFilter.gameType = (char*) dRealloc( sActiveFilter.gameType, 4 );
- dStrcpy( sActiveFilter.gameType, "Any", 4 );
- }
- if ( !sActiveFilter.missionType || dStricmp( sActiveFilter.missionType, "Any" ) != 0 )
- {
- sActiveFilter.missionType = (char*) dRealloc( sActiveFilter.missionType, 4 );
- dStrcpy( sActiveFilter.missionType, "Any", 4 );
- }
- sActiveFilter.queryFlags = 0;
- sActiveFilter.minPlayers = minPlayers;
- sActiveFilter.maxPlayers = maxPlayers;
- sActiveFilter.maxBots = maxBots;
- sActiveFilter.regionMask = regionMask;
- sActiveFilter.maxPing = maxPing;
- sActiveFilter.minCPU = minCPU;
- sActiveFilter.filterFlags = filterFlags;
- NetAddress addr;
- char addrText[256];
- // IPV4
- dSprintf( addrText, sizeof( addrText ), "IP:BROADCAST:%d", port );
- Net::stringToAddress( addrText, &addr );
- pushPingBroadcast( &addr );
- // IPV6
- dSprintf(addrText, sizeof(addrText), "IP6:MULTICAST:%d", port);
- Net::stringToAddress(addrText, &addr);
- pushPingBroadcast(&addr);
- Con::executef("onServerQueryStatus", "start", "Querying LAN servers", "0");
- processPingsAndQueries( gPingSession );
- }
- //-----------------------------------------------------------------------------
- DefineEngineFunction( queryAllServers
- , void, ( U32 lanPort
- , U32 flags
- , const char * gameType
- , const char * missionType
- , U32 minPlayers
- , U32 maxPlayers
- , U32 maxBots
- , U32 regionMask
- , U32 maxPing
- , U32 minCPU
- , U32 filterFlags )
- , , "queryAllServers(...);" )
- {
- U32 buddyList = 0;
- clearServerList();
- queryMasterServer(flags,gameType,missionType,minPlayers,maxPlayers,
- maxBots,regionMask,maxPing,minCPU,filterFlags,0,&buddyList);
- queryLanServers(lanPort, flags, gameType, missionType, minPlayers, maxPlayers, maxBots,
- regionMask, maxPing, minCPU, filterFlags);
- }
- DefineEngineFunction( queryLanServers
- , void, ( U32 lanPort
- , U32 flags
- , const char * gameType
- , const char * missionType
- , U32 minPlayers
- , U32 maxPlayers
- , U32 maxBots
- , U32 regionMask
- , U32 maxPing
- , U32 minCPU
- , U32 filterFlags )
- , , "queryLanServers(...);" )
- {
- clearServerList();
- queryLanServers(lanPort, flags, gameType, missionType, minPlayers, maxPlayers, maxBots,
- regionMask, maxPing, minCPU, filterFlags);
- }
- //-----------------------------------------------------------------------------
- void queryMasterGameTypes()
- {
- Vector<MasterInfo> *masterList = getMasterServerList();
- if ( masterList->size() != 0 )
- {
- U32 master = Sim::getCurrentTime() % masterList->size();
- // Send a request to the master server for the game types:
- Con::printf( "Requesting game types from the master server..." );
- sendPacket( NetInterface::MasterServerGameTypesRequest, &(*masterList)[master].address, gKey, gPingSession, 0 );
- }
- }
- //-----------------------------------------------------------------------------
- void queryMasterServer(U8 flags, const char* gameType, const char* missionType,
- U8 minPlayers, U8 maxPlayers, U8 maxBots, U32 regionMask, U32 maxPing,
- U16 minCPU, U8 filterFlags, U8 buddyCount, U32* buddyList )
- {
- // Reset the list packet flag:
- gGotFirstListPacket = false;
- sgServerQueryActive = true;
- Con::executef( "onServerQueryStatus", "start", "Querying master server", "0");
- if ( buddyCount == 0 )
- {
- sActiveFilter.type = ServerFilter::Normal;
- // Update the active filter:
- if ( !sActiveFilter.gameType || String::compare( sActiveFilter.gameType, gameType ) != 0 )
- {
- dsize_t gameTypeLen = dStrlen(gameType) + 1;
- sActiveFilter.gameType = (char*) dRealloc( sActiveFilter.gameType, gameTypeLen );
- dStrcpy( sActiveFilter.gameType, gameType, gameTypeLen );
- }
- if ( !sActiveFilter.missionType || String::compare( sActiveFilter.missionType, missionType ) != 0 )
- {
- dsize_t missionTypeLen = dStrlen(missionType) + 1;
- sActiveFilter.missionType = (char*) dRealloc( sActiveFilter.missionType, missionTypeLen );
- dStrcpy( sActiveFilter.missionType, missionType, missionTypeLen );
- }
- sActiveFilter.queryFlags = flags | ServerFilter::NewStyleResponse;
- sActiveFilter.minPlayers = minPlayers;
- sActiveFilter.maxPlayers = maxPlayers;
- sActiveFilter.maxBots = maxBots;
- sActiveFilter.regionMask = regionMask;
- sActiveFilter.maxPing = maxPing;
- sActiveFilter.minCPU = minCPU;
- sActiveFilter.filterFlags = filterFlags;
- sActiveFilter.buddyCount = buddyCount;
- dFree( sActiveFilter.buddyList );
- sActiveFilter.buddyList = NULL;
- }
- else
- {
- sActiveFilter.type = ServerFilter::Buddy;
- sActiveFilter.buddyCount = buddyCount;
- sActiveFilter.buddyList = (U32*) dRealloc( sActiveFilter.buddyList, buddyCount * 4 );
- sActiveFilter.queryFlags = ServerFilter::NewStyleResponse;
- dMemcpy( sActiveFilter.buddyList, buddyList, buddyCount * 4 );
- clearServerList();
- }
- // Pick a random master server from the list:
- gMasterServerList.clear();
- Vector<MasterInfo> *masterList = getMasterServerList();
- for ( U32 i = 0; i < masterList->size(); i++ )
- gMasterServerList.push_back( (*masterList)[i] );
- // Clear the master server ping:
- gMasterServerPing.time = 0;
- gMasterServerPing.tryCount = gMasterServerRetryCount;
- if ( !pickMasterServer() )
- Con::errorf( "No master servers found!" );
- else
- processMasterServerQuery( gPingSession );
- }
- DefineEngineFunction( queryMasterServer
- , void, ( U32 flags
- , const char * gameType
- , const char * missionType
- , U32 minPlayers
- , U32 maxPlayers
- , U32 maxBots
- , U32 regionMask
- , U32 maxPing
- , U32 minCPU
- , U32 filterFlags )
- , , "queryMasterServer(...);" )
- {
- U32 buddyList = 0;
- clearServerList();
- queryMasterServer(flags,gameType,missionType,minPlayers,maxPlayers,
- maxBots,regionMask,maxPing,minCPU,filterFlags,0,&buddyList);
- }
- //-----------------------------------------------------------------------------
- DefineEngineFunction( querySingleServer
- , void, ( const char* addrText, U8 flags )
- , (0), "querySingleServer(address, flags);" )
- {
- NetAddress addr;
- Net::stringToAddress( addrText, &addr );
- querySingleServer(&addr,flags);
- }
- //-----------------------------------------------------------------------------
- void queryFavoriteServers( U8 /*flags*/ )
- {
- sgServerQueryActive = true;
- clearServerList();
- sActiveFilter.type = ServerFilter::Favorites;
- pushServerFavorites();
- Con::executef( "onServerQueryStatus", "start", "Query favorites...", "0" );
- processPingsAndQueries( gPingSession );
- }
- //-----------------------------------------------------------------------------
- void querySingleServer( const NetAddress* addr, U8 /*flags*/ )
- {
- sgServerQueryActive = true;
- ServerInfo* si = findServerInfo( addr );
- if ( si )
- si->status = ServerInfo::Status_New | ServerInfo::Status_Updating;
- // Remove the server from the finished list (if it's there):
- for ( U32 i = 0; i < gFinishedList.size(); i++ )
- {
- if ( Net::compareAddresses( addr, &gFinishedList[i] ) )
- {
- gFinishedList.erase( i );
- break;
- }
- }
- Con::executef( "onServerQueryStatus", "start", "Refreshing server...", "0" );
- gServerPingCount = gServerQueryCount = 0;
- pushPingRequest( addr );
- processPingsAndQueries( gPingSession );
- }
- //-----------------------------------------------------------------------------
- void cancelServerQuery()
- {
- // Cancel the current query, if there is anything left
- // on the ping list, it's dropped.
- if ( sgServerQueryActive )
- {
- Con::printf( "Server query canceled." );
- ServerInfo* si;
- // Clear the master server packet list:
- gPacketStatusList.clear();
- // Clear the ping list:
- while ( gPingList.size() )
- {
- si = findServerInfo( &gPingList[0].address );
- if ( si && !si->status.test( ServerInfo::Status_Responded ) )
- si->status = ServerInfo::Status_TimedOut;
- gPingList.erase( U32( 0 ) );
- }
- // Clear the query list:
- while ( gQueryList.size() )
- {
- si = findServerInfo( &gQueryList[0].address );
- if ( si && !si->status.test( ServerInfo::Status_Responded ) )
- si->status = ServerInfo::Status_TimedOut;
- gQueryList.erase( U32( 0 ) );
- }
- sgServerQueryActive = false;
- gServerBrowserDirty = true;
- }
- }
- DefineEngineFunction( cancelServerQuery, void, (), , "cancelServerQuery();" )
- {
- cancelServerQuery();
- }
- //-----------------------------------------------------------------------------
- void stopServerQuery()
- {
- // Cancel the current query, anything left on the ping
- // list is moved to the finished list as "done".
- if ( sgServerQueryActive )
- {
- gPacketStatusList.clear();
- if ( gPingList.size() )
- {
- while ( gPingList.size() )
- {
- gFinishedList.push_back( gPingList[0].address );
- gPingList.erase( U32( 0 ) );
- }
- }
- else
- cancelServerQuery();
- }
- }
- DefineEngineFunction( stopServerQuery, void, (), , "stopServerQuery();" )
- {
- stopServerQuery();
- }
- //-----------------------------------------------------------------------------
- DefineEngineFunction( startHeartbeat, void, (), , "startHeartbeat();" )
- {
- if (validateAuthenticatedServer()) {
- gHeartbeatSeq++;
- processHeartbeat(gHeartbeatSeq); // thump-thump...
- }
- }
- DefineEngineFunction( stopHeartbeat, void, (), , "stopHeartbeat();" )
- {
- gHeartbeatSeq++;
- }
- //-----------------------------------------------------------------------------
- DefineEngineFunction( getServerCount, int, (), , "getServerCount();" )
- {
- return gServerList.size();
- }
- DefineEngineFunction( setServerInfo, bool, (U32 index), , "setServerInfo(index);" )
- {
- if (index < gServerList.size()) {
- ServerInfo& info = gServerList[index];
- char addrString[256];
- Net::addressToString( &info.address, addrString );
- Con::setIntVariable("ServerInfo::Status",info.status);
- Con::setVariable("ServerInfo::Address",addrString);
- Con::setVariable("ServerInfo::Name",info.name);
- Con::setVariable("ServerInfo::GameType",info.gameType);
- Con::setVariable("ServerInfo::MissionName",info.missionName);
- Con::setVariable("ServerInfo::MissionType",info.missionType);
- Con::setVariable("ServerInfo::State",info.statusString);
- Con::setVariable("ServerInfo::Info",info.infoString);
- Con::setIntVariable("ServerInfo::PlayerCount",info.numPlayers);
- Con::setIntVariable("ServerInfo::MaxPlayers",info.maxPlayers);
- Con::setIntVariable("ServerInfo::BotCount",info.numBots);
- Con::setIntVariable("ServerInfo::Version",info.version);
- Con::setIntVariable("ServerInfo::Ping",info.ping);
- Con::setIntVariable("ServerInfo::CPUSpeed",info.cpuSpeed);
- Con::setBoolVariable("ServerInfo::Favorite",info.isFavorite);
- Con::setBoolVariable("ServerInfo::Dedicated",info.isDedicated());
- Con::setBoolVariable("ServerInfo::Password",info.isPassworded());
- return true;
- }
- return false;
- }
- //-----------------------------------------------------------------------------
- // Internal
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- ServerInfo::~ServerInfo()
- {
- if ( name )
- dFree( name );
- if ( gameType )
- dFree( gameType );
- if ( missionType )
- dFree( missionType );
- if( missionName )
- dFree( missionName );
- if ( statusString )
- dFree( statusString );
- if ( infoString )
- dFree( infoString );
- }
- //-----------------------------------------------------------------------------
- Vector<MasterInfo>* getMasterServerList()
- {
- // This code used to get the master server list from the
- // WON.net directory.
- static Vector<MasterInfo> masterList;
- masterList.clear();
- for (U32 i = 0; i < 10; i++) {
- char buffer[50];
- dSprintf(buffer,sizeof(buffer),"pref::Master%d",i);
- const char* master = Con::getVariable(buffer);
- if (master && *master) {
- NetAddress address;
- // Format for master server variable:
- // regionMask:netAddress
- U32 region = 1; // needs to default to something > 0
- dSscanf(master,"%d:",®ion);
- const char* madd = dStrchr(master,':') + 1;
- if (region && Net::stringToAddress(madd,&address) == Net::NoError) {
- masterList.increment();
- MasterInfo& info = masterList.last();
- info.address = address;
- info.region = region;
- }
- else
- Con::errorf("Bad master server address: %s",master);
- }
- }
- if (!masterList.size())
- Con::errorf("No master servers found");
- return &masterList;
- }
- //-----------------------------------------------------------------------------
- bool pickMasterServer()
- {
- // Reset the master server ping:
- gMasterServerPing.time = 0;
- gMasterServerPing.key = 0;
- gMasterServerPing.tryCount = gMasterServerRetryCount;
- gMasterServerPing.session = gPingSession;
- char addrString[256];
- U32 serverCount = gMasterServerList.size();
- if ( !serverCount )
- {
- // There are no more servers left to try...:(
- return( false );
- }
- U32 region = Con::getIntVariable( "$pref::Net::RegionMask" );
- U32 index = Sim::getCurrentTime() % serverCount;
- // First try to find a master server in the same region:
- for ( U32 i = 0; i < serverCount; i++ )
- {
- if ( gMasterServerList[index].region == region )
- {
- Net::addressToString( &gMasterServerList[index].address, addrString );
- Con::printf( "Found master server %s in same region.", addrString );
- gMasterServerPing.address = gMasterServerList[index].address;
- return( true );
- }
- index = index < serverCount - 1 ? index + 1 : 0;
- }
- // Settle for the one we first picked:
- Net::addressToString( &gMasterServerList[index].address, addrString );
- Con::printf( "No master servers found in this region, trying %s.", addrString );
- gMasterServerPing.address = gMasterServerList[index].address;
- return( true );
- }
- //-----------------------------------------------------------------------------
- void clearServerList()
- {
- gPacketStatusList.clear();
- gServerList.clear();
- gFinishedList.clear();
- gPingList.clear();
- gQueryList.clear();
- gServerPingCount = gServerQueryCount = 0;
- gPingSession++;
- }
- //-----------------------------------------------------------------------------
- void sendHeartbeat( U8 flags )
- {
- // send heartbeats to all of the master servers:
- Vector<MasterInfo> *masterList = getMasterServerList();
- for(U32 i = 0; i < masterList->size(); i++)
- {
- char buffer[256];
- Net::addressToString(&(*masterList)[i].address, buffer);
- // Send a request to the master server for the game types:
- Con::printf( "Sending heartbeat to master server [%s]", buffer );
- sendPacket( NetInterface::GameHeartbeat, &(*masterList)[i].address, 0, gPingSession, flags );
- }
- }
- //-----------------------------------------------------------------------------
- static void pushPingRequest( const NetAddress* addr )
- {
- if( addressFinished( addr ) )
- return;
- Ping p;
- p.address = *addr;
- p.session = gPingSession;
- p.key = 0;
- p.time = 0;
- p.tryCount = gPingRetryCount;
- p.broadcast = false;
- gPingList.push_back( p );
- gServerPingCount++;
- }
- //-----------------------------------------------------------------------------
- static void pushPingBroadcast( const NetAddress* addr )
- {
- if( addressFinished( addr ) )
- return;
- Ping p;
- p.address = *addr;
- p.session = gPingSession;
- p.key = 0;
- p.time = 0;
- p.tryCount = 1; // only try this once
- p.broadcast = true;
- gPingList.push_back( p );
- // Don't increment gServerPingCount, broadcasts are not
- // counted as requests.
- }
- //-----------------------------------------------------------------------------
- static S32 countPingRequests()
- {
- // Need a function here because the ping list also includes
- // broadcast pings we don't want counted.
- U32 pSize = gPingList.size(), count = pSize;
- for (U32 i = 0; i < pSize; i++)
- if (gPingList[i].broadcast)
- count--;
- return count;
- }
- //-----------------------------------------------------------------------------
- static void pushServerFavorites()
- {
- S32 count = Con::getIntVariable( "$pref::Client::ServerFavoriteCount" );
- if ( count < 0 )
- {
- Con::setIntVariable( "$pref::Client::ServerFavoriteCount", 0 );
- return;
- }
- NetAddress addr;
- const char* server = NULL;
- char buf[256], serverName[25], addrString[256];
- U32 sz, len;
- for ( S32 i = 0; i < count; i++ )
- {
- dSprintf( buf, sizeof( buf ), "pref::Client::ServerFavorite%d", i );
- server = Con::getVariable( buf );
- if ( server )
- {
- sz = dStrcspn( server, "\t" );
- if ( sz > 0 )
- {
- len = sz > 24 ? 24 : sz;
- dStrncpy( serverName, server, len );
- serverName[len] = 0;
- dStrncpy( addrString, server + ( sz + 1 ), 255 );
- //Con::errorf( "Pushing server favorite \"%s\" - %s...", serverName, addrString );
- Net::stringToAddress( addrString, &addr );
- ServerInfo* si = findOrCreateServerInfo( &addr );
- AssertFatal(si, "pushServerFavorites - failed to create Server Info!" );
- dsize_t nameLen = dStrlen(serverName) + 1;
- si->name = (char*) dRealloc( (void*) si->name, nameLen );
- dStrcpy( si->name, serverName, nameLen );
- si->isFavorite = true;
- pushPingRequest( &addr );
- }
- }
- }
- }
- //-----------------------------------------------------------------------------
- static S32 findPingEntry( Vector<Ping> &v, const NetAddress* addr )
- {
- for ( U32 i = 0; i < v.size(); i++ )
- if ( Net::compareAddresses( addr, &v[i].address ) )
- return S32( i );
- return -1;
- }
- //-----------------------------------------------------------------------------
- static bool addressFinished( const NetAddress* addr )
- {
- for ( U32 i = 0; i < gFinishedList.size(); i++ )
- if ( Net::compareAddresses( addr, &gFinishedList[i] ) )
- return true;
- return false;
- }
- //-----------------------------------------------------------------------------
- static ServerInfo* findServerInfo( const NetAddress* addr )
- {
- for ( U32 i = 0; i < gServerList.size(); i++ )
- if ( Net::compareAddresses( addr, &gServerList[i].address ) )
- return &gServerList[i];
- return NULL;
- }
- //-----------------------------------------------------------------------------
- static ServerInfo* findOrCreateServerInfo( const NetAddress* addr )
- {
- ServerInfo* ret = findServerInfo( addr );
- if ( ret )
- return ret;
- ServerInfo si;
- si.address = *addr;
- gServerList.push_back( si );
- return &gServerList.last();
- }
- //-----------------------------------------------------------------------------
- static void removeServerInfo( const NetAddress* addr )
- {
- for ( U32 i = 0; i < gServerList.size(); i++ )
- {
- if ( Net::compareAddresses( addr, &gServerList[i].address ) )
- {
- gServerList.erase( i );
- gServerBrowserDirty = true;
- }
- }
- }
- //-----------------------------------------------------------------------------
- #if defined(TORQUE_DEBUG)
- // This function is solely for testing the functionality of the server browser
- // with more servers in the list.
- void addFakeServers( S32 howMany )
- {
- static S32 sNumFakeServers = 1;
- ServerInfo newServer;
- for ( S32 i = 0; i < howMany; i++ )
- {
- newServer.numPlayers = (U8)(Platform::getRandom() * 64.0f);
- newServer.maxPlayers = 64;
- char buf[256];
- dSprintf( buf, 255, "Fake server #%d", sNumFakeServers );
- dsize_t nameLen = dStrlen(buf) + 1;
- newServer.name = (char*) dMalloc( nameLen );
- dStrcpy( newServer.name, buf, nameLen );
- newServer.gameType = (char*) dMalloc( 5 );
- dStrcpy( newServer.gameType, "Fake", 5 );
- newServer.missionType = (char*) dMalloc( 16 );
- dStrcpy( newServer.missionType, "FakeMissionType", 16 );
- newServer.missionName = (char*) dMalloc( 14 );
- dStrcpy( newServer.missionName, "FakeMapName", 14 );
- Net::stringToAddress( "IP:198.74.33.35:28000", &newServer.address );
- newServer.ping = (U32)( Platform::getRandom() * 200.0f );
- newServer.cpuSpeed = 470;
- newServer.status = ServerInfo::Status_Responded;
- gServerList.push_back( newServer );
- sNumFakeServers++;
- }
- gServerBrowserDirty = true;
- }
- #endif // DEBUG
- //-----------------------------------------------------------------------------
- static void sendPacket( U8 pType, const NetAddress* addr, U32 key, U32 session, U8 flags )
- {
- BitStream *out = BitStream::getPacketStream();
- out->clearStringBuffer();
- out->write( pType );
- out->write( flags );
- out->write( U32( ( session << 16 ) | ( key & 0xFFFF ) ) );
- BitStream::sendPacketStream(addr);
- }
- //-----------------------------------------------------------------------------
- static void writeCString( BitStream* stream, const char* string )
- {
- U8 strLen = ( string != NULL ) ? dStrlen( string ) : 0;
- stream->write( strLen );
- for ( U32 i = 0; i < strLen; i++ )
- stream->write( U8( string[i] ) );
- }
- //-----------------------------------------------------------------------------
- static void readCString( BitStream* stream, char* buffer )
- {
- U32 i;
- U8 strLen;
- stream->read( &strLen );
- for ( i = 0; i < strLen; i++ )
- {
- U8* ptr = (U8*) buffer;
- stream->read( &ptr[i] );
- }
- buffer[i] = 0;
- }
- //-----------------------------------------------------------------------------
- static void writeLongCString( BitStream* stream, const char* string )
- {
- U16 strLen = ( string != NULL ) ? dStrlen( string ) : 0;
- stream->write( strLen );
- for ( U32 i = 0; i < strLen; i++ )
- stream->write( U8( string[i] ) );
- }
- //-----------------------------------------------------------------------------
- static void readLongCString( BitStream* stream, char* buffer )
- {
- U32 i;
- U16 strLen;
- stream->read( &strLen );
- for ( i = 0; i < strLen; i++ )
- {
- U8* ptr = (U8*) buffer;
- stream->read( &ptr[i] );
- }
- buffer[i] = 0;
- }
- //-----------------------------------------------------------------------------
- // Event processing
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- static void processMasterServerQuery( U32 session )
- {
- if ( session != gPingSession || !sgServerQueryActive )
- return;
- if ( !gGotFirstListPacket )
- {
- bool keepGoing = true;
- U32 time = Platform::getVirtualMilliseconds();
- char addressString[256];
- if ( gMasterServerPing.time + gMasterServerTimeout < time )
- {
- Net::addressToString( &gMasterServerPing.address, addressString );
- if ( !gMasterServerPing.tryCount )
- {
- // The query timed out.
- Con::printf( "Server list request to %s timed out.", addressString );
- // Remove this server from the list:
- for ( U32 i = 0; i < gMasterServerList.size(); i++ )
- {
- if ( Net::compareAddresses( &gMasterServerList[i].address, &gMasterServerPing.address ) )
- {
- gMasterServerList.erase( i );
- break;
- }
- }
- // Pick a new master server to try:
- keepGoing = pickMasterServer();
- if ( keepGoing )
- {
- Con::executef( "onServerQueryStatus", "update", "Switching master servers...", "0" );
- Net::addressToString( &gMasterServerPing.address, addressString );
- }
- }
- if ( keepGoing )
- {
- gMasterServerPing.tryCount--;
- gMasterServerPing.time = time;
- gMasterServerPing.key = gKey++;
- // Send a request to the master server for the server list:
- BitStream *out = BitStream::getPacketStream();
- out->clearStringBuffer();
- out->write( U8( NetInterface::MasterServerListRequest ) );
-
- out->write( U8( sActiveFilter.queryFlags) );
- out->write( ( gMasterServerPing.session << 16 ) | ( gMasterServerPing.key & 0xFFFF ) );
- out->write( U8( 255 ) );
- writeCString( out, sActiveFilter.gameType );
- writeCString( out, sActiveFilter.missionType );
- out->write( sActiveFilter.minPlayers );
- out->write( sActiveFilter.maxPlayers );
- out->write( sActiveFilter.regionMask );
- U32 version = ( sActiveFilter.filterFlags & ServerFilter::CurrentVersion ) ? getVersionNumber() : 0;
- out->write( version );
- out->write( sActiveFilter.filterFlags );
- out->write( sActiveFilter.maxBots );
- out->write( sActiveFilter.minCPU );
- out->write( sActiveFilter.buddyCount );
- for ( U32 i = 0; i < sActiveFilter.buddyCount; i++ )
- out->write( sActiveFilter.buddyList[i] );
- BitStream::sendPacketStream( &gMasterServerPing.address );
- Con::printf( "Requesting the server list from master server %s (%d tries left)...", addressString, gMasterServerPing.tryCount );
- if ( gMasterServerPing.tryCount < gMasterServerRetryCount - 1 )
- Con::executef( "onServerQueryStatus", "update", "Retrying the master server...", "0" );
- }
- }
- if ( keepGoing )
- {
- // schedule another check:
- Sim::postEvent( Sim::getRootGroup(), new ProcessMasterQueryEvent( session ), Sim::getTargetTime() + 1 );
- }
- else
- {
- Con::errorf( "There are no more master servers to try!" );
- Con::executef( "onServerQueryStatus", "done", "No master servers found.", "0" );
- }
- }
- }
- //-----------------------------------------------------------------------------
- static void processPingsAndQueries( U32 session, bool schedule )
- {
- if( session != gPingSession )
- return;
- U32 i = 0;
- U32 time = Platform::getVirtualMilliseconds();
- char addressString[256];
- U8 flags = ServerFilter::OnlineQuery;
- bool waitingForMaster = ( sActiveFilter.type == ServerFilter::Normal ) && !gGotFirstListPacket && sgServerQueryActive;
- for ( i = 0; i < gPingList.size() && i < gMaxConcurrentPings; )
- {
- Ping &p = gPingList[i];
- if ( p.time + gPingTimeout < time )
- {
- if ( !p.tryCount )
- {
- // it's timed out.
- if (!p.broadcast)
- {
- Net::addressToString( &p.address, addressString );
- Con::printf( "Ping to server %s timed out.", addressString );
- }
- // If server info is in list (favorite), set its status:
- ServerInfo* si = findServerInfo( &p.address );
- if ( si )
- {
- si->status = ServerInfo::Status_TimedOut;
- gServerBrowserDirty = true;
- }
- gFinishedList.push_back( p.address );
- gPingList.erase( i );
- if ( !waitingForMaster )
- updatePingProgress();
- }
- else
- {
- p.tryCount--;
- p.time = time;
- p.key = gKey++;
- Net::addressToString( &p.address, addressString );
- if (p.broadcast)
- Con::printf( "LAN server ping: %s...", addressString );
- else
- Con::printf( "Pinging Server %s (%d)...", addressString, p.tryCount );
- sendPacket( NetInterface::GamePingRequest, &p.address, p.key, p.session, flags );
- i++;
- }
- }
- else
- i++;
- }
- if ( !gPingList.size() && !waitingForMaster )
- {
- // Start the query phase:
- for ( i = 0; i < gQueryList.size() && i < gMaxConcurrentQueries; )
- {
- Ping &p = gQueryList[i];
- if ( p.time + gPingTimeout < time )
- {
- ServerInfo* si = findServerInfo( &p.address );
- if ( !si )
- {
- // Server info not found, so remove the query:
- gQueryList.erase( i );
- gServerBrowserDirty = true;
- continue;
- }
- Net::addressToString( &p.address, addressString );
- if ( !p.tryCount )
- {
- Con::printf( "Query to server %s timed out.", addressString );
- si->status = ServerInfo::Status_TimedOut;
- gQueryList.erase( i );
- gServerBrowserDirty = true;
- }
- else
- {
- p.tryCount--;
- p.time = time;
- p.key = gKey++;
- Con::printf( "Querying Server %s (%d)...", addressString, p.tryCount );
- sendPacket( NetInterface::GameInfoRequest, &p.address, p.key, p.session, flags );
- if ( !si->isQuerying() )
- {
- si->status |= ServerInfo::Status_Querying;
- gServerBrowserDirty = true;
- }
- i++;
- }
- }
- else
- i++;
- }
- }
- if ( gPingList.size() || gQueryList.size() || waitingForMaster )
- {
- // The LAN query function doesn't always want to schedule
- // the next ping.
- if (schedule)
- Sim::postEvent( Sim::getRootGroup(), new ProcessPingEvent( session ), Sim::getTargetTime() + 1 );
- }
- else
- {
- // All done!
- char msg[64];
- U32 foundCount = gServerList.size();
- if ( foundCount == 0 )
- dStrcpy( msg, "No servers found.", 64 );
- else if ( foundCount == 1 )
- dStrcpy( msg, "One server found.", 64 );
- else
- dSprintf( msg, sizeof( msg ), "%d servers found.", foundCount );
- Con::executef( "onServerQueryStatus", "done", (const char*)msg, "1");
- }
- }
- //-----------------------------------------------------------------------------
- static void processServerListPackets( U32 session )
- {
- if ( session != gPingSession || !sgServerQueryActive )
- return;
- U32 currentTime = Platform::getVirtualMilliseconds();
- // Loop through the packet status list and resend packet requests where necessary:
- for ( U32 i = 0; i < gPacketStatusList.size(); i++ )
- {
- PacketStatus &p = gPacketStatusList[i];
- if ( p.time + gPacketTimeout < currentTime )
- {
- if ( !p.tryCount )
- {
- // Packet timed out :(
- Con::printf( "Server list packet #%d timed out.", p.getIndex() + 1 );
- gPacketStatusList.erase( i );
- }
- else
- {
- // Try again...
- Con::printf( "Rerequesting server list packet #%d...", p.getIndex() + 1 );
- p.tryCount--;
- p.time = currentTime;
- p.key = gKey++;
- BitStream *out = BitStream::getPacketStream();
- bool extendedPacket = (sActiveFilter.queryFlags & ServerFilter::NewStyleResponse) != 0;
- out->clearStringBuffer();
- if ( extendedPacket )
- out->write( U8( NetInterface::MasterServerExtendedListRequest ) );
- else
- out->write( U8( NetInterface::MasterServerListRequest ) );
- out->write( U8( sActiveFilter.queryFlags ) ); // flags
- out->write( ( session << 16) | ( p.key & 0xFFFF ) );
-
- if ( extendedPacket )
- out->write( p.getOldIndex() ); // packet index
- else
- out->write( p.getIndex() ); // packet index
- out->write( U8( 0 ) ); // game type
- out->write( U8( 0 ) ); // mission type
- out->write( U8( 0 ) ); // minPlayers
- out->write( U8( 0 ) ); // maxPlayers
- out->write( U32( 0 ) ); // region mask
- out->write( U32( 0 ) ); // version
- out->write( U8( 0 ) ); // filter flags
- out->write( U8( 0 ) ); // max bots
- out->write( U16( 0 ) ); // min CPU
- out->write( U8( 0 ) ); // buddy count
- BitStream::sendPacketStream(&gMasterServerQueryAddress);
- }
- }
- }
- if ( gPacketStatusList.size() )
- Sim::postEvent( Sim::getRootGroup(), new ProcessPacketEvent( session ), Sim::getCurrentTime() + 30 );
- else
- processPingsAndQueries( gPingSession );
- }
- //-----------------------------------------------------------------------------
- static void processHeartbeat(U32 seq)
- {
- if(seq != gHeartbeatSeq)
- return;
- sendHeartbeat( 0 );
- Sim::postEvent( Sim::getRootGroup(), new HeartbeatEvent(seq), Sim::getCurrentTime() + gHeartbeatInterval );
- }
- //-----------------------------------------------------------------------------
- static void updatePingProgress()
- {
- if ( !gPingList.size() )
- {
- updateQueryProgress();
- return;
- }
- char msg[64];
- U32 pingsLeft = countPingRequests();
- dSprintf( msg, sizeof(msg),
- (!pingsLeft && gPingList.size())?
- "Waiting for lan servers...":
- "Pinging servers: %d left...",
- pingsLeft );
- // Ping progress is 0 -> 0.5
- F32 progress = 0.0f;
- if ( gServerPingCount )
- progress = F32( gServerPingCount - pingsLeft ) / F32( gServerPingCount * 2 );
- //Con::errorf( ConsoleLogEntry::General, "Ping progress - %d of %d left - progress = %.2f", pingsLeft, gServerPingCount, progress );
- Con::executef( "onServerQueryStatus", "ping", msg, Con::getFloatArg( progress ) );
- }
- //-----------------------------------------------------------------------------
- static void updateQueryProgress()
- {
- if ( gPingList.size() )
- return;
- char msg[64];
- U32 queriesLeft = gQueryList.size();
- dSprintf( msg, sizeof( msg ), "Querying servers: %d left...", queriesLeft );
- // Query progress is 0.5 -> 1
- F32 progress = 0.5f;
- if ( gServerQueryCount )
- progress += ( F32( gServerQueryCount - queriesLeft ) / F32( gServerQueryCount * 2 ) );
- //Con::errorf( ConsoleLogEntry::General, "Query progress - %d of %d left - progress = %.2f", queriesLeft, gServerQueryCount, progress );
- Con::executef( "onServerQueryStatus", "query", msg, Con::getFloatArg( progress ) );
- }
- //-----------------------------------------------------------------------------
- // Server packet handlers:
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- static void handleMasterServerGameTypesResponse( BitStream* stream, U32 /*key*/, U8 /*flags*/ )
- {
- Con::printf( "Received game type list from the master server." );
- U32 i;
- U8 temp;
- char stringBuf[256];
- stream->read( &temp );
- Con::executef("onClearGameTypes");
- for ( i = 0; i < U32( temp ); i++ )
- {
- readCString( stream, stringBuf );
- Con::executef("onAddGameType", stringBuf);
- }
- stream->read( &temp );
- Con::executef("onClearMissionTypes");
- for ( i = 0; i < U32( temp ); i++ )
- {
- readCString( stream, stringBuf );
- Con::executef("onAddMissionType", stringBuf);
- }
- }
- //-----------------------------------------------------------------------------
- static void handleMasterServerListResponse( BitStream* stream, U32 key, U8 /*flags*/ )
- {
- U8 packetIndex, packetTotal;
- U32 i;
- U16 serverCount, port;
- U8 netNum[4];
- char addressBuffer[256];
- NetAddress addr;
- stream->read( &packetIndex );
- // Validate the packet key:
- U32 packetKey = gMasterServerPing.key;
- if ( gGotFirstListPacket )
- {
- for ( i = 0; i < gPacketStatusList.size(); i++ )
- {
- if ( gPacketStatusList[i].index == packetIndex )
- {
- packetKey = gPacketStatusList[i].key;
- break;
- }
- }
- }
- U32 testKey = ( gPingSession << 16 ) | ( packetKey & 0xFFFF );
- if ( testKey != key )
- return;
- stream->read( &packetTotal );
- stream->read( &serverCount );
- Con::printf( "Received server list packet %d of %d from the master server (%d servers).", ( packetIndex + 1 ), packetTotal, serverCount );
- // Enter all of the servers in this packet into the ping list:
- for ( i = 0; i < serverCount; i++ )
- {
- stream->read( &netNum[0] );
- stream->read( &netNum[1] );
- stream->read( &netNum[2] );
- stream->read( &netNum[3] );
- stream->read( &port );
- dSprintf( addressBuffer, sizeof( addressBuffer ), "IP:%d.%d.%d.%d:%d", netNum[0], netNum[1], netNum[2], netNum[3], port );
- Net::stringToAddress( addressBuffer, &addr );
- pushPingRequest( &addr );
- }
- // If this is the first list packet we have received, fill the packet status list
- // and start processing:
- if ( !gGotFirstListPacket )
- {
- gGotFirstListPacket = true;
- gMasterServerQueryAddress = gMasterServerPing.address;
- U32 currentTime = Platform::getVirtualMilliseconds();
- for ( i = 0; i < packetTotal; i++ )
- {
- if ( i != packetIndex )
- {
- PacketStatus p = PacketStatus( i, gMasterServerPing.key, currentTime );
- gPacketStatusList.push_back( p );
- }
- }
- processServerListPackets( gPingSession );
- }
- else
- {
- // Remove the packet we just received from the status list:
- for ( i = 0; i < gPacketStatusList.size(); i++ )
- {
- if ( gPacketStatusList[i].index == packetIndex )
- {
- gPacketStatusList.erase( i );
- break;
- }
- }
- }
- }
- //-----------------------------------------------------------------------------
- static void handleExtendedMasterServerListResponse(BitStream* stream, U32 key, U8 /*flags*/)
- {
- U16 packetIndex, packetTotal;
- U32 i;
- U16 serverCount;
- NetAddress addr;
- stream->read(&packetIndex);
- // Validate the packet key:
- U32 packetKey = gMasterServerPing.key;
- if (gGotFirstListPacket)
- {
- for (i = 0; i < gPacketStatusList.size(); i++)
- {
- if (gPacketStatusList[i].index == packetIndex)
- {
- packetKey = gPacketStatusList[i].key;
- break;
- }
- }
- }
- U32 testKey = (gPingSession << 16) | (packetKey & 0xFFFF);
- if (testKey != key)
- return;
- stream->read(&packetTotal);
- stream->read(&serverCount);
- Con::printf("Received server list packet %d of %d from the master server (%d servers).", (packetIndex + 1), packetTotal, serverCount);
- // Enter all of the servers in this packet into the ping list:
- for (i = 0; i < serverCount; i++)
- {
- U8 type;
- stream->read(&type);
- dMemset(&addr, '\0', sizeof(NetAddress));
- if (type == 0)
- {
- // IPV4
- addr.type = NetAddress::IPAddress;
- stream->read(4, &addr.address.ipv4.netNum[0]);
- stream->read(&addr.port);
- }
- else
- {
- // IPV6
- addr.type = NetAddress::IPV6Address;
- stream->read(16, &addr.address.ipv6.netNum[0]);
- stream->read(&addr.port);
- }
- pushPingRequest(&addr);
- }
- // If this is the first list packet we have received, fill the packet status list
- // and start processing:
- if (!gGotFirstListPacket)
- {
- gGotFirstListPacket = true;
- gMasterServerQueryAddress = gMasterServerPing.address;
- U32 currentTime = Platform::getVirtualMilliseconds();
- for (i = 0; i < packetTotal; i++)
- {
- if (i != packetIndex)
- {
- PacketStatus p = PacketStatus(i, gMasterServerPing.key, currentTime);
- gPacketStatusList.push_back(p);
- }
- }
- processServerListPackets(gPingSession);
- }
- else
- {
- // Remove the packet we just received from the status list:
- for (i = 0; i < gPacketStatusList.size(); i++)
- {
- if (gPacketStatusList[i].index == packetIndex)
- {
- gPacketStatusList.erase(i);
- break;
- }
- }
- }
- }
- //-----------------------------------------------------------------------------
- static void handleGameMasterInfoRequest( const NetAddress* address, U32 key, U8 flags )
- {
- if ( GNet->doesAllowConnections() )
- {
- U8 temp8;
- U32 temp32;
- char netString[256];
- Net::addressToString(address, netString);
- Vector<MasterInfo> *masterList = getMasterServerList();
- const NetAddress *masterAddr;
- bool fromMaster = false;
- for(U32 i = 0; i < masterList->size(); i++)
- {
- masterAddr = &(*masterList)[i].address;
- if (masterAddr->isSameAddress(*address))
- {
- fromMaster = true;
- break;
- }
- }
- Con::printf( "Received info request from %s [%s].", fromMaster?"a master server":"a machine", netString);
- BitStream *out = BitStream::getPacketStream();
- out->clearStringBuffer();
- out->write( U8( NetInterface::GameMasterInfoResponse ) );
- out->write( U8( flags ) );
- out->write( key );
- writeCString( out, Con::getVariable( "Server::GameType" ) );
- writeCString( out, Con::getVariable( "Server::MissionType" ) );
- temp8 = U8( Con::getIntVariable( "pref::Server::MaxPlayers" ) );
- out->write( temp8 );
- temp32 = Con::getIntVariable( "pref::Server::RegionMask" );
- out->write( temp32 );
- temp32 = getVersionNumber();
- out->write( temp32 );
- temp8 = 0;
- #if defined(TORQUE_OS_LINUX) || defined(TORQUE_OS_OPENBSD)
- temp8 |= ServerInfo::Status_Linux;
- #endif
- if ( Con::getBoolVariable( "Server::Dedicated" ) )
- temp8 |= ServerInfo::Status_Dedicated;
- if ( dStrlen( Con::getVariable( "pref::Server::Password" ) ) > 0 )
- temp8 |= ServerInfo::Status_Passworded;
- out->write( temp8 );
- temp8 = U8( Con::getIntVariable( "Server::BotCount" ) );
- out->write( temp8 );
- out->write( Platform::SystemInfo.processor.mhz );
- U8 playerCount = U8( Con::getIntVariable( "Server::PlayerCount" ) );
- out->write( playerCount );
- const char* guidList = Con::getVariable( "Server::GuidList" );
- dsize_t bufLen = dStrlen(guidList) + 1;
- char* buf = new char[bufLen];
- dStrcpy( buf, guidList, bufLen );
- char* temp = dStrtok( buf, "\t" );
- temp8 = 0;
- for ( ; temp && temp8 < playerCount; temp8++ )
- {
- out->write( U32( dAtoi( temp ) ) );
- temp = dStrtok( NULL, "\t" );
- temp8++;
- }
- for ( ; temp8 < playerCount; temp8++ )
- out->write( U32( 0 ) );
- delete [] buf;
- BitStream::sendPacketStream(address);
- }
- }
- //-----------------------------------------------------------------------------
- static void handleGamePingRequest( const NetAddress* address, U32 key, U8 flags )
- {
- // Do not respond if a mission is not running:
- if ( GNet->doesAllowConnections() )
- {
- // Do not respond if this is a single-player game:
- if ( dStricmp( Con::getVariable( "Server::ServerType" ), "SinglePlayer" ) == 0 )
- return;
- // Do not respond to offline queries if this is an online server:
- if ( flags & ServerFilter::OfflineQuery )
- return;
- // some banning code here (?)
- BitStream *out = BitStream::getPacketStream();
- out->clearStringBuffer();
- out->write( U8( NetInterface::GamePingResponse ) );
- out->write( flags );
- out->write( key );
- if ( flags & ServerFilter::NoStringCompress )
- writeCString( out, versionString );
- else
- out->writeString( versionString );
- out->write( GameConnection::CurrentProtocolVersion );
- out->write( GameConnection::MinRequiredProtocolVersion );
- out->write( getVersionNumber() );
- // Enforce a 24-character limit on the server name:
- char serverName[25];
- dStrncpy( serverName, Con::getVariable( "pref::Server::Name" ), 24 );
- serverName[24] = 0;
- if ( flags & ServerFilter::NoStringCompress )
- writeCString( out, serverName );
- else
- out->writeString( serverName );
- BitStream::sendPacketStream(address);
- }
- }
- //-----------------------------------------------------------------------------
- static void handleGamePingResponse( const NetAddress* address, BitStream* stream, U32 key, U8 /*flags*/ )
- {
- // Broadcast has timed out or query has been cancelled:
- if( !gPingList.size() )
- return;
- S32 index = findPingEntry( gPingList, address );
- if( index == -1 )
- {
- // an anonymous ping response - if it's not already timed
- // out or finished, ping it. Probably from a broadcast
- if( !addressFinished( address ) )
- pushPingRequest( address );
- return;
- }
- Ping &p = gPingList[index];
- U32 infoKey = ( p.session << 16 ) | ( p.key & 0xFFFF );
- if( infoKey != key )
- return;
- // Find if the server info already exists (favorite or refreshing):
- ServerInfo* si = findServerInfo( address );
- bool applyFilter = false;
- if ( sActiveFilter.type == ServerFilter::Normal )
- applyFilter = si ? !si->isUpdating() : true;
- char addrString[256];
- Net::addressToString( address, addrString );
- bool waitingForMaster = ( sActiveFilter.type == ServerFilter::Normal ) && !gGotFirstListPacket;
- // Verify the version:
- char buf[256];
- stream->readString( buf );
- if ( String::compare( buf, versionString ) != 0 )
- {
- // Version is different, so remove it from consideration:
- Con::printf( "Server %s is a different version.", addrString );
- Con::printf( "Wanted version %s, got version %s", versionString, buf);
- gFinishedList.push_back( *address );
- gPingList.erase( index );
- if ( si )
- {
- si->status = ServerInfo::Status_TimedOut;
- gServerBrowserDirty = true;
- }
- if ( !waitingForMaster )
- updatePingProgress();
- return;
- }
- // See if the server meets our minimum protocol:
- U32 temp32;
- stream->read( &temp32 );
- if ( temp32 < GameConnection::MinRequiredProtocolVersion )
- {
- Con::printf( "Protocol for server %s does not meet minimum protocol.", addrString );
- gFinishedList.push_back( *address );
- gPingList.erase( index );
- if ( si )
- {
- si->status = ServerInfo::Status_TimedOut;
- gServerBrowserDirty = true;
- }
- if ( !waitingForMaster )
- updatePingProgress();
- return;
- }
- // See if we meet the server's minimum protocol:
- stream->read( &temp32 );
- if ( GameConnection::CurrentProtocolVersion < temp32 )
- {
- Con::printf( "You do not meet the minimum protocol for server %s.", addrString );
- gFinishedList.push_back( *address );
- gPingList.erase( index );
- if ( si )
- {
- si->status = ServerInfo::Status_TimedOut;
- gServerBrowserDirty = true;
- }
- if ( !waitingForMaster )
- updatePingProgress();
- return;
- }
- // Calculate the ping:
- U32 time = Platform::getVirtualMilliseconds();
- U32 ping = ( time > p.time ) ? time - p.time : 0;
- // Check for max ping filter:
- if ( applyFilter && sActiveFilter.maxPing > 0 && ping > sActiveFilter.maxPing )
- {
- // Ping is too high, so remove this server from consideration:
- Con::printf( "Server %s filtered out by maximum ping.", addrString );
- gFinishedList.push_back( *address );
- gPingList.erase( index );
- if ( si )
- removeServerInfo( address );
- if ( !waitingForMaster )
- updatePingProgress();
- return;
- }
- // Get the server build version:
- stream->read( &temp32 );
- if ( applyFilter
- && ( sActiveFilter.filterFlags & ServerFilter::CurrentVersion )
- && ( temp32 != getVersionNumber() ) )
- {
- Con::printf( "Server %s filtered out by version number.", addrString );
- gFinishedList.push_back( *address );
- gPingList.erase( index );
- if ( si )
- removeServerInfo( address );
- if ( !waitingForMaster )
- updatePingProgress();
- return;
- }
- // OK, we can finally create the server info structure:
- if ( !si )
- si = findOrCreateServerInfo( address );
- si->ping = ping;
- si->version = temp32;
- // Get the server name:
- stream->readString( buf );
- if ( !si->name )
- {
- dsize_t bufLen = dStrlen(buf) + 1;
- si->name = (char*) dMalloc(bufLen);
- dStrcpy( si->name, buf, bufLen );
- }
- // Set the server up to be queried:
- gFinishedList.push_back( *address );
- p.key = 0;
- p.time = 0;
- p.tryCount = gQueryRetryCount;
- gQueryList.push_back( p );
- gServerQueryCount++;
- gPingList.erase( index );
- if ( !waitingForMaster )
- updatePingProgress();
- // Update the server browser gui!
- gServerBrowserDirty = true;
- }
- //-----------------------------------------------------------------------------
- static void handleGameInfoRequest( const NetAddress* address, U32 key, U8 flags )
- {
- // Do not respond unless there is a server running:
- if ( GNet->doesAllowConnections() )
- {
- // Do not respond to offline queries if this is an online server:
- if ( flags & ServerFilter::OfflineQuery )
- return;
- bool compressStrings = !( flags & ServerFilter::NoStringCompress );
- BitStream *out = BitStream::getPacketStream();
- out->clearStringBuffer();
- out->write( U8( NetInterface::GameInfoResponse ) );
- out->write( flags );
- out->write( key );
- if ( compressStrings ) {
- out->writeString( Con::getVariable( "Server::GameType" ) );
- out->writeString( Con::getVariable( "Server::MissionType" ) );
- out->writeString( Con::getVariable( "Server::MissionName" ) );
- }
- else {
- writeCString( out, Con::getVariable( "Server::GameType" ) );
- writeCString( out, Con::getVariable( "Server::MissionType" ) );
- writeCString( out, Con::getVariable( "Server::MissionName" ) );
- }
- U8 status = 0;
- #if defined(TORQUE_OS_LINUX) || defined(TORQUE_OS_OPENBSD)
- status |= ServerInfo::Status_Linux;
- #endif
- if ( Con::getBoolVariable( "Server::Dedicated" ) )
- status |= ServerInfo::Status_Dedicated;
- if ( dStrlen( Con::getVariable( "pref::Server::Password" ) ) )
- status |= ServerInfo::Status_Passworded;
- out->write( status );
- out->write( U8( Con::getIntVariable( "Server::PlayerCount" ) ) );
- out->write( U8( Con::getIntVariable( "pref::Server::MaxPlayers" ) ) );
- out->write( U8( Con::getIntVariable( "Server::BotCount" ) ) );
- out->write( U16( Platform::SystemInfo.processor.mhz ) );
- if ( compressStrings )
- out->writeString( Con::getVariable( "pref::Server::Info" ) );
- else
- writeCString( out, Con::getVariable( "pref::Server::Info" ) );
- writeLongCString( out, Con::evaluate( "onServerInfoQuery();" ) );
- BitStream::sendPacketStream(address);
- }
- }
- //-----------------------------------------------------------------------------
- static void handleGameInfoResponse( const NetAddress* address, BitStream* stream, U32 /*key*/, U8 /*flags*/ )
- {
- if ( !gQueryList.size() )
- return;
- S32 index = findPingEntry( gQueryList, address );
- if ( index == -1 )
- return;
- // Remove the server from the query list since it has been so kind as to respond:
- gQueryList.erase( index );
- updateQueryProgress();
- ServerInfo *si = findServerInfo( address );
- if ( !si )
- return;
- bool isUpdate = si->isUpdating();
- bool applyFilter = !isUpdate && ( sActiveFilter.type == ServerFilter::Normal );
- char addrString[256];
- Net::addressToString( address, addrString );
- // Get the rules set:
- char stringBuf[2048]; // Who knows how big this should be?
- stream->readString( stringBuf );
- if ( !si->gameType || dStricmp( si->gameType, stringBuf ) != 0 )
- {
- dsize_t gameTypeLen = dStrlen(stringBuf) + 1;
- si->gameType = (char*) dRealloc( (void*) si->gameType, gameTypeLen );
- dStrcpy( si->gameType, stringBuf, gameTypeLen );
- // Test against the active filter:
- if ( applyFilter && dStricmp( sActiveFilter.gameType, "any" ) != 0
- && dStricmp( si->gameType, sActiveFilter.gameType ) != 0 )
- {
- Con::printf( "Server %s filtered out by rules set. (%s:%s)", addrString, sActiveFilter.gameType, si->gameType );
- removeServerInfo( address );
- return;
- }
- }
- // Get the mission type:
- stream->readString( stringBuf );
- if ( !si->missionType || String::compare( si->missionType, stringBuf ) != 0 )
- {
- dsize_t missionTypeLen = dStrlen(stringBuf) + 1;
- si->missionType = (char*) dRealloc( (void*) si->missionType, missionTypeLen );
- dStrcpy( si->missionType, stringBuf, missionTypeLen );
- // Test against the active filter:
- if ( applyFilter && dStricmp( sActiveFilter.missionType, "any" ) != 0
- && dStricmp( si->missionType, sActiveFilter.missionType ) != 0 )
- {
- Con::printf( "Server %s filtered out by mission type. (%s:%s)", addrString, sActiveFilter.missionType, si->missionType );
- removeServerInfo( address );
- return;
- }
- }
- // Get the mission name:
- stream->readString( stringBuf );
- // Clip the file extension off:
- char* temp = dStrstr( static_cast<char*>( stringBuf ), const_cast<char*>( ".mis" ) );
- if ( temp )
- *temp = '\0';
- if ( !si->missionName || String::compare( si->missionName, stringBuf ) != 0 )
- {
- dsize_t missionNameLen = dStrlen(stringBuf) + 1;
- si->missionName = (char*) dRealloc( (void*) si->missionName, missionNameLen );
- dStrcpy( si->missionName, stringBuf, missionNameLen );
- }
- // Get the server status:
- U8 temp_U8;
- stream->read( &temp_U8 );
- si->status = temp_U8;
- // Filter by the flags:
- if ( applyFilter )
- {
- if ( sActiveFilter.filterFlags & ServerFilter::Dedicated && !si->isDedicated() )
- {
- Con::printf( "Server %s filtered out by dedicated flag.", addrString );
- removeServerInfo( address );
- return;
- }
- if ( sActiveFilter.filterFlags & ServerFilter::NotPassworded && si->isPassworded() )
- {
- Con::printf( "Server %s filtered out by no-password flag.", addrString );
- removeServerInfo( address );
- return;
- }
- }
- si->status.set( ServerInfo::Status_Responded );
- // Get the player count:
- stream->read( &si->numPlayers );
- // Test player count against active filter:
- if ( applyFilter && ( si->numPlayers < sActiveFilter.minPlayers || si->numPlayers > sActiveFilter.maxPlayers ) )
- {
- Con::printf( "Server %s filtered out by player count.", addrString );
- removeServerInfo( address );
- return;
- }
- // Get the max players and bot count:
- stream->read( &si->maxPlayers );
- stream->read( &si->numBots );
- // Test bot count against active filter:
- if ( applyFilter && ( si->numBots > sActiveFilter.maxBots ) )
- {
- Con::printf( "Server %s filtered out by maximum bot count.", addrString );
- removeServerInfo( address );
- return;
- }
- // Get the CPU speed;
- U16 temp_U16;
- stream->read( &temp_U16 );
- si->cpuSpeed = temp_U16;
- // Test CPU speed against active filter:
- if ( applyFilter && ( si->cpuSpeed < sActiveFilter.minCPU ) )
- {
- Con::printf( "Server %s filtered out by minimum CPU speed.", addrString );
- removeServerInfo( address );
- return;
- }
- // Get the server info:
- stream->readString( stringBuf );
- if ( !si->statusString || ( isUpdate && String::compare( si->statusString, stringBuf ) != 0 ) )
- {
- dsize_t infoLen = dStrlen(stringBuf) + 1;
- si->infoString = (char*) dRealloc( (void*) si->infoString, infoLen );
- dStrcpy( si->infoString, stringBuf, infoLen );
- }
- // Get the content string:
- readLongCString( stream, stringBuf );
- if ( !si->statusString || ( isUpdate && String::compare( si->statusString, stringBuf ) != 0 ) )
- {
- dsize_t statusLen = dStrlen(stringBuf) + 1;
- si->statusString = (char*) dRealloc( (void*) si->statusString, statusLen );
- dStrcpy( si->statusString, stringBuf, statusLen );
- }
- // Update the server browser gui!
- gServerBrowserDirty = true;
- }
- //-----------------------------------------------------------------------------
- // Packet Dispatch
- void DemoNetInterface::handleInfoPacket( const NetAddress* address, U8 packetType, BitStream* stream )
- {
- U8 flags;
- U32 key;
- stream->read( &flags );
- stream->read( &key );
- stream->clearStringBuffer();
- switch( packetType )
- {
- case GamePingRequest:
- handleGamePingRequest( address, key, flags );
- break;
- case GamePingResponse:
- handleGamePingResponse( address, stream, key, flags );
- break;
- case GameInfoRequest:
- handleGameInfoRequest( address, key, flags );
- break;
- case GameInfoResponse:
- handleGameInfoResponse( address, stream, key, flags );
- break;
- case MasterServerGameTypesResponse:
- handleMasterServerGameTypesResponse( stream, key, flags );
- break;
- case MasterServerListResponse:
- handleMasterServerListResponse( stream, key, flags );
- break;
- case GameMasterInfoRequest:
- handleGameMasterInfoRequest( address, key, flags );
- break;
- case MasterServerExtendedListResponse:
- handleExtendedMasterServerListResponse(stream, key, flags);
- break;
- }
- }
- ConsoleFunctionGroupEnd( ServerQuery );
|