Exemple #1
0
        public override void PreCheck(TSPlayer sender, CommandDelegate <TSPlayer> command)
        {
            // Stop the server from running a command if he's not allowed to, it's allowed by default
            if (sender is TSServerPlayer && command.GetCustomAttribute <AllowServer>()?.Allow == false)
            {
                Fail("The server doesn't have the permission to execute this command.");
            }

            CommandPermissions permissions = command.GetCustomAttribute <CommandPermissions>();

            // Stop a user from running a command or subcommand if they don't have permission to use it
            if (permissions != null && permissions.Permissions.Any(p => !sender.HasPermission(p)))
            {
                Fail("You don't have the necessary permission to do that.");
            }
        }
        public override void PreCheck(User sender, CommandDelegate <User> command)
        {
            AccessLevel permLevel = command.GetCustomAttribute <AccessLevel>();

            if (permLevel != null && sender.PermissionLevel < permLevel.MinimumLevel)
            {
                Fail($"Command \"{command.Name}\" does not exist.");
            }
        }
        protected override void AddCommand(CommandDelegate <TSPlayer> command, string[] names)
        {
            CommandDelegate commandDelegate = async(CommandArgs args) =>
            {
                try
                {
                    int firstSpace = args.Message.IndexOf(' ');
                    // Get the command text without the command name
                    string rawCommandArguments = firstSpace == -1 ? "" : args.Message.Substring(firstSpace + 1);
                    await command.Invoke(args.Player, rawCommandArguments);
                }
                // TShock's command system does its own exception handling, so we have to catch error messages here.
                catch (CommandParsingException e)
                {
                    args.Player.SendErrorMessage(e.Message);
                }
                catch (CommandExecutionException e)
                {
                    args.Player.SendErrorMessage(e.Message);
                }
                catch (Exception e)
                {
                    TShock.Log.Error(e.ToString());
                    args.Player.SendErrorMessage(Context.TextOptions.CommandThrewException);
                }
            };

            var helpText    = command.GetCustomAttribute <HelpText>();
            var permissions = command.GetCustomAttribute <CommandPermissions>();
            var allowServer = command.GetCustomAttribute <AllowServer>();
            var doLog       = command.GetCustomAttribute <DoLog>();

            var tshockCommand = new TShockAPI.Command(permissions != null ? permissions.Permissions.ToList() : new List <string>(), commandDelegate, names)
            {
                HelpText    = $"{(helpText != null ? helpText.Documentation : "")} Syntax: {command.SyntaxDocumentation(TSPlayer.Server)}",
                AllowServer = allowServer != null ? allowServer.Allow : true,
                DoLog       = doLog != null ? doLog.Log : true
            };

            Commands.ChatCommands.Add(tshockCommand);
        }
        public override bool CanSeeCommand(User sender, CommandDelegate <User> command)
        {
            AccessLevel permLevel = command.GetCustomAttribute <AccessLevel>();

            return(permLevel == null || sender.PermissionLevel >= permLevel.MinimumLevel);
        }
Exemple #5
0
        public override bool CanSeeCommand(TSPlayer sender, CommandDelegate <TSPlayer> command)
        {
            var permissions = command.GetCustomAttribute <CommandPermissions>();

            return(permissions == null || permissions.Permissions.Any(perm => sender.Group.HasPermission(perm)));
        }