From 3844c74d9ce2631aa27398d2fb5c883a495982f3 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Thu, 7 Jul 2016 14:11:23 +0100 Subject: [PATCH] Cleanup --- Facepunch.Steamworks.Test/Client.cs | 4 ++-- Facepunch.Steamworks/Client.Auth.cs | 32 ++++++++++++++++++++++------- Facepunch.Steamworks/Client.cs | 7 ++++--- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/Facepunch.Steamworks.Test/Client.cs b/Facepunch.Steamworks.Test/Client.cs index a18bf88..9f1809e 100644 --- a/Facepunch.Steamworks.Test/Client.cs +++ b/Facepunch.Steamworks.Test/Client.cs @@ -46,13 +46,13 @@ public void ClientAuthSessionTicket() { using ( var client = new Facepunch.Steamworks.Client( 252490 ) ) { - var ticket = client.GetAuthSessionTicket(); + var ticket = client.Auth.GetAuthSessionTicket(); Assert.IsTrue( ticket != null ); Assert.IsTrue( ticket.Handle != 0 ); Assert.IsTrue( ticket.Data.Length > 0 ); - client.CancelAuthTicket( ticket ); + client.Auth.CancelAuthTicket( ticket ); Assert.IsTrue( ticket.Handle == 0 ); } diff --git a/Facepunch.Steamworks/Client.Auth.cs b/Facepunch.Steamworks/Client.Auth.cs index cb2f440..0e72aec 100644 --- a/Facepunch.Steamworks/Client.Auth.cs +++ b/Facepunch.Steamworks/Client.Auth.cs @@ -7,7 +7,25 @@ namespace Facepunch.Steamworks { public partial class Client : IDisposable { - public class AuthTicket + Auth _auth; + + public Auth Auth + { + get + { + if ( _auth == null ) + _auth = new Auth{ client = this }; + + return _auth; + } + } + } + + public class Auth + { + internal Client client; + + public class Ticket { public byte[] Data; public uint Handle; @@ -17,19 +35,19 @@ public class AuthTicket /// Creates an auth ticket. /// Which you can send to a server to authenticate that you are who you say you are. /// - public unsafe AuthTicket GetAuthSessionTicket() + public unsafe Ticket GetAuthSessionTicket() { var data = new byte[1024]; - + fixed ( byte* b = data ) { uint ticketLength = 0; - uint ticket = _user.GetAuthSessionTicket( (IntPtr) b, data.Length, ref ticketLength ); + uint ticket = client._user.GetAuthSessionTicket( (IntPtr) b, data.Length, ref ticketLength ); if ( ticket == 0 ) return null; - return new AuthTicket() + return new Ticket() { Data = data.Take( (int)ticketLength ).ToArray(), Handle = ticket @@ -41,9 +59,9 @@ public unsafe AuthTicket GetAuthSessionTicket() /// Cancels a ticket. /// You should cancel your ticket when you close the game or leave a server. /// - public void CancelAuthTicket( AuthTicket ticket ) + public void CancelAuthTicket( Ticket ticket ) { - _user.CancelAuthTicket( ticket.Handle ); + client._user.CancelAuthTicket( ticket.Handle ); ticket.Handle = 0; ticket.Data = null; } diff --git a/Facepunch.Steamworks/Client.cs b/Facepunch.Steamworks/Client.cs index 8f2aaea..af072b9 100644 --- a/Facepunch.Steamworks/Client.cs +++ b/Facepunch.Steamworks/Client.cs @@ -7,11 +7,12 @@ namespace Facepunch.Steamworks { public partial class Client : IDisposable { - private Valve.Steamworks.ISteamClient _client; private uint _hpipe; private uint _huser; - private Valve.Steamworks.ISteamUser _user; - private Valve.Steamworks.ISteamFriends _friends; + + internal Valve.Steamworks.ISteamClient _client; + internal Valve.Steamworks.ISteamUser _user; + internal Valve.Steamworks.ISteamFriends _friends; /// /// Current running program's AppId