diff --git a/MosswartMassacre/HttpCommandServer.cs b/MosswartMassacre/HttpCommandServer.cs deleted file mode 100644 index 35a6d38..0000000 --- a/MosswartMassacre/HttpCommandServer.cs +++ /dev/null @@ -1,105 +0,0 @@ -using System; -using System.Net; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using Decal.Adapter; - -namespace MosswartMassacre -{ - public static class HttpCommandServer - { - private static HttpListener listener; - private static CancellationTokenSource cts; - private static bool isRunning = false; - - public static bool IsRunning => isRunning; - - public static void Start() - { - if (isRunning) return; - - try - { - listener = new HttpListener(); - listener.Prefixes.Add("http://localhost:8085/"); - listener.Start(); - cts = new CancellationTokenSource(); - Task.Run(() => ListenLoop(cts.Token)); - - isRunning = true; - PluginCore.WriteToChat("[HTTP] Server started on port 8085."); - } - catch (Exception ex) - { - PluginCore.WriteToChat("[HTTP] Error starting server: " + ex.Message); - } - } - - public static void Stop() - { - if (!isRunning) return; - - try - { - cts.Cancel(); - listener.Stop(); - listener.Close(); - listener = null; - isRunning = false; - PluginCore.WriteToChat("[HTTP] Server stopped."); - } - catch (Exception ex) - { - PluginCore.WriteToChat("[HTTP] Error stopping server: " + ex.Message); - } - } - - private static async Task ListenLoop(CancellationToken token) - { - while (!token.IsCancellationRequested) - { - HttpListenerContext context = null; - - try - { - context = await listener.GetContextAsync(); - } - catch (HttpListenerException) - { - break; // Listener was stopped - } - - if (context == null) continue; - - string requestBody = new System.IO.StreamReader(context.Request.InputStream).ReadToEnd(); - - PluginCore.WriteToChat("[HTTP] Received request: " + requestBody); - - // Parse simple format: target=Name&command=/say hello - string target = ""; - string command = ""; - foreach (var pair in requestBody.Split('&')) - { - var parts = pair.Split('='); - if (parts.Length == 2) - { - if (parts[0] == "target") target = WebUtility.UrlDecode(parts[1]); - else if (parts[0] == "command") command = WebUtility.UrlDecode(parts[1]); - } - } - - if (!string.IsNullOrWhiteSpace(target) && !string.IsNullOrWhiteSpace(command)) - { - string tellCmd = $"/a {target} {command}"; - CoreManager.Current.Actions.InvokeChatParser(tellCmd); - } - - byte[] buffer = Encoding.UTF8.GetBytes("Command received."); - context.Response.ContentLength64 = buffer.Length; - context.Response.OutputStream.Write(buffer, 0, buffer.Length); - context.Response.OutputStream.Close(); - } - } - } -} diff --git a/MosswartMassacre/MosswartMassacre.csproj b/MosswartMassacre/MosswartMassacre.csproj index 555baa8..2e812f9 100644 --- a/MosswartMassacre/MosswartMassacre.csproj +++ b/MosswartMassacre/MosswartMassacre.csproj @@ -313,12 +313,10 @@ - - diff --git a/MosswartMassacre/PluginCore.cs b/MosswartMassacre/PluginCore.cs index a111188..522111f 100644 --- a/MosswartMassacre/PluginCore.cs +++ b/MosswartMassacre/PluginCore.cs @@ -111,10 +111,7 @@ namespace MosswartMassacre Views.VVSTabbedMainView.RefreshUpdateStatus(); } } - public static bool RemoteCommandsEnabled { get; set; } = false; - public static bool HttpServerEnabled { get; set; } = false; public static string CharTag { get; set; } = ""; - public static bool TelemetryEnabled { get; set; } = false; public static bool WebSocketEnabled { get; set; } = false; public bool InventoryLogEnabled { get; set; } = false; public static bool AggressiveChatStreamingEnabled { get; set; } = true; @@ -240,8 +237,6 @@ namespace MosswartMassacre try { PluginSettings.Save(); - if (TelemetryEnabled) - Telemetry.Stop(); // ensure no dangling timer / HttpClient WriteToChat("Mosswart Massacre is shutting down. Bye!"); @@ -367,14 +362,9 @@ 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; CharTag = PluginSettings.Instance.CharTag; ViewManager.SetRareMetaToggleState(RareMetaEnabled); ViewManager.RefreshSettingsFromConfig(); // Refresh all UI settings after loading - if (TelemetryEnabled) - Telemetry.Start(); if (WebSocketEnabled) WebSocket.Start(); @@ -575,9 +565,6 @@ namespace MosswartMassacre // 2. Apply the values from settings RareMetaEnabled = PluginSettings.Instance.RareMetaEnabled; WebSocketEnabled = PluginSettings.Instance.WebSocketEnabled; - RemoteCommandsEnabled = PluginSettings.Instance.RemoteCommandsEnabled; - HttpServerEnabled = PluginSettings.Instance.HttpServerEnabled; - TelemetryEnabled = PluginSettings.Instance.TelemetryEnabled; CharTag = PluginSettings.Instance.CharTag; // 3. Update UI with current settings @@ -585,24 +572,12 @@ namespace MosswartMassacre ViewManager.RefreshSettingsFromConfig(); // 4. Restart services if they were enabled (stop first, then start) - if (TelemetryEnabled) - { - Telemetry.Stop(); // Stop existing - Telemetry.Start(); // Restart - } - if (WebSocketEnabled) { - WebSocket.Stop(); // Stop existing + WebSocket.Stop(); // Stop existing WebSocket.Start(); // Restart } - if (HttpServerEnabled) - { - HttpCommandServer.Stop(); // Stop existing - HttpCommandServer.Start(); // Restart - } - // 5. Initialize Harmony patches (only if not already done) // Note: Harmony patches are global and don't need reinitialization if (!DecalHarmonyClean.IsActive()) @@ -1086,31 +1061,6 @@ namespace MosswartMassacre WriteToChat($"[Mosswart Massacre] Reporting to allegiance: {reportMessage}"); MyHost.Actions.InvokeChatParser($"/a {reportMessage}"); } - if (RemoteCommandsEnabled && e.Color == 18) - { - string characterName = Regex.Escape(CoreManager.Current.CharacterFilter.Name); - string pattern = $@"^\[Allegiance\].*Dunking Rares.*say[s]?, \""!do {characterName} (?.+)\""$"; - string tag = Regex.Escape(PluginCore.CharTag); - string patterntag = $@"^\[Allegiance\].*Dunking Rares.*say[s]?, \""!dot {tag} (?.+)\""$"; - - - var match = Regex.Match(e.Text, pattern); - var matchtag = Regex.Match(e.Text, patterntag); - - if (match.Success) - { - string command = match.Groups["command"].Value; - DispatchChatToBoxWithPluginIntercept(command); - DelayedCommandManager.AddDelayedCommand($"/a [Remote] Executing: {command}", 2000); - } - else if (matchtag.Success) - { - string command = matchtag.Groups["command"].Value; - DispatchChatToBoxWithPluginIntercept(command); - DelayedCommandManager.AddDelayedCommand($"/a [Remote] Executing: {command}", 2000); - } - - } @@ -1416,33 +1366,6 @@ namespace MosswartMassacre switch (subCommand) { - case "telemetry": - if (args.Length > 1) - { - if (args[1].Equals("enable", StringComparison.OrdinalIgnoreCase)) - { - TelemetryEnabled = true; - Telemetry.Start(); - PluginSettings.Instance.TelemetryEnabled = true; - WriteToChat("Telemetry streaming ENABLED."); - } - else if (args[1].Equals("disable", StringComparison.OrdinalIgnoreCase)) - { - TelemetryEnabled = false; - Telemetry.Stop(); - PluginSettings.Instance.TelemetryEnabled = false; - WriteToChat("Telemetry streaming DISABLED."); - } - else - { - WriteToChat("Usage: /mm telemetry "); - } - } - else - { - WriteToChat("Usage: /mm telemetry "); - } - break; case "ws": if (args.Length > 1) { @@ -1475,12 +1398,9 @@ namespace MosswartMassacre WriteToChat("Mosswart Massacre Commands:"); WriteToChat("/mm report - Show current stats"); WriteToChat("/mm loc - Show current location"); - 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"); - WriteToChat("/mm remotecommand - Listen to allegiance !do/!dot enable|disable"); WriteToChat("/mm getmetastate - Gets the current metastate"); WriteToChat("/mm setchest - Set chest name for looter"); WriteToChat("/mm setkey - Set key name for looter"); @@ -1526,58 +1446,6 @@ namespace MosswartMassacre WriteToChat($"Rare meta state is now {(RareMetaEnabled ? "ON" : "OFF")}"); ViewManager.SetRareMetaToggleState(RareMetaEnabled); // <-- sync the UI break; - case "http": - if (args.Length > 1) - { - if (args[1].Equals("enable", StringComparison.OrdinalIgnoreCase)) - { - PluginSettings.Instance.HttpServerEnabled = true; - HttpServerEnabled = true; - HttpCommandServer.Start(); - } - else if (args[1].Equals("disable", StringComparison.OrdinalIgnoreCase)) - { - PluginSettings.Instance.HttpServerEnabled = false; - HttpServerEnabled = false; - HttpCommandServer.Stop(); - } - else - { - WriteToChat("Usage: /mm http "); - } - } - else - { - WriteToChat("Usage: /mm http "); - } - break; - - case "remotecommands": - if (args.Length > 1) - { - if (args[1].Equals("enable", StringComparison.OrdinalIgnoreCase)) - { - PluginSettings.Instance.RemoteCommandsEnabled = true; - RemoteCommandsEnabled = true; - WriteToChat("Remote command listening is now ENABLED."); - } - else if (args[1].Equals("disable", StringComparison.OrdinalIgnoreCase)) - { - PluginSettings.Instance.RemoteCommandsEnabled = false; - RemoteCommandsEnabled = false; - WriteToChat("Remote command listening is now DISABLED."); - } - else - { - WriteToChat("Invalid remotecommands argument. Use 'enable' or 'disable'."); - } - } - else - { - WriteToChat("Usage: /mm remotecommands "); - } - break; - case "nextwp": double result = VtankControl.VtAdvanceWaypoint(); if (result == 1) diff --git a/MosswartMassacre/PluginSettings.cs b/MosswartMassacre/PluginSettings.cs index de256e2..83544b4 100644 --- a/MosswartMassacre/PluginSettings.cs +++ b/MosswartMassacre/PluginSettings.cs @@ -13,10 +13,7 @@ namespace MosswartMassacre private static readonly object _sync = new object(); // backing fields - private bool _remoteCommandsEnabled = false; private bool _rareMetaEnabled = true; - private bool _httpServerEnabled = false; - private bool _telemetryEnabled = false; private bool _webSocketEnabled = false; private bool _inventorylog = true; private string _charTag = "default"; @@ -137,29 +134,12 @@ namespace MosswartMassacre } // public properties - public bool RemoteCommandsEnabled - { - get => _remoteCommandsEnabled; - set { _remoteCommandsEnabled = value; Save(); } - } - public bool RareMetaEnabled { get => _rareMetaEnabled; set { _rareMetaEnabled = value; Save(); } } - public bool HttpServerEnabled - { - get => _httpServerEnabled; - set { _httpServerEnabled = value; Save(); } - } - - public bool TelemetryEnabled - { - get => _telemetryEnabled; - set { _telemetryEnabled = value; Save(); } - } public bool WebSocketEnabled { get => _webSocketEnabled; diff --git a/MosswartMassacre/Telemetry.cs b/MosswartMassacre/Telemetry.cs deleted file mode 100644 index b9f8e14..0000000 --- a/MosswartMassacre/Telemetry.cs +++ /dev/null @@ -1,110 +0,0 @@ -// Telemetry.cs ─────────────────────────────────────────────────────────────── -using System; -using System.Net.Http; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using Decal.Adapter; -using Newtonsoft.Json; - -namespace MosswartMassacre -{ - public static class Telemetry - { - /* ───────────── configuration ───────────── */ - private const string Endpoint = "https://mosswart.snakedesert.se/position/"; // <- trailing slash! - private const string SharedSecret = "your_shared_secret"; // <- keep in sync - private const int IntervalSec = 5; // seconds between posts - - /* ───────────── runtime state ───────────── */ - private static readonly HttpClient _http = new HttpClient(); - private static string _sessionId; - private static CancellationTokenSource _cts; - private static bool _enabled; - - /* ───────────── public API ───────────── */ - public static void Start() - { - if (_enabled) return; - - _enabled = true; - _sessionId = $"{CoreManager.Current.CharacterFilter.Name}-{DateTime.UtcNow:yyyyMMdd-HHmmss}"; - _cts = new CancellationTokenSource(); - - PluginCore.WriteToChat("[Telemetry] HTTP streaming ENABLED"); - - _ = Task.Run(() => LoopAsync(_cts.Token)); // fire-and-forget - } - - public static void Stop() - { - if (!_enabled) return; - _cts.Cancel(); - _enabled = false; - PluginCore.WriteToChat("[Telemetry] HTTP streaming DISABLED"); - } - - /* ───────────── async loop ───────────── */ - private static async Task LoopAsync(CancellationToken token) - { - while (!token.IsCancellationRequested) - { - try - { - await SendSnapshotAsync(token); - } - catch (Exception ex) - { - PluginCore.WriteToChat($"[Telemetry] send failed: {ex.Message}"); - } - - try - { - await Task.Delay(TimeSpan.FromSeconds(IntervalSec), token); - } - catch (TaskCanceledException) { } // expected on Stop() - } - } - - /* ───────────── single POST ───────────── */ - private static async Task SendSnapshotAsync(CancellationToken token) - { - var coords = Coordinates.Me; - - var payload = new - { - character_name = CoreManager.Current.CharacterFilter.Name, - char_tag = PluginCore.CharTag, - session_id = _sessionId, - timestamp = DateTime.UtcNow.ToString("o"), - - ew = coords.EW, - ns = coords.NS, - z = coords.Z, - - kills = PluginCore.totalKills, - onlinetime = (DateTime.Now - PluginCore.statsStartTime).ToString(@"dd\.hh\:mm\:ss"), - kills_per_hour = PluginCore.killsPerHour.ToString("F0"), - deaths = PluginCore.sessionDeaths.ToString(), - total_deaths = PluginCore.totalDeaths.ToString(), - rares_found = PluginCore.rareCount, - prismatic_taper_count = PluginCore.cachedPrismaticCount.ToString(), - vt_state = VtankControl.VtGetMetaState(), - }; - - string json = JsonConvert.SerializeObject(payload); - var req = new HttpRequestMessage(HttpMethod.Post, Endpoint) - { - Content = new StringContent(json, Encoding.UTF8, "application/json") - }; - req.Headers.Add("X-Plugin-Secret", SharedSecret); - - using var resp = await _http.SendAsync(req, token); - - if (!resp.IsSuccessStatusCode) // stay quiet on success - { - PluginCore.WriteToChat($"[Telemetry] server replied {resp.StatusCode}"); - } - } - } -} diff --git a/MosswartMassacre/ViewXML/mainViewTabbed.xml b/MosswartMassacre/ViewXML/mainViewTabbed.xml index 2e90591..2a3a86f 100644 --- a/MosswartMassacre/ViewXML/mainViewTabbed.xml +++ b/MosswartMassacre/ViewXML/mainViewTabbed.xml @@ -31,22 +31,13 @@ - - - - - - - + - - - - - + + - - + + diff --git a/MosswartMassacre/Views/VVSTabbedMainView.cs b/MosswartMassacre/Views/VVSTabbedMainView.cs index b11234d..1c1c1d6 100644 --- a/MosswartMassacre/Views/VVSTabbedMainView.cs +++ b/MosswartMassacre/Views/VVSTabbedMainView.cs @@ -29,10 +29,7 @@ namespace MosswartMassacre.Views #region Settings Tab Controls private HudCheckBox chkRareMetaEnabled; - private HudCheckBox chkRemoteCommandsEnabled; - private HudCheckBox chkHttpServerEnabled; private HudCheckBox chkWebSocketEnabled; - private HudCheckBox chkTelemetryEnabled; private HudTextBox txtCharTag; private HudTextBox txtVTankPath; #endregion @@ -212,24 +209,15 @@ namespace MosswartMassacre.Views { // Settings tab controls chkRareMetaEnabled = GetControl("chkRareMetaEnabled"); - chkRemoteCommandsEnabled = GetControl("chkRemoteCommandsEnabled"); - chkHttpServerEnabled = GetControl("chkHttpServerEnabled"); chkWebSocketEnabled = GetControl("chkWebSocketEnabled"); - chkTelemetryEnabled = GetControl("chkTelemetryEnabled"); txtCharTag = GetControl("txtCharTag"); txtVTankPath = GetControl("txtVTankPath"); // Hook up settings events if (chkRareMetaEnabled != null) chkRareMetaEnabled.Change += OnRareMetaSettingChanged; - if (chkRemoteCommandsEnabled != null) - chkRemoteCommandsEnabled.Change += OnRemoteCommandsSettingChanged; - if (chkHttpServerEnabled != null) - chkHttpServerEnabled.Change += OnHttpServerSettingChanged; if (chkWebSocketEnabled != null) chkWebSocketEnabled.Change += OnWebSocketSettingChanged; - if (chkTelemetryEnabled != null) - chkTelemetryEnabled.Change += OnTelemetrySettingChanged; if (txtCharTag != null) txtCharTag.Change += OnCharTagChanged; if (txtVTankPath != null) @@ -368,34 +356,6 @@ namespace MosswartMassacre.Views } } - private void OnRemoteCommandsSettingChanged(object sender, EventArgs e) - { - try - { - PluginSettings.Instance.RemoteCommandsEnabled = chkRemoteCommandsEnabled.Checked; - } - catch (Exception ex) - { - PluginCore.WriteToChat($"Error in remote commands setting change: {ex.Message}"); - } - } - - private void OnHttpServerSettingChanged(object sender, EventArgs e) - { - try - { - PluginSettings.Instance.HttpServerEnabled = chkHttpServerEnabled.Checked; - if (chkHttpServerEnabled.Checked) - HttpCommandServer.Start(); - else - HttpCommandServer.Stop(); - } - catch (Exception ex) - { - PluginCore.WriteToChat($"Error in HTTP server setting change: {ex.Message}"); - } - } - private void OnWebSocketSettingChanged(object sender, EventArgs e) { try @@ -420,22 +380,6 @@ namespace MosswartMassacre.Views } } - private void OnTelemetrySettingChanged(object sender, EventArgs e) - { - try - { - PluginSettings.Instance.TelemetryEnabled = chkTelemetryEnabled.Checked; - if (chkTelemetryEnabled.Checked) - Telemetry.Start(); - else - Telemetry.Stop(); - } - catch (Exception ex) - { - PluginCore.WriteToChat($"Error in telemetry setting change: {ex.Message}"); - } - } - private void OnCharTagChanged(object sender, EventArgs e) { try @@ -603,14 +547,8 @@ namespace MosswartMassacre.Views { if (chkRareMetaEnabled != null) chkRareMetaEnabled.Checked = PluginSettings.Instance.RareMetaEnabled; - if (chkRemoteCommandsEnabled != null) - chkRemoteCommandsEnabled.Checked = PluginSettings.Instance.RemoteCommandsEnabled; - if (chkHttpServerEnabled != null) - chkHttpServerEnabled.Checked = PluginSettings.Instance.HttpServerEnabled; if (chkWebSocketEnabled != null) chkWebSocketEnabled.Checked = PluginSettings.Instance.WebSocketEnabled; - if (chkTelemetryEnabled != null) - chkTelemetryEnabled.Checked = PluginSettings.Instance.TelemetryEnabled; if (txtCharTag != null) txtCharTag.Text = PluginSettings.Instance.CharTag ?? "default"; if (txtVTankPath != null) @@ -1252,14 +1190,8 @@ namespace MosswartMassacre.Views // Settings tab event cleanup if (chkRareMetaEnabled != null) chkRareMetaEnabled.Change -= OnRareMetaSettingChanged; - if (chkRemoteCommandsEnabled != null) - chkRemoteCommandsEnabled.Change -= OnRemoteCommandsSettingChanged; - if (chkHttpServerEnabled != null) - chkHttpServerEnabled.Change -= OnHttpServerSettingChanged; if (chkWebSocketEnabled != null) chkWebSocketEnabled.Change -= OnWebSocketSettingChanged; - if (chkTelemetryEnabled != null) - chkTelemetryEnabled.Change -= OnTelemetrySettingChanged; if (txtCharTag != null) txtCharTag.Change -= OnCharTagChanged; if (txtVTankPath != null) diff --git a/MosswartMassacre/bin/Release/MosswartMassacre.dll b/MosswartMassacre/bin/Release/MosswartMassacre.dll index a5aee04..b2867f3 100644 Binary files a/MosswartMassacre/bin/Release/MosswartMassacre.dll and b/MosswartMassacre/bin/Release/MosswartMassacre.dll differ