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
25 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // The copyright to the contents herein is the property of Valve, L.L.C.
  4. // The contents may be used and/or copied only with the written permission of
  5. // Valve, L.L.C., or in accordance with the terms and conditions stipulated in
  6. // the agreement/contract under which the contents have been supplied.
  7. //
  8. // Purpose:
  9. //
  10. // $Workfile: $
  11. // $Date: $
  12. //
  13. //-----------------------------------------------------------------------------
  14. // $Log: $
  15. //
  16. // $NoKeywords: $
  17. //=============================================================================
  18. #include "pch_serverbrowser.h"
  19. #if defined( _X360 )
  20. #include "xbox/xbox_win32stubs.h"
  21. #endif
  22. #if defined( _WIN32 ) && !defined( _X360 )
  23. #define WIN32_LEAN_AND_MEAN
  24. #include <winsock.h>
  25. #endif
  26. #ifdef LINUX
  27. #include <arpa/inet.h>
  28. #endif
  29. using namespace vgui;
  30. ConVar sb_quick_list_bit_field( "sb_quick_list_bit_field", "-1" );
  31. static CServerBrowserDialog *s_InternetDlg = NULL;
  32. CServerBrowserDialog &ServerBrowserDialog()
  33. {
  34. return *CServerBrowserDialog::GetInstance();
  35. }
  36. // Returns a list of the ports that we hit when looking for
  37. void GetMostCommonQueryPorts( CUtlVector<uint16> &ports )
  38. {
  39. for ( int i=0; i <= 5; i++ )
  40. {
  41. ports.AddToTail( 27015 + i );
  42. ports.AddToTail( 26900 + i );
  43. }
  44. ports.AddToTail(4242); //RDKF
  45. ports.AddToTail(27215); //Lost Planet
  46. }
  47. //-----------------------------------------------------------------------------
  48. // Purpose: Constructor
  49. //-----------------------------------------------------------------------------
  50. CServerBrowserDialog::CServerBrowserDialog(vgui::Panel *parent) : Frame(parent, "CServerBrowserDialog")
  51. {
  52. s_InternetDlg = this;
  53. m_szGameName[0] = 0;
  54. m_szModDir[0] = 0;
  55. m_pSavedData = NULL;
  56. m_pFilterData = NULL;
  57. m_pFavorites = NULL;
  58. m_pBlacklist = NULL;
  59. m_pHistory = NULL;
  60. // Do this before LoadUserData() so it loads the blacklist file properly
  61. m_pBlacklist = new CBlacklistedServers(this);
  62. LoadUserData();
  63. m_pInternetGames = new CCustomGames(this);
  64. m_pFavorites = new CFavoriteGames(this);
  65. m_pHistory = new CHistoryGames(this);
  66. m_pSpectateGames = new CSpectateGames(this);
  67. m_pLanGames = new CLanGames(this);
  68. m_pFriendsGames = new CFriendsGames(this);
  69. SetMinimumSize( 640, 384 );
  70. SetSize( 640, 384 );
  71. m_pGameList = m_pInternetGames;
  72. m_pContextMenu = new CServerContextMenu(this);;
  73. // property sheet
  74. m_pTabPanel = new PropertySheet(this, "GameTabs");
  75. m_pTabPanel->SetTabWidth(72);
  76. m_pTabPanel->AddPage(m_pInternetGames, "#ServerBrowser_InternetTab");
  77. m_pTabPanel->AddPage(m_pFavorites, "#ServerBrowser_FavoritesTab");
  78. m_pTabPanel->AddPage(m_pHistory, "#ServerBrowser_HistoryTab");
  79. m_pTabPanel->AddPage(m_pSpectateGames, "#ServerBrowser_SpectateTab");
  80. m_pTabPanel->AddPage(m_pLanGames, "#ServerBrowser_LanTab");
  81. m_pTabPanel->AddPage(m_pFriendsGames, "#ServerBrowser_FriendsTab");
  82. if ( m_pBlacklist )
  83. {
  84. m_pTabPanel->AddPage(m_pBlacklist, "#ServerBrowser_BlacklistTab");
  85. }
  86. m_pTabPanel->AddActionSignalTarget(this);
  87. m_pStatusLabel = new Label(this, "StatusLabel", "");
  88. LoadControlSettingsAndUserConfig("Servers/DialogServerBrowser.res");
  89. m_pStatusLabel->SetText("");
  90. // load current tab
  91. const char *gameList = m_pSavedData->GetString("GameList");
  92. if (!Q_stricmp(gameList, "spectate"))
  93. {
  94. m_pTabPanel->SetActivePage(m_pSpectateGames);
  95. }
  96. else if (!Q_stricmp(gameList, "favorites"))
  97. {
  98. m_pTabPanel->SetActivePage(m_pFavorites);
  99. }
  100. else if (!Q_stricmp(gameList, "history"))
  101. {
  102. m_pTabPanel->SetActivePage(m_pHistory);
  103. }
  104. else if (!Q_stricmp(gameList, "lan"))
  105. {
  106. m_pTabPanel->SetActivePage(m_pLanGames);
  107. }
  108. else if (!Q_stricmp(gameList, "friends"))
  109. {
  110. m_pTabPanel->SetActivePage(m_pFriendsGames);
  111. }
  112. else if (!Q_stricmp(gameList, "blacklist"))
  113. {
  114. m_pTabPanel->SetActivePage(m_pBlacklist);
  115. }
  116. else
  117. {
  118. m_pTabPanel->SetActivePage(m_pInternetGames);
  119. }
  120. ivgui()->AddTickSignal( GetVPanel() );
  121. }
  122. //-----------------------------------------------------------------------------
  123. // Purpose: Destructor
  124. //-----------------------------------------------------------------------------
  125. CServerBrowserDialog::~CServerBrowserDialog()
  126. {
  127. delete m_pContextMenu;
  128. SaveUserData();
  129. if (m_pSavedData)
  130. {
  131. m_pSavedData->deleteThis();
  132. }
  133. }
  134. //-----------------------------------------------------------------------------
  135. // Purpose: Called once to set up
  136. //-----------------------------------------------------------------------------
  137. void CServerBrowserDialog::Initialize()
  138. {
  139. SetTitle("#ServerBrowser_Servers", true);
  140. SetVisible(false);
  141. }
  142. //-----------------------------------------------------------------------------
  143. // Purpose: returns a server in the list
  144. //-----------------------------------------------------------------------------
  145. gameserveritem_t *CServerBrowserDialog::GetServer( unsigned int serverID )
  146. {
  147. if (m_pGameList)
  148. return m_pGameList->GetServer( serverID );
  149. return NULL;
  150. }
  151. //-----------------------------------------------------------------------------
  152. // Purpose: Activates and gives the tab focus
  153. //-----------------------------------------------------------------------------
  154. void CServerBrowserDialog::Open()
  155. {
  156. BaseClass::Activate();
  157. m_pTabPanel->RequestFocus();
  158. MoveToCenterOfScreen();
  159. }
  160. //-----------------------------------------------------------------------------
  161. // Purpose: Called every frame, updates animations for this module
  162. //-----------------------------------------------------------------------------
  163. void CServerBrowserDialog::OnTick()
  164. {
  165. BaseClass::OnTick();
  166. vgui::GetAnimationController()->UpdateAnimations( system()->GetFrameTime() );
  167. }
  168. //-----------------------------------------------------------------------------
  169. // Purpose: Loads filter settings from disk
  170. //-----------------------------------------------------------------------------
  171. void CServerBrowserDialog::LoadUserData()
  172. {
  173. // free any old filters
  174. if (m_pSavedData)
  175. {
  176. m_pSavedData->deleteThis();
  177. }
  178. m_pSavedData = new KeyValues("Filters");
  179. if (!m_pSavedData->LoadFromFile( g_pFullFileSystem, "ServerBrowser.vdf", "CONFIG"))
  180. {
  181. // doesn't matter if the file is not found, defaults will work successfully and file will be created on exit
  182. }
  183. KeyValues *filters = m_pSavedData->FindKey( "Filters", false );
  184. if ( filters )
  185. {
  186. m_pFilterData = filters->MakeCopy();
  187. m_pSavedData->RemoveSubKey( filters );
  188. }
  189. else
  190. {
  191. m_pFilterData = new KeyValues( "Filters" );
  192. }
  193. // reload all the page settings if necessary
  194. if (m_pHistory)
  195. {
  196. // history
  197. m_pHistory->LoadHistoryList();
  198. if ( IsVisible() && m_pHistory->IsVisible() )
  199. m_pHistory->StartRefresh();
  200. }
  201. if (m_pFavorites)
  202. {
  203. // favorites
  204. m_pFavorites->LoadFavoritesList();
  205. // filters
  206. ReloadFilterSettings();
  207. if ( IsVisible() && m_pFavorites->IsVisible() )
  208. m_pFavorites->StartRefresh();
  209. }
  210. if ( m_pBlacklist )
  211. {
  212. m_pBlacklist->LoadBlacklistedList();
  213. }
  214. InvalidateLayout();
  215. Repaint();
  216. }
  217. //-----------------------------------------------------------------------------
  218. // Purpose:
  219. //-----------------------------------------------------------------------------
  220. void CServerBrowserDialog::SaveUserData()
  221. {
  222. m_pSavedData->Clear();
  223. m_pSavedData->LoadFromFile( g_pFullFileSystem, "ServerBrowser.vdf", "CONFIG");
  224. // set the current tab
  225. if (m_pGameList == m_pSpectateGames)
  226. {
  227. m_pSavedData->SetString("GameList", "spectate");
  228. }
  229. else if (m_pGameList == m_pFavorites)
  230. {
  231. m_pSavedData->SetString("GameList", "favorites");
  232. }
  233. else if (m_pGameList == m_pLanGames)
  234. {
  235. m_pSavedData->SetString("GameList", "lan");
  236. }
  237. else if (m_pGameList == m_pFriendsGames)
  238. {
  239. m_pSavedData->SetString("GameList", "friends");
  240. }
  241. else if (m_pGameList == m_pHistory)
  242. {
  243. m_pSavedData->SetString("GameList", "history");
  244. }
  245. else
  246. {
  247. m_pSavedData->SetString("GameList", "internet");
  248. }
  249. m_pSavedData->RemoveSubKey( m_pSavedData->FindKey( "Filters" ) ); // remove the saved subkey and add our subkey
  250. m_pSavedData->AddSubKey( m_pFilterData->MakeCopy() );
  251. m_pSavedData->SaveToFile( g_pFullFileSystem, "ServerBrowser.vdf", "CONFIG");
  252. if ( m_pBlacklist )
  253. {
  254. m_pBlacklist->SaveBlacklistedList();
  255. }
  256. // save per-page config
  257. SaveUserConfig();
  258. }
  259. //-----------------------------------------------------------------------------
  260. // Purpose: refreshes the page currently visible
  261. //-----------------------------------------------------------------------------
  262. void CServerBrowserDialog::RefreshCurrentPage()
  263. {
  264. if (m_pGameList)
  265. {
  266. m_pGameList->StartRefresh();
  267. }
  268. }
  269. //-----------------------------------------------------------------------------
  270. // Purpose:
  271. //-----------------------------------------------------------------------------
  272. void CServerBrowserDialog::BlacklistsChanged()
  273. {
  274. m_pInternetGames->ApplyGameFilters();
  275. }
  276. //-----------------------------------------------------------------------------
  277. // Purpose: Updates status test at bottom of window
  278. //-----------------------------------------------------------------------------
  279. void CServerBrowserDialog::UpdateStatusText(const char *fmt, ...)
  280. {
  281. if ( !m_pStatusLabel )
  282. return;
  283. if ( fmt && strlen(fmt) > 0 )
  284. {
  285. char str[ 1024 ];
  286. va_list argptr;
  287. va_start( argptr, fmt );
  288. _vsnprintf( str, sizeof(str), fmt, argptr );
  289. va_end( argptr );
  290. m_pStatusLabel->SetText( str );
  291. }
  292. else
  293. {
  294. // clear
  295. m_pStatusLabel->SetText( "" );
  296. }
  297. }
  298. //-----------------------------------------------------------------------------
  299. // Purpose: Updates status test at bottom of window
  300. // Input : wchar_t* (unicode string) -
  301. //-----------------------------------------------------------------------------
  302. void CServerBrowserDialog::UpdateStatusText(wchar_t *unicode)
  303. {
  304. if ( !m_pStatusLabel )
  305. return;
  306. if ( unicode && wcslen(unicode) > 0 )
  307. {
  308. m_pStatusLabel->SetText( unicode );
  309. }
  310. else
  311. {
  312. // clear
  313. m_pStatusLabel->SetText( "" );
  314. }
  315. }
  316. //-----------------------------------------------------------------------------
  317. // Purpose:
  318. //-----------------------------------------------------------------------------
  319. void CServerBrowserDialog::OnGameListChanged()
  320. {
  321. m_pGameList = dynamic_cast<IGameList *>(m_pTabPanel->GetActivePage());
  322. UpdateStatusText("");
  323. InvalidateLayout();
  324. Repaint();
  325. }
  326. //-----------------------------------------------------------------------------
  327. // Purpose: returns a pointer to a static instance of this dialog
  328. //-----------------------------------------------------------------------------
  329. CServerBrowserDialog *CServerBrowserDialog::GetInstance()
  330. {
  331. return s_InternetDlg;
  332. }
  333. //-----------------------------------------------------------------------------
  334. // Purpose: Adds a server to the list of favorites
  335. //-----------------------------------------------------------------------------
  336. void CServerBrowserDialog::AddServerToFavorites(gameserveritem_t &server)
  337. {
  338. if ( steamapicontext->SteamMatchmaking() )
  339. {
  340. steamapicontext->SteamMatchmaking()->AddFavoriteGame(
  341. server.m_nAppID,
  342. server.m_NetAdr.GetIP(),
  343. server.m_NetAdr.GetConnectionPort(),
  344. server.m_NetAdr.GetQueryPort(),
  345. k_unFavoriteFlagFavorite,
  346. time( NULL ) );
  347. if ( GameSupportsReplay() )
  348. {
  349. // send command to propagate to the client so the client can send it on to the GC
  350. char command[ 256 ];
  351. Q_snprintf( command, Q_ARRAYSIZE( command ), "rfgc %s\n", server.m_NetAdr.GetConnectionAddressString() );
  352. g_pRunGameEngine->AddTextCommand( command );
  353. }
  354. }
  355. }
  356. //-----------------------------------------------------------------------------
  357. // Purpose: Adds a server to our list of blacklisted servers
  358. //-----------------------------------------------------------------------------
  359. void CServerBrowserDialog::AddServerToBlacklist(gameserveritem_t &server)
  360. {
  361. if ( m_pBlacklist )
  362. {
  363. m_pBlacklist->AddServer( server );
  364. }
  365. }
  366. //-----------------------------------------------------------------------------
  367. // Purpose:
  368. //-----------------------------------------------------------------------------
  369. bool CServerBrowserDialog::IsServerBlacklisted(gameserveritem_t &server)
  370. {
  371. if ( m_pBlacklist )
  372. return m_pBlacklist->IsServerBlacklisted( server );
  373. return false;
  374. }
  375. //-----------------------------------------------------------------------------
  376. // Purpose:
  377. //-----------------------------------------------------------------------------
  378. CServerContextMenu *CServerBrowserDialog::GetContextMenu(vgui::Panel *pPanel)
  379. {
  380. // create a drop down for this object's states
  381. if (m_pContextMenu)
  382. delete m_pContextMenu;
  383. m_pContextMenu = new CServerContextMenu(this);
  384. m_pContextMenu->SetAutoDelete( false );
  385. if (!pPanel)
  386. {
  387. m_pContextMenu->SetParent(this);
  388. }
  389. else
  390. {
  391. m_pContextMenu->SetParent(pPanel);
  392. }
  393. m_pContextMenu->SetVisible(false);
  394. return m_pContextMenu;
  395. }
  396. //-----------------------------------------------------------------------------
  397. // Purpose: begins the process of joining a server from a game list
  398. // the game info dialog it opens will also update the game list
  399. //-----------------------------------------------------------------------------
  400. CDialogGameInfo *CServerBrowserDialog::JoinGame(IGameList *gameList, unsigned int serverIndex)
  401. {
  402. // open the game info dialog, then mark it to attempt to connect right away
  403. CDialogGameInfo *gameDialog = OpenGameInfoDialog(gameList, serverIndex);
  404. // set the dialog name to be the server name
  405. gameDialog->Connect();
  406. return gameDialog;
  407. }
  408. //-----------------------------------------------------------------------------
  409. // Purpose: joins a game by a specified IP, not attached to any game list
  410. //-----------------------------------------------------------------------------
  411. CDialogGameInfo *CServerBrowserDialog::JoinGame(int serverIP, int serverPort, const char *pszConnectCode)
  412. {
  413. // open the game info dialog, then mark it to attempt to connect right away
  414. CDialogGameInfo *gameDialog = OpenGameInfoDialog( serverIP, serverPort, serverPort, pszConnectCode );
  415. // set the dialog name to be the server name
  416. gameDialog->Connect();
  417. return gameDialog;
  418. }
  419. //-----------------------------------------------------------------------------
  420. // Purpose: opens a game info dialog from a game list
  421. //-----------------------------------------------------------------------------
  422. CDialogGameInfo *CServerBrowserDialog::OpenGameInfoDialog( IGameList *gameList, unsigned int serverIndex )
  423. {
  424. gameserveritem_t *pServer = gameList->GetServer( serverIndex );
  425. if ( !pServer )
  426. return NULL;
  427. CDialogGameInfo *gameDialog = new CDialogGameInfo( NULL, pServer->m_NetAdr.GetIP(), pServer->m_NetAdr.GetQueryPort(), pServer->m_NetAdr.GetConnectionPort(), gameList->GetConnectCode() );
  428. gameDialog->SetParent(GetVParent());
  429. gameDialog->AddActionSignalTarget(this);
  430. gameDialog->Run( pServer->GetName() );
  431. int i = m_GameInfoDialogs.AddToTail();
  432. m_GameInfoDialogs[i] = gameDialog;
  433. return gameDialog;
  434. }
  435. //-----------------------------------------------------------------------------
  436. // Purpose: opens a game info dialog by a specified IP, not attached to any game list
  437. //-----------------------------------------------------------------------------
  438. CDialogGameInfo *CServerBrowserDialog::OpenGameInfoDialog( int serverIP, uint16 connPort, uint16 queryPort, const char *pszConnectCode )
  439. {
  440. CDialogGameInfo *gameDialog = new CDialogGameInfo(NULL, serverIP, queryPort, connPort, pszConnectCode);
  441. gameDialog->AddActionSignalTarget(this);
  442. gameDialog->SetParent(GetVParent());
  443. gameDialog->Run("");
  444. int i = m_GameInfoDialogs.AddToTail();
  445. m_GameInfoDialogs[i] = gameDialog;
  446. return gameDialog;
  447. }
  448. //-----------------------------------------------------------------------------
  449. // Purpose: closes all the game info dialogs
  450. //-----------------------------------------------------------------------------
  451. void CServerBrowserDialog::CloseAllGameInfoDialogs()
  452. {
  453. for (int i = 0; i < m_GameInfoDialogs.Count(); i++)
  454. {
  455. vgui::Panel *dlg = m_GameInfoDialogs[i];
  456. if (dlg)
  457. {
  458. vgui::ivgui()->PostMessage(dlg->GetVPanel(), new KeyValues("Close"), NULL);
  459. }
  460. }
  461. }
  462. //-----------------------------------------------------------------------------
  463. // Purpose: finds a dialog
  464. //-----------------------------------------------------------------------------
  465. CDialogGameInfo *CServerBrowserDialog::GetDialogGameInfoForFriend( uint64 ulSteamIDFriend )
  466. {
  467. FOR_EACH_VEC( m_GameInfoDialogs, i )
  468. {
  469. CDialogGameInfo *pDlg = m_GameInfoDialogs[i];
  470. if ( pDlg && pDlg->GetAssociatedFriend() == ulSteamIDFriend )
  471. {
  472. return pDlg;
  473. }
  474. }
  475. return NULL;
  476. }
  477. //-----------------------------------------------------------------------------
  478. // Purpose: accessor to the filter save data
  479. //-----------------------------------------------------------------------------
  480. KeyValues *CServerBrowserDialog::GetFilterSaveData(const char *filterSet)
  481. {
  482. return m_pFilterData->FindKey(filterSet, true);
  483. }
  484. //-----------------------------------------------------------------------------
  485. // Purpose: gets the name of the mod directory we're restricted to accessing, NULL if none
  486. //-----------------------------------------------------------------------------
  487. const char *CServerBrowserDialog::GetActiveModName()
  488. {
  489. return m_szModDir[0] ? m_szModDir : NULL;
  490. }
  491. //-----------------------------------------------------------------------------
  492. // Purpose: gets the name of the mod directory we're restricted to accessing, NULL if none
  493. //-----------------------------------------------------------------------------
  494. const char *CServerBrowserDialog::GetActiveGameName()
  495. {
  496. return m_szGameName[0] ? m_szGameName : NULL;
  497. }
  498. //-----------------------------------------------------------------------------
  499. // Purpose: return the app id to limit game queries to, set by Source/HL1 engines (NOT by filter settings, that is per page)
  500. //-----------------------------------------------------------------------------
  501. CGameID &CServerBrowserDialog::GetActiveAppID()
  502. {
  503. // !TEST! Un comment this to force a particular AppID
  504. //m_iLimitAppID = CGameID( 440 );
  505. return m_iLimitAppID;
  506. }
  507. //-----------------------------------------------------------------------------
  508. // Purpose: receives a specified game is active, so no other game types can be displayed in server list
  509. //-----------------------------------------------------------------------------
  510. void CServerBrowserDialog::OnActiveGameName( KeyValues *pKV )
  511. {
  512. Q_strncpy(m_szModDir, pKV->GetString( "name" ), sizeof(m_szModDir));
  513. Q_strncpy(m_szGameName, pKV->GetString( "game" ), sizeof(m_szGameName));
  514. m_iLimitAppID = CGameID( pKV->GetUint64( "appid", 0 ) );
  515. // reload filter settings (since they are no forced to be game specific)
  516. ReloadFilterSettings();
  517. }
  518. //-----------------------------------------------------------------------------
  519. // Purpose: resets all pages filter settings
  520. //-----------------------------------------------------------------------------
  521. void CServerBrowserDialog::ReloadFilterSettings()
  522. {
  523. m_pInternetGames->LoadFilterSettings();
  524. m_pSpectateGames->LoadFilterSettings();
  525. m_pFavorites->LoadFilterSettings();
  526. m_pLanGames->LoadFilterSettings();
  527. m_pFriendsGames->LoadFilterSettings();
  528. m_pHistory->LoadFilterSettings();
  529. }
  530. //-----------------------------------------------------------------------------
  531. // Purpose: Adds server to the history, saves as currently connected server
  532. //-----------------------------------------------------------------------------
  533. void CServerBrowserDialog::OnConnectToGame( KeyValues *pMessageValues )
  534. {
  535. int ip = pMessageValues->GetInt( "ip" );
  536. int connectionPort = pMessageValues->GetInt( "connectionport" );
  537. int queryPort = pMessageValues->GetInt( "queryport" );
  538. if ( !ip || !queryPort )
  539. return;
  540. uint32 unIP = htonl( ip );
  541. memset( &m_CurrentConnection, 0, sizeof(gameserveritem_t) );
  542. m_CurrentConnection.m_NetAdr.SetIP( unIP );
  543. m_CurrentConnection.m_NetAdr.SetQueryPort( queryPort );
  544. m_CurrentConnection.m_NetAdr.SetConnectionPort( (unsigned short)connectionPort );
  545. if (m_pHistory && steamapicontext->SteamMatchmaking() )
  546. {
  547. steamapicontext->SteamMatchmaking()->AddFavoriteGame( 0, unIP, connectionPort, queryPort, k_unFavoriteFlagHistory, time( NULL ) );
  548. m_pHistory->SetRefreshOnReload();
  549. }
  550. // tell the game info dialogs, so they can cancel if we have connected
  551. // to a server they were auto-retrying
  552. for (int i = 0; i < m_GameInfoDialogs.Count(); i++)
  553. {
  554. vgui::Panel *dlg = m_GameInfoDialogs[i];
  555. if (dlg)
  556. {
  557. KeyValues *kv = new KeyValues("ConnectedToGame", "ip", unIP, "connectionport", connectionPort);
  558. kv->SetInt( "queryport", queryPort );
  559. vgui::ivgui()->PostMessage(dlg->GetVPanel(), kv, NULL);
  560. }
  561. }
  562. // forward to favorites
  563. m_pFavorites->OnConnectToGame();
  564. if ( m_pBlacklist )
  565. {
  566. m_pBlacklist->OnConnectToGame();
  567. }
  568. m_bCurrentlyConnected = true;
  569. // Now we want to track which tabs have the quick list button checked
  570. int iQuickListBitField = 0;
  571. if ( m_pFriendsGames && m_pFriendsGames->IsQuickListButtonChecked() )
  572. {
  573. iQuickListBitField |= ( 1 << 0 );
  574. }
  575. if ( m_pLanGames && m_pLanGames->IsQuickListButtonChecked() )
  576. {
  577. iQuickListBitField |= ( 1 << 1 );
  578. }
  579. if ( m_pSpectateGames && m_pSpectateGames->IsQuickListButtonChecked() )
  580. {
  581. iQuickListBitField |= ( 1 << 2 );
  582. }
  583. if ( m_pHistory && m_pHistory->IsQuickListButtonChecked() )
  584. {
  585. iQuickListBitField |= ( 1 << 3 );
  586. }
  587. if ( m_pFavorites && m_pFavorites->IsQuickListButtonChecked() )
  588. {
  589. iQuickListBitField |= ( 1 << 4 );
  590. }
  591. if ( m_pInternetGames && m_pInternetGames->IsQuickListButtonChecked() )
  592. {
  593. iQuickListBitField |= ( 1 << 5 );
  594. }
  595. // Set the value so that the client.dll can use it for gamestats
  596. sb_quick_list_bit_field.SetValue( iQuickListBitField );
  597. // TF2 wants to close this dialog when the player connects to a game
  598. if ( GameSupportsReplay() )
  599. {
  600. ConVarRef sb_close_browser_on_connect( "sb_close_browser_on_connect" );
  601. if ( sb_close_browser_on_connect.IsValid() )
  602. {
  603. if ( sb_close_browser_on_connect.GetBool() == true )
  604. {
  605. OnClose();
  606. }
  607. }
  608. }
  609. }
  610. //-----------------------------------------------------------------------------
  611. // Purpose: Clears currently connected server
  612. //-----------------------------------------------------------------------------
  613. void CServerBrowserDialog::OnDisconnectFromGame( void )
  614. {
  615. m_bCurrentlyConnected = false;
  616. memset( &m_CurrentConnection, 0, sizeof(gameserveritem_t) );
  617. // forward to favorites
  618. m_pFavorites->OnDisconnectFromGame();
  619. if ( m_pBlacklist )
  620. {
  621. m_pBlacklist->OnDisconnectFromGame();
  622. }
  623. }
  624. //-----------------------------------------------------------------------------
  625. // Purpose: Called when start start loading, so we can cease server browser activity
  626. //-----------------------------------------------------------------------------
  627. void CServerBrowserDialog::OnLoadingStarted( void )
  628. {
  629. m_pInternetGames->OnLoadingStarted();
  630. m_pSpectateGames->OnLoadingStarted();
  631. m_pFavorites->OnLoadingStarted();
  632. m_pLanGames->OnLoadingStarted();
  633. m_pFriendsGames->OnLoadingStarted();
  634. m_pHistory->OnLoadingStarted();
  635. }
  636. //-----------------------------------------------------------------------------
  637. // Purpose: Passes build mode activation down into the pages
  638. //-----------------------------------------------------------------------------
  639. void CServerBrowserDialog::ActivateBuildMode()
  640. {
  641. // no subpanel, no build mode
  642. EditablePanel *panel = dynamic_cast<EditablePanel *>(m_pTabPanel->GetActivePage());
  643. if (!panel)
  644. return;
  645. panel->ActivateBuildMode();
  646. }
  647. //-----------------------------------------------------------------------------
  648. // Purpose: gets the default position and size on the screen to appear the first time
  649. //-----------------------------------------------------------------------------
  650. bool CServerBrowserDialog::GetDefaultScreenPosition(int &x, int &y, int &wide, int &tall)
  651. {
  652. int wx, wy, ww, wt;
  653. surface()->GetWorkspaceBounds( wx, wy, ww, wt );
  654. x = wx + (int)(ww * 0.05);
  655. y = wy + (int)(wt * 0.4);
  656. wide = (int)(ww * 0.5);
  657. tall = (int)(wt * 0.55);
  658. return true;
  659. }
  660. void CServerBrowserDialog::OnKeyCodePressed( vgui::KeyCode code )
  661. {
  662. // Handle close here, CBasePanel parent doesn't support "DialogClosing" command
  663. ButtonCode_t nButtonCode = GetBaseButtonCode( code );
  664. if ( nButtonCode == KEY_XBUTTON_B || nButtonCode == STEAMCONTROLLER_B )
  665. {
  666. OnCommand( "Close" );
  667. return;
  668. }
  669. else if ( nButtonCode == KEY_XBUTTON_A || nButtonCode == STEAMCONTROLLER_A )
  670. {
  671. //OnOK( false );
  672. //return;
  673. }
  674. else if ( nButtonCode == KEY_XBUTTON_UP ||
  675. nButtonCode == KEY_XSTICK1_UP ||
  676. nButtonCode == KEY_XSTICK2_UP ||
  677. nButtonCode == STEAMCONTROLLER_DPAD_UP ||
  678. nButtonCode == KEY_UP ||
  679. nButtonCode == KEY_XBUTTON_DOWN ||
  680. nButtonCode == KEY_XSTICK1_DOWN ||
  681. nButtonCode == KEY_XSTICK2_DOWN ||
  682. nButtonCode == STEAMCONTROLLER_DPAD_DOWN ||
  683. nButtonCode == KEY_DOWN )
  684. {
  685. CBaseGamesPage *pGamesPage = dynamic_cast< CBaseGamesPage* >( m_pTabPanel->GetActivePage() );
  686. if ( pGamesPage )
  687. {
  688. ListPanel *pListPanel = dynamic_cast< ListPanel * >( pGamesPage->GetActiveList() );
  689. if ( pListPanel )
  690. {
  691. if ( pListPanel->GetSelectedItem( 0 ) == -1 )
  692. {
  693. pListPanel->SetSingleSelectedItem( pListPanel->GetItemIDFromRow( 0 ) );
  694. pListPanel->RequestFocus();
  695. return;
  696. }
  697. else if ( !pListPanel->HasFocus() )
  698. {
  699. pListPanel->RequestFocus();
  700. return;
  701. }
  702. }
  703. }
  704. }
  705. BaseClass::OnKeyCodePressed( code );
  706. }