Exemple #1
0
        private void Load()
        {
            m_Document = new XmlDocument();

            m_DataDirectories = new List <string>();

            if (Exists)
            {
                XmlTextReader reader = new XmlTextReader(m_Filename);

                try
                {
                    m_Document.Load(reader);
                }
                finally
                {
                    reader.Close();
                }
            }
            else
            {
                m_Document.AppendChild(m_Document.CreateElement("x-runuo-config"));
            }

            // Section "global"
            XmlElement global = GetConfiguration("global");

            if (global != null)
            {
                foreach (XmlNode node in global.ChildNodes)
                {
                    if (node.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }

                    XmlElement element = (XmlElement)node;

                    switch (node.Name)
                    {
                    case "server-name":
                    {
                        m_ServerName = element.GetAttribute("value");
                        break;
                    }

                    case "website":
                    {
                        m_Website = element.GetAttribute("value");
                        break;
                    }

                    case "server-email":
                    {
                        m_ServerEmail = element.GetAttribute("value");
                        break;
                    }

                    case "multi-threading":
                    {
                        m_Features[node.Name] = Parser.ParseBool(element.GetAttribute("value"), true);
                        break;
                    }

                    case "feature":
                    {
                        m_Features[element.GetAttribute("name")] = Parser.ParseBool(element.GetAttribute("value"), true);
                        break;
                    }

                    case "save-interval":
                    {
                        double saveInterval = Convert.ToDouble(element.GetAttribute("value"));

                        if (saveInterval < 1.0)
                        {
                            Console.WriteLine("Warning: Invalid value of save-interval, setting it to default");
                        }
                        else
                        {
                            m_SaveInterval = TimeSpan.FromMinutes(saveInterval);
                        }

                        break;
                    }

                    case "account-decay":
                    {
                        m_AccountDecay = TimeSpan.FromDays(Convert.ToDouble(element.GetAttribute("value")));

                        break;
                    }

                    default:
                    {
                        Console.WriteLine("Warning: Invalid element global/{0}", node.Name);
                        break;
                    }
                    }
                }

                // Setup core features.
                Expansion.HS = Features["high-seas"];

                ObjectPropertyListPacket.Enabled = true;
                Mobile.InsuranceEnabled          = true;

                Environment.Logging = Features["logging"];

                World.ManualGC = Features["manual-gc"];
                World.DualSave = Features["dual-save"];
            }

            // Section "locations"
            XmlElement locations = GetConfiguration("locations");

            foreach (XmlNode node in locations.ChildNodes)
            {
                XmlElement element = node as XmlElement;

                if (element != null)
                {
                    string path = element.InnerText;

                    switch (element.Name)
                    {
                    case "config-dir":
                    {
                        m_ConfigDirectory = path;
                        break;
                    }

                    case "save-dir":
                    {
                        m_SaveDirectory = path;
                        break;
                    }

                    case "backup-dir":
                    {
                        m_BackupDirectory = path;
                        break;
                    }

                    case "data-path":
                    {
                        if (Directory.Exists(path))
                        {
                            m_DataDirectories.Add(path);
                        }

                        break;
                    }

                    case "log-dir":
                    {
                        m_LogDirectory = path;
                        break;
                    }

                    case "cache-dir":
                    {
                        m_CacheDirectory = path;
                        break;
                    }

                    default:
                    {
                        Console.WriteLine("Warning: Ignoring unknown location tag in {0}: {1}", m_Filename, element.Name);
                        break;
                    }
                    }
                }
            }

            // Section "libraries"
            XmlElement librariesEl = GetConfiguration("libraries");

            foreach (XmlElement element in librariesEl.GetElementsByTagName("library"))
            {
                string name = element.GetAttribute("name");

                if (string.IsNullOrEmpty(name))
                {
                    Console.WriteLine("Warning: library element without name attribute");
                    continue;
                }

                name = name.ToLower();

                Library libConfig = (Library)m_LibraryConfig[name];

                if (libConfig == null)
                {
                    m_LibraryConfig[name] = libConfig = new Library(name);
                }

                libConfig.Load(element);
            }

            if (!m_LibraryConfig.ContainsKey("distro"))
            {
                m_LibraryConfig["distro"] = new Library("distro");
            }

            // Section "network"
            XmlElement networkEl = GetConfiguration("network");

            m_Network = networkEl == null
                                ? new Network()
                                : new Network(networkEl);

            // Section "server-list"
            XmlElement serverListEl = GetConfiguration("server-list");

            if (serverListEl != null)
            {
                m_GameServers = new GameServerList(serverListEl);
            }

            // Config modules
            foreach (Type t in GetTypesWithAttribute(Assembly.GetExecutingAssembly(), typeof(ConfigModuleAttribute)))
            {
                m_ConfigModules[t] = DeserializeModule(t);
            }
        }
