Functions - User
advertiseGame
advertiseGame( string
server_ip, uint16
port )
Set the rich presence data for an unsecured game server that the user is playing on. This allows friends to be able to view the game info and join your game.
When you are using Steam authentication system this call is never required, the auth system automatically sets the appropriate rich presence.
Returns: void
Note: This is a legacy function.
beginAuthSession
beginAuthSession( PoolByteArray
tickets, int
ticket_size, uint64_t
steam_id )
Authenticate the ticket from the entity Steam ID to be sure it is valid and isn't reused.
The ticket is created on the entity with getAuthSessionTicket and then needs to be provided over the network for the other end to validate.
This registers for validate_auth_ticket_response callbacks if the entity goes offline or cancels the ticket. See EAuthSessionResponse for more information.
When the multiplayer session terminates you must call endAuthSession
Trigger a validate_auth_ticket_response callback.
Returns: int
cancelAuthTicket
cancelAuthTicket( uint32_t
auth_ticket )
Cancels an auth ticket received from getAuthSessionTicket. This should be called when no longer playing with the specified entity.
Returns: void
decompressVoice
decompressVoice( PoolByteArray
voice, uint32
voice_size, uint32
sample_rate )
Decodes the compressed voice data returned by getVoice.
The output data is raw single-channel 16-bit PCM audio. The decoder supports any sample rate from 11025 to 48000. See getVoiceOptimalSampleRate for more information.
It is recommended that you start with a 20KiB buffer and then reallocate as necessary.
See Steam Voice for more information.
Returns: dictionary
Contains the following keys:
- uncompressed (PoolByteArray)
- size (uint32)
endAuthSession
endAuthSession( uint64_t
steam_id )
Ends an auth session that was started with beginAuthSession. This should be called when no longer playing with the specified entity.
Returns: void
getAuthSessionTicket
getAuthSessionTicket()
Retrieve an authentication ticket to be sent to the entity who wishes to authenticate you.
After calling this you can send the ticket to the entity where they can then call beginAuthSession to verify this entities integrity.
When creating a ticket for use by the authenticateUserTicket Web API, the calling application should wait for the get_auth_session_ticket_response callback generated by the API call before attempting to use the ticket to ensure that the ticket has been communicated to the server. If this callback does not come in a timely fashion (10 - 20 seconds), then your client is not connected to Steam, and the authenticateUserTicket call will fail because it can not authenticate the user.
Triggers a get_auth_session_ticket_response callback.
Returns: dictionary
Contains the following keys:
- id (uint32_t)
- buffer (PoolByteArray)
- size (uint32_t)
getAvailableVoice
getAvailableVoice()
Checks to see if there is captured audio data available from getVoice, and gets the size of the data.
Most applications will only use compressed data and should ignore the other parameters, which exist primarily for backwards compatibility. See getVoice for further explanation of "uncompressed" data.
See Steam Voice for more information.
Returns: dictionary
Contains the following keys:
- result (int)
- buffer (uint32)
getDurationControl
getDurationControl()
Retrieves anti indulgence / duration control for current user / game combination.
Triggers a duration_control call result.
Returns: void
getEncryptedAppTicket
getEncryptedAppTicket()
Retrieve an encrypted ticket.
This should be called after requesting an encrypted app ticket with requestEncryptedAppTicket and receiving the encrypted_app_ticket_response call result.
You should then pass this encrypted ticket to your secure servers to be decrypted using your secret key using decryptTicket
Returns: dictionary
Contains the following keys:
- buffer (PoolByteArray)
- size (uint32_t)
Note: If you call this without calling requestEncryptedAppTicket, the call may succeed but you will likely get a stale ticket.
getGameBadgeLevel
getGameBadgeLevel( int
series, bool
foil )
Gets the level of the users Steam badge for your game.
The user can have two different badges for a series; the regular badge (max level 5) and the foil badge (max level 1).
Returns: int
getPlayerSteamLevel
getPlayerSteamLevel()
Gets the Steam level of the user, as shown on their Steam community profile.
Returns: int
getSteamID
getSteamID()
Gets the Steam ID (ID64) of the account currently logged into the Steam client. This is commonly called the 'current user', or 'local user'.
A Steam ID is a unique identifier for a Steam accounts, Steam groups, Lobbies and Chat rooms, and used to differentiate users in all parts of the Steamworks API.
Returns: uint64_t
getVoice
getVoice()
Read captured audio data from the microphone buffer.
The compressed data can be transmitted by your application and decoded back into raw audio data using DecompressVoice on the other side. The compressed data provided is in an arbitrary format and is not meant to be played directly.
This should be called once per frame, and at worst no more than four times a second to keep the microphone input delay as low as possible. Calling this any less may result in gaps in the returned stream.
It is recommended that you pass in an 8 kilobytes or larger destination buffer for compressed audio. Static buffers are recommended for performance reasons. However, if you would like to allocate precisely the right amount of space for a buffer before each call you may use getAvailableVoice to find out how much data is available to be read.
See Steam Voice for more information.
Returns: dictionary
Contains the following keys:
- result (int)
- written (uint32)
- buffer (uint8)
Note: "Uncompressed" audio is a deprecated feature and should not be used by most applications. It is raw single-channel 16-bit PCM wave data which may have been run through preprocessing filters and/or had silence removed, so the uncompressed audio could have a shorter duration than you expect. There may be no data at all during long periods of silence. Also, fetching uncompressed audio will cause getVoice to discard any leftover compressed audio, so you must fetch both types at once. Finally, getAvailableVoice is not precisely accurate when the uncompressed size is requested. So if you really need to use uncompressed audio, you should call getVoice frequently with two very large (20KiB+) output buffers instead of trying to allocate perfectly-sized buffers. But most applications should ignore all of these details and simply leave the "uncompressed" parameters as NULL/0.
getVoiceOptimalSampleRate
getVoiceOptimalSampleRate()
Gets the native sample rate of the Steam voice decoder.
Using this sample rate for decompressVoice will perform the least CPU processing. However, the final audio quality will depend on how well the audio device (and/or your application's audio output SDK) deals with lower sample rates. You may find that you get the best audio output quality when you ignore this function and use the native sample rate of your audio output device, which is usually 48000 or 44100.
See Steam Voice for more information.
Returns: int
initiateGameConnection
initiateGameConnection( uint64_t
server_id, uint32
server_ip, uint16
server_port, bool
secure )
This starts the state machine for authenticating the game client with the game server.
It is the client portion of a three-way handshake between the client, the game server, and the steam servers.
Returns: dictionary
Contains the following keys:
- auth_blob (PoolByteArray)
- server_id (uint64_t)
- server_ip (uint32)
- server_port (uint16)
Note: When you're done with the connection you must call terminateGameConnection
Note: This is part of the old user authentication API and should not be mixed with the new API.
isBehindNAT
isBehindNAT()
Checks if the current user looks like they are behind a NAT device.
This is only valid if the user is connected to the Steam servers and may not catch all forms of NAT.
Returns: bool
isPhoneIdentifying
isPhoneIdentifying()
Checks whether the user's phone number is used to uniquely identify them.
Returns: bool
isPhoneRequiringVerification
isPhoneRequiringVerification()
Checks whether the current user's phone number is awaiting (re)verification.
Returns: bool
isPhoneVerified
isPhoneVerified()
Checks whether the current user has verified their phone number.
See the Steam Guard Mobile Authenticator page on the customer facing Steam Support site for more information.
Returns: bool
isTwoFactorEnabled
isTwoFactorEnabled()
Checks whether the current user has Steam Guard two factor authentication enabled on their account.
See the Steam Guard Mobile Authenticator page on the customer facing Steam Support site for more information.
Returns: bool
loggedOn
loggedOn()
Checks if the current user's Steam client is connected to the Steam servers.
If it's not then no real-time services provided by the Steamworks API will be enabled. The Steam client will automatically be trying to recreate the connection as often as possible. When the connection is restored a steam_server_connected callback will be posted.
You usually don't need to check for this yourself. All of the API calls that rely on this will check internally. Forcefully disabling stuff when the player loses access is usually not a very good experience for the player and you could be preventing them from accessing APIs that do not need a live connection to Steam.
Returns: bool
requestEncryptedAppTicket
requestEncryptedAppTicket( string
secret )
Requests an application ticket encrypted with the secret "encrypted app ticket key".
The encryption key can be obtained from the Encrypted App Ticket Key page on the App Admin for your app.
There can only be one encrypted_app_ticket_response pending, and this call is subject to a 60 second rate limit.
After receiving the response you should call getEncryptedAppTicket to get the ticket data, and then you need to send it to a secure server to be decrypted with the SteamEncryptedAppTicket functions.
Triggers a encrypted_app_ticket_response call result.
Returns: void
requestStoreAuthURL
requestStoreAuthURL( string
redirect )
Requests a URL which authenticates an in-game browser for store check-out, and then redirects to the specified URL.
As long as the in-game browser accepts and handles session cookies, Steam microtransaction checkout pages will automatically recognize the user instead of presenting a login page.
Triggers a store_auth_url_response call result.
Returns: void
Note: The URL has a very short lifetime to prevent history-snooping attacks, so you should only call this API when you are about to launch the browser, or else immediately navigate to the result URL using a hidden browser window.
Note: The resulting authorization cookie has an expiration time of one day, so it would be a good idea to request and visit a new auth URL every 12 hours.
setDurationControlOnlineState
setDurationControlOnlineState( int
new_state )
Allows the game to specify the offline/online gameplay state for Steam China duration control.
Returns: bool
startVoiceRecording
startVoiceRecording()
Starts voice recording.
Once started, use getAvailableVoice and getVoice to get the data, and then call stopVoiceRecording when the user has released their push-to-talk hotkey or the game session has completed.
See Steam Voice for more information.
Returns: void
stopVoiceRecording
stopVoiceRecording()
Stops voice recording.
Because people often release push-to-talk keys early, the system will keep recording for a little bit after this function is called. As such, getVoice should continue to be called until it returns 2, only then will voice recording be stopped.
Returns: void
terminateGameConnection
terminateGameConnection( uint32
server_ip, uint32
server_port )
Notify the game server that we are disconnecting.
This needs to occur when the game client leaves the specified game server, needs to match with the initiateGameConnection call.
Returns: void
Note: This is part of the old user authentication API and should not be mixed with the new API.
userHasLicenseForApp
userHasLicenseForApp( uint64_t
steam_id, uint32_t
app_id )
Checks if the user owns a specific piece of Downloadable Content (DLC).
This can only be called after sending the users auth ticket to beginAuthSession.
Returns: int