mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 14:15:47 +03:00
expose server steamid, test server -> client auth
This commit is contained in:
parent
dfa04d1a70
commit
5c9e239bc6
@ -60,92 +60,126 @@ public void PublicIp()
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AuthCallback()
|
||||
public void AuthenticateAClient()
|
||||
{
|
||||
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
||||
using ( var server = new Facepunch.Steamworks.Server( 252490, new ServerInit( "rust", "Rust" ) ) )
|
||||
{
|
||||
Assert.IsTrue( client.IsValid );
|
||||
var ticket = client.Auth.GetAuthSessionTicket();
|
||||
var ticketBinary = ticket.Data;
|
||||
Assert.IsTrue( server.IsValid );
|
||||
|
||||
using ( var server = new Facepunch.Steamworks.Server( 252490, new ServerInit( "rust", "Rust" ) ) )
|
||||
server.LogOnAnonymous();
|
||||
|
||||
for ( int i = 0; i < 100; i++ )
|
||||
{
|
||||
server.LogOnAnonymous();
|
||||
|
||||
Assert.IsTrue( server.IsValid );
|
||||
|
||||
var auth = server.Auth;
|
||||
|
||||
var Authed = false;
|
||||
|
||||
server.Auth.OnAuthChange = ( steamid, ownerid, status ) =>
|
||||
{
|
||||
Authed = status == Auth.AuthStatus.OK;
|
||||
|
||||
Assert.AreEqual( steamid, client.SteamId );
|
||||
Assert.AreEqual( steamid, ownerid );
|
||||
|
||||
Console.WriteLine( "steamid: {0}", steamid );
|
||||
Console.WriteLine( "ownerid: {0}", ownerid );
|
||||
Console.WriteLine( "status: {0}", status );
|
||||
};
|
||||
|
||||
for ( int i = 0; i < 16; i++ )
|
||||
{
|
||||
System.Threading.Thread.Sleep( 10 );
|
||||
GC.Collect();
|
||||
server.Update();
|
||||
GC.Collect();
|
||||
client.Update();
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
GC.Collect();
|
||||
var startStatus = server.Auth.StartSession( ticketBinary, client.SteamId );
|
||||
Assert.IsTrue( startStatus == Auth.StartAuthResult.OK );
|
||||
GC.Collect();
|
||||
|
||||
//
|
||||
// Server should receive a ServerAuth.Status.OK
|
||||
// message via the OnAuthChange callback
|
||||
//
|
||||
|
||||
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 );
|
||||
|
||||
//
|
||||
// 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 );
|
||||
System.Threading.Thread.Sleep( 16 );
|
||||
server.Update();
|
||||
client.Update();
|
||||
|
||||
if ( server.SteamId != null )
|
||||
break;
|
||||
}
|
||||
|
||||
Assert.IsNotNull( server.SteamId );
|
||||
|
||||
var ticket = client.Auth.GetAuthSessionTicket();
|
||||
var status = server.Auth.StartSession( ticket.Data, client.SteamId );
|
||||
|
||||
Assert.IsTrue( status == Auth.StartAuthResult.OK );
|
||||
|
||||
bool isAuthed = false;
|
||||
|
||||
server.Auth.OnAuthChange += ( steamId, ownerId, authStatus ) => {
|
||||
isAuthed = authStatus == Auth.AuthStatus.OK;
|
||||
};
|
||||
|
||||
for ( int i = 0; i < 100; i++ )
|
||||
{
|
||||
System.Threading.Thread.Sleep( 16 );
|
||||
server.Update();
|
||||
client.Update();
|
||||
|
||||
if ( isAuthed )
|
||||
break;
|
||||
}
|
||||
|
||||
Assert.IsTrue( isAuthed );
|
||||
|
||||
ticket.Cancel();
|
||||
|
||||
for ( int i = 0; i < 100; i++ )
|
||||
{
|
||||
System.Threading.Thread.Sleep( 16 );
|
||||
server.Update();
|
||||
client.Update();
|
||||
|
||||
if ( !isAuthed )
|
||||
break;
|
||||
}
|
||||
|
||||
Assert.IsFalse( isAuthed );
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AuthenticateAServer()
|
||||
{
|
||||
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
||||
using ( var server = new Facepunch.Steamworks.Server( 4000, new ServerInit( "rust", "Rust" ) ) )
|
||||
{
|
||||
Assert.IsTrue( client.IsValid );
|
||||
Assert.IsTrue( server.IsValid );
|
||||
|
||||
server.LogOnAnonymous();
|
||||
|
||||
for ( int i = 0; i < 100; i++ )
|
||||
{
|
||||
System.Threading.Thread.Sleep( 16 );
|
||||
server.Update();
|
||||
client.Update();
|
||||
|
||||
if ( server.SteamId != null )
|
||||
break;
|
||||
}
|
||||
|
||||
Assert.IsNotNull( server.SteamId );
|
||||
|
||||
var ticket = server.Auth.GetAuthSessionTicket();
|
||||
var status = client.Auth.StartSession( ticket.Data, server.SteamId.Value );
|
||||
|
||||
Assert.IsTrue( status == Auth.StartAuthResult.OK );
|
||||
|
||||
bool isAuthed = false;
|
||||
|
||||
client.Auth.OnAuthChange += ( steamId, ownerId, authStatus ) => {
|
||||
isAuthed = authStatus == Auth.AuthStatus.OK;
|
||||
};
|
||||
|
||||
for ( int i = 0; i < 100; i++ )
|
||||
{
|
||||
System.Threading.Thread.Sleep( 16 );
|
||||
server.Update();
|
||||
client.Update();
|
||||
|
||||
if ( isAuthed )
|
||||
break;
|
||||
}
|
||||
|
||||
Assert.IsTrue( isAuthed );
|
||||
|
||||
ticket.Cancel();
|
||||
|
||||
for ( int i = 0; i < 100; i++ )
|
||||
{
|
||||
System.Threading.Thread.Sleep( 16 );
|
||||
server.Update();
|
||||
client.Update();
|
||||
|
||||
if ( !isAuthed )
|
||||
break;
|
||||
}
|
||||
|
||||
Assert.IsFalse( isAuthed );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ public class BaseSteamworks : IDisposable
|
||||
/// <summary>
|
||||
/// Current running program's AppId
|
||||
/// </summary>
|
||||
public uint AppId { get; internal set; }
|
||||
public uint AppId { get; private set; }
|
||||
|
||||
public Auth Auth { get; internal set; }
|
||||
public Networking Networking { get; internal set; }
|
||||
|
@ -19,7 +19,7 @@ public partial class Client : BaseSteamworks
|
||||
/// <summary>
|
||||
/// Current user's SteamId
|
||||
/// </summary>
|
||||
public ulong SteamId { get; private set; }
|
||||
public ulong SteamId { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// If we're sharing this game, this is the owner of it.
|
||||
@ -123,7 +123,6 @@ public Client( uint appId ) : base( appId )
|
||||
//
|
||||
// Cache common, unchanging info
|
||||
//
|
||||
AppId = appId;
|
||||
Username = native.friends.GetPersonaName();
|
||||
SteamId = native.user.GetSteamID();
|
||||
BetaName = native.apps.GetCurrentBetaName();
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using SteamNative;
|
||||
|
||||
namespace Facepunch.Steamworks
|
||||
{
|
||||
@ -15,6 +16,11 @@ public partial class Server : BaseSteamworks
|
||||
/// </summary>
|
||||
public static Server Instance { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Serversd 's SteamId. Only set once logged in with Steam
|
||||
/// </summary>
|
||||
public ulong? SteamId { get; internal set; }
|
||||
|
||||
internal override bool IsGameServer { get { return true; } }
|
||||
|
||||
public ServerQuery Query { get; internal set; }
|
||||
@ -78,6 +84,8 @@ public Server( uint appId, ServerInit init) : base( appId )
|
||||
Query = new ServerQuery( this );
|
||||
Stats = new ServerStats( this );
|
||||
|
||||
RegisterCallback<SteamNative.SteamServersConnected_t>( OnSteamServersConnected );
|
||||
|
||||
//
|
||||
// Run update, first call does some initialization
|
||||
//
|
||||
@ -330,6 +338,9 @@ public void ForceHeartbeat()
|
||||
native.gameServer.ForceHeartbeat();
|
||||
}
|
||||
|
||||
|
||||
private void OnSteamServersConnected( SteamServersConnected_t p )
|
||||
{
|
||||
SteamId = native.gameServer.GetSteamID();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user