Exemplo n.º 1
0
        /// <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>
        /// <param name="i"></param>
        /// <param name="source"></param>
        /// <returns></returns>
        private bool ReadConfig(string iniPath, int i, IConfigSource source)
        {
            bool success = false;

            if (!IsUri(iniPath))
            {
                if (showIniLoading)
                {
                    Console.WriteLine(string.Format("[CONFIG]: Reading configuration file {0}",
                                                    Util.BasePathCombine(iniPath)));
                }

                source.Merge(new IniConfigSource(iniPath, IniFileType.AuroraStyle));
                if (inidbg)
                {
                    WriteConfigFile(i, source);
                }
                success = true;
            }
            else
            {
                // The ini file path is a http URI
                // Try to read it
                try
                {
                    string file     = Utilities.Utilities.ReadExternalWebsite(iniPath);
                    string filename = Path.GetTempFileName();
                    File.WriteAllText(filename, file);

                    if (showIniLoading)
                    {
                        Console.WriteLine(string.Format("[CONFIG]: Reading configuration file {0}",
                                                        Util.BasePathCombine(iniPath)));
                    }

                    source.Merge(new IniConfigSource(filename, IniFileType.AuroraStyle));
                    if (inidbg)
                    {
                        WriteConfigFile(i, source);
                    }
                    File.Delete(filename);
                    success = true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(string.Format("[CONFIG]: Exception reading config from URI {0}\n" + e, iniPath));
                    Environment.Exit(1);
                }
            }
            return(success);
        }
Exemplo n.º 2
0
        public static IConfigSource LoadConfig(IConfigSource source)
        {
            string iniFileName = source.Configs["Startup"].GetString("inifile", CONFIG_FILE);
            string iniFilePath = Path.Combine(Util.configDir(), iniFileName);

            source.Merge(DefaultConfig());

            if (!File.Exists(iniFilePath))
            {
                m_log.FatalFormat("[CONFIG]: File {0} not found, could not load any configuration.", iniFilePath);
                m_log.FatalFormat("[CONFIG]: Did you copy the AssetInventoryServer.ini.example file to AssetInventoryServer.ini?");
                Environment.Exit(1);
            }

            source.Merge(new IniConfigSource(iniFilePath));
            return(source);
        }
Exemplo n.º 3
0
        public static IConfigSource LoadConfig(IConfigSource source)
        {
            string iniFileName = source.Configs["Startup"].GetString("inifile", CONFIG_FILE);
            string iniFilePath = Path.Combine(Util.configDir(), iniFileName);

            source.Merge(DefaultConfig());

            if (!File.Exists(iniFilePath))
            {
                m_log.FatalFormat("[CONFIG]: File {0} not found, could not load any configuration.", iniFilePath);
                m_log.FatalFormat("[CONFIG]: Did you copy the AssetInventoryServer.ini.example file to AssetInventoryServer.ini?");
                Environment.Exit(1);
            }

            source.Merge(new IniConfigSource(iniFilePath));
            return source;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Configure the plugin. This is the equivilent of our parameterized constructor
        /// for regular Robust connectors. But, we just get our configuration and return
        /// the port we want to run our connector on back to the application. Then the
        /// application will send our server to the Initialize method
        /// </summary>
        /// <param name='config'>
        /// IConfigSource - Main Config.
        /// </param>
        public uint Configure(IConfigSource config)
        {
            m_log.Info("[SLIPSTREAM]: Running Configuration");
            Config = config;

            IConfig startconfig     = Config.Configs["Startup"];
            string  configdirectory = startconfig.GetString("ConfigDirectory", ".");

            ConfigFile = Path.Combine(configdirectory, "SlipStream.ini");
            m_log.InfoFormat("[SLIPSTREAM]: Configuration {0}", ConfigFile);

            // Look in our main config first
            IConfig serverConfig = Config.Configs[ConfigName];

            if (serverConfig == null)
            {
                // Look for individual config file
                serverConfig = GetConfig();
            }
            if (serverConfig == null)
            {
                throw new Exception(String.Format("[SlipStream]: Cannot file configuration for {0}, not loaded!", ConfigName));
            }

            uint serverPort = (uint)serverConfig.GetInt("ServerPort", 0);

            ServiceModuleName = serverConfig.GetString("LocalServiceModule",
                                                       String.Empty);

            // Just something to test the config
            m_log.InfoFormat("[SLIPSTREAM]: CodeWord {0}", serverConfig.GetString("CodeWord", "Blaah!"));

            if (ServiceModuleName == String.Empty)
            {
                throw new Exception("No LocalServiceModule in config file");
            }

            // We want to ship these plugins disabled to allow the user to make
            // adjustments to the ini prior to running. The bootstrap ini will be downloaded
            // when the plugin is enabled the first time. It should have an Enable and it
            // should be set to false. The user can disable the module in the console, make
            // edits (including setting Enable to true) then re-enable the plugin. It will
            // load and run w/o restarting their Robust.
            if (serverConfig.GetBoolean("Enabled", false) == false)
            {
                m_log.Info("[SLIPSTREAM]: Module Disabled");
                Enabled = false;
                return(0);
            }
            else
            {
                Enabled = true;
            }

            Config.Merge(serverConfig.ConfigSource);

            return((uint)serverPort);
        }
Exemplo n.º 5
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 IConfigSource LoadConfigSettings()
        {
            bool iniFileExists = false;

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

            string iniFileName = "OpenSim.ini";
            string iniFilePath = Path.Combine(".", iniFileName);

            if (IsUri(iniFileName))
            {
                if (!sources.Contains(iniFileName))
                {
                    sources.Add(iniFileName);
                }
            }
            else
            {
                if (File.Exists(iniFilePath))
                {
                    if (!sources.Contains(iniFilePath))
                    {
                        sources.Add(iniFilePath);
                    }
                }
            }

            m_config = new IniConfigSource();
            m_config.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 OpenSim.ini.example file to OpenSim.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);
            }

            return(m_config);
        }
        private void CreateIni(string filepath, IniConfigSource source)
        {
            string path = Path.GetDirectoryName(filepath);

            if (path != string.Empty)
            {
                Directory.CreateDirectory(path);
            }
            source.Save(filepath);
            m_config.Merge(source);
        }
        /// <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(string iniPath, int i, IConfigSource source)
        {
            bool success = false;

            if (!IsUri(iniPath))
            {
                if (showIniLoading)
                {
                    Console.WriteLine(string.Format("[CONFIG]: Reading configuration file {0}", Util.BasePathCombine(iniPath)));
                }

                source.Merge(new IniConfigSource(iniPath, IniFileType.AuroraStyle));
                if (inidbg)
                {
                    WriteConfigFile(i, source);
                }
                success = true;
            }
            else
            {
                Console.WriteLine(string.Format("[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);
                    source.Merge(cs);

                    success = true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(string.Format("[CONFIG]: Exception reading config from URI {0}\n" + e, iniPath));
                    Environment.Exit(1);
                }
            }
            return(success);
        }
Exemplo n.º 8
0
        /// <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(string iniPath, int i)
        {
            bool success = false;

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

                m_config.Merge(new IniConfigSource(iniPath, Nini.Ini.IniFileType.AuroraStyle));
                if (inidbg)
                {
                    WriteConfigFile(i, m_config);
                }
                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);
                    m_config.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);
        }
