Team Fortress 2 Source Code as on 22/4/2020
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.

130 lines
4.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Holds WarData
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef TFWARDATA_H
  8. #define TFWARDATA_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "gcsdk/protobufsharedobject.h"
  13. #include "tf_gcmessages.h"
  14. #if defined (CLIENT_DLL) || defined (GAME_DLL)
  15. #include "gc_clientsystem.h"
  16. #endif
  17. #ifdef GC
  18. #include "tf_gc.h"
  19. #endif
  20. //---------------------------------------------------------------------------------
  21. // Purpose: The shared object that contains a user's stats for a war
  22. //---------------------------------------------------------------------------------
  23. class CWarData : public GCSDK::CProtoBufSharedObject< CSOWarData, k_EEConTypeWarData >
  24. {
  25. public:
  26. CWarData();
  27. #ifdef GC
  28. DECLARE_CLASS_MEMPOOL( CWarData );
  29. CWarData( uint32 unAccountID, war_definition_index_t eWarID, war_side_t eSide );
  30. virtual bool BYieldingAddInsertToTransaction( GCSDK::CSQLAccess & sqlAccess );
  31. virtual bool BYieldingAddWriteToTransaction( GCSDK::CSQLAccess & sqlAccess, const CUtlVector< int > &fields );
  32. virtual bool BYieldingAddRemoveToTransaction( GCSDK::CSQLAccess & sqlAccess );
  33. void WriteToRecord( CSchWarData *pWarData ) const;
  34. void ReadFromRecord( const CSchWarData & warData );
  35. #endif // GC
  36. };
  37. #if defined( CLIENT_DLL ) || defined( GC )
  38. //---------------------------------------------------------------------------------
  39. // Purpose: Holds the global stats for a war
  40. //
  41. // On the GC, the global stats are tabulated at load-time from all current
  42. // SQL records and is then modified in-memory.
  43. //
  44. // On the client, the global stats are requested whenever they are queried
  45. // but we limit how often we request.
  46. //---------------------------------------------------------------------------------
  47. class CTFWarGlobalDataHelper
  48. {
  49. public:
  50. #ifdef CLIENT_DLL
  51. struct LeaderBoardEntries_t
  52. {
  53. LeaderBoardEntries_t() : m_bInitialized( false ) {}
  54. bool m_bInitialized;
  55. CUtlVector< LeaderboardEntry_t* > m_vecEntries;
  56. };
  57. #endif // CLIENT_DLL
  58. CTFWarGlobalDataHelper();
  59. void Init();
  60. bool BIsInitialized() const { return m_bInitialized; }
  61. void AddToSideScore( war_definition_index_t nWar, war_side_t nSide, uint32 nValue );
  62. uint64 GetGlobalSideScore( war_definition_index_t nWar, war_side_t nSide );
  63. CGCMsgGC_War_GlobalStatsResponse* FindOrCreateWarData( war_definition_index_t nWarDef, bool bCreateIfDoesntExist );
  64. CGCMsgGC_War_GlobalStatsResponse_SideScore* FindOrCreateWarDataSide( war_side_t nWarSide, war_definition_index_t nWarDef, bool bCreateIfDoesntExist );
  65. void SetGlobalStats( const CGCMsgGC_War_GlobalStatsResponse& newData );
  66. #ifdef CLIENT_DLL
  67. const LeaderBoardEntries_t& GetGlobalLeaderboardScores() const { return downloadedLeaderboardScoresGlobal; }
  68. const LeaderBoardEntries_t& GetFriendsLeaderboardScores() const { return downloadedLeaderboardScoresFriends; }
  69. #endif // CLIENT_DLL
  70. private:
  71. #ifdef CLIENT_DLL
  72. void RequestUpdateGlobalStats();
  73. void CheckGlobalStatsStaleness();
  74. // Leaderboard functions
  75. void RequestLeaderboard();
  76. void OnFindLeaderboard( LeaderboardFindResult_t *pResult, bool bIOFailure );
  77. void DownloadLeaderboard();
  78. void OnLeaderboardScoresDownloaded_Global( LeaderboardScoresDownloaded_t *pResult, bool bIOFailure );
  79. void OnLeaderboardScoresDownloaded_Friends( LeaderboardScoresDownloaded_t *pResult, bool bIOFailure );
  80. #endif // CLIENT_DLL
  81. bool m_bInitialized;
  82. typedef CUtlMap< war_definition_index_t, CGCMsgGC_War_GlobalStatsResponse > WarStatsMap_t;
  83. WarStatsMap_t m_mapWarStats;
  84. #ifdef CLIENT_DLL
  85. float m_flLastUpdateRequest;
  86. float m_flLastUpdated;
  87. LeaderboardFindResult_t m_findLeaderboardResults;
  88. CCallResult< CTFWarGlobalDataHelper, LeaderboardFindResult_t > m_findLeaderboardCallback;
  89. LeaderBoardEntries_t downloadedLeaderboardScoresGlobal;
  90. LeaderBoardEntries_t downloadedLeaderboardScoresFriends;
  91. CCallResult< CTFWarGlobalDataHelper, LeaderboardScoresDownloaded_t > downloadLeaderboardCallbackGlobal;
  92. CCallResult< CTFWarGlobalDataHelper, LeaderboardScoresDownloaded_t > downloadLeaderboardCallbackFriends;
  93. #endif // CLIENT_DLL
  94. };
  95. CTFWarGlobalDataHelper& GetWarData();
  96. #endif // CLIENT_DLL || GC
  97. CWarData* GetPlayerWarData( const CSteamID& steamID, war_definition_index_t warDefIndex, bool bLoadEvenIfWarInactive
  98. #ifdef GC_DLL
  99. , bool bLoadSOCacheIfNeeded
  100. #endif
  101. );
  102. #ifdef CLIENT_DLL
  103. CWarData* GetLocalPlayerWarData( war_definition_index_t warDefIndex );
  104. #endif
  105. #endif // TFWARDATA_H