OpenSim.cs 61 KB

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