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.

83 lines
3.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. #ifndef TF_RATING_DATA_H
  3. #define TF_RATING_DATA_H
  4. #ifdef _WIN32
  5. #pragma once
  6. #endif
  7. #include "gcsdk/protobufsharedobject.h"
  8. #include "tf_gcmessages.h"
  9. #if defined (CLIENT_DLL) || defined (GAME_DLL)
  10. #include "gc_clientsystem.h"
  11. #endif
  12. #ifdef GC
  13. #include "tf_gc.h"
  14. #else
  15. #include "tf_matchmaking_shared.h"
  16. #endif
  17. //---------------------------------------------------------------------------------
  18. // Purpose: The shared object that contains a specific MM rating
  19. //---------------------------------------------------------------------------------
  20. class CTFRatingData : public GCSDK::CProtoBufSharedObject< CSOTFRatingData, k_EProtoObjectTFRatingData, /* bPublicMutable */ false >
  21. {
  22. public:
  23. CTFRatingData();
  24. CTFRatingData( uint32 unAccountID, EMMRating eRatingType, const MMRatingData_t &ratingData );
  25. #ifdef GC
  26. CTFRatingData( uint32 unAccountID, EMMRating eRatingType ); // Fills with Default rating for backend
  27. #endif
  28. // Helpers
  29. static CTFRatingData *YieldingGetPlayerRatingDataBySteamID( const CSteamID &steamID, EMMRating eRatingType );
  30. #ifdef GC
  31. DECLARE_CLASS_MEMPOOL( CTFRatingData );
  32. // Mutability is purposefully private, only CTFSharedObjectCache::BYieldingUpdatePlayerRating should be generating
  33. // rating changes.
  34. friend class CTFSharedObjectCache;
  35. // Direct database & client shared SO
  36. // (Some ratings may not be shared with clients, though)
  37. virtual bool BIsNetworked() const OVERRIDE { return true; }
  38. virtual bool BIsDatabaseBacked() const OVERRIDE { return true; }
  39. virtual bool BIsKeyLess( const CSharedObject & soRHS ) const OVERRIDE;
  40. // We purposefully pass false to our template to make Obj() immutable -- these calls currently are just hooked up to
  41. // assert. All database writes should go through BYieldingUpdateRatingAndAddToTransaction, or it's SOCache helper.
  42. // If we have a need to do arbitrary writes of this type of object we should hook it up in a way that doesn't
  43. // encourage mis-use that bypasses audit record creation.
  44. virtual bool BYieldingAddInsertToTransaction( GCSDK::CSQLAccess & sqlAccess ) OVERRIDE;
  45. virtual bool BYieldingAddWriteToTransaction( GCSDK::CSQLAccess & sqlAccess, const CUtlVector< int > &fields ) OVERRIDE;
  46. virtual bool BYieldingAddRemoveToTransaction( GCSDK::CSQLAccess & sqlAccess ) OVERRIDE;
  47. void WriteToRecord( CSchRatingData *pRatingData ) const;
  48. void ReadFromRecord( const CSchRatingData &ladderData );
  49. // CTFSubscriberMessageFilter allows this type to filter flags on a per-object basis, so we can not send certain
  50. // rating types down.
  51. uint32_t FilterSendFlags( uint32_t unTypeFlags ) const;
  52. private:
  53. // Updates this rating object and stages writes, including audit entries, to the given transaction. We purposefully
  54. // make ourselves not publically mutable to ensure callers go through this path to generate audit records. See
  55. // CTFSharedObjectCache::BYieldingUpdatePlayerRating for the SOCache path to calling this.
  56. bool BYieldingUpdateRatingAndAddToTransaction( CSQLAccess &transaction,
  57. const MMRatingData_t &newData,
  58. EMMRatingSource eAdjustmentSource,
  59. uint64_t unSourceEventID,
  60. RTime32 rtTimestamp );
  61. #endif // GC
  62. // Private on the GC to encourage callers to go through the proper lookup in CTFSharedObjectCache (GC) or
  63. // GetLocalPlayerRatingData (client)
  64. MMRatingData_t GetRatingData();
  65. };
  66. #endif // TF_RATING_DATA_H