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

@ -525,10 +525,10 @@ namespace MosswartMassacre
WriteToChat("/mm http - Local http-command server enable|disable");
WriteToChat("/mm remotecommand - Listen to allegiance !do/!dot enable|disable");
WriteToChat("/mm getmetastate - Gets the current metastate");
WriteToChat("/TESTAR");
break;
case "debug":
DispatchChatToBoxWithPluginIntercept("/ub give bajs to Town Crier");
break;
case "report":
TimeSpan elapsed = DateTime.Now - statsStartTime;
string reportMessage = $"Total Kills: {totalKills}, Kills per Hour: {killsPerHour:F2}, Elapsed Time: {elapsed:dd\\.hh\\:mm\\:ss}, Rares Found: {rareCount}";

View file

@ -26,5 +26,5 @@ using System.Runtime.InteropServices;
// Minor Version
// Build Number
// Revision
[assembly: AssemblyVersion("3.0.0.0")]
[assembly: AssemblyFileVersion("3.0.0.0")]
[assembly: AssemblyVersion("3.0.0.2")]
[assembly: AssemblyFileVersion("3.0.0.2")]

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);
}
}
});