Exemplo n.º 9
0
        /// <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(string iniPath)
        {
            bool success = false;

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

                m_config.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);
                    m_config.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);
        }
Exemplo n.º 10
0
        static Config()
        {
            AppConfigRoot = new Nini.Config.DotNetConfigSource(DotNetConfigSource.GetFullConfigPath());
            AppSettings   = AppConfigRoot.Configs["appSettings"];

            bool          hasExtraConfig  = false;
            IConfigSource extraConfigRoot = null;

            if (File.Exists(ExtraConfigFile))
            {
                hasExtraConfig  = true;
                ExtraConfigRoot = new Nini.Config.XmlConfigSource(ExtraConfigFile);
                extraConfigRoot = ExtraConfigRoot;
            }
            if (File.Exists(PrivateExtraConfigFile))
            {
                hasExtraConfig         = true;
                PrivateExtraConfigRoot = new Nini.Config.XmlConfigSource(PrivateExtraConfigFile);
                if (extraConfigRoot != null)
                {
                    extraConfigRoot.Merge(PrivateExtraConfigRoot);
                }
                else
                {
                    extraConfigRoot = PrivateExtraConfigRoot;
                }
            }

            if (hasExtraConfig)
            {
                ExtraConfig        = extraConfigRoot.Configs["Settings"];
                RconServerAddress  = ExtraConfig.GetString("RconServerAddress");
                RconServerPort     = ExtraConfig.GetInt("RconServerPort");
                RconServerPassword = ExtraConfig.GetString("RconServerPassword");
            }
            else
            {
                throw new ApplicationException("Can't find config file: " + ExtraConfigFile);
            }
        }
        /// <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>
        /// <param name="i"></param>
        /// <param name="source"></param>
        /// <returns></returns>
        private bool ReadConfig(string iniPath, int i, IConfigSource source)
        {
            bool success = false;

            if (!IsUri(iniPath))
            {
                if (showIniLoading)
                    Console.WriteLine(string.Format("[CONFIG]: Reading configuration file {0}",
                                                    Util.BasePathCombine(iniPath)));

                source.Merge(new IniConfigSource(iniPath, IniFileType.AuroraStyle));
                if (inidbg)
                {
                    WriteConfigFile(i, source);
                }
                success = true;
            }
            else
            {
                // The ini file path is a http URI
                // Try to read it
                try
                {
                    string file = Utilities.Utilities.ReadExternalWebsite(iniPath);
                    string filename = Path.GetTempFileName();
                    File.WriteAllText(filename, file);

                    if (showIniLoading)
                        Console.WriteLine(string.Format("[CONFIG]: Reading configuration file {0}",
                                                        Util.BasePathCombine(iniPath)));

                    source.Merge(new IniConfigSource(filename, IniFileType.AuroraStyle));
                    if (inidbg)
                    {
                        WriteConfigFile(i, source);
                    }
                    File.Delete(filename);
                    success = true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(string.Format("[CONFIG]: Exception reading config from URI {0}\n" + e, iniPath));
                    Environment.Exit(1);
                }
            }
            return success;
        }
