OpenSim.cs 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Threading;
  29. using System.Collections;
  30. using System.Collections.Generic;
  31. using System.Diagnostics;
  32. using System.IO;
  33. using System.Linq;
  34. using System.Reflection;
  35. using System.Runtime;
  36. using System.Text;
  37. using System.Text.RegularExpressions;
  38. using System.Timers;
  39. using System.Net;
  40. using log4net;
  41. using NDesk.Options;
  42. using Nini.Config;
  43. using OpenMetaverse;
  44. using OpenSim.Framework;
  45. using OpenSim.Framework.Console;
  46. using OpenSim.Framework.Servers;
  47. using OpenSim.Framework.Monitoring;
  48. using OpenSim.Region.Framework.Interfaces;
  49. using OpenSim.Region.Framework.Scenes;
  50. using OpenSim.Services.Interfaces;
  51. namespace OpenSim
  52. {
  53. /// <summary>
  54. /// Interactive OpenSim region server
  55. /// </summary>
  56. public class OpenSim : OpenSimBase
  57. {
  58. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  59. protected string m_startupCommandsFile;
  60. protected string m_shutdownCommandsFile;
  61. protected bool m_gui = false;
  62. protected string m_consoleType = "local";
  63. protected uint m_consolePort = 0;
  64. /// <summary>
  65. /// Prompt to use for simulator command line.
  66. /// </summary>
  67. private string m_consolePrompt;
  68. /// <summary>
  69. /// Regex for parsing out special characters in the prompt.
  70. /// </summary>
  71. private Regex m_consolePromptRegex = new Regex(@"([^\\])\\(\w)", RegexOptions.Compiled);
  72. private string m_timedScript = "disabled";
  73. private int m_timeInterval = 1200;
  74. private System.Timers.Timer m_scriptTimer;
  75. public OpenSim(IConfigSource configSource) : base(configSource)
  76. {
  77. }
  78. protected override void ReadExtraConfigSettings()
  79. {
  80. base.ReadExtraConfigSettings();
  81. IConfig startupConfig = Config.Configs["Startup"];
  82. IConfig networkConfig = Config.Configs["Network"];
  83. int stpMinThreads = 2;
  84. int stpMaxThreads = 15;
  85. if (startupConfig != null)
  86. {
  87. m_startupCommandsFile = startupConfig.GetString("startup_console_commands_file", "startup_commands.txt");
  88. m_shutdownCommandsFile = startupConfig.GetString("shutdown_console_commands_file", "shutdown_commands.txt");
  89. if (startupConfig.GetString("console", String.Empty) == String.Empty)
  90. m_gui = startupConfig.GetBoolean("gui", false);
  91. else
  92. m_consoleType= startupConfig.GetString("console", String.Empty);
  93. if (networkConfig != null)
  94. m_consolePort = (uint)networkConfig.GetInt("console_port", 0);
  95. m_timedScript = startupConfig.GetString("timer_Script", "disabled");
  96. if (m_timedScript != "disabled")
  97. {
  98. m_timeInterval = startupConfig.GetInt("timer_Interval", 1200);
  99. }
  100. string asyncCallMethodStr = startupConfig.GetString("async_call_method", String.Empty);
  101. FireAndForgetMethod asyncCallMethod;
  102. if (!String.IsNullOrEmpty(asyncCallMethodStr) && Utils.EnumTryParse<FireAndForgetMethod>(asyncCallMethodStr, out asyncCallMethod))
  103. Util.FireAndForgetMethod = asyncCallMethod;
  104. stpMinThreads = startupConfig.GetInt("MinPoolThreads", 2 );
  105. stpMaxThreads = startupConfig.GetInt("MaxPoolThreads", 25);
  106. m_consolePrompt = startupConfig.GetString("ConsolePrompt", @"Region (\R) ");
  107. int dnsTimeout = startupConfig.GetInt("DnsTimeout", 30000);
  108. try { ServicePointManager.DnsRefreshTimeout = dnsTimeout; } catch { }
  109. }
  110. if (Util.FireAndForgetMethod == FireAndForgetMethod.SmartThreadPool)
  111. Util.InitThreadPool(stpMinThreads, stpMaxThreads);
  112. m_log.Info("[OPENSIM MAIN]: Using async_call_method " + Util.FireAndForgetMethod);
  113. m_log.InfoFormat("[OPENSIM MAIN] Running GC in {0} mode", GCSettings.IsServerGC ? "server":"workstation");
  114. }
  115. #if (_MONO)
  116. private static Mono.Unix.UnixSignal[] signals;
  117. private Thread signal_thread = new Thread (delegate ()
  118. {
  119. while (true)
  120. {
  121. // Wait for a signal to be delivered
  122. int index = Mono.Unix.UnixSignal.WaitAny (signals, -1);
  123. //Mono.Unix.Native.Signum signal = signals [index].Signum;
  124. MainConsole.Instance.RunCommand("shutdown");
  125. }
  126. });
  127. #endif
  128. /// <summary>
  129. /// Performs initialisation of the scene, such as loading configuration from disk.
  130. /// </summary>
  131. protected override void StartupSpecific()
  132. {
  133. m_log.Info("====================================================================");
  134. m_log.Info("========================= STARTING OPENSIM =========================");
  135. m_log.Info("====================================================================");
  136. #if (_MONO)
  137. if(!Util.IsWindows())
  138. {
  139. try
  140. {
  141. // linux mac os specifics
  142. signals = new Mono.Unix.UnixSignal[]
  143. {
  144. new Mono.Unix.UnixSignal(Mono.Unix.Native.Signum.SIGTERM)
  145. };
  146. signal_thread.IsBackground = true;
  147. signal_thread.Start();
  148. }
  149. catch (Exception e)
  150. {
  151. m_log.Info("Could not set up UNIX signal handlers. SIGTERM will not");
  152. m_log.InfoFormat("shut down gracefully: {0}", e.Message);
  153. m_log.Debug("Exception was: ", e);
  154. }
  155. }
  156. #endif
  157. //m_log.InfoFormat("[OPENSIM MAIN]: GC Is Server GC: {0}", GCSettings.IsServerGC.ToString());
  158. // http://msdn.microsoft.com/en-us/library/bb384202.aspx
  159. //GCSettings.LatencyMode = GCLatencyMode.Batch;
  160. //m_log.InfoFormat("[OPENSIM MAIN]: GC Latency Mode: {0}", GCSettings.LatencyMode.ToString());
  161. if (m_gui) // Driven by external GUI
  162. {
  163. m_console = new CommandConsole("Region");
  164. }
  165. else
  166. {
  167. switch (m_consoleType)
  168. {
  169. case "basic":
  170. m_console = new CommandConsole("Region");
  171. break;
  172. case "rest":
  173. m_console = new RemoteConsole("Region");
  174. ((RemoteConsole)m_console).ReadConfig(Config);
  175. break;
  176. default:
  177. m_console = new LocalConsole("Region", Config.Configs["Startup"]);
  178. break;
  179. }
  180. }
  181. MainConsole.Instance = m_console;
  182. LogEnvironmentInformation();
  183. RegisterCommonAppenders(Config.Configs["Startup"]);
  184. RegisterConsoleCommands();
  185. base.StartupSpecific();
  186. MainServer.Instance.AddStreamHandler(new OpenSim.SimStatusHandler());
  187. MainServer.Instance.AddStreamHandler(new OpenSim.XSimStatusHandler(this));
  188. if (userStatsURI != String.Empty)
  189. MainServer.Instance.AddStreamHandler(new OpenSim.UXSimStatusHandler(this));
  190. MainServer.Instance.AddStreamHandler(new OpenSim.SimRobotsHandler());
  191. if (managedStatsURI != String.Empty)
  192. {
  193. string urlBase = String.Format("/{0}/", managedStatsURI);
  194. StatsManager.StatsPassword = managedStatsPassword;
  195. MainServer.Instance.AddHTTPHandler(urlBase, StatsManager.HandleStatsRequest);
  196. m_log.InfoFormat("[OPENSIM] Enabling remote managed stats fetch. URL = {0}", urlBase);
  197. }
  198. if (m_console is RemoteConsole)
  199. {
  200. if (m_consolePort == 0)
  201. {
  202. ((RemoteConsole)m_console).SetServer(m_httpServer);
  203. }
  204. else
  205. {
  206. ((RemoteConsole)m_console).SetServer(MainServer.GetHttpServer(m_consolePort));
  207. }
  208. }
  209. // Hook up to the watchdog timer
  210. Watchdog.OnWatchdogTimeout += WatchdogTimeoutHandler;
  211. PrintFileToConsole("startuplogo.txt");
  212. // For now, start at the 'root' level by default
  213. if (SceneManager.Scenes.Count == 1) // If there is only one region, select it
  214. ChangeSelectedRegion("region",
  215. new string[] {"change", "region", SceneManager.Scenes[0].RegionInfo.RegionName});
  216. else
  217. ChangeSelectedRegion("region", new string[] {"change", "region", "root"});
  218. //Run Startup Commands
  219. if (String.IsNullOrEmpty(m_startupCommandsFile))
  220. {
  221. m_log.Info("[STARTUP]: No startup command script specified. Moving on...");
  222. }
  223. else
  224. {
  225. RunCommandScript(m_startupCommandsFile);
  226. }
  227. // Start timer script (run a script every xx seconds)
  228. if (m_timedScript != "disabled")
  229. {
  230. m_scriptTimer = new System.Timers.Timer();
  231. m_scriptTimer.Enabled = true;
  232. m_scriptTimer.Interval = m_timeInterval*1000;
  233. m_scriptTimer.Elapsed += RunAutoTimerScript;
  234. }
  235. }
  236. /// <summary>
  237. /// Register standard set of region console commands
  238. /// </summary>
  239. private void RegisterConsoleCommands()
  240. {
  241. MainServer.RegisterHttpConsoleCommands(m_console);
  242. m_console.Commands.AddCommand("Objects", false, "force update",
  243. "force update",
  244. "Force the update of all objects on clients",
  245. HandleForceUpdate);
  246. m_console.Commands.AddCommand("General", false, "change region",
  247. "change region <region name>",
  248. "Change current console region",
  249. ChangeSelectedRegion);
  250. m_console.Commands.AddCommand("Archiving", false, "save xml",
  251. "save xml [<file name>]",
  252. "Save a region's data in XML format",
  253. SaveXml);
  254. m_console.Commands.AddCommand("Archiving", false, "save xml2",
  255. "save xml2 [<file name>]",
  256. "Save a region's data in XML2 format",
  257. SaveXml2);
  258. m_console.Commands.AddCommand("Archiving", false, "load xml",
  259. "load xml [<file name> [-newUID [<x> <y> <z>]]]",
  260. "Load a region's data from XML format",
  261. LoadXml);
  262. m_console.Commands.AddCommand("Archiving", false, "load xml2",
  263. "load xml2 [<file name>]",
  264. "Load a region's data from XML2 format",
  265. LoadXml2);
  266. m_console.Commands.AddCommand("Archiving", false, "save prims xml2",
  267. "save prims xml2 [<prim name> <file name>]",
  268. "Save named prim to XML2",
  269. SavePrimsXml2);
  270. m_console.Commands.AddCommand("Archiving", false, "load oar",
  271. "load oar [-m|--merge] [-s|--skip-assets]"
  272. + " [--default-user \"User Name\"]"
  273. + " [--force-terrain] [--force-parcels]"
  274. + " [--no-objects]"
  275. + " [--rotation degrees]"
  276. + " [--bounding-origin \"<x,y,z>\"]"
  277. + " [--bounding-size \"<x,y,z>\"]"
  278. + " [--displacement \"<x,y,z>\"]"
  279. + " [-d|--debug]"
  280. + " [<OAR path>]",
  281. "Load a region's data from an OAR archive.",
  282. "--merge will merge the OAR with the existing scene (suppresses terrain and parcel info loading).\n"
  283. + "--skip-assets will load the OAR but ignore the assets it contains.\n"
  284. + "--default-user will use this user for any objects with an owner whose UUID is not found in the grid.\n"
  285. + "--force-terrain forces the loading of terrain from the oar (undoes suppression done by --merge).\n"
  286. + "--force-parcels forces the loading of parcels from the oar (undoes suppression done by --merge).\n"
  287. + "--no-objects suppresses the addition of any objects (good for loading only the terrain).\n"
  288. + "--rotation specified rotation to be applied to the oar. Specified in degrees.\n"
  289. + "--bounding-origin will only place objects that after displacement and rotation fall within the bounding cube who's position starts at <x,y,z>. Defaults to <0,0,0>.\n"
  290. + "--bounding-size specifies the size of the bounding cube. The default is the size of the destination region and cannot be larger than this.\n"
  291. + "--displacement will add this value to the position of every object loaded.\n"
  292. + "--debug forces the archiver to display messages about where each object is being placed.\n\n"
  293. + "The path can be either a filesystem location or a URI.\n"
  294. + " If this is not given then the command looks for an OAR named region.oar in the current directory."
  295. + " [--rotation-center \"<x,y,z>\"] used to be an option, now it does nothing and will be removed soon."
  296. + "When an OAR is being loaded, operations are applied in this order:\n"
  297. + "1: Rotation (around the incoming OARs region center)\n"
  298. + "2: Cropping (a bounding cube with origin and size)\n"
  299. + "3: Displacement (setting offset coordinates within the destination region)",
  300. LoadOar); ;
  301. m_console.Commands.AddCommand("Archiving", false, "save oar",
  302. //"save oar [-v|--version=<N>] [-p|--profile=<url>] [<OAR path>]",
  303. "save oar [-h|--home=<url>] [--noassets] [--publish] [--perm=<permissions>] [--all] [<OAR path>]",
  304. "Save a region's data to an OAR archive.",
  305. // "-v|--version=<N> generates scene objects as per older versions of the serialization (e.g. -v=0)" + Environment.NewLine
  306. "-h|--home=<url> adds the url of the profile service to the saved user information.\n"
  307. + "--noassets stops assets being saved to the OAR.\n"
  308. + "--publish saves an OAR stripped of owner and last owner information.\n"
  309. + " on reload, the estate owner will be the owner of all objects\n"
  310. + " this is useful if you're making oars generally available that might be reloaded to the same grid from which you published\n"
  311. + "--perm=<permissions> stops objects with insufficient permissions from being saved to the OAR.\n"
  312. + " <permissions> can contain one or more of these characters: \"C\" = Copy, \"T\" = Transfer\n"
  313. + "--all saves all the regions in the simulator, instead of just the current region.\n"
  314. + "The OAR path must be a filesystem path."
  315. + " If this is not given then the oar is saved to region.oar in the current directory.",
  316. SaveOar);
  317. m_console.Commands.AddCommand("Objects", false, "edit scale",
  318. "edit scale <name> <x> <y> <z>",
  319. "Change the scale of a named prim",
  320. HandleEditScale);
  321. m_console.Commands.AddCommand("Objects", false, "rotate scene",
  322. "rotate scene <degrees> [centerX, centerY]",
  323. "Rotates all scene objects around centerX, centerY (default 128, 128) (please back up your region before using)",
  324. HandleRotateScene);
  325. m_console.Commands.AddCommand("Objects", false, "scale scene",
  326. "scale scene <factor>",
  327. "Scales the scene objects (please back up your region before using)",
  328. HandleScaleScene);
  329. m_console.Commands.AddCommand("Objects", false, "translate scene",
  330. "translate scene xOffset yOffset zOffset",
  331. "translates the scene objects (please back up your region before using)",
  332. HandleTranslateScene);
  333. m_console.Commands.AddCommand("Users", false, "kick user",
  334. "kick user <first> <last> [--force] [message]",
  335. "Kick a user off the simulator",
  336. "The --force option will kick the user without any checks to see whether it's already in the process of closing\n"
  337. + "Only use this option if you are sure the avatar is inactive and a normal kick user operation does not removed them",
  338. KickUserCommand);
  339. m_console.Commands.AddCommand("Users", false, "show users",
  340. "show users [full]",
  341. "Show user data for users currently on the region",
  342. "Without the 'full' option, only users actually on the region are shown."
  343. + " With the 'full' option child agents of users in neighbouring regions are also shown.",
  344. HandleShow);
  345. m_console.Commands.AddCommand("Comms", false, "show connections",
  346. "show connections",
  347. "Show connection data",
  348. HandleShow);
  349. m_console.Commands.AddCommand("Comms", false, "show circuits",
  350. "show circuits",
  351. "Show agent circuit data",
  352. HandleShow);
  353. m_console.Commands.AddCommand("Comms", false, "show pending-objects",
  354. "show pending-objects",
  355. "Show # of objects on the pending queues of all scene viewers",
  356. HandleShow);
  357. m_console.Commands.AddCommand("General", false, "show modules",
  358. "show modules",
  359. "Show module data",
  360. HandleShow);
  361. m_console.Commands.AddCommand("Regions", false, "show regions",
  362. "show regions",
  363. "Show region data",
  364. HandleShow);
  365. m_console.Commands.AddCommand("Regions", false, "show ratings",
  366. "show ratings",
  367. "Show rating data",
  368. HandleShow);
  369. m_console.Commands.AddCommand("Objects", false, "backup",
  370. "backup",
  371. "Persist currently unsaved object changes immediately instead of waiting for the normal persistence call.",
  372. RunCommand);
  373. m_console.Commands.AddCommand("Regions", false, "create region",
  374. "create region [\"region name\"] <region_file.ini>",
  375. "Create a new region.",
  376. "The settings for \"region name\" are read from <region_file.ini>. Paths specified with <region_file.ini> are relative to your Regions directory, unless an absolute path is given."
  377. + " If \"region name\" does not exist in <region_file.ini>, it will be added." + Environment.NewLine
  378. + "Without \"region name\", the first region found in <region_file.ini> will be created." + Environment.NewLine
  379. + "If <region_file.ini> does not exist, it will be created.",
  380. HandleCreateRegion);
  381. m_console.Commands.AddCommand("Regions", false, "restart",
  382. "restart",
  383. "Restart the currently selected region(s) in this instance",
  384. RunCommand);
  385. m_console.Commands.AddCommand("General", false, "command-script",
  386. "command-script <script>",
  387. "Run a command script from file",
  388. RunCommand);
  389. m_console.Commands.AddCommand("Regions", false, "remove-region",
  390. "remove-region <name>",
  391. "Remove a region from this simulator",
  392. RunCommand);
  393. m_console.Commands.AddCommand("Regions", false, "delete-region",
  394. "delete-region <name>",
  395. "Delete a region from disk",
  396. RunCommand);
  397. m_console.Commands.AddCommand("Estates", false, "estate create",
  398. "estate create <owner UUID> <estate name>",
  399. "Creates a new estate with the specified name, owned by the specified user."
  400. + " Estate name must be unique.",
  401. CreateEstateCommand);
  402. m_console.Commands.AddCommand("Estates", false, "estate set owner",
  403. "estate set owner <estate-id>[ <UUID> | <Firstname> <Lastname> ]",
  404. "Sets the owner of the specified estate to the specified UUID or user. ",
  405. SetEstateOwnerCommand);
  406. m_console.Commands.AddCommand("Estates", false, "estate set name",
  407. "estate set name <estate-id> <new name>",
  408. "Sets the name of the specified estate to the specified value. New name must be unique.",
  409. SetEstateNameCommand);
  410. m_console.Commands.AddCommand("Estates", false, "estate link region",
  411. "estate link region <estate ID> <region ID>",
  412. "Attaches the specified region to the specified estate.",
  413. EstateLinkRegionCommand);
  414. }
  415. protected override void ShutdownSpecific()
  416. {
  417. if (m_shutdownCommandsFile != String.Empty)
  418. {
  419. RunCommandScript(m_shutdownCommandsFile);
  420. }
  421. if (m_timedScript != "disabled")
  422. {
  423. m_scriptTimer.Dispose();
  424. m_timedScript = "disabled";
  425. }
  426. base.ShutdownSpecific();
  427. }
  428. /// <summary>
  429. /// Timer to run a specific text file as console commands. Configured in in the main ini file
  430. /// </summary>
  431. /// <param name="sender"></param>
  432. /// <param name="e"></param>
  433. private void RunAutoTimerScript(object sender, EventArgs e)
  434. {
  435. if (m_timedScript != "disabled")
  436. {
  437. RunCommandScript(m_timedScript);
  438. }
  439. }
  440. private void WatchdogTimeoutHandler(Watchdog.ThreadWatchdogInfo twi)
  441. {
  442. int now = Environment.TickCount & Int32.MaxValue;
  443. m_log.ErrorFormat(
  444. "[WATCHDOG]: Timeout detected for thread \"{0}\". ThreadState={1}. Last tick was {2}ms ago. {3}",
  445. twi.Thread.Name,
  446. twi.Thread.ThreadState,
  447. now - twi.LastTick,
  448. twi.AlarmMethod != null ? string.Format("Data: {0}", twi.AlarmMethod()) : "");
  449. }
  450. #region Console Commands
  451. /// <summary>
  452. /// Kicks users off the region
  453. /// </summary>
  454. /// <param name="module"></param>
  455. /// <param name="cmdparams">name of avatar to kick</param>
  456. private void KickUserCommand(string module, string[] cmdparams)
  457. {
  458. bool force = false;
  459. OptionSet options = new OptionSet().Add("f|force", delegate (string v) { force = v != null; });
  460. List<string> mainParams = options.Parse(cmdparams);
  461. if (mainParams.Count < 4)
  462. return;
  463. string alert = null;
  464. if (mainParams.Count > 4)
  465. alert = String.Format("\n{0}\n", String.Join(" ", cmdparams, 4, cmdparams.Length - 4));
  466. IList agents = SceneManager.GetCurrentSceneAvatars();
  467. foreach (ScenePresence presence in agents)
  468. {
  469. RegionInfo regionInfo = presence.Scene.RegionInfo;
  470. if (presence.Firstname.ToLower().Equals(mainParams[2].ToLower()) &&
  471. presence.Lastname.ToLower().Equals(mainParams[3].ToLower()))
  472. {
  473. MainConsole.Instance.Output(
  474. String.Format(
  475. "Kicking user: {0,-16} {1,-16} {2,-37} in region: {3,-16}",
  476. presence.Firstname, presence.Lastname, presence.UUID, regionInfo.RegionName));
  477. // kick client...
  478. if (alert != null)
  479. presence.ControllingClient.Kick(alert);
  480. else
  481. presence.ControllingClient.Kick("\nYou have been logged out by an administrator.\n");
  482. presence.Scene.CloseAgent(presence.UUID, force);
  483. break;
  484. }
  485. }
  486. MainConsole.Instance.Output("");
  487. }
  488. /// <summary>
  489. /// Opens a file and uses it as input to the console command parser.
  490. /// </summary>
  491. /// <param name="fileName">name of file to use as input to the console</param>
  492. private static void PrintFileToConsole(string fileName)
  493. {
  494. if (File.Exists(fileName))
  495. {
  496. StreamReader readFile = File.OpenText(fileName);
  497. string currentLine;
  498. while ((currentLine = readFile.ReadLine()) != null)
  499. {
  500. m_log.Info("[!]" + currentLine);
  501. }
  502. }
  503. }
  504. /// <summary>
  505. /// Force resending of all updates to all clients in active region(s)
  506. /// </summary>
  507. /// <param name="module"></param>
  508. /// <param name="args"></param>
  509. private void HandleForceUpdate(string module, string[] args)
  510. {
  511. MainConsole.Instance.Output("Updating all clients");
  512. SceneManager.ForceCurrentSceneClientUpdate();
  513. }
  514. /// <summary>
  515. /// Edits the scale of a primative with the name specified
  516. /// </summary>
  517. /// <param name="module"></param>
  518. /// <param name="args">0,1, name, x, y, z</param>
  519. private void HandleEditScale(string module, string[] args)
  520. {
  521. if (args.Length == 6)
  522. {
  523. SceneManager.HandleEditCommandOnCurrentScene(args);
  524. }
  525. else
  526. {
  527. MainConsole.Instance.Output("Argument error: edit scale <prim name> <x> <y> <z>");
  528. }
  529. }
  530. private void HandleRotateScene(string module, string[] args)
  531. {
  532. string usage = "Usage: rotate scene <angle in degrees> [centerX centerY] (centerX and centerY are optional and default to Constants.RegionSize / 2";
  533. float centerX = Constants.RegionSize * 0.5f;
  534. float centerY = Constants.RegionSize * 0.5f;
  535. if (args.Length < 3 || args.Length == 4)
  536. {
  537. MainConsole.Instance.Output(usage);
  538. return;
  539. }
  540. float angle = (float)(Convert.ToSingle(args[2]) / 180.0 * Math.PI);
  541. OpenMetaverse.Quaternion rot = OpenMetaverse.Quaternion.CreateFromAxisAngle(0, 0, 1, angle);
  542. if (args.Length > 4)
  543. {
  544. centerX = Convert.ToSingle(args[3]);
  545. centerY = Convert.ToSingle(args[4]);
  546. }
  547. Vector3 center = new Vector3(centerX, centerY, 0.0f);
  548. SceneManager.ForEachSelectedScene(delegate(Scene scene)
  549. {
  550. scene.ForEachSOG(delegate(SceneObjectGroup sog)
  551. {
  552. if (!sog.IsAttachment)
  553. {
  554. sog.RootPart.UpdateRotation(rot * sog.GroupRotation);
  555. Vector3 offset = sog.AbsolutePosition - center;
  556. offset *= rot;
  557. sog.UpdateGroupPosition(center + offset);
  558. }
  559. });
  560. });
  561. }
  562. private void HandleScaleScene(string module, string[] args)
  563. {
  564. string usage = "Usage: scale scene <factor>";
  565. if (args.Length < 3)
  566. {
  567. MainConsole.Instance.Output(usage);
  568. return;
  569. }
  570. float factor = (float)(Convert.ToSingle(args[2]));
  571. float minZ = float.MaxValue;
  572. SceneManager.ForEachSelectedScene(delegate(Scene scene)
  573. {
  574. scene.ForEachSOG(delegate(SceneObjectGroup sog)
  575. {
  576. if (!sog.IsAttachment)
  577. {
  578. if (sog.RootPart.AbsolutePosition.Z < minZ)
  579. minZ = sog.RootPart.AbsolutePosition.Z;
  580. }
  581. });
  582. });
  583. SceneManager.ForEachSelectedScene(delegate(Scene scene)
  584. {
  585. scene.ForEachSOG(delegate(SceneObjectGroup sog)
  586. {
  587. if (!sog.IsAttachment)
  588. {
  589. Vector3 tmpRootPos = sog.RootPart.AbsolutePosition;
  590. tmpRootPos.Z -= minZ;
  591. tmpRootPos *= factor;
  592. tmpRootPos.Z += minZ;
  593. foreach (SceneObjectPart sop in sog.Parts)
  594. {
  595. if (sop.ParentID != 0)
  596. sop.OffsetPosition *= factor;
  597. sop.Scale *= factor;
  598. }
  599. sog.UpdateGroupPosition(tmpRootPos);
  600. }
  601. });
  602. });
  603. }
  604. private void HandleTranslateScene(string module, string[] args)
  605. {
  606. string usage = "Usage: translate scene <xOffset, yOffset, zOffset>";
  607. if (args.Length < 5)
  608. {
  609. MainConsole.Instance.Output(usage);
  610. return;
  611. }
  612. float xOFfset = (float)Convert.ToSingle(args[2]);
  613. float yOffset = (float)Convert.ToSingle(args[3]);
  614. float zOffset = (float)Convert.ToSingle(args[4]);
  615. Vector3 offset = new Vector3(xOFfset, yOffset, zOffset);
  616. SceneManager.ForEachSelectedScene(delegate(Scene scene)
  617. {
  618. scene.ForEachSOG(delegate(SceneObjectGroup sog)
  619. {
  620. if (!sog.IsAttachment)
  621. sog.UpdateGroupPosition(sog.AbsolutePosition + offset);
  622. });
  623. });
  624. }
  625. /// <summary>
  626. /// Creates a new region based on the parameters specified. This will ask the user questions on the console
  627. /// </summary>
  628. /// <param name="module"></param>
  629. /// <param name="cmd">0,1,region name, region ini or XML file</param>
  630. private void HandleCreateRegion(string module, string[] cmd)
  631. {
  632. string regionName = string.Empty;
  633. string regionFile = string.Empty;
  634. if (cmd.Length == 3)
  635. {
  636. regionFile = cmd[2];
  637. }
  638. else if (cmd.Length > 3)
  639. {
  640. regionName = cmd[2];
  641. regionFile = cmd[3];
  642. }
  643. string extension = Path.GetExtension(regionFile).ToLower();
  644. bool isXml = extension.Equals(".xml");
  645. bool isIni = extension.Equals(".ini");
  646. if (!isXml && !isIni)
  647. {
  648. MainConsole.Instance.Output("Usage: create region [\"region name\"] <region_file.ini>");
  649. return;
  650. }
  651. if (!Path.IsPathRooted(regionFile))
  652. {
  653. string regionsDir = ConfigSource.Source.Configs["Startup"].GetString("regionload_regionsdir", "Regions").Trim();
  654. regionFile = Path.Combine(regionsDir, regionFile);
  655. }
  656. RegionInfo regInfo;
  657. if (isXml)
  658. {
  659. regInfo = new RegionInfo(regionName, regionFile, false, ConfigSource.Source);
  660. }
  661. else
  662. {
  663. regInfo = new RegionInfo(regionName, regionFile, false, ConfigSource.Source, regionName);
  664. }
  665. Scene existingScene;
  666. if (SceneManager.TryGetScene(regInfo.RegionID, out existingScene))
  667. {
  668. MainConsole.Instance.Output(
  669. "ERROR: Cannot create region {0} with ID {1}, this ID is already assigned to region {2}", null,
  670. regInfo.RegionName, regInfo.RegionID, existingScene.RegionInfo.RegionName);
  671. return;
  672. }
  673. bool changed = PopulateRegionEstateInfo(regInfo);
  674. IScene scene;
  675. CreateRegion(regInfo, true, out scene);
  676. if (changed)
  677. m_estateDataService.StoreEstateSettings(regInfo.EstateSettings);
  678. scene.Start();
  679. }
  680. /// <summary>
  681. /// Runs commands issued by the server console from the operator
  682. /// </summary>
  683. /// <param name="command">The first argument of the parameter (the command)</param>
  684. /// <param name="cmdparams">Additional arguments passed to the command</param>
  685. public void RunCommand(string module, string[] cmdparams)
  686. {
  687. List<string> args = new List<string>(cmdparams);
  688. if (args.Count < 1)
  689. return;
  690. string command = args[0];
  691. args.RemoveAt(0);
  692. cmdparams = args.ToArray();
  693. switch (command)
  694. {
  695. case "backup":
  696. MainConsole.Instance.Output("Triggering save of pending object updates to persistent store");
  697. SceneManager.BackupCurrentScene();
  698. break;
  699. case "remove-region":
  700. string regRemoveName = CombineParams(cmdparams, 0);
  701. Scene removeScene;
  702. if (SceneManager.TryGetScene(regRemoveName, out removeScene))
  703. RemoveRegion(removeScene, false);
  704. else
  705. MainConsole.Instance.Output("No region with that name");
  706. break;
  707. case "delete-region":
  708. string regDeleteName = CombineParams(cmdparams, 0);
  709. Scene killScene;
  710. if (SceneManager.TryGetScene(regDeleteName, out killScene))
  711. RemoveRegion(killScene, true);
  712. else
  713. MainConsole.Instance.Output("no region with that name");
  714. break;
  715. case "restart":
  716. SceneManager.RestartCurrentScene();
  717. break;
  718. }
  719. }
  720. /// <summary>
  721. /// Change the currently selected region. The selected region is that operated upon by single region commands.
  722. /// </summary>
  723. /// <param name="cmdParams"></param>
  724. protected void ChangeSelectedRegion(string module, string[] cmdparams)
  725. {
  726. if (cmdparams.Length > 2)
  727. {
  728. string newRegionName = CombineParams(cmdparams, 2);
  729. if (!SceneManager.TrySetCurrentScene(newRegionName))
  730. MainConsole.Instance.Output(String.Format("Couldn't select region {0}", newRegionName));
  731. else
  732. RefreshPrompt();
  733. }
  734. else
  735. {
  736. MainConsole.Instance.Output("Usage: change region <region name>");
  737. }
  738. }
  739. /// <summary>
  740. /// Refreshs prompt with the current selection details.
  741. /// </summary>
  742. private void RefreshPrompt()
  743. {
  744. string regionName = (SceneManager.CurrentScene == null ? "root" : SceneManager.CurrentScene.RegionInfo.RegionName);
  745. MainConsole.Instance.Output(String.Format("Currently selected region is {0}", regionName));
  746. // m_log.DebugFormat("Original prompt is {0}", m_consolePrompt);
  747. string prompt = m_consolePrompt;
  748. // Replace "\R" with the region name
  749. // Replace "\\" with "\"
  750. prompt = m_consolePromptRegex.Replace(prompt, m =>
  751. {
  752. // m_log.DebugFormat("Matched {0}", m.Groups[2].Value);
  753. if (m.Groups[2].Value == "R")
  754. return m.Groups[1].Value + regionName;
  755. else
  756. return m.Groups[0].Value;
  757. });
  758. m_console.DefaultPrompt = prompt;
  759. m_console.ConsoleScene = SceneManager.CurrentScene;
  760. }
  761. protected override void HandleRestartRegion(RegionInfo whichRegion)
  762. {
  763. base.HandleRestartRegion(whichRegion);
  764. // Where we are restarting multiple scenes at once, a previous call to RefreshPrompt may have set the
  765. // m_console.ConsoleScene to null (indicating all scenes).
  766. if (m_console.ConsoleScene != null && whichRegion.RegionName == ((Scene)m_console.ConsoleScene).Name)
  767. SceneManager.TrySetCurrentScene(whichRegion.RegionName);
  768. RefreshPrompt();
  769. }
  770. // see BaseOpenSimServer
  771. /// <summary>
  772. /// Many commands list objects for debugging. Some of the types are listed here
  773. /// </summary>
  774. /// <param name="mod"></param>
  775. /// <param name="cmd"></param>
  776. public override void HandleShow(string mod, string[] cmd)
  777. {
  778. base.HandleShow(mod, cmd);
  779. List<string> args = new List<string>(cmd);
  780. args.RemoveAt(0);
  781. string[] showParams = args.ToArray();
  782. switch (showParams[0])
  783. {
  784. case "users":
  785. IList agents;
  786. if (showParams.Length > 1 && showParams[1] == "full")
  787. {
  788. agents = SceneManager.GetCurrentScenePresences();
  789. } else
  790. {
  791. agents = SceneManager.GetCurrentSceneAvatars();
  792. }
  793. MainConsole.Instance.Output(String.Format("\nAgents connected: {0}\n", agents.Count));
  794. MainConsole.Instance.Output(
  795. String.Format("{0,-16} {1,-16} {2,-37} {3,-11} {4,-16} {5,-30}", "Firstname", "Lastname",
  796. "Agent ID", "Root/Child", "Region", "Position")
  797. );
  798. foreach (ScenePresence presence in agents)
  799. {
  800. RegionInfo regionInfo = presence.Scene.RegionInfo;
  801. string regionName;
  802. if (regionInfo == null)
  803. {
  804. regionName = "Unresolvable";
  805. } else
  806. {
  807. regionName = regionInfo.RegionName;
  808. }
  809. MainConsole.Instance.Output(
  810. String.Format(
  811. "{0,-16} {1,-16} {2,-37} {3,-11} {4,-16} {5,-30}",
  812. presence.Firstname,
  813. presence.Lastname,
  814. presence.UUID,
  815. presence.IsChildAgent ? "Child" : "Root",
  816. regionName,
  817. presence.AbsolutePosition.ToString())
  818. );
  819. }
  820. MainConsole.Instance.Output(String.Empty);
  821. break;
  822. case "connections":
  823. HandleShowConnections();
  824. break;
  825. case "circuits":
  826. HandleShowCircuits();
  827. break;
  828. case "modules":
  829. SceneManager.ForEachSelectedScene(
  830. scene =>
  831. {
  832. MainConsole.Instance.Output("Loaded region modules in {0} are:", null, scene.Name);
  833. List<IRegionModuleBase> sharedModules = new List<IRegionModuleBase>();
  834. List<IRegionModuleBase> nonSharedModules = new List<IRegionModuleBase>();
  835. foreach (IRegionModuleBase module in scene.RegionModules.Values)
  836. {
  837. if (module.GetType().GetInterface("ISharedRegionModule") == null)
  838. nonSharedModules.Add(module);
  839. else
  840. sharedModules.Add(module);
  841. }
  842. foreach (IRegionModuleBase module in sharedModules.OrderBy(m => m.Name))
  843. MainConsole.Instance.Output("New Region Module (Shared): {0}", null, module.Name);
  844. foreach (IRegionModuleBase module in nonSharedModules.OrderBy(m => m.Name))
  845. MainConsole.Instance.Output("New Region Module (Non-Shared): {0}", null, module.Name);
  846. }
  847. );
  848. MainConsole.Instance.Output("");
  849. break;
  850. case "regions":
  851. ConsoleDisplayTable cdt = new ConsoleDisplayTable();
  852. cdt.AddColumn("Name", ConsoleDisplayUtil.RegionNameSize);
  853. cdt.AddColumn("ID", ConsoleDisplayUtil.UuidSize);
  854. cdt.AddColumn("Position", ConsoleDisplayUtil.CoordTupleSize);
  855. cdt.AddColumn("Size", 11);
  856. cdt.AddColumn("Port", ConsoleDisplayUtil.PortSize);
  857. cdt.AddColumn("Ready?", 6);
  858. cdt.AddColumn("Estate", ConsoleDisplayUtil.EstateNameSize);
  859. SceneManager.ForEachScene(
  860. scene =>
  861. {
  862. RegionInfo ri = scene.RegionInfo;
  863. cdt.AddRow(
  864. ri.RegionName,
  865. ri.RegionID,
  866. string.Format("{0},{1}", ri.RegionLocX, ri.RegionLocY),
  867. string.Format("{0}x{1}", ri.RegionSizeX, ri.RegionSizeY),
  868. ri.InternalEndPoint.Port,
  869. scene.Ready ? "Yes" : "No",
  870. ri.EstateSettings.EstateName);
  871. }
  872. );
  873. MainConsole.Instance.Output(cdt.ToString());
  874. break;
  875. case "ratings":
  876. SceneManager.ForEachScene(
  877. delegate(Scene scene)
  878. {
  879. string rating = "";
  880. if (scene.RegionInfo.RegionSettings.Maturity == 1)
  881. {
  882. rating = "MATURE";
  883. }
  884. else if (scene.RegionInfo.RegionSettings.Maturity == 2)
  885. {
  886. rating = "ADULT";
  887. }
  888. else
  889. {
  890. rating = "PG";
  891. }
  892. MainConsole.Instance.Output(String.Format(
  893. "Region Name: {0}, Region Rating {1}",
  894. scene.RegionInfo.RegionName,
  895. rating));
  896. });
  897. break;
  898. }
  899. }
  900. private void HandleShowCircuits()
  901. {
  902. ConsoleDisplayTable cdt = new ConsoleDisplayTable();
  903. cdt.AddColumn("Region", 20);
  904. cdt.AddColumn("Avatar name", 24);
  905. cdt.AddColumn("Type", 5);
  906. cdt.AddColumn("Code", 10);
  907. cdt.AddColumn("IP", 16);
  908. cdt.AddColumn("Viewer Name", 24);
  909. SceneManager.ForEachScene(
  910. s =>
  911. {
  912. foreach (AgentCircuitData aCircuit in s.AuthenticateHandler.GetAgentCircuits().Values)
  913. cdt.AddRow(
  914. s.Name,
  915. aCircuit.Name,
  916. aCircuit.child ? "child" : "root",
  917. aCircuit.circuitcode.ToString(),
  918. aCircuit.IPAddress != null ? aCircuit.IPAddress.ToString() : "not set",
  919. Util.GetViewerName(aCircuit));
  920. });
  921. MainConsole.Instance.Output(cdt.ToString());
  922. }
  923. private void HandleShowConnections()
  924. {
  925. ConsoleDisplayTable cdt = new ConsoleDisplayTable();
  926. cdt.AddColumn("Region", 20);
  927. cdt.AddColumn("Avatar name", 24);
  928. cdt.AddColumn("Circuit code", 12);
  929. cdt.AddColumn("Endpoint", 23);
  930. cdt.AddColumn("Active?", 7);
  931. cdt.AddColumn("ChildAgent?", 7);
  932. cdt.AddColumn("ping(ms)", 8);
  933. SceneManager.ForEachScene(
  934. s => s.ForEachClient(
  935. c =>
  936. {
  937. bool child = false;
  938. if(c.SceneAgent != null && c.SceneAgent.IsChildAgent)
  939. child = true;
  940. cdt.AddRow(
  941. s.Name,
  942. c.Name,
  943. c.CircuitCode.ToString(),
  944. c.RemoteEndPoint.ToString(),
  945. c.IsActive.ToString(),
  946. child.ToString(),
  947. c.PingTimeMS);
  948. }));
  949. MainConsole.Instance.Output(cdt.ToString());
  950. }
  951. /// <summary>
  952. /// Use XML2 format to serialize data to a file
  953. /// </summary>
  954. /// <param name="module"></param>
  955. /// <param name="cmdparams"></param>
  956. protected void SavePrimsXml2(string module, string[] cmdparams)
  957. {
  958. if (cmdparams.Length > 4)
  959. {
  960. SceneManager.SaveNamedPrimsToXml2(cmdparams[3], cmdparams[4]);
  961. }
  962. else
  963. {
  964. SceneManager.SaveNamedPrimsToXml2("Primitive", DEFAULT_PRIM_BACKUP_FILENAME);
  965. }
  966. }
  967. /// <summary>
  968. /// Use XML format to serialize data to a file
  969. /// </summary>
  970. /// <param name="module"></param>
  971. /// <param name="cmdparams"></param>
  972. protected void SaveXml(string module, string[] cmdparams)
  973. {
  974. MainConsole.Instance.Output("PLEASE NOTE, save-xml is DEPRECATED and may be REMOVED soon. If you are using this and there is some reason you can't use save-xml2, please file a mantis detailing the reason.");
  975. if (cmdparams.Length > 2)
  976. {
  977. SceneManager.SaveCurrentSceneToXml(cmdparams[2]);
  978. }
  979. else
  980. {
  981. SceneManager.SaveCurrentSceneToXml(DEFAULT_PRIM_BACKUP_FILENAME);
  982. }
  983. }
  984. /// <summary>
  985. /// Loads data and region objects from XML format.
  986. /// </summary>
  987. /// <param name="module"></param>
  988. /// <param name="cmdparams"></param>
  989. protected void LoadXml(string module, string[] cmdparams)
  990. {
  991. MainConsole.Instance.Output("PLEASE NOTE, load-xml is DEPRECATED and may be REMOVED soon. If you are using this and there is some reason you can't use load-xml2, please file a mantis detailing the reason.");
  992. Vector3 loadOffset = new Vector3(0, 0, 0);
  993. if (cmdparams.Length > 2)
  994. {
  995. bool generateNewIDS = false;
  996. if (cmdparams.Length > 3)
  997. {
  998. if (cmdparams[3] == "-newUID")
  999. {
  1000. generateNewIDS = true;
  1001. }
  1002. if (cmdparams.Length > 4)
  1003. {
  1004. loadOffset.X = (float)Convert.ToDecimal(cmdparams[4], Culture.NumberFormatInfo);
  1005. if (cmdparams.Length > 5)
  1006. {
  1007. loadOffset.Y = (float)Convert.ToDecimal(cmdparams[5], Culture.NumberFormatInfo);
  1008. }
  1009. if (cmdparams.Length > 6)
  1010. {
  1011. loadOffset.Z = (float)Convert.ToDecimal(cmdparams[6], Culture.NumberFormatInfo);
  1012. }
  1013. MainConsole.Instance.Output(String.Format("loadOffsets <X,Y,Z> = <{0},{1},{2}>",loadOffset.X,loadOffset.Y,loadOffset.Z));
  1014. }
  1015. }
  1016. SceneManager.LoadCurrentSceneFromXml(cmdparams[2], generateNewIDS, loadOffset);
  1017. }
  1018. else
  1019. {
  1020. try
  1021. {
  1022. SceneManager.LoadCurrentSceneFromXml(DEFAULT_PRIM_BACKUP_FILENAME, false, loadOffset);
  1023. }
  1024. catch (FileNotFoundException)
  1025. {
  1026. MainConsole.Instance.Output("Default xml not found. Usage: load-xml <filename>");
  1027. }
  1028. }
  1029. }
  1030. /// <summary>
  1031. /// Serialize region data to XML2Format
  1032. /// </summary>
  1033. /// <param name="module"></param>
  1034. /// <param name="cmdparams"></param>
  1035. protected void SaveXml2(string module, string[] cmdparams)
  1036. {
  1037. if (cmdparams.Length > 2)
  1038. {
  1039. SceneManager.SaveCurrentSceneToXml2(cmdparams[2]);
  1040. }
  1041. else
  1042. {
  1043. SceneManager.SaveCurrentSceneToXml2(DEFAULT_PRIM_BACKUP_FILENAME);
  1044. }
  1045. }
  1046. /// <summary>
  1047. /// Load region data from Xml2Format
  1048. /// </summary>
  1049. /// <param name="module"></param>
  1050. /// <param name="cmdparams"></param>
  1051. protected void LoadXml2(string module, string[] cmdparams)
  1052. {
  1053. if (cmdparams.Length > 2)
  1054. {
  1055. try
  1056. {
  1057. SceneManager.LoadCurrentSceneFromXml2(cmdparams[2]);
  1058. }
  1059. catch (FileNotFoundException)
  1060. {
  1061. MainConsole.Instance.Output("Specified xml not found. Usage: load xml2 <filename>");
  1062. }
  1063. }
  1064. else
  1065. {
  1066. try
  1067. {
  1068. SceneManager.LoadCurrentSceneFromXml2(DEFAULT_PRIM_BACKUP_FILENAME);
  1069. }
  1070. catch (FileNotFoundException)
  1071. {
  1072. MainConsole.Instance.Output("Default xml not found. Usage: load xml2 <filename>");
  1073. }
  1074. }
  1075. }
  1076. /// <summary>
  1077. /// Load a whole region from an opensimulator archive.
  1078. /// </summary>
  1079. /// <param name="cmdparams"></param>
  1080. protected void LoadOar(string module, string[] cmdparams)
  1081. {
  1082. try
  1083. {
  1084. SceneManager.LoadArchiveToCurrentScene(cmdparams);
  1085. }
  1086. catch (Exception e)
  1087. {
  1088. MainConsole.Instance.Output(e.Message);
  1089. }
  1090. }
  1091. /// <summary>
  1092. /// Save a region to a file, including all the assets needed to restore it.
  1093. /// </summary>
  1094. /// <param name="cmdparams"></param>
  1095. protected void SaveOar(string module, string[] cmdparams)
  1096. {
  1097. SceneManager.SaveCurrentSceneToArchive(cmdparams);
  1098. }
  1099. protected void CreateEstateCommand(string module, string[] args)
  1100. {
  1101. string response = null;
  1102. UUID userID;
  1103. if (args.Length == 2)
  1104. {
  1105. response = "No user specified.";
  1106. }
  1107. else if (!UUID.TryParse(args[2], out userID))
  1108. {
  1109. response = String.Format("{0} is not a valid UUID", args[2]);
  1110. }
  1111. else if (args.Length == 3)
  1112. {
  1113. response = "No estate name specified.";
  1114. }
  1115. else
  1116. {
  1117. Scene scene = SceneManager.CurrentOrFirstScene;
  1118. // TODO: Is there a better choice here?
  1119. UUID scopeID = UUID.Zero;
  1120. UserAccount account = scene.UserAccountService.GetUserAccount(scopeID, userID);
  1121. if (account == null)
  1122. {
  1123. response = String.Format("Could not find user {0}", userID);
  1124. }
  1125. else
  1126. {
  1127. // concatenate it all to "name"
  1128. StringBuilder sb = new StringBuilder(args[3]);
  1129. for (int i = 4; i < args.Length; i++)
  1130. sb.Append (" " + args[i]);
  1131. string estateName = sb.ToString().Trim();
  1132. // send it off for processing.
  1133. IEstateModule estateModule = scene.RequestModuleInterface<IEstateModule>();
  1134. response = estateModule.CreateEstate(estateName, userID);
  1135. if (response == String.Empty)
  1136. {
  1137. List<int> estates = scene.EstateDataService.GetEstates(estateName);
  1138. response = String.Format("Estate {0} created as \"{1}\"", estates.ElementAt(0), estateName);
  1139. }
  1140. }
  1141. }
  1142. // give the user some feedback
  1143. if (response != null)
  1144. MainConsole.Instance.Output(response);
  1145. }
  1146. protected void SetEstateOwnerCommand(string module, string[] args)
  1147. {
  1148. string response = null;
  1149. Scene scene = SceneManager.CurrentOrFirstScene;
  1150. IEstateModule estateModule = scene.RequestModuleInterface<IEstateModule>();
  1151. if (args.Length == 3)
  1152. {
  1153. response = "No estate specified.";
  1154. }
  1155. else
  1156. {
  1157. int estateId;
  1158. if (!int.TryParse(args[3], out estateId))
  1159. {
  1160. response = String.Format("\"{0}\" is not a valid ID for an Estate", args[3]);
  1161. }
  1162. else
  1163. {
  1164. if (args.Length == 4)
  1165. {
  1166. response = "No user specified.";
  1167. }
  1168. else
  1169. {
  1170. UserAccount account = null;
  1171. // TODO: Is there a better choice here?
  1172. UUID scopeID = UUID.Zero;
  1173. string s1 = args[4];
  1174. if (args.Length == 5)
  1175. {
  1176. // attempt to get account by UUID
  1177. UUID u;
  1178. if (UUID.TryParse(s1, out u))
  1179. {
  1180. account = scene.UserAccountService.GetUserAccount(scopeID, u);
  1181. if (account == null)
  1182. response = String.Format("Could not find user {0}", s1);
  1183. }
  1184. else
  1185. {
  1186. response = String.Format("Invalid UUID {0}", s1);
  1187. }
  1188. }
  1189. else
  1190. {
  1191. // attempt to get account by Firstname, Lastname
  1192. string s2 = args[5];
  1193. account = scene.UserAccountService.GetUserAccount(scopeID, s1, s2);
  1194. if (account == null)
  1195. response = String.Format("Could not find user {0} {1}", s1, s2);
  1196. }
  1197. // If it's valid, send it off for processing.
  1198. if (account != null)
  1199. response = estateModule.SetEstateOwner(estateId, account);
  1200. if (response == String.Empty)
  1201. {
  1202. response = String.Format("Estate owner changed to {0} ({1} {2})", account.PrincipalID, account.FirstName, account.LastName);
  1203. }
  1204. }
  1205. }
  1206. }
  1207. // give the user some feedback
  1208. if (response != null)
  1209. MainConsole.Instance.Output(response);
  1210. }
  1211. protected void SetEstateNameCommand(string module, string[] args)
  1212. {
  1213. string response = null;
  1214. Scene scene = SceneManager.CurrentOrFirstScene;
  1215. IEstateModule estateModule = scene.RequestModuleInterface<IEstateModule>();
  1216. if (args.Length == 3)
  1217. {
  1218. response = "No estate specified.";
  1219. }
  1220. else
  1221. {
  1222. int estateId;
  1223. if (!int.TryParse(args[3], out estateId))
  1224. {
  1225. response = String.Format("\"{0}\" is not a valid ID for an Estate", args[3]);
  1226. }
  1227. else
  1228. {
  1229. if (args.Length == 4)
  1230. {
  1231. response = "No name specified.";
  1232. }
  1233. else
  1234. {
  1235. // everything after the estate ID is "name"
  1236. StringBuilder sb = new StringBuilder(args[4]);
  1237. for (int i = 5; i < args.Length; i++)
  1238. sb.Append (" " + args[i]);
  1239. string estateName = sb.ToString();
  1240. // send it off for processing.
  1241. response = estateModule.SetEstateName(estateId, estateName);
  1242. if (response == String.Empty)
  1243. {
  1244. response = String.Format("Estate {0} renamed to \"{1}\"", estateId, estateName);
  1245. }
  1246. }
  1247. }
  1248. }
  1249. // give the user some feedback
  1250. if (response != null)
  1251. MainConsole.Instance.Output(response);
  1252. }
  1253. private void EstateLinkRegionCommand(string module, string[] args)
  1254. {
  1255. int estateId =-1;
  1256. UUID regionId = UUID.Zero;
  1257. Scene scene = null;
  1258. string response = null;
  1259. if (args.Length == 3)
  1260. {
  1261. response = "No estate specified.";
  1262. }
  1263. else if (!int.TryParse(args [3], out estateId))
  1264. {
  1265. response = String.Format("\"{0}\" is not a valid ID for an Estate", args [3]);
  1266. }
  1267. else if (args.Length == 4)
  1268. {
  1269. response = "No region specified.";
  1270. }
  1271. else if (!UUID.TryParse(args[4], out regionId))
  1272. {
  1273. response = String.Format("\"{0}\" is not a valid UUID for a Region", args [4]);
  1274. }
  1275. else if (!SceneManager.TryGetScene(regionId, out scene))
  1276. {
  1277. // region may exist, but on a different sim.
  1278. response = String.Format("No access to Region \"{0}\"", args [4]);
  1279. }
  1280. if (response != null)
  1281. {
  1282. MainConsole.Instance.Output(response);
  1283. return;
  1284. }
  1285. // send it off for processing.
  1286. IEstateModule estateModule = scene.RequestModuleInterface<IEstateModule>();
  1287. response = estateModule.SetRegionEstate(scene.RegionInfo, estateId);
  1288. if (response == String.Empty)
  1289. {
  1290. estateModule.TriggerRegionInfoChange();
  1291. estateModule.sendRegionHandshakeToAll();
  1292. response = String.Format ("Region {0} is now attached to estate {1}", regionId, estateId);
  1293. }
  1294. // give the user some feedback
  1295. if (response != null)
  1296. MainConsole.Instance.Output (response);
  1297. }
  1298. #endregion
  1299. private static string CombineParams(string[] commandParams, int pos)
  1300. {
  1301. string result = String.Empty;
  1302. for (int i = pos; i < commandParams.Length; i++)
  1303. {
  1304. result += commandParams[i] + " ";
  1305. }
  1306. result = result.TrimEnd(' ');
  1307. return result;
  1308. }
  1309. }
  1310. }