AddRank() public static méthode

Adds a new rank to the list. Checks for duplicates.
public static AddRank ( Rank rank ) : void
rank Rank
Résultat void
Exemple #1
0
        static void LoadRankList(XElement el, int version, bool fromFile)
        {
            if (el == null)
            {
                throw new ArgumentNullException("el");
            }

            XElement legacyRankMappingTag = el.Element("LegacyRankMapping");

            if (legacyRankMappingTag != null)
            {
                foreach (XElement rankPair in legacyRankMappingTag.Elements("LegacyRankPair"))
                {
                    XAttribute fromRankID = rankPair.Attribute("from");
                    XAttribute toRankID   = rankPair.Attribute("to");
                    if (fromRankID == null || String.IsNullOrEmpty(fromRankID.Value) ||
                        toRankID == null || String.IsNullOrEmpty(toRankID.Value))
                    {
                        Logger.Log("Config.Load: Could not parse a LegacyRankMapping entry: {0}", LogType.Error, rankPair.ToString());
                    }
                    else
                    {
                        RankManager.LegacyRankMapping.Add(fromRankID.Value, toRankID.Value);
                    }
                }
            }

            XElement rankList = el.Element("Ranks") ?? el.Element("Classes");

            if (rankList != null)
            {
                XElement[] rankDefinitionList = rankList.Elements("Rank").ToArray();
                if (rankDefinitionList.Length == 0)
                {
                    rankDefinitionList = rankList.Elements("PlayerClass").ToArray();   // LEGACY
                }
                foreach (XElement rankDefinition in rankDefinitionList)
                {
                    try {
                        RankManager.AddRank(new Rank(rankDefinition));
                    } catch (RankDefinitionException ex) {
                        Logger.Log(ex.Message, LogType.Error);
                    }
                }

                if (RankManager.RanksByName.Count == 0)
                {
                    Logger.Log("Config.Load: No ranks were defined, or none were defined correctly. Using default ranks (guest, regular, op, and owner).", LogType.Warning);
                    rankList.Remove();
                    el.Add(DefineDefaultRanks());
                }
                else if (version < ConfigVersion)      // start LEGACY code

                {
                    if (version < 103)    // speedhack permission
                    {
                        if (!RankManager.RanksByID.Values.Any(rank => rank.Can(Permission.UseSpeedHack)))
                        {
                            foreach (Rank rank in RankManager.RanksByID.Values)
                            {
                                rank.Permissions[(int)Permission.UseSpeedHack] = true;
                            }
                            Logger.Log("Config.Load: All ranks were granted UseSpeedHack permission (default). " +
                                       "Use ConfigTool to update config. If you are editing config.xml manually, " +
                                       "set version=\"{0}\" to prevent permissions from resetting in the future.", LogType.Warning, ConfigVersion);
                        }
                    }

                    if (version < 111)
                    {
                        RankManager.SortRanksByLegacyNumericRank();
                    }
                } // end LEGACY code
            }
            else
            {
                if (fromFile)
                {
                    Logger.Log("Config.Load: using default player ranks.", LogType.Warning);
                }
                el.Add(DefineDefaultRanks());
            }

            // parse rank-limit permissions
            RankManager.ParsePermissionLimits();
        }