Exemplo n.º 12
0
        // Handle all the automagical stuff
        //
        public ServicesServerBase(string prompt, string[] args)
        {
            // Save raw arguments
            //
            m_Arguments = args;

            // Read command line
            //
            ArgvConfigSource argvConfig = new ArgvConfigSource(args);

            argvConfig.AddSwitch("Startup", "console", "c");
            argvConfig.AddSwitch("Startup", "logfile", "l");
            argvConfig.AddSwitch("Startup", "inifile", "i");
            argvConfig.AddSwitch("Startup", "prompt", "p");
            argvConfig.AddSwitch("Startup", "logconfig", "g");

            // Automagically create the ini file name
            //
            string fileName  = Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location);
            string iniFile   = fileName + ".ini";
            string logConfig = null;

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

            if (startupConfig != null)
            {
                // Check if a file name was given on the command line
                //
                iniFile = startupConfig.GetString("inifile", iniFile);
                //
                // Check if a prompt was given on the command line
                prompt = startupConfig.GetString("prompt", prompt);
                //
                // Check for a Log4Net config file on the command line
                logConfig = startupConfig.GetString("logconfig", logConfig);
            }

            // Find out of the file name is a URI and remote load it
            // if it's possible. Load it as a local file otherwise.
            //
            Uri configUri;

            try
            {
                if (Uri.TryCreate(iniFile, UriKind.Absolute, out configUri) &&
                    configUri.Scheme == Uri.UriSchemeHttp)
                {
                    XmlReader r = XmlReader.Create(iniFile);
                    m_Config = new XmlConfigSource(r);
                }
                else
                {
                    m_Config = new IniConfigSource(iniFile);
                }
            }
            catch (Exception)
            {
                System.Console.WriteLine("Error reading from config source {0}",
                                         iniFile);
                Thread.CurrentThread.Abort();
            }

            // Merge the configuration from the command line into the
            // loaded file
            //
            m_Config.Merge(argvConfig);

            // Refresh the startupConfig post merge
            //
            if (m_Config.Configs["Startup"] != null)
            {
                startupConfig = m_Config.Configs["Startup"];
            }

            prompt = startupConfig.GetString("Prompt", prompt);

            // Allow derived classes to load config before the console is
            // opened.
            //
            ReadConfig();

            // Create main console
            //
            string consoleType = "local";

            if (startupConfig != null)
            {
                consoleType = startupConfig.GetString("console", consoleType);
            }

            if (consoleType == "basic")
            {
                MainConsole.Instance = new CommandConsole(prompt);
            }
            else if (consoleType == "rest")
            {
                MainConsole.Instance = new RemoteConsole(prompt);
                ((RemoteConsole)MainConsole.Instance).ReadConfig(Config);
            }
            else
            {
                MainConsole.Instance = new LocalConsole(prompt);
            }

            // Configure the appenders for log4net
            //
            OpenSimAppender consoleAppender = null;
            FileAppender    fileAppender    = null;

            if (logConfig != null)
            {
                FileInfo cfg = new FileInfo(logConfig);
                XmlConfigurator.Configure(cfg);
            }
            else
            {
                XmlConfigurator.Configure();
            }

            ILoggerRepository repository = LogManager.GetRepository();

            IAppender[] appenders = repository.GetAppenders();

            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "Console")
                {
                    consoleAppender = (OpenSimAppender)appender;
                }
                if (appender.Name == "LogFileAppender")
                {
                    fileAppender = (FileAppender)appender;
                }
            }

            if (consoleAppender == null)
            {
                System.Console.WriteLine("No console appender found. Server can't start");
                Thread.CurrentThread.Abort();
            }
            else
            {
                consoleAppender.Console = MainConsole.Instance;

                if (null == consoleAppender.Threshold)
                {
                    consoleAppender.Threshold = Level.All;
                }
            }

            // Set log file
            //
            if (fileAppender != null)
            {
                if (startupConfig != null)
                {
                    string cfgFileName = startupConfig.GetString("logfile", null);
                    if (cfgFileName != null)
                    {
                        fileAppender.File = cfgFileName;
                        fileAppender.ActivateOptions();
                    }
                }
            }

            if (startupConfig.GetString("PIDFile", String.Empty) != String.Empty)
            {
                CreatePIDFile(startupConfig.GetString("PIDFile"));
            }

            // Register the quit command
            //
            MainConsole.Instance.Commands.AddCommand("base", false, "quit",
                                                     "quit",
                                                     "Quit the application", HandleQuit);

            MainConsole.Instance.Commands.AddCommand("base", false, "shutdown",
                                                     "shutdown",
                                                     "Quit the application", HandleQuit);

            // Register a command to read other commands from a file
            MainConsole.Instance.Commands.AddCommand("base", false, "command-script",
                                                     "command-script <script>",
                                                     "Run a command script from file", HandleScript);


            // Allow derived classes to perform initialization that
            // needs to be done after the console has opened
            //
            Initialise();
        }
