137 lines
No EOL
6 KiB
C#
137 lines
No EOL
6 KiB
C#
using System;
|
|
using System.Text.RegularExpressions;
|
|
using Decal.Adapter;
|
|
|
|
namespace MosswartMassacre
|
|
{
|
|
/// <summary>
|
|
/// Handles "/mm" commands from chat.
|
|
/// </summary>
|
|
public class CommandHandler : ICommandHandler
|
|
{
|
|
private readonly StatsManager _statsManager;
|
|
private readonly IWebSocketService _wsService;
|
|
|
|
public CommandHandler(StatsManager statsManager, IWebSocketService wsService)
|
|
{
|
|
_statsManager = statsManager ?? throw new ArgumentNullException(nameof(statsManager));
|
|
_wsService = wsService ?? throw new ArgumentNullException(nameof(wsService));
|
|
}
|
|
|
|
public void Handle(string commandText)
|
|
{
|
|
// Remove the /mm prefix and trim
|
|
string[] args = commandText.Length > 3
|
|
? commandText.Substring(3).Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
|
|
: Array.Empty<string>();
|
|
if (args.Length == 0)
|
|
{
|
|
PluginCore.WriteToChat("Usage: /mm <command>. Try /mm help");
|
|
return;
|
|
}
|
|
|
|
string sub = args[0].ToLowerInvariant();
|
|
switch (sub)
|
|
{
|
|
case "ws":
|
|
if (args.Length > 1)
|
|
{
|
|
if (args[1].Equals("enable", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
_wsService.Start();
|
|
PluginSettings.Instance.WebSocketEnabled = true;
|
|
PluginCore.WriteToChat("WS streaming ENABLED.");
|
|
}
|
|
else if (args[1].Equals("disable", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
_wsService.Stop();
|
|
PluginSettings.Instance.WebSocketEnabled = false;
|
|
PluginCore.WriteToChat("WS streaming DISABLED.");
|
|
}
|
|
else
|
|
{
|
|
PluginCore.WriteToChat("Usage: /mm ws <enable|disable>");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
PluginCore.WriteToChat("Usage: /mm ws <enable|disable>");
|
|
}
|
|
break;
|
|
|
|
case "help":
|
|
PluginCore.WriteToChat("Mosswart Massacre Commands:");
|
|
PluginCore.WriteToChat("/mm report - Show current stats");
|
|
PluginCore.WriteToChat("/mm loc - Show current location");
|
|
PluginCore.WriteToChat("/mm ws - Websocket streaming enable|disable");
|
|
PluginCore.WriteToChat("/mm reset - Reset all counters");
|
|
PluginCore.WriteToChat("/mm meta - Toggle rare meta state");
|
|
PluginCore.WriteToChat("/mm http - Local http-command server enable|disable");
|
|
PluginCore.WriteToChat("/mm remotecommand - Listen to allegiance !do/!dot enable|disable");
|
|
PluginCore.WriteToChat("/mm getmetastate - Gets the current metastate");
|
|
break;
|
|
|
|
case "report":
|
|
var elapsed = DateTime.Now - _statsManager.StatsStartTime;
|
|
var report = $"Total Kills: {_statsManager.TotalKills}, Kills per Hour: {_statsManager.KillsPerHour:F2}, Elapsed Time: {elapsed:dd.hh:mm:ss}, Rares Found: {_statsManager.RareCount}";
|
|
PluginCore.WriteToChat(report);
|
|
break;
|
|
|
|
case "getmetastate":
|
|
var state = VtankControl.VtGetMetaState();
|
|
PluginCore.WriteToChat(state);
|
|
break;
|
|
|
|
case "loc":
|
|
var here = Coordinates.Me;
|
|
var pos = Utils.GetPlayerPosition();
|
|
PluginCore.WriteToChat($"Location: {here} (X={pos.X:F1}, Y={pos.Y:F1}, Z={pos.Z:F1})");
|
|
break;
|
|
|
|
case "reset":
|
|
_statsManager.Restart();
|
|
PluginCore.WriteToChat("Stats have been reset.");
|
|
break;
|
|
|
|
case "meta":
|
|
PluginSettings.Instance.RareMetaEnabled = !PluginSettings.Instance.RareMetaEnabled;
|
|
PluginCore.WriteToChat($"Rare meta state is now {(PluginSettings.Instance.RareMetaEnabled ? "ON" : "OFF")}");
|
|
MainView.SetRareMetaToggleState(PluginSettings.Instance.RareMetaEnabled);
|
|
break;
|
|
|
|
case "http":
|
|
if (args.Length > 1)
|
|
{
|
|
if (args[1].Equals("enable", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
PluginSettings.Instance.HttpServerEnabled = true;
|
|
HttpCommandServer.Start();
|
|
}
|
|
else if (args[1].Equals("disable", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
PluginSettings.Instance.HttpServerEnabled = false;
|
|
HttpCommandServer.Stop();
|
|
}
|
|
else
|
|
{
|
|
PluginCore.WriteToChat("Usage: /mm http <enable|disable>");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
PluginCore.WriteToChat("Usage: /mm http <enable|disable>");
|
|
}
|
|
break;
|
|
|
|
case "remotecommands":
|
|
PluginSettings.Instance.RemoteCommandsEnabled = !PluginSettings.Instance.RemoteCommandsEnabled;
|
|
PluginCore.WriteToChat($"Remote command listening is now {(PluginSettings.Instance.RemoteCommandsEnabled ? "ENABLED" : "DISABLED")}.");
|
|
break;
|
|
|
|
default:
|
|
PluginCore.WriteToChat($"Unknown /mm command: {sub}. Try /mm help");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
} |