From 7aad5af49850b3938282426dd1ecf160d7053032 Mon Sep 17 00:00:00 2001 From: Marck Date: Sat, 14 Aug 2010 12:46:17 +0200 Subject: Some code cleanup for console command "create region". Make region name an optional command parameter. Avoid question for region name if it has already been specified. Extend help text. --- OpenSim/Region/Application/OpenSim.cs | 65 +++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 30 deletions(-) (limited to 'OpenSim/Region/Application/OpenSim.cs') diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index d9ec287..6834606 100644 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs @@ -308,8 +308,13 @@ namespace OpenSim "Persist objects to the database now", RunCommand); m_console.Commands.AddCommand("region", false, "create region", - "create region", - "Create a new region", HandleCreateRegion); + "create region [\"region name\"] ", + "Create a new region.", + "The settings for \"region name\" are read from ." + + " If \"region name\" does not exist in , it will be added." + Environment.NewLine + + "Without \"region name\", the first region found in will be created." + Environment.NewLine + + "If does not exist, it will be created.", + HandleCreateRegion); m_console.Commands.AddCommand("region", false, "restart", "restart", @@ -513,47 +518,47 @@ namespace OpenSim /// Creates a new region based on the parameters specified. This will ask the user questions on the console /// /// - /// 0,1,region name, region XML file + /// 0,1,region name, region ini or XML file private void HandleCreateRegion(string module, string[] cmd) { - if (cmd.Length < 4) + string regionName = string.Empty; + string regionFile = string.Empty; + if (cmd.Length == 3) { - MainConsole.Instance.Output("Usage: create region "); + regionFile = cmd[2]; + } + else if (cmd.Length > 3) + { + regionName = cmd[2]; + regionFile = cmd[3]; + } + string extension = Path.GetExtension(regionFile).ToLower(); + bool isXml = extension.Equals(".xml"); + bool isIni = extension.Equals(".ini"); + if (!isXml && !isIni) + { + MainConsole.Instance.Output("Usage: create region [\"region name\"] "); return; } - if (cmd[3].EndsWith(".xml")) + if (!Path.IsPathRooted(regionFile)) { string regionsDir = ConfigSource.Source.Configs["Startup"].GetString("regionload_regionsdir", "Regions").Trim(); - string regionFile = String.Format("{0}/{1}", regionsDir, cmd[3]); - // Allow absolute and relative specifiers - if (cmd[3].StartsWith("/") || cmd[3].StartsWith("\\") || cmd[3].StartsWith("..")) - regionFile = cmd[3]; - - IScene scene; - RegionInfo regInfo = new RegionInfo(cmd[2], regionFile, false, ConfigSource.Source); - PopulateRegionEstateInfo(regInfo); - CreateRegion(regInfo, true, out scene); - regInfo.EstateSettings.Save(); + regionFile = Path.Combine(regionsDir, regionFile); } - else if (cmd[3].EndsWith(".ini")) + + RegionInfo regInfo; + if (isXml) { - string regionsDir = ConfigSource.Source.Configs["Startup"].GetString("regionload_regionsdir", "Regions").Trim(); - string regionFile = String.Format("{0}/{1}", regionsDir, cmd[3]); - // Allow absolute and relative specifiers - if (cmd[3].StartsWith("/") || cmd[3].StartsWith("\\") || cmd[3].StartsWith("..")) - regionFile = cmd[3]; - - IScene scene; - RegionInfo regInfo = new RegionInfo(cmd[2], regionFile, false, ConfigSource.Source, cmd[2]); - PopulateRegionEstateInfo(regInfo); - CreateRegion(regInfo, true, out scene); - regInfo.EstateSettings.Save(); + regInfo = new RegionInfo(regionName, regionFile, false, ConfigSource.Source); } else { - MainConsole.Instance.Output("Usage: create region "); - return; + regInfo = new RegionInfo(regionName, regionFile, false, ConfigSource.Source, regionName); } + IScene scene; + PopulateRegionEstateInfo(regInfo); + CreateRegion(regInfo, true, out scene); + regInfo.EstateSettings.Save(); } /// -- cgit v1.1