Exemple #2
0
        static XElement DefineDefaultRanks()
        {
            XElement permissions = new XElement("Ranks");

            XElement owner = new XElement("Rank");

            owner.Add(new XAttribute("id", RankManager.GenerateID()));
            owner.Add(new XAttribute("name", "owner"));
            owner.Add(new XAttribute("rank", 100));
            owner.Add(new XAttribute("color", "red"));
            owner.Add(new XAttribute("prefix", "+"));
            owner.Add(new XAttribute("drawLimit", 0));
            owner.Add(new XAttribute("antiGriefBlocks", 0));
            owner.Add(new XAttribute("antiGriefSeconds", 0));
            owner.Add(new XAttribute("idleKickAfter", 0));
            owner.Add(new XAttribute("reserveSlot", true));
            owner.Add(new XAttribute("allowSecurityCircumvention", true));

            owner.Add(new XElement(Permission.Chat.ToString()));
            owner.Add(new XElement(Permission.Build.ToString()));
            owner.Add(new XElement(Permission.Delete.ToString()));
            owner.Add(new XElement(Permission.UseSpeedHack.ToString()));
            owner.Add(new XElement(Permission.UseColorCodes.ToString()));

            owner.Add(new XElement(Permission.PlaceGrass.ToString()));
            owner.Add(new XElement(Permission.PlaceWater.ToString()));
            owner.Add(new XElement(Permission.PlaceLava.ToString()));
            owner.Add(new XElement(Permission.PlaceAdmincrete.ToString()));
            owner.Add(new XElement(Permission.DeleteAdmincrete.ToString()));

            owner.Add(new XElement(Permission.Say.ToString()));
            owner.Add(new XElement(Permission.ReadStaffChat.ToString()));
            XElement temp = new XElement(Permission.Kick.ToString());

            temp.Add(new XAttribute("max", "owner"));
            owner.Add(temp);
            temp = new XElement(Permission.Ban.ToString());
            temp.Add(new XAttribute("max", "owner"));
            owner.Add(temp);
            owner.Add(new XElement(Permission.BanIP.ToString()));
            owner.Add(new XElement(Permission.BanAll.ToString()));

            temp = new XElement(Permission.Promote.ToString());
            temp.Add(new XAttribute("max", "owner"));
            owner.Add(temp);
            temp = new XElement(Permission.Demote.ToString());
            temp.Add(new XAttribute("max", "owner"));
            owner.Add(temp);
            owner.Add(new XElement(Permission.Hide.ToString()));

            owner.Add(new XElement(Permission.ViewOthersInfo.ToString()));
            owner.Add(new XElement(Permission.ViewPlayerIPs.ToString()));
            owner.Add(new XElement(Permission.EditPlayerDB.ToString()));

            owner.Add(new XElement(Permission.Teleport.ToString()));
            owner.Add(new XElement(Permission.Bring.ToString()));
            owner.Add(new XElement(Permission.BringAll.ToString()));
            owner.Add(new XElement(Permission.Patrol.ToString()));
            //owner.Add( new XElement( Permission.Spectate.ToString() ) );
            owner.Add(new XElement(Permission.Freeze.ToString()));
            owner.Add(new XElement(Permission.Mute.ToString()));
            owner.Add(new XElement(Permission.SetSpawn.ToString()));

            owner.Add(new XElement(Permission.Lock.ToString()));

            owner.Add(new XElement(Permission.ManageZones.ToString()));
            owner.Add(new XElement(Permission.ManageWorlds.ToString()));
            owner.Add(new XElement(Permission.Import.ToString()));
            owner.Add(new XElement(Permission.Draw.ToString()));
            owner.Add(new XElement(Permission.CopyAndPaste.ToString()));

            owner.Add(new XElement(Permission.ReloadConfig.ToString()));
            owner.Add(new XElement(Permission.ShutdownServer.ToString()));
            permissions.Add(owner);
            try {
                RankManager.AddRank(new Rank(owner));
            } catch (RankDefinitionException ex) {
                Logger.Log(ex.Message, LogType.Error);
            }


            XElement op = new XElement("Rank");

            op.Add(new XAttribute("id", RankManager.GenerateID()));
            op.Add(new XAttribute("name", "op"));
            op.Add(new XAttribute("rank", 80));
            op.Add(new XAttribute("color", "aqua"));
            op.Add(new XAttribute("prefix", "-"));
            op.Add(new XAttribute("drawLimit", 0));
            op.Add(new XAttribute("antiGriefBlocks", 0));
            op.Add(new XAttribute("antiGriefSeconds", 0));
            op.Add(new XAttribute("idleKickAfter", 0));

            op.Add(new XElement(Permission.Chat.ToString()));
            op.Add(new XElement(Permission.Build.ToString()));
            op.Add(new XElement(Permission.Delete.ToString()));
            op.Add(new XElement(Permission.UseSpeedHack.ToString()));
            op.Add(new XElement(Permission.UseColorCodes.ToString()));

            op.Add(new XElement(Permission.PlaceGrass.ToString()));
            op.Add(new XElement(Permission.PlaceWater.ToString()));
            op.Add(new XElement(Permission.PlaceLava.ToString()));
            op.Add(new XElement(Permission.PlaceAdmincrete.ToString()));
            op.Add(new XElement(Permission.DeleteAdmincrete.ToString()));

            op.Add(new XElement(Permission.Say.ToString()));
            op.Add(new XElement(Permission.ReadStaffChat.ToString()));
            temp = new XElement(Permission.Kick.ToString());
            temp.Add(new XAttribute("max", "op"));
            op.Add(temp);
            temp = new XElement(Permission.Ban.ToString());
            temp.Add(new XAttribute("max", "regular"));
            op.Add(temp);
            op.Add(new XElement(Permission.BanIP.ToString()));

            temp = new XElement(Permission.Promote.ToString());
            temp.Add(new XAttribute("max", "regular"));
            op.Add(temp);
            temp = new XElement(Permission.Demote.ToString());
            temp.Add(new XAttribute("max", "regular"));
            op.Add(temp);
            op.Add(new XElement(Permission.Hide.ToString()));

            op.Add(new XElement(Permission.ViewOthersInfo.ToString()));
            op.Add(new XElement(Permission.ViewPlayerIPs.ToString()));

            op.Add(new XElement(Permission.Teleport.ToString()));
            op.Add(new XElement(Permission.Bring.ToString()));
            op.Add(new XElement(Permission.Patrol.ToString()));
            //op.Add( new XElement( Permission.Spectate.ToString() ) );
            op.Add(new XElement(Permission.Freeze.ToString()));
            op.Add(new XElement(Permission.Mute.ToString()));
            op.Add(new XElement(Permission.SetSpawn.ToString()));

            op.Add(new XElement(Permission.ManageZones.ToString()));
            op.Add(new XElement(Permission.Lock.ToString()));
            op.Add(new XElement(Permission.Draw.ToString()));
            op.Add(new XElement(Permission.CopyAndPaste.ToString()));
            permissions.Add(op);
            try {
                RankManager.AddRank(new Rank(op));
            } catch (RankDefinitionException ex) {
                Logger.Log(ex.Message, LogType.Error);
            }


            XElement regular = new XElement("Rank");

            regular.Add(new XAttribute("id", RankManager.GenerateID()));
            regular.Add(new XAttribute("name", "regular"));
            regular.Add(new XAttribute("rank", 30));
            regular.Add(new XAttribute("color", "white"));
            regular.Add(new XAttribute("prefix", ""));
            regular.Add(new XAttribute("drawLimit", 4096));
            regular.Add(new XAttribute("antiGriefBlocks", 47));
            regular.Add(new XAttribute("antiGriefSeconds", 6));
            regular.Add(new XAttribute("idleKickAfter", 20));

            regular.Add(new XElement(Permission.Chat.ToString()));
            regular.Add(new XElement(Permission.Build.ToString()));
            regular.Add(new XElement(Permission.Delete.ToString()));
            regular.Add(new XElement(Permission.UseSpeedHack.ToString()));

            regular.Add(new XElement(Permission.PlaceGrass.ToString()));
            regular.Add(new XElement(Permission.PlaceWater.ToString()));
            regular.Add(new XElement(Permission.PlaceLava.ToString()));
            regular.Add(new XElement(Permission.PlaceAdmincrete.ToString()));
            regular.Add(new XElement(Permission.DeleteAdmincrete.ToString()));

            temp = new XElement(Permission.Kick.ToString());
            temp.Add(new XAttribute("max", "regular"));
            regular.Add(temp);

            regular.Add(new XElement(Permission.ViewOthersInfo.ToString()));

            regular.Add(new XElement(Permission.Teleport.ToString()));

            regular.Add(new XElement(Permission.Draw.ToString()));
            permissions.Add(regular);
            try {
                RankManager.AddRank(new Rank(regular));
            } catch (RankDefinitionException ex) {
                Logger.Log(ex.Message, LogType.Error);
            }


            XElement guest = new XElement("Rank");

            guest.Add(new XAttribute("id", RankManager.GenerateID()));
            guest.Add(new XAttribute("name", "guest"));
            guest.Add(new XAttribute("rank", 0));
            guest.Add(new XAttribute("color", "silver"));
            guest.Add(new XAttribute("prefix", ""));
            guest.Add(new XAttribute("drawLimit", 512));
            guest.Add(new XAttribute("antiGriefBlocks", 37));
            guest.Add(new XAttribute("antiGriefSeconds", 5));
            guest.Add(new XAttribute("idleKickAfter", 20));
            guest.Add(new XElement(Permission.Chat.ToString()));
            guest.Add(new XElement(Permission.Build.ToString()));
            guest.Add(new XElement(Permission.Delete.ToString()));
            guest.Add(new XElement(Permission.UseSpeedHack.ToString()));
            permissions.Add(guest);
            try {
                RankManager.AddRank(new Rank(guest));
            } catch (RankDefinitionException ex) {
                Logger.Log(ex.Message, LogType.Error);
            }

            return(permissions);
        }
