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

View File

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