ParsePermissionLimits() static private method

static private ParsePermissionLimits ( ) : void
return void
コード例 #1
0
ファイル: Config.cs プロジェクト: TheDireMaster/fCraft
        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();
        }
コード例 #2
0
ファイル: Config.cs プロジェクト: TheDireMaster/fCraft
 /// <summary> Resets the list of ranks to defaults (guest/regular/op/owner).
 /// Warning: This method is not thread-safe. </summary>
 public static void ResetRanks()
 {
     RankManager.Reset();
     DefineDefaultRanks();
     RankManager.ParsePermissionLimits();
 }
コード例 #3
0
ファイル: Config.cs プロジェクト: mstefarov/fCraft
        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();
        }