Exemple #3
0
        static void LoadRankList([NotNull] XContainer el, bool fromFile)
        {
            if (el == null)
            {
                throw new ArgumentNullException("el");
            }

            XElement legacyRankMappingTag = el.Element("LegacyRankMapping");

            if (legacyRankMappingTag != null)
            {
                foreach (XElement rankPair in legacyRankMappingTag.Elements("LegacyRankPair"))
                {
                    XAttribute fromRankID = rankPair.Attribute("from");
                    XAttribute toRankID   = rankPair.Attribute("to");
                    if (fromRankID == null || String.IsNullOrEmpty(fromRankID.Value) ||
                        toRankID == null || String.IsNullOrEmpty(toRankID.Value))
                    {
                        Logger.Log(LogType.Error,
                                   "Config.Load: Could not parse a LegacyRankMapping entry: {0}", rankPair);
                    }
                    else
                    {
                        RankManager.LegacyRankMapping.Add(fromRankID.Value, toRankID.Value);
                    }
                }
            }

            XElement rankList = el.Element("Ranks");

            if (rankList != null)
            {
                XElement[] rankDefinitionList = rankList.Elements("Rank").ToArray();

                foreach (XElement rankDefinition in rankDefinitionList)
                {
                    try {
                        RankManager.AddRank(new Rank(rankDefinition));
                    } catch (RankDefinitionException ex) {
                        Logger.Log(LogType.Error, ex.Message);
                    }
                }

                if (RankManager.RanksByName.Count == 0)
                {
                    Logger.Log(LogType.Warning,
                               "Config.Load: No ranks were defined, or none were defined correctly. " +
                               "Using default ranks (guest, builder, op, and owner).");
                    rankList.Remove();
                    el.Add(DefineDefaultRanks());
                }
            }
            else
            {
                if (fromFile)
                {
                    Logger.Log(LogType.Warning, "Config.Load: using default player ranks.");
                }
                el.Add(DefineDefaultRanks());
            }

            // parse rank-limit permissions
            RankManager.ParsePermissionLimits();
        }