public void ResetClasses() { classes = new ClassList(world); XElement classList = DefineDefaultClasses(); foreach (XElement pc in classList.Elements()) { DefineClass(pc); } // parse rank-limit permissions foreach (PlayerClass pc in classes.classesByIndex) { classes.ParseClassLimits(pc); } }
public bool Load(string configFileName) { // generate random salt Salt = new Random().Next(); LoadDefaults(); bool fromFile = false; // try to load config file (XML) XDocument file; if (File.Exists(configFileName)) { try { file = XDocument.Load(configFileName); if (file.Root == null || file.Root.Name != ConfigRootName) { Log("Config.Load: Malformed or incompatible config file {0}. Loading defaults.", LogType.Warning, configFileName); file = new XDocument(); file.Add(new XElement(ConfigRootName)); } else { Log("Config.Load: Config file {0} loaded succesfully.", LogType.Debug, configFileName); fromFile = true; } } catch (Exception ex) { Log("Config.Load: Fatal error while loading config file {0}: {1}", LogType.FatalError, configFileName, ex.Message); return(false); } } else { // create a new one (with defaults) if no file exists file = new XDocument(); file.Add(new XElement(ConfigRootName)); } XElement config = file.Root; XAttribute attr = config.Attribute("version"); int version; if (fromFile && (attr == null || !Int32.TryParse(attr.Value, out version) || version < ConfigVersion)) { Log("Config.Load: Your config.xml was made for an older version of fCraft. " + "Some obsolete settings might be ignored, and some recently-added settings will be set to their default values. " + "It is recommended that you run ConfigTool to make sure everything is in order.", LogType.Warning); } XElement classList = config.Element("Classes"); if (classList != null) { foreach (XElement playerClass in classList.Elements("PlayerClass")) { if (!DefineClass(playerClass)) { Log("Config.Load: Could not parse one of the class definitions.", LogType.Warning); } } if (classes.classes.Count == 0) { Log("Config.Load: No classes were defined, or none were defined correctly. Using default player classes.", LogType.Warning); config.Add(DefineDefaultClasses()); } } else { if (fromFile) { Log("Config.Load: using default player classes.", LogType.Warning); } config.Add(DefineDefaultClasses()); } // parse rank-limit permissions foreach (PlayerClass pc in classes.classesByIndex) { if (!classes.ParseClassLimits(pc)) { Log("Could not parse one of the rank-limits for kick, ban, promote, and/or demote permissions for {0}. " + "Any unrecognized limits were reset to default (own class).", LogType.Warning, pc.name); } } XElement consoleOptions = config.Element("ConsoleOptions"); if (consoleOptions != null) { ParseLogOptions(consoleOptions, ref logger.consoleOptions); } else { if (fromFile) { Log("Config.Load: using default console options.", LogType.Warning); } for (int i = 0; i < logger.consoleOptions.Length; i++) { logger.consoleOptions[i] = true; } logger.consoleOptions[(int)LogType.ConsoleInput] = false; logger.consoleOptions[(int)LogType.Debug] = false; } XElement logFileOptions = config.Element("LogFileOptions"); if (logFileOptions != null) { ParseLogOptions(logFileOptions, ref logger.logFileOptions); } else { if (fromFile) { Log("Config.Load: using default log file options.", LogType.Warning); } for (int i = 0; i < logger.logFileOptions.Length; i++) { logger.logFileOptions[i] = true; } } // Load config foreach (XElement element in config.Elements()) { if (settings.ContainsKey(element.Name.ToString())) { // known key SetValue(element.Name.ToString(), element.Value); } else if (element.Name.ToString() != "ConsoleOptions" && element.Name.ToString() != "LogFileOptions" && element.Name.ToString() != "Classes") { // unknown key Log("Unrecognized entry ignored: {0} = {1}", LogType.Debug, element.Name, element.Value); //TODO: custom settings store //settings.Add( element.Name.ToString(), element.Value ); } } return(true); }
public void ResetClasses() { classes = new ClassList( world ); XElement classList = DefineDefaultClasses(); foreach( XElement pc in classList.Elements() ) { DefineClass( pc ); } // parse rank-limit permissions foreach( PlayerClass pc in classes.classesByIndex ) { classes.ParseClassLimits( pc ); } }