isteamuser.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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. // gets whether the users phone number is identifying
  154. virtual bool BIsPhoneIdentifying() = 0;
  155. // gets whether the users phone number is awaiting (re)verification
  156. virtual bool BIsPhoneRequiringVerification() = 0;
  157. };
  158. #define STEAMUSER_INTERFACE_VERSION "SteamUser019"
  159. // callbacks
  160. #if defined( VALVE_CALLBACK_PACK_SMALL )
  161. #pragma pack( push, 4 )
  162. #elif defined( VALVE_CALLBACK_PACK_LARGE )
  163. #pragma pack( push, 8 )
  164. #else
  165. #error isteamclient.h must be included
  166. #endif
  167. //-----------------------------------------------------------------------------
  168. // Purpose: called when a connections to the Steam back-end has been established
  169. // this means the Steam client now has a working connection to the Steam servers
  170. // usually this will have occurred before the game has launched, and should
  171. // only be seen if the user has dropped connection due to a networking issue
  172. // or a Steam server update
  173. //-----------------------------------------------------------------------------
  174. struct SteamServersConnected_t
  175. {
  176. enum { k_iCallback = k_iSteamUserCallbacks + 1 };
  177. };
  178. //-----------------------------------------------------------------------------
  179. // Purpose: called when a connection attempt has failed
  180. // this will occur periodically if the Steam client is not connected,
  181. // and has failed in it's retry to establish a connection
  182. //-----------------------------------------------------------------------------
  183. struct SteamServerConnectFailure_t
  184. {
  185. enum { k_iCallback = k_iSteamUserCallbacks + 2 };
  186. EResult m_eResult;
  187. bool m_bStillRetrying;
  188. };
  189. //-----------------------------------------------------------------------------
  190. // Purpose: called if the client has lost connection to the Steam servers
  191. // real-time services will be disabled until a matching SteamServersConnected_t has been posted
  192. //-----------------------------------------------------------------------------
  193. struct SteamServersDisconnected_t
  194. {
  195. enum { k_iCallback = k_iSteamUserCallbacks + 3 };
  196. EResult m_eResult;
  197. };
  198. //-----------------------------------------------------------------------------
  199. // Purpose: Sent by the Steam server to the client telling it to disconnect from the specified game server,
  200. // which it may be in the process of or already connected to.
  201. // The game client should immediately disconnect upon receiving this message.
  202. // This can usually occur if the user doesn't have rights to play on the game server.
  203. //-----------------------------------------------------------------------------
  204. struct ClientGameServerDeny_t
  205. {
  206. enum { k_iCallback = k_iSteamUserCallbacks + 13 };
  207. uint32 m_uAppID;
  208. uint32 m_unGameServerIP;
  209. uint16 m_usGameServerPort;
  210. uint16 m_bSecure;
  211. uint32 m_uReason;
  212. };
  213. //-----------------------------------------------------------------------------
  214. // Purpose: called when the callback system for this client is in an error state (and has flushed pending callbacks)
  215. // When getting this message the client should disconnect from Steam, reset any stored Steam state and reconnect.
  216. // This usually occurs in the rare event the Steam client has some kind of fatal error.
  217. //-----------------------------------------------------------------------------
  218. struct IPCFailure_t
  219. {
  220. enum { k_iCallback = k_iSteamUserCallbacks + 17 };
  221. enum EFailureType
  222. {
  223. k_EFailureFlushedCallbackQueue,
  224. k_EFailurePipeFail,
  225. };
  226. uint8 m_eFailureType;
  227. };
  228. //-----------------------------------------------------------------------------
  229. // Purpose: Signaled whenever licenses change
  230. //-----------------------------------------------------------------------------
  231. struct LicensesUpdated_t
  232. {
  233. enum { k_iCallback = k_iSteamUserCallbacks + 25 };
  234. };
  235. //-----------------------------------------------------------------------------
  236. // callback for BeginAuthSession
  237. //-----------------------------------------------------------------------------
  238. struct ValidateAuthTicketResponse_t
  239. {
  240. enum { k_iCallback = k_iSteamUserCallbacks + 43 };
  241. CSteamID m_SteamID;
  242. EAuthSessionResponse m_eAuthSessionResponse;
  243. CSteamID m_OwnerSteamID; // different from m_SteamID if borrowed
  244. };
  245. //-----------------------------------------------------------------------------
  246. // Purpose: called when a user has responded to a microtransaction authorization request
  247. //-----------------------------------------------------------------------------
  248. struct MicroTxnAuthorizationResponse_t
  249. {
  250. enum { k_iCallback = k_iSteamUserCallbacks + 52 };
  251. uint32 m_unAppID; // AppID for this microtransaction
  252. uint64 m_ulOrderID; // OrderID provided for the microtransaction
  253. uint8 m_bAuthorized; // if user authorized transaction
  254. };
  255. //-----------------------------------------------------------------------------
  256. // Purpose: Result from RequestEncryptedAppTicket
  257. //-----------------------------------------------------------------------------
  258. struct EncryptedAppTicketResponse_t
  259. {
  260. enum { k_iCallback = k_iSteamUserCallbacks + 54 };
  261. EResult m_eResult;
  262. };
  263. //-----------------------------------------------------------------------------
  264. // callback for GetAuthSessionTicket
  265. //-----------------------------------------------------------------------------
  266. struct GetAuthSessionTicketResponse_t
  267. {
  268. enum { k_iCallback = k_iSteamUserCallbacks + 63 };
  269. HAuthTicket m_hAuthTicket;
  270. EResult m_eResult;
  271. };
  272. //-----------------------------------------------------------------------------
  273. // Purpose: sent to your game in response to a steam://gamewebcallback/ command
  274. //-----------------------------------------------------------------------------
  275. struct GameWebCallback_t
  276. {
  277. enum { k_iCallback = k_iSteamUserCallbacks + 64 };
  278. char m_szURL[256];
  279. };
  280. //-----------------------------------------------------------------------------
  281. // Purpose: sent to your game in response to ISteamUser::RequestStoreAuthURL
  282. //-----------------------------------------------------------------------------
  283. struct StoreAuthURLResponse_t
  284. {
  285. enum { k_iCallback = k_iSteamUserCallbacks + 65 };
  286. char m_szURL[512];
  287. };
  288. #pragma pack( pop )
  289. #endif // ISTEAMUSER_H