OpenSim.cs 59 KB

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