Websockets-version
This commit is contained in:
parent
9de0d03474
commit
d2e9988bdd
5 changed files with 337 additions and 3 deletions
|
|
@ -25,6 +25,7 @@ namespace MosswartMassacre
|
|||
public static bool HttpServerEnabled { get; set; } = false;
|
||||
public static string CharTag { get; set; } = "";
|
||||
public static bool TelemetryEnabled { get; set; } = false;
|
||||
public bool WebSocketEnabled { get; set; } = false;
|
||||
private static Queue<string> rareMessageQueue = new Queue<string>();
|
||||
private static DateTime _lastSent = DateTime.MinValue;
|
||||
private static readonly Queue<string> _chatQueue = new Queue<string>();
|
||||
|
|
@ -39,6 +40,7 @@ namespace MosswartMassacre
|
|||
|
||||
// Subscribe to chat message event
|
||||
CoreManager.Current.ChatBoxMessage += new EventHandler<ChatTextInterceptEventArgs>(OnChatText);
|
||||
CoreManager.Current.ChatBoxMessage += new EventHandler<ChatTextInterceptEventArgs>(AllChatText);
|
||||
CoreManager.Current.CommandLineText += OnChatCommand;
|
||||
CoreManager.Current.CharacterFilter.LoginComplete += CharacterFilter_LoginComplete;
|
||||
|
||||
|
|
@ -54,6 +56,8 @@ namespace MosswartMassacre
|
|||
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
|
||||
//Enable vTank interface
|
||||
vTank.Enable();
|
||||
//lyssna på commands
|
||||
WebSocket.OnServerCommand += HandleServerCommand;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -73,6 +77,7 @@ namespace MosswartMassacre
|
|||
// Unsubscribe from chat message event
|
||||
CoreManager.Current.ChatBoxMessage -= new EventHandler<ChatTextInterceptEventArgs>(OnChatText);
|
||||
CoreManager.Current.CommandLineText -= OnChatCommand;
|
||||
CoreManager.Current.ChatBoxMessage -= new EventHandler<ChatTextInterceptEventArgs>(AllChatText);
|
||||
|
||||
// Stop and dispose of the timer
|
||||
if (updateTimer != null)
|
||||
|
|
@ -86,6 +91,9 @@ namespace MosswartMassacre
|
|||
MainView.ViewDestroy();
|
||||
//Disable vtank interface
|
||||
vTank.Disable();
|
||||
// sluta lyssna på commands
|
||||
WebSocket.OnServerCommand -= HandleServerCommand;
|
||||
WebSocket.Stop();
|
||||
|
||||
MyHost = null;
|
||||
}
|
||||
|
|
@ -102,6 +110,7 @@ namespace MosswartMassacre
|
|||
|
||||
// Apply the values
|
||||
RareMetaEnabled = PluginSettings.Instance.RareMetaEnabled;
|
||||
WebSocketEnabled = PluginSettings.Instance.WebSocketEnabled;
|
||||
RemoteCommandsEnabled = PluginSettings.Instance.RemoteCommandsEnabled;
|
||||
HttpServerEnabled = PluginSettings.Instance.HttpServerEnabled;
|
||||
TelemetryEnabled = PluginSettings.Instance.TelemetryEnabled;
|
||||
|
|
@ -109,11 +118,47 @@ namespace MosswartMassacre
|
|||
MainView.SetRareMetaToggleState(RareMetaEnabled);
|
||||
if (TelemetryEnabled)
|
||||
Telemetry.Start();
|
||||
|
||||
if (WebSocketEnabled)
|
||||
WebSocket.Start();
|
||||
|
||||
|
||||
}
|
||||
private static string NormalizeChatLine(string raw)
|
||||
{
|
||||
if (string.IsNullOrEmpty(raw))
|
||||
return raw;
|
||||
|
||||
// 1) Remove all <…> tags
|
||||
var noTags = Regex.Replace(raw, "<[^>]+>", "");
|
||||
|
||||
// 2) Trim trailing newline or carriage-return
|
||||
var trimmed = noTags.TrimEnd('\r', '\n');
|
||||
|
||||
// 3) Collapse multiple spaces into one
|
||||
var collapsed = Regex.Replace(trimmed, @"[ ]{2,}", " ");
|
||||
|
||||
return collapsed;
|
||||
}
|
||||
private void AllChatText(object sender, ChatTextInterceptEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var cleaned = NormalizeChatLine(e.Text);
|
||||
|
||||
_ = WebSocket.SendChatTextAsync(e.Color, cleaned);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
PluginCore.WriteToChat("Error sending chat over WS: " + ex.Message);
|
||||
}
|
||||
}
|
||||
private void HandleServerCommand(CommandEnvelope env)
|
||||
{
|
||||
// Skicka commands
|
||||
DispatchChatToBoxWithPluginIntercept(env.Command);
|
||||
CoreManager.Current.Actions.InvokeChatParser($"/a Executed '{env.Command}' from Mosswart Overlord");
|
||||
}
|
||||
private void OnChatText(object sender, ChatTextInterceptEventArgs e)
|
||||
{
|
||||
try
|
||||
|
|
@ -407,11 +452,39 @@ namespace MosswartMassacre
|
|||
WriteToChat("Usage: /mm telemetry <enable|disable>");
|
||||
}
|
||||
break;
|
||||
case "ws":
|
||||
if (args.Length > 1)
|
||||
{
|
||||
if (args[1].Equals("enable", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
WebSocketEnabled = true;
|
||||
WebSocket.Start();
|
||||
PluginSettings.Instance.WebSocketEnabled = true;
|
||||
WriteToChat("WS streaming ENABLED.");
|
||||
}
|
||||
else if (args[1].Equals("disable", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
WebSocketEnabled = false;
|
||||
WebSocket.Stop();
|
||||
PluginSettings.Instance.WebSocketEnabled = false;
|
||||
WriteToChat("WS streaming DISABLED.");
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteToChat("Usage: /mm ws <enable|disable>");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteToChat("Usage: /mm ws <enable|disable>");
|
||||
}
|
||||
break;
|
||||
case "help":
|
||||
WriteToChat("Mosswart Massacre Commands:");
|
||||
WriteToChat("/mm report - Show current stats");
|
||||
WriteToChat("/mm loc - Show current location");
|
||||
WriteToChat("/mm telemetry - Telemetry streaming enable|disable"); // NEW
|
||||
WriteToChat("/mm telemetry - Telemetry streaming enable|disable");
|
||||
WriteToChat("/mm ws - Websocket streaming enable|disable");
|
||||
WriteToChat("/mm reset - Reset all counters");
|
||||
WriteToChat("/mm meta - Toggle rare meta state");
|
||||
WriteToChat("/mm http - Local http-command server enable|disable");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue