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.

306 lines
16 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. #pragma pack( push, 8 )
  15. struct CallbackMsg_t
  16. {
  17. HSteamUser m_hSteamUser;
  18. int m_iCallback;
  19. uint8 *m_pubParam;
  20. int m_cubParam;
  21. };
  22. #pragma pack( pop )
  23. // reference to a steam call, to filter results by
  24. typedef int32 HSteamCall;
  25. //-----------------------------------------------------------------------------
  26. // Purpose: Functions for accessing and manipulating a steam account
  27. // associated with one client instance
  28. //-----------------------------------------------------------------------------
  29. class ISteamUser
  30. {
  31. public:
  32. // returns the HSteamUser this interface represents
  33. // this is only used internally by the API, and by a few select interfaces that support multi-user
  34. virtual HSteamUser GetHSteamUser() = 0;
  35. // returns true if the Steam client current has a live connection to the Steam servers.
  36. // 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.
  37. // The Steam client will automatically be trying to recreate the connection as often as possible.
  38. virtual bool BLoggedOn() = 0;
  39. // returns the CSteamID of the account currently logged into the Steam client
  40. // a CSteamID is a unique identifier for an account, and used to differentiate users in all parts of the Steamworks API
  41. virtual CSteamID GetSteamID() = 0;
  42. // Multiplayer Authentication functions
  43. // InitiateGameConnection() starts the state machine for authenticating the game client with the game server
  44. // It is the client portion of a three-way handshake between the client, the game server, and the steam servers
  45. //
  46. // Parameters:
  47. // void *pAuthBlob - a pointer to empty memory that will be filled in with the authentication token.
  48. // int cbMaxAuthBlob - the number of bytes of allocated memory in pBlob. Should be at least 2048 bytes.
  49. // CSteamID steamIDGameServer - the steamID of the game server, received from the game server by the client
  50. // CGameID gameID - the ID of the current game. For games without mods, this is just CGameID( <appID> )
  51. // uint32 unIPServer, uint16 usPortServer - the IP address of the game server
  52. // bool bSecure - whether or not the client thinks that the game server is reporting itself as secure (i.e. VAC is running)
  53. //
  54. // 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
  55. // The contents of pBlob should then be sent to the game server, for it to use to complete the authentication process.
  56. virtual int InitiateGameConnection( void *pAuthBlob, int cbMaxAuthBlob, CSteamID steamIDGameServer, uint32 unIPServer, uint16 usPortServer, bool bSecure ) = 0;
  57. // notify of disconnect
  58. // needs to occur when the game client leaves the specified game server, needs to match with the InitiateGameConnection() call
  59. virtual void TerminateGameConnection( uint32 unIPServer, uint16 usPortServer ) = 0;
  60. // Legacy functions
  61. // used by only a few games to track usage events
  62. virtual void TrackAppUsageEvent( CGameID gameID, int eAppUsageEvent, const char *pchExtraInfo = "" ) = 0;
  63. // get the local storage folder for current Steam account to write application data, e.g. save games, configs etc.
  64. // this will usually be something like "C:\Progam Files\Steam\userdata\<SteamID>\<AppID>\local"
  65. virtual bool GetUserDataFolder( char *pchBuffer, int cubBuffer ) = 0;
  66. // Starts voice recording. Once started, use GetVoice() to get the data
  67. virtual void StartVoiceRecording( ) = 0;
  68. // Stops voice recording. Because people often release push-to-talk keys early, the system will keep recording for
  69. // a little bit after this function is called. GetVoice() should continue to be called until it returns
  70. // k_eVoiceResultNotRecording
  71. virtual void StopVoiceRecording( ) = 0;
  72. // Determine the amount of captured audio data that is available in bytes.
  73. // This provides both the compressed and uncompressed data. Please note that the uncompressed
  74. // data is not the raw feed from the microphone: data may only be available if audible
  75. // levels of speech are detected.
  76. // 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)
  77. // If you're upgrading from an older Steamworks API, you'll want to pass in 11025 to nUncompressedVoiceDesiredSampleRate
  78. virtual EVoiceResult GetAvailableVoice(uint32 *pcbCompressed, uint32 *pcbUncompressed, uint32 nUncompressedVoiceDesiredSampleRate) = 0;
  79. // Gets the latest voice data from the microphone. Compressed data is an arbitrary format, and is meant to be handed back to
  80. // DecompressVoice() for playback later as a binary blob. Uncompressed data is 16-bit, signed integer, 11025Hz PCM format.
  81. // Please note that the uncompressed data is not the raw feed from the microphone: data may only be available if audible
  82. // levels of speech are detected, and may have passed through denoising filters, etc.
  83. // This function should be called as often as possible once recording has started; once per frame at least.
  84. // nBytesWritten is set to the number of bytes written to pDestBuffer.
  85. // nUncompressedBytesWritten is set to the number of bytes written to pUncompressedDestBuffer.
  86. // You must grab both compressed and uncompressed here at the same time, if you want both.
  87. // Matching data that is not read during this call will be thrown away.
  88. // GetAvailableVoice() can be used to determine how much data is actually available.
  89. // If you're upgrading from an older Steamworks API, you'll want to pass in 11025 to nUncompressedVoiceDesiredSampleRate
  90. virtual EVoiceResult GetVoice( bool bWantCompressed, void *pDestBuffer, uint32 cbDestBufferSize, uint32 *nBytesWritten, bool bWantUncompressed, void *pUncompressedDestBuffer, uint32 cbUncompressedDestBufferSize, uint32 *nUncompressBytesWritten, uint32 nUncompressedVoiceDesiredSampleRate ) = 0;
  91. // Decompresses a chunk of compressed data produced by GetVoice().
  92. // nBytesWritten is set to the number of bytes written to pDestBuffer unless the return value is k_EVoiceResultBufferTooSmall.
  93. // In that case, nBytesWritten is set to the size of the buffer required to decompress the given
  94. // data. The suggested buffer size for the destination buffer is 22 kilobytes.
  95. // The output format of the data is 16-bit signed at the requested samples per second.
  96. // If you're upgrading from an older Steamworks API, you'll want to pass in 11025 to nDesiredSampleRate
  97. virtual EVoiceResult DecompressVoice( const void *pCompressed, uint32 cbCompressed, void *pDestBuffer, uint32 cbDestBufferSize, uint32 *nBytesWritten, uint32 nDesiredSampleRate ) = 0;
  98. // This returns the frequency of the voice data as it's stored internally; calling DecompressVoice() with this size will yield the best results
  99. virtual uint32 GetVoiceOptimalSampleRate() = 0;
  100. // Retrieve ticket to be sent to the entity who wishes to authenticate you.
  101. // pcbTicket retrieves the length of the actual ticket.
  102. virtual HAuthTicket GetAuthSessionTicket( void *pTicket, int cbMaxTicket, uint32 *pcbTicket ) = 0;
  103. // Authenticate ticket from entity steamID to be sure it is valid and isnt reused
  104. // Registers for callbacks if the entity goes offline or cancels the ticket ( see ValidateAuthTicketResponse_t callback and EAuthSessionResponse )
  105. virtual EBeginAuthSessionResult BeginAuthSession( const void *pAuthTicket, int cbAuthTicket, CSteamID steamID ) = 0;
  106. // Stop tracking started by BeginAuthSession - called when no longer playing game with this entity
  107. virtual void EndAuthSession( CSteamID steamID ) = 0;
  108. // Cancel auth ticket from GetAuthSessionTicket, called when no longer playing game with the entity you gave the ticket to
  109. virtual void CancelAuthTicket( HAuthTicket hAuthTicket ) = 0;
  110. // After receiving a user's authentication data, and passing it to BeginAuthSession, use this function
  111. // to determine if the user owns downloadable content specified by the provided AppID.
  112. virtual EUserHasLicenseForAppResult UserHasLicenseForApp( CSteamID steamID, AppId_t appID ) = 0;
  113. // returns true if this users looks like they are behind a NAT device. Only valid once the user has connected to steam
  114. // (i.e a SteamServersConnected_t has been issued) and may not catch all forms of NAT.
  115. virtual bool BIsBehindNAT() = 0;
  116. // set data to be replicated to friends so that they can join your game
  117. // CSteamID steamIDGameServer - the steamID of the game server, received from the game server by the client
  118. // uint32 unIPServer, uint16 usPortServer - the IP address of the game server
  119. virtual void AdvertiseGame( CSteamID steamIDGameServer, uint32 unIPServer, uint16 usPortServer ) = 0;
  120. // Requests a ticket encrypted with an app specific shared key
  121. // pDataToInclude, cbDataToInclude will be encrypted into the ticket
  122. // ( This is asynchronous, you must wait for the ticket to be completed by the server )
  123. virtual SteamAPICall_t RequestEncryptedAppTicket( void *pDataToInclude, int cbDataToInclude ) = 0;
  124. // retrieve a finished ticket
  125. virtual bool GetEncryptedAppTicket( void *pTicket, int cbMaxTicket, uint32 *pcbTicket ) = 0;
  126. #ifdef _PS3
  127. // Initiates PS3 Logon request using just PSN ticket.
  128. //
  129. // PARAMS: bInteractive - If set tells Steam to go ahead and show the PS3 NetStart dialog if needed to
  130. // prompt the user for network setup/PSN logon before initiating the Steam side of the logon.
  131. //
  132. // Listen for SteamServersConnected_t or SteamServerConnectFailure_t for status. SteamServerConnectFailure_t
  133. // may return with EResult k_EResultExternalAccountUnlinked if the PSN account is unknown to Steam. You should
  134. // then call LogOnAndLinkSteamAccountToPSN() after prompting the user for credentials to establish a link.
  135. // Future calls to LogOn() after the one time link call should succeed as long as the user is connected to PSN.
  136. virtual void LogOn( bool bInteractive ) = 0;
  137. // Initiates a request to logon with a specific steam username/password and create a PSN account link at
  138. // the same time. Should call this only if LogOn() has failed and indicated the PSN account is unlinked.
  139. //
  140. // PARAMS: bInteractive - If set tells Steam to go ahead and show the PS3 NetStart dialog if needed to
  141. // prompt the user for network setup/PSN logon before initiating the Steam side of the logon. pchUserName
  142. // should be the users Steam username, and pchPassword should be the users Steam password.
  143. //
  144. // Listen for SteamServersConnected_t or SteamServerConnectFailure_t for status. SteamServerConnectFailure_t
  145. // may return with EResult k_EResultOtherAccountAlreadyLinked if already linked to another account.
  146. virtual void LogOnAndLinkSteamAccountToPSN( bool bInteractive, const char *pchUserName, const char *pchPassword ) = 0;
  147. // Final logon option for PS3, this logs into an existing account if already linked, but if not already linked
  148. // creates a new account using the info in the PSN ticket to generate a unique account name. The new account is
  149. // then linked to the PSN ticket. This is the faster option for new users who don't have an existing Steam account
  150. // to get into multiplayer.
  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. virtual void LogOnAndCreateNewSteamAccountIfNeeded( bool bInteractive ) = 0;
  155. // Returns a special SteamID that represents the user's PSN information. Can be used to query the user's PSN avatar,
  156. // online name, etc. through the standard Steamworks interfaces.
  157. virtual CSteamID GetConsoleSteamID() = 0;
  158. #endif
  159. };
  160. #define STEAMUSER_INTERFACE_VERSION "SteamUser016"
  161. // callbacks
  162. #pragma pack( push, 8 )
  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. };
  184. //-----------------------------------------------------------------------------
  185. // Purpose: called if the client has lost connection to the Steam servers
  186. // real-time services will be disabled until a matching SteamServersConnected_t has been posted
  187. //-----------------------------------------------------------------------------
  188. struct SteamServersDisconnected_t
  189. {
  190. enum { k_iCallback = k_iSteamUserCallbacks + 3 };
  191. EResult m_eResult;
  192. };
  193. //-----------------------------------------------------------------------------
  194. // Purpose: Sent by the Steam server to the client telling it to disconnect from the specified game server,
  195. // which it may be in the process of or already connected to.
  196. // The game client should immediately disconnect upon receiving this message.
  197. // This can usually occur if the user doesn't have rights to play on the game server.
  198. //-----------------------------------------------------------------------------
  199. struct ClientGameServerDeny_t
  200. {
  201. enum { k_iCallback = k_iSteamUserCallbacks + 13 };
  202. uint32 m_uAppID;
  203. uint32 m_unGameServerIP;
  204. uint16 m_usGameServerPort;
  205. uint16 m_bSecure;
  206. uint32 m_uReason;
  207. };
  208. //-----------------------------------------------------------------------------
  209. // Purpose: called when the callback system for this client is in an error state (and has flushed pending callbacks)
  210. // When getting this message the client should disconnect from Steam, reset any stored Steam state and reconnect.
  211. // This usually occurs in the rare event the Steam client has some kind of fatal error.
  212. //-----------------------------------------------------------------------------
  213. struct IPCFailure_t
  214. {
  215. enum { k_iCallback = k_iSteamUserCallbacks + 17 };
  216. enum EFailureType
  217. {
  218. k_EFailureFlushedCallbackQueue,
  219. k_EFailurePipeFail,
  220. };
  221. uint8 m_eFailureType;
  222. };
  223. //-----------------------------------------------------------------------------
  224. // callback for BeginAuthSession
  225. //-----------------------------------------------------------------------------
  226. struct ValidateAuthTicketResponse_t
  227. {
  228. enum { k_iCallback = k_iSteamUserCallbacks + 43 };
  229. CSteamID m_SteamID;
  230. EAuthSessionResponse m_eAuthSessionResponse;
  231. };
  232. //-----------------------------------------------------------------------------
  233. // Purpose: called when a user has responded to a microtransaction authorization request
  234. //-----------------------------------------------------------------------------
  235. struct MicroTxnAuthorizationResponse_t
  236. {
  237. enum { k_iCallback = k_iSteamUserCallbacks + 52 };
  238. uint32 m_unAppID; // AppID for this microtransaction
  239. uint64 m_ulOrderID; // OrderID provided for the microtransaction
  240. uint8 m_bAuthorized; // if user authorized transaction
  241. };
  242. //-----------------------------------------------------------------------------
  243. // Purpose: Result from RequestEncryptedAppTicket
  244. //-----------------------------------------------------------------------------
  245. struct EncryptedAppTicketResponse_t
  246. {
  247. enum { k_iCallback = k_iSteamUserCallbacks + 54 };
  248. EResult m_eResult;
  249. };
  250. #pragma pack( pop )
  251. #endif // ISTEAMUSER_H