mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-01-26 13:38:06 +03:00
Auth ticket
This commit is contained in:
parent
f39341d90f
commit
2caf093e6d
@ -40,5 +40,22 @@ namespace Facepunch.Steamworks.Test
|
|||||||
Assert.AreNotEqual( 0, steamid );
|
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 @@ using System.Runtime.InteropServices;
|
|||||||
|
|
||||||
namespace Facepunch.Steamworks
|
namespace Facepunch.Steamworks
|
||||||
{
|
{
|
||||||
public class Client : IDisposable
|
public partial class Client : IDisposable
|
||||||
{
|
{
|
||||||
private Valve.Steamworks.ISteamClient _client;
|
private Valve.Steamworks.ISteamClient _client;
|
||||||
private uint _hpipe;
|
private uint _hpipe;
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
@ -31,6 +32,7 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<DocumentationFile>
|
<DocumentationFile>
|
||||||
</DocumentationFile>
|
</DocumentationFile>
|
||||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
@ -41,6 +43,7 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Client.Auth.cs" />
|
||||||
<Compile Include="Client.cs" />
|
<Compile Include="Client.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="steam_api_interop.cs" />
|
<Compile Include="steam_api_interop.cs" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user