expose GetAuthSessionTicketResponse

This commit is contained in:
William Wallace 2019-03-27 18:16:40 +00:00
parent 5c9e239bc6
commit ac44bb2293
4 changed files with 53 additions and 0 deletions

View File

@ -182,5 +182,45 @@ public void AuthenticateAServer()
Assert.IsFalse( isAuthed );
}
}
[TestMethod]
public void WaitForAuthTicketValidation()
{
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
using ( var server = new Facepunch.Steamworks.Server( 252490, new ServerInit( "rust", "Rust" ) ) )
{
Assert.IsTrue( client.IsValid );
Assert.IsTrue( server.IsValid );
server.LogOnAnonymous();
bool clientAuthed = false;
bool serverAuthed = false;
client.Auth.OnGetAuthSessionTicketResponse += ( uint handle, bool authed ) => {
clientAuthed = authed;
};
server.Auth.OnGetAuthSessionTicketResponse += ( uint handle, bool authed ) => {
serverAuthed = authed;
};
var clientTicket = client.Auth.GetAuthSessionTicket();
var serverTicket = server.Auth.GetAuthSessionTicket();
for ( int i = 0; i < 100; i++ )
{
System.Threading.Thread.Sleep( 16 );
server.Update();
client.Update();
if ( clientAuthed && serverAuthed )
break;
}
Assert.IsTrue( clientAuthed );
Assert.IsTrue( serverAuthed );
}
}
}
}

View File

@ -11,6 +11,7 @@ public ClientAuth( Client client )
{
_client = client;
_client.RegisterCallback<SteamNative.ValidateAuthTicketResponse_t>( OnAuthTicketValidate );
_client.RegisterCallback<SteamNative.GetAuthSessionTicketResponse_t>( OnGetAuthSessionTicketResponseThing );
}
public unsafe override Ticket GetAuthSessionTicket()

View File

@ -45,6 +45,17 @@ internal void OnAuthTicketValidate( SteamNative.ValidateAuthTicketResponse_t dat
OnAuthChange( data.SteamID, data.OwnerSteamID, (AuthStatus) data.AuthSessionResponse );
}
/// <summary>
/// This is called when your locally generated auth ticket has been validated by Steam
/// </summary>
public Action<uint, bool> OnGetAuthSessionTicketResponse;
internal void OnGetAuthSessionTicketResponseThing( SteamNative.GetAuthSessionTicketResponse_t data )
{
if ( OnGetAuthSessionTicketResponse != null )
OnGetAuthSessionTicketResponse( data.AuthTicket, data.Result == SteamNative.Result.OK );
}
/// <summary>
/// An auth ticket for the local client/server (never remote)
/// You should not cancel this ticket until you are disconnected from the remote user

View File

@ -11,6 +11,7 @@ public ServerAuth( Server server )
{
_server = server;
_server.RegisterCallback<SteamNative.ValidateAuthTicketResponse_t>( OnAuthTicketValidate );
_server.RegisterCallback<SteamNative.GetAuthSessionTicketResponse_t>( OnGetAuthSessionTicketResponseThing );
}
public unsafe override Ticket GetAuthSessionTicket()