Counter Strike : Global Offensive Source Code
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.

838 lines
25 KiB

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