Exemplo n.º 1
0
        ProcessCommandResult ProcessHelpCommand(ProcessCommandContext context)
        {
            string response = "List of available commands: " +
                              string.Join(", ", m_registeredCommands
                                          .Where(pair => context.hasServerPermissions || pair.Value.allowToRunWithoutServerPermissions)
                                          .Select(pair => pair.Key));

            return(new ProcessCommandResult {
                response = response
            });
        }
Exemplo 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));
        }