Fixed webcommand bug

This commit is contained in:
erik 2025-05-27 21:29:43 +02:00
parent 6fcfe5fc21
commit a91556c949
3 changed files with 17 additions and 6 deletions

View file

@ -33,6 +33,7 @@ namespace MosswartMassacre
private static CancellationTokenSource _cts;
private static bool _enabled;
private static readonly SemaphoreSlim _sendLock = new SemaphoreSlim(1, 1);
private static readonly SynchronizationContext _uiCtx = SynchronizationContext.Current;
/// <summary>
/// Fires when a valid CommandEnvelope arrives for this character.
@ -134,7 +135,17 @@ namespace MosswartMassacre
CoreManager.Current.CharacterFilter.Name,
StringComparison.OrdinalIgnoreCase))
{
OnServerCommand?.Invoke(env);
_uiCtx.Post(_ =>
{
try
{
OnServerCommand?.Invoke(env); // now on the correct thread
}
catch (Exception ex)
{
PluginCore.WriteToChat($"[CMD] {ex.Message}");
}
}, null);
}
}
});