mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 14:15:47 +03:00
Server authentication boiler
This commit is contained in:
parent
458355b546
commit
c2270c6840
@ -14,10 +14,52 @@ public class Server
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Init()
|
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 );
|
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();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,10 +132,9 @@
|
|||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Interop\steam_api_interop.cs" />
|
<Compile Include="Interop\steam_api_interop.cs" />
|
||||||
<Compile Include="Server.cs" />
|
<Compile Include="Server.cs" />
|
||||||
|
<Compile Include="Server\Auth.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup />
|
||||||
<Folder Include="Server\" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PostBuildEvent>
|
<PostBuildEvent>
|
||||||
|
@ -101,12 +101,7 @@ public enum MessageType : int
|
|||||||
|
|
||||||
public Server( uint appId, uint IpAddress, ushort SteamPort, ushort GamePort, ushort QueryPort, bool Secure, string VersionString )
|
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 ) )
|
Valve.Interop.NativeEntrypoints.Extended.SteamInternal_GameServer_Init( IpAddress, SteamPort, GamePort, QueryPort, Secure ? 3 : 2, VersionString );
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Valve.Steamworks.SteamAPI.Init( appId );
|
|
||||||
|
|
||||||
native = new Internal();
|
native = new Internal();
|
||||||
|
|
||||||
|
50
Facepunch.Steamworks/Server/Auth.cs
Normal file
50
Facepunch.Steamworks/Server/Auth.cs
Normal 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 );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user