OpenSim.cs 58 KB

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