Beispiel #1
0
//        private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        public static Scene CreateScene(RegionInfo regionInfo, AgentCircuitManager circuitManager, CommunicationsManager m_commsManager,
            StorageManager storageManager, ModuleLoader m_moduleLoader, ConfigSettings m_configSettings, OpenSimConfigSource m_config, string m_version)
        {
            HGSceneCommunicationService sceneGridService = new HGSceneCommunicationService(m_commsManager);

            return
                new HGScene(
                    regionInfo, circuitManager, m_commsManager, sceneGridService, storageManager,
                    m_moduleLoader, false, m_configSettings.PhysicalPrim,
                    m_configSettings.See_into_region_from_neighbor, m_config.Source, m_version);
        }
 protected virtual void LoadConfigSettings(IConfigSource configSource)
 {
     m_configLoader = new ConfigurationLoader();
     m_config = m_configLoader.LoadConfigSettings(configSource, out m_configSettings, out m_networkServersInfo);
     ReadExtraConfigSettings();
 }
        public OpenSimConfigSource LoadConfigSettings(
                IConfigSource argvSource, out ConfigSettings configSettings)
        {
            IConfig startupConfig = argvSource.Configs["Startup"];
            string iniFilename = startupConfig.GetString("inifile", DEFAULT_INI_FILE);

            // If we are using the default ini file path and it doesn't exist, create an initial 
            // file that includes the base ini file
            if (iniFilename == DEFAULT_INI_FILE)
            {
                try
                {
                    if (!File.Exists(iniFilename))
                    {
                        using (StreamWriter writer = new StreamWriter(iniFilename))
                            writer.WriteLine("Include " + DEFAULT_INI_BASE_FILE);
                    }
                }
                catch (Exception ex)
                {
                    m_log.Error("Failed to create initial OpenSim.ini file. Please check file permissions " +
                        "and pass the inifile parameter if necessary. Error: " + ex.Message);
                    Environment.Exit(-1);
                }
            }

            // Create a configuration source and load the ini file
            m_config = new OpenSimConfigSource();
            m_config.Source = LoadConfig(iniFilename);

            // Create m_configSettings and set it up
            configSettings = new ConfigSettings();
            m_configSettings = configSettings;
            ReadConfigSettings();

            return m_config;
        }
        /// <summary>
        /// Loads the region configuration
        /// </summary>
        /// <param name="argvSource">Parameters passed into the process when started</param>
        /// <param name="configSettings"></param>
        /// <param name="networkInfo"></param>
        /// <returns>A configuration that gets passed to modules</returns>
        public OpenSimConfigSource LoadConfigSettings(
                IConfigSource argvSource, EnvConfigSource envConfigSource, out ConfigSettings configSettings,
                out NetworkServersInfo networkInfo)
        {
            m_configSettings = configSettings = new ConfigSettings();
            m_networkServersInfo = networkInfo = new NetworkServersInfo();

            bool iniFileExists = false;

            IConfig startupConfig = argvSource.Configs["Startup"];

            List<string> sources = new List<string>();

            string masterFileName = startupConfig.GetString("inimaster", "OpenSimDefaults.ini");

            if (masterFileName == "none")
                masterFileName = String.Empty;

            if (IsUri(masterFileName))
            {
                if (!sources.Contains(masterFileName))
                    sources.Add(masterFileName);
            }
            else
            {
                string masterFilePath = Path.GetFullPath(
                        Path.Combine(Util.configDir(), masterFileName));

                if (masterFileName != String.Empty)
                {
                    if (File.Exists(masterFilePath))
                    {
                        if (!sources.Contains(masterFilePath))
                            sources.Add(masterFilePath);
                    }
                    else
                    {
                        m_log.ErrorFormat("Master ini file {0} not found", Path.GetFullPath(masterFilePath));
                        Environment.Exit(1);
                    }
                }
            }

            string iniFileName = startupConfig.GetString("inifile", "OpenSim.ini");

            if (IsUri(iniFileName))
            {
                if (!sources.Contains(iniFileName))
                    sources.Add(iniFileName);
                Application.iniFilePath = iniFileName;
            }
            else
            {
                Application.iniFilePath = Path.GetFullPath(
                    Path.Combine(Util.configDir(), iniFileName));

                if (!File.Exists(Application.iniFilePath))
                {
                    iniFileName = "OpenSim.xml";
                    Application.iniFilePath = Path.GetFullPath(Path.Combine(Util.configDir(), iniFileName));
                }

                if (File.Exists(Application.iniFilePath))
                {
                    if (!sources.Contains(Application.iniFilePath))
                        sources.Add(Application.iniFilePath);
                }
            }

            m_config = new OpenSimConfigSource();
            m_config.Source = new IniConfigSource();
            m_config.Source.Merge(DefaultConfig());

            m_log.Info("[CONFIG]: Reading configuration settings");

            for (int i = 0 ; i < sources.Count ; i++)
            {
                if (ReadConfig(m_config, sources[i]))
                {
                    iniFileExists = true;
                    AddIncludes(m_config, sources);
                }
            }

            // Override distro settings with contents of inidirectory
            string iniDirName = startupConfig.GetString("inidirectory", "config");
            string iniDirPath = Path.Combine(Util.configDir(), iniDirName);

            if (Directory.Exists(iniDirPath))
            {
                m_log.InfoFormat("[CONFIG]: Searching folder {0} for config ini files", iniDirPath);
                List<string> overrideSources = new List<string>();

                string[] fileEntries = Directory.GetFiles(iniDirName);
                foreach (string filePath in fileEntries)
                {
                    if (Path.GetExtension(filePath).ToLower() == ".ini")
                    {
                        if (!sources.Contains(Path.GetFullPath(filePath)))
                        {
                            overrideSources.Add(Path.GetFullPath(filePath));
                            // put it in sources too, to avoid circularity
                            sources.Add(Path.GetFullPath(filePath));
                        }
                    }
                }


                if (overrideSources.Count > 0)
                {
                    OpenSimConfigSource overrideConfig = new OpenSimConfigSource();
                    overrideConfig.Source = new IniConfigSource();

                    for (int i = 0 ; i < overrideSources.Count ; i++)
                    {
                        if (ReadConfig(overrideConfig, overrideSources[i]))
                        {
                            iniFileExists = true;
                            AddIncludes(overrideConfig, overrideSources);
                        } 
                    }
                    m_config.Source.Merge(overrideConfig.Source);
                }
            }

            if (sources.Count == 0)
            {
                m_log.FatalFormat("[CONFIG]: Could not load any configuration");
                Environment.Exit(1);
            } 
            else if (!iniFileExists)
            {
                m_log.FatalFormat("[CONFIG]: Could not load any configuration");
                m_log.FatalFormat("[CONFIG]: Configuration exists, but there was an error loading it!");
                Environment.Exit(1);
            }

            // Merge OpSys env vars
            m_log.Info("[CONFIG]: Loading environment variables for Config");
            Util.MergeEnvironmentToConfig(m_config.Source);

            // Make sure command line options take precedence
            m_config.Source.Merge(argvSource);

            m_config.Source.ReplaceKeyValues();

            ReadConfigSettings();

            return m_config;
        }
        /// <summary>
        /// Provide same ini loader functionality for standard ini and master ini - file system or XML over http
        /// </summary>
        /// <param name="iniPath">Full path to the ini</param>
        /// <returns></returns>
        private bool ReadConfig(OpenSimConfigSource configSource, string iniPath)
        {
            bool success = false;

            if (!IsUri(iniPath))
            {
                m_log.InfoFormat("[CONFIG]: Reading configuration file {0}", Path.GetFullPath(iniPath));

                configSource.Source.Merge(new IniConfigSource(iniPath));
                success = true;
            }
            else
            {
                m_log.InfoFormat("[CONFIG]: {0} is a http:// URI, fetching ...", iniPath);

                // The ini file path is a http URI
                // Try to read it
                try
                {
                    XmlReader r = XmlReader.Create(iniPath);
                    XmlConfigSource cs = new XmlConfigSource(r);
                    configSource.Source.Merge(cs);

                    success = true;
                }
                catch (Exception e)
                {
                    m_log.FatalFormat("[CONFIG]: Exception reading config from URI {0}\n" + e.ToString(), iniPath);
                    Environment.Exit(1);
                }
            }
            return success;
        }
 /// <summary>
 /// Adds the included files as ini configuration files
 /// </summary>
 /// <param name="sources">List of URL strings or filename strings</param>
 private void AddIncludes(OpenSimConfigSource configSource, List<string> sources)
 {
     //loop over config sources
     foreach (IConfig config in configSource.Source.Configs)
     {
         // Look for Include-* in the key name
         string[] keys = config.GetKeys();
         foreach (string k in keys)
         {
             if (k.StartsWith("Include-"))
             {
                 // read the config file to be included.
                 string file = config.GetString(k);
                 if (IsUri(file))
                 {
                     if (!sources.Contains(file))
                         sources.Add(file);
                 }
                 else
                 {
                     string basepath = Path.GetFullPath(Util.configDir());
                     // Resolve relative paths with wildcards
                     string chunkWithoutWildcards = file;
                     string chunkWithWildcards = string.Empty;
                     int wildcardIndex = file.IndexOfAny(new char[] { '*', '?' });
                     if (wildcardIndex != -1)
                     {
                         chunkWithoutWildcards = file.Substring(0, wildcardIndex);
                         chunkWithWildcards = file.Substring(wildcardIndex);
                     }
                     string path = Path.Combine(basepath, chunkWithoutWildcards);
                     path = Path.GetFullPath(path) + chunkWithWildcards;
                     string[] paths = Util.Glob(path);
                     
                     // If the include path contains no wildcards, then warn the user that it wasn't found.
                     if (wildcardIndex == -1 && paths.Length == 0)
                     {
                         m_log.WarnFormat("[CONFIG]: Could not find include file {0}", path);
                     }
                     else
                     {                            
                         foreach (string p in paths)
                         {
                             if (!sources.Contains(p))
                                 sources.Add(p);
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #7
0
        /// <summary>
        /// Loads the region configuration
        /// </summary>
        /// <param name="argvSource">Parameters passed into the process when started</param>
        /// <param name="configSettings"></param>
        /// <param name="networkInfo"></param>
        /// <returns>A configuration that gets passed to modules</returns>
        public OpenSimConfigSource LoadConfigSettings(
                IConfigSource argvSource, EnvConfigSource envConfigSource, out ConfigSettings configSettings,
                out NetworkServersInfo networkInfo)
        {
            m_configSettings = configSettings = new ConfigSettings();
            m_networkServersInfo = networkInfo = new NetworkServersInfo();

            bool iniFileExists = false;

            IConfig startupConfig = argvSource.Configs["Startup"];

            List<string> sources = new List<string>();

            string masterFileName =
                    startupConfig.GetString("inimaster", "OpenSimDefaults.ini");

            if (masterFileName == "none")
                masterFileName = String.Empty;

            if (IsUri(masterFileName))
            {
                if (!sources.Contains(masterFileName))
                    sources.Add(masterFileName);
            }
            else
            {
                string masterFilePath = Path.GetFullPath(
                        Path.Combine(Util.configDir(), masterFileName));

                if (masterFileName != String.Empty)
                {
                    if (File.Exists(masterFilePath))
                    {
                        if (!sources.Contains(masterFilePath))
                            sources.Add(masterFilePath);
                    }
                    else
                    {
                        m_log.ErrorFormat("Master ini file {0} not found", masterFilePath);
                        Environment.Exit(1);
                    }
                }
            }


            string iniFileName =
                    startupConfig.GetString("inifile", "OpenSim.ini");

            if (IsUri(iniFileName))
            {
                if (!sources.Contains(iniFileName))
                    sources.Add(iniFileName);
                Application.iniFilePath = iniFileName;
            }
            else
            {
                Application.iniFilePath = Path.GetFullPath(
                        Path.Combine(Util.configDir(), iniFileName));

                if (!File.Exists(Application.iniFilePath))
                {
                    iniFileName = "OpenSim.xml";
                    Application.iniFilePath = Path.GetFullPath(
                            Path.Combine(Util.configDir(), iniFileName));
                }

                if (File.Exists(Application.iniFilePath))
                {
                    if (!sources.Contains(Application.iniFilePath))
                        sources.Add(Application.iniFilePath);
                }
            }

            string iniDirName =
                    startupConfig.GetString("inidirectory", "config");
            string iniDirPath =
                    Path.Combine(Util.configDir(), iniDirName);

            if (Directory.Exists(iniDirPath))
            {
                m_log.InfoFormat("Searching folder {0} for config ini files",
                        iniDirPath);

                string[] fileEntries = Directory.GetFiles(iniDirName);
                foreach (string filePath in fileEntries)
                {
                    if (Path.GetExtension(filePath).ToLower() == ".ini")
                    {
                        if (!sources.Contains(Path.GetFullPath(filePath)))
                            sources.Add(Path.GetFullPath(filePath));
                    }
                }
            }

            m_config = new OpenSimConfigSource();
            m_config.Source = new IniConfigSource();
            m_config.Source.Merge(DefaultConfig());

            m_log.Info("[CONFIG]: Reading configuration settings");

            if (sources.Count == 0)
            {
                m_log.FatalFormat("[CONFIG]: Could not load any configuration");
                m_log.FatalFormat("[CONFIG]: Did you copy the OpenSimDefaults.ini.example file to OpenSimDefaults.ini?");
                Environment.Exit(1);
            }

            for (int i = 0 ; i < sources.Count ; i++)
            {
                if (ReadConfig(sources[i]))
                {
                    iniFileExists = true;
                    AddIncludes(sources);
                }
            }

            if (!iniFileExists)
            {
                m_log.FatalFormat("[CONFIG]: Could not load any configuration");
                m_log.FatalFormat("[CONFIG]: Configuration exists, but there was an error loading it!");
                Environment.Exit(1);
            }

            // Make sure command line options take precedence
            m_config.Source.Merge(argvSource);


            IConfig enVars = m_config.Source.Configs["Environment"];

            if( enVars != null )
            {
                string[] env_keys = enVars.GetKeys();

                foreach ( string key in env_keys )
                {
                    envConfigSource.AddEnv(key, string.Empty);
                }

                envConfigSource.LoadEnv();
                m_config.Source.Merge(envConfigSource);
                m_config.Source.ExpandKeyValues();
            }


            ReadConfigSettings();

            return m_config;
        }
Beispiel #8
0
        public OpenSimConfigSource LoadConfigSettings(IConfigSource configSource, out ConfigSettings configSettings,
                                                      out NetworkServersInfo networkInfo)
        {
            m_configSettings = configSettings = new ConfigSettings();
            m_networkServersInfo = networkInfo = new NetworkServersInfo();
            bool iniFileExists = false;

            IConfig startupConfig = configSource.Configs["Startup"];

            //old style or new style settings?
            string iniFileName = startupConfig.GetString("inifile", "Halcyon.ini");
            ApplicationBase.iniFilePath = Path.Combine(Util.configDir(), iniFileName);

            string masterFileName = startupConfig.GetString("inimaster", String.Empty);
            string masterfilePath = Path.Combine(Util.configDir(), masterFileName);

            string iniDirName = startupConfig.GetString("inidirectory", "config");
            //string iniDirPath = Path.Combine(Util.configDir(), iniDirName);

            m_config = new OpenSimConfigSource();
            m_config.Source = new IniConfigSource();
            m_config.Source.Merge(DefaultConfig());

            m_log.Info("[CONFIG] Reading configuration settings");

            Uri configUri;
            
            String xmlPath = Path.Combine(Util.configDir(), "Halcyon.xml");

            //check for master .INI file (name passed in command line, no default), or XML over http
            if (!String.IsNullOrEmpty(masterFileName)) // If a master file name is given ...
            {
                m_log.InfoFormat("[CONFIG] Reading config master file {0}", masterfilePath);

                bool isMasterUri = Uri.TryCreate(masterFileName, UriKind.Absolute, out configUri) &&
                                   configUri.Scheme == Uri.UriSchemeHttp;

                if (!ReadConfig(masterFileName, masterfilePath, m_config, isMasterUri))
                {
                    m_log.FatalFormat("[CONFIG] Could not open master config file {0}", masterfilePath);
                }
            }

            if (Directory.Exists(iniDirName))
            {
                m_log.InfoFormat("Searching folder: {0} , for config ini files", iniDirName);
                string[] fileEntries = Directory.GetFiles(iniDirName);
                foreach (string filePath in fileEntries)
                {
                    if (Path.GetExtension(filePath).ToLower() == ".ini")
                    {
                        // m_log.InfoFormat("reading ini file < {0} > from config dir", filePath);
                        ReadConfig(Path.GetFileName(filePath), filePath, m_config, false);
                    }
                }
            }

            // Check for .INI file (either default or name passed on command
            // line) or XML config source over http
            bool isIniUri = Uri.TryCreate(iniFileName, UriKind.Absolute, out configUri) &&
                            configUri.Scheme == Uri.UriSchemeHttp;
            iniFileExists = ReadConfig(iniFileName, ApplicationBase.iniFilePath, m_config, isIniUri);

            if (!iniFileExists)
            {
                // check for a xml config file                                
                if (File.Exists(xmlPath))
                {
                    ApplicationBase.iniFilePath = xmlPath;

                    m_log.InfoFormat("Reading XML configuration from {0}", Path.GetFullPath(xmlPath));
                    iniFileExists = true;

                    m_config.Source = new XmlConfigSource();
                    m_config.Source.Merge(new XmlConfigSource(ApplicationBase.iniFilePath));
                }
            }

            m_config.Source.Merge(configSource);

            if (!iniFileExists)
            {
                m_log.FatalFormat("[CONFIG] Could not load any configuration");
                if (!isIniUri)
                    m_log.FatalFormat("[CONFIG] Tried to load {0}, ", Path.GetFullPath(ApplicationBase.iniFilePath));
                else
                    m_log.FatalFormat("[CONFIG] Tried to load from URI {0}, ", iniFileName);
                m_log.FatalFormat("[CONFIG] and XML source {0}", Path.GetFullPath(xmlPath));

                string sampleName = Path.GetFileNameWithoutExtension(ApplicationBase.iniFilePath) + ".sample.ini";

                m_log.FatalFormat("[CONFIG] Did you copy the {0} file to {1}?", sampleName, ApplicationBase.iniFilePath);
                Environment.Exit(1);
            }

            ReadConfigSettings();

            return m_config;
        }
Beispiel #9
0
        /// <summary>
        /// Provide same ini loader functionality for standard ini and master ini - file system or XML over http
        /// </summary>
        /// <param name="iniName">The name of the ini to load</param>
        /// <param name="iniPath">Full path to the ini</param>
        /// <param name="m_config">The current configuration source</param>
        /// <param name="isUri">Boolean representing whether the ini source is a URI path over http or a file on the system</param>
        /// <returns></returns>
        private bool ReadConfig(string iniName, string iniPath, OpenSimConfigSource m_config, bool isUri)
        {
            bool success = false;

            if (!isUri && File.Exists(iniPath))
            {
                m_log.InfoFormat("[CONFIG] Reading configuration file {0}", Path.GetFullPath(iniPath));

                // From reading Nini's code, it seems that later merged keys replace earlier ones.                
                m_config.Source.Merge(new IniConfigSource(iniPath));
                success = true;
            }
            else
            {
                if (isUri)
                {
                    m_log.InfoFormat("[CONFIG] {0} is a http:// URI, fetching ...", iniName);

                    // The ini file path is a http URI
                    // Try to read it
                    try
                    {
                        XmlReader r = XmlReader.Create(iniName);
                        XmlConfigSource cs = new XmlConfigSource(r);
                        m_config.Source.Merge(cs);

                        success = true;
                        m_log.InfoFormat("[CONFIG] Loaded config from {0}", iniName);
                    }
                    catch (Exception e)
                    {
                        m_log.FatalFormat("[CONFIG] Exception reading config from URI {0}\n" + e.ToString(), iniName);
                        Environment.Exit(1);
                    }
                }
            }
            return success;
        }