serverQuery.cc 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. //-----------------------------------------------------------------------------
  23. // Server Query States:
  24. // 1: Master server query status -> wait for master response
  25. // 2: Master server packet status -> wait for master packets to arrive
  26. // 3: Server ping status -> wait for servers to respond to pings
  27. // 4: Server query status -> wait for servers to respond to queries
  28. // 5: Done
  29. // Master Server Packets:
  30. // Header
  31. // message Message id
  32. // flags Query flags
  33. // sequenceNumber Packet sequence id
  34. // Server Query Filter Packet
  35. // packetIndex Request specific page # (rest empty)
  36. // gameType Game type string
  37. // missionType Mission type string
  38. // minPlayers At least this many players
  39. // maxPlayers No more than this many
  40. // regions Region mask, 0 = all
  41. // version Server version, 0 = any
  42. // filterFlags Server flags (dedicated, etc), 0 = any
  43. // maxBots No more than maxBots
  44. // minCPUSpeed At least this fast
  45. // playerCount Buddy list search
  46. // playerList[playerCount]
  47. // Master Server Info Packet
  48. // gameType Game type string
  49. // missionType Mission type string
  50. // maxPlayers Max allowed
  51. // regions Region mask
  52. // version Server version #
  53. // infoFlags Server flags (dedicated, etc)
  54. // numBots Current bot count
  55. // CPUSpeed Server CPU speed
  56. // playerCount Current player count
  57. // playerList[playerCount]
  58. // Game Info Query Packet
  59. // gameType Game type string
  60. // missionType Mission type string
  61. // missionName You get one guess...
  62. // satusFlags Dedicated, etc.
  63. // playerCount Current player count
  64. // maxPlayers Max allowed
  65. // numBots Current bot count
  66. // CPUSpeed Server CPU speed
  67. // statusString Server info message
  68. // statusString Server status message
  69. // Accessed Environment Vars
  70. // Server::MissionType
  71. // Server::MissionName
  72. // Server::GameType
  73. // Server::ServerType
  74. // Server::PlayerCount
  75. // Server::BotCount
  76. // Server::GuidList[playerCount]
  77. // Server::Dedicated
  78. // Server::Status
  79. // Pref::Server::Name
  80. // Pref::Server::Password
  81. // Pref::Server::Info
  82. // Pref::Server::MaxPlayers
  83. // Pref::Server::RegionMask
  84. // Pref::Net::RegionMask
  85. // Pref::Client::Master[n]
  86. // Pref::Client::ServerFavoriteCount
  87. // Pref::Client::ServerFavorite[ServerFavoriteCount]
  88. //-----------------------------------------------------------------------------
  89. #include "network/serverQuery.h"
  90. #include "platform/platform.h"
  91. #include "platform/event.h"
  92. #include "network/connectionProtocol.h"
  93. #include "collection/vector.h"
  94. #include "io/resource/resourceManager.h"
  95. #include "io/bitStream.h"
  96. #include "console/console.h"
  97. #include "sim/simBase.h"
  98. #include "game/version.h"
  99. #include "game/gameConnection.h"
  100. #include "serverQuery_ScriptBinding.h"
  101. // This is basically the server query protocol version now:
  102. static const char* versionString = "VER1";
  103. Vector<ServerInfo> gServerList(__FILE__, __LINE__);
  104. static Vector<MasterInfo> gMasterServerList(__FILE__, __LINE__);
  105. static Vector<NetAddress> gFinishedList(__FILE__, __LINE__); // timed out servers and finished servers go here
  106. NetAddress gMasterServerQueryAddress;
  107. bool gServerBrowserDirty = false;
  108. static const U32 gHeartbeatInterval = 120000;
  109. static const S32 gMasterServerRetryCount = 3;
  110. static const S32 gMasterServerTimeout = 2000;
  111. static const S32 gPacketRetryCount = 4;
  112. static const S32 gPacketTimeout = 1000;
  113. static const S32 gMaxConcurrentPings = 10;
  114. static const S32 gMaxConcurrentQueries = 2;
  115. static const S32 gPingRetryCount = 4;
  116. static const S32 gPingTimeout = 800;
  117. static const S32 gQueryRetryCount = 4;
  118. //static const S32 gQueryTimeout = 1000;
  119. // State variables:
  120. static bool sgServerQueryActive = false;
  121. static S32 gPingSession = 0;
  122. static S32 gKey = 0;
  123. static bool gGotFirstListPacket = false;
  124. // Variables used for the interface:
  125. static U32 gServerPingCount = 0;
  126. static U32 gServerQueryCount = 0;
  127. static U32 gHeartbeatSeq = 0;
  128. //-----------------------------------------------------------------------------
  129. struct Ping
  130. {
  131. NetAddress address;
  132. S32 session;
  133. S32 key;
  134. U32 time;
  135. U32 tryCount;
  136. bool broadcast;
  137. };
  138. static Ping gMasterServerPing;
  139. static Vector<Ping> gPingList(__FILE__, __LINE__);
  140. static Vector<Ping> gQueryList(__FILE__, __LINE__);
  141. //-----------------------------------------------------------------------------
  142. struct PacketStatus
  143. {
  144. U8 index;
  145. S32 key;
  146. U32 time;
  147. U32 tryCount;
  148. PacketStatus( U8 _index, S32 _key, U32 _time )
  149. {
  150. index = _index;
  151. key = _key;
  152. time = _time;
  153. tryCount = gPacketRetryCount;
  154. }
  155. };
  156. static Vector<PacketStatus> gPacketStatusList(__FILE__, __LINE__);
  157. //-----------------------------------------------------------------------------
  158. struct ServerFilter
  159. {
  160. enum Type
  161. {
  162. Normal = 0,
  163. Buddy = 1,
  164. Offline = 2,
  165. Favorites = 3,
  166. };
  167. Type type;
  168. char* gameType;
  169. char* missionType;
  170. enum // Query Flags
  171. {
  172. OnlineQuery = 0, // Authenticated with master
  173. OfflineQuery = BIT(0), // On our own
  174. NoStringCompress = BIT(1),
  175. };
  176. enum // Filter flags:
  177. {
  178. Dedicated = BIT(0),
  179. NotPassworded = BIT(1),
  180. Linux = BIT(2),
  181. CurrentVersion = BIT(7),
  182. };
  183. U8 queryFlags;
  184. U8 minPlayers;
  185. U8 maxPlayers;
  186. U8 maxBots;
  187. U32 regionMask;
  188. U32 maxPing;
  189. U8 filterFlags;
  190. U16 minCPU;
  191. U8 buddyCount;
  192. U32* buddyList;
  193. ServerFilter()
  194. {
  195. queryFlags = 0;
  196. gameType = NULL;
  197. missionType = NULL;
  198. minPlayers = 0;
  199. maxPlayers = 255;
  200. maxBots = 16;
  201. regionMask = 0xFFFFFFFF;
  202. maxPing = 0;
  203. filterFlags = 0;
  204. minCPU = 0;
  205. buddyCount = 0;
  206. buddyList = NULL;
  207. }
  208. ~ServerFilter()
  209. {
  210. if ( gameType )
  211. dFree( gameType );
  212. if ( missionType )
  213. dFree( missionType );
  214. if ( buddyList )
  215. dFree( buddyList );
  216. }
  217. };
  218. static ServerFilter sActiveFilter;
  219. //-----------------------------------------------------------------------------
  220. // Forward function declarations:
  221. //-----------------------------------------------------------------------------
  222. static void pushPingRequest( const NetAddress *addr );
  223. static void pushPingBroadcast( const NetAddress *addr );
  224. static void pushServerFavorites();
  225. static bool pickMasterServer();
  226. static S32 findPingEntry( Vector<Ping> &v, const NetAddress* addr );
  227. static bool addressFinished( const NetAddress* addr );
  228. static ServerInfo* findServerInfo( const NetAddress* addr );
  229. static ServerInfo* findOrCreateServerInfo( const NetAddress* addr );
  230. static void removeServerInfo( const NetAddress* addr );
  231. static void sendPacket( U8 pType, const NetAddress* addr, U32 key, U32 session, U8 flags );
  232. static void writeCString( BitStream* stream, const char* string );
  233. static void readCString( BitStream* stream, char* buffer );
  234. static void writeLongCString( BitStream* stream, const char* string );
  235. static void readLongCString( BitStream* stream, char* buffer );
  236. static void processMasterServerQuery( U32 session );
  237. static void processPingsAndQueries( U32 session, bool schedule = true);
  238. static void processServerListPackets( U32 session );
  239. static void processHeartbeat(U32);
  240. static void updatePingProgress();
  241. static void updateQueryProgress();
  242. Vector<MasterInfo>* getMasterServerList();
  243. bool pickMasterServer();
  244. void clearServerList();
  245. //-----------------------------------------------------------------------------
  246. // Events
  247. //-----------------------------------------------------------------------------
  248. //----------------------------------------------------------------
  249. class ProcessMasterQueryEvent : public SimEvent
  250. {
  251. U32 session;
  252. public:
  253. ProcessMasterQueryEvent( U32 _session )
  254. {
  255. session = _session;
  256. }
  257. void process( SimObject *object )
  258. {
  259. processMasterServerQuery( session );
  260. }
  261. };
  262. //----------------------------------------------------------------
  263. class ProcessPingEvent : public SimEvent
  264. {
  265. U32 session;
  266. public:
  267. ProcessPingEvent( U32 _session )
  268. {
  269. session = _session;
  270. }
  271. void process( SimObject *object )
  272. {
  273. processPingsAndQueries( session );
  274. }
  275. };
  276. //----------------------------------------------------------------
  277. class ProcessPacketEvent : public SimEvent
  278. {
  279. U32 session;
  280. public:
  281. ProcessPacketEvent( U32 _session )
  282. {
  283. session = _session;
  284. }
  285. void process( SimObject *object )
  286. {
  287. processServerListPackets( session );
  288. }
  289. };
  290. //----------------------------------------------------------------
  291. class HeartbeatEvent : public SimEvent
  292. {
  293. U32 mSeq;
  294. public:
  295. HeartbeatEvent(U32 seq)
  296. {
  297. mSeq = seq;
  298. }
  299. void process( SimObject *object )
  300. {
  301. processHeartbeat(mSeq);
  302. }
  303. };
  304. //-----------------------------------------------------------------------------
  305. // Public query methods
  306. //-----------------------------------------------------------------------------
  307. //-----------------------------------------------------------------------------
  308. void queryLanServers(U32 port, U8 flags, const char* gameType, const char* missionType,
  309. U8 minPlayers, U8 maxPlayers, U8 maxBots, U32 regionMask, U32 maxPing, U16 minCPU,
  310. U8 filterFlags)
  311. {
  312. sgServerQueryActive = true;
  313. clearServerList();
  314. pushServerFavorites();
  315. sActiveFilter.type = ServerFilter::Offline;
  316. // Clear the filter:
  317. if ( !sActiveFilter.gameType || dStricmp( sActiveFilter.gameType, "Any" ) != 0 )
  318. {
  319. sActiveFilter.gameType = (char*) dRealloc( sActiveFilter.gameType, 4 );
  320. dStrcpy( sActiveFilter.gameType, "Any" );
  321. }
  322. if ( !sActiveFilter.missionType || dStricmp( sActiveFilter.missionType, "Any" ) != 0 )
  323. {
  324. sActiveFilter.missionType = (char*) dRealloc( sActiveFilter.missionType, 4 );
  325. dStrcpy( sActiveFilter.missionType, "Any" );
  326. }
  327. sActiveFilter.queryFlags = 0;
  328. sActiveFilter.minPlayers = minPlayers;
  329. sActiveFilter.maxPlayers = maxPlayers;
  330. sActiveFilter.maxBots = maxBots;
  331. sActiveFilter.regionMask = regionMask;
  332. sActiveFilter.maxPing = maxPing;
  333. sActiveFilter.minCPU = minCPU;
  334. sActiveFilter.filterFlags = filterFlags;
  335. NetAddress addr;
  336. char addrText[256];
  337. dSprintf( addrText, sizeof( addrText ), "IP:BROADCAST:%d", port );
  338. Net::stringToAddress( addrText, &addr );
  339. pushPingBroadcast( &addr );
  340. Con::executef( 4, "onServerQueryStatus", "start", "Querying LAN servers", "0");
  341. processPingsAndQueries( gPingSession );
  342. }
  343. //-----------------------------------------------------------------------------
  344. void queryMasterGameTypes()
  345. {
  346. Vector<MasterInfo> *masterList = getMasterServerList();
  347. if ( masterList->size() != 0 )
  348. {
  349. U32 master = Sim::getCurrentTime() % masterList->size();
  350. // Send a request to the master server for the game types:
  351. Con::printf( "Requesting game types from the master server..." );
  352. sendPacket( NetInterface::MasterServerGameTypesRequest, &(*masterList)[master].address, gKey, gPingSession, 0 );
  353. }
  354. }
  355. //-----------------------------------------------------------------------------
  356. void queryMasterServer(U8 flags, const char* gameType, const char* missionType,
  357. U8 minPlayers, U8 maxPlayers, U8 maxBots, U32 regionMask, U32 maxPing,
  358. U16 minCPU, U8 filterFlags, U8 buddyCount, U32* buddyList )
  359. {
  360. // Reset the list packet flag:
  361. gGotFirstListPacket = false;
  362. sgServerQueryActive = true;
  363. clearServerList();
  364. Con::executef( 4, "onServerQueryStatus", "start", "Querying master server", "0");
  365. if ( buddyCount == 0 )
  366. {
  367. sActiveFilter.type = ServerFilter::Normal;
  368. // Update the active filter:
  369. if ( !sActiveFilter.gameType || dStrcmp( sActiveFilter.gameType, gameType ) != 0 )
  370. {
  371. sActiveFilter.gameType = (char*) dRealloc( sActiveFilter.gameType, dStrlen( gameType ) + 1 );
  372. dStrcpy( sActiveFilter.gameType, gameType );
  373. }
  374. if ( !sActiveFilter.missionType || dStrcmp( sActiveFilter.missionType, missionType ) != 0 )
  375. {
  376. sActiveFilter.missionType = (char*) dRealloc( sActiveFilter.missionType, dStrlen( missionType ) + 1 );
  377. dStrcpy( sActiveFilter.missionType, missionType );
  378. }
  379. sActiveFilter.queryFlags = flags;
  380. sActiveFilter.minPlayers = minPlayers;
  381. sActiveFilter.maxPlayers = maxPlayers;
  382. sActiveFilter.maxBots = maxBots;
  383. sActiveFilter.regionMask = regionMask;
  384. sActiveFilter.maxPing = maxPing;
  385. sActiveFilter.minCPU = minCPU;
  386. sActiveFilter.filterFlags = filterFlags;
  387. sActiveFilter.buddyCount = buddyCount;
  388. dFree( sActiveFilter.buddyList );
  389. sActiveFilter.buddyList = NULL;
  390. }
  391. else
  392. {
  393. sActiveFilter.type = ServerFilter::Buddy;
  394. sActiveFilter.buddyCount = buddyCount;
  395. sActiveFilter.buddyList = (U32*) dRealloc( sActiveFilter.buddyList, buddyCount * 4 );
  396. dMemcpy( sActiveFilter.buddyList, buddyList, buddyCount * 4 );
  397. clearServerList();
  398. }
  399. // Pick a random master server from the list:
  400. gMasterServerList.clear();
  401. Vector<MasterInfo> *masterList = getMasterServerList();
  402. for ( U32 i = 0; i < (U32)masterList->size(); i++ )
  403. gMasterServerList.push_back( (*masterList)[i] );
  404. // Clear the master server ping:
  405. gMasterServerPing.time = 0;
  406. gMasterServerPing.tryCount = gMasterServerRetryCount;
  407. //Luma: Make sure to spit out to the script that the search is "done" now
  408. if ( !pickMasterServer() )
  409. {
  410. Con::errorf( "No master servers found!" );
  411. Con::executef( 4, "onServerQueryStatus", "done", "No master servers found.", "0" );
  412. }
  413. else
  414. processMasterServerQuery( gPingSession );
  415. }
  416. //-----------------------------------------------------------------------------
  417. void queryFavoriteServers( U8 /*flags*/ )
  418. {
  419. sgServerQueryActive = true;
  420. clearServerList();
  421. sActiveFilter.type = ServerFilter::Favorites;
  422. pushServerFavorites();
  423. Con::executef( 4, "onServerQueryStatus", "start", "Query favorites...", "0" );
  424. processPingsAndQueries( gPingSession );
  425. }
  426. //-----------------------------------------------------------------------------
  427. void querySingleServer( const NetAddress* addr, U8 /*flags*/ )
  428. {
  429. sgServerQueryActive = true;
  430. ServerInfo* si = findServerInfo( addr );
  431. if ( si )
  432. si->status = ServerInfo::Status_New | ServerInfo::Status_Updating;
  433. // Remove the server from the finished list (if it's there):
  434. for ( U32 i = 0; i < (U32)gFinishedList.size(); i++ )
  435. {
  436. if ( Net::compareAddresses( addr, &gFinishedList[i] ) )
  437. {
  438. gFinishedList.erase( i );
  439. break;
  440. }
  441. }
  442. Con::executef( 4, "onServerQueryStatus", "start", "Refreshing server...", "0" );
  443. gServerPingCount = gServerQueryCount = 0;
  444. pushPingRequest( addr );
  445. processPingsAndQueries( gPingSession );
  446. }
  447. //-----------------------------------------------------------------------------
  448. void cancelServerQuery()
  449. {
  450. // Cancel the current query, if there is anything left
  451. // on the ping list, it's dropped.
  452. if ( sgServerQueryActive )
  453. {
  454. Con::printf( "Server query canceled." );
  455. ServerInfo* si;
  456. // Clear the master server packet list:
  457. gPacketStatusList.clear();
  458. // Clear the ping list:
  459. while ( gPingList.size() )
  460. {
  461. si = findServerInfo( &gPingList[0].address );
  462. if ( si && !si->status.test( ServerInfo::Status_Responded ) )
  463. si->status = ServerInfo::Status_TimedOut;
  464. gPingList.erase( U32( 0 ) );
  465. }
  466. // Clear the query list:
  467. while ( gQueryList.size() )
  468. {
  469. si = findServerInfo( &gQueryList[0].address );
  470. if ( si && !si->status.test( ServerInfo::Status_Responded ) )
  471. si->status = ServerInfo::Status_TimedOut;
  472. gQueryList.erase( U32( 0 ) );
  473. }
  474. sgServerQueryActive = false;
  475. gServerBrowserDirty = true;
  476. }
  477. }
  478. //-----------------------------------------------------------------------------
  479. void stopServerQuery()
  480. {
  481. // Cancel the current query, anything left on the ping
  482. // list is moved to the finished list as "done".
  483. if ( sgServerQueryActive )
  484. {
  485. gPacketStatusList.clear();
  486. if ( gPingList.size() )
  487. {
  488. while ( gPingList.size() )
  489. {
  490. gFinishedList.push_back( gPingList[0].address );
  491. gPingList.erase( U32( 0 ) );
  492. }
  493. }
  494. else
  495. cancelServerQuery();
  496. }
  497. }
  498. void startHeartbeat()
  499. {
  500. if (validateAuthenticatedServer())
  501. {
  502. gHeartbeatSeq++;
  503. processHeartbeat(gHeartbeatSeq); // thump-thump...
  504. }
  505. }
  506. void stopHeartBeat()
  507. {
  508. gHeartbeatSeq++;
  509. }
  510. //-----------------------------------------------------------------------------
  511. // Internal
  512. //-----------------------------------------------------------------------------
  513. //-----------------------------------------------------------------------------
  514. ServerInfo::~ServerInfo()
  515. {
  516. if ( name )
  517. dFree( name );
  518. if ( gameType )
  519. dFree( gameType );
  520. if ( missionType )
  521. dFree( missionType );
  522. if ( statusString )
  523. dFree( statusString );
  524. if ( infoString )
  525. dFree( infoString );
  526. }
  527. //-----------------------------------------------------------------------------
  528. Vector<MasterInfo>* getMasterServerList()
  529. {
  530. // This code used to get the master server list from the
  531. // WON.net directory.
  532. static Vector<MasterInfo> masterList;
  533. masterList.clear();
  534. for (U32 i = 0; i < 10; i++) {
  535. char buffer[50];
  536. dSprintf(buffer,sizeof(buffer),"Pref::Master%d",i);
  537. const char* master = Con::getVariable(buffer);
  538. if (master && *master) {
  539. NetAddress address;
  540. // Format for master server variable:
  541. // regionMask:netAddress
  542. U32 region = 1; // needs to default to something > 0
  543. dSscanf(master,"%d:",&region);
  544. const char* madd = dStrchr(master,':') + 1;
  545. if (region && Net::stringToAddress(madd,&address)) {
  546. masterList.increment();
  547. MasterInfo& info = masterList.last();
  548. info.address = address;
  549. info.region = region;
  550. }
  551. else
  552. Con::errorf("Bad master server address: %s",master);
  553. }
  554. }
  555. if (!masterList.size())
  556. Con::errorf("No master servers found");
  557. return &masterList;
  558. }
  559. //-----------------------------------------------------------------------------
  560. bool pickMasterServer()
  561. {
  562. // Reset the master server ping:
  563. gMasterServerPing.time = 0;
  564. gMasterServerPing.key = 0;
  565. gMasterServerPing.tryCount = gMasterServerRetryCount;
  566. gMasterServerPing.session = gPingSession;
  567. char addrString[256];
  568. U32 serverCount = gMasterServerList.size();
  569. if ( !serverCount )
  570. {
  571. // There are no more servers left to try...:(
  572. return( false );
  573. }
  574. U32 region = Con::getIntVariable( "$pref::Net::RegionMask" );
  575. U32 index = Sim::getCurrentTime() % serverCount;
  576. // First try to find a master server in the same region:
  577. for ( U32 i = 0; i < serverCount; i++ )
  578. {
  579. if ( gMasterServerList[index].region == region )
  580. {
  581. Net::addressToString( &gMasterServerList[index].address, addrString );
  582. Con::printf( "Found master server %s in same region.", addrString );
  583. gMasterServerPing.address = gMasterServerList[index].address;
  584. return( true );
  585. }
  586. index = index < serverCount - 1 ? index + 1 : 0;
  587. }
  588. // Settle for the one we first picked:
  589. Net::addressToString( &gMasterServerList[index].address, addrString );
  590. Con::printf( "No master servers found in this region, trying %s.", addrString );
  591. gMasterServerPing.address = gMasterServerList[index].address;
  592. return( true );
  593. }
  594. //-----------------------------------------------------------------------------
  595. void clearServerList()
  596. {
  597. gPacketStatusList.clear();
  598. gServerList.clear();
  599. gFinishedList.clear();
  600. gPingList.clear();
  601. gQueryList.clear();
  602. gServerPingCount = gServerQueryCount = 0;
  603. gPingSession++;
  604. }
  605. //-----------------------------------------------------------------------------
  606. void sendHeartbeat( U8 flags )
  607. {
  608. // send heartbeats to all of the master servers:
  609. Vector<MasterInfo> *masterList = getMasterServerList();
  610. for(U32 i = 0; i < (U32)masterList->size(); i++)
  611. {
  612. char buffer[256];
  613. Net::addressToString(&(*masterList)[i].address, buffer);
  614. // Send a request to the master server for the game types:
  615. Con::printf( "Sending heartbeat to master server [%s]", buffer );
  616. sendPacket( NetInterface::GameHeartbeat, &(*masterList)[i].address, 0, gPingSession, flags );
  617. }
  618. }
  619. //-----------------------------------------------------------------------------
  620. static void pushPingRequest( const NetAddress* addr )
  621. {
  622. if( addressFinished( addr ) )
  623. return;
  624. Ping p;
  625. p.address = *addr;
  626. p.session = gPingSession;
  627. p.key = 0;
  628. p.time = 0;
  629. p.tryCount = gPingRetryCount;
  630. p.broadcast = false;
  631. gPingList.push_back( p );
  632. gServerPingCount++;
  633. }
  634. //-----------------------------------------------------------------------------
  635. static void pushPingBroadcast( const NetAddress* addr )
  636. {
  637. if( addressFinished( addr ) )
  638. return;
  639. Ping p;
  640. p.address = *addr;
  641. p.session = gPingSession;
  642. p.key = 0;
  643. p.time = 0;
  644. p.tryCount = 1; // only try this once
  645. p.broadcast = true;
  646. gPingList.push_back( p );
  647. // Don't increment gServerPingCount, broadcasts are not
  648. // counted as requests.
  649. }
  650. //-----------------------------------------------------------------------------
  651. static S32 countPingRequests()
  652. {
  653. // Need a function here because the ping list also includes
  654. // broadcast pings we don't want counted.
  655. U32 pSize = gPingList.size(), count = pSize;
  656. for (U32 i = 0; i < pSize; i++)
  657. if (gPingList[i].broadcast)
  658. count--;
  659. return count;
  660. }
  661. //-----------------------------------------------------------------------------
  662. static void pushServerFavorites()
  663. {
  664. S32 count = Con::getIntVariable( "$pref::Client::ServerFavoriteCount" );
  665. if ( count < 0 )
  666. {
  667. Con::setIntVariable( "$pref::Client::ServerFavoriteCount", 0 );
  668. return;
  669. }
  670. NetAddress addr;
  671. const char* server = NULL;
  672. char buf[256], serverName[25], addrString[256];
  673. U32 sz, len;
  674. for ( S32 i = 0; i < count; i++ )
  675. {
  676. dSprintf( buf, sizeof( buf ), "Pref::Client::ServerFavorite%d", i );
  677. server = Con::getVariable( buf );
  678. if ( server )
  679. {
  680. sz = dStrcspn( server, "\t" );
  681. if ( sz > 0 )
  682. {
  683. len = sz > 24 ? 24 : sz;
  684. dStrncpy( serverName, server, len );
  685. serverName[len] = 0;
  686. dStrncpy( addrString, server + ( sz + 1 ), 255 );
  687. //Con::errorf( "Pushing server favorite \"%s\" - %s...", serverName, addrString );
  688. Net::stringToAddress( addrString, &addr );
  689. ServerInfo* si = findOrCreateServerInfo( &addr );
  690. AssertFatal(si, "pushServerFavorites - failed to create Server Info!" );
  691. si->name = (char*) dRealloc( (void*) si->name, dStrlen( serverName ) + 1 );
  692. dStrcpy( si->name, serverName );
  693. si->isFavorite = true;
  694. pushPingRequest( &addr );
  695. }
  696. }
  697. }
  698. }
  699. //-----------------------------------------------------------------------------
  700. static S32 findPingEntry( Vector<Ping> &v, const NetAddress* addr )
  701. {
  702. for ( U32 i = 0; i < (U32)v.size(); i++ )
  703. if ( Net::compareAddresses( addr, &v[i].address ) )
  704. return S32( i );
  705. return -1;
  706. }
  707. //-----------------------------------------------------------------------------
  708. static bool addressFinished( const NetAddress* addr )
  709. {
  710. for ( U32 i = 0; i < (U32)gFinishedList.size(); i++ )
  711. if ( Net::compareAddresses( addr, &gFinishedList[i] ) )
  712. return true;
  713. return false;
  714. }
  715. //-----------------------------------------------------------------------------
  716. static ServerInfo* findServerInfo( const NetAddress* addr )
  717. {
  718. for ( U32 i = 0; i < (U32)gServerList.size(); i++ )
  719. if ( Net::compareAddresses( addr, &gServerList[i].address ) )
  720. return &gServerList[i];
  721. return NULL;
  722. }
  723. //-----------------------------------------------------------------------------
  724. static ServerInfo* findOrCreateServerInfo( const NetAddress* addr )
  725. {
  726. ServerInfo* ret = findServerInfo( addr );
  727. if ( ret )
  728. return ret;
  729. ServerInfo si;
  730. si.address = *addr;
  731. gServerList.push_back( si );
  732. return &gServerList.last();
  733. }
  734. //-----------------------------------------------------------------------------
  735. static void removeServerInfo( const NetAddress* addr )
  736. {
  737. for ( U32 i = 0; i < (U32)gServerList.size(); i++ )
  738. {
  739. if ( Net::compareAddresses( addr, &gServerList[i].address ) )
  740. {
  741. gServerList.erase( i );
  742. gServerBrowserDirty = true;
  743. }
  744. }
  745. }
  746. //-----------------------------------------------------------------------------
  747. #if defined(TORQUE_DEBUG)
  748. // This function is solely for testing the functionality of the server browser
  749. // with more servers in the list.
  750. void addFakeServers( S32 howMany )
  751. {
  752. static S32 sNumFakeServers = 1;
  753. ServerInfo newServer;
  754. for ( S32 i = 0; i < howMany; i++ )
  755. {
  756. newServer.numPlayers = (U8)(Platform::getRandom() * 64);
  757. newServer.maxPlayers = 64;
  758. char buf[256];
  759. dSprintf( buf, 255, "Fake server #%d", sNumFakeServers );
  760. newServer.name = (char*) dMalloc( dStrlen( buf ) + 1 );
  761. dStrcpy( newServer.name, buf );
  762. newServer.gameType = (char*) dMalloc( 5 );
  763. dStrcpy( newServer.gameType, "Fake" );
  764. newServer.missionType = (char*) dMalloc( 4 );
  765. dStrcpy( newServer.missionType, "FakeMissionType" );
  766. newServer.missionName = (char*) dMalloc( 14 );
  767. dStrcpy( newServer.missionName, "FakeMapName" );
  768. Net::stringToAddress( "IP:198.74.33.35:28000", &newServer.address );
  769. newServer.ping = U32( Platform::getRandom() * 200 );
  770. newServer.cpuSpeed = 470;
  771. newServer.status = ServerInfo::Status_Responded;
  772. gServerList.push_back( newServer );
  773. sNumFakeServers++;
  774. }
  775. gServerBrowserDirty = true;
  776. }
  777. #endif // DEBUG
  778. //-----------------------------------------------------------------------------
  779. static void sendPacket( U8 pType, const NetAddress* addr, U32 key, U32 session, U8 flags )
  780. {
  781. BitStream *out = BitStream::getPacketStream();
  782. out->write( pType );
  783. out->write( flags );
  784. out->write( U32( ( session << 16 ) | ( key & 0xFFFF ) ) );
  785. BitStream::sendPacketStream(addr);
  786. }
  787. //-----------------------------------------------------------------------------
  788. static void writeCString( BitStream* stream, const char* string )
  789. {
  790. U8 strLen = ( string != NULL ) ? dStrlen( string ) : 0;
  791. stream->write( strLen );
  792. for ( U32 i = 0; i < strLen; i++ )
  793. stream->write( U8( string[i] ) );
  794. }
  795. //-----------------------------------------------------------------------------
  796. static void readCString( BitStream* stream, char* buffer )
  797. {
  798. U32 i;
  799. U8 strLen;
  800. stream->read( &strLen );
  801. for ( i = 0; i < strLen; i++ )
  802. {
  803. U8* ptr = (U8*) buffer;
  804. stream->read( &ptr[i] );
  805. }
  806. buffer[i] = 0;
  807. }
  808. //-----------------------------------------------------------------------------
  809. static void writeLongCString( BitStream* stream, const char* string )
  810. {
  811. U16 strLen = ( string != NULL ) ? dStrlen( string ) : 0;
  812. stream->write( strLen );
  813. for ( U32 i = 0; i < strLen; i++ )
  814. stream->write( U8( string[i] ) );
  815. }
  816. //-----------------------------------------------------------------------------
  817. static void readLongCString( BitStream* stream, char* buffer )
  818. {
  819. U32 i;
  820. U16 strLen;
  821. stream->read( &strLen );
  822. for ( i = 0; i < strLen; i++ )
  823. {
  824. U8* ptr = (U8*) buffer;
  825. stream->read( &ptr[i] );
  826. }
  827. buffer[i] = 0;
  828. }
  829. //-----------------------------------------------------------------------------
  830. // Event processing
  831. //-----------------------------------------------------------------------------
  832. //-----------------------------------------------------------------------------
  833. static void processMasterServerQuery( U32 session )
  834. {
  835. if ( session != gPingSession || !sgServerQueryActive )
  836. return;
  837. if ( !gGotFirstListPacket )
  838. {
  839. bool keepGoing = true;
  840. U32 time = Platform::getVirtualMilliseconds();
  841. char addressString[256];
  842. if ( gMasterServerPing.time + gMasterServerTimeout < time )
  843. {
  844. Net::addressToString( &gMasterServerPing.address, addressString );
  845. if ( !gMasterServerPing.tryCount )
  846. {
  847. // The query timed out.
  848. Con::printf( "Server list request to %s timed out.", addressString );
  849. // Remove this server from the list:
  850. for ( U32 i = 0; i < (U32)gMasterServerList.size(); i++ )
  851. {
  852. if ( Net::compareAddresses( &gMasterServerList[i].address, &gMasterServerPing.address ) )
  853. {
  854. gMasterServerList.erase( i );
  855. break;
  856. }
  857. }
  858. // Pick a new master server to try:
  859. keepGoing = pickMasterServer();
  860. if ( keepGoing )
  861. {
  862. Con::executef( 4, "onServerQueryStatus", "update", "Switching master servers...", "0" );
  863. Net::addressToString( &gMasterServerPing.address, addressString );
  864. }
  865. }
  866. if ( keepGoing )
  867. {
  868. gMasterServerPing.tryCount--;
  869. gMasterServerPing.time = time;
  870. gMasterServerPing.key = gKey++;
  871. // Send a request to the master server for the server list:
  872. BitStream *out = BitStream::getPacketStream();
  873. out->write( U8( NetInterface::MasterServerListRequest ) );
  874. out->write( U8( sActiveFilter.queryFlags) );
  875. out->write( ( gMasterServerPing.session << 16 ) | ( gMasterServerPing.key & 0xFFFF ) );
  876. out->write( U8( 255 ) );
  877. writeCString( out, sActiveFilter.gameType );
  878. writeCString( out, sActiveFilter.missionType );
  879. out->write( sActiveFilter.minPlayers );
  880. out->write( sActiveFilter.maxPlayers );
  881. out->write( sActiveFilter.regionMask );
  882. U32 version = ( sActiveFilter.filterFlags & ServerFilter::CurrentVersion ) ? getVersionNumber() : 0;
  883. out->write( version );
  884. out->write( sActiveFilter.filterFlags );
  885. out->write( sActiveFilter.maxBots );
  886. out->write( sActiveFilter.minCPU );
  887. out->write( sActiveFilter.buddyCount );
  888. for ( U32 i = 0; i < sActiveFilter.buddyCount; i++ )
  889. out->write( sActiveFilter.buddyList[i] );
  890. BitStream::sendPacketStream( &gMasterServerPing.address );
  891. Con::printf( "Requesting the server list from master server %s (%d tries left)...", addressString, gMasterServerPing.tryCount );
  892. if ( gMasterServerPing.tryCount < gMasterServerRetryCount - 1 )
  893. Con::executef( 4, "onServerQueryStatus", "update", "Retrying the master server...", "0" );
  894. }
  895. }
  896. if ( keepGoing )
  897. {
  898. // schedule another check:
  899. Sim::postEvent( Sim::getRootGroup(), new ProcessMasterQueryEvent( session ), Sim::getTargetTime() + 1 );
  900. }
  901. else
  902. {
  903. Con::errorf( "There are no more master servers to try!" );
  904. Con::executef( 4, "onServerQueryStatus", "done", "No master servers found.", "0" );
  905. }
  906. }
  907. }
  908. //-----------------------------------------------------------------------------
  909. static void processPingsAndQueries( U32 session, bool schedule )
  910. {
  911. if( session != gPingSession )
  912. return;
  913. U32 i = 0;
  914. U32 time = Platform::getVirtualMilliseconds();
  915. char addressString[256];
  916. U8 flags = ServerFilter::OnlineQuery;
  917. bool waitingForMaster = ( sActiveFilter.type == ServerFilter::Normal ) && !gGotFirstListPacket && sgServerQueryActive;
  918. for ( i = 0; i < (U32)gPingList.size() && i < (U32)gMaxConcurrentPings; )
  919. {
  920. Ping &p = gPingList[i];
  921. if ( p.time + gPingTimeout < time )
  922. {
  923. if ( !p.tryCount )
  924. {
  925. // it's timed out.
  926. if (!p.broadcast)
  927. {
  928. Net::addressToString( &p.address, addressString );
  929. Con::printf( "Ping to server %s timed out.", addressString );
  930. }
  931. // If server info is in list (favorite), set its status:
  932. ServerInfo* si = findServerInfo( &p.address );
  933. if ( si )
  934. {
  935. si->status = ServerInfo::Status_TimedOut;
  936. gServerBrowserDirty = true;
  937. }
  938. gFinishedList.push_back( p.address );
  939. gPingList.erase( i );
  940. if ( !waitingForMaster )
  941. updatePingProgress();
  942. }
  943. else
  944. {
  945. p.tryCount--;
  946. p.time = time;
  947. p.key = gKey++;
  948. Net::addressToString( &p.address, addressString );
  949. if (p.broadcast)
  950. Con::printf( "LAN server ping: %s...", addressString );
  951. else
  952. Con::printf( "Pinging Server %s (%d)...", addressString, p.tryCount );
  953. sendPacket( NetInterface::GamePingRequest, &p.address, p.key, p.session, flags );
  954. i++;
  955. }
  956. }
  957. else
  958. i++;
  959. }
  960. if ( !gPingList.size() && !waitingForMaster )
  961. {
  962. // Start the query phase:
  963. for ( U32 i = 0; i < (U32)gQueryList.size() && i < (U32)gMaxConcurrentQueries; )
  964. {
  965. Ping &p = gQueryList[i];
  966. if ( p.time + gPingTimeout < time )
  967. {
  968. ServerInfo* si = findServerInfo( &p.address );
  969. if ( !si )
  970. {
  971. // Server info not found, so remove the query:
  972. gQueryList.erase( i );
  973. gServerBrowserDirty = true;
  974. continue;
  975. }
  976. Net::addressToString( &p.address, addressString );
  977. if ( !p.tryCount )
  978. {
  979. Con::printf( "Query to server %s timed out.", addressString );
  980. si->status = ServerInfo::Status_TimedOut;
  981. gQueryList.erase( i );
  982. gServerBrowserDirty = true;
  983. }
  984. else
  985. {
  986. p.tryCount--;
  987. p.time = time;
  988. p.key = gKey++;
  989. Con::printf( "Querying Server %s (%d)...", addressString, p.tryCount );
  990. sendPacket( NetInterface::GameInfoRequest, &p.address, p.key, p.session, flags );
  991. if ( !si->isQuerying() )
  992. {
  993. si->status |= ServerInfo::Status_Querying;
  994. gServerBrowserDirty = true;
  995. }
  996. i++;
  997. }
  998. }
  999. else
  1000. i++;
  1001. }
  1002. }
  1003. if ( gPingList.size() || gQueryList.size() || waitingForMaster )
  1004. {
  1005. // The LAN query function doesn't always want to schedule
  1006. // the next ping.
  1007. if (schedule)
  1008. Sim::postEvent( Sim::getRootGroup(), new ProcessPingEvent( session ), Sim::getTargetTime() + 1 );
  1009. }
  1010. else
  1011. {
  1012. // All done!
  1013. char msg[64];
  1014. U32 foundCount = gServerList.size();
  1015. if ( foundCount == 0 )
  1016. dStrcpy( msg, "No servers found." );
  1017. else if ( foundCount == 1 )
  1018. dStrcpy( msg, "One server found." );
  1019. else
  1020. dSprintf( msg, sizeof( msg ), "%d servers found.", foundCount );
  1021. Con::executef( 4, "onServerQueryStatus", "done", msg, "1");
  1022. }
  1023. }
  1024. //-----------------------------------------------------------------------------
  1025. static void processServerListPackets( U32 session )
  1026. {
  1027. if ( session != gPingSession || !sgServerQueryActive )
  1028. return;
  1029. U32 currentTime = Platform::getVirtualMilliseconds();
  1030. // Loop through the packet status list and resend packet requests where necessary:
  1031. for ( U32 i = 0; i < (U32)gPacketStatusList.size(); i++ )
  1032. {
  1033. PacketStatus &p = gPacketStatusList[i];
  1034. if ( p.time + gPacketTimeout < currentTime )
  1035. {
  1036. if ( !p.tryCount )
  1037. {
  1038. // Packet timed out :(
  1039. Con::printf( "Server list packet #%d timed out.", p.index + 1 );
  1040. gPacketStatusList.erase( i );
  1041. }
  1042. else
  1043. {
  1044. // Try again...
  1045. Con::printf( "Rerequesting server list packet #%d...", p.index + 1 );
  1046. p.tryCount--;
  1047. p.time = currentTime;
  1048. p.key = gKey++;
  1049. BitStream *out = BitStream::getPacketStream();
  1050. out->write( U8( NetInterface::MasterServerListRequest ) );
  1051. out->write( U8( sActiveFilter.queryFlags ) ); // flags
  1052. out->write( ( session << 16) | ( p.key & 0xFFFF ) );
  1053. out->write( p.index ); // packet index
  1054. out->write( U8( 0 ) ); // game type
  1055. out->write( U8( 0 ) ); // mission type
  1056. out->write( U8( 0 ) ); // minPlayers
  1057. out->write( U8( 0 ) ); // maxPlayers
  1058. out->write( U32( 0 ) ); // region mask
  1059. out->write( U32( 0 ) ); // version
  1060. out->write( U8( 0 ) ); // filter flags
  1061. out->write( U8( 0 ) ); // max bots
  1062. out->write( U16( 0 ) ); // min CPU
  1063. out->write( U8( 0 ) ); // buddy count
  1064. BitStream::sendPacketStream(&gMasterServerQueryAddress);
  1065. }
  1066. }
  1067. }
  1068. if ( gPacketStatusList.size() )
  1069. Sim::postEvent( Sim::getRootGroup(), new ProcessPacketEvent( session ), Sim::getCurrentTime() + 30 );
  1070. else
  1071. processPingsAndQueries( gPingSession );
  1072. }
  1073. //-----------------------------------------------------------------------------
  1074. static void processHeartbeat(U32 seq)
  1075. {
  1076. if(seq != gHeartbeatSeq)
  1077. return;
  1078. sendHeartbeat( 0 );
  1079. Sim::postEvent( Sim::getRootGroup(), new HeartbeatEvent(seq), Sim::getCurrentTime() + gHeartbeatInterval );
  1080. }
  1081. //-----------------------------------------------------------------------------
  1082. static void updatePingProgress()
  1083. {
  1084. if ( !gPingList.size() )
  1085. {
  1086. updateQueryProgress();
  1087. return;
  1088. }
  1089. char msg[64];
  1090. U32 pingsLeft = countPingRequests();
  1091. dSprintf( msg, sizeof(msg),
  1092. (!pingsLeft && gPingList.size())?
  1093. "Waiting for lan servers...":
  1094. "Pinging servers: %d left...",
  1095. pingsLeft );
  1096. // Ping progress is 0 -> 0.5
  1097. F32 progress = 0.0f;
  1098. if ( gServerPingCount )
  1099. progress = F32( gServerPingCount - pingsLeft ) / F32( gServerPingCount * 2 );
  1100. //Con::errorf( ConsoleLogEntry::General, "Ping progress - %d of %d left - progress = %.2f", pingsLeft, gServerPingCount, progress );
  1101. Con::executef( 4, "onServerQueryStatus", "ping", msg, Con::getFloatArg( progress ) );
  1102. }
  1103. //-----------------------------------------------------------------------------
  1104. static void updateQueryProgress()
  1105. {
  1106. if ( gPingList.size() )
  1107. return;
  1108. char msg[64];
  1109. U32 queriesLeft = gQueryList.size();
  1110. dSprintf( msg, sizeof( msg ), "Querying servers: %d left...", queriesLeft );
  1111. // Query progress is 0.5 -> 1
  1112. F32 progress = 0.5f;
  1113. if ( gServerQueryCount )
  1114. progress += ( F32( gServerQueryCount - queriesLeft ) / F32( gServerQueryCount * 2 ) );
  1115. //Con::errorf( ConsoleLogEntry::General, "Query progress - %d of %d left - progress = %.2f", queriesLeft, gServerQueryCount, progress );
  1116. Con::executef( 4, "onServerQueryStatus", "query", msg, Con::getFloatArg( progress ) );
  1117. }
  1118. //-----------------------------------------------------------------------------
  1119. // Server packet handlers:
  1120. //-----------------------------------------------------------------------------
  1121. //-----------------------------------------------------------------------------
  1122. static void handleMasterServerGameTypesResponse( BitStream* stream, U32 /*key*/, U8 /*flags*/ )
  1123. {
  1124. Con::printf( "Received game type list from the master server." );
  1125. U32 i;
  1126. U8 temp;
  1127. char stringBuf[256];
  1128. stream->read( &temp );
  1129. Con::executef(1, "onClearGameTypes");
  1130. for ( i = 0; i < U32( temp ); i++ )
  1131. {
  1132. readCString( stream, stringBuf );
  1133. Con::executef(2, "onAddGameType", stringBuf);
  1134. }
  1135. stream->read( &temp );
  1136. Con::executef(1, "onClearMissionTypes");
  1137. for ( i = 0; i < U32( temp ); i++ )
  1138. {
  1139. readCString( stream, stringBuf );
  1140. Con::executef(2, "onAddMissionType", stringBuf);
  1141. }
  1142. }
  1143. //-----------------------------------------------------------------------------
  1144. static void handleMasterServerListResponse( BitStream* stream, U32 key, U8 /*flags*/ )
  1145. {
  1146. U8 packetIndex, packetTotal;
  1147. U32 i;
  1148. U16 serverCount, port;
  1149. U8 netNum[4];
  1150. char addressBuffer[256];
  1151. NetAddress addr;
  1152. stream->read( &packetIndex );
  1153. // Validate the packet key:
  1154. U32 packetKey = gMasterServerPing.key;
  1155. if ( gGotFirstListPacket )
  1156. {
  1157. for ( i = 0; i < (U32)gPacketStatusList.size(); i++ )
  1158. {
  1159. if ( gPacketStatusList[i].index == packetIndex )
  1160. {
  1161. packetKey = gPacketStatusList[i].key;
  1162. break;
  1163. }
  1164. }
  1165. }
  1166. U32 testKey = ( gPingSession << 16 ) | ( packetKey & 0xFFFF );
  1167. if ( testKey != key )
  1168. return;
  1169. stream->read( &packetTotal );
  1170. stream->read( &serverCount );
  1171. Con::printf( "Received server list packet %d of %d from the master server (%d servers).", ( packetIndex + 1 ), packetTotal, serverCount );
  1172. // Enter all of the servers in this packet into the ping list:
  1173. for ( i = 0; i < serverCount; i++ )
  1174. {
  1175. stream->read( &netNum[0] );
  1176. stream->read( &netNum[1] );
  1177. stream->read( &netNum[2] );
  1178. stream->read( &netNum[3] );
  1179. stream->read( &port );
  1180. dSprintf( addressBuffer, sizeof( addressBuffer ), "IP:%d.%d.%d.%d:%d", netNum[0], netNum[1], netNum[2], netNum[3], port );
  1181. Net::stringToAddress( addressBuffer, &addr );
  1182. pushPingRequest( &addr );
  1183. }
  1184. // If this is the first list packet we have received, fill the packet status list
  1185. // and start processing:
  1186. if ( !gGotFirstListPacket )
  1187. {
  1188. gGotFirstListPacket = true;
  1189. gMasterServerQueryAddress = gMasterServerPing.address;
  1190. U32 currentTime = Platform::getVirtualMilliseconds();
  1191. for ( i = 0; i < packetTotal; i++ )
  1192. {
  1193. if ( i != packetIndex )
  1194. {
  1195. PacketStatus* p = new PacketStatus( i, gMasterServerPing.key, currentTime );
  1196. gPacketStatusList.push_back( *p );
  1197. }
  1198. }
  1199. processServerListPackets( gPingSession );
  1200. }
  1201. else
  1202. {
  1203. // Remove the packet we just received from the status list:
  1204. for ( i = 0; i < (U32)gPacketStatusList.size(); i++ )
  1205. {
  1206. if ( gPacketStatusList[i].index == packetIndex )
  1207. {
  1208. gPacketStatusList.erase( i );
  1209. break;
  1210. }
  1211. }
  1212. }
  1213. }
  1214. //-----------------------------------------------------------------------------
  1215. static void handleGameMasterInfoRequest( const NetAddress* address, U32 key, U8 flags )
  1216. {
  1217. if ( GNet->doesAllowConnections() )
  1218. {
  1219. U8 temp8;
  1220. U32 temp32;
  1221. char netString[256];
  1222. Net::addressToString(address, netString);
  1223. Vector<MasterInfo> *masterList = getMasterServerList();
  1224. const NetAddress *masterAddr;
  1225. bool fromMaster = false;
  1226. for(U32 i = 0; i < (U32)masterList->size(); i++)
  1227. {
  1228. masterAddr = &(*masterList)[i].address;
  1229. if (*(U32*)(masterAddr->netNum) == *(U32*)(address->netNum))
  1230. {
  1231. fromMaster = true;
  1232. break;
  1233. }
  1234. }
  1235. Con::printf( "Received info request from %s [%s].", fromMaster?"a master server":"a machine", netString);
  1236. BitStream *out = BitStream::getPacketStream();
  1237. out->write( U8( NetInterface::GameMasterInfoResponse ) );
  1238. out->write( U8( flags ) );
  1239. out->write( key );
  1240. writeCString( out, Con::getVariable( "Server::GameType" ) );
  1241. writeCString( out, Con::getVariable( "Server::MissionType" ) );
  1242. temp8 = U8( Con::getIntVariable( "Pref::Server::MaxPlayers" ) );
  1243. out->write( temp8 );
  1244. temp32 = Con::getIntVariable( "Pref::Server::RegionMask" );
  1245. out->write( temp32 );
  1246. temp32 = getVersionNumber();
  1247. out->write( temp32 );
  1248. temp8 = 0;
  1249. #if defined(TORQUE_OS_LINUX) || defined(TORQUE_OS_OPENBSD)
  1250. temp8 |= ServerInfo::Status_Linux;
  1251. #endif
  1252. if ( Con::getBoolVariable( "Server::Dedicated" ) )
  1253. temp8 |= ServerInfo::Status_Dedicated;
  1254. if ( dStrlen( Con::getVariable( "Pref::Server::Password" ) ) > 0 )
  1255. temp8 |= ServerInfo::Status_Passworded;
  1256. out->write( temp8 );
  1257. temp8 = U8( Con::getIntVariable( "Server::BotCount" ) );
  1258. out->write( temp8 );
  1259. out->write( PlatformSystemInfo.processor.mhz );
  1260. U8 playerCount = U8( Con::getIntVariable( "Server::PlayerCount" ) );
  1261. out->write( playerCount );
  1262. const char* guidList = Con::getVariable( "Server::GuidList" );
  1263. char* buf = new char[dStrlen( guidList ) + 1];
  1264. dStrcpy( buf, guidList );
  1265. char* temp = dStrtok( buf, "\t" );
  1266. temp8 = 0;
  1267. for ( ; temp && temp8 < playerCount; temp8++ )
  1268. {
  1269. out->write( U32( dAtoi( temp ) ) );
  1270. temp = dStrtok( NULL, "\t" );
  1271. temp8++;
  1272. }
  1273. for ( ; temp8 < playerCount; temp8++ )
  1274. out->write( U32( 0 ) );
  1275. delete [] buf;
  1276. BitStream::sendPacketStream(address);
  1277. }
  1278. }
  1279. //-----------------------------------------------------------------------------
  1280. static void handleGamePingRequest( const NetAddress* address, U32 key, U8 flags )
  1281. {
  1282. // Do not respond if a mission is not running:
  1283. if ( GNet->doesAllowConnections() )
  1284. {
  1285. // Do not respond if this is a single-player game:
  1286. if ( dStricmp( Con::getVariable( "Server::ServerType" ), "SinglePlayer" ) == 0 )
  1287. return;
  1288. // Do not respond to offline queries if this is an online server:
  1289. if ( flags & ServerFilter::OfflineQuery )
  1290. return;
  1291. // some banning code here (?)
  1292. BitStream *out = BitStream::getPacketStream();
  1293. out->write( U8( NetInterface::GamePingResponse ) );
  1294. out->write( flags );
  1295. out->write( key );
  1296. if ( flags & ServerFilter::NoStringCompress )
  1297. writeCString( out, versionString );
  1298. else
  1299. out->writeString( versionString );
  1300. out->write( GameConnection::CurrentProtocolVersion );
  1301. out->write( GameConnection::MinRequiredProtocolVersion );
  1302. out->write( getVersionNumber() );
  1303. // Enforce a 24-character limit on the server name:
  1304. char serverName[25];
  1305. dStrncpy( serverName, Con::getVariable( "Pref::Server::Name" ), 24 );
  1306. serverName[24] = 0;
  1307. if ( flags & ServerFilter::NoStringCompress )
  1308. writeCString( out, serverName );
  1309. else
  1310. out->writeString( serverName );
  1311. BitStream::sendPacketStream(address);
  1312. }
  1313. }
  1314. //-----------------------------------------------------------------------------
  1315. static void handleGamePingResponse( const NetAddress* address, BitStream* stream, U32 key, U8 /*flags*/ )
  1316. {
  1317. // Broadcast has timed out or query has been cancelled:
  1318. if( !gPingList.size() )
  1319. return;
  1320. S32 index = findPingEntry( gPingList, address );
  1321. if( index == -1 )
  1322. {
  1323. // an anonymous ping response - if it's not already timed
  1324. // out or finished, ping it. Probably from a broadcast
  1325. if( !addressFinished( address ) )
  1326. pushPingRequest( address );
  1327. return;
  1328. }
  1329. Ping &p = gPingList[index];
  1330. U32 infoKey = ( p.session << 16 ) | ( p.key & 0xFFFF );
  1331. if( infoKey != key )
  1332. return;
  1333. // Find if the server info already exists (favorite or refreshing):
  1334. ServerInfo* si = findServerInfo( address );
  1335. bool applyFilter = false;
  1336. if ( sActiveFilter.type == ServerFilter::Normal )
  1337. applyFilter = si ? !si->isUpdating() : true;
  1338. char addrString[256];
  1339. Net::addressToString( address, addrString );
  1340. bool waitingForMaster = ( sActiveFilter.type == ServerFilter::Normal ) && !gGotFirstListPacket;
  1341. // Verify the version:
  1342. char buf[256];
  1343. stream->readString( buf );
  1344. if ( dStrcmp( buf, versionString ) != 0 )
  1345. {
  1346. // Version is different, so remove it from consideration:
  1347. Con::printf( "Server %s is a different version.", addrString );
  1348. gFinishedList.push_back( *address );
  1349. gPingList.erase( index );
  1350. if ( si )
  1351. {
  1352. si->status = ServerInfo::Status_TimedOut;
  1353. gServerBrowserDirty = true;
  1354. }
  1355. if ( !waitingForMaster )
  1356. updatePingProgress();
  1357. return;
  1358. }
  1359. // See if the server meets our minimum protocol:
  1360. U32 temp32;
  1361. stream->read( &temp32 );
  1362. if ( temp32 < GameConnection::MinRequiredProtocolVersion )
  1363. {
  1364. Con::printf( "Protocol for server %s does not meet minimum protocol.", addrString );
  1365. gFinishedList.push_back( *address );
  1366. gPingList.erase( index );
  1367. if ( si )
  1368. {
  1369. si->status = ServerInfo::Status_TimedOut;
  1370. gServerBrowserDirty = true;
  1371. }
  1372. if ( !waitingForMaster )
  1373. updatePingProgress();
  1374. return;
  1375. }
  1376. // See if we meet the server's minimum protocol:
  1377. stream->read( &temp32 );
  1378. if ( GameConnection::CurrentProtocolVersion < temp32 )
  1379. {
  1380. Con::printf( "You do not meet the minimum protocol for server %s.", addrString );
  1381. gFinishedList.push_back( *address );
  1382. gPingList.erase( index );
  1383. if ( si )
  1384. {
  1385. si->status = ServerInfo::Status_TimedOut;
  1386. gServerBrowserDirty = true;
  1387. }
  1388. if ( !waitingForMaster )
  1389. updatePingProgress();
  1390. return;
  1391. }
  1392. // Calculate the ping:
  1393. U32 time = Platform::getVirtualMilliseconds();
  1394. U32 ping = ( time > p.time ) ? time - p.time : 0;
  1395. // Check for max ping filter:
  1396. if ( applyFilter && sActiveFilter.maxPing > 0 && ping > sActiveFilter.maxPing )
  1397. {
  1398. // Ping is too high, so remove this server from consideration:
  1399. Con::printf( "Server %s filtered out by maximum ping.", addrString );
  1400. gFinishedList.push_back( *address );
  1401. gPingList.erase( index );
  1402. if ( si )
  1403. removeServerInfo( address );
  1404. if ( !waitingForMaster )
  1405. updatePingProgress();
  1406. return;
  1407. }
  1408. // Get the server build version:
  1409. stream->read( &temp32 );
  1410. if ( applyFilter
  1411. && ( sActiveFilter.filterFlags & ServerFilter::CurrentVersion )
  1412. && ( temp32 != getVersionNumber() ) )
  1413. {
  1414. Con::printf( "Server %s filtered out by version number.", addrString );
  1415. gFinishedList.push_back( *address );
  1416. gPingList.erase( index );
  1417. if ( si )
  1418. removeServerInfo( address );
  1419. if ( !waitingForMaster )
  1420. updatePingProgress();
  1421. return;
  1422. }
  1423. // OK, we can finally create the server info structure:
  1424. if ( !si )
  1425. si = findOrCreateServerInfo( address );
  1426. si->ping = ping;
  1427. si->version = temp32;
  1428. // Get the server name:
  1429. stream->readString( buf );
  1430. if ( !si->name )
  1431. {
  1432. si->name = (char*) dMalloc( dStrlen( buf ) + 1 );
  1433. dStrcpy( si->name, buf );
  1434. }
  1435. // Set the server up to be queried:
  1436. gFinishedList.push_back( *address );
  1437. p.key = 0;
  1438. p.time = 0;
  1439. p.tryCount = gQueryRetryCount;
  1440. gQueryList.push_back( p );
  1441. gServerQueryCount++;
  1442. gPingList.erase( index );
  1443. if ( !waitingForMaster )
  1444. updatePingProgress();
  1445. // Update the server browser gui!
  1446. gServerBrowserDirty = true;
  1447. }
  1448. //-----------------------------------------------------------------------------
  1449. static void handleGameInfoRequest( const NetAddress* address, U32 key, U8 flags )
  1450. {
  1451. // Do not respond unless there is a server running:
  1452. if ( GNet->doesAllowConnections() )
  1453. {
  1454. // Do not respond to offline queries if this is an online server:
  1455. if ( flags & ServerFilter::OfflineQuery )
  1456. return;
  1457. bool compressStrings = !( flags & ServerFilter::NoStringCompress );
  1458. BitStream *out = BitStream::getPacketStream();
  1459. out->write( U8( NetInterface::GameInfoResponse ) );
  1460. out->write( flags );
  1461. out->write( key );
  1462. if ( compressStrings ) {
  1463. out->writeString( Con::getVariable( "Server::GameType" ) );
  1464. out->writeString( Con::getVariable( "Server::MissionType" ) );
  1465. out->writeString( Con::getVariable( "Server::MissionName" ) );
  1466. }
  1467. else {
  1468. writeCString( out, Con::getVariable( "Server::GameType" ) );
  1469. writeCString( out, Con::getVariable( "Server::MissionType" ) );
  1470. writeCString( out, Con::getVariable( "Server::MissionName" ) );
  1471. }
  1472. U8 status = 0;
  1473. #if defined(TORQUE_OS_LINUX) || defined(TORQUE_OS_OPENBSD)
  1474. status |= ServerInfo::Status_Linux;
  1475. #endif
  1476. if ( Con::getBoolVariable( "Server::Dedicated" ) )
  1477. status |= ServerInfo::Status_Dedicated;
  1478. if ( dStrlen( Con::getVariable( "Pref::Server::Password" ) ) )
  1479. status |= ServerInfo::Status_Passworded;
  1480. out->write( status );
  1481. out->write( U8( Con::getIntVariable( "Server::PlayerCount" ) ) );
  1482. out->write( U8( Con::getIntVariable( "Pref::Server::MaxPlayers" ) ) );
  1483. out->write( U8( Con::getIntVariable( "Server::BotCount" ) ) );
  1484. out->write( U16( PlatformSystemInfo.processor.mhz ) );
  1485. if ( compressStrings )
  1486. out->writeString( Con::getVariable( "Pref::Server::Info" ) );
  1487. else
  1488. writeCString( out, Con::getVariable( "Pref::Server::Info" ) );
  1489. writeLongCString( out, Con::evaluate( "onServerInfoQuery();" ) );
  1490. BitStream::sendPacketStream(address);
  1491. }
  1492. }
  1493. //-----------------------------------------------------------------------------
  1494. static void handleGameInfoResponse( const NetAddress* address, BitStream* stream, U32 /*key*/, U8 /*flags*/ )
  1495. {
  1496. if ( !gQueryList.size() )
  1497. return;
  1498. S32 index = findPingEntry( gQueryList, address );
  1499. if ( index == -1 )
  1500. return;
  1501. // Remove the server from the query list since it has been so kind as to respond:
  1502. gQueryList.erase( index );
  1503. updateQueryProgress();
  1504. ServerInfo *si = findServerInfo( address );
  1505. if ( !si )
  1506. return;
  1507. bool isUpdate = si->isUpdating();
  1508. bool applyFilter = !isUpdate && ( sActiveFilter.type == ServerFilter::Normal );
  1509. char addrString[256];
  1510. Net::addressToString( address, addrString );
  1511. // Get the rules set:
  1512. char stringBuf[2048]; // Who knows how big this should be?
  1513. stream->readString( stringBuf );
  1514. if ( !si->gameType || dStricmp( si->gameType, stringBuf ) != 0 )
  1515. {
  1516. si->gameType = (char*) dRealloc( (void*) si->gameType, dStrlen( stringBuf ) + 1 );
  1517. dStrcpy( si->gameType, stringBuf );
  1518. // Test against the active filter:
  1519. if ( applyFilter && dStricmp( sActiveFilter.gameType, "any" ) != 0
  1520. && dStricmp( si->gameType, sActiveFilter.gameType ) != 0 )
  1521. {
  1522. Con::printf( "Server %s filtered out by rules set. (%s:%s)", addrString, sActiveFilter.gameType, si->gameType );
  1523. removeServerInfo( address );
  1524. return;
  1525. }
  1526. }
  1527. // Get the mission type:
  1528. stream->readString( stringBuf );
  1529. if ( !si->missionType || dStrcmp( si->missionType, stringBuf ) != 0 )
  1530. {
  1531. si->missionType = (char*) dRealloc( (void*) si->missionType, dStrlen( stringBuf ) + 1 );
  1532. dStrcpy( si->missionType, stringBuf );
  1533. // Test against the active filter:
  1534. if ( applyFilter && dStricmp( sActiveFilter.missionType, "any" ) != 0
  1535. && dStricmp( si->missionType, sActiveFilter.missionType ) != 0 )
  1536. {
  1537. Con::printf( "Server %s filtered out by mission type. (%s:%s)", addrString, sActiveFilter.missionType, si->missionType );
  1538. removeServerInfo( address );
  1539. return;
  1540. }
  1541. }
  1542. // Get the mission name:
  1543. stream->readString( stringBuf );
  1544. // Clip the file extension off:
  1545. char* temp = dStrstr( static_cast<char*>( stringBuf ), const_cast<char*>( ".mis" ) );
  1546. if ( temp )
  1547. *temp = '\0';
  1548. if ( !si->missionName || dStrcmp( si->missionName, stringBuf ) != 0 )
  1549. {
  1550. si->missionName = (char*) dRealloc( (void*) si->missionName, dStrlen( stringBuf ) + 1 );
  1551. dStrcpy( si->missionName, stringBuf );
  1552. }
  1553. // Get the server status:
  1554. U8 temp_U8;
  1555. stream->read( &temp_U8 );
  1556. si->status = temp_U8;
  1557. // Filter by the flags:
  1558. if ( applyFilter )
  1559. {
  1560. if ( sActiveFilter.filterFlags & ServerFilter::Dedicated && !si->isDedicated() )
  1561. {
  1562. Con::printf( "Server %s filtered out by dedicated flag.", addrString );
  1563. removeServerInfo( address );
  1564. return;
  1565. }
  1566. if ( sActiveFilter.filterFlags & ServerFilter::NotPassworded && si->isPassworded() )
  1567. {
  1568. Con::printf( "Server %s filtered out by no-password flag.", addrString );
  1569. removeServerInfo( address );
  1570. return;
  1571. }
  1572. }
  1573. si->status.set( ServerInfo::Status_Responded );
  1574. // Get the player count:
  1575. stream->read( &si->numPlayers );
  1576. // Test player count against active filter:
  1577. if ( applyFilter && ( si->numPlayers < sActiveFilter.minPlayers || si->numPlayers > sActiveFilter.maxPlayers ) )
  1578. {
  1579. Con::printf( "Server %s filtered out by player count.", addrString );
  1580. removeServerInfo( address );
  1581. return;
  1582. }
  1583. // Get the max players and bot count:
  1584. stream->read( &si->maxPlayers );
  1585. stream->read( &si->numBots );
  1586. // Test bot count against active filter:
  1587. if ( applyFilter && ( si->numBots > sActiveFilter.maxBots ) )
  1588. {
  1589. Con::printf( "Server %s filtered out by maximum bot count.", addrString );
  1590. removeServerInfo( address );
  1591. return;
  1592. }
  1593. // Get the CPU speed;
  1594. U16 temp_U16;
  1595. stream->read( &temp_U16 );
  1596. si->cpuSpeed = temp_U16;
  1597. // Test CPU speed against active filter:
  1598. if ( applyFilter && ( si->cpuSpeed < sActiveFilter.minCPU ) )
  1599. {
  1600. Con::printf( "Server %s filtered out by minimum CPU speed.", addrString );
  1601. removeServerInfo( address );
  1602. return;
  1603. }
  1604. // Get the server info:
  1605. stream->readString( stringBuf );
  1606. if ( !si->statusString || ( isUpdate && dStrcmp( si->statusString, stringBuf ) != 0 ) )
  1607. {
  1608. si->infoString = (char*) dRealloc( (void*) si->infoString, dStrlen( stringBuf ) + 1 );
  1609. dStrcpy( si->infoString, stringBuf );
  1610. }
  1611. // Get the content string:
  1612. readLongCString( stream, stringBuf );
  1613. if ( !si->statusString || ( isUpdate && dStrcmp( si->statusString, stringBuf ) != 0 ) )
  1614. {
  1615. si->statusString = (char*) dRealloc( (void*) si->statusString, dStrlen( stringBuf ) + 1 );
  1616. dStrcpy( si->statusString, stringBuf );
  1617. }
  1618. // Update the server browser gui!
  1619. gServerBrowserDirty = true;
  1620. }
  1621. //-----------------------------------------------------------------------------
  1622. // Packet Dispatch
  1623. void DemoNetInterface::handleInfoPacket( const NetAddress* address, U8 packetType, BitStream* stream )
  1624. {
  1625. U8 flags;
  1626. U32 key;
  1627. stream->read( &flags );
  1628. stream->read( &key );
  1629. switch( packetType )
  1630. {
  1631. case GamePingRequest:
  1632. handleGamePingRequest( address, key, flags );
  1633. break;
  1634. case GamePingResponse:
  1635. handleGamePingResponse( address, stream, key, flags );
  1636. break;
  1637. case GameInfoRequest:
  1638. handleGameInfoRequest( address, key, flags );
  1639. break;
  1640. case GameInfoResponse:
  1641. handleGameInfoResponse( address, stream, key, flags );
  1642. break;
  1643. case MasterServerGameTypesResponse:
  1644. handleMasterServerGameTypesResponse( stream, key, flags );
  1645. break;
  1646. case MasterServerListResponse:
  1647. handleMasterServerListResponse( stream, key, flags );
  1648. break;
  1649. case GameMasterInfoRequest:
  1650. handleGameMasterInfoRequest( address, key, flags );
  1651. break;
  1652. }
  1653. }