From d9528bd06e770d9d0bfc1c34d83abb02e7489e66 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Thu, 25 Jun 2009 15:48:54 +0000 Subject: Allow the reading of ini files instead of xml files when reading region definitions from the file system --- OpenSim/Framework/RegionInfo.cs | 160 +++++++++++++++------ .../Filesystem/RegionLoaderFileSystem.cs | 29 +++- 2 files changed, 139 insertions(+), 50 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/RegionInfo.cs b/OpenSim/Framework/RegionInfo.cs index db23af9..2423097 100644 --- a/OpenSim/Framework/RegionInfo.cs +++ b/OpenSim/Framework/RegionInfo.cs @@ -209,7 +209,7 @@ namespace OpenSim.Framework public bool isSandbox = false; private EstateSettings m_estateSettings; private RegionSettings m_regionSettings; - //private IConfigSource m_configSource = null; + // private IConfigSource m_configSource = null; public UUID MasterAvatarAssignedUUID = UUID.Zero; public string MasterAvatarFirstName = String.Empty; @@ -238,18 +238,51 @@ namespace OpenSim.Framework // access the same database server. Since estate settings are lodaed // from there, that should be sufficient for full remote administration - public RegionInfo(string description, string filename, bool skipConsoleConfig, IConfigSource configSource) + // File based loading + // + public RegionInfo(string description, string filename, bool skipConsoleConfig, IConfigSource configSource) : this(description, filename, skipConsoleConfig, configSource, String.Empty) { - //m_configSource = configSource; + } + + public RegionInfo(string description, string filename, bool skipConsoleConfig, IConfigSource configSource, string configName) + { + // m_configSource = configSource; + + if (filename.ToLower().EndsWith(".ini")) + { + IConfigSource source = new IniConfigSource(filename); + + ReadNiniConfig(source, configName); + + return; + } + + try + { + // This will throw if it's not legal Nini XML format + // and thereby toss it to the legacy loader + // + IConfigSource xmlsource = new XmlConfigSource(filename); + + ReadNiniConfig(xmlsource, configName); + + return; + } + catch (Exception) + { + } + configMember = new ConfigurationMember(filename, description, loadConfigurationOptions, handleIncomingConfiguration, !skipConsoleConfig); configMember.performConfigurationRetrieve(); RegionFile = filename; } + // The web loader uses this + // public RegionInfo(string description, XmlNode xmlNode, bool skipConsoleConfig, IConfigSource configSource) { - //m_configSource = configSource; + // m_configSource = configSource; configMember = new ConfigurationMember(xmlNode, description, loadConfigurationOptions, handleIncomingConfiguration, !skipConsoleConfig); configMember.performConfigurationRetrieve(); @@ -355,53 +388,92 @@ namespace OpenSim.Framework m_internalEndPoint = tmpEPE; } - //not in use, should swap to nini though. - public void LoadFromNiniSource(IConfigSource source) + private void ReadNiniConfig(IConfigSource source, string name) { - LoadFromNiniSource(source, "RegionInfo"); - } + if (name == String.Empty) + name = source.Configs[0].Name; - //not in use, should swap to nini though. - public void LoadFromNiniSource(IConfigSource source, string sectionName) - { - string errorMessage = String.Empty; - RegionID = new UUID(source.Configs[sectionName].GetString("Region_ID", UUID.Random().ToString())); - RegionName = source.Configs[sectionName].GetString("sim_name", "OpenSim Test"); - m_regionLocX = Convert.ToUInt32(source.Configs[sectionName].GetString("sim_location_x", "1000")); - m_regionLocY = Convert.ToUInt32(source.Configs[sectionName].GetString("sim_location_y", "1000")); - // this.DataStore = source.Configs[sectionName].GetString("datastore", "OpenSim.db"); + if (source.Configs[name] == null) + throw new Exception("Config name does not exist"); - string ipAddress = source.Configs[sectionName].GetString("internal_ip_address", "0.0.0.0"); - IPAddress ipAddressResult; - if (IPAddress.TryParse(ipAddress, out ipAddressResult)) - { - m_internalEndPoint = new IPEndPoint(ipAddressResult, 0); - } - else - { - errorMessage = "needs an IP Address (IPAddress)"; - } - m_internalEndPoint.Port = - source.Configs[sectionName].GetInt("internal_ip_port", (int) ConfigSettings.DefaultRegionHttpPort); + IConfig config = source.Configs[name]; - string externalHost = source.Configs[sectionName].GetString("external_host_name", "127.0.0.1"); - if (externalHost != "SYSTEMIP") - { - m_externalHostName = externalHost; - } - else - { + // UUID + // + string regionUUID = config.GetString("RegionUUID", string.Empty); + + if (regionUUID == String.Empty) + throw new Exception("A region UUID is required"); + + RegionID = new UUID(regionUUID); + originRegionID = RegionID; // What IS this?! + + + // Region name + // + RegionName = name; + + + // Region location + // + string location = config.GetString("Location", String.Empty); + + if (location == String.Empty) + throw new Exception("Location is required"); + + string[] locationElements = location.Split(new char[] {','}); + + m_regionLocX = Convert.ToUInt32(locationElements[0]); + m_regionLocY = Convert.ToUInt32(locationElements[1]); + + + // Datastore + // + DataStore = config.GetString("Datastore", String.Empty); + + + // Internal IP + // + IPAddress address = IPAddress.Parse(config.GetString("InternalAddress", "127.0.0.1")); + int port = config.GetInt("InternalPort", 9000); + + m_internalEndPoint = new IPEndPoint(address, port); + + m_allow_alternate_ports = config.GetBoolean("AllowAlternatePorts", true); + + // External IP + // + string externalName = config.GetString("ExternalHostName", "SYSTEMIP"); + if (externalName == "SYSTEMIP") m_externalHostName = Util.GetLocalHost().ToString(); - } + else + m_externalHostName = externalName; - MasterAvatarFirstName = source.Configs[sectionName].GetString("master_avatar_first", "Test"); - MasterAvatarLastName = source.Configs[sectionName].GetString("master_avatar_last", "User"); - MasterAvatarSandboxPassword = source.Configs[sectionName].GetString("master_avatar_pass", "test"); - if (errorMessage != String.Empty) - { - // a error - } + // Master avatar cruft + // + string masterAvatarUUID = config.GetString("MasterAvatarUUID", UUID.Zero.ToString()); + MasterAvatarAssignedUUID = new UUID(masterAvatarUUID); + + MasterAvatarFirstName = config.GetString("MasterAvatarFirstName", String.Empty); + MasterAvatarLastName = config.GetString("MasterAvatarLastName", String.Empty); + MasterAvatarSandboxPassword = config.GetString("MasterAvatarSandboxPassword", String.Empty); + + + // Prim stuff + // + m_nonphysPrimMax = config.GetInt("NonphysicalPrimMax", 256); + + m_physPrimMax = config.GetInt("PhysicalPrimMax", 10); + + m_clampPrimSize = config.GetBoolean("ClampPrimSize", false); + + m_objectCapacity = config.GetInt("MaxPrims", 15000); + + + // Multi-tenancy + // + ScopeID = new UUID(config.GetString("ScopeID", UUID.Zero.ToString())); } public bool ignoreIncomingConfiguration(string configuration_key, object configuration_result) diff --git a/OpenSim/Framework/RegionLoader/Filesystem/RegionLoaderFileSystem.cs b/OpenSim/Framework/RegionLoader/Filesystem/RegionLoaderFileSystem.cs index c58c41d..b4b15e4 100644 --- a/OpenSim/Framework/RegionLoader/Filesystem/RegionLoaderFileSystem.cs +++ b/OpenSim/Framework/RegionLoader/Filesystem/RegionLoaderFileSystem.cs @@ -26,6 +26,7 @@ */ using System; +using System.Collections.Generic; using System.IO; using Nini.Config; @@ -60,21 +61,37 @@ namespace OpenSim.Framework.RegionLoader.Filesystem } string[] configFiles = Directory.GetFiles(regionConfigPath, "*.xml"); + string[] iniFiles = Directory.GetFiles(regionConfigPath, "*.ini"); - if (configFiles.Length == 0) + if (configFiles.Length == 0 && iniFiles.Length == 0) { new RegionInfo("DEFAULT REGION CONFIG", Path.Combine(regionConfigPath, "default.xml"), false, m_configSource); configFiles = Directory.GetFiles(regionConfigPath, "*.xml"); } - RegionInfo[] regionInfos = new RegionInfo[configFiles.Length]; - for (int i = 0; i < configFiles.Length; i++) + List regionInfos = new List(); + + int i = 0; + foreach (string file in iniFiles) + { + IConfigSource source = new IniConfigSource(file); + + foreach (IConfig config in source.Configs) + { + RegionInfo regionInfo = new RegionInfo("REGION CONFIG #" + (i + 1), file, false, m_configSource, config.Name); + regionInfos.Add(regionInfo); + i++; + } + } + + foreach (string file in configFiles) { - RegionInfo regionInfo = new RegionInfo("REGION CONFIG #" + (i + 1), configFiles[i], false, m_configSource); - regionInfos[i] = regionInfo; + RegionInfo regionInfo = new RegionInfo("REGION CONFIG #" + (i + 1), file, false, m_configSource); + regionInfos.Add(regionInfo); + i++; } - return regionInfos; + return regionInfos.ToArray(); } } } -- cgit v1.1