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