static void Load(bool reloading, bool loadRankList) { JsonObject root; bool fromFile; // load file if (File.Exists(Paths.ConfigFileName)) { try { string raw = File.ReadAllText(Paths.ConfigFileName); root = new JsonObject(raw); fromFile = true; } catch (SerializationException ex) { string errorMsg = "Config.Load: Config file is not properly formatted: " + ex.Message; throw new MisconfigurationException(errorMsg, ex); } } else { Logger.Log(LogType.Warning, "Config.Load: Config file not found; using defaults."); root = new JsonObject(); fromFile = false; } // detect version number int version; if (root.TryGetInt("ConfigVersion", out version)) { if (version < LowestSupportedVersion) { Logger.Log(LogType.Warning, "Config.Load: Your config file is too old to be loaded properly. " + "Some settings will be lost or replaced with defaults. " + "Please run ConfigGUI/ConfigCLI to make sure that everything is in order."); } else if (version != CurrentVersion) { Logger.Log(LogType.Warning, "Config.Load: Your config.xml was made for a different version of fCraft. " + "Some obsolete settings might be ignored, and some recently-added settings will be set to defaults. " + "It is recommended that you run ConfigGUI/ConfigCLI to make sure that everything is in order."); } } else if (fromFile) { Logger.Log(LogType.Warning, "Config.Load: Version number missing from config file. It might be corrupted. " + "Please run ConfigGUI/ConfigCLI to make sure that everything is in order."); } // read rank definitions if (loadRankList) { RankManager.Reset(); // TODO: LoadRankList( config, fromFile ); } // load log options ResetLogOptions(); if (root.HasArray("ConsoleOptions")) { ReadLogOptions(root, "ConsoleOptions", Logger.ConsoleOptions); } else if (fromFile) { Logger.Log(LogType.Warning, "Config.Load: Using default console options."); } if (root.HasArray("LogFileOptions")) { ReadLogOptions(root, "LogFileOptions", Logger.LogFileOptions); } else if (fromFile) { Logger.Log(LogType.Warning, "Config.Load: Using default log file options."); } // load normal config keys JsonObject settings; if (root.TryGetObject("Settings", out settings)) { foreach (var kvp in settings) { ReadSetting(kvp.Key, kvp.Value); } } // apply rank-related settings if (!reloading) { RankManager.DefaultRank = Rank.Parse(ConfigKey.DefaultRank.GetString()); RankManager.DefaultBuildRank = Rank.Parse(ConfigKey.DefaultBuildRank.GetString()); RankManager.PatrolledRank = Rank.Parse(ConfigKey.PatrolledRank.GetString()); RankManager.BlockDBAutoEnableRank = Rank.Parse(ConfigKey.BlockDBAutoEnableRank.GetString()); } // read PlayerDB settings JsonObject playerDBSettings; if (!reloading && root.TryGetObject("PlayerDB", out playerDBSettings)) { ReadPlayerDBSettings(playerDBSettings); } // key relation validation if (ConfigKey.MaxPlayersPerWorld.GetInt() > ConfigKey.MaxPlayers.GetInt()) { Logger.Log(LogType.Warning, "Value of MaxPlayersPerWorld ({0}) was lowered to match MaxPlayers ({1}).", ConfigKey.MaxPlayersPerWorld.GetInt(), ConfigKey.MaxPlayers.GetInt()); ConfigKey.MaxPlayersPerWorld.TrySetValue(ConfigKey.MaxPlayers.GetInt()); } // raise Config.Reloaded, if applicable if (reloading) { RaiseReloadedEvent(); } }
/// <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(); }