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.

306 lines
7.7 KiB

  1. //========= Copyright � 1996-2009, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=====================================================================================//
  6. #ifndef _PLAYER_H_
  7. #define _PLAYER_H_
  8. class PlayerFriend;
  9. class PlayerLocal;
  10. #include "mm_framework.h"
  11. #include "matchmaking/iplayer.h"
  12. #include "matchmaking/cstrike15/imatchext_cstrike15.h"
  13. #include "playerrankingdata.h"
  14. #include "mathlib/expressioncalculator.h"
  15. //Players can be created several ways
  16. // -They are the local player and this is a reference to themselves
  17. // -They are created by the friends enumerator
  18. // -They are part of a party that a player joins
  19. // -They are part of a game that a player joins.
  20. template < typename TBaseInterface >
  21. class Player : public TBaseInterface
  22. {
  23. protected:
  24. Player() : m_xuid( 0 ), m_iController( XUSER_INDEX_NONE ), m_eOnlineState( IPlayer::STATE_OFFLINE )
  25. {
  26. memset( m_szName, 0, sizeof( m_szName ) );
  27. strcpy(m_szName, "EMPTY");
  28. }
  29. virtual ~Player() {}
  30. public:
  31. // Updates connection info if needed.
  32. virtual void Update() = 0;
  33. // Deletes the player class instance
  34. virtual void Destroy() = 0;
  35. //
  36. // IPlayer implementation
  37. //
  38. public:
  39. virtual XUID GetXUID() { return m_xuid; }
  40. virtual int GetPlayerIndex() { return m_iController; }
  41. virtual const char * GetName() { return m_szName; }
  42. virtual IPlayer::OnlineState_t GetOnlineState() { return m_eOnlineState; }
  43. protected:
  44. XUID m_xuid;
  45. int m_iController;
  46. IPlayer::OnlineState_t m_eOnlineState;
  47. char m_szName[MAX_PLAYER_NAME_LENGTH];
  48. };
  49. class PlayerFriend : public Player< IPlayerFriend >
  50. {
  51. public:
  52. struct FriendInfo_t
  53. {
  54. char const *m_szName;
  55. wchar_t const *m_wszRichPresence;
  56. XNKID m_xSessionID;
  57. uint64 m_uiTitleID;
  58. uint32 m_uiGameServerIP;
  59. KeyValues *m_pGameDetails;
  60. };
  61. public:
  62. explicit PlayerFriend( XUID xuid, FriendInfo_t const *pFriendInfo = NULL );
  63. //
  64. // IPlayerFriend implementation
  65. //
  66. public:
  67. virtual wchar_t const * GetRichPresence();
  68. virtual KeyValues *GetGameDetails();
  69. virtual KeyValues *GetPublishedPresence();
  70. virtual bool IsJoinable();
  71. virtual void Join();
  72. virtual uint64 GetTitleID();
  73. virtual uint32 GetGameServerIP();
  74. //
  75. // Player<IPlayerFriend> implementation
  76. //
  77. public:
  78. virtual void Update();
  79. virtual void Destroy();
  80. public:
  81. void SetFriendMark( unsigned maskSetting );
  82. unsigned GetFriendMark( );
  83. void SetIsStale( bool bStale );
  84. bool GetIsStale();
  85. void UpdateFriendInfo( FriendInfo_t const *pFriendInfo );
  86. bool IsUpdatingInfo();
  87. public:
  88. void StartSearchForSessionInfo();
  89. void StartSearchForSessionInfoImpl();
  90. void AbortSearch();
  91. protected:
  92. unsigned m_uFriendMark;
  93. bool m_bIsStale;
  94. wchar_t m_wszRichPresence[MAX_RICHPRESENCE_SIZE];
  95. uint64 m_uiTitleID;
  96. uint32 m_uiGameServerIP;
  97. XNKID m_xSessionID;
  98. XSESSION_INFO m_GameSessionInfo;
  99. KeyValues *m_pDetails;
  100. KeyValues *m_pPublishedPresence;
  101. enum SearchState_t
  102. {
  103. SEARCH_NONE,
  104. SEARCH_QUEUED,
  105. #ifdef _X360
  106. SEARCH_XNKID,
  107. SEARCH_QOS,
  108. #elif !defined( NO_STEAM )
  109. SEARCH_WAIT_LOBBY_DATA,
  110. #endif
  111. SEARCH_COMPLETED
  112. };
  113. SearchState_t m_eSearchState;
  114. #ifdef _X360
  115. XSESSION_INFO m_xsiSearchState;
  116. XNADDR const *m_pQOS_xnaddr;
  117. XNKID const *m_pQOS_xnkid;
  118. XNKEY const *m_pQOS_xnkey;
  119. XNQOS *m_XNQOS;
  120. XOVERLAPPED m_SessionSearchOverlapped;
  121. CUtlBuffer m_bufSessionSearchResults;
  122. XSESSION_SEARCHRESULT_HEADER * GetXSearchResults() { return ( XSESSION_SEARCHRESULT_HEADER * ) m_bufSessionSearchResults.Base(); }
  123. void Live_Update_SearchXNKID();
  124. void Live_Update_Search_QOS();
  125. #elif !defined( NO_STEAM )
  126. STEAM_CALLBACK_MANUAL( PlayerFriend, Steam_OnLobbyDataUpdate, LobbyDataUpdate_t, m_CallbackOnLobbyDataUpdate );
  127. #endif
  128. };
  129. class PlayerLocal : public Player< IPlayerLocal >
  130. {
  131. public:
  132. explicit PlayerLocal( int iController );
  133. ~PlayerLocal();
  134. public:
  135. void RecomputeXUID( char const *szNetwork );
  136. void DetectOnlineState();
  137. //
  138. // IPlayerLocal implementation
  139. //
  140. public:
  141. virtual const UserProfileData& GetPlayerProfileData();
  142. virtual MatchmakingData * GetPlayerMatchmakingData( void );
  143. virtual void UpdatePlayerMatchmakingData( int mmDataType );
  144. virtual void ResetPlayerMatchmakingData( int mmDataScope );
  145. virtual const void * GetPlayerTitleData( int iTitleDataIndex );
  146. virtual void UpdatePlayerTitleData( TitleDataFieldsDescription_t const *fdKey, const void *pvNewTitleData, int numNewBytes );
  147. virtual void GetLeaderboardData( KeyValues *pLeaderboardInfo );
  148. virtual void UpdateLeaderboardData( KeyValues *pLeaderboardInfo );
  149. virtual void GetAwardsData( KeyValues *pAwardsData );
  150. virtual void UpdateAwardsData( KeyValues *pAwardsData );
  151. virtual void SetNeedsSave( void );
  152. #if defined ( _X360 )
  153. virtual bool IsTitleDataValid() { return m_bIsTitleDataValid; };
  154. virtual bool IsTitleDataBlockValid( int blockId );
  155. virtual void SetIsTitleDataValid( bool isValid ) { m_bIsTitleDataValid = isValid; }
  156. virtual bool IsFreshPlayerProfile( void ) { return m_bIsFreshPlayerProfile; }
  157. virtual void ClearBufTitleData( void );
  158. #endif
  159. //
  160. // Player<IPlayerLocal> implementation
  161. //
  162. public:
  163. virtual void Update();
  164. virtual void Destroy();
  165. public:
  166. XUSER_SIGNIN_STATE GetAssumedSigninState();
  167. void LoadPlayerProfileData();
  168. void LoadTitleData();
  169. void SetTitleDataWriteTime( float flTime );
  170. void WriteTitleData();
  171. bool IsTitleDataStorageConnected( void );
  172. void OnLeaderboardRequestFinished( KeyValues *pLeaderboardData );
  173. void SetFlag_AwaitingTitleData() { m_uiPlayerFlags |= PLAYER_INVITE_AWAITING_TITLEDATA; }
  174. #if defined ( _X360 )
  175. bool m_bIsTitleDataValid;
  176. bool m_bIsFreshPlayerProfile;
  177. #endif
  178. protected:
  179. //stats
  180. XUSER_SIGNIN_STATE m_eLoadedTitleData;
  181. float m_flLastSave;
  182. enum Flags_t
  183. {
  184. PLAYER_INVITE_AWAITING_TITLEDATA = ( 1 << 0 )
  185. };
  186. uint32 m_uiPlayerFlags;
  187. enum Consts_t
  188. {
  189. TITLE_DATA_COUNT_X360 = 3, // number of Xbox LIVE - backed title data buffers
  190. TITLE_DATA_COUNT = 3, // number of valid title data buffers
  191. };
  192. UserProfileData m_ProfileData;
  193. MatchmakingData m_MatchmakingData;
  194. CUtlVector<int> m_arrAchievementsEarned, m_arrAvatarAwardsEarned;
  195. char m_bufTitleData[TITLE_DATA_COUNT][XPROFILE_SETTING_MAX_SIZE];
  196. bool m_bSaveTitleData[TITLE_DATA_COUNT];
  197. #if defined ( _X360 )
  198. bool m_bIsTitleDataBlockValid[TITLE_DATA_COUNT];
  199. #endif
  200. KeyValues *m_pLeaderboardData;
  201. KeyValues::AutoDelete m_autodelete_pLeaderboardData;
  202. #ifdef _X360
  203. struct XPendingAsyncAward_t
  204. {
  205. float m_flStartTimestamp;
  206. XOVERLAPPED m_xOverlapped;
  207. PlayerLocal *m_pLocalPlayer;
  208. enum Type_t
  209. {
  210. TYPE_ACHIEVEMENT,
  211. TYPE_AVATAR_AWARD
  212. };
  213. Type_t m_eType;
  214. union
  215. {
  216. TitleAchievementsDescription_t const *m_pAchievementDesc;
  217. TitleAvatarAwardsDescription_t const *m_pAvatarAwardDesc;
  218. };
  219. union
  220. {
  221. XUSER_ACHIEVEMENT m_xAchievement;
  222. XUSER_AVATARASSET m_xAvatarAsset;
  223. };
  224. };
  225. static CUtlVector< XPendingAsyncAward_t * > s_arrPendingAsyncAwards;
  226. void UpdatePendingAwardsState();
  227. #elif !defined( NO_STEAM )
  228. void UpdatePlayersSteamLogon();
  229. STEAM_CALLBACK_MANUAL( PlayerLocal, Steam_OnUserStatsReceived, UserStatsReceived_t, m_CallbackOnUserStatsReceived );
  230. STEAM_CALLBACK_MANUAL( PlayerLocal, Steam_OnPersonaStateChange, PersonaStateChange_t, m_CallbackOnPersonaStateChange );
  231. STEAM_CALLBACK_MANUAL( PlayerLocal, Steam_OnServersConnected, SteamServersConnected_t, m_CallbackOnServersConnected );
  232. STEAM_CALLBACK_MANUAL( PlayerLocal, Steam_OnServersDisconnected, SteamServersDisconnected_t, m_CallbackOnServersDisconnected );
  233. #endif
  234. void EvaluateAwardsStateBasedOnStats();
  235. void LoadGuestsTitleData();
  236. void OnProfileTitleDataLoaded( int iErrorCode );
  237. protected:
  238. };
  239. //
  240. // Players XWrite opportunities
  241. //
  242. // XWrite opportunities
  243. enum MM_XWriteOpportunity
  244. {
  245. MMXWO_NONE = 0,
  246. MMXWO_SETTINGS,
  247. MMXWO_SESSION_STARTED,
  248. MMXWO_CHECKPOINT,
  249. MMXWO_SESSION_FINISHED
  250. };
  251. void SignalXWriteOpportunity( MM_XWriteOpportunity eXWO );
  252. #endif