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.

344 lines
9.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef C_TF_GAMESTATS_H
  7. #define C_TF_GAMESTATS_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "gamestats.h"
  12. #include "tf_gamestats_shared.h"
  13. #include "GameEventListener.h"
  14. #include "c_tf_player.h"
  15. #include "econ_store.h"
  16. #include "store/store_panel.h"
  17. class CTFPlayer;
  18. struct TF_Gamestats_ClientSession_t
  19. {
  20. public:
  21. TF_Gamestats_ClientSession_t();
  22. private:
  23. TF_Gamestats_ClientSession_t( const TF_Gamestats_ClientSession_t &stats ) {}
  24. public:
  25. void Reset();
  26. struct SessionSummary_t
  27. {
  28. int iClassesPlayed;
  29. int iMapsPlayed;
  30. int iRoundsPlayed;
  31. int iFavoriteClass;
  32. int iFavoriteWeapon;
  33. char szFavoriteMap[64];
  34. int iKills;
  35. int iDeaths;
  36. int iSuicides;
  37. int iAssists;
  38. int iBuildingsBuilt;
  39. int iBuildingsUpgraded;
  40. int iBuildingsDestroyed;
  41. int iHeadshots;
  42. int iDominations;
  43. int iRevenges;
  44. int iInvulns;
  45. int iTeleports;
  46. int iDamageDone;
  47. int iHealingDone;
  48. int iCrits;
  49. int iBackstabs;
  50. int iAchievementsEarned;
  51. };
  52. SessionSummary_t m_Summary;
  53. RTime32 m_SessionStart;
  54. RTime32 m_FirstConnect;
  55. int m_iMapsPlayed;
  56. int m_iRoundsPlayed;
  57. CBitVecT< CFixedBitVecBase<32> > m_ClassesPlayed;
  58. };
  59. struct TF_Gamestats_WeaponInfo_t
  60. {
  61. TF_Gamestats_WeaponInfo_t();
  62. int weaponID;
  63. int critsFired;
  64. int shotsFired;
  65. int shotsHit;
  66. int shotsMissed;
  67. int avgDamage;
  68. int totalDamage;
  69. int critHits;
  70. float lastUpdateTime;
  71. };
  72. struct TF_Gamestats_AchievementEvent_t
  73. {
  74. TF_Gamestats_AchievementEvent_t( int in_achievementNum, const char* in_achievementID );
  75. int eventTime;
  76. int achievementNum;
  77. const char* achievementID;
  78. };
  79. // Item event baseclass.
  80. class TF_Gamestats_ItemEvent
  81. {
  82. public:
  83. TF_Gamestats_ItemEvent( int in_eventNum, CEconItemView* in_item );
  84. int eventNum;
  85. int eventTime;
  86. const char* eventID;
  87. item_definition_index_t itemDefIndex;
  88. itemid_t itemID;
  89. const char* itemName;
  90. char itemNameBuf[512];
  91. bool bUseNameBuf;
  92. const char* GetItemName()
  93. {
  94. if ( bUseNameBuf )
  95. return itemNameBuf;
  96. else
  97. return itemName;
  98. }
  99. };
  100. // Mann Co Catalog Usage Tracking
  101. class TF_Gamestats_CatalogEvent : public TF_Gamestats_ItemEvent
  102. {
  103. public:
  104. TF_Gamestats_CatalogEvent( int in_eventNum, CEconItemView* in_item, const char* in_filter );
  105. const char* catalogFilter;
  106. };
  107. // Crafting System Usage Tracking
  108. class TF_Gamestats_CraftingEvent : public TF_Gamestats_ItemEvent
  109. {
  110. public:
  111. TF_Gamestats_CraftingEvent( int in_eventNum, CEconItemView* in_item, int in_numAttempts, int in_recipe );
  112. int numAttempts;
  113. int recipeFound;
  114. };
  115. // Store Usage Tracking
  116. class TF_Gamestats_StoreEvent : public TF_Gamestats_ItemEvent
  117. {
  118. public:
  119. TF_Gamestats_StoreEvent( int in_eventNum, CEconItemView* in_item,
  120. const char* in_panelName, int in_classId, const cart_item_t* in_cartItem,
  121. int in_checkoutAttempts, const char* in_storeError, int in_totalPrice, int in_currencyCode );
  122. int classId;
  123. int cartQuantity;
  124. int cartItemCost;
  125. int currencyCode;
  126. int checkoutAttempt;
  127. const char* storeError;
  128. const char* panelName;
  129. };
  130. // General client-subjective item transaction tracking.
  131. class TF_Gamestats_ItemTransactionEvent : public TF_Gamestats_ItemEvent
  132. {
  133. public:
  134. TF_Gamestats_ItemTransactionEvent( int in_eventNum, CEconItemView* in_item, const char* in_reason, int in_quality );
  135. const char* reason;
  136. int itemQuality;
  137. };
  138. // Trade Usage Tracking
  139. class TF_Gamestats_TradeEvent : public TF_Gamestats_ItemEvent
  140. {
  141. public:
  142. TF_Gamestats_TradeEvent( int eventID, CEconItemView* item, bool localPlayerIsPartyA,
  143. uint64 steamIDPartyA, uint64 steamIDPartyB, int iTradeRequests, int iTradeAttempts );
  144. TF_Gamestats_TradeEvent( int eventID, uint64 steamIDRequested, int iTradeRequests, int iTradeAttempts );
  145. TF_Gamestats_TradeEvent( int eventID, int iTradeRequests, const char* reason, int iTradeAttempts );
  146. bool localPlayerPartyMatters;
  147. bool localPlayerIsPartyA;
  148. uint64 steamIDPartyA;
  149. uint64 steamIDPartyB;
  150. uint64 steamIDRequested;
  151. int tradeRequests;
  152. int tradeAttempts;
  153. const char* reason;
  154. };
  155. // Matchmaking stats
  156. struct TF_Gamestats_QuickPlay_t
  157. {
  158. // Status code for the search as a whole
  159. enum eResult
  160. {
  161. k_Result_InternalError = -1,
  162. k_Result_UserCancel = 10,
  163. k_Result_NoServersFound = 20,
  164. k_Result_NoServersMetCrtieria = 30,
  165. //k_Result_NeverHeardBackFromGC = 40,
  166. //k_Result_ReceivedZeroGCScores = 50,
  167. k_Result_FinalPingFailed = 60,
  168. k_Result_TriedToConnect = 100,
  169. };
  170. // Status codes for the servers
  171. enum eServerStatus
  172. {
  173. k_Server_Invalid = -1, // we have a bug if this gets reported
  174. k_Server_Ineligible = 10,
  175. k_Server_Eligible = 20,
  176. k_Server_RequestedScore = 30,
  177. k_Server_Scored = 40,
  178. k_Server_Pinged = 50,
  179. k_Server_PingTimedOut = 60,
  180. k_Server_PingIneligible = 70,
  181. k_Server_Connected = 100,
  182. };
  183. TF_Gamestats_QuickPlay_t()
  184. {
  185. m_fUserHoursPlayed = -1.0f;
  186. m_sUserGameMode;
  187. m_fSearchTime = -1.0;
  188. m_eResultCode = k_Result_UserCancel;
  189. m_iExperimentGroup = 0;
  190. }
  191. float m_fUserHoursPlayed;
  192. CUtlString m_sUserGameMode;
  193. float m_fSearchTime;
  194. eResult m_eResultCode;
  195. int m_iExperimentGroup; // TF2ScoringNumbers_t::ExperimentGroup_t
  196. struct Server_t
  197. {
  198. uint32 m_ip;
  199. uint16 m_port;
  200. bool m_bRegistered;
  201. bool m_bValve;
  202. bool m_bSecure;
  203. bool m_bMapIsNewUserFriendly;
  204. bool m_bMapIsQuickPlayOK;
  205. int m_nPlayers;
  206. int m_nMaxPlayers;
  207. CUtlString m_sMapName;
  208. CUtlString m_sTags;
  209. int m_iPing;
  210. float m_fScoreClient;
  211. float m_fScoreServer;
  212. float m_fScoreGC;
  213. eServerStatus m_eStatus;
  214. };
  215. CUtlVector<Server_t> m_vecServers;
  216. };
  217. //=============================================================================
  218. //
  219. // TF Game Stats Class
  220. //
  221. class C_CTFGameStats : public CBaseGameStats, public CGameEventListener, public CAutoGameSystem
  222. {
  223. public:
  224. // Constructor/Destructor.
  225. C_CTFGameStats( void );
  226. ~C_CTFGameStats( void );
  227. virtual void Clear( void );
  228. virtual bool UseOldFormat() { return false; }
  229. virtual bool AddDataForSend( KeyValues *pKV, StatSendType_t sendType );
  230. virtual bool Init();
  231. virtual void Shutdown();
  232. void ResetRoundStats();
  233. void ClientDisconnect( int iReason );
  234. // Events.
  235. virtual void Event_LevelInit( void );
  236. virtual void Event_LevelShutdown( float flElapsed );
  237. virtual void Event_RoundActive();
  238. virtual void Event_RoundEnd( int winningTeam, float roundTime, int fullRound );
  239. virtual void Event_PlayerChangeClass( int userid, int classid );
  240. virtual void Event_AchievementProgress( int achievementID, const char* achievementName );
  241. virtual void Event_PlayerHurt( IGameEvent* event /*player_hurt*/ );
  242. virtual void Event_PlayerFiredWeapon( C_TFPlayer *pPlayer, bool bCritical );
  243. virtual void Event_Catalog( int eventID, const char* filter=NULL, CEconItemView* item=NULL );
  244. virtual void Event_Crafting( int eventID, CEconItemView* item=NULL, int numAttempts=0, int recipeFound=0 );
  245. virtual void Event_Store( int eventID, CEconItemView* item=NULL, const char* panelName=NULL,
  246. int classId=0, const cart_item_t* in_cartItem=NULL, int in_checkoutAttempts=0, const char* storeError=NULL, int in_totalPrice=0, int in_currencyCode=0 );
  247. virtual void Event_ItemTransaction( int eventID, CEconItemView* item, const char* pszReason=NULL, int iQuality=0 );
  248. virtual void Event_Trading( int eventID, CEconItemView* item=NULL, bool localPlayerIsPartyA=false,
  249. uint64 steamIDPartyA=0, uint64 steamIDPartyB=0, int iTradeRequests=0, int iTradeAttempts=0 );
  250. virtual void Event_Trading( int eventID, uint64 steamIDRequested=0, int iTradeRequests=0, int iTradeAttempts=0 );
  251. virtual void Event_Trading( int eventID, int iTradeRequests=0, const char* reason=NULL, int iTradeAttempts=0 );
  252. virtual void Event_Trading( TF_Gamestats_TradeEvent& event );
  253. virtual void FireGameEvent( IGameEvent * event );
  254. void SW_GameStats_WriteClientSessionSummary();
  255. void SW_GameStats_WriteClientWeapons();
  256. void SW_GameStats_WriteClientRound( int winningTeam, int fullRound, int endReason );
  257. void SW_GameStats_WriteClientMap();
  258. void SetExperimentValue( uint64 experimentValue ) { m_ulExperimentValue = experimentValue; }
  259. static void ImmediateWriteInterfaceEvent( const char *pszEventType, const char *pszEventDesc );
  260. /*
  261. void SW_GameStats_WriteClientAchievements();
  262. void SW_GameStats_WriteClientCatalogEvents();
  263. void SW_GameStats_WriteClientCraftingEvents();
  264. void SW_GameStats_WriteClientStoreEvents();
  265. void SW_GameStats_WriteClientItemTransactionEvents();
  266. void SW_GameStats_WriteClientTradeEvents();
  267. */
  268. void QuickplayResults( const TF_Gamestats_QuickPlay_t &info );
  269. private:
  270. char m_szCountryCode[64];
  271. char m_szAudioLanguage[64];
  272. char m_szTextLanguage[64];
  273. TF_Gamestats_ClientSession_t m_currentSession;
  274. TF_Gamestats_RoundStats_t m_currentRound;
  275. TF_Gamestats_LevelStats_t m_currentMap;
  276. CUtlVector<TF_Gamestats_AchievementEvent_t> m_vecAchievementEvents;
  277. CUtlMap<int, TF_Gamestats_WeaponInfo_t> m_mapWeaponInfo;
  278. CUtlVector<TF_Gamestats_CatalogEvent> m_vecCatalogEvents;
  279. CUtlVector<TF_Gamestats_CraftingEvent> m_vecCraftingEvents;
  280. CUtlVector<TF_Gamestats_StoreEvent> m_vecStoreEvents;
  281. CUtlVector<TF_Gamestats_ItemTransactionEvent> m_vecItemTransactionEvents;
  282. CUtlVector<TF_Gamestats_TradeEvent> m_vecTradeEvents;
  283. uint64 m_ulExperimentValue;
  284. bool m_bRoundActive;
  285. bool m_bIsDisconnecting;
  286. };
  287. extern C_CTFGameStats C_CTF_GameStats;
  288. #endif // C_TF_GAMESTATS_H