From ac44bb229373526d6c256a87603daa80b1bd77a4 Mon Sep 17 00:00:00 2001 From: William Wallace Date: Wed, 27 Mar 2019 18:16:40 +0000 Subject: [PATCH] expose GetAuthSessionTicketResponse --- .../Client/Server/ServerTest.cs | 40 +++++++++++++++++++ Facepunch.Steamworks/Client/ClientAuth.cs | 1 + Facepunch.Steamworks/Interfaces/Auth.cs | 11 +++++ Facepunch.Steamworks/Server/ServerAuth.cs | 1 + 4 files changed, 53 insertions(+) diff --git a/Facepunch.Steamworks.Test/Client/Server/ServerTest.cs b/Facepunch.Steamworks.Test/Client/Server/ServerTest.cs index f100bf1..ea2763c 100644 --- a/Facepunch.Steamworks.Test/Client/Server/ServerTest.cs +++ b/Facepunch.Steamworks.Test/Client/Server/ServerTest.cs @@ -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 ); + } + } } } diff --git a/Facepunch.Steamworks/Client/ClientAuth.cs b/Facepunch.Steamworks/Client/ClientAuth.cs index 582e3e9..272d27c 100644 --- a/Facepunch.Steamworks/Client/ClientAuth.cs +++ b/Facepunch.Steamworks/Client/ClientAuth.cs @@ -11,6 +11,7 @@ public ClientAuth( Client client ) { _client = client; _client.RegisterCallback( OnAuthTicketValidate ); + _client.RegisterCallback( OnGetAuthSessionTicketResponseThing ); } public unsafe override Ticket GetAuthSessionTicket() diff --git a/Facepunch.Steamworks/Interfaces/Auth.cs b/Facepunch.Steamworks/Interfaces/Auth.cs index 75f5447..fffc079 100644 --- a/Facepunch.Steamworks/Interfaces/Auth.cs +++ b/Facepunch.Steamworks/Interfaces/Auth.cs @@ -45,6 +45,17 @@ internal void OnAuthTicketValidate( SteamNative.ValidateAuthTicketResponse_t dat OnAuthChange( data.SteamID, data.OwnerSteamID, (AuthStatus) data.AuthSessionResponse ); } + /// + /// This is called when your locally generated auth ticket has been validated by Steam + /// + public Action OnGetAuthSessionTicketResponse; + + internal void OnGetAuthSessionTicketResponseThing( SteamNative.GetAuthSessionTicketResponse_t data ) + { + if ( OnGetAuthSessionTicketResponse != null ) + OnGetAuthSessionTicketResponse( data.AuthTicket, data.Result == SteamNative.Result.OK ); + } + /// /// An auth ticket for the local client/server (never remote) /// You should not cancel this ticket until you are disconnected from the remote user diff --git a/Facepunch.Steamworks/Server/ServerAuth.cs b/Facepunch.Steamworks/Server/ServerAuth.cs index 564d7c8..94e47c4 100644 --- a/Facepunch.Steamworks/Server/ServerAuth.cs +++ b/Facepunch.Steamworks/Server/ServerAuth.cs @@ -11,6 +11,7 @@ public ServerAuth( Server server ) { _server = server; _server.RegisterCallback( OnAuthTicketValidate ); + _server.RegisterCallback( OnGetAuthSessionTicketResponseThing ); } public unsafe override Ticket GetAuthSessionTicket()