OpenSim.cs 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362
  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.Collections;
  29. using System.Collections.Generic;
  30. using System.IO;
  31. using System.Reflection;
  32. using System.Text;
  33. using System.Text.RegularExpressions;
  34. using System.Timers;
  35. using log4net;
  36. using Nini.Config;
  37. using OpenMetaverse;
  38. using OpenSim.Framework;
  39. using OpenSim.Framework.Console;
  40. using OpenSim.Framework.Servers;
  41. using OpenSim.Framework.Statistics;
  42. using OpenSim.Region.Framework.Interfaces;
  43. using OpenSim.Region.Framework.Scenes;
  44. namespace OpenSim
  45. {
  46. /// <summary>
  47. /// Interactive OpenSim region server
  48. /// </summary>
  49. public class OpenSim : OpenSimBase
  50. {
  51. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  52. protected string m_startupCommandsFile;
  53. protected string m_shutdownCommandsFile;
  54. protected bool m_gui = false;
  55. protected string m_consoleType = "local";
  56. protected uint m_consolePort = 0;
  57. /// <summary>
  58. /// Prompt to use for simulator command line.
  59. /// </summary>
  60. private string m_consolePrompt;
  61. /// <summary>
  62. /// Regex for parsing out special characters in the prompt.
  63. /// </summary>
  64. private Regex m_consolePromptRegex = new Regex(@"([^\\])\\(\w)", RegexOptions.Compiled);
  65. private string m_timedScript = "disabled";
  66. private Timer m_scriptTimer;
  67. public OpenSim(IConfigSource configSource) : base(configSource)
  68. {
  69. }
  70. protected override void ReadExtraConfigSettings()
  71. {
  72. base.ReadExtraConfigSettings();
  73. IConfig startupConfig = m_config.Source.Configs["Startup"];
  74. IConfig networkConfig = m_config.Source.Configs["Network"];
  75. int stpMaxThreads = 15;
  76. if (startupConfig != null)
  77. {
  78. m_startupCommandsFile = startupConfig.GetString("startup_console_commands_file", "startup_commands.txt");
  79. m_shutdownCommandsFile = startupConfig.GetString("shutdown_console_commands_file", "shutdown_commands.txt");
  80. if (startupConfig.GetString("console", String.Empty) == String.Empty)
  81. m_gui = startupConfig.GetBoolean("gui", false);
  82. else
  83. m_consoleType= startupConfig.GetString("console", String.Empty);
  84. if (networkConfig != null)
  85. m_consolePort = (uint)networkConfig.GetInt("console_port", 0);
  86. m_timedScript = startupConfig.GetString("timer_Script", "disabled");
  87. if (m_logFileAppender != null)
  88. {
  89. if (m_logFileAppender is log4net.Appender.FileAppender)
  90. {
  91. log4net.Appender.FileAppender appender =
  92. (log4net.Appender.FileAppender)m_logFileAppender;
  93. string fileName = startupConfig.GetString("LogFile", String.Empty);
  94. if (fileName != String.Empty)
  95. {
  96. appender.File = fileName;
  97. appender.ActivateOptions();
  98. }
  99. m_log.InfoFormat("[LOGGING]: Logging started to file {0}", appender.File);
  100. }
  101. }
  102. string asyncCallMethodStr = startupConfig.GetString("async_call_method", String.Empty);
  103. FireAndForgetMethod asyncCallMethod;
  104. if (!String.IsNullOrEmpty(asyncCallMethodStr) && Utils.EnumTryParse<FireAndForgetMethod>(asyncCallMethodStr, out asyncCallMethod))
  105. Util.FireAndForgetMethod = asyncCallMethod;
  106. stpMaxThreads = startupConfig.GetInt("MaxPoolThreads", 15);
  107. m_consolePrompt = startupConfig.GetString("ConsolePrompt", @"Region (\R) ");
  108. }
  109. if (Util.FireAndForgetMethod == FireAndForgetMethod.SmartThreadPool)
  110. Util.InitThreadPool(stpMaxThreads);
  111. m_log.Info("[OPENSIM MAIN]: Using async_call_method " + Util.FireAndForgetMethod);
  112. }
  113. /// <summary>
  114. /// Performs initialisation of the scene, such as loading configuration from disk.
  115. /// </summary>
  116. protected override void StartupSpecific()
  117. {
  118. m_log.Info("====================================================================");
  119. m_log.Info("========================= STARTING OPENSIM =========================");
  120. m_log.Info("====================================================================");
  121. //m_log.InfoFormat("[OPENSIM MAIN]: GC Is Server GC: {0}", GCSettings.IsServerGC.ToString());
  122. // http://msdn.microsoft.com/en-us/library/bb384202.aspx
  123. //GCSettings.LatencyMode = GCLatencyMode.Batch;
  124. //m_log.InfoFormat("[OPENSIM MAIN]: GC Latency Mode: {0}", GCSettings.LatencyMode.ToString());
  125. if (m_gui) // Driven by external GUI
  126. {
  127. m_console = new CommandConsole("Region");
  128. }
  129. else
  130. {
  131. switch (m_consoleType)
  132. {
  133. case "basic":
  134. m_console = new CommandConsole("Region");
  135. break;
  136. case "rest":
  137. m_console = new RemoteConsole("Region");
  138. ((RemoteConsole)m_console).ReadConfig(m_config.Source);
  139. break;
  140. default:
  141. m_console = new LocalConsole("Region");
  142. break;
  143. }
  144. }
  145. MainConsole.Instance = m_console;
  146. RegisterConsoleCommands();
  147. base.StartupSpecific();
  148. MainServer.Instance.AddStreamHandler(new OpenSim.SimStatusHandler());
  149. MainServer.Instance.AddStreamHandler(new OpenSim.XSimStatusHandler(this));
  150. if (userStatsURI != String.Empty)
  151. MainServer.Instance.AddStreamHandler(new OpenSim.UXSimStatusHandler(this));
  152. if (m_console is RemoteConsole)
  153. {
  154. if (m_consolePort == 0)
  155. {
  156. ((RemoteConsole)m_console).SetServer(m_httpServer);
  157. }
  158. else
  159. {
  160. ((RemoteConsole)m_console).SetServer(MainServer.GetHttpServer(m_consolePort));
  161. }
  162. }
  163. // Hook up to the watchdog timer
  164. Watchdog.OnWatchdogTimeout += WatchdogTimeoutHandler;
  165. PrintFileToConsole("startuplogo.txt");
  166. // For now, start at the 'root' level by default
  167. if (m_sceneManager.Scenes.Count == 1) // If there is only one region, select it
  168. ChangeSelectedRegion("region",
  169. new string[] {"change", "region", m_sceneManager.Scenes[0].RegionInfo.RegionName});
  170. else
  171. ChangeSelectedRegion("region", new string[] {"change", "region", "root"});
  172. //Run Startup Commands
  173. if (String.IsNullOrEmpty(m_startupCommandsFile))
  174. {
  175. m_log.Info("[STARTUP]: No startup command script specified. Moving on...");
  176. }
  177. else
  178. {
  179. RunCommandScript(m_startupCommandsFile);
  180. }
  181. // Start timer script (run a script every xx seconds)
  182. if (m_timedScript != "disabled")
  183. {
  184. m_scriptTimer = new Timer();
  185. m_scriptTimer.Enabled = true;
  186. m_scriptTimer.Interval = 1200*1000;
  187. m_scriptTimer.Elapsed += RunAutoTimerScript;
  188. }
  189. }
  190. /// <summary>
  191. /// Register standard set of region console commands
  192. /// </summary>
  193. private void RegisterConsoleCommands()
  194. {
  195. m_console.Commands.AddCommand("region", false, "force update",
  196. "force update",
  197. "Force the update of all objects on clients",
  198. HandleForceUpdate);
  199. m_console.Commands.AddCommand("region", false, "debug packet",
  200. "debug packet <level> [<avatar-first-name> <avatar-last-name>]",
  201. "Turn on packet debugging",
  202. "If level > 255 then all incoming and outgoing packets are logged.\n"
  203. + "If level <= 255 then incoming AgentUpdate and outgoing SimStats and SimulatorViewerTimeMessage packets are not logged.\n"
  204. + "If level <= 200 then incoming RequestImage and outgoing ImagePacket, ImageData, LayerData and CoarseLocationUpdate packets are not logged.\n"
  205. + "If level <= 100 then incoming ViewerEffect and AgentAnimation and outgoing ViewerEffect and AvatarAnimation packets are not logged.\n"
  206. + "If level <= 50 then outgoing ImprovedTerseObjectUpdate packets are not logged.\n"
  207. + "If level <= 0 then no packets are logged.\n"
  208. + "If an avatar name is given then only packets from that avatar are logged",
  209. Debug);
  210. m_console.Commands.AddCommand("region", false, "debug http",
  211. "debug http <level>",
  212. "Turn on inbound http request debugging for everything except the event queue (see debug eq).",
  213. "If level >= 2 then the handler used to service the request is logged.\n"
  214. + "If level >= 1 then incoming HTTP requests are logged.\n"
  215. + "If level <= 0 then no extra http logging is done.\n",
  216. Debug);
  217. m_console.Commands.AddCommand("region", false, "debug scene",
  218. "debug scene <cripting> <collisions> <physics>",
  219. "Turn on scene debugging", Debug);
  220. m_console.Commands.AddCommand("region", false, "change region",
  221. "change region <region name>",
  222. "Change current console region", ChangeSelectedRegion);
  223. m_console.Commands.AddCommand("region", false, "save xml",
  224. "save xml",
  225. "Save a region's data in XML format", SaveXml);
  226. m_console.Commands.AddCommand("region", false, "save xml2",
  227. "save xml2",
  228. "Save a region's data in XML2 format", SaveXml2);
  229. m_console.Commands.AddCommand("region", false, "load xml",
  230. "load xml [-newIDs [<x> <y> <z>]]",
  231. "Load a region's data from XML format", LoadXml);
  232. m_console.Commands.AddCommand("region", false, "load xml2",
  233. "load xml2",
  234. "Load a region's data from XML2 format", LoadXml2);
  235. m_console.Commands.AddCommand("region", false, "save prims xml2",
  236. "save prims xml2 [<prim name> <file name>]",
  237. "Save named prim to XML2", SavePrimsXml2);
  238. m_console.Commands.AddCommand("region", false, "load oar",
  239. "load oar [--merge] [--skip-assets] [<OAR path>]",
  240. "Load a region's data from an OAR archive.",
  241. "--merge will merge the OAR with the existing scene." + Environment.NewLine
  242. + "--skip-assets will load the OAR but ignore the assets it contains." + Environment.NewLine
  243. + "The path can be either a filesystem location or a URI."
  244. + " If this is not given then the command looks for an OAR named region.oar in the current directory.",
  245. LoadOar);
  246. m_console.Commands.AddCommand("region", false, "save oar",
  247. //"save oar [-v|--version=<N>] [-p|--profile=<url>] [<OAR path>]",
  248. "save oar [-p|--profile=<url>] [--noassets] [--perm=<permissions>] [<OAR path>]",
  249. "Save a region's data to an OAR archive.",
  250. // "-v|--version=<N> generates scene objects as per older versions of the serialization (e.g. -v=0)" + Environment.NewLine
  251. "-p|--profile=<url> adds the url of the profile service to the saved user information." + Environment.NewLine
  252. + "--noassets stops assets being saved to the OAR." + Environment.NewLine
  253. + "--perm stops objects with insufficient permissions from being saved to the OAR." + Environment.NewLine
  254. + " <permissions> can contain one or more of these characters: \"C\" = Copy, \"T\" = Transfer" + Environment.NewLine
  255. + "The OAR path must be a filesystem path."
  256. + " If this is not given then the oar is saved to region.oar in the current directory.",
  257. SaveOar);
  258. m_console.Commands.AddCommand("region", false, "edit scale",
  259. "edit scale <name> <x> <y> <z>",
  260. "Change the scale of a named prim", HandleEditScale);
  261. m_console.Commands.AddCommand("region", false, "kick user",
  262. "kick user <first> <last> [message]",
  263. "Kick a user off the simulator", KickUserCommand);
  264. m_console.Commands.AddCommand("region", false, "show users",
  265. "show users [full]",
  266. "Show user data for users currently on the region",
  267. "Without the 'full' option, only users actually on the region are shown."
  268. + " With the 'full' option child agents of users in neighbouring regions are also shown.",
  269. HandleShow);
  270. m_console.Commands.AddCommand("region", false, "show connections",
  271. "show connections",
  272. "Show connection data", HandleShow);
  273. m_console.Commands.AddCommand("region", false, "show circuits",
  274. "show circuits",
  275. "Show agent circuit data", HandleShow);
  276. m_console.Commands.AddCommand("region", false, "show http-handlers",
  277. "show http-handlers",
  278. "Show all registered http handlers", HandleShow);
  279. m_console.Commands.AddCommand("region", false, "show pending-objects",
  280. "show pending-objects",
  281. "Show # of objects on the pending queues of all scene viewers", HandleShow);
  282. m_console.Commands.AddCommand("region", false, "show modules",
  283. "show modules",
  284. "Show module data", HandleShow);
  285. m_console.Commands.AddCommand("region", false, "show regions",
  286. "show regions",
  287. "Show region data", HandleShow);
  288. m_console.Commands.AddCommand("region", false, "show ratings",
  289. "show ratings",
  290. "Show rating data", HandleShow);
  291. m_console.Commands.AddCommand("region", false, "backup",
  292. "backup",
  293. "Persist currently unsaved object changes immediately instead of waiting for the normal persistence call.", RunCommand);
  294. m_console.Commands.AddCommand("region", false, "create region",
  295. "create region [\"region name\"] <region_file.ini>",
  296. "Create a new region.",
  297. "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."
  298. + " If \"region name\" does not exist in <region_file.ini>, it will be added." + Environment.NewLine
  299. + "Without \"region name\", the first region found in <region_file.ini> will be created." + Environment.NewLine
  300. + "If <region_file.ini> does not exist, it will be created.",
  301. HandleCreateRegion);
  302. m_console.Commands.AddCommand("region", false, "restart",
  303. "restart",
  304. "Restart all sims in this instance", RunCommand);
  305. m_console.Commands.AddCommand("region", false, "config set",
  306. "config set <section> <key> <value>",
  307. "Set a config option. In most cases this is not useful since changed parameters are not dynamically reloaded. Neither do changed parameters persist - you will have to change a config file manually and restart.", HandleConfig);
  308. m_console.Commands.AddCommand("region", false, "config get",
  309. "config get [<section>] [<key>]",
  310. "Synonym for config show",
  311. HandleConfig);
  312. m_console.Commands.AddCommand("region", false, "config show",
  313. "config show [<section>] [<key>]",
  314. "Show config information",
  315. "If neither section nor field are specified, then the whole current configuration is printed." + Environment.NewLine
  316. + "If a section is given but not a field, then all fields in that section are printed.",
  317. HandleConfig);
  318. m_console.Commands.AddCommand("region", false, "config save",
  319. "config save <path>",
  320. "Save current configuration to a file at the given path", HandleConfig);
  321. m_console.Commands.AddCommand("region", false, "command-script",
  322. "command-script <script>",
  323. "Run a command script from file", RunCommand);
  324. m_console.Commands.AddCommand("region", false, "remove-region",
  325. "remove-region <name>",
  326. "Remove a region from this simulator", RunCommand);
  327. m_console.Commands.AddCommand("region", false, "delete-region",
  328. "delete-region <name>",
  329. "Delete a region from disk", RunCommand);
  330. m_console.Commands.AddCommand("region", false, "modules list",
  331. "modules list",
  332. "List modules", HandleModules);
  333. m_console.Commands.AddCommand("region", false, "modules load",
  334. "modules load <name>",
  335. "Load a module", HandleModules);
  336. m_console.Commands.AddCommand("region", false, "modules unload",
  337. "modules unload <name>",
  338. "Unload a module", HandleModules);
  339. m_console.Commands.AddCommand("region", false, "Add-InventoryHost",
  340. "Add-InventoryHost <host>",
  341. String.Empty, RunCommand);
  342. m_console.Commands.AddCommand("region", false, "kill uuid",
  343. "kill uuid <UUID>",
  344. "Kill an object by UUID", KillUUID);
  345. }
  346. public override void ShutdownSpecific()
  347. {
  348. if (m_shutdownCommandsFile != String.Empty)
  349. {
  350. RunCommandScript(m_shutdownCommandsFile);
  351. }
  352. base.ShutdownSpecific();
  353. }
  354. /// <summary>
  355. /// Timer to run a specific text file as console commands. Configured in in the main ini file
  356. /// </summary>
  357. /// <param name="sender"></param>
  358. /// <param name="e"></param>
  359. private void RunAutoTimerScript(object sender, EventArgs e)
  360. {
  361. if (m_timedScript != "disabled")
  362. {
  363. RunCommandScript(m_timedScript);
  364. }
  365. }
  366. private void WatchdogTimeoutHandler(System.Threading.Thread thread, int lastTick)
  367. {
  368. int now = Environment.TickCount & Int32.MaxValue;
  369. m_log.ErrorFormat("[WATCHDOG]: Timeout detected for thread \"{0}\". ThreadState={1}. Last tick was {2}ms ago",
  370. thread.Name, thread.ThreadState, now - lastTick);
  371. }
  372. #region Console Commands
  373. /// <summary>
  374. /// Kicks users off the region
  375. /// </summary>
  376. /// <param name="module"></param>
  377. /// <param name="cmdparams">name of avatar to kick</param>
  378. private void KickUserCommand(string module, string[] cmdparams)
  379. {
  380. if (cmdparams.Length < 4)
  381. return;
  382. string alert = null;
  383. if (cmdparams.Length > 4)
  384. alert = String.Format("\n{0}\n", String.Join(" ", cmdparams, 4, cmdparams.Length - 4));
  385. IList agents = m_sceneManager.GetCurrentSceneAvatars();
  386. foreach (ScenePresence presence in agents)
  387. {
  388. RegionInfo regionInfo = presence.Scene.RegionInfo;
  389. if (presence.Firstname.ToLower().Contains(cmdparams[2].ToLower()) &&
  390. presence.Lastname.ToLower().Contains(cmdparams[3].ToLower()))
  391. {
  392. MainConsole.Instance.Output(
  393. String.Format(
  394. "Kicking user: {0,-16} {1,-16} {2,-37} in region: {3,-16}",
  395. presence.Firstname, presence.Lastname, presence.UUID, regionInfo.RegionName));
  396. // kick client...
  397. if (alert != null)
  398. presence.ControllingClient.Kick(alert);
  399. else
  400. presence.ControllingClient.Kick("\nThe OpenSim manager kicked you out.\n");
  401. // ...and close on our side
  402. presence.Scene.IncomingCloseAgent(presence.UUID);
  403. }
  404. }
  405. MainConsole.Instance.Output("");
  406. }
  407. /// <summary>
  408. /// Run an optional startup list of commands
  409. /// </summary>
  410. /// <param name="fileName"></param>
  411. private void RunCommandScript(string fileName)
  412. {
  413. if (File.Exists(fileName))
  414. {
  415. m_log.Info("[COMMANDFILE]: Running " + fileName);
  416. using (StreamReader readFile = File.OpenText(fileName))
  417. {
  418. string currentCommand;
  419. while ((currentCommand = readFile.ReadLine()) != null)
  420. {
  421. if (currentCommand != String.Empty)
  422. {
  423. m_log.Info("[COMMANDFILE]: Running '" + currentCommand + "'");
  424. m_console.RunCommand(currentCommand);
  425. }
  426. }
  427. }
  428. }
  429. }
  430. /// <summary>
  431. /// Opens a file and uses it as input to the console command parser.
  432. /// </summary>
  433. /// <param name="fileName">name of file to use as input to the console</param>
  434. private static void PrintFileToConsole(string fileName)
  435. {
  436. if (File.Exists(fileName))
  437. {
  438. StreamReader readFile = File.OpenText(fileName);
  439. string currentLine;
  440. while ((currentLine = readFile.ReadLine()) != null)
  441. {
  442. m_log.Info("[!]" + currentLine);
  443. }
  444. }
  445. }
  446. /// <summary>
  447. /// Force resending of all updates to all clients in active region(s)
  448. /// </summary>
  449. /// <param name="module"></param>
  450. /// <param name="args"></param>
  451. private void HandleForceUpdate(string module, string[] args)
  452. {
  453. MainConsole.Instance.Output("Updating all clients");
  454. m_sceneManager.ForceCurrentSceneClientUpdate();
  455. }
  456. /// <summary>
  457. /// Edits the scale of a primative with the name specified
  458. /// </summary>
  459. /// <param name="module"></param>
  460. /// <param name="args">0,1, name, x, y, z</param>
  461. private void HandleEditScale(string module, string[] args)
  462. {
  463. if (args.Length == 6)
  464. {
  465. m_sceneManager.HandleEditCommandOnCurrentScene(args);
  466. }
  467. else
  468. {
  469. MainConsole.Instance.Output("Argument error: edit scale <prim name> <x> <y> <z>");
  470. }
  471. }
  472. /// <summary>
  473. /// Creates a new region based on the parameters specified. This will ask the user questions on the console
  474. /// </summary>
  475. /// <param name="module"></param>
  476. /// <param name="cmd">0,1,region name, region ini or XML file</param>
  477. private void HandleCreateRegion(string module, string[] cmd)
  478. {
  479. string regionName = string.Empty;
  480. string regionFile = string.Empty;
  481. if (cmd.Length == 3)
  482. {
  483. regionFile = cmd[2];
  484. }
  485. else if (cmd.Length > 3)
  486. {
  487. regionName = cmd[2];
  488. regionFile = cmd[3];
  489. }
  490. string extension = Path.GetExtension(regionFile).ToLower();
  491. bool isXml = extension.Equals(".xml");
  492. bool isIni = extension.Equals(".ini");
  493. if (!isXml && !isIni)
  494. {
  495. MainConsole.Instance.Output("Usage: create region [\"region name\"] <region_file.ini>");
  496. return;
  497. }
  498. if (!Path.IsPathRooted(regionFile))
  499. {
  500. string regionsDir = ConfigSource.Source.Configs["Startup"].GetString("regionload_regionsdir", "Regions").Trim();
  501. regionFile = Path.Combine(regionsDir, regionFile);
  502. }
  503. RegionInfo regInfo;
  504. if (isXml)
  505. {
  506. regInfo = new RegionInfo(regionName, regionFile, false, ConfigSource.Source);
  507. }
  508. else
  509. {
  510. regInfo = new RegionInfo(regionName, regionFile, false, ConfigSource.Source, regionName);
  511. }
  512. Scene existingScene;
  513. if (SceneManager.TryGetScene(regInfo.RegionID, out existingScene))
  514. {
  515. MainConsole.Instance.OutputFormat(
  516. "ERROR: Cannot create region {0} with ID {1}, this ID is already assigned to region {2}",
  517. regInfo.RegionName, regInfo.RegionID, existingScene.RegionInfo.RegionName);
  518. return;
  519. }
  520. PopulateRegionEstateInfo(regInfo);
  521. IScene scene;
  522. CreateRegion(regInfo, true, out scene);
  523. regInfo.EstateSettings.Save();
  524. }
  525. /// <summary>
  526. /// Change and load configuration file data.
  527. /// </summary>
  528. /// <param name="module"></param>
  529. /// <param name="cmd"></param>
  530. private void HandleConfig(string module, string[] cmd)
  531. {
  532. List<string> args = new List<string>(cmd);
  533. args.RemoveAt(0);
  534. string[] cmdparams = args.ToArray();
  535. if (cmdparams.Length > 0)
  536. {
  537. string firstParam = cmdparams[0].ToLower();
  538. switch (firstParam)
  539. {
  540. case "set":
  541. if (cmdparams.Length < 4)
  542. {
  543. Notice("Syntax: config set <section> <key> <value>");
  544. Notice("Example: config set ScriptEngine.DotNetEngine NumberOfScriptThreads 5");
  545. }
  546. else
  547. {
  548. IConfig c;
  549. IConfigSource source = new IniConfigSource();
  550. c = source.AddConfig(cmdparams[1]);
  551. if (c != null)
  552. {
  553. string _value = String.Join(" ", cmdparams, 3, cmdparams.Length - 3);
  554. c.Set(cmdparams[2], _value);
  555. m_config.Source.Merge(source);
  556. Notice("In section [{0}], set {1} = {2}", c.Name, cmdparams[2], _value);
  557. }
  558. }
  559. break;
  560. case "get":
  561. case "show":
  562. if (cmdparams.Length == 1)
  563. {
  564. foreach (IConfig config in m_config.Source.Configs)
  565. {
  566. Notice("[{0}]", config.Name);
  567. string[] keys = config.GetKeys();
  568. foreach (string key in keys)
  569. Notice(" {0} = {1}", key, config.GetString(key));
  570. }
  571. }
  572. else if (cmdparams.Length == 2 || cmdparams.Length == 3)
  573. {
  574. IConfig config = m_config.Source.Configs[cmdparams[1]];
  575. if (config == null)
  576. {
  577. Notice("Section \"{0}\" does not exist.",cmdparams[1]);
  578. break;
  579. }
  580. else
  581. {
  582. if (cmdparams.Length == 2)
  583. {
  584. Notice("[{0}]", config.Name);
  585. foreach (string key in config.GetKeys())
  586. Notice(" {0} = {1}", key, config.GetString(key));
  587. }
  588. else
  589. {
  590. Notice(
  591. "config get {0} {1} : {2}",
  592. cmdparams[1], cmdparams[2], config.GetString(cmdparams[2]));
  593. }
  594. }
  595. }
  596. else
  597. {
  598. Notice("Syntax: config {0} [<section>] [<key>]", firstParam);
  599. Notice("Example: config {0} ScriptEngine.DotNetEngine NumberOfScriptThreads", firstParam);
  600. }
  601. break;
  602. case "save":
  603. if (cmdparams.Length < 2)
  604. {
  605. Notice("Syntax: config save <path>");
  606. return;
  607. }
  608. if (Application.iniFilePath == cmdparams[1])
  609. {
  610. Notice("Path can not be " + Application.iniFilePath);
  611. return;
  612. }
  613. Notice("Saving configuration file: " + cmdparams[1]);
  614. m_config.Save(cmdparams[1]);
  615. break;
  616. }
  617. }
  618. }
  619. /// <summary>
  620. /// Load, Unload, and list Region modules in use
  621. /// </summary>
  622. /// <param name="module"></param>
  623. /// <param name="cmd"></param>
  624. private void HandleModules(string module, string[] cmd)
  625. {
  626. List<string> args = new List<string>(cmd);
  627. args.RemoveAt(0);
  628. string[] cmdparams = args.ToArray();
  629. if (cmdparams.Length > 0)
  630. {
  631. switch (cmdparams[0].ToLower())
  632. {
  633. case "list":
  634. foreach (IRegionModule irm in m_moduleLoader.GetLoadedSharedModules)
  635. {
  636. MainConsole.Instance.Output(String.Format("Shared region module: {0}", irm.Name));
  637. }
  638. break;
  639. case "unload":
  640. if (cmdparams.Length > 1)
  641. {
  642. foreach (IRegionModule rm in new ArrayList(m_moduleLoader.GetLoadedSharedModules))
  643. {
  644. if (rm.Name.ToLower() == cmdparams[1].ToLower())
  645. {
  646. MainConsole.Instance.Output(String.Format("Unloading module: {0}", rm.Name));
  647. m_moduleLoader.UnloadModule(rm);
  648. }
  649. }
  650. }
  651. break;
  652. case "load":
  653. if (cmdparams.Length > 1)
  654. {
  655. foreach (Scene s in new ArrayList(m_sceneManager.Scenes))
  656. {
  657. MainConsole.Instance.Output(String.Format("Loading module: {0}", cmdparams[1]));
  658. m_moduleLoader.LoadRegionModules(cmdparams[1], s);
  659. }
  660. }
  661. break;
  662. }
  663. }
  664. }
  665. /// <summary>
  666. /// Runs commands issued by the server console from the operator
  667. /// </summary>
  668. /// <param name="command">The first argument of the parameter (the command)</param>
  669. /// <param name="cmdparams">Additional arguments passed to the command</param>
  670. public void RunCommand(string module, string[] cmdparams)
  671. {
  672. List<string> args = new List<string>(cmdparams);
  673. if (args.Count < 1)
  674. return;
  675. string command = args[0];
  676. args.RemoveAt(0);
  677. cmdparams = args.ToArray();
  678. switch (command)
  679. {
  680. case "command-script":
  681. if (cmdparams.Length > 0)
  682. {
  683. RunCommandScript(cmdparams[0]);
  684. }
  685. break;
  686. case "backup":
  687. MainConsole.Instance.Output("Triggering save of pending object updates to persistent store");
  688. m_sceneManager.BackupCurrentScene();
  689. break;
  690. case "remove-region":
  691. string regRemoveName = CombineParams(cmdparams, 0);
  692. Scene removeScene;
  693. if (m_sceneManager.TryGetScene(regRemoveName, out removeScene))
  694. RemoveRegion(removeScene, false);
  695. else
  696. MainConsole.Instance.Output("No region with that name");
  697. break;
  698. case "delete-region":
  699. string regDeleteName = CombineParams(cmdparams, 0);
  700. Scene killScene;
  701. if (m_sceneManager.TryGetScene(regDeleteName, out killScene))
  702. RemoveRegion(killScene, true);
  703. else
  704. MainConsole.Instance.Output("no region with that name");
  705. break;
  706. case "restart":
  707. m_sceneManager.RestartCurrentScene();
  708. break;
  709. case "Add-InventoryHost":
  710. if (cmdparams.Length > 0)
  711. {
  712. MainConsole.Instance.Output("Not implemented.");
  713. }
  714. break;
  715. }
  716. }
  717. /// <summary>
  718. /// Change the currently selected region. The selected region is that operated upon by single region commands.
  719. /// </summary>
  720. /// <param name="cmdParams"></param>
  721. protected void ChangeSelectedRegion(string module, string[] cmdparams)
  722. {
  723. if (cmdparams.Length > 2)
  724. {
  725. string newRegionName = CombineParams(cmdparams, 2);
  726. if (!m_sceneManager.TrySetCurrentScene(newRegionName))
  727. MainConsole.Instance.Output(String.Format("Couldn't select region {0}", newRegionName));
  728. }
  729. else
  730. {
  731. MainConsole.Instance.Output("Usage: change region <region name>");
  732. }
  733. string regionName = (m_sceneManager.CurrentScene == null ? "root" : m_sceneManager.CurrentScene.RegionInfo.RegionName);
  734. MainConsole.Instance.Output(String.Format("Currently selected region is {0}", regionName));
  735. // m_log.DebugFormat("Original prompt is {0}", m_consolePrompt);
  736. string prompt = m_consolePrompt;
  737. // Replace "\R" with the region name
  738. // Replace "\\" with "\"
  739. prompt = m_consolePromptRegex.Replace(prompt, m =>
  740. {
  741. // m_log.DebugFormat("Matched {0}", m.Groups[2].Value);
  742. if (m.Groups[2].Value == "R")
  743. return m.Groups[1].Value + regionName;
  744. else
  745. return m.Groups[0].Value;
  746. });
  747. m_console.DefaultPrompt = prompt;
  748. m_console.ConsoleScene = m_sceneManager.CurrentScene;
  749. }
  750. /// <summary>
  751. /// Turn on some debugging values for OpenSim.
  752. /// </summary>
  753. /// <param name="args"></param>
  754. protected void Debug(string module, string[] args)
  755. {
  756. if (args.Length == 1)
  757. return;
  758. switch (args[1])
  759. {
  760. case "packet":
  761. string name = null;
  762. if (args.Length == 5)
  763. name = string.Format("{0} {1}", args[3], args[4]);
  764. if (args.Length > 2)
  765. {
  766. int newDebug;
  767. if (int.TryParse(args[2], out newDebug))
  768. {
  769. m_sceneManager.SetDebugPacketLevelOnCurrentScene(newDebug, name);
  770. // We provide user information elsewhere if any clients had their debug level set.
  771. // MainConsole.Instance.OutputFormat("Debug packet level set to {0}", newDebug);
  772. }
  773. else
  774. {
  775. MainConsole.Instance.Output("Usage: debug packet 0..255");
  776. }
  777. }
  778. break;
  779. case "http":
  780. if (args.Length == 3)
  781. {
  782. int newDebug;
  783. if (int.TryParse(args[2], out newDebug))
  784. {
  785. MainServer.Instance.DebugLevel = newDebug;
  786. MainConsole.Instance.OutputFormat("Debug http level set to {0}", newDebug);
  787. break;
  788. }
  789. }
  790. MainConsole.Instance.Output("Usage: debug http 0..2");
  791. break;
  792. case "scene":
  793. if (args.Length == 5)
  794. {
  795. if (m_sceneManager.CurrentScene == null)
  796. {
  797. MainConsole.Instance.Output("Please use 'change region <regioname>' first");
  798. }
  799. else
  800. {
  801. bool scriptingOn = !Convert.ToBoolean(args[2]);
  802. bool collisionsOn = !Convert.ToBoolean(args[3]);
  803. bool physicsOn = !Convert.ToBoolean(args[4]);
  804. m_sceneManager.CurrentScene.SetSceneCoreDebug(scriptingOn, collisionsOn, physicsOn);
  805. MainConsole.Instance.Output(
  806. String.Format(
  807. "Set debug scene scripting = {0}, collisions = {1}, physics = {2}",
  808. !scriptingOn, !collisionsOn, !physicsOn));
  809. }
  810. }
  811. else
  812. {
  813. MainConsole.Instance.Output("Usage: debug scene <scripting> <collisions> <physics> (where inside <> is true/false)");
  814. }
  815. break;
  816. default:
  817. MainConsole.Instance.Output("Unknown debug command");
  818. break;
  819. }
  820. }
  821. // see BaseOpenSimServer
  822. /// <summary>
  823. /// Many commands list objects for debugging. Some of the types are listed here
  824. /// </summary>
  825. /// <param name="mod"></param>
  826. /// <param name="cmd"></param>
  827. public override void HandleShow(string mod, string[] cmd)
  828. {
  829. base.HandleShow(mod, cmd);
  830. List<string> args = new List<string>(cmd);
  831. args.RemoveAt(0);
  832. string[] showParams = args.ToArray();
  833. switch (showParams[0])
  834. {
  835. case "users":
  836. IList agents;
  837. if (showParams.Length > 1 && showParams[1] == "full")
  838. {
  839. agents = m_sceneManager.GetCurrentScenePresences();
  840. }
  841. else
  842. {
  843. agents = m_sceneManager.GetCurrentSceneAvatars();
  844. }
  845. MainConsole.Instance.Output(String.Format("\nAgents connected: {0}\n", agents.Count));
  846. MainConsole.Instance.Output(
  847. String.Format("{0,-16} {1,-16} {2,-37} {3,-11} {4,-16} {5,-30}", "Firstname", "Lastname",
  848. "Agent ID", "Root/Child", "Region", "Position"));
  849. foreach (ScenePresence presence in agents)
  850. {
  851. RegionInfo regionInfo = presence.Scene.RegionInfo;
  852. string regionName;
  853. if (regionInfo == null)
  854. {
  855. regionName = "Unresolvable";
  856. }
  857. else
  858. {
  859. regionName = regionInfo.RegionName;
  860. }
  861. MainConsole.Instance.Output(
  862. String.Format(
  863. "{0,-16} {1,-16} {2,-37} {3,-11} {4,-16} {5,-30}",
  864. presence.Firstname,
  865. presence.Lastname,
  866. presence.UUID,
  867. presence.IsChildAgent ? "Child" : "Root",
  868. regionName,
  869. presence.AbsolutePosition.ToString()));
  870. }
  871. MainConsole.Instance.Output(String.Empty);
  872. break;
  873. case "connections":
  874. System.Text.StringBuilder connections = new System.Text.StringBuilder("Connections:\n");
  875. m_sceneManager.ForEachScene(
  876. delegate(Scene scene)
  877. {
  878. scene.ForEachClient(
  879. delegate(IClientAPI client)
  880. {
  881. connections.AppendFormat("{0}: {1} ({2}) from {3} on circuit {4}\n",
  882. scene.RegionInfo.RegionName, client.Name, client.AgentId, client.RemoteEndPoint, client.CircuitCode);
  883. }
  884. );
  885. }
  886. );
  887. MainConsole.Instance.Output(connections.ToString());
  888. break;
  889. case "circuits":
  890. System.Text.StringBuilder acd = new System.Text.StringBuilder("Agent Circuits:\n");
  891. m_sceneManager.ForEachScene(
  892. delegate(Scene scene)
  893. {
  894. //this.HttpServer.
  895. acd.AppendFormat("{0}:\n", scene.RegionInfo.RegionName);
  896. foreach (AgentCircuitData aCircuit in scene.AuthenticateHandler.GetAgentCircuits().Values)
  897. acd.AppendFormat("\t{0} {1} ({2})\n", aCircuit.firstname, aCircuit.lastname, (aCircuit.child ? "Child" : "Root"));
  898. }
  899. );
  900. MainConsole.Instance.Output(acd.ToString());
  901. break;
  902. case "http-handlers":
  903. System.Text.StringBuilder handlers = new System.Text.StringBuilder("Registered HTTP Handlers:\n");
  904. handlers.AppendFormat("* XMLRPC:\n");
  905. foreach (String s in HttpServer.GetXmlRpcHandlerKeys())
  906. handlers.AppendFormat("\t{0}\n", s);
  907. handlers.AppendFormat("* HTTP:\n");
  908. List<String> poll = HttpServer.GetPollServiceHandlerKeys();
  909. foreach (String s in HttpServer.GetHTTPHandlerKeys())
  910. handlers.AppendFormat("\t{0} {1}\n", s, (poll.Contains(s) ? "(poll service)" : string.Empty));
  911. handlers.AppendFormat("* Agent:\n");
  912. foreach (String s in HttpServer.GetAgentHandlerKeys())
  913. handlers.AppendFormat("\t{0}\n", s);
  914. handlers.AppendFormat("* LLSD:\n");
  915. foreach (String s in HttpServer.GetLLSDHandlerKeys())
  916. handlers.AppendFormat("\t{0}\n", s);
  917. handlers.AppendFormat("* StreamHandlers ({0}):\n", HttpServer.GetStreamHandlerKeys().Count);
  918. foreach (String s in HttpServer.GetStreamHandlerKeys())
  919. handlers.AppendFormat("\t{0}\n", s);
  920. MainConsole.Instance.Output(handlers.ToString());
  921. break;
  922. case "modules":
  923. MainConsole.Instance.Output("The currently loaded shared modules are:");
  924. foreach (IRegionModule module in m_moduleLoader.GetLoadedSharedModules)
  925. {
  926. MainConsole.Instance.Output("Shared Module: " + module.Name);
  927. }
  928. m_sceneManager.ForEachScene(
  929. delegate(Scene scene)
  930. {
  931. m_log.Error("The currently loaded modules in " + scene.RegionInfo.RegionName + " are:");
  932. foreach (IRegionModule module in scene.Modules.Values)
  933. {
  934. if (!module.IsSharedModule)
  935. {
  936. m_log.Error("Region Module: " + module.Name);
  937. }
  938. }
  939. });
  940. MainConsole.Instance.Output("");
  941. break;
  942. case "regions":
  943. m_sceneManager.ForEachScene(
  944. delegate(Scene scene)
  945. {
  946. MainConsole.Instance.Output(String.Format(
  947. "Region Name: {0}, Region XLoc: {1}, Region YLoc: {2}, Region Port: {3}, Estate Name: {4}",
  948. scene.RegionInfo.RegionName,
  949. scene.RegionInfo.RegionLocX,
  950. scene.RegionInfo.RegionLocY,
  951. scene.RegionInfo.InternalEndPoint.Port,
  952. scene.RegionInfo.EstateSettings.EstateName));
  953. });
  954. break;
  955. case "ratings":
  956. m_sceneManager.ForEachScene(
  957. delegate(Scene scene)
  958. {
  959. string rating = "";
  960. if (scene.RegionInfo.RegionSettings.Maturity == 1)
  961. {
  962. rating = "MATURE";
  963. }
  964. else if (scene.RegionInfo.RegionSettings.Maturity == 2)
  965. {
  966. rating = "ADULT";
  967. }
  968. else
  969. {
  970. rating = "PG";
  971. }
  972. MainConsole.Instance.Output(String.Format(
  973. "Region Name: {0}, Region Rating {1}",
  974. scene.RegionInfo.RegionName,
  975. rating));
  976. });
  977. break;
  978. }
  979. }
  980. /// <summary>
  981. /// Use XML2 format to serialize data to a file
  982. /// </summary>
  983. /// <param name="module"></param>
  984. /// <param name="cmdparams"></param>
  985. protected void SavePrimsXml2(string module, string[] cmdparams)
  986. {
  987. if (cmdparams.Length > 5)
  988. {
  989. m_sceneManager.SaveNamedPrimsToXml2(cmdparams[3], cmdparams[4]);
  990. }
  991. else
  992. {
  993. m_sceneManager.SaveNamedPrimsToXml2("Primitive", DEFAULT_PRIM_BACKUP_FILENAME);
  994. }
  995. }
  996. /// <summary>
  997. /// Use XML format to serialize data to a file
  998. /// </summary>
  999. /// <param name="module"></param>
  1000. /// <param name="cmdparams"></param>
  1001. protected void SaveXml(string module, string[] cmdparams)
  1002. {
  1003. 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.");
  1004. if (cmdparams.Length > 0)
  1005. {
  1006. m_sceneManager.SaveCurrentSceneToXml(cmdparams[2]);
  1007. }
  1008. else
  1009. {
  1010. m_sceneManager.SaveCurrentSceneToXml(DEFAULT_PRIM_BACKUP_FILENAME);
  1011. }
  1012. }
  1013. /// <summary>
  1014. /// Loads data and region objects from XML format.
  1015. /// </summary>
  1016. /// <param name="module"></param>
  1017. /// <param name="cmdparams"></param>
  1018. protected void LoadXml(string module, string[] cmdparams)
  1019. {
  1020. 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.");
  1021. Vector3 loadOffset = new Vector3(0, 0, 0);
  1022. if (cmdparams.Length > 2)
  1023. {
  1024. bool generateNewIDS = false;
  1025. if (cmdparams.Length > 3)
  1026. {
  1027. if (cmdparams[3] == "-newUID")
  1028. {
  1029. generateNewIDS = true;
  1030. }
  1031. if (cmdparams.Length > 4)
  1032. {
  1033. loadOffset.X = (float)Convert.ToDecimal(cmdparams[4], Culture.NumberFormatInfo);
  1034. if (cmdparams.Length > 5)
  1035. {
  1036. loadOffset.Y = (float)Convert.ToDecimal(cmdparams[5], Culture.NumberFormatInfo);
  1037. }
  1038. if (cmdparams.Length > 6)
  1039. {
  1040. loadOffset.Z = (float)Convert.ToDecimal(cmdparams[6], Culture.NumberFormatInfo);
  1041. }
  1042. MainConsole.Instance.Output(String.Format("loadOffsets <X,Y,Z> = <{0},{1},{2}>",loadOffset.X,loadOffset.Y,loadOffset.Z));
  1043. }
  1044. }
  1045. m_sceneManager.LoadCurrentSceneFromXml(cmdparams[2], generateNewIDS, loadOffset);
  1046. }
  1047. else
  1048. {
  1049. try
  1050. {
  1051. m_sceneManager.LoadCurrentSceneFromXml(DEFAULT_PRIM_BACKUP_FILENAME, false, loadOffset);
  1052. }
  1053. catch (FileNotFoundException)
  1054. {
  1055. MainConsole.Instance.Output("Default xml not found. Usage: load-xml <filename>");
  1056. }
  1057. }
  1058. }
  1059. /// <summary>
  1060. /// Serialize region data to XML2Format
  1061. /// </summary>
  1062. /// <param name="module"></param>
  1063. /// <param name="cmdparams"></param>
  1064. protected void SaveXml2(string module, string[] cmdparams)
  1065. {
  1066. if (cmdparams.Length > 2)
  1067. {
  1068. m_sceneManager.SaveCurrentSceneToXml2(cmdparams[2]);
  1069. }
  1070. else
  1071. {
  1072. m_sceneManager.SaveCurrentSceneToXml2(DEFAULT_PRIM_BACKUP_FILENAME);
  1073. }
  1074. }
  1075. /// <summary>
  1076. /// Load region data from Xml2Format
  1077. /// </summary>
  1078. /// <param name="module"></param>
  1079. /// <param name="cmdparams"></param>
  1080. protected void LoadXml2(string module, string[] cmdparams)
  1081. {
  1082. if (cmdparams.Length > 2)
  1083. {
  1084. try
  1085. {
  1086. m_sceneManager.LoadCurrentSceneFromXml2(cmdparams[2]);
  1087. }
  1088. catch (FileNotFoundException)
  1089. {
  1090. MainConsole.Instance.Output("Specified xml not found. Usage: load xml2 <filename>");
  1091. }
  1092. }
  1093. else
  1094. {
  1095. try
  1096. {
  1097. m_sceneManager.LoadCurrentSceneFromXml2(DEFAULT_PRIM_BACKUP_FILENAME);
  1098. }
  1099. catch (FileNotFoundException)
  1100. {
  1101. MainConsole.Instance.Output("Default xml not found. Usage: load xml2 <filename>");
  1102. }
  1103. }
  1104. }
  1105. /// <summary>
  1106. /// Load a whole region from an opensimulator archive.
  1107. /// </summary>
  1108. /// <param name="cmdparams"></param>
  1109. protected void LoadOar(string module, string[] cmdparams)
  1110. {
  1111. try
  1112. {
  1113. m_sceneManager.LoadArchiveToCurrentScene(cmdparams);
  1114. }
  1115. catch (Exception e)
  1116. {
  1117. MainConsole.Instance.Output(e.Message);
  1118. }
  1119. }
  1120. /// <summary>
  1121. /// Save a region to a file, including all the assets needed to restore it.
  1122. /// </summary>
  1123. /// <param name="cmdparams"></param>
  1124. protected void SaveOar(string module, string[] cmdparams)
  1125. {
  1126. m_sceneManager.SaveCurrentSceneToArchive(cmdparams);
  1127. }
  1128. private static string CombineParams(string[] commandParams, int pos)
  1129. {
  1130. string result = String.Empty;
  1131. for (int i = pos; i < commandParams.Length; i++)
  1132. {
  1133. result += commandParams[i] + " ";
  1134. }
  1135. result = result.TrimEnd(' ');
  1136. return result;
  1137. }
  1138. /// <summary>
  1139. /// Kill an object given its UUID.
  1140. /// </summary>
  1141. /// <param name="cmdparams"></param>
  1142. protected void KillUUID(string module, string[] cmdparams)
  1143. {
  1144. if (cmdparams.Length > 2)
  1145. {
  1146. UUID id = UUID.Zero;
  1147. SceneObjectGroup grp = null;
  1148. Scene sc = null;
  1149. if (!UUID.TryParse(cmdparams[2], out id))
  1150. {
  1151. MainConsole.Instance.Output("[KillUUID]: Error bad UUID format!");
  1152. return;
  1153. }
  1154. m_sceneManager.ForEachScene(
  1155. delegate(Scene scene)
  1156. {
  1157. SceneObjectPart part = scene.GetSceneObjectPart(id);
  1158. if (part == null)
  1159. return;
  1160. grp = part.ParentGroup;
  1161. sc = scene;
  1162. });
  1163. if (grp == null)
  1164. {
  1165. MainConsole.Instance.Output(String.Format("[KillUUID]: Given UUID {0} not found!", id));
  1166. }
  1167. else
  1168. {
  1169. MainConsole.Instance.Output(String.Format("[KillUUID]: Found UUID {0} in scene {1}", id, sc.RegionInfo.RegionName));
  1170. try
  1171. {
  1172. sc.DeleteSceneObject(grp, false);
  1173. }
  1174. catch (Exception e)
  1175. {
  1176. m_log.ErrorFormat("[KillUUID]: Error while removing objects from scene: " + e);
  1177. }
  1178. }
  1179. }
  1180. else
  1181. {
  1182. MainConsole.Instance.Output("[KillUUID]: Usage: kill uuid <UUID>");
  1183. }
  1184. }
  1185. #endregion
  1186. }
  1187. }