Fix for command response in UI. How did this ever work?

This commit is contained in:
John Gross
2019-04-16 11:57:13 -07:00
parent 8198243425
commit b974487fc4
4 changed files with 39 additions and 6 deletions

View File

@@ -174,10 +174,12 @@ namespace Torch.Server
var commands = _server.CurrentSession?.Managers.GetManager<Torch.Commands.CommandManager>();
if (commands != null && commands.IsCommand(text))
{
InsertMessage(new TorchChatMessage("Server", text, MyFontEnum.DarkBlue));
InsertMessage(new TorchChatMessage(TorchBase.Instance.Config.ChatName, text, TorchBase.Instance.Config.ChatColor));
_server.Invoke(() =>
{
commands.HandleCommandFromServer(text);
var responses = commands.HandleCommandFromServer(text);
foreach (var response in responses)
InsertMessage(response);
});
}
else

View File

@@ -81,22 +81,22 @@ namespace Torch.Commands
}
}
public bool HandleCommandFromServer(string message)
public List<TorchChatMessage> HandleCommandFromServer(string message)
{
var cmdText = new string(message.Skip(1).ToArray());
var command = Commands.GetCommand(cmdText, out string argText);
if (command == null)
return false;
return null;
var cmdPath = string.Join(".", command.Path);
var splitArgs = Regex.Matches(argText, "(\"[^\"]+\"|\\S+)").Cast<Match>().Select(x => x.ToString().Replace("\"", "")).ToList();
_log.Trace($"Invoking {cmdPath} for server.");
var context = new CommandContext(Torch, command.Plugin, Sync.MyId, argText, splitArgs);
var context = new ConsoleCommandContext(Torch, command.Plugin, Sync.MyId, argText, splitArgs);
if (command.TryInvoke(context))
_log.Info($"Server ran command '{message}'");
else
context.Respond($"Invalid Syntax: {command.SyntaxHelp}");
return true;
return context.Responses;
}
public void HandleCommand(TorchChatMessage msg, ref bool consumed)

View File

@@ -0,0 +1,30 @@
using System.Collections.Generic;
using System.Text;
using Torch.API;
using Torch.API.Managers;
using Torch.API.Plugins;
namespace Torch.Commands
{
public class ConsoleCommandContext : CommandContext
{
public List<TorchChatMessage> Responses = new List<TorchChatMessage>();
private bool _flag;
/// <inheritdoc />
public ConsoleCommandContext(ITorchBase torch, ITorchPlugin plugin, ulong steamIdSender, string rawArgs = null, List<string> args = null)
: base(torch, plugin, steamIdSender, rawArgs, args) { }
/// <inheritdoc />
public override void Respond(string message, string sender = null, string font = null)
{
if (sender == "Server")
{
sender = null;
font = null;
}
Responses.Add(new TorchChatMessage(sender ?? TorchBase.Instance.Config.ChatName, message, font ?? TorchBase.Instance.Config.ChatColor));
}
}
}

View File

@@ -187,6 +187,7 @@
<Compile Include="Collections\SortedView.cs" />
<Compile Include="Collections\TransformComparer.cs" />
<Compile Include="Collections\TransformEnumerator.cs" />
<Compile Include="Commands\ConsoleCommandContext.cs" />
<Compile Include="Event\EventShimAttribute.cs" />
<Compile Include="Managers\ChatManager\ChatManagerClient.cs" />
<Compile Include="Managers\ChatManager\ChatManagerServer.cs" />