diff --git a/Facepunch.Steamworks.Test/GameServerTest.cs b/Facepunch.Steamworks.Test/GameServerTest.cs index c858c4d..8320534 100644 --- a/Facepunch.Steamworks.Test/GameServerTest.cs +++ b/Facepunch.Steamworks.Test/GameServerTest.cs @@ -53,7 +53,7 @@ public async Task BeginAuthSession() // The client sends this data to the server along with their steamid // var ticketData = clientTicket.Data; - var clientSteamId = User.SteamID; + var clientSteamId = User.SteamId; // // Server listens to auth responses from Gabe diff --git a/Facepunch.Steamworks.Test/UserTest.cs b/Facepunch.Steamworks.Test/UserTest.cs index 3c1e54e..64f2fdd 100644 --- a/Facepunch.Steamworks.Test/UserTest.cs +++ b/Facepunch.Steamworks.Test/UserTest.cs @@ -53,8 +53,8 @@ public void IsLoggedOn() [TestMethod] public void SteamID() { - Assert.AreNotEqual( 0, User.SteamID.Value ); - Console.WriteLine( $"User.SteamID: {User.SteamID.Value}" ); + Assert.AreNotEqual( 0, User.SteamId.Value ); + Console.WriteLine( $"User.SteamID: {User.SteamId.Value}" ); } [TestMethod] @@ -67,11 +67,11 @@ public void AuthSession() Console.WriteLine( $"ticket.Handle: {ticket.Handle}" ); Console.WriteLine( $"ticket.Data: { string.Join( "", ticket.Data.Select( x => x.ToString( "x" ) ) ) }" ); - var result = User.BeginAuthSession( ticket.Data, User.SteamID ); + var result = User.BeginAuthSession( ticket.Data, User.SteamId ); Console.WriteLine( $"result: { result }" ); Assert.AreEqual( result, SteamNative.BeginAuthSessionResult.OK ); - User.EndAuthSession( User.SteamID ); + User.EndAuthSession( User.SteamId ); } diff --git a/Facepunch.Steamworks/Redux/GameServer.cs b/Facepunch.Steamworks/Redux/GameServer.cs index f5629ae..8aafa69 100644 --- a/Facepunch.Steamworks/Redux/GameServer.cs +++ b/Facepunch.Steamworks/Redux/GameServer.cs @@ -13,6 +13,8 @@ namespace Steamworks /// public static partial class GameServer { + static bool initialized; + static Internal.ISteamGameServer _internal; internal static Internal.ISteamGameServer Internal { @@ -25,6 +27,8 @@ internal static Internal.ISteamGameServer Internal } } + public static bool IsValid => initialized; + internal static void InstallEvents() { new Event( x => OnValidateAuthTicketResponse?.Invoke( x.SteamID, x.OwnerSteamID, x.AuthSessionResponse ), true ); @@ -53,6 +57,8 @@ public static void Init( AppId appid, ServerInit init ) throw new System.Exception( "InitGameServer returned false" ); } + initialized = true; + // // Initial settings // @@ -69,20 +75,30 @@ public static void Init( AppId appid, ServerInit init ) RunCallbacks(); } + public static void Shutdown() + { + initialized = false; + } + internal static async void RunCallbacks() { while ( true ) { await Task.Delay( 16 ); - try - { - SteamApi.SteamGameServer_RunCallbacks(); - } - catch ( System.Exception ) - { - // TODO - error outputs - } + Update(); + } + } + + public static void Update() + { + try + { + SteamApi.SteamGameServer_RunCallbacks(); + } + catch ( System.Exception ) + { + // TODO - error outputs } } diff --git a/Facepunch.Steamworks/Redux/Steam.cs b/Facepunch.Steamworks/Redux/Steam.cs index 4431322..84a1cb8 100644 --- a/Facepunch.Steamworks/Redux/Steam.cs +++ b/Facepunch.Steamworks/Redux/Steam.cs @@ -8,7 +8,7 @@ namespace Steamworks { public static class Steam { - internal static int HUser; + static bool initialized; public static void Init( uint appid ) { @@ -25,11 +25,7 @@ public static void Init( uint appid ) throw new System.Exception( "SteamApi_Init returned false. Steam isn't running, couldn't find Steam, AppId is ureleased, Don't own AppId." ); } - HUser = SteamApi.GetHSteamUser(); - if ( HUser == 0 ) - { - throw new System.Exception( "GetHSteamUser returned 0" ); - } + initialized = true; Apps.InstallEvents(); Utils.InstallEvents(); @@ -42,6 +38,8 @@ public static void Init( uint appid ) RunCallbacks(); } + public static bool IsValid => initialized; + internal static async void RunCallbacks() { while ( true ) diff --git a/Facepunch.Steamworks/Redux/User.cs b/Facepunch.Steamworks/Redux/User.cs index 15d0f57..20bc79f 100644 --- a/Facepunch.Steamworks/Redux/User.cs +++ b/Facepunch.Steamworks/Redux/User.cs @@ -118,7 +118,7 @@ internal static void InstallEvents() /// A Steam ID is a unique identifier for a Steam accounts, Steam groups, Lobbies and Chat /// rooms, and used to differentiate users in all parts of the Steamworks API. /// - public static CSteamID SteamID => Internal.GetSteamID(); + public static CSteamID SteamId => Internal.GetSteamID(); static bool _recordingVoice;