diff --git a/Facepunch.Steamworks/Callbacks/CallResult.cs b/Facepunch.Steamworks/Callbacks/CallResult.cs index 2850366..13fd500 100644 --- a/Facepunch.Steamworks/Callbacks/CallResult.cs +++ b/Facepunch.Steamworks/Callbacks/CallResult.cs @@ -15,10 +15,12 @@ internal struct CallResult : INotifyCompletion where T : struct, ICallbackDat { SteamAPICall_t call; ISteamUtils utils; + bool server; public CallResult( SteamAPICall_t call, bool server ) { this.call = call; + this.server = server; utils = (server ? SteamUtils.InterfaceServer : SteamUtils.InterfaceClient) as ISteamUtils; @@ -33,7 +35,7 @@ public CallResult( SteamAPICall_t call, bool server ) /// public void OnCompleted( Action continuation ) { - Dispatch.OnCallComplete( call, continuation ); + Dispatch.OnCallComplete( call, continuation, server ); } /// diff --git a/Facepunch.Steamworks/Classes/Dispatch.cs b/Facepunch.Steamworks/Classes/Dispatch.cs index a35920f..339b65e 100644 --- a/Facepunch.Steamworks/Classes/Dispatch.cs +++ b/Facepunch.Steamworks/Classes/Dispatch.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using Steamworks.Data; using Steamworks; +using System.Linq; namespace Steamworks { @@ -151,6 +152,7 @@ public static async void LoopServerAsync() struct ResultCallback { public Action continuation; + public bool server; } static Dictionary ResultCallbacks = new Dictionary(); @@ -158,11 +160,12 @@ struct ResultCallback /// /// Watch for a steam api call /// - internal static void OnCallComplete( SteamAPICall_t call, Action continuation ) + internal static void OnCallComplete( SteamAPICall_t call, Action continuation, bool server ) { ResultCallbacks[call.Value] = new ResultCallback { - continuation = continuation + continuation = continuation, + server = server }; } @@ -195,12 +198,30 @@ internal static void Install( Action p, bool server = false ) where T : IC } ); } - internal static void Wipe() + internal static void ShutdownServer() { - Callbacks = new Dictionary>(); - ResultCallbacks = new Dictionary(); - ClientPipe = 0; ServerPipe = 0; + + foreach ( var callback in Callbacks ) + { + Callbacks[callback.Key].RemoveAll( x => x.server ); + } + + ResultCallbacks = ResultCallbacks.Where( x => !x.Value.server ) + .ToDictionary( x => x.Key, x => x.Value ); + } + + internal static void ShutdownClient() + { + ClientPipe = 0; + + foreach ( var callback in Callbacks ) + { + Callbacks[callback.Key].RemoveAll( x => !x.server ); + } + + ResultCallbacks = ResultCallbacks.Where( x => x.Value.server ) + .ToDictionary( x => x.Key, x => x.Value ); } } } \ No newline at end of file diff --git a/Facepunch.Steamworks/SteamClient.cs b/Facepunch.Steamworks/SteamClient.cs index 73e7149..49b923b 100644 --- a/Facepunch.Steamworks/SteamClient.cs +++ b/Facepunch.Steamworks/SteamClient.cs @@ -102,10 +102,9 @@ public static void Shutdown() internal static void Cleanup() { - Dispatch.Wipe(); + Dispatch.ShutdownClient(); initialized = false; - ShutdownInterfaces(); } diff --git a/Facepunch.Steamworks/SteamServer.cs b/Facepunch.Steamworks/SteamServer.cs index 32ec298..eca72d8 100644 --- a/Facepunch.Steamworks/SteamServer.cs +++ b/Facepunch.Steamworks/SteamServer.cs @@ -145,6 +145,8 @@ internal static void ShutdownInterfaces() public static void Shutdown() { + Dispatch.ShutdownServer(); + ShutdownInterfaces(); SteamGameServer.Shutdown(); }