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.

179 lines
3.7 KiB

  1. //===== Copyright � 1996-2009, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #ifndef MATCH_SEARCHER_H
  7. #define MATCH_SEARCHER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #if !defined( NO_STEAM )
  12. #include "steam/steam_api.h"
  13. #endif // _X360
  14. //
  15. // CMatchSearcher
  16. //
  17. class CMatchSearcher
  18. #ifdef _X360
  19. : public IDormantOperation
  20. #endif
  21. #if !defined (NO_STEAM)
  22. : public IMatchAsyncOperationCallback
  23. #endif
  24. {
  25. public:
  26. explicit CMatchSearcher( KeyValues *pSettings );
  27. virtual ~CMatchSearcher();
  28. public:
  29. // Run a frame update
  30. virtual void Update();
  31. // Destroy the object
  32. virtual void Destroy();
  33. //
  34. // Overrides
  35. //
  36. public:
  37. // Obtain adjusted match search settings
  38. virtual KeyValues * GetSearchSettings();
  39. // Event broadcasting
  40. virtual void OnSearchEvent( KeyValues *pNotify );
  41. protected:
  42. #ifdef _X360
  43. public:
  44. struct SearchResult_t
  45. {
  46. inline XNKID GetXNKID() const { return m_info.sessionID; }
  47. KeyValues * GetGameDetails() const { return m_pGameDetails; }
  48. XSESSION_INFO m_info;
  49. KeyValues *m_pGameDetails;
  50. };
  51. protected:
  52. CUtlVector< XUSER_CONTEXT > m_arrContexts;
  53. CUtlVector< XUSER_PROPERTY > m_arrProperties;
  54. float m_flQosTimeout;
  55. XNQOS *m_pQosResults;
  56. CUtlBuffer m_bufSearchResultHeader;
  57. XSESSION_SEARCHRESULT_HEADER * GetXSearchResult() { return ( XSESSION_SEARCHRESULT_HEADER * ) m_bufSearchResultHeader.Base(); }
  58. XOVERLAPPED m_xOverlapped;
  59. CJob *m_pCancelOverlappedJob;
  60. void Live_OnSessionSearchCompleted();
  61. void Live_CheckSearchResultsQos();
  62. void Live_OnQosCheckCompleted();
  63. virtual bool UpdateDormantOperation();
  64. #elif !defined( NO_STEAM )
  65. public:
  66. struct SearchResult_t
  67. {
  68. inline XNKID GetXNKID() const { return ( const XNKID & ) m_uiLobbyId; }
  69. KeyValues * GetGameDetails() const;
  70. uint64 m_uiLobbyId;
  71. mutable KeyValues *m_pGameDetails;
  72. netadr_t m_svAdr;
  73. int m_svPing;
  74. int m_numPlayers;
  75. IMatchAsyncOperation *m_pAsyncOperationPingWeakRef;
  76. };
  77. protected:
  78. CCallResult< CMatchSearcher, LobbyMatchList_t > m_CallbackOnLobbyMatchListReceived;
  79. void Steam_OnLobbyMatchListReceived( LobbyMatchList_t *p, bool bError );
  80. #else
  81. public:
  82. struct SearchResult_t
  83. {
  84. inline XNKID GetXNKID() const { return ( const XNKID & ) m_uiLobbyId; }
  85. KeyValues * GetGameDetails() const { return m_pGameDetails; }
  86. uint64 m_uiLobbyId;
  87. KeyValues *m_pGameDetails;
  88. };
  89. #endif
  90. protected:
  91. KeyValues *m_pSettings;
  92. KeyValues::AutoDelete m_autodelete_pSettings;
  93. KeyValues *m_pSessionSearchTree;
  94. KeyValues::AutoDelete m_autodelete_pSessionSearchTree;
  95. KeyValues *m_pSearchPass;
  96. #if !defined( NO_STEAM )
  97. uint32 m_uiQosTimeoutStartMS;
  98. uint32 m_uiQosPingLastMS;
  99. CUtlVector< IMatchAsyncOperation * > m_arrOutstandingAsyncOperation;
  100. STEAM_CALLBACK_MANUAL( CMatchSearcher, Steam_OnLobbyDataReceived, LobbyDataUpdate_t, m_CallbackOnLobbyDataReceived );
  101. // Callback for server reservation check
  102. virtual void OnOperationFinished( IMatchAsyncOperation *pOperation );
  103. #endif
  104. enum State_t
  105. {
  106. STATE_INIT,
  107. STATE_SEARCHING,
  108. #ifdef _X360
  109. STATE_CHECK_QOS,
  110. #endif
  111. #if !defined( NO_STEAM )
  112. STATE_WAITING_LOBBY_DATA_AND_PING,
  113. #endif
  114. STATE_DONE
  115. };
  116. State_t m_eState;
  117. CUtlVector< SearchResult_t > m_arrSearchResults;
  118. CUtlVector< SearchResult_t > m_arrSearchResultsAggregate;
  119. protected:
  120. void InitializeSettings();
  121. void StartSearch();
  122. virtual void StartSearchPass( KeyValues *pSearchPass );
  123. void AggregateSearchPassResults();
  124. virtual void OnSearchPassDone( KeyValues *pSearchPass );
  125. virtual void OnSearchDone();
  126. //
  127. // Results retrieval overrides
  128. //
  129. public:
  130. virtual bool IsSearchFinished() const;
  131. virtual int GetNumSearchResults() const;
  132. virtual SearchResult_t const & GetSearchResult( int idx ) const;
  133. };
  134. #endif // MATCH_SEARCHER_H