mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-01-26 05:28:07 +03:00
Added GetAuthSessionTicketAsync, which waits on GetAuthSessionTicketResponse_t before returning
This commit is contained in:
parent
2c4fc82ae2
commit
761ff33663
@ -74,6 +74,16 @@ namespace Steamworks
|
||||
SteamUser.EndAuthSession( SteamClient.SteamId );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task AuthSessionAsync()
|
||||
{
|
||||
var ticket = await SteamUser.GetAuthSessionTicketAsync( 5.0 );
|
||||
|
||||
Assert.AreNotEqual( 0, ticket.Handle );
|
||||
Assert.AreNotEqual( 0, ticket.Data.Length );
|
||||
Console.WriteLine( $"ticket.Handle: {ticket.Handle}" );
|
||||
Console.WriteLine( $"ticket.Data: { string.Join( "", ticket.Data.Select( x => x.ToString( "x" ) ) ) }" );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SteamLevel()
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
@ -49,6 +50,7 @@ namespace Steamworks
|
||||
ValidateAuthTicketResponse_t.Install( x => OnValidateAuthTicketResponse?.Invoke( x.SteamID, x.OwnerSteamID, x.AuthSessionResponse ) );
|
||||
MicroTxnAuthorizationResponse_t.Install( x => OnMicroTxnAuthorizationResponse?.Invoke( x.AppID, x.OrderID, x.Authorized != 0 ) );
|
||||
GameWebCallback_t.Install( x => OnGameWebCallback?.Invoke( x.URL ) );
|
||||
GetAuthSessionTicketResponse_t.Install( x => OnGetAuthSessionTicketResponse?.Invoke( x ) );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -88,10 +90,16 @@ namespace Steamworks
|
||||
/// <summary>
|
||||
/// Called when an auth ticket has been validated.
|
||||
/// The first parameter is the steamid of this user
|
||||
/// The second is the Steam ID that owns the game, this will be different from the first if the game is being borrowed via Steam Family Sharing
|
||||
/// The second is the Steam ID that owns the game, this will be different from the first
|
||||
/// if the game is being borrowed via Steam Family Sharing
|
||||
/// </summary>
|
||||
public static event Action<SteamId, SteamId, AuthResponse> OnValidateAuthTicketResponse;
|
||||
|
||||
/// <summary>
|
||||
/// Used internally for GetAuthSessionTicketAsync
|
||||
/// </summary>
|
||||
internal static event Action<GetAuthSessionTicketResponse_t> OnGetAuthSessionTicketResponse;
|
||||
|
||||
/// <summary>
|
||||
/// Called when a user has responded to a microtransaction authorization request.
|
||||
/// ( appid, orderid, user authorized )
|
||||
@ -302,6 +310,55 @@ namespace Steamworks
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve a authentication ticket to be sent to the entity who wishes to authenticate you.
|
||||
/// This waits for a positive response from the backend before returning the ticket. This means
|
||||
/// the ticket is definitely ready to go as soon as it returns. Will return null if the callback
|
||||
/// times out or returns negatively.
|
||||
/// </summary>
|
||||
public static async Task<AuthTicket> GetAuthSessionTicketAsync( double timeoutSeconds = 10.0f )
|
||||
{
|
||||
var result = Result.Pending;
|
||||
AuthTicket ticket = null;
|
||||
var stopwatch = Stopwatch.StartNew();
|
||||
|
||||
Action<GetAuthSessionTicketResponse_t> f = ( t ) =>
|
||||
{
|
||||
if ( t.AuthTicket != ticket.Handle ) return;
|
||||
result = t.Result;
|
||||
};
|
||||
|
||||
OnGetAuthSessionTicketResponse += f;
|
||||
|
||||
try
|
||||
{
|
||||
ticket = GetAuthSessionTicket();
|
||||
if ( ticket == null )
|
||||
return null;
|
||||
|
||||
while ( result == Result.Pending )
|
||||
{
|
||||
await Task.Delay( 10 );
|
||||
|
||||
if ( stopwatch.Elapsed.TotalSeconds > timeoutSeconds )
|
||||
{
|
||||
ticket.Cancel();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if ( result == Result.OK )
|
||||
return ticket;
|
||||
|
||||
ticket.Cancel();
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
OnGetAuthSessionTicketResponse -= f;
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe BeginAuthResult BeginAuthSession( byte[] ticketData, SteamId steamid )
|
||||
{
|
||||
fixed ( byte* ptr = ticketData )
|
||||
|
Loading…
x
Reference in New Issue
Block a user