diff --git a/Torch.Server/Views/ChatControl.xaml.cs b/Torch.Server/Views/ChatControl.xaml.cs index 65174f1..cc7536c 100644 --- a/Torch.Server/Views/ChatControl.xaml.cs +++ b/Torch.Server/Views/ChatControl.xaml.cs @@ -174,10 +174,12 @@ namespace Torch.Server var commands = _server.CurrentSession?.Managers.GetManager(); 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 diff --git a/Torch/Commands/CommandManager.cs b/Torch/Commands/CommandManager.cs index a80ad07..8482183 100644 --- a/Torch/Commands/CommandManager.cs +++ b/Torch/Commands/CommandManager.cs @@ -81,22 +81,22 @@ namespace Torch.Commands } } - public bool HandleCommandFromServer(string message) + public List 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().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) diff --git a/Torch/Commands/ConsoleCommandContext.cs b/Torch/Commands/ConsoleCommandContext.cs new file mode 100644 index 0000000..49fcfe1 --- /dev/null +++ b/Torch/Commands/ConsoleCommandContext.cs @@ -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 Responses = new List(); + private bool _flag; + + /// + public ConsoleCommandContext(ITorchBase torch, ITorchPlugin plugin, ulong steamIdSender, string rawArgs = null, List args = null) + : base(torch, plugin, steamIdSender, rawArgs, args) { } + + /// + 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)); + } + } +} \ No newline at end of file diff --git a/Torch/Torch.csproj b/Torch/Torch.csproj index edc2f53..814c916 100644 --- a/Torch/Torch.csproj +++ b/Torch/Torch.csproj @@ -187,6 +187,7 @@ +