Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

815 lines
24 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "FavoriteGames.h"
  8. #include "proto_oob.h"
  9. #include "ServerContextMenu.h"
  10. #include "ServerListCompare.h"
  11. #include "Socket.h"
  12. #include "util.h"
  13. #include "serverpage.h"
  14. #include "DialogAddServer.h"
  15. #include "FavoriteGames.h"
  16. #include "filesystem.h"
  17. #include "tier1/utlbuffer.h"
  18. #include <VGUI_Controls.h>
  19. #include <VGUI_KeyValues.h>
  20. #include <VGUI_ListPanel.h>
  21. #include <VGUI_IScheme.h>
  22. #include <VGUI_IVGui.h>
  23. #include <VGUI_ImagePanel.h>
  24. #include <VGUI_ISystem.h>
  25. #include <VGUI_MessageBox.h>
  26. #include <VGUI_Button.h>
  27. using namespace vgui;
  28. const int TIMEOUT = 99999;
  29. //-----------------------------------------------------------------------------
  30. // Purpose: Constructor
  31. //-----------------------------------------------------------------------------
  32. CFavoriteGames::CFavoriteGames(vgui::Panel *parent) : CBaseGamesPage(parent, "FavoriteGames")
  33. {
  34. m_iServerRefreshCount = 0;
  35. m_pImportFavoritesdlg = NULL;
  36. m_bSaveRcon=false;
  37. StartRefresh();
  38. }
  39. //-----------------------------------------------------------------------------
  40. // Purpose: Destructor
  41. //-----------------------------------------------------------------------------
  42. CFavoriteGames::~CFavoriteGames()
  43. {
  44. }
  45. //-----------------------------------------------------------------------------
  46. // Purpose:
  47. //-----------------------------------------------------------------------------
  48. void CFavoriteGames::LoadFavoritesList(KeyValues *favoritesData,bool loadrcon)
  49. {
  50. // load in favorites
  51. for (KeyValues *dat = favoritesData->GetFirstSubKey(); dat != NULL; dat = dat->GetNextKey())
  52. {
  53. serveritem_t server;
  54. memset(&server, 0, sizeof(server));
  55. const char *addr = dat->GetString("address");
  56. int ip1, ip2, ip3, ip4, port;
  57. sscanf(addr, "%d.%d.%d.%d:%d", &ip1, &ip2, &ip3, &ip4, &port);
  58. server.ip[0] = ip1;
  59. server.ip[1] = ip2;
  60. server.ip[2] = ip3;
  61. server.ip[3] = ip4;
  62. server.port = port;
  63. server.players = 0;
  64. v_strncpy(server.name, dat->GetString("name"), sizeof(server.name));
  65. v_strncpy(server.map, dat->GetString("map"), sizeof(server.map));
  66. v_strncpy(server.gameDir, dat->GetString("gamedir"), sizeof(server.gameDir));
  67. server.players = dat->GetInt("players");
  68. server.maxPlayers = dat->GetInt("maxplayers");
  69. if(loadrcon)
  70. {
  71. v_strncpy(server.rconPassword,dat->GetString("rconpassword"),sizeof(server.rconPassword));
  72. }
  73. // add to main list
  74. AddNewServer(server);
  75. }
  76. }
  77. //-----------------------------------------------------------------------------
  78. // Purpose: updates the Rconpassword for a server, and perhaps more later :)
  79. //-----------------------------------------------------------------------------
  80. void CFavoriteGames::UpdateServer(serveritem_t &serverIn)
  81. {
  82. for (int i = 0; i < m_Servers.ServerCount(); i++)
  83. {
  84. serveritem_t &serverOut = m_Servers.GetServer(i);
  85. if( !memcmp(serverOut.ip,serverIn.ip,sizeof(serverIn.ip)) &&
  86. serverOut.port==serverIn.port)
  87. {
  88. // we have a match!
  89. v_strncpy(serverOut.rconPassword,serverIn.rconPassword,sizeof(serverOut.rconPassword));
  90. }
  91. }
  92. }
  93. //-----------------------------------------------------------------------------
  94. // Purpose: saves the current list of servers to the favorites section of the data file
  95. //-----------------------------------------------------------------------------
  96. void CFavoriteGames::SaveFavoritesList(KeyValues *favoritesData,bool savercon)
  97. {
  98. favoritesData->Clear();
  99. // loop through all the servers writing them into the doc
  100. for (int i = 0; i < m_Servers.ServerCount(); i++)
  101. {
  102. serveritem_t &server = m_Servers.GetServer(i);
  103. // always save away all the entries, even if they didn't respond this time
  104. //if (server.doNotRefresh)
  105. // continue;
  106. KeyValues *dat = favoritesData->CreateNewKey();
  107. dat->SetString("name", server.name);
  108. dat->SetString("gamedir", server.gameDir);
  109. dat->SetInt("players", server.players);
  110. dat->SetInt("maxplayers", server.maxPlayers);
  111. dat->SetString("map", server.map);
  112. if(savercon)
  113. {
  114. dat->SetString("rconpassword",server.rconPassword);
  115. }
  116. char buf[64];
  117. sprintf(buf, "%d.%d.%d.%d:%d", server.ip[0], server.ip[1], server.ip[2], server.ip[3], server.port);
  118. dat->SetString("address", buf);
  119. }
  120. }
  121. //-----------------------------------------------------------------------------
  122. // Purpose: returns true if the game list supports the specified ui elements
  123. // Input : item -
  124. // Output : Returns true on success, false on failure.
  125. //-----------------------------------------------------------------------------
  126. bool CFavoriteGames::SupportsItem(InterfaceItem_e item)
  127. {
  128. switch (item)
  129. {
  130. case GETNEWLIST:
  131. case FILTERS:
  132. default:
  133. return false;
  134. }
  135. }
  136. //-----------------------------------------------------------------------------
  137. // Purpose: starts the servers refreshing
  138. //-----------------------------------------------------------------------------
  139. void CFavoriteGames::StartRefresh()
  140. {
  141. // stop current refresh
  142. m_Servers.StopRefresh();
  143. // build the refresh list from the server list
  144. for (int i = 0; i < m_Servers.ServerCount(); i++)
  145. {
  146. // When managing servers it doesn't matter if they don't respond
  147. //if (m_Servers.GetServer(i).doNotRefresh)
  148. // continue;
  149. m_Servers.AddServerToRefreshList(i);
  150. }
  151. m_Servers.StartRefresh();
  152. SetRefreshing(IsRefreshing());
  153. }
  154. //-----------------------------------------------------------------------------
  155. // Purpose: gets a new server list
  156. //-----------------------------------------------------------------------------
  157. void CFavoriteGames::GetNewServerList()
  158. {
  159. }
  160. //-----------------------------------------------------------------------------
  161. // Purpose: stops current refresh/GetNewServerList()
  162. //-----------------------------------------------------------------------------
  163. void CFavoriteGames::StopRefresh()
  164. {
  165. // stop the server list refreshing
  166. m_Servers.StopRefresh();
  167. // clear update states
  168. m_iServerRefreshCount = 0;
  169. // update UI
  170. RefreshComplete();
  171. }
  172. //-----------------------------------------------------------------------------
  173. // Purpose: returns true if the list is currently refreshing servers
  174. // Output : Returns true on success, false on failure.
  175. //-----------------------------------------------------------------------------
  176. bool CFavoriteGames::IsRefreshing()
  177. {
  178. return m_Servers.IsRefreshing();
  179. }
  180. //-----------------------------------------------------------------------------
  181. // Purpose: adds a new server to list
  182. // Input : &server -
  183. //-----------------------------------------------------------------------------
  184. void CFavoriteGames::AddNewServer(serveritem_t &newServer)
  185. {
  186. // copy server into main server list
  187. unsigned int index = m_Servers.AddNewServer(newServer);
  188. // reget the server
  189. serveritem_t &server = m_Servers.GetServer(index);
  190. server.hadSuccessfulResponse = true;
  191. server.doNotRefresh = false;
  192. server.listEntry = NULL;
  193. server.serverID = index;
  194. }
  195. //-----------------------------------------------------------------------------
  196. // Purpose: Continues the refresh
  197. // Input : moreAvailable -
  198. // lastUnique -
  199. //-----------------------------------------------------------------------------
  200. void CFavoriteGames::ListReceived(bool moreAvailable, int lastUnique)
  201. {
  202. m_Servers.StartRefresh();
  203. }
  204. //-----------------------------------------------------------------------------
  205. // Purpose: called when Connect button is pressed
  206. //-----------------------------------------------------------------------------
  207. void CFavoriteGames::OnBeginConnect()
  208. {
  209. if (!m_pGameList->GetNumSelectedRows())
  210. return;
  211. // get the server
  212. int serverIndex = m_pGameList->GetDataItem(m_pGameList->GetSelectedRow(0))->userData;
  213. // stop the current refresh
  214. StopRefresh();
  215. // join the game
  216. CServerPage::GetInstance()->JoinGame(this, serverIndex);
  217. }
  218. //-----------------------------------------------------------------------------
  219. // Purpose: Displays the current game info without connecting
  220. //-----------------------------------------------------------------------------
  221. void CFavoriteGames::OnViewGameInfo()
  222. {
  223. if (!m_pGameList->GetNumSelectedRows())
  224. return;
  225. // get the server
  226. int serverIndex = m_pGameList->GetDataItem(m_pGameList->GetSelectedRow(0))->userData;
  227. // stop the current refresh
  228. StopRefresh();
  229. // join the game
  230. CServerPage::GetInstance()->OpenGameInfoDialog(this, serverIndex);
  231. }
  232. //-----------------------------------------------------------------------------
  233. // Purpose: reapplies filters (does nothing with this)
  234. //-----------------------------------------------------------------------------
  235. void CFavoriteGames::ApplyFilters()
  236. {
  237. }
  238. //-----------------------------------------------------------------------------
  239. // Purpose: called when the server has successfully responded
  240. // Input : &server -
  241. //-----------------------------------------------------------------------------
  242. void CFavoriteGames::ServerResponded(serveritem_t &server)
  243. {
  244. // update UI
  245. KeyValues *kv;
  246. if (server.listEntry)
  247. {
  248. // we're updating an existing entry
  249. kv = server.listEntry->kv;
  250. server.listEntry->userData = server.serverID;
  251. }
  252. else
  253. {
  254. // new entry
  255. kv = new KeyValues("Server");
  256. }
  257. if (server.name[0] && server.maxPlayers)
  258. {
  259. kv->SetString("name", server.name);
  260. kv->SetString("map", server.map);
  261. kv->SetString("GameDir", server.gameDir);
  262. kv->SetString("GameDesc", server.gameDescription);
  263. kv->SetPtr("password", server.password ? m_pPasswordIcon : NULL);
  264. char buf[256];
  265. sprintf(buf, "%d / %d", server.players, server.maxPlayers);
  266. kv->SetString("Players", buf);
  267. }
  268. if(server.ping==TIMEOUT)
  269. {
  270. kv->SetString("Ping", "timeout");
  271. }
  272. else
  273. {
  274. kv->SetInt("Ping", server.ping);
  275. }
  276. if (!server.listEntry)
  277. {
  278. // new server, add to list
  279. int index = m_pGameList->AddItem(kv, server.serverID);
  280. server.listEntry = m_pGameList->GetDataItem(index);
  281. }
  282. else
  283. {
  284. m_pGameList->ApplyItemChanges(server.listEntry->row);
  285. }
  286. m_iServerRefreshCount++;
  287. if (m_pGameList->GetItemCount() > 1)
  288. {
  289. char buf[64];
  290. sprintf(buf, " Servers (%d)", m_pGameList->GetItemCount());
  291. m_pGameList->SetColumnHeaderText(1, buf);
  292. }
  293. else
  294. {
  295. m_pGameList->SetColumnHeaderText(1, " Servers");
  296. }
  297. m_pGameList->Repaint();
  298. }
  299. //-----------------------------------------------------------------------------
  300. // Purpose: called when a server response has timed out, treated just like a normal server
  301. //-----------------------------------------------------------------------------
  302. void CFavoriteGames::ServerFailedToRespond(serveritem_t &server)
  303. {
  304. server.ping=TIMEOUT;
  305. ServerResponded(server);
  306. }
  307. //-----------------------------------------------------------------------------
  308. // Purpose: called when the current refresh list is complete
  309. //-----------------------------------------------------------------------------
  310. void CFavoriteGames::RefreshComplete()
  311. {
  312. SetRefreshing(false);
  313. m_pGameList->SortList();
  314. m_iServerRefreshCount = 0;
  315. }
  316. //-----------------------------------------------------------------------------
  317. // Purpose: opens context menu (user right clicked on a server)
  318. //-----------------------------------------------------------------------------
  319. void CFavoriteGames::OnOpenContextMenu(int row)
  320. {
  321. CServerContextMenu *menu = CServerPage::GetInstance()->GetContextMenu();
  322. if (m_pGameList->GetNumSelectedRows())
  323. {
  324. // get the server
  325. unsigned int serverID = m_pGameList->GetDataItem(m_pGameList->GetSelectedRow(0))->userData;
  326. serveritem_t &server = m_Servers.GetServer(serverID);
  327. // activate context menu
  328. menu->ShowMenu(this, serverID, true, true, false,true);
  329. menu->AddMenuItem("RemoveServer", "R&emove server from favorites", new KeyValues("RemoveFromFavorites"), this);
  330. }
  331. else
  332. {
  333. // no selected rows, so don't display default stuff in menu
  334. menu->ShowMenu(this, -1, false, false, false,false);
  335. }
  336. menu->AddMenuItem("AddServerByName", "&Add server by IP address", new KeyValues("AddServerByName"), this);
  337. }
  338. //-----------------------------------------------------------------------------
  339. // Purpose: refreshes a single server
  340. //-----------------------------------------------------------------------------
  341. void CFavoriteGames::OnRefreshServer(int serverID)
  342. {
  343. // walk the list of selected servers refreshing them
  344. for (int i = 0; i < m_pGameList->GetNumSelectedRows(); i++)
  345. {
  346. int row = m_pGameList->GetSelectedRow(i);
  347. ListPanel::DATAITEM *data = m_pGameList->GetDataItem(row);
  348. if (data)
  349. {
  350. serverID = data->userData;
  351. // refresh this server
  352. m_Servers.AddServerToRefreshList(serverID);
  353. }
  354. }
  355. m_Servers.StartRefresh();
  356. SetRefreshing(IsRefreshing());
  357. }
  358. //-----------------------------------------------------------------------------
  359. // Purpose: adds a server to the favorites
  360. // Input : serverID -
  361. //-----------------------------------------------------------------------------
  362. void CFavoriteGames::OnRemoveFromFavorites()
  363. {
  364. // iterate the selection
  365. while (m_pGameList->GetNumSelectedRows() > 0)
  366. {
  367. int row = m_pGameList->GetSelectedRow(0);
  368. int serverID = m_pGameList->GetDataItem(row)->userData;
  369. if (serverID >= m_Servers.ServerCount())
  370. continue;
  371. serveritem_t &server = m_Servers.GetServer(serverID);
  372. // remove from favorites list
  373. if (server.listEntry)
  374. {
  375. // find the row in the list and kill
  376. m_pGameList->RemoveItem(server.listEntry->row);
  377. server.listEntry = NULL;
  378. }
  379. server.doNotRefresh = true;
  380. }
  381. InvalidateLayout();
  382. Repaint();
  383. }
  384. //-----------------------------------------------------------------------------
  385. // Purpose: Adds a server by IP address
  386. //-----------------------------------------------------------------------------
  387. void CFavoriteGames::OnAddServerByName()
  388. {
  389. // open the add server dialog
  390. CDialogAddServer *dlg = new CDialogAddServer(this);
  391. dlg->Open();
  392. }
  393. //-----------------------------------------------------------------------------
  394. // Purpose: Load a file into a CUtlBuffer class
  395. //-----------------------------------------------------------------------------
  396. int LoadFileIntoBuffer(CUtlBuffer &buf, char *pszFilename)
  397. {
  398. // Open the file
  399. FileHandle_t fh = g_pFullFileSystem->Open( pszFilename, "rb" );
  400. if (fh == 0)
  401. {
  402. MessageBox *dlg = new MessageBox ("Unable to open datafile.", false);
  403. dlg->DoModal();
  404. return 0; //file didn't load
  405. }
  406. int nFileSize = g_pFullFileSystem->Size(fh);
  407. // Read the file in one gulp
  408. buf.EnsureCapacity( nFileSize );
  409. int result = g_pFullFileSystem->Read( buf.Base(), nFileSize, fh );
  410. g_pFullFileSystem->Close( fh );
  411. return nFileSize;
  412. }
  413. //-----------------------------------------------------------------------------
  414. // Purpose: Import Favorite Servers from previous installations of
  415. // Halflife
  416. //-----------------------------------------------------------------------------
  417. void CFavoriteGames::ImportFavorites()
  418. {
  419. // disabled for now due to filesystem not accepting non-relative paths
  420. return;
  421. char name[512];
  422. // check if halflife is installed
  423. if (vgui::system()->GetRegistryString("HKEY_LOCAL_MACHINE\\Software\\Valve\\Half-life\\InstallPath", name, sizeof(name)))
  424. {
  425. // attach name of favorites file
  426. strcat(name, "\\favsvrs.dat");
  427. }
  428. // check if counterstrike is installed
  429. else if (vgui::system()->GetRegistryString("HKEY_LOCAL_MACHINE\\Software\\Sierra OnLine\\Setup\\CSTRIKE\\Directory", name, sizeof(name)))
  430. {
  431. // attach name of favorites file
  432. strcat(name, "\\favsvrs.dat");
  433. }
  434. else // no hl installation, no fav servers?
  435. {
  436. return;
  437. }
  438. // see if the favorite server list file exists.
  439. FileHandle_t fh = g_pFullFileSystem->Open(name, "rb");
  440. if ( !fh )
  441. {
  442. return;
  443. }
  444. g_pFullFileSystem->Close(fh);
  445. // it exists! yay lets transfer the servers over into the server browser
  446. // pop up a message about what we are doing
  447. m_pImportFavoritesdlg = new MessageBox ("Updating Favorites", "Transferring your Favorites. This may take a minute...", this);
  448. m_pImportFavoritesdlg->SetCommand("OnImportFavoritesFile");
  449. m_pImportFavoritesdlg->AddActionSignalTarget(this);
  450. // hide the ok button since they dont have to do anything
  451. m_pImportFavoritesdlg->SetOkButtonVisible(false);
  452. // don't let them close this window
  453. m_pImportFavoritesdlg->DisableCloseButton(false);
  454. // dont let them put this window on the menubar
  455. m_pImportFavoritesdlg->SetMenuButtonVisible(false);
  456. // Pop up the box
  457. m_pImportFavoritesdlg->DoModal();
  458. // execute the message box's command
  459. KeyValues *command = new KeyValues("Command");
  460. command->SetString("Command", "OnImportFavoritesFile");
  461. // post the message with a delay so that the box will display before the command is executed
  462. PostMessage(this, command, (float).1);
  463. }
  464. //-----------------------------------------------------------------------------
  465. // Purpose: Parse posted messages
  466. //
  467. //-----------------------------------------------------------------------------
  468. void CFavoriteGames::OnCommand(const char *command)
  469. {
  470. if (!strcmp(command, "OnImportFavoritesFile"))
  471. {
  472. OnImportFavoritesFile();
  473. }
  474. else
  475. {
  476. BaseClass::OnCommand(command);
  477. }
  478. }
  479. //-----------------------------------------------------------------------------
  480. // Purpose: Import Favorite Servers from previous installations of
  481. // Halflife
  482. //-----------------------------------------------------------------------------
  483. void CFavoriteGames::OnImportFavoritesFile()
  484. {
  485. char name[512];
  486. // check if they have halflife
  487. if (vgui::system()->GetRegistryString("HKEY_LOCAL_MACHINE\\Software\\Valve\\Half-life\\InstallPath", name, sizeof(name)))
  488. {
  489. // add filename
  490. strcat(name, "\\favsvrs.dat");
  491. }
  492. // check if they have counterstrike
  493. else if (vgui::system()->GetRegistryString("HKEY_LOCAL_MACHINE\\Software\\Sierra OnLine\\Setup\\CSTRIKE\\Directory", name, sizeof(name)))
  494. {
  495. // add filename
  496. strcat(name, "\\favsvrs.dat");
  497. }
  498. else // no hl installation, no fav servers? // should never hit this!
  499. {
  500. return;
  501. }
  502. // load the file in one gulp
  503. CUtlBuffer buf ( 0, 1024, true);
  504. int fileSize = LoadFileIntoBuffer(buf, name);
  505. if ( fileSize == 0)
  506. {
  507. MessageBox *dlg = new MessageBox ("Unable to load favorites", "Error loading file.", this);
  508. dlg->DoModal();
  509. return; //file didn't load
  510. }
  511. // scan for the favorite servers
  512. char data[255];
  513. buf.GetString(data);
  514. while (buf.TellGet() < fileSize)
  515. {
  516. // store the start of the server description so we can go back
  517. // if its a favorite
  518. int serverStart;
  519. if ( strstr (data, "server") != NULL)
  520. {
  521. buf.GetString(data); // get the '{'
  522. serverStart = buf.TellGet();
  523. }
  524. // check if server is a favorite
  525. if ( strstr (data, "favorite") != NULL)
  526. {
  527. buf.GetString(data);
  528. if ( strstr(data, "1") )// server is a favorite
  529. {
  530. // go back to the start and load the details
  531. buf.SeekGet( CUtlBuffer::SEEK_HEAD, serverStart);
  532. // try and add this server
  533. if (!LoadAFavoriteServer (buf))
  534. {
  535. // file may be corrupt, had trouble parsing it
  536. break;
  537. };
  538. }
  539. }
  540. buf.EatWhiteSpace();
  541. buf.GetString(data);
  542. }
  543. // we are done. Hide the message box.
  544. m_pImportFavoritesdlg->SetVisible(false);
  545. }
  546. //-----------------------------------------------------------------------------
  547. // Purpose: Check to make sure we are reading what is expected
  548. //
  549. //-----------------------------------------------------------------------------
  550. bool CFavoriteGames::CheckForCorruption(char *data, const char *checkString)
  551. {
  552. if (strcmp(data, checkString) != 0)
  553. {
  554. MessageBox *dlg = new MessageBox ("Unable to load favorites", "Error loading. File may be corrupt.");
  555. dlg->DoModal();
  556. return true;
  557. }
  558. return false;
  559. }
  560. //-----------------------------------------------------------------------------
  561. // Purpose: Parse throught the details of a server and populate a serveritem_t structure
  562. // Add it to the favorites list at the end.
  563. //-----------------------------------------------------------------------------
  564. bool CFavoriteGames::LoadAFavoriteServer (CUtlBuffer &buf)
  565. {
  566. serveritem_t fav;
  567. char data[255];
  568. buf.GetString(data);
  569. if (CheckForCorruption(data, "\"address\""))
  570. return false;;
  571. buf.GetString(data);
  572. int temp[4];
  573. sscanf (data, "\"%d.%d.%d.%d\"\n", &temp[0], &temp[1], &temp[2], &temp[3]);
  574. fav.ip[0] = temp[0];
  575. fav.ip[1] = temp[1];
  576. fav.ip[2] = temp[2];
  577. fav.ip[3] = temp[3];
  578. buf.EatWhiteSpace();
  579. buf.Scanf ("\"port\" \"%d\"", &fav.port );
  580. if (fav.port < 0)
  581. fav.port += 65536;
  582. buf.EatWhiteSpace();
  583. buf.Scanf ("\"name\" \"%s\"", fav.name );
  584. fav.name[strlen(fav.name)-1]='\0'; // remove trailing quote
  585. buf.EatWhiteSpace();
  586. buf.Scanf ("\"map\" \"%s\"", fav.map );
  587. fav.map[strlen(fav.map)-1]='\0'; // remove trailing quote
  588. buf.EatWhiteSpace();
  589. buf.Scanf ("\"game\" \"%s\"", fav.gameDescription );
  590. fav.gameDescription[strlen(fav.gameDescription)-1]='\0'; // remove trailing quote
  591. buf.EatWhiteSpace();
  592. buf.Scanf ("\"dir\" \"%s\"", fav.gameDir );
  593. fav.gameDir[strlen(fav.gameDir)-1
  594. ]='\0'; // remove trailing quote
  595. buf.GetString(data);
  596. if (CheckForCorruption(data, "\"url\""))
  597. return false;;
  598. buf.GetString(data);
  599. buf.GetString(data);
  600. if (CheckForCorruption(data, "\"dl\""))
  601. return false;;
  602. buf.GetString(data);
  603. buf.EatWhiteSpace();
  604. buf.Scanf ("\"maxplayers\" \"%d\"", &fav.maxPlayers );
  605. buf.EatWhiteSpace();
  606. buf.Scanf ("\"currentplayers\" \"%d\"", &fav.players );
  607. buf.GetString(data);
  608. if (CheckForCorruption(data, "\"protocol\""))
  609. return false;;
  610. buf.GetString(data);
  611. buf.GetString(data);
  612. if (CheckForCorruption(data, "\"favorite\""))
  613. return false;;
  614. buf.GetString(data);
  615. buf.GetString(data);
  616. if (CheckForCorruption(data, "\"ipx\""))
  617. return false;;
  618. buf.GetString(data);
  619. buf.GetString(data);
  620. if (CheckForCorruption(data, "\"mod\""))
  621. return false;;
  622. buf.GetString(data);
  623. buf.GetString(data);
  624. if (CheckForCorruption(data, "\"version\""))
  625. return false;;
  626. buf.GetString(data);
  627. buf.GetString(data);
  628. if (CheckForCorruption(data, "\"size\""))
  629. return false;;
  630. buf.GetString(data);
  631. buf.GetString(data);
  632. if (CheckForCorruption(data, "\"svtype\""))
  633. return false;;
  634. buf.GetString(data);
  635. buf.GetString(data);
  636. if (CheckForCorruption(data, "\"svos\""))
  637. return false;;
  638. buf.GetString(data);
  639. buf.EatWhiteSpace();
  640. buf.Scanf ("\"password\" \"%d\"\n", &fav.password );
  641. buf.GetString(data);
  642. if (CheckForCorruption(data, "\"svside\""))
  643. return false;;
  644. buf.GetString(data);
  645. buf.GetString(data);
  646. if (CheckForCorruption(data, "\"cldll\""))
  647. return false;;
  648. buf.GetString(data);
  649. buf.GetString(data);
  650. if (CheckForCorruption(data, "\"lan\""))
  651. return false;;
  652. buf.GetString(data);
  653. buf.GetString(data);
  654. if (CheckForCorruption(data, "\"svping\""))
  655. return false;;
  656. buf.GetString(data);
  657. buf.GetString(data);
  658. if (CheckForCorruption(data, "\"noresponse\""))
  659. return false;;
  660. buf.GetString(data);
  661. buf.GetString(data);
  662. if (CheckForCorruption(data, "\"packetloss\""))
  663. return false;;
  664. buf.GetString(data);
  665. buf.GetString(data);
  666. if (CheckForCorruption(data, "\"status\""))
  667. return false;;
  668. buf.GetString(data);
  669. buf.GetString(data);
  670. if (CheckForCorruption(data, "\"filtered\""))
  671. return false;;
  672. buf.GetString(data);
  673. buf.GetString(data);
  674. if (CheckForCorruption(data, "\"fullmax\""))
  675. return false;;
  676. buf.GetString(data);
  677. buf.GetString(data);
  678. if (CheckForCorruption(data, "\"hlversion\""))
  679. return false;;
  680. buf.GetString(data);
  681. AddNewServer(fav);
  682. return true;
  683. }
  684. //-----------------------------------------------------------------------------
  685. // Purpose: Message map
  686. //-----------------------------------------------------------------------------
  687. MessageMapItem_t CFavoriteGames::m_MessageMap[] =
  688. {
  689. MAP_MESSAGE( CFavoriteGames, "ConnectToServer", OnBeginConnect ),
  690. MAP_MESSAGE( CFavoriteGames, "ViewGameInfo", OnViewGameInfo ),
  691. MAP_MESSAGE( CFavoriteGames, "RemoveFromFavorites", OnRemoveFromFavorites ),
  692. MAP_MESSAGE( CFavoriteGames, "AddServerByName", OnAddServerByName ),
  693. MAP_MESSAGE_INT( CFavoriteGames, "RefreshServer", OnRefreshServer, "serverID" ),
  694. MAP_MESSAGE_INT( CFavoriteGames, "OpenContextMenu", OnOpenContextMenu, "row" ),
  695. };
  696. IMPLEMENT_PANELMAP(CFavoriteGames, BaseClass);