Exemplo n.º 13
0
        /// <summary>
        /// Loads the region configuration
        /// </summary>
        /// <param name="argvSource">Parameters passed into the process when started</param>
        /// <returns>A configuration that gets passed to modules</returns>
        public IConfigSource LoadConfigSettings(IConfigSource argvSource)
        {
            bool iniFileExists = false;

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

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

            inidbg =
                startupConfig.GetBoolean("inidbg", false);

            string masterFileName =
                startupConfig.GetString("inimaster", String.Empty);

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

            //Be mindful of these when modifying...
            //1) When file A includes file B, if the same directive is found in both, that the value in file B wins.
            //2) That inifile may be used with or without inimaster being used.
            //3) That any values for directives pulled in via inifile (Config Set 2) override directives of the same name found in the directive set (Config Set 1) created by reading in bin/Opensim.ini and its subsequently included files or that created by reading in whatever file inimaster points to and its subsequently included files.
            
            if (IsUri(masterFileName))
            {
                if (!sources.Contains(masterFileName))
                    sources.Add(masterFileName);
            }
            else
            {
                string masterFilePath = Path.GetFullPath(
                        Path.Combine(Util.configDir(), masterFileName));

                if (masterFileName != String.Empty &&
                        File.Exists(masterFilePath) &&
                        (!sources.Contains(masterFilePath)))
                    sources.Add(masterFilePath);
                if (iniFileName == "") //Then it doesn't exist and we need to set this
                    Application.iniFilePath = masterFilePath;
            }

            if (iniFileName != "")
            {
                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))
                    {
                        if (!sources.Contains(Application.iniFilePath))
                            sources.Add(Application.iniFilePath);
                    }
                }
            }

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

            if (Directory.Exists(iniDirPath) && iniDirName != "")
            {
                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 IniConfigSource();
            
            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 OpenSim.ini.example file to OpenSim.ini?");
                throw new NotSupportedException();
            }

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

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

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

            return m_config;
        }
Exemplo n.º 14
0
        /// <summary>
        /// Loads the region configuration
        /// </summary>
        /// <param name="argvSource">Parameters passed into the process when started</param>
        /// <returns>A configuration that gets passed to modules</returns>
        public IConfigSource LoadConfigSettings(IConfigSource argvSource)
        {
            bool iniFileExists = false;

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

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

            string masterFileName =
                    startupConfig.GetString("inimaster", 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 &&
                        File.Exists(masterFilePath) &&
                        (!sources.Contains(masterFilePath)))
                    sources.Add(masterFilePath);
            }


            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))
                {
                    if (!sources.Contains(Application.iniFilePath))
                        sources.Add(Application.iniFilePath);
                }
            }

            string iniDirName =
                    startupConfig.GetString("inidirectory", "Configuration/Modules");
            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 IniConfigSource();
            
            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 OpenSim.ini.example file to OpenSim.ini?");
                throw new NotSupportedException();
            }

            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!");
                throw new NotSupportedException();
            }

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

            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 IConfigSource LoadConfigSettings(IConfig startupConfig)
        {
            bool iniFileExists = false;

            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", Path.Combine(".", "OpenSim.ini"));

            if (IsUri(iniFileName))
            {
                if (!sources.Contains(iniFileName))
                    sources.Add(iniFileName);
            }
            else
            {
                if (File.Exists(iniFileName))
                {
                    if (!sources.Contains(iniFileName))
                        sources.Add(iniFileName);
                }
            }

            m_config = new IniConfigSource();
            m_config.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 OpenSim.ini.example file to OpenSim.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);
            }

            return m_config;
        }
Exemplo n.º 16
0
        /// <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(string iniPath, int i, IConfigSource source)
        {
            bool success = false;

            if (!IsUri(iniPath))
            {
                if (showIniLoading)
                    Console.WriteLine(string.Format("[CONFIG]: Reading configuration file {0}", Util.BasePathCombine(iniPath)));

                source.Merge(new IniConfigSource(iniPath, IniFileType.AuroraStyle));
                if (inidbg)
                {
                    WriteConfigFile(i, source);
                }
                success = true;
            }
            else
            {
                Console.WriteLine(string.Format("[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);
                    source.Merge(cs);

                    success = true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(string.Format("[CONFIG]: Exception reading config from URI {0}\n" + e, iniPath));
                    Environment.Exit(1);
                }
            }
            return success;
        }
Exemplo n.º 17
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 IConfigSource LoadConfigSettings()
        {
            bool iniFileExists = false;

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

            string iniFileName = "OpenSim.ini";
            string iniFilePath = Path.Combine(".", iniFileName);

            if (IsUri(iniFileName))
            {
                if (!sources.Contains(iniFileName))
                    sources.Add(iniFileName);
            }
            else
            {
                if (File.Exists(iniFilePath))
                {
                    if (!sources.Contains(iniFilePath))
                        sources.Add(iniFilePath);
                }
            }

            m_config = new IniConfigSource();
            m_config.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 OpenSim.ini.example file to OpenSim.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);
            }

            return m_config;
        }
