コード例 #1
0
        private static bool ServerIsOperatorOrModerator(ICharacter playerCharacter)
        {
            var name = playerCharacter.Name;

            return(ServerOperatorSystem.ServerIsOperator(name) ||
                   ServerModeratorSystem.ServerIsModerator(name));
        }
コード例 #2
0
        private static void PlayerLoginHook(string playerName, out string errorMessage)
        {
            if (ServerOperatorSystem.ServerIsOperator(playerName) ||
                ServerModeratorSystem.ServerIsModerator(playerName))
            {
                // operators/moderators cannot be blocked or kicked
                errorMessage = null;
                return;
            }

            if (IsInBlackList(playerName))
            {
                errorMessage = CannotJoinBanned;
                return;
            }

            if (isWhiteListEnabled && !whiteList.Contains(playerName, StringComparer.OrdinalIgnoreCase))
            {
                errorMessage = CannotJoinNotInWhitelist;
                return;
            }

            if (IsKicked(playerName, out var secondsRemains))
            {
                errorMessage = string.Format(CannotJoinKicked,
                                             ClientTimeFormatHelper.FormatTimeDuration(secondsRemains));
                return;
            }

            // all checks passed successfully
            errorMessage = null;
        }
コード例 #3
0
        public string Execute([CurrentCharacterIfNull] ICharacter character)
        {
            if (ServerModeratorSystem.ServerIsModerator(character.Name))
            {
                return(character.Name + " is already a server moderator");
            }

            ServerModeratorSystem.ServerAdd(character);
            return(character.Name + " added to the server moderators list");
        }
コード例 #4
0
        public string Execute([CurrentCharacterIfNull] ICharacter character)
        {
            if (!ServerModeratorSystem.ServerIsModerator(character.Name))
            {
                return(character.Name + " is not a server moderator");
            }

            ServerModeratorSystem.ServerRemove(character);
            return(character.Name + " removed from the server moderators list");
        }
コード例 #5
0
        private static void PlayerLoginHook(string playerName, out string errorMessage)
        {
            if (ServerOperatorSystem.ServerIsOperator(playerName) ||
                ServerModeratorSystem.ServerIsModerator(playerName))
            {
                // operators/moderators cannot be blocked or kicked
                errorMessage = null;
                return;
            }

            if (IsInBlackList(playerName))
            {
                errorMessage = CannotJoinBanned;
                return;
            }

            if (IsWhiteListEnabled &&
                !WhiteList.Contains(playerName))
            {
                errorMessage = CannotJoinNotInWhitelist;
                return;
            }

            if (IsKicked(playerName,
                         out var secondsRemains,
                         out var message))
            {
                errorMessage = string.Format(CannotJoinKicked,
                                             ClientTimeFormatHelper.FormatTimeDuration(secondsRemains));

                if (!string.IsNullOrEmpty(message))
                {
                    errorMessage = message
                                   + Environment.NewLine
                                   + "[br][br]"
                                   + errorMessage;
                }

                return;
            }

            // all checks passed successfully
            errorMessage = null;
        }
コード例 #6
0
        public void Execute(ICharacter byCharacter, string[] args)
        {
            var sendNotification = Api.IsServer &&
                                   byCharacter is not null;

            try
            {
                var parsedArgs = this.ParseArguments(
                    byCharacter,
                    args,
                    throwExceptionOnUnparsedArgument: true,
                    successfullyParsedArgsCount: out _);
                var resultObj = this.MethodInfo.MethodInfo.Invoke(this.ConsoleCommand, parsedArgs);
                if (resultObj is not null)
                {
                    var result = resultObj.ToString();
                    Api.Logger.Important(
                        $"Console command \"{this.ConsoleCommand.Name}\" completed: {result}",
                        byCharacter);

                    if (sendNotification)
                    {
                        var maxLength = ServerOperatorSystem.ServerIsOperator(byCharacter.Name) ||
                                        ServerModeratorSystem.ServerIsModerator(byCharacter.Name)
                                            ? 30000
                                            : 5000;

                        if (result.Length > maxLength)
                        {
                            result = result.Substring(0, maxLength) + "... (server's response truncated)";
                        }

                        // send notification to this character
                        ConsoleCommandsSystem.ServerOnConsoleCommandResult(
                            byCharacter,
                            this.ConsoleCommand,
                            result);
                    }
                }
            }
            catch (ConsoleCommandWrongArgumentException ex)
            {
                var commandParameter = this.Parameters[ex.Index];
                var message          = new StringBuilder(capacity: 100)
                                       .Append(ex.IsMissing ? "Argument missing" : "Argument wrong/unknown value provided")
                                       .Append(" - argument #")
                                       .Append(ex.Index + 1)
                                       .Append(' ')
                                       .Append(commandParameter.Name).ToString();

                Api.Logger.Warning(message, byCharacter);

                if (sendNotification)
                {
                    // send notification to this character
                    NotificationSystem.ServerSendNotification(
                        byCharacter,
                        "Command cannot be executed: " + this.ConsoleCommand.Name,
                        message,
                        NotificationColor.Bad);
                }
            }
            catch (Exception ex)
            {
                ex = ex.InnerException ?? ex;
                Api.Logger.Warning(ex.Message, byCharacter);

                if (sendNotification)
                {
                    // send notification to this character
                    NotificationSystem.ServerSendNotification(
                        byCharacter,
                        "Command error: " + this.ConsoleCommand.Name,
                        ex.Message,
                        NotificationColor.Bad);
                }
            }
        }