Auth ticket

This commit is contained in:
Garry Newman 2016-07-07 14:04:15 +01:00
parent f39341d90f
commit 2caf093e6d
4 changed files with 72 additions and 1 deletions

View File

@ -40,5 +40,22 @@ public void ClientSteamId()
Assert.AreNotEqual( 0, steamid );
}
}
[TestMethod]
public void ClientAuthSessionTicket()
{
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
{
var ticket = client.GetAuthSessionTicket();
Assert.IsTrue( ticket != null );
Assert.IsTrue( ticket.Handle != 0 );
Assert.IsTrue( ticket.Data.Length > 0 );
client.CancelAuthTicket( ticket );
Assert.IsTrue( ticket.Handle == 0 );
}
}
}
}

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Facepunch.Steamworks
{
public partial class Client : IDisposable
{
public class AuthTicket
{
public byte[] Data;
public uint Handle;
}
/// <summary>
/// Creates an auth ticket.
/// Which you can send to a server to authenticate that you are who you say you are.
/// </summary>
public unsafe AuthTicket GetAuthSessionTicket()
{
var data = new byte[1024];
fixed ( byte* b = data )
{
uint ticketLength = 0;
uint ticket = _user.GetAuthSessionTicket( (IntPtr) b, data.Length, ref ticketLength );
if ( ticket == 0 )
return null;
return new AuthTicket()
{
Data = data.Take( (int)ticketLength ).ToArray(),
Handle = ticket
};
}
}
/// <summary>
/// Cancels a ticket.
/// You should cancel your ticket when you close the game or leave a server.
/// </summary>
public void CancelAuthTicket( AuthTicket ticket )
{
_user.CancelAuthTicket( ticket.Handle );
ticket.Handle = 0;
ticket.Data = null;
}
}
}

View File

@ -5,7 +5,7 @@
namespace Facepunch.Steamworks
{
public class Client : IDisposable
public partial class Client : IDisposable
{
private Valve.Steamworks.ISteamClient _client;
private uint _hpipe;

View File

@ -21,6 +21,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@ -31,6 +32,7 @@
<WarningLevel>4</WarningLevel>
<DocumentationFile>
</DocumentationFile>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
@ -41,6 +43,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Client.Auth.cs" />
<Compile Include="Client.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="steam_api_interop.cs" />