Add event to override Torch command permission checker

This commit is contained in:
John Gross
2020-10-29 13:25:23 -07:00
parent a4edbf3bd9
commit 1b8bddabc8
3 changed files with 19 additions and 8 deletions

View File

@@ -17,11 +17,13 @@ using VRage.Network;
namespace Torch.Commands namespace Torch.Commands
{ {
public delegate void CommandExecutingDel(Command command, IMyPlayer player, bool hasPermission, ref bool? hasPermissionOverride);
public class CommandManager : Manager public class CommandManager : Manager
{ {
public char Prefix { get; set; } public char Prefix { get; set; }
public CommandTree Commands { get; set; } = new CommandTree(); public CommandTree Commands { get; set; } = new CommandTree();
public event CommandExecutingDel OnCommandExecuting;
private Logger _log = LogManager.GetCurrentClassLogger(); private Logger _log = LogManager.GetCurrentClassLogger();
[Dependency] [Dependency]
private IChatManagerServer _chatManager; private IChatManagerServer _chatManager;
@@ -124,7 +126,6 @@ namespace Torch.Commands
public void HandleCommand(string message, ulong steamId, ref bool consumed, bool serverConsole = false) public void HandleCommand(string message, ulong steamId, ref bool consumed, bool serverConsole = false)
{ {
if (message.Length < 1 || message[0] != Prefix) if (message.Length < 1 || message[0] != Prefix)
return; return;
@@ -144,11 +145,23 @@ namespace Torch.Commands
{ {
var cmdPath = string.Join(".", command.Path); var cmdPath = string.Join(".", command.Path);
if (!HasPermission(steamId, command)) var defaultPermission = HasPermission(steamId, command);
bool? cancel = null;
OnCommandExecuting?.Invoke(command, player, defaultPermission, ref cancel);
if (cancel.HasValue)
{ {
_log.Info($"{player.DisplayName} tried to use command {cmdPath} without permission"); if (cancel.Value)
_chatManager.SendMessageAsOther(null, $"You need to be a {command.MinimumPromoteLevel} or higher to use that command.", targetSteamId: steamId); return;
return; }
else
{
if (!defaultPermission)
{
_log.Info($"{player.DisplayName} tried to use command {cmdPath} without permission");
_chatManager.SendMessageAsOther(null, $"You need to be a {command.MinimumPromoteLevel} or higher to use that command.", targetSteamId: steamId);
return;
}
} }
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();

View File

@@ -1 +0,0 @@
theme: jekyll-theme-modernist

View File

@@ -1 +0,0 @@
# Torch