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.

349 lines
17 KiB

  1. //====== Copyright (c) 1996-2008, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: interface to user account information in Steam
  4. //
  5. //=============================================================================
  6. #ifndef ISTEAMUSER_H
  7. #define ISTEAMUSER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "isteamclient.h"
  12. // structure that contains client callback data
  13. // see callbacks documentation for more details
  14. #if defined( VALVE_CALLBACK_PACK_SMALL )
  15. #pragma pack( push, 4 )
  16. #elif defined( VALVE_CALLBACK_PACK_LARGE )
  17. #pragma pack( push, 8 )
  18. #else
  19. #error isteamclient.h must be included
  20. #endif
  21. struct CallbackMsg_t
  22. {
  23. HSteamUser m_hSteamUser;
  24. int m_iCallback;
  25. uint8 *m_pubParam;
  26. int m_cubParam;
  27. };
  28. #pragma pack( pop )
  29. //-----------------------------------------------------------------------------
  30. // Purpose: Functions for accessing and manipulating a steam account
  31. // associated with one client instance
  32. //-----------------------------------------------------------------------------
  33. class ISteamUser
  34. {
  35. public:
  36. // returns the HSteamUser this interface represents
  37. // this is only used internally by the API, and by a few select interfaces that support multi-user
  38. virtual HSteamUser GetHSteamUser() = 0;
  39. // returns true if the Steam client current has a live connection to the Steam servers.
  40. // If false, it means there is no active connection due to either a networking issue on the local machine, or the Steam server is down/busy.
  41. // The Steam client will automatically be trying to recreate the connection as often as possible.
  42. virtual bool BLoggedOn() = 0;
  43. // returns the CSteamID of the account currently logged into the Steam client
  44. // a CSteamID is a unique identifier for an account, and used to differentiate users in all parts of the Steamworks API
  45. virtual CSteamID GetSteamID() = 0;
  46. // Multiplayer Authentication functions
  47. // InitiateGameConnection() starts the state machine for authenticating the game client with the game server
  48. // It is the client portion of a three-way handshake between the client, the game server, and the steam servers
  49. //
  50. // Parameters:
  51. // void *pAuthBlob - a pointer to empty memory that will be filled in with the authentication token.
  52. // int cbMaxAuthBlob - the number of bytes of allocated memory in pBlob. Should be at least 2048 bytes.
  53. // CSteamID steamIDGameServer - the steamID of the game server, received from the game server by the client
  54. // CGameID gameID - the ID of the current game. For games without mods, this is just CGameID( <appID> )
  55. // uint32 unIPServer, uint16 usPortServer - the IP address of the game server
  56. // bool bSecure - whether or not the client thinks that the game server is reporting itself as secure (i.e. VAC is running)
  57. //
  58. // return value - returns the number of bytes written to pBlob. If the return is 0, then the buffer passed in was too small, and the call has failed
  59. // The contents of pBlob should then be sent to the game server, for it to use to complete the authentication process.
  60. virtual int InitiateGameConnection( void *pAuthBlob, int cbMaxAuthBlob, CSteamID steamIDGameServer, uint32 unIPServer, uint16 usPortServer, bool bSecure ) = 0;
  61. // notify of disconnect
  62. // needs to occur when the game client leaves the specified game server, needs to match with the InitiateGameConnection() call
  63. virtual void TerminateGameConnection( uint32 unIPServer, uint16 usPortServer ) = 0;
  64. // Legacy functions
  65. // used by only a few games to track usage events
  66. virtual void TrackAppUsageEvent( CGameID gameID, int eAppUsageEvent, const char *pchExtraInfo = "" ) = 0;
  67. // get the local storage folder for current Steam account to write application data, e.g. save games, configs etc.
  68. // this will usually be something like "C:\Progam Files\Steam\userdata\<SteamID>\<AppID>\local"
  69. virtual bool GetUserDataFolder( char *pchBuffer, int cubBuffer ) = 0;
  70. // Starts voice recording. Once started, use GetVoice() to get the data
  71. virtual void StartVoiceRecording( ) = 0;
  72. // Stops voice recording. Because people often release push-to-talk keys early, the system will keep recording for
  73. // a little bit after this function is called. GetVoice() should continue to be called until it returns
  74. // k_eVoiceResultNotRecording
  75. virtual void StopVoiceRecording( ) = 0;
  76. // Determine the amount of captured audio data that is available in bytes.
  77. // This provides both the compressed and uncompressed data. Please note that the uncompressed
  78. // data is not the raw feed from the microphone: data may only be available if audible
  79. // levels of speech are detected.
  80. // nUncompressedVoiceDesiredSampleRate is necessary to know the number of bytes to return in pcbUncompressed - can be set to 0 if you don't need uncompressed (the usual case)
  81. // If you're upgrading from an older Steamworks API, you'll want to pass in 11025 to nUncompressedVoiceDesiredSampleRate
  82. virtual EVoiceResult GetAvailableVoice( uint32 *pcbCompressed, uint32 *pcbUncompressed, uint32 nUncompressedVoiceDesiredSampleRate ) = 0;
  83. // Gets the latest voice data from the microphone. Compressed data is an arbitrary format, and is meant to be handed back to
  84. // DecompressVoice() for playback later as a binary blob. Uncompressed data is 16-bit, signed integer, 11025Hz PCM format.
  85. // Please note that the uncompressed data is not the raw feed from the microphone: data may only be available if audible
  86. // levels of speech are detected, and may have passed through denoising filters, etc.
  87. // This function should be called as often as possible once recording has started; once per frame at least.
  88. // nBytesWritten is set to the number of bytes written to pDestBuffer.
  89. // nUncompressedBytesWritten is set to the number of bytes written to pUncompressedDestBuffer.
  90. // You must grab both compressed and uncompressed here at the same time, if you want both.
  91. // Matching data that is not read during this call will be thrown away.
  92. // GetAvailableVoice() can be used to determine how much data is actually available.
  93. // If you're upgrading from an older Steamworks API, you'll want to pass in 11025 to nUncompressedVoiceDesiredSampleRate
  94. virtual EVoiceResult GetVoice( bool bWantCompressed, void *pDestBuffer, uint32 cbDestBufferSize, uint32 *nBytesWritten, bool bWantUncompressed, void *pUncompressedDestBuffer, uint32 cbUncompressedDestBufferSize, uint32 *nUncompressBytesWritten, uint32 nUncompressedVoiceDesiredSampleRate ) = 0;
  95. // Decompresses a chunk of compressed data produced by GetVoice().
  96. // nBytesWritten is set to the number of bytes written to pDestBuffer unless the return value is k_EVoiceResultBufferTooSmall.
  97. // In that case, nBytesWritten is set to the size of the buffer required to decompress the given
  98. // data. The suggested buffer size for the destination buffer is 22 kilobytes.
  99. // The output format of the data is 16-bit signed at the requested samples per second.
  100. // If you're upgrading from an older Steamworks API, you'll want to pass in 11025 to nDesiredSampleRate
  101. virtual EVoiceResult DecompressVoice( const void *pCompressed, uint32 cbCompressed, void *pDestBuffer, uint32 cbDestBufferSize, uint32 *nBytesWritten, uint32 nDesiredSampleRate ) = 0;
  102. // This returns the frequency of the voice data as it's stored internally; calling DecompressVoice() with this size will yield the best results
  103. virtual uint32 GetVoiceOptimalSampleRate() = 0;
  104. // Retrieve ticket to be sent to the entity who wishes to authenticate you.
  105. // pcbTicket retrieves the length of the actual ticket.
  106. virtual HAuthTicket GetAuthSessionTicket( void *pTicket, int cbMaxTicket, uint32 *pcbTicket ) = 0;
  107. // Authenticate ticket from entity steamID to be sure it is valid and isnt reused
  108. // Registers for callbacks if the entity goes offline or cancels the ticket ( see ValidateAuthTicketResponse_t callback and EAuthSessionResponse )
  109. virtual EBeginAuthSessionResult BeginAuthSession( const void *pAuthTicket, int cbAuthTicket, CSteamID steamID ) = 0;
  110. // Stop tracking started by BeginAuthSession - called when no longer playing game with this entity
  111. virtual void EndAuthSession( CSteamID steamID ) = 0;
  112. // Cancel auth ticket from GetAuthSessionTicket, called when no longer playing game with the entity you gave the ticket to
  113. virtual void CancelAuthTicket( HAuthTicket hAuthTicket ) = 0;
  114. // After receiving a user's authentication data, and passing it to BeginAuthSession, use this function
  115. // to determine if the user owns downloadable content specified by the provided AppID.
  116. virtual EUserHasLicenseForAppResult UserHasLicenseForApp( CSteamID steamID, AppId_t appID ) = 0;
  117. // returns true if this users looks like they are behind a NAT device. Only valid once the user has connected to steam
  118. // (i.e a SteamServersConnected_t has been issued) and may not catch all forms of NAT.
  119. virtual bool BIsBehindNAT() = 0;
  120. // set data to be replicated to friends so that they can join your game
  121. // CSteamID steamIDGameServer - the steamID of the game server, received from the game server by the client
  122. // uint32 unIPServer, uint16 usPortServer - the IP address of the game server
  123. virtual void AdvertiseGame( CSteamID steamIDGameServer, uint32 unIPServer, uint16 usPortServer ) = 0;
  124. // Requests a ticket encrypted with an app specific shared key
  125. // pDataToInclude, cbDataToInclude will be encrypted into the ticket
  126. // ( This is asynchronous, you must wait for the ticket to be completed by the server )
  127. CALL_RESULT( EncryptedAppTicketResponse_t )
  128. virtual SteamAPICall_t RequestEncryptedAppTicket( void *pDataToInclude, int cbDataToInclude ) = 0;
  129. // retrieve a finished ticket
  130. virtual bool GetEncryptedAppTicket( void *pTicket, int cbMaxTicket, uint32 *pcbTicket ) = 0;
  131. // Trading Card badges data access
  132. // if you only have one set of cards, the series will be 1
  133. // the user has can have two different badges for a series; the regular (max level 5) and the foil (max level 1)
  134. virtual int GetGameBadgeLevel( int nSeries, bool bFoil ) = 0;
  135. // gets the Steam Level of the user, as shown on their profile
  136. virtual int GetPlayerSteamLevel() = 0;
  137. // Requests a URL which authenticates an in-game browser for store check-out,
  138. // and then redirects to the specified URL. As long as the in-game browser
  139. // accepts and handles session cookies, Steam microtransaction checkout pages
  140. // will automatically recognize the user instead of presenting a login page.
  141. // The result of this API call will be a StoreAuthURLResponse_t callback.
  142. // NOTE: The URL has a very short lifetime to prevent history-snooping attacks,
  143. // so you should only call this API when you are about to launch the browser,
  144. // or else immediately navigate to the result URL using a hidden browser window.
  145. // NOTE 2: The resulting authorization cookie has an expiration time of one day,
  146. // so it would be a good idea to request and visit a new auth URL every 12 hours.
  147. CALL_RESULT( StoreAuthURLResponse_t )
  148. virtual SteamAPICall_t RequestStoreAuthURL( const char *pchRedirectURL ) = 0;
  149. // gets whether the users phone number is verified
  150. virtual bool BIsPhoneVerified() = 0;
  151. // gets whether the user has two factor enabled on their account
  152. virtual bool BIsTwoFactorEnabled() = 0;
  153. };
  154. #define STEAMUSER_INTERFACE_VERSION "SteamUser019"
  155. // callbacks
  156. #if defined( VALVE_CALLBACK_PACK_SMALL )
  157. #pragma pack( push, 4 )
  158. #elif defined( VALVE_CALLBACK_PACK_LARGE )
  159. #pragma pack( push, 8 )
  160. #else
  161. #error isteamclient.h must be included
  162. #endif
  163. //-----------------------------------------------------------------------------
  164. // Purpose: called when a connections to the Steam back-end has been established
  165. // this means the Steam client now has a working connection to the Steam servers
  166. // usually this will have occurred before the game has launched, and should
  167. // only be seen if the user has dropped connection due to a networking issue
  168. // or a Steam server update
  169. //-----------------------------------------------------------------------------
  170. struct SteamServersConnected_t
  171. {
  172. enum { k_iCallback = k_iSteamUserCallbacks + 1 };
  173. };
  174. //-----------------------------------------------------------------------------
  175. // Purpose: called when a connection attempt has failed
  176. // this will occur periodically if the Steam client is not connected,
  177. // and has failed in it's retry to establish a connection
  178. //-----------------------------------------------------------------------------
  179. struct SteamServerConnectFailure_t
  180. {
  181. enum { k_iCallback = k_iSteamUserCallbacks + 2 };
  182. EResult m_eResult;
  183. bool m_bStillRetrying;
  184. };
  185. //-----------------------------------------------------------------------------
  186. // Purpose: called if the client has lost connection to the Steam servers
  187. // real-time services will be disabled until a matching SteamServersConnected_t has been posted
  188. //-----------------------------------------------------------------------------
  189. struct SteamServersDisconnected_t
  190. {
  191. enum { k_iCallback = k_iSteamUserCallbacks + 3 };
  192. EResult m_eResult;
  193. };
  194. //-----------------------------------------------------------------------------
  195. // Purpose: Sent by the Steam server to the client telling it to disconnect from the specified game server,
  196. // which it may be in the process of or already connected to.
  197. // The game client should immediately disconnect upon receiving this message.
  198. // This can usually occur if the user doesn't have rights to play on the game server.
  199. //-----------------------------------------------------------------------------
  200. struct ClientGameServerDeny_t
  201. {
  202. enum { k_iCallback = k_iSteamUserCallbacks + 13 };
  203. uint32 m_uAppID;
  204. uint32 m_unGameServerIP;
  205. uint16 m_usGameServerPort;
  206. uint16 m_bSecure;
  207. uint32 m_uReason;
  208. };
  209. //-----------------------------------------------------------------------------
  210. // Purpose: called when the callback system for this client is in an error state (and has flushed pending callbacks)
  211. // When getting this message the client should disconnect from Steam, reset any stored Steam state and reconnect.
  212. // This usually occurs in the rare event the Steam client has some kind of fatal error.
  213. //-----------------------------------------------------------------------------
  214. struct IPCFailure_t
  215. {
  216. enum { k_iCallback = k_iSteamUserCallbacks + 17 };
  217. enum EFailureType
  218. {
  219. k_EFailureFlushedCallbackQueue,
  220. k_EFailurePipeFail,
  221. };
  222. uint8 m_eFailureType;
  223. };
  224. //-----------------------------------------------------------------------------
  225. // Purpose: Signaled whenever licenses change
  226. //-----------------------------------------------------------------------------
  227. struct LicensesUpdated_t
  228. {
  229. enum { k_iCallback = k_iSteamUserCallbacks + 25 };
  230. };
  231. //-----------------------------------------------------------------------------
  232. // callback for BeginAuthSession
  233. //-----------------------------------------------------------------------------
  234. struct ValidateAuthTicketResponse_t
  235. {
  236. enum { k_iCallback = k_iSteamUserCallbacks + 43 };
  237. CSteamID m_SteamID;
  238. EAuthSessionResponse m_eAuthSessionResponse;
  239. CSteamID m_OwnerSteamID; // different from m_SteamID if borrowed
  240. };
  241. //-----------------------------------------------------------------------------
  242. // Purpose: called when a user has responded to a microtransaction authorization request
  243. //-----------------------------------------------------------------------------
  244. struct MicroTxnAuthorizationResponse_t
  245. {
  246. enum { k_iCallback = k_iSteamUserCallbacks + 52 };
  247. uint32 m_unAppID; // AppID for this microtransaction
  248. uint64 m_ulOrderID; // OrderID provided for the microtransaction
  249. uint8 m_bAuthorized; // if user authorized transaction
  250. };
  251. //-----------------------------------------------------------------------------
  252. // Purpose: Result from RequestEncryptedAppTicket
  253. //-----------------------------------------------------------------------------
  254. struct EncryptedAppTicketResponse_t
  255. {
  256. enum { k_iCallback = k_iSteamUserCallbacks + 54 };
  257. EResult m_eResult;
  258. };
  259. //-----------------------------------------------------------------------------
  260. // callback for GetAuthSessionTicket
  261. //-----------------------------------------------------------------------------
  262. struct GetAuthSessionTicketResponse_t
  263. {
  264. enum { k_iCallback = k_iSteamUserCallbacks + 63 };
  265. HAuthTicket m_hAuthTicket;
  266. EResult m_eResult;
  267. };
  268. //-----------------------------------------------------------------------------
  269. // Purpose: sent to your game in response to a steam://gamewebcallback/ command
  270. //-----------------------------------------------------------------------------
  271. struct GameWebCallback_t
  272. {
  273. enum { k_iCallback = k_iSteamUserCallbacks + 64 };
  274. char m_szURL[256];
  275. };
  276. //-----------------------------------------------------------------------------
  277. // Purpose: sent to your game in response to ISteamUser::RequestStoreAuthURL
  278. //-----------------------------------------------------------------------------
  279. struct StoreAuthURLResponse_t
  280. {
  281. enum { k_iCallback = k_iSteamUserCallbacks + 65 };
  282. char m_szURL[512];
  283. };
  284. #pragma pack( pop )
  285. #endif // ISTEAMUSER_H