OpenSim.cs 61 KB

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