Exemplo n.º 18
0
        public bool Start(Simian simian)
        {
            m_scheduler = simian.GetAppModule <IScheduler>();
            if (m_scheduler == null)
            {
                m_log.Error("LLSceneFactory requires an IScheduler");
                return(false);
            }

            m_scenes = new Dictionary <UUID, IScene>();

            m_renderer   = simian.GetAppModule <ISceneRenderer>();
            m_gridClient = simian.GetAppModule <IGridClient>();

            string[] sceneFiles = null;

            try { sceneFiles = Directory.GetFiles(SOURCE_PATH, "*.ini", SearchOption.AllDirectories); }
            catch (DirectoryNotFoundException)
            {
                m_log.Warn(Path.GetFullPath(SOURCE_PATH) + " not found, cannot load scene definitions");
                return(false);
            }

            for (int i = 0; i < sceneFiles.Length; i++)
            {
                // Create the config source for this region by merging the app config and the region config
                IConfigSource   configSource       = simian.GetConfigCopy();
                IniConfigSource regionConfigSource = new IniConfigSource(sceneFiles[i]);
                configSource.Merge(regionConfigSource);

                IConfig config = configSource.Configs["LindenRegion"];

                if (config != null)
                {
                    UUID id;
                    UUID.TryParse(config.GetString("ID"), out id);

                    string name = config.GetString("Name");

                    uint     locationX = 0, locationY = 0;
                    string[] locationParts = config.GetString("Location").Trim().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    if (locationParts.Length != 2 || !UInt32.TryParse(locationParts[0], out locationX) || !UInt32.TryParse(locationParts[1], out locationY))
                    {
                        m_log.Warn("Missing or invalid Location for " + name + " region");
                    }
                    Vector3d regionPosition = new Vector3d(locationX * (uint)REGION_SIZE, locationY * (uint)REGION_SIZE, 0.0d);

                    Scene scene = new Scene(id, name, regionPosition, new Vector3d(256.0, 256.0, 4096.0), simian, configSource);
                    m_log.Info("Starting scene " + scene.Name + " (" + scene.ID + ")");
                    scene.Start();

                    m_scenes[scene.ID] = scene;

                    // Create a map tile for this scene
                    m_scheduler.FireAndForget(o => CreateMapTile((IScene)o), scene);
                }
                else
                {
                    m_log.Warn("No [LindenRegion] config section found in " + sceneFiles[i] + ", skipping");
                }
            }

            // Create the array
            m_scenesArray = new IScene[m_scenes.Count];
            int j = 0;

            foreach (IScene scene in m_scenes.Values)
            {
                m_scenesArray[j++] = scene;
            }

            // Fire the OnSceneStart callback for each scene we started
            SceneStartCallback callback = OnSceneStart;

            if (callback != null)
            {
                for (int i = 0; i < m_scenesArray.Length; i++)
                {
                    callback(m_scenesArray[i]);
                }
            }

            return(true);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Loads the region configuration
        /// </summary>
        /// <param name="argvSource">Parameters passed into the process when started</param>
        /// <returns>A configuration that gets passed to modules</returns>
        public IConfigSource LoadConfigSettings(IConfigSource argvSource)
        {
            iniFilePath = "";
            bool iniFileExists = false;

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

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

            bool oldoptions =
                startupConfig.GetBoolean ("oldoptions", false);

            inidbg =
                startupConfig.GetBoolean ("inidbg", inidbg);

            showIniLoading =
                startupConfig.GetBoolean ("inishowfileloading", showIniLoading);
            string basePath = Util.configDir();
            if (oldoptions)
            {
                string masterFileName =
                    startupConfig.GetString ("inimaster", String.Empty);

                string iniGridName =
                    startupConfig.GetString ("inigrid", String.Empty);

                if (iniGridName == string.Empty) //Read the old name then
                    iniGridName =
                        startupConfig.GetString ("inifile", String.Empty);

                string iniSimName =
                    startupConfig.GetString ("inisim", defaultIniFile);

                //Be mindful of these when modifying...
                //1) When file A includes file B, if the same directive is found in both, that the value in file B wins.
                //2) That inifile may be used with or without inimaster being used.
                //3) That any values for directives pulled in via inifile (Config Set 2) override directives of the same name found in the directive set (Config Set 1) created by reading in bin/Aurora.ini and its subsequently included files or that created by reading in whatever file inimaster points to and its subsequently included files.

                if (IsUri (masterFileName))
                {
                    if (!sources.Contains (masterFileName))
                        sources.Add (masterFileName);
                }
                else
                {
                    string masterFilePath = Util.BasePathCombine (masterFileName);

                    if (masterFileName != String.Empty &&
                            File.Exists (masterFilePath) &&
                            (!sources.Contains (masterFilePath)))
                        sources.Add (masterFilePath);
                    if (iniGridName == "") //Then it doesn't exist and we need to set this
                        iniFilePath = masterFilePath;
                    if (iniSimName == "") //Then it doesn't exist and we need to set this
                        iniFilePath = masterFilePath;
                }

                if (iniGridName != "")
                {
                    if (IsUri (iniGridName))
                    {
                        if (!sources.Contains (iniGridName))
                            sources.Add (iniGridName);
                        iniFilePath = iniGridName;
                    }
                    else
                    {
                        iniFilePath = Util.BasePathCombine (iniGridName);

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

                if (iniSimName != "")
                {
                    if (IsUri (iniSimName))
                    {
                        if (!sources.Contains (iniSimName))
                            sources.Add (iniSimName);
                        iniFilePath = iniSimName;
                    }
                    else
                    {
                        iniFilePath = Util.BasePathCombine (iniSimName);

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

                string iniDirName =
                        startupConfig.GetString ("inidirectory", "");

                if (iniDirName != "" && 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")
                        {
                            if (!sources.Contains (Path.Combine (iniDirName, filePath)))
                                sources.Add (Path.Combine (iniDirName, filePath));
                        }
                    }
                }
            }
            else
            {
                string mainIniDirectory = startupConfig.GetString ("mainIniDirectory", "");
                if(mainIniDirectory != "")
                    basePath = mainIniDirectory;

                string mainIniFileName = startupConfig.GetString ("mainIniFileName", defaultIniFile);

                string secondaryIniFileName = startupConfig.GetString ("secondaryIniFileName", "");

                if(mainIniFileName == "")
                {
                }
                else if (IsUri (mainIniFileName))
                {
                    if (!sources.Contains (mainIniFileName))
                        sources.Add (mainIniFileName);
                }
                else
                {
                    string mainIniFilePath = Path.Combine (mainIniDirectory, mainIniFileName);
                    if (!sources.Contains (mainIniFilePath))
                        sources.Add (mainIniFilePath);
                }

                if (secondaryIniFileName == "")
                {
                }
                else if (IsUri (secondaryIniFileName))
                {
                    if (!sources.Contains (secondaryIniFileName))
                        sources.Add (secondaryIniFileName);
                }
                else
                {
                    string secondaryIniFilePath = Path.Combine (mainIniDirectory, secondaryIniFileName);
                    if (!sources.Contains (secondaryIniFilePath))
                        sources.Add (secondaryIniFilePath);
                }
            }

            m_config = new IniConfigSource();
            
            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 " + defaultIniFile + ".example file to " + defaultIniFile + "?");
                throw new NotSupportedException();
            }

            List<string> triedPaths = new List<string> ();
            for (int i = 0 ; i < sources.Count ; i++)
            {
                if (ReadConfig(sources[i], i))
                    iniFileExists = true;
                AddIncludes (sources, basePath, ref i, ref triedPaths);
            }

            FixDefines (ref m_config);

            if (!iniFileExists)
            {
                m_log.FatalFormat("[CONFIG]: Could not load any configuration");
                m_log.FatalFormat("[CONFIG]: Configuration exists, but there was an error loading it!");
                throw new NotSupportedException();
            }
            // Make sure command line options take precedence
            m_config.Merge(argvSource);

            return m_config;
        }
Exemplo n.º 20
0
        // Handle all the automagical stuff
        public ServicesServerBase(string prompt, string[] args)
        {
            // Save raw arguments
            m_Arguments = args;

            // Read command line
            ArgvConfigSource argvConfig = new ArgvConfigSource(args);

            argvConfig.AddSwitch("Startup", "console", "c");
            argvConfig.AddSwitch("Startup", "logfile", "l");
            argvConfig.AddSwitch("Startup", "inifile", "i");

            // Automagically create the ini file name
            string       fullName     = Assembly.GetEntryAssembly().FullName;
            AssemblyName assemblyName = new AssemblyName(fullName);

            string iniFile = assemblyName.Name + ".ini";

            // Check if a file name was given on the command line
            IConfig startupConfig = argvConfig.Configs["Startup"];

            if (startupConfig != null)
            {
                iniFile = startupConfig.GetString("inifile", iniFile);
            }

            // Find out of the file name is a URI and remote load it
            // if it's possible. Load it as a local file otherwise.
            Uri configUri;

            try
            {
                if (Uri.TryCreate(iniFile, UriKind.Absolute, out configUri) && configUri.Scheme == Uri.UriSchemeHttp)
                {
                    XmlReader r = XmlReader.Create(iniFile);
                    m_Config = new XmlConfigSource(r);
                }
                else
                {
                    m_Config = new IniConfigSource(iniFile);
                }
            }
            catch (Exception)
            {
                System.Console.WriteLine("Error reading from config source {0}", iniFile);
                Thread.CurrentThread.Abort();
            }

            // Merge the configuration from the command line into the
            // loaded file
            m_Config.Merge(argvConfig);

            // Refresh the startupConfig post merge
            startupConfig = argvConfig.Configs["Startup"];

            // Allow derived classes to load config before the console is
            // opened.
            ReadConfig();

            // Create main console
            string consoleType = "local";

            if (startupConfig != null)
            {
                consoleType = startupConfig.GetString("console", consoleType);
            }

            if (consoleType == "basic")
            {
                MainConsole.Instance = new CommandConsole(prompt);
            }
            else
            {
                MainConsole.Instance = new LocalConsole(prompt);
            }

            // Configure the appenders for log4net
            OpenSimAppender consoleAppender = null;
            FileAppender    fileAppender    = null;

            XmlConfigurator.Configure();

            ILoggerRepository repository = LogManager.GetRepository();

            IAppender[] appenders = repository.GetAppenders();

            foreach (IAppender appender in appenders)
            {
                if (appender.Name == "Console")
                {
                    consoleAppender = (OpenSimAppender)appender;
                }

                if (appender.Name == "LogFileAppender")
                {
                    fileAppender = (FileAppender)appender;
                }
            }

            if (consoleAppender == null)
            {
                System.Console.WriteLine("No console appender found. Server can't start");
                Thread.CurrentThread.Abort();
            }
            else
            {
                consoleAppender.Console = MainConsole.Instance;

                if (null == consoleAppender.Threshold)
                {
                    consoleAppender.Threshold = Level.All;
                }
            }

            // Set log file
            if (fileAppender != null)
            {
                if (startupConfig != null)
                {
                    fileAppender.File = startupConfig.GetString("logfile", assemblyName.Name + ".log");
                }
            }

            // Register the quit command
            MainConsole.Instance.Commands.AddCommand("base", false, "quit",
                                                     "quit",
                                                     "Quit the application", HandleQuit);

            // Allow derived classes to perform initialization that
            // needs to be done after the console has opened
            Initialise();
        }
Exemplo n.º 21
0
        public uint Configure(IConfigSource config)
        {
            Config = config;

            IConfig startconfig     = Config.Configs["Startup"];
            string  configdirectory = startconfig.GetString("ConfigDirectory", ".");

            ConfigFile = Path.Combine(configdirectory, CONFIG_FILE);

            IConfig wifiConfig = Config.Configs[ConfigName];

            if (wifiConfig == null)
            {
                // No [WifiService] in the main configuration. We need to read it from its own file
                if (!File.Exists(ConfigFile))
                {
                    // We need to copy the one that comes in the package
                    if (!Directory.Exists(configdirectory))
                    {
                        Directory.CreateDirectory(configdirectory);
                    }

                    string embeddedConfig = Path.Combine(AssemblyDirectory, CONFIG_FILE);
                    File.Copy(embeddedConfig, ConfigFile);
                    m_log.ErrorFormat("[Wifi]: PLEASE EDIT {0} BEFORE RUNNING THIS SERVICE", ConfigFile);
                    throw new Exception("Wifi addin must be configured prior to running");
                }
                else
                {
                    m_log.DebugFormat("[Wifi]: Configuring from {0}...", ConfigFile);

                    IConfigSource configsource = new IniConfigSource(ConfigFile);
                    AdjustStorageProvider(configsource);

                    wifiConfig = configsource.Configs[ConfigName];

                    // Merge everything and expand eventual key values used by our config
                    Config.Merge(configsource);
                    Config.ExpandKeyValues();
                }

                if (wifiConfig == null)
                {
                    throw new Exception(string.Format("[Wifi]: Could not load configuration from {0}. Unable to proceed.", ConfigFile));
                }
            }

            Enabled = wifiConfig.GetBoolean("Enabled", false);

            // Let's look for the port in WifiService first, then look elsewhere
            int port = wifiConfig.GetInt("ServerPort", -1);

            if (port > 0)
            {
                return((uint)port);
            }

            IConfig section = Config.Configs["Const"];

            if (section != null)
            {
                port = section.GetInt("PublicPort", -1);
                if (port > 0)
                {
                    return((uint)port);
                }
            }

            if (port < 0)
            {
                throw new Exception("[Wifi]: Could not find port in configuration file");
            }

            return(0);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Loads the region configuration
        /// </summary>
        /// <param name="argvSource">Parameters passed into the process when started</param>
        /// <returns>A configuration that gets passed to modules</returns>
        public IConfigSource LoadConfigSettings(IConfigSource argvSource)
        {
            iniFilePath = "";
            bool iniFileExists = false;

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

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

            inidbg =
                startupConfig.GetBoolean("inidbg", inidbg);

            showIniLoading =
                startupConfig.GetBoolean("inishowfileloading", showIniLoading);

            string masterFileName =
                startupConfig.GetString("inimaster", String.Empty);

            string iniGridName =
                startupConfig.GetString("inigrid", String.Empty);

            if (iniGridName == string.Empty) //Read the old name then
            {
                iniGridName =
                    startupConfig.GetString("inifile", String.Empty);
            }

            string iniSimName =
                startupConfig.GetString("inisim", defaultIniFile);

            //Be mindful of these when modifying...
            //1) When file A includes file B, if the same directive is found in both, that the value in file B wins.
            //2) That inifile may be used with or without inimaster being used.
            //3) That any values for directives pulled in via inifile (Config Set 2) override directives of the same name found in the directive set (Config Set 1) created by reading in bin/Aurora.ini and its subsequently included files or that created by reading in whatever file inimaster points to and its subsequently included files.

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

                if (masterFileName != String.Empty &&
                    File.Exists(masterFilePath) &&
                    (!sources.Contains(masterFilePath)))
                {
                    sources.Add(masterFilePath);
                }
                if (iniGridName == "") //Then it doesn't exist and we need to set this
                {
                    iniFilePath = masterFilePath;
                }
                if (iniSimName == "") //Then it doesn't exist and we need to set this
                {
                    iniFilePath = masterFilePath;
                }
            }

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

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

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

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

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

            if (Directory.Exists(iniDirPath) && iniDirName != "")
            {
                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 IniConfigSource();

            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 " + defaultIniFile + ".example file to " + defaultIniFile + "?");
                throw new NotSupportedException();
            }

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

            if (!iniFileExists)
            {
                m_log.FatalFormat("[CONFIG]: Could not load any configuration");
                m_log.FatalFormat("[CONFIG]: Configuration exists, but there was an error loading it!");
                throw new NotSupportedException();
            }
            // Make sure command line options take precedence
            m_config.Merge(argvSource);

            return(m_config);
        }
Exemplo n.º 23
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 IConfigSource LoadConfigSettings(IConfig startupConfig)
        {
            bool iniFileExists = false;

            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", Path.Combine(".", "OpenSim.ini"));

            if (IsUri(iniFileName))
            {
                if (!sources.Contains(iniFileName))
                {
                    sources.Add(iniFileName);
                }
            }
            else
            {
                if (File.Exists(iniFileName))
                {
                    if (!sources.Contains(iniFileName))
                    {
                        sources.Add(iniFileName);
                    }
                }
            }

            m_config = new IniConfigSource();
            m_config.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 OpenSim.ini.example file to OpenSim.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);
            }

            return(m_config);
        }
        public uint Configure(IConfigSource config)
        {
            Config = config;

            IConfig startconfig = Config.Configs["Startup"];
            string configdirectory = startconfig.GetString("ConfigDirectory", ".");

            ConfigFile = Path.Combine(configdirectory, CONFIG_FILE);

            IConfig wifiConfig = Config.Configs[ConfigName];

            if (wifiConfig == null)
            {
                // No [WifiService] in the main configuration. We need to read it from its own file
                if (!File.Exists(ConfigFile))
                {
                    // We need to copy the one that comes in the package
                    if (!Directory.Exists(configdirectory))
                        Directory.CreateDirectory(configdirectory);

                    string embeddedConfig = Path.Combine(AssemblyDirectory, CONFIG_FILE);
                    File.Copy(embeddedConfig, ConfigFile);
                    m_log.ErrorFormat("[Wifi]: PLEASE EDIT {0} BEFORE RUNNING THIS SERVICE", ConfigFile);
                    throw new Exception("Wifi addin must be configured prior to running");
                }
                else
                {
                    m_log.DebugFormat("[Wifi]: Configuring from {0}...", ConfigFile);

                    IConfigSource configsource = new IniConfigSource(ConfigFile);
                    AdjustStorageProvider(configsource);

                    wifiConfig = configsource.Configs[ConfigName];

                    // Merge everything and expand eventual key values used by our config
                    Config.Merge(configsource);
                    Config.ExpandKeyValues();
                }

                if (wifiConfig == null)
                    throw new Exception(string.Format("[Wifi]: Could not load configuration from {0}. Unable to proceed.", ConfigFile));

            }

            Enabled = wifiConfig.GetBoolean("Enabled", false);

            // Let's look for the port in WifiService first, then look elsewhere
            int port = wifiConfig.GetInt("ServerPort", -1);
            if (port > 0)
                return (uint)port;

            IConfig section = Config.Configs["Const"];
            if (section != null)
            {
                port = section.GetInt("PublicPort", -1);
                if (port > 0)
                    return (uint)port;
            }

            if (port < 0)
                throw new Exception("[Wifi]: Could not find port in configuration file");

            return 0;
        }
        /// <summary>
        /// Configure the plugin. This is the equivilent of our parameterized constructor
        /// for regular Robust connectors. But, we just get our configuration and return
        /// the port we want to run our connector on back to the application. Then the 
        /// application will send our server to the Initialize method
        /// </summary>
        /// <param name='config'>
        /// IConfigSource - Main Config.
        /// </param>
		public uint Configure(IConfigSource config)
		{
			m_log.Info("[SLIPSTREAM]: Running Configuration");
			Config = config;

			IConfig startconfig = Config.Configs["Startup"];
			string configdirectory = startconfig.GetString("ConfigDirectory", ".");

			ConfigFile = Path.Combine(configdirectory, "SlipStream.ini");
			m_log.InfoFormat("[SLIPSTREAM]: Configuration {0}", ConfigFile);

			// Look in our main config first
			IConfig serverConfig = Config.Configs[ConfigName];
            if (serverConfig == null)
            {
				// Look for individual config file
				serverConfig = GetConfig ();
			    if (serverConfig == null)
				    throw new Exception(String.Format("[SlipStream]: Cannot file configuration for {0}, not loaded!", ConfigName));
                Config.Merge(serverConfig.ConfigSource);
            }

			uint serverPort = (uint) serverConfig.GetInt("ServerPort", 0);
            ServiceModuleName = serverConfig.GetString("LocalServiceModule",
                    String.Empty);

            // Just something to test the config 
			m_log.InfoFormat("[SLIPSTREAM]: CodeWord {0}", serverConfig.GetString ("CodeWord","Blaah!"));

            if (ServiceModuleName == String.Empty)
                throw new Exception("No LocalServiceModule in config file");

            // We want to ship these plugins disabled to allow the user to make
            // adjustments to the ini prior to running. The bootstrap ini will be downloaded
            // when the plugin is enabled the first time. It should have an Enable and it
            // should be set to false. The user can disable the module in the console, make
            // edits (including setting Enable to true) then re-enable the plugin. It will 
            // load and run w/o restarting their Robust.
			if (serverConfig.GetBoolean("Enabled", false) == false)
			{
				m_log.Info("[SLIPSTREAM]: Module Disabled");
				Enabled = false;
				return 0;
			}
			else
				Enabled = true;

			return (uint) serverPort;
		}