Example #1
0
        public override void Execute(CommandArguments args, ICommandUser sender)
        {
            var commands = CommandManager.Instance.Commands;

            foreach (var cmd in commands.Values.Distinct())
            {
                var perm = cmd.RequiredPermission;
                if (sender != null && perm != null && !sender.HasPermission(perm))
                    continue;

                var cmd1 = cmd;
                var triggers = commands.Where(x => x.Value == cmd1).Select(x => x.Key).ToList();
                var count = triggers.Count;

                for (var i = 0; i < count; i++)
                {
                    Console.Write(triggers[i]);

                    if (i < count - 1)
                        Console.Write("|");
                }

                Console.WriteLine(": {0}", cmd.Description);
            }
        }
Example #2
0
        public override void Execute(CommandArguments args, ICommandUser sender)
        {
            var commands = CommandManager.Instance.Commands;

            foreach (var cmd in commands.Values.Distinct())
            {
                var perm = cmd.RequiredPermission;
                if (sender != null && perm != null && !sender.HasPermission(perm))
                {
                    continue;
                }

                var cmd1     = cmd;
                var triggers = commands.Where(x => x.Value == cmd1).Select(x => x.Key).ToList();
                var count    = triggers.Count;

                for (var i = 0; i < count; i++)
                {
                    Console.Write(triggers[i]);

                    if (i < count - 1)
                    {
                        Console.Write("|");
                    }
                }

                Console.WriteLine(": {0}", cmd.Description);
            }
        }
Example #3
0
        public void ExecuteCommand(string[] fullCmd, ICommandUser sender)
        {
            Contract.Requires(fullCmd != null);
            Contract.Requires(fullCmd.Length > 0);

            var cmd = fullCmd.Take(1).Single();

            if (string.IsNullOrWhiteSpace(cmd))
            {
                return;
            }

            var command = GetCommand(cmd);

            if (command == null)
            {
                sender.Respond("Unknown command: {0}".Interpolate(cmd));
                return;
            }

            if (command.RequiresSender && (sender == null || sender is ConsoleCommandUser))
            {
                sender.Respond("Command {0} requires a sender.".Interpolate(cmd));
                return;
            }

            var permission = command.RequiredPermission;

            if (sender != null && permission != null && permission != typeof(ConsolePermission) && !sender.HasPermission(permission))
            {
                sender.Respond("Command {0} requires permission {1}.".Interpolate(cmd, permission));
                return;
            }

            // Process all commands in a serial manner. Not asynchronously, though, as this would cause
            // problems with console cancellation.
            lock (_cmdLock)
            {
                try
                {
                    command.Execute(new CommandArguments(fullCmd.Skip(1)), sender);
                }
                catch (CommandArgumentException ex)
                {
                    sender.Respond("Argument error for command {0}: {1}".Interpolate(cmd, ex.Message));
                }
                catch (Exception ex)
                {
                    ExceptionManager.RegisterException(ex);
                    return;
                }
            }
        }