summaryrefslogtreecommitdiff
path: root/game/shared/tf/tf_wardata.h
blob: bd78825d6b82a68d0db3b0e275c67c91df5d5703 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Holds WarData
//
// $NoKeywords: $
//=============================================================================//

#ifndef TFWARDATA_H
#define TFWARDATA_H
#ifdef _WIN32
#pragma once
#endif

#include "gcsdk/protobufsharedobject.h"
#include "tf_gcmessages.h"
#if defined (CLIENT_DLL) || defined (GAME_DLL)
	#include "gc_clientsystem.h"
#endif

#ifdef GC
	#include "tf_gc.h"
#endif

//---------------------------------------------------------------------------------
// Purpose: The shared object that contains a user's stats for a war	
//---------------------------------------------------------------------------------
class CWarData : public GCSDK::CProtoBufSharedObject< CSOWarData, k_EEConTypeWarData >
{
public:
	CWarData();
#ifdef GC
	DECLARE_CLASS_MEMPOOL( CWarData );
	CWarData( uint32 unAccountID, war_definition_index_t eWarID, war_side_t eSide );

	virtual bool BYieldingAddInsertToTransaction( GCSDK::CSQLAccess & sqlAccess );
	virtual bool BYieldingAddWriteToTransaction( GCSDK::CSQLAccess & sqlAccess, const CUtlVector< int > &fields );
	virtual bool BYieldingAddRemoveToTransaction( GCSDK::CSQLAccess & sqlAccess );

	void WriteToRecord( CSchWarData *pWarData ) const;
	void ReadFromRecord( const CSchWarData & warData );
#endif // GC
};


#if defined( CLIENT_DLL ) || defined( GC )
//---------------------------------------------------------------------------------
// Purpose: Holds the global stats for a war
//
//			On the GC, the global stats are tabulated at load-time from all current
//			SQL records and is then modified in-memory.  
//
//			On the client, the global stats are requested whenever they are queried
//			but we limit how often we request.
//---------------------------------------------------------------------------------
class CTFWarGlobalDataHelper
{
public:
#ifdef CLIENT_DLL
	struct LeaderBoardEntries_t
	{
		LeaderBoardEntries_t() : m_bInitialized( false ) {}

		bool m_bInitialized;
		CUtlVector< LeaderboardEntry_t* > m_vecEntries;
	};
#endif // CLIENT_DLL

	CTFWarGlobalDataHelper();
	void Init();
	bool BIsInitialized() const { return m_bInitialized; }

	void AddToSideScore( war_definition_index_t nWar, war_side_t nSide, uint32 nValue );
	uint64 GetGlobalSideScore( war_definition_index_t nWar, war_side_t nSide );

	CGCMsgGC_War_GlobalStatsResponse* FindOrCreateWarData( war_definition_index_t nWarDef, bool bCreateIfDoesntExist );
	CGCMsgGC_War_GlobalStatsResponse_SideScore* FindOrCreateWarDataSide( war_side_t nWarSide, war_definition_index_t nWarDef, bool bCreateIfDoesntExist );

	void SetGlobalStats( const CGCMsgGC_War_GlobalStatsResponse& newData );

#ifdef CLIENT_DLL
	const LeaderBoardEntries_t& GetGlobalLeaderboardScores() const { return downloadedLeaderboardScoresGlobal; }
	const LeaderBoardEntries_t& GetFriendsLeaderboardScores() const { return downloadedLeaderboardScoresFriends; }
#endif // CLIENT_DLL

private:

#ifdef CLIENT_DLL
	void RequestUpdateGlobalStats();
	void CheckGlobalStatsStaleness();

	// Leaderboard functions
	void RequestLeaderboard();
	void OnFindLeaderboard( LeaderboardFindResult_t *pResult, bool bIOFailure );
	void DownloadLeaderboard();
	void OnLeaderboardScoresDownloaded_Global( LeaderboardScoresDownloaded_t *pResult, bool bIOFailure );
	void OnLeaderboardScoresDownloaded_Friends( LeaderboardScoresDownloaded_t *pResult, bool bIOFailure );
#endif // CLIENT_DLL

	bool m_bInitialized;

	typedef CUtlMap< war_definition_index_t, CGCMsgGC_War_GlobalStatsResponse > WarStatsMap_t;
	WarStatsMap_t m_mapWarStats;

#ifdef CLIENT_DLL
	float m_flLastUpdateRequest;
	float m_flLastUpdated;
	LeaderboardFindResult_t m_findLeaderboardResults;

	CCallResult< CTFWarGlobalDataHelper, LeaderboardFindResult_t > m_findLeaderboardCallback;
	LeaderBoardEntries_t downloadedLeaderboardScoresGlobal;
	LeaderBoardEntries_t downloadedLeaderboardScoresFriends;

	CCallResult< CTFWarGlobalDataHelper, LeaderboardScoresDownloaded_t > downloadLeaderboardCallbackGlobal;
	CCallResult< CTFWarGlobalDataHelper, LeaderboardScoresDownloaded_t > downloadLeaderboardCallbackFriends;
#endif // CLIENT_DLL
};

CTFWarGlobalDataHelper& GetWarData();
#endif // CLIENT_DLL || GC

CWarData* GetPlayerWarData( const CSteamID& steamID, war_definition_index_t warDefIndex, bool bLoadEvenIfWarInactive 
#ifdef GC_DLL
	, bool bLoadSOCacheIfNeeded
#endif
	);
#ifdef CLIENT_DLL
CWarData* GetLocalPlayerWarData( war_definition_index_t warDefIndex );
#endif

#endif // TFWARDATA_H