Adds gateway support including SingalR

This commit is contained in:
Kamron Batman 2026-03-30 18:52:28 -07:00
parent c207c2c19f
commit fde85a5f7c
No known key found for this signature in database
GPG key ID: 7D81DF26D9A5D94A
13 changed files with 692 additions and 2 deletions

View file

@ -50,6 +50,7 @@ public static class Core
private static int _itemCount;
private static int _mobileCount;
public static EventLoopContext LoopContext { get; set; }
public static TaskScheduler LoopContextTaskScheduler { get; set; }
private static readonly Type[] _serialTypeArray = { typeof(Serial) };
@ -372,6 +373,7 @@ public static class Core
Thread = Thread.CurrentThread;
LoopContext = new EventLoopContext();
SynchronizationContext.SetSynchronizationContext(LoopContext);
LoopContextTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;

View file

@ -0,0 +1,48 @@
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Server.Tasks;
public static class TaskExtensions
{
public static void OnFaultedCurrentSyncContext(this Task task, Action<Task> onFaulted, CancellationToken cancellationToken = default)
{
var scheduler = TaskScheduler.FromCurrentSynchronizationContext();
task.ContinueWith(onFaulted, cancellationToken, TaskContinuationOptions.OnlyOnFaulted, scheduler);
}
public static void ContinueWithOnCurrentSyncContext<T>(
this Task<T> task,
Action<Task<T>> onRanToCompletion,
Action<Task<T>> onFaulted,
CancellationToken cancellationToken = default
)
{
var scheduler = TaskScheduler.FromCurrentSynchronizationContext();
task.ContinueWith(onRanToCompletion, cancellationToken, TaskContinuationOptions.OnlyOnRanToCompletion, scheduler);
task.ContinueWith(onFaulted, cancellationToken, TaskContinuationOptions.OnlyOnFaulted, scheduler);
}
public static void ContinueWithOnCurrentSyncContext<T>(
this Task<T> task,
Action<Task<T>> onCompletion,
CancellationToken cancellationToken = default
)
{
var scheduler = TaskScheduler.FromCurrentSynchronizationContext();
task.ContinueWith(onCompletion, cancellationToken, TaskContinuationOptions.None, scheduler);
}
public static void ContinueWithOnGameThread<T>(
this Task<T> task,
Action<Task<T>> onCompletion,
CancellationToken cancellationToken = default
) => task.ContinueWith(onCompletion, cancellationToken, TaskContinuationOptions.None, Core.LoopContextTaskScheduler);
public static void ContinueWithOnGameThread(
this Task task,
Action<Task> onCompletion,
CancellationToken cancellationToken = default
) => task.ContinueWith(onCompletion, cancellationToken, TaskContinuationOptions.None, Core.LoopContextTaskScheduler);
}