Ejemplo n.º 1
0
        /// <summary>
        /// 処理を実行します。
        /// </summary>
        /// <param name="prevExitCode">前処理の終了コード</param>
        /// <returns>終了コード</returns>
        public override async Task <int> ExecuteAsync(int prevExitCode)
        {
            IProcessCommand[]      commands = Commands.ToArray();
            ProcessCommandResult[] results  = new ProcessCommandResult[commands.Length];

            for (int i = 0; i < commands.Length; ++i)
            {
                int exitCode = await ExecuteCommandAsync(commands[i], prevExitCode);

                results[i] = new ProcessCommandResult(commands[i], exitCode);
            }

            return(HandleExitCode(results));
        }
Ejemplo n.º 2
0
        ProcessCommandResult ProcessCommand(ProcessCommandContext context)
        {
            if (string.IsNullOrWhiteSpace(context.command))
            {
                return(ProcessCommandResult.UnknownCommand);
            }

            string[] arguments = SplitCommandIntoArguments(context.command);
            if (0 == arguments.Length)
            {
                return(ProcessCommandResult.InvalidCommand);
            }

            if (!m_registeredCommands.TryGetValue(arguments[0], out CommandInfo commandInfo))
            {
                return(ProcessCommandResult.UnknownCommand);
            }

            if (commandInfo.runOnlyOnServer && !NetStatus.IsServer)
            {
                return(ProcessCommandResult.CanOnlyRunOnServer);
            }

            if (!context.hasServerPermissions && !commandInfo.allowToRunWithoutServerPermissions)
            {
                return(ProcessCommandResult.NoPermissions);
            }

            if (context.player != null)
            {
                m_perPlayerData.TryGetValue(context.player, out PlayerData playerData);

                if (commandInfo.limitInterval > 0 && Time.time - playerData.timeWhenLastExecutedCommand < commandInfo.limitInterval)
                {
                    return(ProcessCommandResult.LimitInterval(commandInfo.limitInterval));
                }

                playerData.timeWhenLastExecutedCommand = Time.time;
                m_perPlayerData[context.player]        = playerData;
            }

            return(commandInfo.commandHandler(context));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 処理を実行します。
        /// </summary>
        /// <param name="prevExitCode">前処理の終了コード</param>
        /// <returns>終了コード</returns>
        public override async Task <int> ExecuteAsync(int prevExitCode)
        {
            IProcessCommand[] commands = Commands.ToArray();

            Task <int>[] tasks = new Task <int> [commands.Length];

            for (int i = 0; i < commands.Length; ++i)
            {
                tasks[i] = ExecuteCommandAsync(commands[i], prevExitCode);
            }

            int[] exitCodes = await Task.WhenAll(tasks);

            ProcessCommandResult[] results = new ProcessCommandResult[commands.Length];

            for (int i = 0; i < commands.Length; ++i)
            {
                results[i] = new ProcessCommandResult(commands[i], exitCodes[i]);
            }

            return(HandleExitCode(results));
        }