From a0d9fdeab144be6081c02a1086d70f730f5cd7ae Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Mon, 6 May 2019 15:45:01 +0100 Subject: [PATCH] Added Steamworks.Realm --- Facepunch.Steamworks/SteamClient.cs | 3 +- Facepunch.Steamworks/SteamServer.cs | 13 ++++---- Facepunch.Steamworks/Utility/Realm.cs | 43 +++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 Facepunch.Steamworks/Utility/Realm.cs diff --git a/Facepunch.Steamworks/SteamClient.cs b/Facepunch.Steamworks/SteamClient.cs index 4ccd798..b89d6fb 100644 --- a/Facepunch.Steamworks/SteamClient.cs +++ b/Facepunch.Steamworks/SteamClient.cs @@ -29,7 +29,6 @@ namespace Steamworks initialized = true; - SteamApps.InstallEvents(); SteamUtils.InstallEvents(); SteamParental.InstallEvents(); @@ -143,5 +142,7 @@ namespace Steamworks /// returns the appID of the current process /// public static AppId AppId { get; internal set; } + + public static IDisposable Push() => Realm.Client(); } } \ No newline at end of file diff --git a/Facepunch.Steamworks/SteamServer.cs b/Facepunch.Steamworks/SteamServer.cs index 60e6a0c..8ebe476 100644 --- a/Facepunch.Steamworks/SteamServer.cs +++ b/Facepunch.Steamworks/SteamServer.cs @@ -35,7 +35,6 @@ namespace Steamworks { ValidateAuthTicketResponse_t.Install( x => OnValidateAuthTicketResponse?.Invoke( x.SteamID, x.OwnerSteamID, x.AuthSessionResponse ), true ); - SteamServerInventory.InstallEvents(); } /// @@ -87,10 +86,10 @@ namespace Steamworks _internal = null; - SteamServerInventory.Shutdown(); - SteamGameServer.Shutdown(); SteamNetworkingUtils.Shutdown(); SteamNetworkingSockets.Shutdown(); + + SteamGameServer.Shutdown(); } @@ -282,7 +281,7 @@ namespace Steamworks /// any time a player's name or score changes. This keeps the information shown /// to server queries up to date. /// - public static void UpdatePlayer( ulong steamid, string name, int score ) + public static void UpdatePlayer( SteamId steamid, string name, int score ) { Internal.BUpdateUserData( steamid, name, (uint)score ); } @@ -315,7 +314,7 @@ namespace Steamworks /// /// Start authorizing a ticket. This user isn't authorized yet. Wait for a call to OnAuthChange. /// - public static unsafe bool BeginAuthSession( byte[] data, ulong steamid ) + public static unsafe bool BeginAuthSession( byte[] data, SteamId steamid ) { fixed ( byte* p = data ) { @@ -331,7 +330,7 @@ namespace Steamworks /// /// Forget this guy. They're no longer in the game. /// - public static void EndSession( ulong steamid ) + public static void EndSession( SteamId steamid ) { Internal.EndAuthSession( steamid ); } @@ -374,5 +373,7 @@ namespace Steamworks Internal.HandleIncomingPacket( (IntPtr)ptr, size, address, port ); } } + + public static IDisposable Push() => Realm.Server(); } } \ No newline at end of file diff --git a/Facepunch.Steamworks/Utility/Realm.cs b/Facepunch.Steamworks/Utility/Realm.cs new file mode 100644 index 0000000..3eb1f9e --- /dev/null +++ b/Facepunch.Steamworks/Utility/Realm.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Text; + +namespace Steamworks +{ + public static class Realm + { + // + // true = serverside + // + static Stack _stack = new Stack(); + + public static bool IsServer => _stack.Count > 0 && _stack.Peek(); + + public static bool IsClient => _stack.Count == 0 || !_stack.Peek(); + + + static public IDisposable Server() + { + _stack.Push( true ); + return new StackPopper(); + } + + static public IDisposable Client() + { + _stack.Push( false ); + return new StackPopper(); + } + + public struct StackPopper : IDisposable + { + public void Dispose() + { + _stack.Pop(); + } + } + + } +}