* add api glue * most of gpose together impl * more cleanup and impl * more impl * minor fixes and chara name abbreviations --------- Co-authored-by: Stanley Dimant <root.darkarchon@outlook.com>
126 lines
5.4 KiB
C#
126 lines
5.4 KiB
C#
using Dalamud.Game.Command;
|
|
using Dalamud.Plugin.Services;
|
|
using MareSynchronos.FileCache;
|
|
using MareSynchronos.MareConfiguration;
|
|
using MareSynchronos.MareConfiguration.Models;
|
|
using MareSynchronos.Services.Mediator;
|
|
using MareSynchronos.Services.ServerConfiguration;
|
|
using MareSynchronos.UI;
|
|
using MareSynchronos.WebAPI;
|
|
using System.Globalization;
|
|
|
|
namespace MareSynchronos.Services;
|
|
|
|
public sealed class CommandManagerService : IDisposable
|
|
{
|
|
private const string _commandName = "/mare";
|
|
|
|
private readonly ApiController _apiController;
|
|
private readonly ICommandManager _commandManager;
|
|
private readonly MareMediator _mediator;
|
|
private readonly MareConfigService _mareConfigService;
|
|
private readonly PerformanceCollectorService _performanceCollectorService;
|
|
private readonly CacheMonitor _cacheMonitor;
|
|
private readonly ServerConfigurationManager _serverConfigurationManager;
|
|
|
|
public CommandManagerService(ICommandManager commandManager, PerformanceCollectorService performanceCollectorService,
|
|
ServerConfigurationManager serverConfigurationManager, CacheMonitor periodicFileScanner,
|
|
ApiController apiController, MareMediator mediator, MareConfigService mareConfigService)
|
|
{
|
|
_commandManager = commandManager;
|
|
_performanceCollectorService = performanceCollectorService;
|
|
_serverConfigurationManager = serverConfigurationManager;
|
|
_cacheMonitor = periodicFileScanner;
|
|
_apiController = apiController;
|
|
_mediator = mediator;
|
|
_mareConfigService = mareConfigService;
|
|
_commandManager.AddHandler(_commandName, new CommandInfo(OnCommand)
|
|
{
|
|
HelpMessage = "Opens the Mare Synchronos UI" + Environment.NewLine + Environment.NewLine +
|
|
"Additionally possible commands:" + Environment.NewLine +
|
|
"\t /mare toggle - Disconnects from Mare, if connected. Connects to Mare, if disconnected" + Environment.NewLine +
|
|
"\t /mare toggle on|off - Connects or disconnects to Mare respectively" + Environment.NewLine +
|
|
"\t /mare gpose - Opens the Mare Character Data Hub window" + Environment.NewLine +
|
|
"\t /mare analyze - Opens the Mare Character Data Analysis window" + Environment.NewLine +
|
|
"\t /mare settings - Opens the Mare Settings window"
|
|
});
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_commandManager.RemoveHandler(_commandName);
|
|
}
|
|
|
|
private void OnCommand(string command, string args)
|
|
{
|
|
var splitArgs = args.ToLowerInvariant().Trim().Split(" ", StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
if (splitArgs.Length == 0)
|
|
{
|
|
// Interpret this as toggling the UI
|
|
if (_mareConfigService.Current.HasValidSetup())
|
|
_mediator.Publish(new UiToggleMessage(typeof(CompactUi)));
|
|
else
|
|
_mediator.Publish(new UiToggleMessage(typeof(IntroUi)));
|
|
return;
|
|
}
|
|
|
|
if (!_mareConfigService.Current.HasValidSetup())
|
|
return;
|
|
|
|
if (string.Equals(splitArgs[0], "toggle", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
if (_apiController.ServerState == WebAPI.SignalR.Utils.ServerState.Disconnecting)
|
|
{
|
|
_mediator.Publish(new NotificationMessage("Mare disconnecting", "Cannot use /toggle while Mare Synchronos is still disconnecting",
|
|
NotificationType.Error));
|
|
}
|
|
|
|
if (_serverConfigurationManager.CurrentServer == null) return;
|
|
var fullPause = splitArgs.Length > 1 ? splitArgs[1] switch
|
|
{
|
|
"on" => false,
|
|
"off" => true,
|
|
_ => !_serverConfigurationManager.CurrentServer.FullPause,
|
|
} : !_serverConfigurationManager.CurrentServer.FullPause;
|
|
|
|
if (fullPause != _serverConfigurationManager.CurrentServer.FullPause)
|
|
{
|
|
_serverConfigurationManager.CurrentServer.FullPause = fullPause;
|
|
_serverConfigurationManager.Save();
|
|
_ = _apiController.CreateConnectionsAsync();
|
|
}
|
|
}
|
|
else if (string.Equals(splitArgs[0], "gpose", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
_mediator.Publish(new UiToggleMessage(typeof(CharaDataHubUi)));
|
|
}
|
|
else if (string.Equals(splitArgs[0], "rescan", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
_cacheMonitor.InvokeScan();
|
|
}
|
|
else if (string.Equals(splitArgs[0], "perf", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
if (splitArgs.Length > 1 && int.TryParse(splitArgs[1], CultureInfo.InvariantCulture, out var limitBySeconds))
|
|
{
|
|
_performanceCollectorService.PrintPerformanceStats(limitBySeconds);
|
|
}
|
|
else
|
|
{
|
|
_performanceCollectorService.PrintPerformanceStats();
|
|
}
|
|
}
|
|
else if (string.Equals(splitArgs[0], "medi", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
_mediator.PrintSubscriberInfo();
|
|
}
|
|
else if (string.Equals(splitArgs[0], "analyze", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
_mediator.Publish(new UiToggleMessage(typeof(DataAnalysisUi)));
|
|
}
|
|
else if (string.Equals(splitArgs[0], "settings", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
_mediator.Publish(new UiToggleMessage(typeof(SettingsUi)));
|
|
}
|
|
}
|
|
} |