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;
        }
Ejemplo n.º 2
0
        private static bool ServerIsOperatorOrModerator(ICharacter playerCharacter)
        {
            var name = playerCharacter.Name;

            return(ServerOperatorSystem.ServerIsOperator(name) ||
                   ServerModeratorSystem.ServerIsModerator(name));
        }
Ejemplo n.º 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");
        }
        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");
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Returns true if character has the Moderator role or it's null and we're on the server
 /// (it means the command is invoked from the server system console directly).
 /// </summary>
 public static bool ServerIsModeratorOrSystemConsole(ICharacter character)
 {
     return(ServerModeratorSystem.SharedIsModerator(character) ||
            character is null && Api.IsServer);
 }
Ejemplo n.º 7
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);
                }
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Returns true if character has the Moderator role or it's null and we're on the server
 /// (it means the command is invoked from the server system console directly).
 /// </summary>
 public static bool ServerIsModeratorOrSystemConsole(ICharacter character)
 => ServerModeratorSystem.SharedIsModerator(character) ||
 character == null && Api.IsServer;
 public string Execute([CurrentCharacterIfNull] ICharacter character)
 {
     ServerModeratorSystem.ServerRemove(character);
     return(null);
 }
Ejemplo n.º 10
0
        public string Execute(
            [CustomSuggestions(nameof(GetCommandNameSuggestions))]
            string searchCommand = null)
        {
            var allCommands = ConsoleCommandsSystem.AllCommands.ToList();

            if (Api.IsServer)
            {
                allCommands.RemoveAll(
                    // exclude client commands on Server-side
                    c => (c.Kind ^ ConsoleCommandKinds.Client) == default);
            }

            var currentCharacter = this.ExecutionContextCurrentCharacter;

            if (currentCharacter is not null)
            {
                var isOperator  = ServerOperatorSystem.SharedIsOperator(currentCharacter);
                var isModerator = ServerModeratorSystem.SharedIsModerator(currentCharacter);
                ConsoleCommandsSystem.SharedFilterAvailableCommands(allCommands, isOperator, isModerator);
            }

            var sb = new StringBuilder(capacity: 2047);

            sb.AppendLine().AppendLine();

            if (!string.IsNullOrEmpty(searchCommand))
            {
                var foundCommandsList =
                    allCommands.Where(
                        c => c.Name.StartsWith(searchCommand, StringComparison.OrdinalIgnoreCase) ||
                        c.Alias is not null &&
                        c.Alias.StartsWith(searchCommand, StringComparison.OrdinalIgnoreCase))
                    .ToList();
                if (foundCommandsList.Count == 0)
                {
                    sb.Append("No commands found.");
                    return(sb.ToString());
                }

                allCommands = foundCommandsList;
            }

            //AppendLegend(sb);
            //sb.AppendLine();
            sb.AppendLine("Commands: ");

            foreach (var consoleCommand in allCommands)
            {
                string prefix;
                switch (consoleCommand.Kind)
                {
                // add server suffix for server commands
                case ConsoleCommandKinds.ServerEveryone:
                case ConsoleCommandKinds.ServerOperator:
                case ConsoleCommandKinds.ServerModerator:
                    prefix = "/";
                    break;

                case ConsoleCommandKinds.ClientAndServerEveryone:
                case ConsoleCommandKinds.ClientAndServerOperatorOnly:
                    prefix = "(/)";
                    break;

                default:
                    prefix = string.Empty;
                    break;
                }

                AppendCommandInfo(sb, consoleCommand, prefix);
            }

            return(sb.ToString());
        }