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.

126 lines
3.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #ifndef DIALOGGAMEINFO_H
  8. #define DIALOGGAMEINFO_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. struct challenge_s
  13. {
  14. netadr_t addr;
  15. int challenge;
  16. };
  17. //-----------------------------------------------------------------------------
  18. // Purpose: Dialog for displaying information about a game server
  19. //-----------------------------------------------------------------------------
  20. class CDialogGameInfo : public vgui::Frame, public ISteamMatchmakingPlayersResponse, public ISteamMatchmakingPingResponse
  21. {
  22. DECLARE_CLASS_SIMPLE( CDialogGameInfo, vgui::Frame );
  23. public:
  24. CDialogGameInfo(vgui::Panel *parent, int serverIP, int queryPort, unsigned short connectionPort, const char *pszConnectCode );
  25. ~CDialogGameInfo();
  26. void Run(const char *titleName);
  27. void ChangeGame(int serverIP, int queryPort, unsigned short connectionPort);
  28. void SetFriend( uint64 ulSteamIDFriend );
  29. uint64 GetAssociatedFriend();
  30. // forces the dialog to attempt to connect to the server
  31. void Connect();
  32. // implementation of IServerRefreshResponse interface
  33. // called when the server has successfully responded
  34. virtual void ServerResponded( gameserveritem_t &server );
  35. // called when a server response has timed out
  36. virtual void ServerFailedToRespond();
  37. // on individual player added
  38. virtual void AddPlayerToList(const char *playerName, int score, float timePlayedSeconds);
  39. virtual void PlayersFailedToRespond() {}
  40. virtual void PlayersRefreshComplete() { m_hPlayersQuery = HSERVERQUERY_INVALID; }
  41. // called when the current refresh list is complete
  42. virtual void RefreshComplete( EMatchMakingServerResponse response );
  43. // player list received
  44. virtual void ClearPlayerList();
  45. //virtual void SendChallengeQuery( const netadr_t & to );
  46. virtual void SendPlayerQuery( uint32 unIP, uint16 usQueryPort );
  47. //virtual void InsertChallengeResponse( const netadr_t & to, int nChallenge );
  48. protected:
  49. // message handlers
  50. MESSAGE_FUNC( OnConnect, "Connect" );
  51. MESSAGE_FUNC( OnRefresh, "Refresh" );
  52. MESSAGE_FUNC_PTR( OnButtonToggled, "ButtonToggled", panel );
  53. MESSAGE_FUNC_PTR( OnRadioButtonChecked, "RadioButtonChecked", panel )
  54. {
  55. OnButtonToggled( panel );
  56. }
  57. // response from the get password dialog
  58. MESSAGE_FUNC_CHARPTR( OnJoinServerWithPassword, "JoinServerWithPassword", password );
  59. MESSAGE_FUNC_INT_INT( OnConnectToGame, "ConnectedToGame", ip, port );
  60. // vgui overrides
  61. virtual void OnTick();
  62. virtual void PerformLayout();
  63. virtual void OnKeyCodePressed( vgui::KeyCode code );
  64. private:
  65. STEAM_CALLBACK( CDialogGameInfo, OnPersonaStateChange, PersonaStateChange_t, m_CallbackPersonaStateChange );
  66. long m_iRequestRetry; // time at which to retry the request
  67. static int PlayerTimeColumnSortFunc(vgui::ListPanel *pPanel, const vgui::ListPanelItem &p1, const vgui::ListPanelItem &p2);
  68. // methods
  69. void RequestInfo();
  70. void ConnectToServer();
  71. void ShowAutoRetryOptions(bool state);
  72. void ConstructConnectArgs( char *pchOptions, int cchOptions, const gameserveritem_t &server );
  73. void ApplyConnectCommand( const gameserveritem_t &server );
  74. vgui::Button *m_pConnectButton;
  75. vgui::Button *m_pCloseButton;
  76. vgui::Button *m_pRefreshButton;
  77. vgui::Label *m_pInfoLabel;
  78. vgui::ToggleButton *m_pAutoRetry;
  79. vgui::RadioButton *m_pAutoRetryAlert;
  80. vgui::RadioButton *m_pAutoRetryJoin;
  81. vgui::ListPanel *m_pPlayerList;
  82. enum { PING_TIMES_MAX = 4 };
  83. // true if we should try connect to the server when it refreshes
  84. bool m_bConnecting;
  85. // password, if entered
  86. char m_szPassword[64];
  87. // state
  88. bool m_bServerNotResponding;
  89. bool m_bServerFull;
  90. bool m_bShowAutoRetryToggle;
  91. bool m_bShowingExtendedOptions;
  92. uint64 m_SteamIDFriend;
  93. CUtlString m_sConnectCode;
  94. gameserveritem_t m_Server;
  95. HServerQuery m_hPingQuery;
  96. HServerQuery m_hPlayersQuery;
  97. bool m_bPlayerListUpdatePending;
  98. };
  99. #endif // DIALOGGAMEINFO_H