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.

157 lines
3.1 KiB

  1. //====== Copyright �, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: Ownership id for a shared object cache
  4. //
  5. //=============================================================================
  6. #ifndef SOID_H
  7. #define SOID_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "steam/steamclientpublic.h"
  12. class CMsgSOIDOwner;
  13. namespace GCSDK
  14. {
  15. //----------------------------------------------------------------------------
  16. // Shared type for object caches. This can hold SteamIDs, LobbyIDs, PartyIds,
  17. // etc. Make sure they don't conflict!
  18. //----------------------------------------------------------------------------
  19. struct SOID_t;
  20. const uint32 k_SOID_Type_SteamID = 1;
  21. const uint32 k_SOID_Type_PartyGroupID = 2;
  22. const uint32 k_SOID_Type_LobbyGroupID = 3;
  23. const uint32 k_SOID_Type_PartyInvite = 4;
  24. const uint32 k_SOID_Type_CheatReport = 5;
  25. const uint32 k_SOID_Type_NqmmRating = 6;
  26. struct SOIDRender_t
  27. {
  28. explicit SOIDRender_t( const SOID_t id );
  29. const char *String() const;
  30. //the buffer that is formatted into (should be large enough to hold the string representation of the type and the value)
  31. static const uint32 k_cBufLen = 128;
  32. char m_buf[ k_cBufLen ];
  33. //a utility class that is intended to be defined in a source file that will handle registering
  34. //the provided name and whether or not it should be displayed as a steam ID with the lock
  35. class CAutoRegisterName
  36. {
  37. public:
  38. CAutoRegisterName( uint16 nType, const char* pszDefaultString, bool bDisplaySteamID = false );
  39. };
  40. static const char *GetName( uint32 nType );
  41. };
  42. struct SOID_t
  43. {
  44. SOID_t()
  45. : m_type( 0 )
  46. , m_id( 0 )
  47. , m_padding( 0 )
  48. {
  49. }
  50. SOID_t( uint32 type, uint64 id )
  51. : m_type( type )
  52. , m_id( id )
  53. , m_padding( 0 )
  54. {
  55. }
  56. // Conversion from a SteamID
  57. SOID_t( CSteamID steamID )
  58. : m_type( k_SOID_Type_SteamID )
  59. , m_id( steamID.ConvertToUint64() )
  60. , m_padding( 0 )
  61. {
  62. }
  63. //initializes the soid fields
  64. void Init( uint32 type, uint64 id )
  65. {
  66. m_type = type;
  67. m_id = id;
  68. }
  69. // Conversion from a protobuf version
  70. SOID_t( const CMsgSOIDOwner &msgSOIDOwner );
  71. void ToMsgSOIDOwner( CMsgSOIDOwner *pMsgSOIDOwner ) const;
  72. uint64 ID() const
  73. {
  74. return m_id;
  75. }
  76. uint32 Type() const
  77. {
  78. return m_type;
  79. }
  80. bool IsValid()
  81. {
  82. return m_type != 0;
  83. }
  84. bool operator==( const SOID_t &rhs ) const
  85. {
  86. return m_type == rhs.m_type && m_id == rhs.m_id;
  87. }
  88. bool operator!=( const SOID_t &rhs ) const
  89. {
  90. return m_type != rhs.m_type || m_id != rhs.m_id;
  91. }
  92. bool operator<( const SOID_t &rhs ) const
  93. {
  94. if ( m_type == rhs.m_type )
  95. {
  96. return m_id < rhs.m_id;
  97. }
  98. return m_type < rhs.m_type;
  99. }
  100. SOIDRender_t GetRender() const
  101. {
  102. return SOIDRender_t( *this );
  103. }
  104. uint64 m_id;
  105. uint32 m_type;
  106. uint32 m_padding; // so structure is 16 bytes
  107. };
  108. inline const char *SOIDRender_t::String() const
  109. {
  110. return m_buf;
  111. }
  112. inline SOID_t GetSOIDFromSteamID( CSteamID steamID )
  113. {
  114. return SOID_t( k_SOID_Type_SteamID, steamID.ConvertToUint64() );
  115. }
  116. inline CSteamID GetSteamIDFromSOID( SOID_t ID )
  117. {
  118. if ( ID.Type() == k_SOID_Type_SteamID )
  119. {
  120. return CSteamID( ID.ID() );
  121. }
  122. return k_steamIDNil;
  123. }
  124. } // namespace GCSDK
  125. #endif //SOID_H