Server authentication boiler

This commit is contained in:
Garry Newman 2016-10-03 12:06:30 +01:00
parent 458355b546
commit c2270c6840
4 changed files with 96 additions and 10 deletions

View File

@ -14,10 +14,52 @@ public class Server
[TestMethod]
public void Init()
{
using ( var server = new Facepunch.Steamworks.Server( 252490, 0, 20216, 20816, 20817, false, "VersionString" ) )
using ( var server = new Facepunch.Steamworks.Server( 252490, 30000, 30001, 30002, 30003, false, "VersionString" ) )
{
Assert.IsTrue( server.Valid );
}
}
[TestMethod]
public void AuthCallback()
{
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
{
Assert.IsTrue( client.Valid );
var ticket = client.Auth.GetAuthSessionTicket();
var ticketBinary = ticket.Data;
using ( var server = new Facepunch.Steamworks.Server( 252490, 30000, 30001, 30002, 30003, false, "VersionString" ) )
{
Assert.IsTrue( server.Valid );
for ( int i = 0; i < 16; i++ )
{
System.Threading.Thread.Sleep( 10 );
server.Update();
client.Update();
}
if ( !server.Auth.StartSession( ticketBinary, client.SteamId ) )
{
Assert.Fail( "Start Session returned false" );
}
for( int i = 0; i<16; i++ )
{
System.Threading.Thread.Sleep( 10 );
server.Update();
client.Update();
}
//
// Client cancels ticket
//
ticket.Cancel();
}
}
}
}
}

View File

@ -132,10 +132,9 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Interop\steam_api_interop.cs" />
<Compile Include="Server.cs" />
<Compile Include="Server\Auth.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Server\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>

View File

@ -101,12 +101,7 @@ public enum MessageType : int
public Server( uint appId, uint IpAddress, ushort SteamPort, ushort GamePort, ushort QueryPort, bool Secure, string VersionString )
{
if ( !Valve.Interop.NativeEntrypoints.Extended.SteamInternal_GameServer_Init( IpAddress, SteamPort, GamePort, QueryPort, Secure ? 3 : 2 , VersionString ) )
{
return;
}
//Valve.Steamworks.SteamAPI.Init( appId );
Valve.Interop.NativeEntrypoints.Extended.SteamInternal_GameServer_Init( IpAddress, SteamPort, GamePort, QueryPort, Secure ? 3 : 2, VersionString );
native = new Internal();

View File

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Facepunch.Steamworks
{
public partial class Server
{
ServerAuth _auth;
public ServerAuth Auth
{
get
{
if ( _auth == null )
_auth = new ServerAuth { server = this };
return _auth;
}
}
}
public class ServerAuth
{
internal Server server;
/// <summary>
/// Start authorizing a ticket
/// </summary>
public unsafe bool StartSession( byte[] data, ulong steamid )
{
fixed ( byte* p = data )
{
var result = (Valve.Steamworks.EBeginAuthSessionResult) server.native.gameServer.BeginAuthSession( (IntPtr)p, data.Length, steamid );
if ( result == Valve.Steamworks.EBeginAuthSessionResult.k_EBeginAuthSessionResultOK )
return true;
return false;
}
}
public void EndSession( ulong steamid )
{
server.native.gameServer.EndAuthSession( steamid );
}
}
}