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.

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