BeginAuthSession test

This commit is contained in:
Garry Newman 2019-04-15 21:39:13 +01:00
parent c1d611dae7
commit 8107297262
3 changed files with 56 additions and 77 deletions

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
using SteamNative;
namespace Steamworks namespace Steamworks
{ {
@ -38,96 +39,70 @@ namespace Steamworks
} }
[TestMethod] [TestMethod]
public void AuthCallback() public async Task BeginAuthSession()
{ {
/* bool finished = false;
using ( var client = new Facepunch.Steamworks.Client( 252490 ) ) AuthSessionResponse response = AuthSessionResponse.AuthTicketInvalidAlreadyUsed;
{
Assert.IsTrue( client.IsValid );
var ticket = client.Auth.GetAuthSessionTicket();
var ticketBinary = ticket.Data;
using ( var server = new Facepunch.Steamworks.Server( 252490, new ServerInit( "rust", "Rust" ) ) ) //
{ // Clientside calls this function, gets ticket
server.LogOnAnonymous(); //
var clientTicket = User.GetAuthSessionTicket();
Assert.IsTrue( server.IsValid ); //
// The client sends this data to the server along with their steamid
//
var ticketData = clientTicket.Data;
var clientSteamId = User.SteamID;
var auth = server.Auth; //
// Server listens to auth responses from Gabe
//
GameServer.OnValidateAuthTicketResponse += ( steamid, ownerid, rsponse ) =>
{
finished = true;
response = rsponse;
var Authed = false; Assert.AreEqual( steamid, clientSteamId );
Assert.AreEqual( steamid, ownerid );
server.Auth.OnAuthChange = ( steamid, ownerid, status ) => Console.WriteLine( "steamid: {0}", steamid );
{ Console.WriteLine( "ownerid: {0}", ownerid );
Authed = status == ServerAuth.Status.OK; Console.WriteLine( "status: {0}", response );
};
Assert.AreEqual( steamid, client.SteamId ); //
Assert.AreEqual( steamid, ownerid ); // Server gets the ticket, starts authing
//
if ( !GameServer.BeginAuthSession( ticketData, clientSteamId ) )
{
Assert.Fail( "BeginAuthSession returned false, called bullshit without even having to check with Gabe" );
}
Console.WriteLine( "steamid: {0}", steamid ); //
Console.WriteLine( "ownerid: {0}", ownerid ); // Wait for that to go through steam
Console.WriteLine( "status: {0}", status ); //
}; while ( !finished )
await Task.Delay( 10 );
for ( int i = 0; i < 16; i++ ) Assert.AreEqual( response, AuthSessionResponse.OK );
{
System.Threading.Thread.Sleep( 10 );
GC.Collect();
server.Update();
GC.Collect();
client.Update();
GC.Collect();
}
GC.Collect(); finished = false;
if ( !server.Auth.StartSession( ticketBinary, client.SteamId ) )
{
Assert.Fail( "Start Session returned false" );
}
GC.Collect();
// //
// Server should receive a ServerAuth.Status.OK // The client is leaving, and now wants to cancel the ticket
// message via the OnAuthChange callback //
//
for ( int i = 0; i< 100; i++ ) clientTicket.Cancel();
{
GC.Collect();
System.Threading.Thread.Sleep( 100 );
GC.Collect();
server.Update();
client.Update();
if ( Authed ) //
break; // We should get another callback
} //
while ( !finished )
await Task.Delay( 10 );
Assert.IsTrue( Authed ); Assert.AreEqual( response, AuthSessionResponse.AuthTicketCanceled );
// }
// Client cancels ticket
//
ticket.Cancel();
//
// Server should receive a ticket cancelled message
//
for ( int i = 0; i < 100; i++ )
{
System.Threading.Thread.Sleep( 100 );
server.Update();
client.Update();
if ( !Authed )
break;
}
Assert.IsTrue( !Authed );
}
}*/
}
} }
} }

View File

@ -27,6 +27,10 @@ public static class SteamApi
[DllImport( "Steam_api64", EntryPoint = "SteamAPI_RunCallbacks", CallingConvention = CallingConvention.Cdecl )] [DllImport( "Steam_api64", EntryPoint = "SteamAPI_RunCallbacks", CallingConvention = CallingConvention.Cdecl )]
public static extern int SteamAPI_RunCallbacks(); public static extern int SteamAPI_RunCallbacks();
[DllImport( "Steam_api64", EntryPoint = "SteamGameServer_RunCallbacks", CallingConvention = CallingConvention.Cdecl )]
public static extern int SteamGameServer_RunCallbacks();
[DllImport( "Steam_api64", EntryPoint = "SteamAPI_RegisterCallback", CallingConvention = CallingConvention.Cdecl )] [DllImport( "Steam_api64", EntryPoint = "SteamAPI_RegisterCallback", CallingConvention = CallingConvention.Cdecl )]
public static extern int RegisterCallback( IntPtr pCallback, int callback ); public static extern int RegisterCallback( IntPtr pCallback, int callback );

View File

@ -77,7 +77,7 @@ namespace Steamworks
await Task.Delay( 16 ); await Task.Delay( 16 );
try try
{ {
SteamApi.SteamAPI_RunCallbacks(); SteamApi.SteamGameServer_RunCallbacks();
} }
catch ( System.Exception ) catch ( System.Exception )
{ {