OpenSim.cs 57 KB

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