Command perms (#408)
* Add event to override Torch command permission checker * Correct permission override condition
This commit is contained in:
@@ -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,12 +145,24 @@ 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)
|
||||||
|
{
|
||||||
|
if (!cancel.Value)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!defaultPermission)
|
||||||
{
|
{
|
||||||
_log.Info($"{player.DisplayName} tried to use command {cmdPath} without permission");
|
_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);
|
_chatManager.SendMessageAsOther(null, $"You need to be a {command.MinimumPromoteLevel} or higher to use that command.", targetSteamId: steamId);
|
||||||
return;
|
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();
|
||||||
_log.Trace($"Invoking {cmdPath} for player {player.DisplayName}");
|
_log.Trace($"Invoking {cmdPath} for player {player.DisplayName}");
|
||||||
|
@@ -1 +0,0 @@
|
|||||||
theme: jekyll-theme-modernist
|
|
@@ -1 +0,0 @@
|
|||||||
# Torch
|
|
Reference in New Issue
Block a user