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 @@ namespace Steamworks
{ {
SteamAPICall_t call; SteamAPICall_t call;
ISteamUtils utils; ISteamUtils utils;
bool server;
public CallResult( SteamAPICall_t call, bool server ) public CallResult( SteamAPICall_t call, bool server )
{ {
this.call = call; this.call = call;
this.server = server;
utils = (server ? SteamUtils.InterfaceServer : SteamUtils.InterfaceClient) as ISteamUtils; utils = (server ? SteamUtils.InterfaceServer : SteamUtils.InterfaceClient) as ISteamUtils;
@ -33,7 +35,7 @@ namespace Steamworks
/// </summary> /// </summary>
public void OnCompleted( Action continuation ) public void OnCompleted( Action continuation )
{ {
Dispatch.OnCallComplete( call, continuation ); Dispatch.OnCallComplete( call, continuation, server );
} }
/// <summary> /// <summary>

View File

@ -4,6 +4,7 @@ using System.Runtime.InteropServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using Steamworks.Data; using Steamworks.Data;
using Steamworks; using Steamworks;
using System.Linq;
namespace Steamworks namespace Steamworks
{ {
@ -151,6 +152,7 @@ namespace Steamworks
struct ResultCallback struct ResultCallback
{ {
public Action continuation; public Action continuation;
public bool server;
} }
static Dictionary<ulong, ResultCallback> ResultCallbacks = new Dictionary<ulong, ResultCallback>(); static Dictionary<ulong, ResultCallback> ResultCallbacks = new Dictionary<ulong, ResultCallback>();
@ -158,11 +160,12 @@ namespace Steamworks
/// <summary> /// <summary>
/// Watch for a steam api call /// Watch for a steam api call
/// </summary> /// </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 ResultCallbacks[call.Value] = new ResultCallback
{ {
continuation = continuation continuation = continuation,
server = server
}; };
} }
@ -195,12 +198,30 @@ namespace Steamworks
} ); } );
} }
internal static void Wipe() internal static void ShutdownServer()
{ {
Callbacks = new Dictionary<CallbackType, List<Callback>>();
ResultCallbacks = new Dictionary<ulong, ResultCallback>();
ClientPipe = 0;
ServerPipe = 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 @@ namespace Steamworks
internal static void Cleanup() internal static void Cleanup()
{ {
Dispatch.Wipe(); Dispatch.ShutdownClient();
initialized = false; initialized = false;
ShutdownInterfaces(); ShutdownInterfaces();
} }

View File

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