diff --git a/Facepunch.Steamworks/ServerList/Base.cs b/Facepunch.Steamworks/ServerList/Base.cs index ce447ca..1c883ed 100644 --- a/Facepunch.Steamworks/ServerList/Base.cs +++ b/Facepunch.Steamworks/ServerList/Base.cs @@ -20,7 +20,7 @@ internal static ISteamMatchmakingServers Internal if ( _internal == null ) { _internal = new ISteamMatchmakingServers(); - _internal.InitClient(); + _internal.Init(); } return _internal; diff --git a/Facepunch.Steamworks/SteamApps.cs b/Facepunch.Steamworks/SteamApps.cs index e7d95b1..f79eaaa 100644 --- a/Facepunch.Steamworks/SteamApps.cs +++ b/Facepunch.Steamworks/SteamApps.cs @@ -21,7 +21,7 @@ internal static ISteamApps Internal if ( _internal == null ) { _internal = new ISteamApps(); - _internal.InitClient(); + _internal.Init(); } return _internal; diff --git a/Facepunch.Steamworks/SteamClient.cs b/Facepunch.Steamworks/SteamClient.cs index b89d6fb..ec60c64 100644 --- a/Facepunch.Steamworks/SteamClient.cs +++ b/Facepunch.Steamworks/SteamClient.cs @@ -142,7 +142,5 @@ internal static void UnregisterCallback( IntPtr intPtr ) /// 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/SteamFriends.cs b/Facepunch.Steamworks/SteamFriends.cs index e7adaf8..e6bf019 100644 --- a/Facepunch.Steamworks/SteamFriends.cs +++ b/Facepunch.Steamworks/SteamFriends.cs @@ -20,7 +20,7 @@ internal static ISteamFriends Internal if ( _internal == null ) { _internal = new ISteamFriends(); - _internal.InitClient(); + _internal.Init(); richPresence = new Dictionary(); } diff --git a/Facepunch.Steamworks/SteamInventory.cs b/Facepunch.Steamworks/SteamInventory.cs index 59c7d3a..f123cd2 100644 --- a/Facepunch.Steamworks/SteamInventory.cs +++ b/Facepunch.Steamworks/SteamInventory.cs @@ -22,7 +22,7 @@ internal static ISteamInventory Internal if ( _internal == null ) { _internal = new ISteamInventory(); - _internal.InitClient(); + _internal.Init(); } return _internal; diff --git a/Facepunch.Steamworks/SteamMatchmaking.cs b/Facepunch.Steamworks/SteamMatchmaking.cs index 261c296..70d1458 100644 --- a/Facepunch.Steamworks/SteamMatchmaking.cs +++ b/Facepunch.Steamworks/SteamMatchmaking.cs @@ -13,6 +13,7 @@ namespace Steamworks public static class SteamMatchmaking { static ISteamMatchmaking _internal; + internal static ISteamMatchmaking Internal { get @@ -20,7 +21,6 @@ internal static ISteamMatchmaking Internal if ( _internal == null ) { _internal = new ISteamMatchmaking(); - _internal.InitClient(); } return _internal; diff --git a/Facepunch.Steamworks/SteamMusic.cs b/Facepunch.Steamworks/SteamMusic.cs index 27142e2..825d179 100644 --- a/Facepunch.Steamworks/SteamMusic.cs +++ b/Facepunch.Steamworks/SteamMusic.cs @@ -23,7 +23,7 @@ internal static ISteamMusic Internal if ( _internal == null ) { _internal = new ISteamMusic(); - _internal.InitClient(); + _internal.Init(); } return _internal; diff --git a/Facepunch.Steamworks/SteamNetworkingSockets.cs b/Facepunch.Steamworks/SteamNetworkingSockets.cs index aed7921..cf9e344 100644 --- a/Facepunch.Steamworks/SteamNetworkingSockets.cs +++ b/Facepunch.Steamworks/SteamNetworkingSockets.cs @@ -18,7 +18,7 @@ internal static ISteamNetworkingSockets Internal if ( _internal == null ) { _internal = new ISteamNetworkingSockets(); - _internal.InitClient(); + _internal.Init(); SocketInterfaces = new Dictionary(); ConnectionInterfaces = new Dictionary(); diff --git a/Facepunch.Steamworks/SteamParental.cs b/Facepunch.Steamworks/SteamParental.cs index 18fe938..b2c6e18 100644 --- a/Facepunch.Steamworks/SteamParental.cs +++ b/Facepunch.Steamworks/SteamParental.cs @@ -20,7 +20,7 @@ internal static ISteamParentalSettings Internal if ( _internal == null ) { _internal = new ISteamParentalSettings(); - _internal.InitClient(); + _internal.Init(); } return _internal; diff --git a/Facepunch.Steamworks/SteamParties.cs b/Facepunch.Steamworks/SteamParties.cs index 6a97770..c31b904 100644 --- a/Facepunch.Steamworks/SteamParties.cs +++ b/Facepunch.Steamworks/SteamParties.cs @@ -17,7 +17,7 @@ internal static ISteamParties Internal if ( _internal == null ) { _internal = new ISteamParties(); - _internal.InitClient(); + _internal.Init(); } return _internal; diff --git a/Facepunch.Steamworks/SteamRemoteStorage.cs b/Facepunch.Steamworks/SteamRemoteStorage.cs index c0287d8..d559ffa 100644 --- a/Facepunch.Steamworks/SteamRemoteStorage.cs +++ b/Facepunch.Steamworks/SteamRemoteStorage.cs @@ -20,7 +20,7 @@ internal static ISteamRemoteStorage Internal if ( _internal == null ) { _internal = new ISteamRemoteStorage(); - _internal.InitClient(); + _internal.Init(); } return _internal; diff --git a/Facepunch.Steamworks/SteamScreenshots.cs b/Facepunch.Steamworks/SteamScreenshots.cs index a3c69a9..f4ad5bd 100644 --- a/Facepunch.Steamworks/SteamScreenshots.cs +++ b/Facepunch.Steamworks/SteamScreenshots.cs @@ -20,7 +20,7 @@ internal static ISteamScreenshots Internal if ( _internal == null ) { _internal = new ISteamScreenshots(); - _internal.InitClient(); + _internal.Init(); } return _internal; diff --git a/Facepunch.Steamworks/SteamServer.cs b/Facepunch.Steamworks/SteamServer.cs index 8ebe476..7e82f77 100644 --- a/Facepunch.Steamworks/SteamServer.cs +++ b/Facepunch.Steamworks/SteamServer.cs @@ -75,7 +75,8 @@ public static void Init( AppId appid, SteamServerInit init ) DedicatedServer = true; InstallEvents(); - RunCallbacks(); + + RunCallbacksAsync(); } public static void Shutdown() @@ -92,16 +93,14 @@ public static void Shutdown() SteamGameServer.Shutdown(); } - - internal static async void RunCallbacks() + internal static async void RunCallbacksAsync() { - while ( true ) + while ( IsValid ) { await Task.Delay( 16 ); Update(); } } - public static void Update() { try @@ -373,7 +372,5 @@ public static unsafe void HandleIncomingPacket( byte[] data, int size, uint addr Internal.HandleIncomingPacket( (IntPtr)ptr, size, address, port ); } } - - public static IDisposable Push() => Realm.Server(); } } \ No newline at end of file diff --git a/Facepunch.Steamworks/SteamUgc.cs b/Facepunch.Steamworks/SteamUgc.cs index 47348ea..d430794 100644 --- a/Facepunch.Steamworks/SteamUgc.cs +++ b/Facepunch.Steamworks/SteamUgc.cs @@ -22,7 +22,7 @@ internal static ISteamUGC Internal if ( _internal == null ) { _internal = new ISteamUGC(); - _internal.InitClient(); + _internal.Init(); } return _internal; diff --git a/Facepunch.Steamworks/SteamUser.cs b/Facepunch.Steamworks/SteamUser.cs index 264b94b..5f43cfd 100644 --- a/Facepunch.Steamworks/SteamUser.cs +++ b/Facepunch.Steamworks/SteamUser.cs @@ -22,7 +22,7 @@ internal static ISteamUser Internal if ( _internal == null ) { _internal = new ISteamUser(); - _internal.InitClient(); + _internal.Init(); richPresence = new Dictionary(); diff --git a/Facepunch.Steamworks/SteamUserStats.cs b/Facepunch.Steamworks/SteamUserStats.cs index 0638275..3f93774 100644 --- a/Facepunch.Steamworks/SteamUserStats.cs +++ b/Facepunch.Steamworks/SteamUserStats.cs @@ -17,7 +17,7 @@ internal static ISteamUserStats Internal if ( _internal == null ) { _internal = new ISteamUserStats(); - _internal.InitClient(); + _internal.Init(); RequestCurrentStats(); } diff --git a/Facepunch.Steamworks/SteamUtils.cs b/Facepunch.Steamworks/SteamUtils.cs index 2726422..2cbf2ef 100644 --- a/Facepunch.Steamworks/SteamUtils.cs +++ b/Facepunch.Steamworks/SteamUtils.cs @@ -20,7 +20,7 @@ internal static ISteamUtils Internal if ( _internal == null ) { _internal = new ISteamUtils(); - _internal.InitClient(); + _internal.Init(); } return _internal; diff --git a/Facepunch.Steamworks/SteamVideo.cs b/Facepunch.Steamworks/SteamVideo.cs index 6d0269f..66c6c3f 100644 --- a/Facepunch.Steamworks/SteamVideo.cs +++ b/Facepunch.Steamworks/SteamVideo.cs @@ -20,7 +20,7 @@ internal static ISteamVideo Internal if ( _internal == null ) { _internal = new ISteamVideo(); - _internal.InitClient(); + _internal.Init(); } return _internal; diff --git a/Facepunch.Steamworks/Utility/Realm.cs b/Facepunch.Steamworks/Utility/Realm.cs deleted file mode 100644 index 3eb1f9e..0000000 --- a/Facepunch.Steamworks/Utility/Realm.cs +++ /dev/null @@ -1,43 +0,0 @@ -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(); - } - } - - } -} diff --git a/Facepunch.Steamworks/Utility/SteamInterface.cs b/Facepunch.Steamworks/Utility/SteamInterface.cs index 75ea132..a8e9f94 100644 --- a/Facepunch.Steamworks/Utility/SteamInterface.cs +++ b/Facepunch.Steamworks/Utility/SteamInterface.cs @@ -16,7 +16,24 @@ internal abstract class SteamInterface public virtual string InterfaceName => null; - public virtual void InitClient() + public void Init() + { + if ( SteamClient.IsValid ) + { + InitClient(); + return; + } + + if ( SteamServer.IsValid ) + { + InitServer(); + return; + } + + throw new System.Exception( "Trying to initialize Steam Interface but Steam not initialized" ); + } + + public void InitClient() { var user = SteamAPI.GetHSteamUser(); Self = SteamInternal.FindOrCreateUserInterface( user, InterfaceName ); @@ -31,7 +48,7 @@ public virtual void InitClient() InitInternals(); } - public virtual void InitServer() + public void InitServer() { var user = SteamGameServer.GetHSteamUser(); Self = SteamInternal.FindOrCreateGameServerInterface( user, InterfaceName );