Merge branch 'master' into Patron
This commit is contained in:
@@ -174,10 +174,12 @@ namespace Torch.Server
|
|||||||
var commands = _server.CurrentSession?.Managers.GetManager<Torch.Commands.CommandManager>();
|
var commands = _server.CurrentSession?.Managers.GetManager<Torch.Commands.CommandManager>();
|
||||||
if (commands != null && commands.IsCommand(text))
|
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(() =>
|
_server.Invoke(() =>
|
||||||
{
|
{
|
||||||
commands.HandleCommandFromServer(text);
|
var responses = commands.HandleCommandFromServer(text);
|
||||||
|
foreach (var response in responses)
|
||||||
|
InsertMessage(response);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@@ -80,6 +80,9 @@ namespace Torch.Server
|
|||||||
|
|
||||||
private void KickButton_Click(object sender, RoutedEventArgs e)
|
private void KickButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
if (PlayerList.SelectedItem == null)
|
||||||
|
return;
|
||||||
|
|
||||||
var player = (KeyValuePair<ulong, PlayerViewModel>)PlayerList.SelectedItem;
|
var player = (KeyValuePair<ulong, PlayerViewModel>)PlayerList.SelectedItem;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -93,6 +96,9 @@ namespace Torch.Server
|
|||||||
|
|
||||||
private void BanButton_Click(object sender, RoutedEventArgs e)
|
private void BanButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
if (PlayerList.SelectedItem == null)
|
||||||
|
return;
|
||||||
|
|
||||||
var player = (KeyValuePair<ulong, PlayerViewModel>)PlayerList.SelectedItem;
|
var player = (KeyValuePair<ulong, PlayerViewModel>)PlayerList.SelectedItem;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -106,6 +112,9 @@ namespace Torch.Server
|
|||||||
|
|
||||||
private void PromoteButton_OnClick(object sender, RoutedEventArgs e)
|
private void PromoteButton_OnClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
if (PlayerList.SelectedItem == null)
|
||||||
|
return;
|
||||||
|
|
||||||
var player = (KeyValuePair<ulong, PlayerViewModel>)PlayerList.SelectedItem;
|
var player = (KeyValuePair<ulong, PlayerViewModel>)PlayerList.SelectedItem;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -119,6 +128,9 @@ namespace Torch.Server
|
|||||||
|
|
||||||
private void DemoteButton_OnClick(object sender, RoutedEventArgs e)
|
private void DemoteButton_OnClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
if (PlayerList.SelectedItem == null)
|
||||||
|
return;
|
||||||
|
|
||||||
var player = (KeyValuePair<ulong, PlayerViewModel>)PlayerList.SelectedItem;
|
var player = (KeyValuePair<ulong, PlayerViewModel>)PlayerList.SelectedItem;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@@ -55,17 +55,17 @@ namespace Torch.Commands
|
|||||||
Args = args ?? new List<string>();
|
Args = args ?? new List<string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Respond(string message, string sender = null, string font = MyFontEnum.Blue)
|
public virtual void Respond(string message, string sender = null, string font = null)
|
||||||
{
|
{
|
||||||
|
//hack: Backwards compatibility 20190416
|
||||||
|
if (sender == "Server")
|
||||||
|
{
|
||||||
|
sender = null;
|
||||||
|
font = null;
|
||||||
|
}
|
||||||
|
|
||||||
var chat = Torch.CurrentSession.Managers.GetManager<IChatManagerServer>();
|
var chat = Torch.CurrentSession.Managers.GetManager<IChatManagerServer>();
|
||||||
if (sender != null)
|
|
||||||
{
|
|
||||||
chat?.SendMessageAsOther(sender, message, font, _steamIdSender);
|
chat?.SendMessageAsOther(sender, message, font, _steamIdSender);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
chat?.SendMessageAsSelf(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -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 cmdText = new string(message.Skip(1).ToArray());
|
||||||
var command = Commands.GetCommand(cmdText, out string argText);
|
var command = Commands.GetCommand(cmdText, out string argText);
|
||||||
if (command == null)
|
if (command == null)
|
||||||
return false;
|
return null;
|
||||||
var cmdPath = string.Join(".", command.Path);
|
var cmdPath = string.Join(".", command.Path);
|
||||||
|
|
||||||
var splitArgs = Regex.Matches(argText, "(\"[^\"]+\"|\\S+)").Cast<Match>().Select(x => x.ToString().Replace("\"", "")).ToList();
|
var splitArgs = Regex.Matches(argText, "(\"[^\"]+\"|\\S+)").Cast<Match>().Select(x => x.ToString().Replace("\"", "")).ToList();
|
||||||
_log.Trace($"Invoking {cmdPath} for server.");
|
_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))
|
if (command.TryInvoke(context))
|
||||||
_log.Info($"Server ran command '{message}'");
|
_log.Info($"Server ran command '{message}'");
|
||||||
else
|
else
|
||||||
context.Respond($"Invalid Syntax: {command.SyntaxHelp}");
|
context.Respond($"Invalid Syntax: {command.SyntaxHelp}");
|
||||||
return true;
|
return context.Responses;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HandleCommand(TorchChatMessage msg, ref bool consumed)
|
public void HandleCommand(TorchChatMessage msg, ref bool consumed)
|
||||||
@@ -130,7 +130,7 @@ namespace Torch.Commands
|
|||||||
if (!HasPermission(steamId, command))
|
if (!HasPermission(steamId, command))
|
||||||
{
|
{
|
||||||
_log.Info($"{player.DisplayName} tried to use command {cmdPath} without permission");
|
_log.Info($"{player.DisplayName} tried to use command {cmdPath} without permission");
|
||||||
_chatManager.SendMessageAsOther("Server", $"You need to be a {command.MinimumPromoteLevel} or higher to use that command.", MyFontEnum.Red, steamId);
|
_chatManager.SendMessageAsOther(Torch.Config.ChatName, $"You need to be a {command.MinimumPromoteLevel} or higher to use that command.", Torch.Config.ChatColor, steamId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
30
Torch/Commands/ConsoleCommandContext.cs
Normal file
30
Torch/Commands/ConsoleCommandContext.cs
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -106,9 +106,9 @@ namespace Torch.Managers.ChatManager
|
|||||||
}
|
}
|
||||||
var scripted = new ScriptedChatMsg()
|
var scripted = new ScriptedChatMsg()
|
||||||
{
|
{
|
||||||
Author = author,
|
Author = author ?? Torch.Config.ChatName,
|
||||||
Text = message,
|
Text = message,
|
||||||
Font = font,
|
Font = font ?? Torch.Config.ChatColor,
|
||||||
Target = Sync.Players.TryGetIdentityId(targetSteamId)
|
Target = Sync.Players.TryGetIdentityId(targetSteamId)
|
||||||
};
|
};
|
||||||
_chatLog.Info($"{author} (to {GetMemberName(targetSteamId)}): {message}");
|
_chatLog.Info($"{author} (to {GetMemberName(targetSteamId)}): {message}");
|
||||||
|
@@ -187,6 +187,7 @@
|
|||||||
<Compile Include="Collections\SortedView.cs" />
|
<Compile Include="Collections\SortedView.cs" />
|
||||||
<Compile Include="Collections\TransformComparer.cs" />
|
<Compile Include="Collections\TransformComparer.cs" />
|
||||||
<Compile Include="Collections\TransformEnumerator.cs" />
|
<Compile Include="Collections\TransformEnumerator.cs" />
|
||||||
|
<Compile Include="Commands\ConsoleCommandContext.cs" />
|
||||||
<Compile Include="Event\EventShimAttribute.cs" />
|
<Compile Include="Event\EventShimAttribute.cs" />
|
||||||
<Compile Include="Managers\ChatManager\ChatManagerClient.cs" />
|
<Compile Include="Managers\ChatManager\ChatManagerClient.cs" />
|
||||||
<Compile Include="Managers\ChatManager\ChatManagerServer.cs" />
|
<Compile Include="Managers\ChatManager\ChatManagerServer.cs" />
|
||||||
|
Reference in New Issue
Block a user