From f1e10e555d1cc7bee40b4fd05caf2507c5808816 Mon Sep 17 00:00:00 2001 From: MW Date: Sat, 4 Aug 2007 18:15:48 +0000 Subject: clean up of startup config settings (command line args etc), Now using the Nini configuration library (suggest we look into using this for the rest of our config handling, as it provides a standard interface for command line args, INI files, Xml files, .NET config files, and windows registry). One IMPORTANT change is that to TO START GRIDMODE , you need to now use -gridmode=true . Also need someone to test it under mono. (there is a dll that has been compiled under mono available, just hoping that we don't have to deal with separate dlls for windows and linux. --- OpenSim/Region/Application/Application.cs | 71 ++++-------------------------- OpenSim/Region/Application/OpenSimMain.cs | 73 +++++++++++++++++++------------ 2 files changed, 55 insertions(+), 89 deletions(-) (limited to 'OpenSim/Region/Application') diff --git a/OpenSim/Region/Application/Application.cs b/OpenSim/Region/Application/Application.cs index a8c40ec..b07a4d6 100644 --- a/OpenSim/Region/Application/Application.cs +++ b/OpenSim/Region/Application/Application.cs @@ -28,6 +28,7 @@ using System; using OpenSim.Framework.Console; using OpenSim.Region.Environment.Scenes; +using Nini.Config; namespace OpenSim { @@ -52,70 +53,16 @@ namespace OpenSim Console.WriteLine("Starting...\n"); - bool sandBoxMode = true; - bool startLoginServer = true; - string physicsEngine = "basicphysics"; + ArgvConfigSource source = new ArgvConfigSource(args); - bool userAccounts = false; - bool gridLocalAsset = false; - bool useConfigFile = false; - bool silent = false; - string configFile = "simconfig.xml"; - - for (int i = 0; i < args.Length; i++) - { - if (args[i] == "-gridmode") - { - sandBoxMode = false; - startLoginServer = false; - } - - if (args[i] == "-accounts") - { - userAccounts = true; - } - if (args[i] == "-realphysx") - { - physicsEngine = "RealPhysX"; - } - if (args[i] == "-bulletX") - { - physicsEngine = "BulletXEngine"; - } - if (args[i] == "-ode") - { - physicsEngine = "OpenDynamicsEngine"; - } - if (args[i] == "-localasset") - { - gridLocalAsset = true; - } - if (args[i] == "-configfile") - { - useConfigFile = true; - } - if (args[i] == "-noverbose") - { - silent = true; - } - if (args[i] == "-config") - { - try - { - i++; - configFile = args[i]; - } - catch (Exception e) - { - Console.WriteLine("-config: Please specify a config file. (" + e.ToString() + ")"); - } - } - } - - OpenSimMain sim = new OpenSimMain(sandBoxMode, startLoginServer, physicsEngine, useConfigFile, silent, configFile); + source.AddSwitch("Startup", "inifile"); + source.AddSwitch("Startup", "configfile"); + source.AddSwitch("Startup", "gridmode"); + source.AddSwitch("Startup", "physics"); + source.AddSwitch("Startup", "config"); + source.AddSwitch("Startup", "noverbose"); - sim.user_accounts = userAccounts; - sim.m_gridLocalAsset = gridLocalAsset; + OpenSimMain sim = new OpenSimMain(source); sim.StartUp(); diff --git a/OpenSim/Region/Application/OpenSimMain.cs b/OpenSim/Region/Application/OpenSimMain.cs index fbd6790..c68f75e 100644 --- a/OpenSim/Region/Application/OpenSimMain.cs +++ b/OpenSim/Region/Application/OpenSimMain.cs @@ -29,6 +29,7 @@ using System; using System.IO; using libsecondlife; +using Nini.Config; using OpenSim.Assets; using OpenSim.Framework; using OpenSim.Framework.Communications; @@ -39,7 +40,7 @@ using OpenSim.Framework.Servers; using OpenSim.Framework.Types; using OpenSim.Framework.Configuration; using OpenSim.Physics.Manager; - + using OpenSim.Region.ClientStack; using OpenSim.Region.Communications.Local; using OpenSim.Region.Communications.OGS1; @@ -57,7 +58,6 @@ namespace OpenSim { public string m_physicsEngine; public bool m_sandbox; - public bool m_loginserver; public bool user_accounts; public bool m_gridLocalAsset; protected bool m_useConfigFile; @@ -70,18 +70,37 @@ namespace OpenSim private bool m_silent; private string m_logFilename = ("region-console-" + Guid.NewGuid().ToString() + ".log"); - public OpenSimMain(bool sandBoxMode, bool startLoginServer, string physicsEngineName, bool useConfigFile, bool silent, string configFileName) - :base( ) + public OpenSimMain(IConfigSource configSource) + : base() + { + IConfigSource startupSource = configSource; + string iniFile = startupSource.Configs["Startup"].GetString("inifile", "NA"); + if (iniFile != "NA") + { + //a ini is set to be used for startup settings + string iniFilePath = Path.Combine(Util.configDir(), iniFile); + if (File.Exists(iniFilePath)) + { + startupSource = new IniConfigSource(iniFilePath); + + //enable follow line, if we want the original config source(normally commandline args) merged with ini file settings. + //in this case we have it so if both sources have the same named setting, command line value will overwrite the ini file value. + //(as if someone has bothered to enter a command line arg, we should take notice of it) + //startupSource.Merge(configSource); + } + } + ReadConfigSettings(startupSource); + } + + protected void ReadConfigSettings(IConfigSource configSource) { - m_useConfigFile = useConfigFile; - m_sandbox = sandBoxMode; - m_loginserver = startLoginServer; - m_physicsEngine = physicsEngineName; - m_configFileName = configFileName; - m_silent = silent; + m_useConfigFile = configSource.Configs["Startup"].GetBoolean("configfile", false); + m_sandbox = !configSource.Configs["Startup"].GetBoolean("gridmode", false); + m_physicsEngine = configSource.Configs["Startup"].GetString("physics", "basicphysics"); + m_configFileName = configSource.Configs["Startup"].GetString("config", "simconfig.xml"); + m_silent = configSource.Configs["Startup"].GetBoolean("noverbose", false); } - /// /// Performs initialisation of the scene, such as loading configuration from disk. /// @@ -91,7 +110,7 @@ namespace OpenSim { Directory.CreateDirectory(Util.logDir()); } - m_log = new LogBase(Path.Combine(Util.logDir(),m_logFilename), "Region", this, m_silent); + m_log = new LogBase(Path.Combine(Util.logDir(), m_logFilename), "Region", this, m_silent); MainLog.Instance = m_log; base.StartUp(); @@ -103,11 +122,11 @@ namespace OpenSim if (m_sandbox) { - m_commsManager = new CommunicationsLocal( m_networkServersInfo, m_httpServer, m_assetCache); + m_commsManager = new CommunicationsLocal(m_networkServersInfo, m_httpServer, m_assetCache); } else { - m_commsManager = new CommunicationsOGS1( m_networkServersInfo, m_httpServer , m_assetCache); + m_commsManager = new CommunicationsOGS1(m_networkServersInfo, m_httpServer, m_assetCache); } @@ -129,15 +148,15 @@ namespace OpenSim for (int i = 0; i < configFiles.Length; i++) { - Console.WriteLine("Loading region config file"); + //Console.WriteLine("Loading region config file"); RegionInfo regionInfo = new RegionInfo("REGION CONFIG #" + (i + 1), configFiles[i]); - + UDPServer udpServer; Scene scene = SetupScene(regionInfo, out udpServer); - + m_localScenes.Add(scene); - - + + m_udpServers.Add(udpServer); m_regionData.Add(regionInfo); } @@ -148,7 +167,7 @@ namespace OpenSim this.m_udpServers[i].ServerListener(); } - + } protected override StorageManager CreateStorageManager(RegionInfo regionInfo) @@ -160,10 +179,10 @@ namespace OpenSim { return new Scene(regionInfo, circuitManager, m_commsManager, m_assetCache, storageManager, m_httpServer); } - + protected override void Initialize() { - m_networkServersInfo = new NetworkServersInfo("NETWORK SERVERS INFO", Path.Combine(Util.configDir(),"network_servers_information.xml")); + m_networkServersInfo = new NetworkServersInfo("NETWORK SERVERS INFO", Path.Combine(Util.configDir(), "network_servers_information.xml")); m_httpServerPort = m_networkServersInfo.HttpListenerPort; m_assetCache = new AssetCache("OpenSim.Region.GridInterfaces.Local.dll", m_networkServersInfo.AssetURL, m_networkServersInfo.AssetSendKey); } @@ -174,15 +193,15 @@ namespace OpenSim { Directory.CreateDirectory(Util.logDir()); } - - return new LogBase((Path.Combine(Util.logDir(),m_logFilename)), "Region", this, m_silent); + + return new LogBase((Path.Combine(Util.logDir(), m_logFilename)), "Region", this, m_silent); } # region Setup methods - protected override PhysicsScene GetPhysicsScene( ) + protected override PhysicsScene GetPhysicsScene() { - return GetPhysicsScene( m_physicsEngine ); + return GetPhysicsScene(m_physicsEngine); } private class SimStatusHandler : IStreamHandler @@ -201,7 +220,7 @@ namespace OpenSim { get { return "GET"; } } - + public string Path { get { return "/simstatus/"; } -- cgit v1.1