1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236 |
- //-----------------------------------------------------------------------------
- // 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 );
- }
- //-----------------------------------------------------------------------------
- DefineConsoleFunction( 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);
- }
- DefineConsoleFunction( 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 || dStrcmp( 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 || dStrcmp( 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 );
- }
- DefineConsoleFunction( 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);
- }
- //-----------------------------------------------------------------------------
- DefineConsoleFunction( 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;
- }
- }
- DefineConsoleFunction( 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();
- }
- }
- DefineConsoleFunction( stopServerQuery, void, (), , "stopServerQuery();" )
- {
- stopServerQuery();
- }
- //-----------------------------------------------------------------------------
- DefineConsoleFunction( startHeartbeat, void, (), , "startHeartbeat();" )
- {
- if (validateAuthenticatedServer()) {
- gHeartbeatSeq++;
- processHeartbeat(gHeartbeatSeq); // thump-thump...
- }
- }
- DefineConsoleFunction( stopHeartbeat, void, (), , "stopHeartbeat();" )
- {
- gHeartbeatSeq++;
- }
- //-----------------------------------------------------------------------------
- DefineConsoleFunction( getServerCount, int, (), , "getServerCount();" )
- {
- return gServerList.size();
- }
- DefineConsoleFunction( 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 = new 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, port;
- U8 netNum[16];
- 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++)
- {
- 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 = new 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 ( dStrcmp( 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 || dStrcmp( 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 || dStrcmp( 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 && dStrcmp( 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 && dStrcmp( 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 );
|