OpenSim.cs 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435
  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", 15);
  102. stpMaxThreads = startupConfig.GetInt("MaxPoolThreads", 300);
  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 all sims 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("\nThe OpenSim manager kicked you out.\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. }
  622. /// <summary>
  623. /// Runs commands issued by the server console from the operator
  624. /// </summary>
  625. /// <param name="command">The first argument of the parameter (the command)</param>
  626. /// <param name="cmdparams">Additional arguments passed to the command</param>
  627. public void RunCommand(string module, string[] cmdparams)
  628. {
  629. List<string> args = new List<string>(cmdparams);
  630. if (args.Count < 1)
  631. return;
  632. string command = args[0];
  633. args.RemoveAt(0);
  634. cmdparams = args.ToArray();
  635. switch (command)
  636. {
  637. case "backup":
  638. MainConsole.Instance.Output("Triggering save of pending object updates to persistent store");
  639. SceneManager.BackupCurrentScene();
  640. break;
  641. case "remove-region":
  642. string regRemoveName = CombineParams(cmdparams, 0);
  643. Scene removeScene;
  644. if (SceneManager.TryGetScene(regRemoveName, out removeScene))
  645. RemoveRegion(removeScene, false);
  646. else
  647. MainConsole.Instance.Output("No region with that name");
  648. break;
  649. case "delete-region":
  650. string regDeleteName = CombineParams(cmdparams, 0);
  651. Scene killScene;
  652. if (SceneManager.TryGetScene(regDeleteName, out killScene))
  653. RemoveRegion(killScene, true);
  654. else
  655. MainConsole.Instance.Output("no region with that name");
  656. break;
  657. case "restart":
  658. SceneManager.RestartCurrentScene();
  659. break;
  660. }
  661. }
  662. /// <summary>
  663. /// Change the currently selected region. The selected region is that operated upon by single region commands.
  664. /// </summary>
  665. /// <param name="cmdParams"></param>
  666. protected void ChangeSelectedRegion(string module, string[] cmdparams)
  667. {
  668. if (cmdparams.Length > 2)
  669. {
  670. string newRegionName = CombineParams(cmdparams, 2);
  671. if (!SceneManager.TrySetCurrentScene(newRegionName))
  672. MainConsole.Instance.Output(String.Format("Couldn't select region {0}", newRegionName));
  673. else
  674. RefreshPrompt();
  675. }
  676. else
  677. {
  678. MainConsole.Instance.Output("Usage: change region <region name>");
  679. }
  680. }
  681. /// <summary>
  682. /// Refreshs prompt with the current selection details.
  683. /// </summary>
  684. private void RefreshPrompt()
  685. {
  686. string regionName = (SceneManager.CurrentScene == null ? "root" : SceneManager.CurrentScene.RegionInfo.RegionName);
  687. MainConsole.Instance.Output(String.Format("Currently selected region is {0}", regionName));
  688. // m_log.DebugFormat("Original prompt is {0}", m_consolePrompt);
  689. string prompt = m_consolePrompt;
  690. // Replace "\R" with the region name
  691. // Replace "\\" with "\"
  692. prompt = m_consolePromptRegex.Replace(prompt, m =>
  693. {
  694. // m_log.DebugFormat("Matched {0}", m.Groups[2].Value);
  695. if (m.Groups[2].Value == "R")
  696. return m.Groups[1].Value + regionName;
  697. else
  698. return m.Groups[0].Value;
  699. });
  700. m_console.DefaultPrompt = prompt;
  701. m_console.ConsoleScene = SceneManager.CurrentScene;
  702. }
  703. protected override void HandleRestartRegion(RegionInfo whichRegion)
  704. {
  705. base.HandleRestartRegion(whichRegion);
  706. // Where we are restarting multiple scenes at once, a previous call to RefreshPrompt may have set the
  707. // m_console.ConsoleScene to null (indicating all scenes).
  708. if (m_console.ConsoleScene != null && whichRegion.RegionName == ((Scene)m_console.ConsoleScene).Name)
  709. SceneManager.TrySetCurrentScene(whichRegion.RegionName);
  710. RefreshPrompt();
  711. }
  712. // see BaseOpenSimServer
  713. /// <summary>
  714. /// Many commands list objects for debugging. Some of the types are listed here
  715. /// </summary>
  716. /// <param name="mod"></param>
  717. /// <param name="cmd"></param>
  718. public override void HandleShow(string mod, string[] cmd)
  719. {
  720. base.HandleShow(mod, cmd);
  721. List<string> args = new List<string>(cmd);
  722. args.RemoveAt(0);
  723. string[] showParams = args.ToArray();
  724. switch (showParams[0])
  725. {
  726. case "users":
  727. IList agents;
  728. if (showParams.Length > 1 && showParams[1] == "full")
  729. {
  730. agents = SceneManager.GetCurrentScenePresences();
  731. } else
  732. {
  733. agents = SceneManager.GetCurrentSceneAvatars();
  734. }
  735. MainConsole.Instance.Output(String.Format("\nAgents connected: {0}\n", agents.Count));
  736. MainConsole.Instance.Output(
  737. String.Format("{0,-16} {1,-16} {2,-37} {3,-11} {4,-16} {5,-30}", "Firstname", "Lastname",
  738. "Agent ID", "Root/Child", "Region", "Position")
  739. );
  740. foreach (ScenePresence presence in agents)
  741. {
  742. RegionInfo regionInfo = presence.Scene.RegionInfo;
  743. string regionName;
  744. if (regionInfo == null)
  745. {
  746. regionName = "Unresolvable";
  747. } else
  748. {
  749. regionName = regionInfo.RegionName;
  750. }
  751. MainConsole.Instance.Output(
  752. String.Format(
  753. "{0,-16} {1,-16} {2,-37} {3,-11} {4,-16} {5,-30}",
  754. presence.Firstname,
  755. presence.Lastname,
  756. presence.UUID,
  757. presence.IsChildAgent ? "Child" : "Root",
  758. regionName,
  759. presence.AbsolutePosition.ToString())
  760. );
  761. }
  762. MainConsole.Instance.Output(String.Empty);
  763. break;
  764. case "connections":
  765. HandleShowConnections();
  766. break;
  767. case "circuits":
  768. HandleShowCircuits();
  769. break;
  770. case "modules":
  771. SceneManager.ForEachSelectedScene(
  772. scene =>
  773. {
  774. MainConsole.Instance.OutputFormat("Loaded region modules in {0} are:", scene.Name);
  775. List<IRegionModuleBase> sharedModules = new List<IRegionModuleBase>();
  776. List<IRegionModuleBase> nonSharedModules = new List<IRegionModuleBase>();
  777. foreach (IRegionModuleBase module in scene.RegionModules.Values)
  778. {
  779. if (module.GetType().GetInterface("ISharedRegionModule") == null)
  780. nonSharedModules.Add(module);
  781. else
  782. sharedModules.Add(module);
  783. }
  784. foreach (IRegionModuleBase module in sharedModules.OrderBy(m => m.Name))
  785. MainConsole.Instance.OutputFormat("New Region Module (Shared): {0}", module.Name);
  786. foreach (IRegionModuleBase module in nonSharedModules.OrderBy(m => m.Name))
  787. MainConsole.Instance.OutputFormat("New Region Module (Non-Shared): {0}", module.Name);
  788. }
  789. );
  790. MainConsole.Instance.Output("");
  791. break;
  792. case "regions":
  793. ConsoleDisplayTable cdt = new ConsoleDisplayTable();
  794. cdt.AddColumn("Name", ConsoleDisplayUtil.RegionNameSize);
  795. cdt.AddColumn("ID", ConsoleDisplayUtil.UuidSize);
  796. cdt.AddColumn("Position", ConsoleDisplayUtil.CoordTupleSize);
  797. cdt.AddColumn("Size", 11);
  798. cdt.AddColumn("Port", ConsoleDisplayUtil.PortSize);
  799. cdt.AddColumn("Ready?", 6);
  800. cdt.AddColumn("Estate", ConsoleDisplayUtil.EstateNameSize);
  801. SceneManager.ForEachScene(
  802. scene =>
  803. {
  804. RegionInfo ri = scene.RegionInfo;
  805. cdt.AddRow(
  806. ri.RegionName,
  807. ri.RegionID,
  808. string.Format("{0},{1}", ri.RegionLocX, ri.RegionLocY),
  809. string.Format("{0}x{1}", ri.RegionSizeX, ri.RegionSizeY),
  810. ri.InternalEndPoint.Port,
  811. scene.Ready ? "Yes" : "No",
  812. ri.EstateSettings.EstateName);
  813. }
  814. );
  815. MainConsole.Instance.Output(cdt.ToString());
  816. break;
  817. case "ratings":
  818. SceneManager.ForEachScene(
  819. delegate(Scene scene)
  820. {
  821. string rating = "";
  822. if (scene.RegionInfo.RegionSettings.Maturity == 1)
  823. {
  824. rating = "MATURE";
  825. }
  826. else if (scene.RegionInfo.RegionSettings.Maturity == 2)
  827. {
  828. rating = "ADULT";
  829. }
  830. else
  831. {
  832. rating = "PG";
  833. }
  834. MainConsole.Instance.Output(String.Format(
  835. "Region Name: {0}, Region Rating {1}",
  836. scene.RegionInfo.RegionName,
  837. rating));
  838. });
  839. break;
  840. }
  841. }
  842. private void HandleShowCircuits()
  843. {
  844. ConsoleDisplayTable cdt = new ConsoleDisplayTable();
  845. cdt.AddColumn("Region", 20);
  846. cdt.AddColumn("Avatar name", 24);
  847. cdt.AddColumn("Type", 5);
  848. cdt.AddColumn("Code", 10);
  849. cdt.AddColumn("IP", 16);
  850. cdt.AddColumn("Viewer Name", 24);
  851. SceneManager.ForEachScene(
  852. s =>
  853. {
  854. foreach (AgentCircuitData aCircuit in s.AuthenticateHandler.GetAgentCircuits().Values)
  855. cdt.AddRow(
  856. s.Name,
  857. aCircuit.Name,
  858. aCircuit.child ? "child" : "root",
  859. aCircuit.circuitcode.ToString(),
  860. aCircuit.IPAddress != null ? aCircuit.IPAddress.ToString() : "not set",
  861. Util.GetViewerName(aCircuit));
  862. });
  863. MainConsole.Instance.Output(cdt.ToString());
  864. }
  865. private void HandleShowConnections()
  866. {
  867. ConsoleDisplayTable cdt = new ConsoleDisplayTable();
  868. cdt.AddColumn("Region", 20);
  869. cdt.AddColumn("Avatar name", 24);
  870. cdt.AddColumn("Circuit code", 12);
  871. cdt.AddColumn("Endpoint", 23);
  872. cdt.AddColumn("Active?", 7);
  873. SceneManager.ForEachScene(
  874. s => s.ForEachClient(
  875. c => cdt.AddRow(
  876. s.Name,
  877. c.Name,
  878. c.CircuitCode.ToString(),
  879. c.RemoteEndPoint.ToString(),
  880. c.IsActive.ToString())));
  881. MainConsole.Instance.Output(cdt.ToString());
  882. }
  883. /// <summary>
  884. /// Use XML2 format to serialize data to a file
  885. /// </summary>
  886. /// <param name="module"></param>
  887. /// <param name="cmdparams"></param>
  888. protected void SavePrimsXml2(string module, string[] cmdparams)
  889. {
  890. if (cmdparams.Length > 5)
  891. {
  892. SceneManager.SaveNamedPrimsToXml2(cmdparams[3], cmdparams[4]);
  893. }
  894. else
  895. {
  896. SceneManager.SaveNamedPrimsToXml2("Primitive", DEFAULT_PRIM_BACKUP_FILENAME);
  897. }
  898. }
  899. /// <summary>
  900. /// Use XML format to serialize data to a file
  901. /// </summary>
  902. /// <param name="module"></param>
  903. /// <param name="cmdparams"></param>
  904. protected void SaveXml(string module, string[] cmdparams)
  905. {
  906. 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.");
  907. if (cmdparams.Length > 0)
  908. {
  909. SceneManager.SaveCurrentSceneToXml(cmdparams[2]);
  910. }
  911. else
  912. {
  913. SceneManager.SaveCurrentSceneToXml(DEFAULT_PRIM_BACKUP_FILENAME);
  914. }
  915. }
  916. /// <summary>
  917. /// Loads data and region objects from XML format.
  918. /// </summary>
  919. /// <param name="module"></param>
  920. /// <param name="cmdparams"></param>
  921. protected void LoadXml(string module, string[] cmdparams)
  922. {
  923. 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.");
  924. Vector3 loadOffset = new Vector3(0, 0, 0);
  925. if (cmdparams.Length > 2)
  926. {
  927. bool generateNewIDS = false;
  928. if (cmdparams.Length > 3)
  929. {
  930. if (cmdparams[3] == "-newUID")
  931. {
  932. generateNewIDS = true;
  933. }
  934. if (cmdparams.Length > 4)
  935. {
  936. loadOffset.X = (float)Convert.ToDecimal(cmdparams[4], Culture.NumberFormatInfo);
  937. if (cmdparams.Length > 5)
  938. {
  939. loadOffset.Y = (float)Convert.ToDecimal(cmdparams[5], Culture.NumberFormatInfo);
  940. }
  941. if (cmdparams.Length > 6)
  942. {
  943. loadOffset.Z = (float)Convert.ToDecimal(cmdparams[6], Culture.NumberFormatInfo);
  944. }
  945. MainConsole.Instance.Output(String.Format("loadOffsets <X,Y,Z> = <{0},{1},{2}>",loadOffset.X,loadOffset.Y,loadOffset.Z));
  946. }
  947. }
  948. SceneManager.LoadCurrentSceneFromXml(cmdparams[2], generateNewIDS, loadOffset);
  949. }
  950. else
  951. {
  952. try
  953. {
  954. SceneManager.LoadCurrentSceneFromXml(DEFAULT_PRIM_BACKUP_FILENAME, false, loadOffset);
  955. }
  956. catch (FileNotFoundException)
  957. {
  958. MainConsole.Instance.Output("Default xml not found. Usage: load-xml <filename>");
  959. }
  960. }
  961. }
  962. /// <summary>
  963. /// Serialize region data to XML2Format
  964. /// </summary>
  965. /// <param name="module"></param>
  966. /// <param name="cmdparams"></param>
  967. protected void SaveXml2(string module, string[] cmdparams)
  968. {
  969. if (cmdparams.Length > 2)
  970. {
  971. SceneManager.SaveCurrentSceneToXml2(cmdparams[2]);
  972. }
  973. else
  974. {
  975. SceneManager.SaveCurrentSceneToXml2(DEFAULT_PRIM_BACKUP_FILENAME);
  976. }
  977. }
  978. /// <summary>
  979. /// Load region data from Xml2Format
  980. /// </summary>
  981. /// <param name="module"></param>
  982. /// <param name="cmdparams"></param>
  983. protected void LoadXml2(string module, string[] cmdparams)
  984. {
  985. if (cmdparams.Length > 2)
  986. {
  987. try
  988. {
  989. SceneManager.LoadCurrentSceneFromXml2(cmdparams[2]);
  990. }
  991. catch (FileNotFoundException)
  992. {
  993. MainConsole.Instance.Output("Specified xml not found. Usage: load xml2 <filename>");
  994. }
  995. }
  996. else
  997. {
  998. try
  999. {
  1000. SceneManager.LoadCurrentSceneFromXml2(DEFAULT_PRIM_BACKUP_FILENAME);
  1001. }
  1002. catch (FileNotFoundException)
  1003. {
  1004. MainConsole.Instance.Output("Default xml not found. Usage: load xml2 <filename>");
  1005. }
  1006. }
  1007. }
  1008. /// <summary>
  1009. /// Load a whole region from an opensimulator archive.
  1010. /// </summary>
  1011. /// <param name="cmdparams"></param>
  1012. protected void LoadOar(string module, string[] cmdparams)
  1013. {
  1014. try
  1015. {
  1016. SceneManager.LoadArchiveToCurrentScene(cmdparams);
  1017. }
  1018. catch (Exception e)
  1019. {
  1020. MainConsole.Instance.Output(e.Message);
  1021. }
  1022. }
  1023. /// <summary>
  1024. /// Save a region to a file, including all the assets needed to restore it.
  1025. /// </summary>
  1026. /// <param name="cmdparams"></param>
  1027. protected void SaveOar(string module, string[] cmdparams)
  1028. {
  1029. SceneManager.SaveCurrentSceneToArchive(cmdparams);
  1030. }
  1031. protected void CreateEstateCommand(string module, string[] args)
  1032. {
  1033. string response = null;
  1034. UUID userID;
  1035. if (args.Length == 2)
  1036. {
  1037. response = "No user specified.";
  1038. }
  1039. else if (!UUID.TryParse(args[2], out userID))
  1040. {
  1041. response = String.Format("{0} is not a valid UUID", args[2]);
  1042. }
  1043. else if (args.Length == 3)
  1044. {
  1045. response = "No estate name specified.";
  1046. }
  1047. else
  1048. {
  1049. Scene scene = SceneManager.CurrentOrFirstScene;
  1050. // TODO: Is there a better choice here?
  1051. UUID scopeID = UUID.Zero;
  1052. UserAccount account = scene.UserAccountService.GetUserAccount(scopeID, userID);
  1053. if (account == null)
  1054. {
  1055. response = String.Format("Could not find user {0}", userID);
  1056. }
  1057. else
  1058. {
  1059. // concatenate it all to "name"
  1060. StringBuilder sb = new StringBuilder(args[3]);
  1061. for (int i = 4; i < args.Length; i++)
  1062. sb.Append (" " + args[i]);
  1063. string estateName = sb.ToString().Trim();
  1064. // send it off for processing.
  1065. IEstateModule estateModule = scene.RequestModuleInterface<IEstateModule>();
  1066. response = estateModule.CreateEstate(estateName, userID);
  1067. if (response == String.Empty)
  1068. {
  1069. List<int> estates = scene.EstateDataService.GetEstates(estateName);
  1070. response = String.Format("Estate {0} created as \"{1}\"", estates.ElementAt(0), estateName);
  1071. }
  1072. }
  1073. }
  1074. // give the user some feedback
  1075. if (response != null)
  1076. MainConsole.Instance.Output(response);
  1077. }
  1078. protected void SetEstateOwnerCommand(string module, string[] args)
  1079. {
  1080. string response = null;
  1081. Scene scene = SceneManager.CurrentOrFirstScene;
  1082. IEstateModule estateModule = scene.RequestModuleInterface<IEstateModule>();
  1083. if (args.Length == 3)
  1084. {
  1085. response = "No estate specified.";
  1086. }
  1087. else
  1088. {
  1089. int estateId;
  1090. if (!int.TryParse(args[3], out estateId))
  1091. {
  1092. response = String.Format("\"{0}\" is not a valid ID for an Estate", args[3]);
  1093. }
  1094. else
  1095. {
  1096. if (args.Length == 4)
  1097. {
  1098. response = "No user specified.";
  1099. }
  1100. else
  1101. {
  1102. UserAccount account = null;
  1103. // TODO: Is there a better choice here?
  1104. UUID scopeID = UUID.Zero;
  1105. string s1 = args[4];
  1106. if (args.Length == 5)
  1107. {
  1108. // attempt to get account by UUID
  1109. UUID u;
  1110. if (UUID.TryParse(s1, out u))
  1111. {
  1112. account = scene.UserAccountService.GetUserAccount(scopeID, u);
  1113. if (account == null)
  1114. response = String.Format("Could not find user {0}", s1);
  1115. }
  1116. else
  1117. {
  1118. response = String.Format("Invalid UUID {0}", s1);
  1119. }
  1120. }
  1121. else
  1122. {
  1123. // attempt to get account by Firstname, Lastname
  1124. string s2 = args[5];
  1125. account = scene.UserAccountService.GetUserAccount(scopeID, s1, s2);
  1126. if (account == null)
  1127. response = String.Format("Could not find user {0} {1}", s1, s2);
  1128. }
  1129. // If it's valid, send it off for processing.
  1130. if (account != null)
  1131. response = estateModule.SetEstateOwner(estateId, account);
  1132. if (response == String.Empty)
  1133. {
  1134. response = String.Format("Estate owner changed to {0} ({1} {2})", account.PrincipalID, account.FirstName, account.LastName);
  1135. }
  1136. }
  1137. }
  1138. }
  1139. // give the user some feedback
  1140. if (response != null)
  1141. MainConsole.Instance.Output(response);
  1142. }
  1143. protected void SetEstateNameCommand(string module, string[] args)
  1144. {
  1145. string response = null;
  1146. Scene scene = SceneManager.CurrentOrFirstScene;
  1147. IEstateModule estateModule = scene.RequestModuleInterface<IEstateModule>();
  1148. if (args.Length == 3)
  1149. {
  1150. response = "No estate specified.";
  1151. }
  1152. else
  1153. {
  1154. int estateId;
  1155. if (!int.TryParse(args[3], out estateId))
  1156. {
  1157. response = String.Format("\"{0}\" is not a valid ID for an Estate", args[3]);
  1158. }
  1159. else
  1160. {
  1161. if (args.Length == 4)
  1162. {
  1163. response = "No name specified.";
  1164. }
  1165. else
  1166. {
  1167. // everything after the estate ID is "name"
  1168. StringBuilder sb = new StringBuilder(args[4]);
  1169. for (int i = 5; i < args.Length; i++)
  1170. sb.Append (" " + args[i]);
  1171. string estateName = sb.ToString();
  1172. // send it off for processing.
  1173. response = estateModule.SetEstateName(estateId, estateName);
  1174. if (response == String.Empty)
  1175. {
  1176. response = String.Format("Estate {0} renamed to \"{1}\"", estateId, estateName);
  1177. }
  1178. }
  1179. }
  1180. }
  1181. // give the user some feedback
  1182. if (response != null)
  1183. MainConsole.Instance.Output(response);
  1184. }
  1185. private void EstateLinkRegionCommand(string module, string[] args)
  1186. {
  1187. int estateId =-1;
  1188. UUID regionId = UUID.Zero;
  1189. Scene scene = null;
  1190. string response = null;
  1191. if (args.Length == 3)
  1192. {
  1193. response = "No estate specified.";
  1194. }
  1195. else if (!int.TryParse(args [3], out estateId))
  1196. {
  1197. response = String.Format("\"{0}\" is not a valid ID for an Estate", args [3]);
  1198. }
  1199. else if (args.Length == 4)
  1200. {
  1201. response = "No region specified.";
  1202. }
  1203. else if (!UUID.TryParse(args[4], out regionId))
  1204. {
  1205. response = String.Format("\"{0}\" is not a valid UUID for a Region", args [4]);
  1206. }
  1207. else if (!SceneManager.TryGetScene(regionId, out scene))
  1208. {
  1209. // region may exist, but on a different sim.
  1210. response = String.Format("No access to Region \"{0}\"", args [4]);
  1211. }
  1212. if (response != null)
  1213. {
  1214. MainConsole.Instance.Output(response);
  1215. return;
  1216. }
  1217. // send it off for processing.
  1218. IEstateModule estateModule = scene.RequestModuleInterface<IEstateModule>();
  1219. response = estateModule.SetRegionEstate(scene.RegionInfo, estateId);
  1220. if (response == String.Empty)
  1221. {
  1222. estateModule.TriggerRegionInfoChange();
  1223. estateModule.sendRegionHandshakeToAll();
  1224. response = String.Format ("Region {0} is now attached to estate {1}", regionId, estateId);
  1225. }
  1226. // give the user some feedback
  1227. if (response != null)
  1228. MainConsole.Instance.Output (response);
  1229. }
  1230. #endregion
  1231. private static string CombineParams(string[] commandParams, int pos)
  1232. {
  1233. string result = String.Empty;
  1234. for (int i = pos; i < commandParams.Length; i++)
  1235. {
  1236. result += commandParams[i] + " ";
  1237. }
  1238. result = result.TrimEnd(' ');
  1239. return result;
  1240. }
  1241. }
  1242. }