Esempio n. 1
0
        internal static void Commands(Player player, Command cmd)
        {
            string param = cmd.Next();

            CommandDescriptor[] cd;

            if (param == null)
            {
                player.Message("List of available commands:");
                cd = CommandManager.GetCommands(false);
            }
            else if (param.StartsWith("@"))
            {
                string rankName = param.Substring(1);
                Rank   rank     = RankManager.FindRank(rankName);
                if (rank == null)
                {
                    player.Message("Unknown rank: {0}", rankName);
                    return;
                }
                else
                {
                    player.Message("List of commands available to {0}&S:", rank.GetClassyName());
                    cd = CommandManager.GetCommands(rank, true);
                }
            }
            else if (param.Equals("all", StringComparison.OrdinalIgnoreCase))
            {
                player.Message("List of ALL commands:");
                cd = CommandManager.GetCommands();
            }
            else if (param.Equals("hidden", StringComparison.OrdinalIgnoreCase))
            {
                player.Message("List of hidden commands:");
                cd = CommandManager.GetCommands(true);
            }
            else if (Enum.GetNames(typeof(CommandCategory)).Contains(param, StringComparer.OrdinalIgnoreCase))
            {
                CommandCategory category = (CommandCategory)Enum.Parse(typeof(CommandCategory), param, true);
                player.Message("List of {0} commands:", category);
                cd = CommandManager.GetCommands(category, false);
            }
            else if (Enum.GetNames(typeof(Permission)).Contains(param, StringComparer.OrdinalIgnoreCase))
            {
                Permission permission = (Permission)Enum.Parse(typeof(Permission), param, true);
                player.Message("List of commands that need {0} permission:", permission);
                cd = CommandManager.GetCommands(permission, true);
            }
            else
            {
                cdCommands.PrintUsage(player);
                return;
            }

            string[] commandNames = cd.Select(desc => desc.Name).ToArray();

            player.MessagePrefixed("&S   ", "&S   " + String.Join(", ", commandNames));
        }
Esempio n. 2
0
        public void NoAccessMessage(params Permission[] permissions)
        {
            Rank reqRank = RankManager.GetMinRankWithPermission(permissions);

            if (reqRank == null)
            {
                Message("This command is disabled on the server.");
            }
            else
            {
                Message("This command requires {0}+&S rank.",
                        reqRank.GetClassyName());
            }
        }
Esempio n. 3
0
        internal static void ZoneEdit(Player player, Command cmd)
        {
            bool   changesWereMade = false;
            string zoneName        = cmd.Next();

            if (zoneName == null)
            {
                player.Message("No zone name specified. See &H/help zedit");
                return;
            }

            Zone zone = player.World.Map.FindZone(zoneName);

            if (zone == null)
            {
                player.Message("No zone found with the name \"{0}\". See &H/zones", zoneName);
                return;
            }

            string name;

            while ((name = cmd.Next()) != null)
            {
                if (name.Length < 2)
                {
                    continue;
                }

                if (name.StartsWith("+"))
                {
                    PlayerInfo info;
                    if (!PlayerDB.FindPlayerInfo(name.Substring(1), out info))
                    {
                        player.Message("More than one player found matching \"{0}\"", name.Substring(1));
                        return;
                    }

                    if (info == null)
                    {
                        player.NoPlayerMessage(name.Substring(1));
                        return;
                    }

                    // prevent players from whitelisting themselves to bypass protection
                    if (!player.Info.Rank.AllowSecurityCircumvention && player.Info == info)
                    {
                        if (!zone.Controller.Check(info))
                        {
                            player.Message("You must be {0}+&S to add yourself to this zone's whitelist.",
                                           zone.Controller.MinRank.GetClassyName());
                            continue;
                        }
                    }

                    switch (zone.Controller.Include(info))
                    {
                    case PermissionOverride.Deny:
                        player.Message("{0}&S is no longer excluded from zone {1}",
                                       info.GetClassyName(), zone.GetClassyName());
                        changesWereMade = true;
                        break;

                    case PermissionOverride.None:
                        player.Message("{0}&S is now included in zone {1}",
                                       info.GetClassyName(), zone.GetClassyName());
                        changesWereMade = true;
                        break;

                    case PermissionOverride.Allow:
                        player.Message("{0}&S is already included in zone {1}",
                                       info.GetClassyName(), zone.GetClassyName());
                        break;
                    }
                }
                else if (name.StartsWith("-"))
                {
                    PlayerInfo info;
                    if (!PlayerDB.FindPlayerInfo(name.Substring(1), out info))
                    {
                        player.Message("More than one player found matching \"{0}\"", name.Substring(1));
                        return;
                    }

                    if (info == null)
                    {
                        player.NoPlayerMessage(name.Substring(1));
                        return;
                    }

                    switch (zone.Controller.Exclude(info))
                    {
                    case PermissionOverride.Deny:
                        player.Message("{0}&S is already excluded from zone {1}",
                                       info.GetClassyName(), zone.GetClassyName());
                        break;

                    case PermissionOverride.None:
                        player.Message("{0}&S is now excluded from zone {1}",
                                       info.GetClassyName(), zone.GetClassyName());
                        changesWereMade = true;
                        break;

                    case PermissionOverride.Allow:
                        player.Message("{0}&S is no longer included in zone {1}",
                                       info.GetClassyName(), zone.GetClassyName());
                        changesWereMade = true;
                        break;
                    }
                }
                else
                {
                    Rank minRank = RankManager.ParseRank(name);

                    if (minRank != null)
                    {
                        // prevent players from lowering rank so bypass protection
                        if (!player.Info.Rank.AllowSecurityCircumvention &&
                            zone.Controller.MinRank > player.Info.Rank && minRank <= player.Info.Rank)
                        {
                            player.Message("You are not allowed to lower the zone's rank.");
                            continue;
                        }

                        if (zone.Controller.MinRank != minRank)
                        {
                            zone.Controller.MinRank = minRank;
                            player.Message("Permission for zone \"{0}\" changed to {1}+",
                                           zone.Name,
                                           minRank.GetClassyName());
                            changesWereMade = true;
                        }
                    }
                    else
                    {
                        player.NoRankMessage(name);
                    }
                }

                if (changesWereMade)
                {
                    zone.Edit(player.Info);
                    player.World.Map.ChangedSinceSave = true;
                }
                else
                {
                    player.Message("No changes were made to the zone.");
                }
            }
        }