OpenSim.cs 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437
  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 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("\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. 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. SceneManager.ForEachScene(
  875. s => s.ForEachClient(
  876. c => cdt.AddRow(
  877. s.Name,
  878. c.Name,
  879. c.CircuitCode.ToString(),
  880. c.RemoteEndPoint.ToString(),
  881. c.IsActive.ToString())));
  882. MainConsole.Instance.Output(cdt.ToString());
  883. }
  884. /// <summary>
  885. /// Use XML2 format to serialize data to a file
  886. /// </summary>
  887. /// <param name="module"></param>
  888. /// <param name="cmdparams"></param>
  889. protected void SavePrimsXml2(string module, string[] cmdparams)
  890. {
  891. if (cmdparams.Length > 5)
  892. {
  893. SceneManager.SaveNamedPrimsToXml2(cmdparams[3], cmdparams[4]);
  894. }
  895. else
  896. {
  897. SceneManager.SaveNamedPrimsToXml2("Primitive", DEFAULT_PRIM_BACKUP_FILENAME);
  898. }
  899. }
  900. /// <summary>
  901. /// Use XML format to serialize data to a file
  902. /// </summary>
  903. /// <param name="module"></param>
  904. /// <param name="cmdparams"></param>
  905. protected void SaveXml(string module, string[] cmdparams)
  906. {
  907. 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.");
  908. if (cmdparams.Length > 0)
  909. {
  910. SceneManager.SaveCurrentSceneToXml(cmdparams[2]);
  911. }
  912. else
  913. {
  914. SceneManager.SaveCurrentSceneToXml(DEFAULT_PRIM_BACKUP_FILENAME);
  915. }
  916. }
  917. /// <summary>
  918. /// Loads data and region objects from XML format.
  919. /// </summary>
  920. /// <param name="module"></param>
  921. /// <param name="cmdparams"></param>
  922. protected void LoadXml(string module, string[] cmdparams)
  923. {
  924. 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.");
  925. Vector3 loadOffset = new Vector3(0, 0, 0);
  926. if (cmdparams.Length > 2)
  927. {
  928. bool generateNewIDS = false;
  929. if (cmdparams.Length > 3)
  930. {
  931. if (cmdparams[3] == "-newUID")
  932. {
  933. generateNewIDS = true;
  934. }
  935. if (cmdparams.Length > 4)
  936. {
  937. loadOffset.X = (float)Convert.ToDecimal(cmdparams[4], Culture.NumberFormatInfo);
  938. if (cmdparams.Length > 5)
  939. {
  940. loadOffset.Y = (float)Convert.ToDecimal(cmdparams[5], Culture.NumberFormatInfo);
  941. }
  942. if (cmdparams.Length > 6)
  943. {
  944. loadOffset.Z = (float)Convert.ToDecimal(cmdparams[6], Culture.NumberFormatInfo);
  945. }
  946. MainConsole.Instance.Output(String.Format("loadOffsets <X,Y,Z> = <{0},{1},{2}>",loadOffset.X,loadOffset.Y,loadOffset.Z));
  947. }
  948. }
  949. SceneManager.LoadCurrentSceneFromXml(cmdparams[2], generateNewIDS, loadOffset);
  950. }
  951. else
  952. {
  953. try
  954. {
  955. SceneManager.LoadCurrentSceneFromXml(DEFAULT_PRIM_BACKUP_FILENAME, false, loadOffset);
  956. }
  957. catch (FileNotFoundException)
  958. {
  959. MainConsole.Instance.Output("Default xml not found. Usage: load-xml <filename>");
  960. }
  961. }
  962. }
  963. /// <summary>
  964. /// Serialize region data to XML2Format
  965. /// </summary>
  966. /// <param name="module"></param>
  967. /// <param name="cmdparams"></param>
  968. protected void SaveXml2(string module, string[] cmdparams)
  969. {
  970. if (cmdparams.Length > 2)
  971. {
  972. SceneManager.SaveCurrentSceneToXml2(cmdparams[2]);
  973. }
  974. else
  975. {
  976. SceneManager.SaveCurrentSceneToXml2(DEFAULT_PRIM_BACKUP_FILENAME);
  977. }
  978. }
  979. /// <summary>
  980. /// Load region data from Xml2Format
  981. /// </summary>
  982. /// <param name="module"></param>
  983. /// <param name="cmdparams"></param>
  984. protected void LoadXml2(string module, string[] cmdparams)
  985. {
  986. if (cmdparams.Length > 2)
  987. {
  988. try
  989. {
  990. SceneManager.LoadCurrentSceneFromXml2(cmdparams[2]);
  991. }
  992. catch (FileNotFoundException)
  993. {
  994. MainConsole.Instance.Output("Specified xml not found. Usage: load xml2 <filename>");
  995. }
  996. }
  997. else
  998. {
  999. try
  1000. {
  1001. SceneManager.LoadCurrentSceneFromXml2(DEFAULT_PRIM_BACKUP_FILENAME);
  1002. }
  1003. catch (FileNotFoundException)
  1004. {
  1005. MainConsole.Instance.Output("Default xml not found. Usage: load xml2 <filename>");
  1006. }
  1007. }
  1008. }
  1009. /// <summary>
  1010. /// Load a whole region from an opensimulator archive.
  1011. /// </summary>
  1012. /// <param name="cmdparams"></param>
  1013. protected void LoadOar(string module, string[] cmdparams)
  1014. {
  1015. try
  1016. {
  1017. SceneManager.LoadArchiveToCurrentScene(cmdparams);
  1018. }
  1019. catch (Exception e)
  1020. {
  1021. MainConsole.Instance.Output(e.Message);
  1022. }
  1023. }
  1024. /// <summary>
  1025. /// Save a region to a file, including all the assets needed to restore it.
  1026. /// </summary>
  1027. /// <param name="cmdparams"></param>
  1028. protected void SaveOar(string module, string[] cmdparams)
  1029. {
  1030. SceneManager.SaveCurrentSceneToArchive(cmdparams);
  1031. }
  1032. protected void CreateEstateCommand(string module, string[] args)
  1033. {
  1034. string response = null;
  1035. UUID userID;
  1036. if (args.Length == 2)
  1037. {
  1038. response = "No user specified.";
  1039. }
  1040. else if (!UUID.TryParse(args[2], out userID))
  1041. {
  1042. response = String.Format("{0} is not a valid UUID", args[2]);
  1043. }
  1044. else if (args.Length == 3)
  1045. {
  1046. response = "No estate name specified.";
  1047. }
  1048. else
  1049. {
  1050. Scene scene = SceneManager.CurrentOrFirstScene;
  1051. // TODO: Is there a better choice here?
  1052. UUID scopeID = UUID.Zero;
  1053. UserAccount account = scene.UserAccountService.GetUserAccount(scopeID, userID);
  1054. if (account == null)
  1055. {
  1056. response = String.Format("Could not find user {0}", userID);
  1057. }
  1058. else
  1059. {
  1060. // concatenate it all to "name"
  1061. StringBuilder sb = new StringBuilder(args[3]);
  1062. for (int i = 4; i < args.Length; i++)
  1063. sb.Append (" " + args[i]);
  1064. string estateName = sb.ToString().Trim();
  1065. // send it off for processing.
  1066. IEstateModule estateModule = scene.RequestModuleInterface<IEstateModule>();
  1067. response = estateModule.CreateEstate(estateName, userID);
  1068. if (response == String.Empty)
  1069. {
  1070. List<int> estates = scene.EstateDataService.GetEstates(estateName);
  1071. response = String.Format("Estate {0} created as \"{1}\"", estates.ElementAt(0), estateName);
  1072. }
  1073. }
  1074. }
  1075. // give the user some feedback
  1076. if (response != null)
  1077. MainConsole.Instance.Output(response);
  1078. }
  1079. protected void SetEstateOwnerCommand(string module, string[] args)
  1080. {
  1081. string response = null;
  1082. Scene scene = SceneManager.CurrentOrFirstScene;
  1083. IEstateModule estateModule = scene.RequestModuleInterface<IEstateModule>();
  1084. if (args.Length == 3)
  1085. {
  1086. response = "No estate specified.";
  1087. }
  1088. else
  1089. {
  1090. int estateId;
  1091. if (!int.TryParse(args[3], out estateId))
  1092. {
  1093. response = String.Format("\"{0}\" is not a valid ID for an Estate", args[3]);
  1094. }
  1095. else
  1096. {
  1097. if (args.Length == 4)
  1098. {
  1099. response = "No user specified.";
  1100. }
  1101. else
  1102. {
  1103. UserAccount account = null;
  1104. // TODO: Is there a better choice here?
  1105. UUID scopeID = UUID.Zero;
  1106. string s1 = args[4];
  1107. if (args.Length == 5)
  1108. {
  1109. // attempt to get account by UUID
  1110. UUID u;
  1111. if (UUID.TryParse(s1, out u))
  1112. {
  1113. account = scene.UserAccountService.GetUserAccount(scopeID, u);
  1114. if (account == null)
  1115. response = String.Format("Could not find user {0}", s1);
  1116. }
  1117. else
  1118. {
  1119. response = String.Format("Invalid UUID {0}", s1);
  1120. }
  1121. }
  1122. else
  1123. {
  1124. // attempt to get account by Firstname, Lastname
  1125. string s2 = args[5];
  1126. account = scene.UserAccountService.GetUserAccount(scopeID, s1, s2);
  1127. if (account == null)
  1128. response = String.Format("Could not find user {0} {1}", s1, s2);
  1129. }
  1130. // If it's valid, send it off for processing.
  1131. if (account != null)
  1132. response = estateModule.SetEstateOwner(estateId, account);
  1133. if (response == String.Empty)
  1134. {
  1135. response = String.Format("Estate owner changed to {0} ({1} {2})", account.PrincipalID, account.FirstName, account.LastName);
  1136. }
  1137. }
  1138. }
  1139. }
  1140. // give the user some feedback
  1141. if (response != null)
  1142. MainConsole.Instance.Output(response);
  1143. }
  1144. protected void SetEstateNameCommand(string module, string[] args)
  1145. {
  1146. string response = null;
  1147. Scene scene = SceneManager.CurrentOrFirstScene;
  1148. IEstateModule estateModule = scene.RequestModuleInterface<IEstateModule>();
  1149. if (args.Length == 3)
  1150. {
  1151. response = "No estate specified.";
  1152. }
  1153. else
  1154. {
  1155. int estateId;
  1156. if (!int.TryParse(args[3], out estateId))
  1157. {
  1158. response = String.Format("\"{0}\" is not a valid ID for an Estate", args[3]);
  1159. }
  1160. else
  1161. {
  1162. if (args.Length == 4)
  1163. {
  1164. response = "No name specified.";
  1165. }
  1166. else
  1167. {
  1168. // everything after the estate ID is "name"
  1169. StringBuilder sb = new StringBuilder(args[4]);
  1170. for (int i = 5; i < args.Length; i++)
  1171. sb.Append (" " + args[i]);
  1172. string estateName = sb.ToString();
  1173. // send it off for processing.
  1174. response = estateModule.SetEstateName(estateId, estateName);
  1175. if (response == String.Empty)
  1176. {
  1177. response = String.Format("Estate {0} renamed to \"{1}\"", estateId, estateName);
  1178. }
  1179. }
  1180. }
  1181. }
  1182. // give the user some feedback
  1183. if (response != null)
  1184. MainConsole.Instance.Output(response);
  1185. }
  1186. private void EstateLinkRegionCommand(string module, string[] args)
  1187. {
  1188. int estateId =-1;
  1189. UUID regionId = UUID.Zero;
  1190. Scene scene = null;
  1191. string response = null;
  1192. if (args.Length == 3)
  1193. {
  1194. response = "No estate specified.";
  1195. }
  1196. else if (!int.TryParse(args [3], out estateId))
  1197. {
  1198. response = String.Format("\"{0}\" is not a valid ID for an Estate", args [3]);
  1199. }
  1200. else if (args.Length == 4)
  1201. {
  1202. response = "No region specified.";
  1203. }
  1204. else if (!UUID.TryParse(args[4], out regionId))
  1205. {
  1206. response = String.Format("\"{0}\" is not a valid UUID for a Region", args [4]);
  1207. }
  1208. else if (!SceneManager.TryGetScene(regionId, out scene))
  1209. {
  1210. // region may exist, but on a different sim.
  1211. response = String.Format("No access to Region \"{0}\"", args [4]);
  1212. }
  1213. if (response != null)
  1214. {
  1215. MainConsole.Instance.Output(response);
  1216. return;
  1217. }
  1218. // send it off for processing.
  1219. IEstateModule estateModule = scene.RequestModuleInterface<IEstateModule>();
  1220. response = estateModule.SetRegionEstate(scene.RegionInfo, estateId);
  1221. if (response == String.Empty)
  1222. {
  1223. estateModule.TriggerRegionInfoChange();
  1224. estateModule.sendRegionHandshakeToAll();
  1225. response = String.Format ("Region {0} is now attached to estate {1}", regionId, estateId);
  1226. }
  1227. // give the user some feedback
  1228. if (response != null)
  1229. MainConsole.Instance.Output (response);
  1230. }
  1231. #endregion
  1232. private static string CombineParams(string[] commandParams, int pos)
  1233. {
  1234. string result = String.Empty;
  1235. for (int i = pos; i < commandParams.Length; i++)
  1236. {
  1237. result += commandParams[i] + " ";
  1238. }
  1239. result = result.TrimEnd(' ');
  1240. return result;
  1241. }
  1242. }
  1243. }