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.

169 lines
3.8 KiB

  1. //========= Copyright � 1996-2009, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=====================================================================================//
  6. #ifndef _SERVERMANAGER_H_
  7. #define _SERVERMANAGER_H_
  8. #include "utlvector.h"
  9. #include "utlmap.h"
  10. class CServer :
  11. public IMatchServer
  12. {
  13. public:
  14. CServer();
  15. virtual ~CServer();
  16. //
  17. // IMatchServer implementation
  18. //
  19. public:
  20. //
  21. // GetOnlineId
  22. // returns server online id to store as reference
  23. //
  24. virtual XUID GetOnlineId();
  25. //
  26. // GetGameDetails
  27. // returns server game details
  28. //
  29. virtual KeyValues *GetGameDetails();
  30. //
  31. // IsJoinable and Join
  32. // returns whether server is joinable and initiates join to the server
  33. //
  34. virtual bool IsJoinable();
  35. virtual void Join();
  36. public:
  37. float m_flLastRefresh;
  38. XUID m_xuid;
  39. KeyValues *m_pGameDetails;
  40. #if !defined( NO_STEAM ) && !defined( SWDS )
  41. servernetadr_t m_netAdr;
  42. #endif
  43. };
  44. class CServerManager :
  45. public IServerManager,
  46. #if !defined( NO_STEAM ) && !defined( SWDS )
  47. public ISteamMatchmakingServerListResponse,
  48. #endif
  49. public IMatchEventsSink
  50. {
  51. public :
  52. CServerManager();
  53. virtual ~CServerManager();
  54. //
  55. // IServerManager implementation
  56. //
  57. public:
  58. //
  59. // EnableServersUpdate
  60. // controls whether server data is being updated in the background
  61. //
  62. virtual void EnableServersUpdate( bool bEnable );
  63. //
  64. // GetNumServers
  65. // returns number of servers discovered and for which data is available
  66. //
  67. virtual int GetNumServers();
  68. //
  69. // GetServerByIndex / GetServerByOnlineId
  70. // returns server interface to the given server or NULL if server not found or not available
  71. //
  72. virtual IMatchServer* GetServerByIndex( int iServerIdx );
  73. virtual IMatchServer* GetServerByOnlineId( XUID xuidServerOnline );
  74. // IMatchEventsSink
  75. public:
  76. virtual void OnEvent( KeyValues *pEvent );
  77. #if !defined( _X360 ) && !defined( NO_STEAM ) && !defined( SWDS )
  78. protected:
  79. HServerListRequest m_hRequest;
  80. public:
  81. // ISteamMatchmakingServerListResponse implementation
  82. virtual void ServerResponded( HServerListRequest hReq, int iServer );
  83. virtual void ServerFailedToRespond( HServerListRequest hReq, int iServer ) {}
  84. virtual void RefreshComplete( HServerListRequest hReq, EMatchMakingServerResponse response );
  85. #endif
  86. //
  87. // Interface for match system
  88. //
  89. public:
  90. void Update();
  91. protected:
  92. void MarkOldServersAndBeginSearch();
  93. void RemoveOldServers();
  94. void UpdateLanSearch();
  95. void OnGroupFetched();
  96. void OnAllGroupsFetched();
  97. void RequestPingingDetails();
  98. void UpdateRequestingDetails();
  99. void OnAllDataFetched();
  100. bool StartFetchingGroupServersData();
  101. bool FetchGroupServers();
  102. CServer * GetServerRecordByOnlineId( CUtlVector< CServer * > &arr, XUID xuidServerOnline );
  103. //
  104. // Internal data
  105. protected:
  106. bool m_bUpdateEnabled; // whether data should be auto-updated
  107. float m_flNextUpdateTime; // when next update cycle should occur
  108. float m_flNextServerUpdateTime;
  109. // list of servers
  110. CUtlVector< CServer * > m_Servers;
  111. CUtlVector< CServer * > m_ServersPinging;
  112. enum State
  113. {
  114. STATE_IDLE,
  115. STATE_LAN_SEARCH,
  116. STATE_GROUP_SEARCH,
  117. #if !defined( _X360 ) && !defined( NO_STEAM ) && !defined( SWDS )
  118. STATE_FETCHING_SERVERS,
  119. #endif
  120. STATE_GROUP_FETCHED,
  121. STATE_REQUESTING_DETAILS,
  122. };
  123. State m_eState;
  124. struct SLanSearchData_t
  125. {
  126. SLanSearchData_t() { memset( this, 0, sizeof( *this ) ); }
  127. float m_flStartTime;
  128. float m_flLastBroadcastTime;
  129. };
  130. SLanSearchData_t m_lanSearchData;
  131. struct SGroupSearchData_t
  132. {
  133. SGroupSearchData_t() : m_idxSearchGroupId( 0 ) {}
  134. void Reset() { m_idxSearchGroupId = 0; m_UserGroupAccountIDs.RemoveAll(); }
  135. int m_idxSearchGroupId;
  136. CUtlVector< uint32 > m_UserGroupAccountIDs; // list of user groups
  137. };
  138. SGroupSearchData_t m_groupSearchData;
  139. };
  140. extern class CServerManager *g_pServerManager;
  141. #endif // _SERVERMANAGER_H_