コード例 #1
0
        public static string Admin_command_server(CommandInfo cmdInfo)
        {
            TaskInfo result = TaskInfo.Fail("Index not int: " + cmdInfo.data);

            TaskInfo unlockedStatus = isLocked();

            if (unlockedStatus)
            {
                return(LockedFormat(unlockedStatus));
            }
            else
            {
                int commandIndex = -1;
                if (
                    int.TryParse(cmdInfo.data, out commandIndex) &&
                    commandIndex > -1)
                {
                    result = TaskInfo.Fail("Index out of range : " + commandIndex);
                    if (commandIndex < Config.Instance.ADMIN_COMMANDS.Length)
                    {
                        ConfigCommand command = Config.Instance.ADMIN_COMMANDS[commandIndex];
                        result = SystemUtils.RunProcessInfo(command.name, command.path, command.arg);
                    }
                }
            }

            return(chopString("Run admin_cmd? " + result.success.ToString() + ", " + result.eventReason));
        }
コード例 #2
0
        public static string Allowed_command_server(CommandInfo cmdInfo)
        {
            TaskInfo result = TaskInfo.Fail("Index not int: " + cmdInfo.data);

            int commandIndex = -1;

            if (
                int.TryParse(cmdInfo.data, out commandIndex) &&
                commandIndex > -1)
            {
                result = TaskInfo.Fail("Index out of range : " + commandIndex);
                if (commandIndex < Config.Instance.ALLOWED_COMMANDS.Length)
                {
                    TimeSpan cooldownLeft = TimeSpan.FromSeconds(0);
                    if (!CommandCooldown.ContainsKey(commandIndex)
                        ||
                        Math.Abs((cooldownLeft = CommandCooldown[commandIndex] - DateTime.Now).TotalSeconds) > COOLDOWN_SEC)
                    {
                        CommandCooldown[commandIndex] = DateTime.Now;

                        ConfigCommand command = Config.Instance.ALLOWED_COMMANDS[commandIndex];
                        result = SystemUtils.RunProcessInfo(command.name, command.path, command.arg);
                    }
                    else
                    {
                        result = TaskInfo.Fail("Cooldown, Wait: " + cooldownLeft.TotalSeconds + "sec");
                    }
                }
            }

            return(chopString("Run allowed_cmd? " + result.success.ToString() + ", " + result.eventReason));
        }