Shutdown dispatch on server/client close

This commit is contained in:
Garry Newman 2020-02-25 12:32:12 +00:00
parent 895e11e801
commit f191ee5e42
4 changed files with 33 additions and 9 deletions

View File

@ -15,10 +15,12 @@ internal struct CallResult<T> : 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 )
/// </summary>
public void OnCompleted( Action continuation )
{
Dispatch.OnCallComplete( call, continuation );
Dispatch.OnCallComplete( call, continuation, server );
}
/// <summary>

View File

@ -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<ulong, ResultCallback> ResultCallbacks = new Dictionary<ulong, ResultCallback>();
@ -158,11 +160,12 @@ struct ResultCallback
/// <summary>
/// Watch for a steam api call
/// </summary>
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<T>( Action<T> p, bool server = false ) where T : IC
} );
}
internal static void Wipe()
internal static void ShutdownServer()
{
Callbacks = new Dictionary<CallbackType, List<Callback>>();
ResultCallbacks = new Dictionary<ulong, ResultCallback>();
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 );
}
}
}

View File

@ -102,10 +102,9 @@ public static void Shutdown()
internal static void Cleanup()
{
Dispatch.Wipe();
Dispatch.ShutdownClient();
initialized = false;
ShutdownInterfaces();
}

View File

@ -145,6 +145,8 @@ internal static void ShutdownInterfaces()
public static void Shutdown()
{
Dispatch.ShutdownServer();
ShutdownInterfaces();
SteamGameServer.Shutdown();
}