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.

161 lines
4.2 KiB

  1. //===== Copyright � 1996-2009, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #ifndef MM_SESSION_ONLINE_SEARCH_H
  7. #define MM_SESSION_ONLINE_SEARCH_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. //
  12. // CMatchSessionOnlineSearch
  13. //
  14. // Implementation of an online session search (aka matchmaking)
  15. //
  16. class CMatchSearcher_OnlineSearch;
  17. class CMatchSessionOnlineSearch : public IMatchSessionInternal
  18. {
  19. // Methods of IMatchSession
  20. public:
  21. // Get an internal pointer to session system-specific data
  22. virtual KeyValues * GetSessionSystemData() { return NULL; }
  23. // Get an internal pointer to session settings
  24. virtual KeyValues * GetSessionSettings();
  25. // Update session settings, only changing keys and values need
  26. // to be passed and they will be updated
  27. virtual void UpdateSessionSettings( KeyValues *pSettings );
  28. virtual void UpdateTeamProperties( KeyValues *pTeamProperties );
  29. // Issue a session command
  30. virtual void Command( KeyValues *pCommand );
  31. virtual uint64 GetSessionID();
  32. // Run a frame update
  33. virtual void Update();
  34. // Destroy the session object
  35. virtual void Destroy();
  36. // Debug print a session object
  37. virtual void DebugPrint();
  38. // Check if another session is joinable
  39. virtual bool IsAnotherSessionJoinable( char const *pszAnotherSessionInfo ) { return true; }
  40. // Process event
  41. virtual void OnEvent( KeyValues *pEvent );
  42. enum Result
  43. {
  44. RESULT_UNDEFINED,
  45. RESULT_SUCCESS,
  46. RESULT_FAIL
  47. };
  48. Result GetResult() { return m_result; }
  49. public:
  50. explicit CMatchSessionOnlineSearch( KeyValues *pSettings );
  51. virtual ~CMatchSessionOnlineSearch();
  52. protected:
  53. CMatchSessionOnlineSearch(); // for derived classes construction
  54. //
  55. // Overrides when search is used as a nested object
  56. //
  57. protected:
  58. virtual CMatchSearcher *OnStartSearching();
  59. virtual void OnSearchCompletedEmpty( KeyValues *pSettings );
  60. virtual void OnSearchCompletedSuccess( CSysSessionClient *pSysSession, KeyValues *pSettings );
  61. virtual void OnSearchEvent( KeyValues *pNotify );
  62. virtual CSysSessionClient * OnBeginJoiningSearchResult();
  63. protected:
  64. void StartJoinNextFoundSession();
  65. void ValidateSearchResultWhitelist();
  66. void ConnectJoinLobbyNextFoundSession();
  67. void OnSearchDoneNoResultsMatch();
  68. protected:
  69. KeyValues *m_pSettings;
  70. KeyValues::AutoDelete m_autodelete_pSettings;
  71. friend class CMatchSearcher_OnlineSearch;
  72. CMatchSearcher *m_pMatchSearcher;
  73. Result m_result;
  74. enum State_t
  75. {
  76. STATE_INIT,
  77. STATE_SEARCHING,
  78. STATE_JOIN_NEXT,
  79. #if !defined( NO_STEAM )
  80. STATE_VALIDATING_WHITELIST,
  81. #endif
  82. STATE_JOINING,
  83. STATE_CLOSING,
  84. };
  85. State_t m_eState;
  86. CUtlVector< CMatchSearcher::SearchResult_t const * > m_arrSearchResults;
  87. CSysSessionClient *m_pSysSession;
  88. CSysSessionConTeamHost *m_pSysSessionConTeam;
  89. #if !defined( NO_STEAM )
  90. void SetupSteamRankingConfiguration();
  91. bool IsSteamRankingConfigured() const;
  92. class CServerListListener : public ISteamMatchmakingServerListResponse
  93. {
  94. public:
  95. explicit CServerListListener( CMatchSessionOnlineSearch *pDsSearcher, CUtlVector< MatchMakingKeyValuePair_t > &filters );
  96. void Destroy();
  97. public:
  98. // Server has responded ok with updated data
  99. virtual void ServerResponded( HServerListRequest hReq, int iServer ) { HandleServerResponse( hReq, iServer, true ); }
  100. // Server has failed to respond
  101. virtual void ServerFailedToRespond( HServerListRequest hReq, int iServer ) { HandleServerResponse( hReq, iServer, false ); }
  102. // A list refresh you had initiated is now 100% completed
  103. virtual void RefreshComplete( HServerListRequest hReq, EMatchMakingServerResponse response );
  104. protected:
  105. void HandleServerResponse( HServerListRequest hReq, int iServer, bool bResponded );
  106. CMatchSessionOnlineSearch *m_pOuter;
  107. HServerListRequest m_hRequest;
  108. };
  109. friend class CServerListListener;
  110. CServerListListener *m_pServerListListener;
  111. void Steam_OnDedicatedServerListFetched();
  112. #endif
  113. float m_flInitializeTimestamp;
  114. };
  115. class CMatchSearcher_OnlineSearch : public CMatchSearcher
  116. {
  117. public:
  118. CMatchSearcher_OnlineSearch( CMatchSessionOnlineSearch *pSession, KeyValues *pSettings );
  119. public:
  120. virtual void OnSearchEvent( KeyValues *pNotify );
  121. virtual void OnSearchDone();
  122. protected:
  123. CMatchSessionOnlineSearch *m_pSession;
  124. };
  125. #endif