Exemple #2
0
        private void Load()
        {
            m_Document = new XmlDocument();

            DataDirectories = new List <string>();

            if (Exists)
            {
                var reader = new XmlTextReader(m_Filename);

                try
                {
                    m_Document.Load(reader);
                }
                finally
                {
                    reader.Close();
                }
            }
            else
            {
                m_Document.AppendChild(m_Document.CreateElement("x-runuo-config"));
            }

            // Section "global"
            var global = GetConfiguration("global");

            if (global != null)
            {
                foreach (XmlNode node in global.ChildNodes)
                {
                    if (node.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }

                    var element = (XmlElement)node;

                    switch (node.Name)
                    {
                    case "server-name":
                    {
                        ServerName = element.GetAttribute("value");
                        break;
                    }

                    case "website":
                    {
                        Website = element.GetAttribute("value");
                        break;
                    }

                    case "server-email":
                    {
                        ServerEmail = element.GetAttribute("value");
                        break;
                    }

                    case "multi-threading":
                    {
                        Features[node.Name] = Parser.ParseBool(element.GetAttribute("value"), true);
                        break;
                    }

                    case "feature":
                    {
                        Features[element.GetAttribute("name")] = Parser.ParseBool(element.GetAttribute("value"), true);
                        break;
                    }

                    case "save-interval":
                    {
                        var saveInterval = Convert.ToDouble(element.GetAttribute("value"));

                        if (saveInterval < 1.0)
                        {
                            log.Warning("Invalid value of save-interval, setting it to default");
                        }
                        else
                        {
                            SaveInterval = TimeSpan.FromMinutes(saveInterval);
                        }

                        break;
                    }

                    case "account-decay":
                    {
                        AccountDecay = TimeSpan.FromDays(Convert.ToDouble(element.GetAttribute("value")));

                        break;
                    }

                    default:
                    {
                        log.Warning("Invalid element global/{0}", node.Name);
                        break;
                    }
                    }
                }

                // Setup core features.
                Expansion.HS = Features["high-seas"];

                ObjectPropertyListPacket.Enabled = true;
                Mobile.InsuranceEnabled          = true;

                Core.Logging = Features["logging"];

                World.ManualGC = Features["manual-gc"];
                World.DualSave = Features["dual-save"];
            }

            // Section "locations"
            var locations = GetConfiguration("locations");

            foreach (XmlNode node in locations.ChildNodes)
            {
                var element = node as XmlElement;

                if (element != null)
                {
                    var path = element.InnerText;

                    switch (element.Name)
                    {
                    case "config-dir":
                    {
                        ConfigDirectory = path;
                        break;
                    }

                    case "save-dir":
                    {
                        SaveDirectory = path;
                        break;
                    }

                    case "backup-dir":
                    {
                        BackupDirectory = path;
                        break;
                    }

                    case "data-path":
                    {
                        if (Directory.Exists(path))
                        {
                            DataDirectories.Add(path);
                        }

                        break;
                    }

                    case "log-dir":
                    {
                        LogDirectory = path;
                        break;
                    }

                    case "cache-dir":
                    {
                        CacheDirectory = path;
                        break;
                    }

                    default:
                    {
                        log.Warning("Ignoring unknown location tag in {0}: {1}", m_Filename, element.Name);
                        break;
                    }
                    }
                }
            }

            // Section "network"
            var networkEl = GetConfiguration("network");

            Network = networkEl == null
                                ? new Network()
                                : new Network(networkEl);

            // Section "server-list"
            var serverListEl = GetConfiguration("server-list");

            if (serverListEl != null)
            {
                GameServers = new GameServerList(serverListEl);
            }

            // Config modules
            foreach (var t in GetTypesWithAttribute(Assembly.GetExecutingAssembly(), typeof(ConfigModuleAttribute)))
            {
                m_ConfigModules[t] = DeserializeModule(t);
            }
        }