mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-24 13:45:37 +03:00
Auth ticket
This commit is contained in:
parent
f39341d90f
commit
2caf093e6d
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
51
Facepunch.Steamworks/Client.Auth.cs
Normal file
51
Facepunch.Steamworks/Client.Auth.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
|
||||
namespace Facepunch.Steamworks
|
||||
{
|
||||
public class Client : IDisposable
|
||||
public partial class Client : IDisposable
|
||||
{
|
||||
private Valve.Steamworks.ISteamClient _client;
|
||||
private uint _hpipe;
|
||||
|
@ -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" />
|
||||
|
Loading…
Reference in New Issue
Block a user