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.

166 lines
4.0 KiB

  1. //===== Copyright � 1996-2009, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #ifndef DS_SEARCHER_H
  7. #define DS_SEARCHER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. class CDsSearcher;
  12. #include "mm_framework.h"
  13. class CDsSearcher : public IMatchAsyncOperationCallback, IMatchEventsSink
  14. {
  15. public:
  16. explicit CDsSearcher( KeyValues *pSettings, uint64 uiReserveCookie, IMatchSession *pMatchSession, uint64 ullCrypt = 0ull );
  17. virtual ~CDsSearcher();
  18. // IMatchEventsSink
  19. public:
  20. virtual void OnEvent( KeyValues *pEvent );
  21. public:
  22. virtual void Update();
  23. virtual void Destroy();
  24. virtual bool IsFinished();
  25. struct DsResult_t
  26. {
  27. bool m_bAborted;
  28. bool m_bDedicated;
  29. char m_szConnectionString[256];
  30. #ifdef _X360
  31. char m_szInsecureSendableServerAddress[256];
  32. #elif !defined( NO_STEAM )
  33. char m_szPublicConnectionString[256];
  34. char m_szPrivateConnectionString[256];
  35. #endif
  36. void CopyToServerKey( KeyValues *pKvServer, uint64 ullCrypt = 0ull ) const;
  37. };
  38. virtual DsResult_t const& GetResult();
  39. protected:
  40. void InitDedicatedSearch();
  41. void InitWithKnownServer();
  42. void ReserveNextServer();
  43. virtual void OnOperationFinished( IMatchAsyncOperation *pOperation );
  44. float m_flTimeout;
  45. IMatchAsyncOperation *m_pAsyncOperation;
  46. protected:
  47. #ifdef _X360
  48. CXlspTitleServers *m_pTitleServers;
  49. void Xlsp_EnumerateDcs();
  50. void Xlsp_OnEnumerateDcsCompleted();
  51. CUtlVector< CXlspDatacenter > m_arrDatacenters;
  52. char m_chDatacenterQuery[ MAX_PATH ];
  53. void Xlsp_PrepareDatacenterQuery();
  54. void Xlsp_StartNextDc();
  55. CXlspDatacenter m_dc;
  56. void Xlsp_OnDcServerBatch( void const *pData, int numBytes );
  57. CUtlVector< uint16 > m_arrServerPorts;
  58. #elif !defined( NO_STEAM )
  59. int m_nSearchPass;
  60. void Steam_SearchPass();
  61. class CServerListListener : public ISteamMatchmakingServerListResponse
  62. {
  63. public:
  64. explicit CServerListListener( CDsSearcher *pDsSearcher, CUtlVector< MatchMakingKeyValuePair_t > &filters );
  65. void Destroy();
  66. public:
  67. // Server has responded ok with updated data
  68. virtual void ServerResponded( HServerListRequest hReq, int iServer );
  69. // Server has failed to respond
  70. virtual void ServerFailedToRespond( HServerListRequest hReq, int iServer )
  71. {
  72. gameserveritem_t *pServer = steamapicontext->SteamMatchmakingServers()
  73. ->GetServerDetails( hReq, iServer );
  74. DevMsg( " server failed to respond '%s'\n",
  75. pServer->m_NetAdr.GetConnectionAddressString() );
  76. }
  77. // A list refresh you had initiated is now 100% completed
  78. virtual void RefreshComplete( HServerListRequest hReq, EMatchMakingServerResponse response );
  79. protected:
  80. CDsSearcher *m_pOuter;
  81. HServerListRequest m_hRequest;
  82. };
  83. friend class CServerListListener;
  84. CServerListListener *m_pServerListListener;
  85. struct DsServer_t
  86. {
  87. DsServer_t( char const *szConnectionString, char const *szPrivateConnectionString, int nPing ) : m_nPing( nPing )
  88. {
  89. Q_strncpy( m_szConnectionString, szConnectionString, ARRAYSIZE( m_szConnectionString ) );
  90. Q_strncpy( m_szPrivateConnectionString, szPrivateConnectionString, ARRAYSIZE( m_szPrivateConnectionString ) );
  91. }
  92. char m_szConnectionString[256];
  93. char m_szPrivateConnectionString[256];
  94. int m_nPing;
  95. };
  96. CUtlVector< DsServer_t > m_arrServerList;
  97. void Steam_OnDedicatedServerListFetched();
  98. #endif
  99. protected:
  100. IMatchSession *m_pMatchSession;
  101. KeyValues *m_pSettings;
  102. uint64 m_uiReserveCookie;
  103. KeyValues *m_pReserveSettings;
  104. KeyValues::AutoDelete m_autodelete_pReserveSettings;
  105. enum State_t
  106. {
  107. STATE_INIT,
  108. STATE_WAITING,
  109. #ifdef _X360
  110. STATE_XLSP_ENUMERATE_DCS,
  111. STATE_XLSP_NEXT_DC,
  112. STATE_XLSP_REQUESTING_SERVERS,
  113. #elif !defined( NO_STEAM )
  114. STATE_STEAM_REQUESTING_SERVERS,
  115. STATE_STEAM_NEXT_SEARCH_PASS,
  116. #endif
  117. STATE_RESERVING,
  118. STATE_FINISHED,
  119. };
  120. State_t m_eState;
  121. DsResult_t m_Result;
  122. // If we are loadtesting, do a 2-pass search
  123. // 1st pass, look for empty ds with sv_load_test = 1
  124. // 2 pass, don't include sv_load_test flag in search
  125. bool m_bLoadTest;
  126. uint64 m_ullCrypt;
  127. };
  128. #endif