OpenSim.cs 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.IO;
  31. using System.Reflection;
  32. using System.Text;
  33. using System.Timers;
  34. using log4net;
  35. using Nini.Config;
  36. using OpenMetaverse;
  37. using OpenSim.Framework;
  38. using OpenSim.Framework.Console;
  39. using OpenSim.Framework.Statistics;
  40. using OpenSim.Region.Framework.Interfaces;
  41. using OpenSim.Region.Framework.Scenes;
  42. namespace OpenSim
  43. {
  44. /// <summary>
  45. /// Interactive OpenSim region server
  46. /// </summary>
  47. public class OpenSim : OpenSimBase
  48. {
  49. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  50. protected string m_startupCommandsFile;
  51. protected string m_shutdownCommandsFile;
  52. protected bool m_gui = false;
  53. protected string m_consoleType = "local";
  54. protected uint m_consolePort = 0;
  55. private string m_timedScript = "disabled";
  56. private Timer m_scriptTimer;
  57. public OpenSim(IConfigSource configSource) : base(configSource)
  58. {
  59. }
  60. protected override void ReadExtraConfigSettings()
  61. {
  62. base.ReadExtraConfigSettings();
  63. IConfig startupConfig = m_config.Source.Configs["Startup"];
  64. IConfig networkConfig = m_config.Source.Configs["Network"];
  65. int stpMaxThreads = 15;
  66. if (startupConfig != null)
  67. {
  68. m_startupCommandsFile = startupConfig.GetString("startup_console_commands_file", "startup_commands.txt");
  69. m_shutdownCommandsFile = startupConfig.GetString("shutdown_console_commands_file", "shutdown_commands.txt");
  70. if (startupConfig.GetString("console", String.Empty) == String.Empty)
  71. m_gui = startupConfig.GetBoolean("gui", false);
  72. else
  73. m_consoleType= startupConfig.GetString("console", String.Empty);
  74. if (networkConfig != null)
  75. m_consolePort = (uint)networkConfig.GetInt("console_port", 0);
  76. m_timedScript = startupConfig.GetString("timer_Script", "disabled");
  77. if (m_logFileAppender != null)
  78. {
  79. if (m_logFileAppender is log4net.Appender.FileAppender)
  80. {
  81. log4net.Appender.FileAppender appender =
  82. (log4net.Appender.FileAppender)m_logFileAppender;
  83. string fileName = startupConfig.GetString("LogFile", String.Empty);
  84. if (fileName != String.Empty)
  85. {
  86. appender.File = fileName;
  87. appender.ActivateOptions();
  88. }
  89. m_log.InfoFormat("[LOGGING]: Logging started to file {0}", appender.File);
  90. }
  91. }
  92. string asyncCallMethodStr = startupConfig.GetString("async_call_method", String.Empty);
  93. FireAndForgetMethod asyncCallMethod;
  94. if (!String.IsNullOrEmpty(asyncCallMethodStr) && Utils.EnumTryParse<FireAndForgetMethod>(asyncCallMethodStr, out asyncCallMethod))
  95. Util.FireAndForgetMethod = asyncCallMethod;
  96. stpMaxThreads = startupConfig.GetInt("MaxPoolThreads", 15);
  97. }
  98. if (Util.FireAndForgetMethod == FireAndForgetMethod.SmartThreadPool)
  99. Util.InitThreadPool(stpMaxThreads);
  100. m_log.Info("[OPENSIM MAIN]: Using async_call_method " + Util.FireAndForgetMethod);
  101. }
  102. /// <summary>
  103. /// Performs initialisation of the scene, such as loading configuration from disk.
  104. /// </summary>
  105. protected override void StartupSpecific()
  106. {
  107. m_log.Info("====================================================================");
  108. m_log.Info("========================= STARTING OPENSIM =========================");
  109. m_log.Info("====================================================================");
  110. //m_log.InfoFormat("[OPENSIM MAIN]: GC Is Server GC: {0}", GCSettings.IsServerGC.ToString());
  111. // http://msdn.microsoft.com/en-us/library/bb384202.aspx
  112. //GCSettings.LatencyMode = GCLatencyMode.Batch;
  113. //m_log.InfoFormat("[OPENSIM MAIN]: GC Latency Mode: {0}", GCSettings.LatencyMode.ToString());
  114. if (m_gui) // Driven by external GUI
  115. m_console = new CommandConsole("Region");
  116. else
  117. {
  118. switch (m_consoleType)
  119. {
  120. case "basic":
  121. m_console = new CommandConsole("Region");
  122. break;
  123. case "rest":
  124. m_console = new RemoteConsole("Region");
  125. ((RemoteConsole)m_console).ReadConfig(m_config.Source);
  126. break;
  127. default:
  128. m_console = new LocalConsole("Region");
  129. break;
  130. }
  131. }
  132. MainConsole.Instance = m_console;
  133. RegisterConsoleCommands();
  134. base.StartupSpecific();
  135. MainServer.Instance.AddStreamHandler(new OpenSim.SimStatusHandler());
  136. MainServer.Instance.AddStreamHandler(new OpenSim.XSimStatusHandler(this));
  137. if (userStatsURI != String.Empty)
  138. MainServer.Instance.AddStreamHandler(new OpenSim.UXSimStatusHandler(this));
  139. if (m_console is RemoteConsole)
  140. {
  141. if (m_consolePort == 0)
  142. {
  143. ((RemoteConsole)m_console).SetServer(m_httpServer);
  144. }
  145. else
  146. {
  147. ((RemoteConsole)m_console).SetServer(MainServer.GetHttpServer(m_consolePort));
  148. }
  149. }
  150. //Run Startup Commands
  151. if (String.IsNullOrEmpty(m_startupCommandsFile))
  152. {
  153. m_log.Info("[STARTUP]: No startup command script specified. Moving on...");
  154. }
  155. else
  156. {
  157. RunCommandScript(m_startupCommandsFile);
  158. }
  159. // Start timer script (run a script every xx seconds)
  160. if (m_timedScript != "disabled")
  161. {
  162. m_scriptTimer = new Timer();
  163. m_scriptTimer.Enabled = true;
  164. m_scriptTimer.Interval = 1200*1000;
  165. m_scriptTimer.Elapsed += RunAutoTimerScript;
  166. }
  167. // Hook up to the watchdog timer
  168. Watchdog.OnWatchdogTimeout += WatchdogTimeoutHandler;
  169. PrintFileToConsole("startuplogo.txt");
  170. // For now, start at the 'root' level by default
  171. if (m_sceneManager.Scenes.Count == 1) // If there is only one region, select it
  172. ChangeSelectedRegion("region",
  173. new string[] {"change", "region", m_sceneManager.Scenes[0].RegionInfo.RegionName});
  174. else
  175. ChangeSelectedRegion("region", new string[] {"change", "region", "root"});
  176. }
  177. /// <summary>
  178. /// Register standard set of region console commands
  179. /// </summary>
  180. private void RegisterConsoleCommands()
  181. {
  182. m_console.Commands.AddCommand("region", false, "clear assets",
  183. "clear assets",
  184. "Clear the asset cache", HandleClearAssets);
  185. m_console.Commands.AddCommand("region", false, "force update",
  186. "force update",
  187. "Force the update of all objects on clients",
  188. HandleForceUpdate);
  189. m_console.Commands.AddCommand("region", false, "debug packet",
  190. "debug packet <level>",
  191. "Turn on packet debugging",
  192. "If level > 255 then all incoming and outgoing packets are logged.\n"
  193. + "If level <= 255 then incoming AgentUpdate and outgoing SimStats and SimulatorViewerTimeMessage packets are not logged.\n"
  194. + "If level <= 200 then incoming RequestImage and outgoing ImagePacket, ImageData, LayerData and CoarseLocationUpdate packets are not logged.\n"
  195. + "If level <= 100 then incoming ViewerEffect and AgentAnimation and outgoing ViewerEffect and AvatarAnimation packets are not logged.\n"
  196. + "If level <= 50 then outgoing ImprovedTerseObjectUpdate packets are not logged.\n"
  197. + "If level <= 0 then no packets are logged.",
  198. Debug);
  199. m_console.Commands.AddCommand("region", false, "debug scene",
  200. "debug scene <cripting> <collisions> <physics>",
  201. "Turn on scene debugging", Debug);
  202. m_console.Commands.AddCommand("region", false, "change region",
  203. "change region <region name>",
  204. "Change current console region", ChangeSelectedRegion);
  205. m_console.Commands.AddCommand("region", false, "save xml",
  206. "save xml",
  207. "Save a region's data in XML format", SaveXml);
  208. m_console.Commands.AddCommand("region", false, "save xml2",
  209. "save xml2",
  210. "Save a region's data in XML2 format", SaveXml2);
  211. m_console.Commands.AddCommand("region", false, "load xml",
  212. "load xml [-newIDs [<x> <y> <z>]]",
  213. "Load a region's data from XML format", LoadXml);
  214. m_console.Commands.AddCommand("region", false, "load xml2",
  215. "load xml2",
  216. "Load a region's data from XML2 format", LoadXml2);
  217. m_console.Commands.AddCommand("region", false, "save prims xml2",
  218. "save prims xml2 [<prim name> <file name>]",
  219. "Save named prim to XML2", SavePrimsXml2);
  220. m_console.Commands.AddCommand("region", false, "load oar",
  221. "load oar [--merge] [--skip-assets] [<OAR path>]",
  222. "Load a region's data from an OAR archive.",
  223. "--merge will merge the OAR with the existing scene." + Environment.NewLine
  224. + "--skip-assets will load the OAR but ignore the assets it contains." + Environment.NewLine
  225. + "The path can be either a filesystem location or a URI."
  226. + " If this is not given then the command looks for an OAR named region.oar in the current directory.",
  227. LoadOar);
  228. m_console.Commands.AddCommand("region", false, "save oar",
  229. //"save oar [-v|--version=<N>] [-p|--profile=<url>] [<OAR path>]",
  230. "save oar [-p|--profile=<url>] [--noassets] [<OAR path>]",
  231. "Save a region's data to an OAR archive.",
  232. // "-v|--version=<N> generates scene objects as per older versions of the serialization (e.g. -v=0)" + Environment.NewLine
  233. "-p|--profile=<url> adds the url of the profile service to the saved user information." + Environment.NewLine
  234. + " The OAR path must be a filesystem path."
  235. + " If this is not given then the oar is saved to region.oar in the current directory." + Environment.NewLine
  236. + "--noassets stops assets being saved to the OAR.",
  237. SaveOar);
  238. m_console.Commands.AddCommand("region", false, "edit scale",
  239. "edit scale <name> <x> <y> <z>",
  240. "Change the scale of a named prim", HandleEditScale);
  241. m_console.Commands.AddCommand("region", false, "kick user",
  242. "kick user <first> <last> [message]",
  243. "Kick a user off the simulator", KickUserCommand);
  244. m_console.Commands.AddCommand("region", false, "show users",
  245. "show users [full]",
  246. "Show user data for users currently on the region",
  247. "Without the 'full' option, only users actually on the region are shown."
  248. + " With the 'full' option child agents of users in neighbouring regions are also shown.",
  249. HandleShow);
  250. m_console.Commands.AddCommand("region", false, "show connections",
  251. "show connections",
  252. "Show connection data", HandleShow);
  253. m_console.Commands.AddCommand("region", false, "show circuits",
  254. "show circuits",
  255. "Show agent circuit data", HandleShow);
  256. m_console.Commands.AddCommand("region", false, "show http-handlers",
  257. "show http-handlers",
  258. "Show all registered http handlers", HandleShow);
  259. m_console.Commands.AddCommand("region", false, "show pending-objects",
  260. "show pending-objects",
  261. "Show # of objects on the pending queues of all scene viewers", HandleShow);
  262. m_console.Commands.AddCommand("region", false, "show modules",
  263. "show modules",
  264. "Show module data", HandleShow);
  265. m_console.Commands.AddCommand("region", false, "show regions",
  266. "show regions",
  267. "Show region data", HandleShow);
  268. m_console.Commands.AddCommand("region", false, "show ratings",
  269. "show ratings",
  270. "Show rating data", HandleShow);
  271. m_console.Commands.AddCommand("region", false, "backup",
  272. "backup",
  273. "Persist objects to the database now", RunCommand);
  274. m_console.Commands.AddCommand("region", false, "create region",
  275. "create region [\"region name\"] <region_file.ini>",
  276. "Create a new region.",
  277. "The settings for \"region name\" are read from <region_file.ini>. Paths specified with <region_file.ini> are relative to your Regions directory, unless an absolute path is given."
  278. + " If \"region name\" does not exist in <region_file.ini>, it will be added." + Environment.NewLine
  279. + "Without \"region name\", the first region found in <region_file.ini> will be created." + Environment.NewLine
  280. + "If <region_file.ini> does not exist, it will be created.",
  281. HandleCreateRegion);
  282. m_console.Commands.AddCommand("region", false, "restart",
  283. "restart",
  284. "Restart all sims in this instance", RunCommand);
  285. m_console.Commands.AddCommand("region", false, "config set",
  286. "config set <section> <key> <value>",
  287. "Set a config option. In most cases this is not useful since changed parameters are not dynamically reloaded. Neither do changed parameters persist - you will have to change a config file manually and restart.", HandleConfig);
  288. m_console.Commands.AddCommand("region", false, "config get",
  289. "config get [<section>] [<key>]",
  290. "Synonym for config show",
  291. HandleConfig);
  292. m_console.Commands.AddCommand("region", false, "config show",
  293. "config show [<section>] [<key>]",
  294. "Show config information",
  295. "If neither section nor field are specified, then the whole current configuration is printed." + Environment.NewLine
  296. + "If a section is given but not a field, then all fields in that section are printed.",
  297. HandleConfig);
  298. m_console.Commands.AddCommand("region", false, "config save",
  299. "config save <path>",
  300. "Save current configuration to a file at the given path", HandleConfig);
  301. m_console.Commands.AddCommand("region", false, "command-script",
  302. "command-script <script>",
  303. "Run a command script from file", RunCommand);
  304. m_console.Commands.AddCommand("region", false, "remove-region",
  305. "remove-region <name>",
  306. "Remove a region from this simulator", RunCommand);
  307. m_console.Commands.AddCommand("region", false, "delete-region",
  308. "delete-region <name>",
  309. "Delete a region from disk", RunCommand);
  310. m_console.Commands.AddCommand("region", false, "modules list",
  311. "modules list",
  312. "List modules", HandleModules);
  313. m_console.Commands.AddCommand("region", false, "modules load",
  314. "modules load <name>",
  315. "Load a module", HandleModules);
  316. m_console.Commands.AddCommand("region", false, "modules unload",
  317. "modules unload <name>",
  318. "Unload a module", HandleModules);
  319. m_console.Commands.AddCommand("region", false, "Add-InventoryHost",
  320. "Add-InventoryHost <host>",
  321. String.Empty, RunCommand);
  322. m_console.Commands.AddCommand("region", false, "kill uuid",
  323. "kill uuid <UUID>",
  324. "Kill an object by UUID", KillUUID);
  325. }
  326. public override void ShutdownSpecific()
  327. {
  328. if (m_shutdownCommandsFile != String.Empty)
  329. {
  330. RunCommandScript(m_shutdownCommandsFile);
  331. }
  332. base.ShutdownSpecific();
  333. }
  334. /// <summary>
  335. /// Timer to run a specific text file as console commands. Configured in in the main ini file
  336. /// </summary>
  337. /// <param name="sender"></param>
  338. /// <param name="e"></param>
  339. private void RunAutoTimerScript(object sender, EventArgs e)
  340. {
  341. if (m_timedScript != "disabled")
  342. {
  343. RunCommandScript(m_timedScript);
  344. }
  345. }
  346. private void WatchdogTimeoutHandler(System.Threading.Thread thread, int lastTick)
  347. {
  348. int now = Environment.TickCount & Int32.MaxValue;
  349. m_log.ErrorFormat("[WATCHDOG]: Timeout detected for thread \"{0}\". ThreadState={1}. Last tick was {2}ms ago",
  350. thread.Name, thread.ThreadState, now - lastTick);
  351. }
  352. #region Console Commands
  353. /// <summary>
  354. /// Kicks users off the region
  355. /// </summary>
  356. /// <param name="module"></param>
  357. /// <param name="cmdparams">name of avatar to kick</param>
  358. private void KickUserCommand(string module, string[] cmdparams)
  359. {
  360. if (cmdparams.Length < 4)
  361. return;
  362. string alert = null;
  363. if (cmdparams.Length > 4)
  364. alert = String.Format("\n{0}\n", String.Join(" ", cmdparams, 4, cmdparams.Length - 4));
  365. IList agents = m_sceneManager.GetCurrentSceneAvatars();
  366. foreach (ScenePresence presence in agents)
  367. {
  368. RegionInfo regionInfo = presence.Scene.RegionInfo;
  369. if (presence.Firstname.ToLower().Contains(cmdparams[2].ToLower()) &&
  370. presence.Lastname.ToLower().Contains(cmdparams[3].ToLower()))
  371. {
  372. MainConsole.Instance.Output(
  373. String.Format(
  374. "Kicking user: {0,-16} {1,-16} {2,-37} in region: {3,-16}",
  375. presence.Firstname, presence.Lastname, presence.UUID, regionInfo.RegionName));
  376. // kick client...
  377. if (alert != null)
  378. presence.ControllingClient.Kick(alert);
  379. else
  380. presence.ControllingClient.Kick("\nThe OpenSim manager kicked you out.\n");
  381. // ...and close on our side
  382. presence.Scene.IncomingCloseAgent(presence.UUID);
  383. }
  384. }
  385. MainConsole.Instance.Output("");
  386. }
  387. /// <summary>
  388. /// Run an optional startup list of commands
  389. /// </summary>
  390. /// <param name="fileName"></param>
  391. private void RunCommandScript(string fileName)
  392. {
  393. if (File.Exists(fileName))
  394. {
  395. m_log.Info("[COMMANDFILE]: Running " + fileName);
  396. using (StreamReader readFile = File.OpenText(fileName))
  397. {
  398. string currentCommand;
  399. while ((currentCommand = readFile.ReadLine()) != null)
  400. {
  401. if (currentCommand != String.Empty)
  402. {
  403. m_log.Info("[COMMANDFILE]: Running '" + currentCommand + "'");
  404. m_console.RunCommand(currentCommand);
  405. }
  406. }
  407. }
  408. }
  409. }
  410. /// <summary>
  411. /// Opens a file and uses it as input to the console command parser.
  412. /// </summary>
  413. /// <param name="fileName">name of file to use as input to the console</param>
  414. private static void PrintFileToConsole(string fileName)
  415. {
  416. if (File.Exists(fileName))
  417. {
  418. StreamReader readFile = File.OpenText(fileName);
  419. string currentLine;
  420. while ((currentLine = readFile.ReadLine()) != null)
  421. {
  422. m_log.Info("[!]" + currentLine);
  423. }
  424. }
  425. }
  426. private void HandleClearAssets(string module, string[] args)
  427. {
  428. MainConsole.Instance.Output("Not implemented.");
  429. }
  430. /// <summary>
  431. /// Force resending of all updates to all clients in active region(s)
  432. /// </summary>
  433. /// <param name="module"></param>
  434. /// <param name="args"></param>
  435. private void HandleForceUpdate(string module, string[] args)
  436. {
  437. MainConsole.Instance.Output("Updating all clients");
  438. m_sceneManager.ForceCurrentSceneClientUpdate();
  439. }
  440. /// <summary>
  441. /// Edits the scale of a primative with the name specified
  442. /// </summary>
  443. /// <param name="module"></param>
  444. /// <param name="args">0,1, name, x, y, z</param>
  445. private void HandleEditScale(string module, string[] args)
  446. {
  447. if (args.Length == 6)
  448. {
  449. m_sceneManager.HandleEditCommandOnCurrentScene(args);
  450. }
  451. else
  452. {
  453. MainConsole.Instance.Output("Argument error: edit scale <prim name> <x> <y> <z>");
  454. }
  455. }
  456. /// <summary>
  457. /// Creates a new region based on the parameters specified. This will ask the user questions on the console
  458. /// </summary>
  459. /// <param name="module"></param>
  460. /// <param name="cmd">0,1,region name, region ini or XML file</param>
  461. private void HandleCreateRegion(string module, string[] cmd)
  462. {
  463. string regionName = string.Empty;
  464. string regionFile = string.Empty;
  465. if (cmd.Length == 3)
  466. {
  467. regionFile = cmd[2];
  468. }
  469. else if (cmd.Length > 3)
  470. {
  471. regionName = cmd[2];
  472. regionFile = cmd[3];
  473. }
  474. string extension = Path.GetExtension(regionFile).ToLower();
  475. bool isXml = extension.Equals(".xml");
  476. bool isIni = extension.Equals(".ini");
  477. if (!isXml && !isIni)
  478. {
  479. MainConsole.Instance.Output("Usage: create region [\"region name\"] <region_file.ini>");
  480. return;
  481. }
  482. if (!Path.IsPathRooted(regionFile))
  483. {
  484. string regionsDir = ConfigSource.Source.Configs["Startup"].GetString("regionload_regionsdir", "Regions").Trim();
  485. regionFile = Path.Combine(regionsDir, regionFile);
  486. }
  487. RegionInfo regInfo;
  488. if (isXml)
  489. {
  490. regInfo = new RegionInfo(regionName, regionFile, false, ConfigSource.Source);
  491. }
  492. else
  493. {
  494. regInfo = new RegionInfo(regionName, regionFile, false, ConfigSource.Source, regionName);
  495. }
  496. IScene scene;
  497. PopulateRegionEstateInfo(regInfo);
  498. CreateRegion(regInfo, true, out scene);
  499. regInfo.EstateSettings.Save();
  500. }
  501. /// <summary>
  502. /// Change and load configuration file data.
  503. /// </summary>
  504. /// <param name="module"></param>
  505. /// <param name="cmd"></param>
  506. private void HandleConfig(string module, string[] cmd)
  507. {
  508. List<string> args = new List<string>(cmd);
  509. args.RemoveAt(0);
  510. string[] cmdparams = args.ToArray();
  511. if (cmdparams.Length > 0)
  512. {
  513. string firstParam = cmdparams[0].ToLower();
  514. switch (firstParam)
  515. {
  516. case "set":
  517. if (cmdparams.Length < 4)
  518. {
  519. Notice("Syntax: config set <section> <key> <value>");
  520. Notice("Example: config set ScriptEngine.DotNetEngine NumberOfScriptThreads 5");
  521. }
  522. else
  523. {
  524. IConfig c;
  525. IConfigSource source = new IniConfigSource();
  526. c = source.AddConfig(cmdparams[1]);
  527. if (c != null)
  528. {
  529. string _value = String.Join(" ", cmdparams, 3, cmdparams.Length - 3);
  530. c.Set(cmdparams[2], _value);
  531. m_config.Source.Merge(source);
  532. Notice("In section [{0}], set {1} = {2}", c.Name, cmdparams[2], _value);
  533. }
  534. }
  535. break;
  536. case "get":
  537. case "show":
  538. if (cmdparams.Length == 1)
  539. {
  540. foreach (IConfig config in m_config.Source.Configs)
  541. {
  542. Notice("[{0}]", config.Name);
  543. string[] keys = config.GetKeys();
  544. foreach (string key in keys)
  545. Notice(" {0} = {1}", key, config.GetString(key));
  546. }
  547. }
  548. else if (cmdparams.Length == 2 || cmdparams.Length == 3)
  549. {
  550. IConfig config = m_config.Source.Configs[cmdparams[1]];
  551. if (config == null)
  552. {
  553. Notice("Section \"{0}\" does not exist.",cmdparams[1]);
  554. break;
  555. }
  556. else
  557. {
  558. if (cmdparams.Length == 2)
  559. {
  560. Notice("[{0}]", config.Name);
  561. foreach (string key in config.GetKeys())
  562. Notice(" {0} = {1}", key, config.GetString(key));
  563. }
  564. else
  565. {
  566. Notice(
  567. "config get {0} {1} : {2}",
  568. cmdparams[1], cmdparams[2], config.GetString(cmdparams[2]));
  569. }
  570. }
  571. }
  572. else
  573. {
  574. Notice("Syntax: config {0} [<section>] [<key>]", firstParam);
  575. Notice("Example: config {0} ScriptEngine.DotNetEngine NumberOfScriptThreads", firstParam);
  576. }
  577. break;
  578. case "save":
  579. if (cmdparams.Length < 2)
  580. {
  581. Notice("Syntax: config save <path>");
  582. return;
  583. }
  584. if (Application.iniFilePath == cmdparams[1])
  585. {
  586. Notice("Path can not be " + Application.iniFilePath);
  587. return;
  588. }
  589. Notice("Saving configuration file: " + cmdparams[1]);
  590. m_config.Save(cmdparams[1]);
  591. break;
  592. }
  593. }
  594. }
  595. /// <summary>
  596. /// Load, Unload, and list Region modules in use
  597. /// </summary>
  598. /// <param name="module"></param>
  599. /// <param name="cmd"></param>
  600. private void HandleModules(string module, string[] cmd)
  601. {
  602. List<string> args = new List<string>(cmd);
  603. args.RemoveAt(0);
  604. string[] cmdparams = args.ToArray();
  605. if (cmdparams.Length > 0)
  606. {
  607. switch (cmdparams[0].ToLower())
  608. {
  609. case "list":
  610. foreach (IRegionModule irm in m_moduleLoader.GetLoadedSharedModules)
  611. {
  612. MainConsole.Instance.Output(String.Format("Shared region module: {0}", irm.Name));
  613. }
  614. break;
  615. case "unload":
  616. if (cmdparams.Length > 1)
  617. {
  618. foreach (IRegionModule rm in new ArrayList(m_moduleLoader.GetLoadedSharedModules))
  619. {
  620. if (rm.Name.ToLower() == cmdparams[1].ToLower())
  621. {
  622. MainConsole.Instance.Output(String.Format("Unloading module: {0}", rm.Name));
  623. m_moduleLoader.UnloadModule(rm);
  624. }
  625. }
  626. }
  627. break;
  628. case "load":
  629. if (cmdparams.Length > 1)
  630. {
  631. foreach (Scene s in new ArrayList(m_sceneManager.Scenes))
  632. {
  633. MainConsole.Instance.Output(String.Format("Loading module: {0}", cmdparams[1]));
  634. m_moduleLoader.LoadRegionModules(cmdparams[1], s);
  635. }
  636. }
  637. break;
  638. }
  639. }
  640. }
  641. /// <summary>
  642. /// Runs commands issued by the server console from the operator
  643. /// </summary>
  644. /// <param name="command">The first argument of the parameter (the command)</param>
  645. /// <param name="cmdparams">Additional arguments passed to the command</param>
  646. public void RunCommand(string module, string[] cmdparams)
  647. {
  648. List<string> args = new List<string>(cmdparams);
  649. if (args.Count < 1)
  650. return;
  651. string command = args[0];
  652. args.RemoveAt(0);
  653. cmdparams = args.ToArray();
  654. switch (command)
  655. {
  656. case "command-script":
  657. if (cmdparams.Length > 0)
  658. {
  659. RunCommandScript(cmdparams[0]);
  660. }
  661. break;
  662. case "backup":
  663. m_sceneManager.BackupCurrentScene();
  664. break;
  665. case "remove-region":
  666. string regRemoveName = CombineParams(cmdparams, 0);
  667. Scene removeScene;
  668. if (m_sceneManager.TryGetScene(regRemoveName, out removeScene))
  669. RemoveRegion(removeScene, false);
  670. else
  671. MainConsole.Instance.Output("no region with that name");
  672. break;
  673. case "delete-region":
  674. string regDeleteName = CombineParams(cmdparams, 0);
  675. Scene killScene;
  676. if (m_sceneManager.TryGetScene(regDeleteName, out killScene))
  677. RemoveRegion(killScene, true);
  678. else
  679. MainConsole.Instance.Output("no region with that name");
  680. break;
  681. case "restart":
  682. m_sceneManager.RestartCurrentScene();
  683. break;
  684. case "Add-InventoryHost":
  685. if (cmdparams.Length > 0)
  686. {
  687. MainConsole.Instance.Output("Not implemented.");
  688. }
  689. break;
  690. }
  691. }
  692. /// <summary>
  693. /// Change the currently selected region. The selected region is that operated upon by single region commands.
  694. /// </summary>
  695. /// <param name="cmdParams"></param>
  696. protected void ChangeSelectedRegion(string module, string[] cmdparams)
  697. {
  698. if (cmdparams.Length > 2)
  699. {
  700. string newRegionName = CombineParams(cmdparams, 2);
  701. if (!m_sceneManager.TrySetCurrentScene(newRegionName))
  702. MainConsole.Instance.Output(String.Format("Couldn't select region {0}", newRegionName));
  703. }
  704. else
  705. {
  706. MainConsole.Instance.Output("Usage: change region <region name>");
  707. }
  708. string regionName = (m_sceneManager.CurrentScene == null ? "root" : m_sceneManager.CurrentScene.RegionInfo.RegionName);
  709. MainConsole.Instance.Output(String.Format("Currently selected region is {0}", regionName));
  710. m_console.DefaultPrompt = String.Format("Region ({0}) ", regionName);
  711. m_console.ConsoleScene = m_sceneManager.CurrentScene;
  712. }
  713. /// <summary>
  714. /// Turn on some debugging values for OpenSim.
  715. /// </summary>
  716. /// <param name="args"></param>
  717. protected void Debug(string module, string[] args)
  718. {
  719. if (args.Length == 1)
  720. return;
  721. switch (args[1])
  722. {
  723. case "packet":
  724. if (args.Length > 2)
  725. {
  726. int newDebug;
  727. if (int.TryParse(args[2], out newDebug))
  728. {
  729. m_sceneManager.SetDebugPacketLevelOnCurrentScene(newDebug);
  730. }
  731. else
  732. {
  733. MainConsole.Instance.Output("packet debug should be 0..255");
  734. }
  735. MainConsole.Instance.Output(String.Format("New packet debug: {0}", newDebug));
  736. }
  737. break;
  738. case "scene":
  739. if (args.Length == 5)
  740. {
  741. if (m_sceneManager.CurrentScene == null)
  742. {
  743. MainConsole.Instance.Output("Please use 'change region <regioname>' first");
  744. }
  745. else
  746. {
  747. bool scriptingOn = !Convert.ToBoolean(args[2]);
  748. bool collisionsOn = !Convert.ToBoolean(args[3]);
  749. bool physicsOn = !Convert.ToBoolean(args[4]);
  750. m_sceneManager.CurrentScene.SetSceneCoreDebug(scriptingOn, collisionsOn, physicsOn);
  751. MainConsole.Instance.Output(
  752. String.Format(
  753. "Set debug scene scripting = {0}, collisions = {1}, physics = {2}",
  754. !scriptingOn, !collisionsOn, !physicsOn));
  755. }
  756. }
  757. else
  758. {
  759. MainConsole.Instance.Output("debug scene <scripting> <collisions> <physics> (where inside <> is true/false)");
  760. }
  761. break;
  762. default:
  763. MainConsole.Instance.Output("Unknown debug");
  764. break;
  765. }
  766. }
  767. // see BaseOpenSimServer
  768. /// <summary>
  769. /// Many commands list objects for debugging. Some of the types are listed here
  770. /// </summary>
  771. /// <param name="mod"></param>
  772. /// <param name="cmd"></param>
  773. public override void HandleShow(string mod, string[] cmd)
  774. {
  775. base.HandleShow(mod, cmd);
  776. List<string> args = new List<string>(cmd);
  777. args.RemoveAt(0);
  778. string[] showParams = args.ToArray();
  779. switch (showParams[0])
  780. {
  781. case "users":
  782. IList agents;
  783. if (showParams.Length > 1 && showParams[1] == "full")
  784. {
  785. agents = m_sceneManager.GetCurrentScenePresences();
  786. }
  787. else
  788. {
  789. agents = m_sceneManager.GetCurrentSceneAvatars();
  790. }
  791. MainConsole.Instance.Output(String.Format("\nAgents connected: {0}\n", agents.Count));
  792. MainConsole.Instance.Output(
  793. String.Format("{0,-16} {1,-16} {2,-37} {3,-11} {4,-16} {5,-30}", "Firstname", "Lastname",
  794. "Agent ID", "Root/Child", "Region", "Position"));
  795. foreach (ScenePresence presence in agents)
  796. {
  797. RegionInfo regionInfo = presence.Scene.RegionInfo;
  798. string regionName;
  799. if (regionInfo == null)
  800. {
  801. regionName = "Unresolvable";
  802. }
  803. else
  804. {
  805. regionName = regionInfo.RegionName;
  806. }
  807. MainConsole.Instance.Output(
  808. String.Format(
  809. "{0,-16} {1,-16} {2,-37} {3,-11} {4,-16} {5,-30}",
  810. presence.Firstname,
  811. presence.Lastname,
  812. presence.UUID,
  813. presence.IsChildAgent ? "Child" : "Root",
  814. regionName,
  815. presence.AbsolutePosition.ToString()));
  816. }
  817. MainConsole.Instance.Output(String.Empty);
  818. break;
  819. case "connections":
  820. System.Text.StringBuilder connections = new System.Text.StringBuilder("Connections:\n");
  821. m_sceneManager.ForEachScene(
  822. delegate(Scene scene)
  823. {
  824. scene.ForEachClient(
  825. delegate(IClientAPI client)
  826. {
  827. connections.AppendFormat("{0}: {1} ({2}) from {3} on circuit {4}\n",
  828. scene.RegionInfo.RegionName, client.Name, client.AgentId, client.RemoteEndPoint, client.CircuitCode);
  829. }
  830. );
  831. }
  832. );
  833. MainConsole.Instance.Output(connections.ToString());
  834. break;
  835. case "circuits":
  836. System.Text.StringBuilder acd = new System.Text.StringBuilder("Agent Circuits:\n");
  837. m_sceneManager.ForEachScene(
  838. delegate(Scene scene)
  839. {
  840. //this.HttpServer.
  841. acd.AppendFormat("{0}:\n", scene.RegionInfo.RegionName);
  842. foreach (AgentCircuitData aCircuit in scene.AuthenticateHandler.AgentCircuits.Values)
  843. acd.AppendFormat("\t{0} {1} ({2})\n", aCircuit.firstname, aCircuit.lastname, (aCircuit.child ? "Child" : "Root"));
  844. }
  845. );
  846. MainConsole.Instance.Output(acd.ToString());
  847. break;
  848. case "http-handlers":
  849. System.Text.StringBuilder handlers = new System.Text.StringBuilder("Registered HTTP Handlers:\n");
  850. handlers.AppendFormat("* XMLRPC:\n");
  851. foreach (String s in HttpServer.GetXmlRpcHandlerKeys())
  852. handlers.AppendFormat("\t{0}\n", s);
  853. handlers.AppendFormat("* HTTP:\n");
  854. List<String> poll = HttpServer.GetPollServiceHandlerKeys();
  855. foreach (String s in HttpServer.GetHTTPHandlerKeys())
  856. handlers.AppendFormat("\t{0} {1}\n", s, (poll.Contains(s) ? "(poll service)" : string.Empty));
  857. handlers.AppendFormat("* Agent:\n");
  858. foreach (String s in HttpServer.GetAgentHandlerKeys())
  859. handlers.AppendFormat("\t{0}\n", s);
  860. handlers.AppendFormat("* LLSD:\n");
  861. foreach (String s in HttpServer.GetLLSDHandlerKeys())
  862. handlers.AppendFormat("\t{0}\n", s);
  863. handlers.AppendFormat("* StreamHandlers ({0}):\n", HttpServer.GetStreamHandlerKeys().Count);
  864. foreach (String s in HttpServer.GetStreamHandlerKeys())
  865. handlers.AppendFormat("\t{0}\n", s);
  866. MainConsole.Instance.Output(handlers.ToString());
  867. break;
  868. case "pending-objects":
  869. System.Text.StringBuilder pending = new System.Text.StringBuilder("Pending objects:\n");
  870. m_sceneManager.ForEachScene(
  871. delegate(Scene scene)
  872. {
  873. scene.ForEachScenePresence(
  874. delegate(ScenePresence sp)
  875. {
  876. pending.AppendFormat("{0}: {1} {2} pending\n",
  877. scene.RegionInfo.RegionName, sp.Name, sp.SceneViewer.GetPendingObjectsCount());
  878. }
  879. );
  880. }
  881. );
  882. MainConsole.Instance.Output(pending.ToString());
  883. break;
  884. case "modules":
  885. MainConsole.Instance.Output("The currently loaded shared modules are:");
  886. foreach (IRegionModule module in m_moduleLoader.GetLoadedSharedModules)
  887. {
  888. MainConsole.Instance.Output("Shared Module: " + module.Name);
  889. }
  890. MainConsole.Instance.Output("");
  891. break;
  892. case "regions":
  893. m_sceneManager.ForEachScene(
  894. delegate(Scene scene)
  895. {
  896. MainConsole.Instance.Output(String.Format(
  897. "Region Name: {0}, Region XLoc: {1}, Region YLoc: {2}, Region Port: {3}, Estate Name: {4}",
  898. scene.RegionInfo.RegionName,
  899. scene.RegionInfo.RegionLocX,
  900. scene.RegionInfo.RegionLocY,
  901. scene.RegionInfo.InternalEndPoint.Port,
  902. scene.RegionInfo.EstateSettings.EstateName));
  903. });
  904. break;
  905. case "ratings":
  906. m_sceneManager.ForEachScene(
  907. delegate(Scene scene)
  908. {
  909. string rating = "";
  910. if (scene.RegionInfo.RegionSettings.Maturity == 1)
  911. {
  912. rating = "MATURE";
  913. }
  914. else if (scene.RegionInfo.RegionSettings.Maturity == 2)
  915. {
  916. rating = "ADULT";
  917. }
  918. else
  919. {
  920. rating = "PG";
  921. }
  922. MainConsole.Instance.Output(String.Format(
  923. "Region Name: {0}, Region Rating {1}",
  924. scene.RegionInfo.RegionName,
  925. rating));
  926. });
  927. break;
  928. }
  929. }
  930. /// <summary>
  931. /// Use XML2 format to serialize data to a file
  932. /// </summary>
  933. /// <param name="module"></param>
  934. /// <param name="cmdparams"></param>
  935. protected void SavePrimsXml2(string module, string[] cmdparams)
  936. {
  937. if (cmdparams.Length > 5)
  938. {
  939. m_sceneManager.SaveNamedPrimsToXml2(cmdparams[3], cmdparams[4]);
  940. }
  941. else
  942. {
  943. m_sceneManager.SaveNamedPrimsToXml2("Primitive", DEFAULT_PRIM_BACKUP_FILENAME);
  944. }
  945. }
  946. /// <summary>
  947. /// Use XML format to serialize data to a file
  948. /// </summary>
  949. /// <param name="module"></param>
  950. /// <param name="cmdparams"></param>
  951. protected void SaveXml(string module, string[] cmdparams)
  952. {
  953. 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.");
  954. if (cmdparams.Length > 0)
  955. {
  956. m_sceneManager.SaveCurrentSceneToXml(cmdparams[2]);
  957. }
  958. else
  959. {
  960. m_sceneManager.SaveCurrentSceneToXml(DEFAULT_PRIM_BACKUP_FILENAME);
  961. }
  962. }
  963. /// <summary>
  964. /// Loads data and region objects from XML format.
  965. /// </summary>
  966. /// <param name="module"></param>
  967. /// <param name="cmdparams"></param>
  968. protected void LoadXml(string module, string[] cmdparams)
  969. {
  970. 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.");
  971. Vector3 loadOffset = new Vector3(0, 0, 0);
  972. if (cmdparams.Length > 2)
  973. {
  974. bool generateNewIDS = false;
  975. if (cmdparams.Length > 3)
  976. {
  977. if (cmdparams[3] == "-newUID")
  978. {
  979. generateNewIDS = true;
  980. }
  981. if (cmdparams.Length > 4)
  982. {
  983. loadOffset.X = (float)Convert.ToDecimal(cmdparams[4], Culture.NumberFormatInfo);
  984. if (cmdparams.Length > 5)
  985. {
  986. loadOffset.Y = (float)Convert.ToDecimal(cmdparams[5], Culture.NumberFormatInfo);
  987. }
  988. if (cmdparams.Length > 6)
  989. {
  990. loadOffset.Z = (float)Convert.ToDecimal(cmdparams[6], Culture.NumberFormatInfo);
  991. }
  992. MainConsole.Instance.Output(String.Format("loadOffsets <X,Y,Z> = <{0},{1},{2}>",loadOffset.X,loadOffset.Y,loadOffset.Z));
  993. }
  994. }
  995. m_sceneManager.LoadCurrentSceneFromXml(cmdparams[2], generateNewIDS, loadOffset);
  996. }
  997. else
  998. {
  999. try
  1000. {
  1001. m_sceneManager.LoadCurrentSceneFromXml(DEFAULT_PRIM_BACKUP_FILENAME, false, loadOffset);
  1002. }
  1003. catch (FileNotFoundException)
  1004. {
  1005. MainConsole.Instance.Output("Default xml not found. Usage: load-xml <filename>");
  1006. }
  1007. }
  1008. }
  1009. /// <summary>
  1010. /// Serialize region data to XML2Format
  1011. /// </summary>
  1012. /// <param name="module"></param>
  1013. /// <param name="cmdparams"></param>
  1014. protected void SaveXml2(string module, string[] cmdparams)
  1015. {
  1016. if (cmdparams.Length > 2)
  1017. {
  1018. m_sceneManager.SaveCurrentSceneToXml2(cmdparams[2]);
  1019. }
  1020. else
  1021. {
  1022. m_sceneManager.SaveCurrentSceneToXml2(DEFAULT_PRIM_BACKUP_FILENAME);
  1023. }
  1024. }
  1025. /// <summary>
  1026. /// Load region data from Xml2Format
  1027. /// </summary>
  1028. /// <param name="module"></param>
  1029. /// <param name="cmdparams"></param>
  1030. protected void LoadXml2(string module, string[] cmdparams)
  1031. {
  1032. if (cmdparams.Length > 2)
  1033. {
  1034. try
  1035. {
  1036. m_sceneManager.LoadCurrentSceneFromXml2(cmdparams[2]);
  1037. }
  1038. catch (FileNotFoundException)
  1039. {
  1040. MainConsole.Instance.Output("Specified xml not found. Usage: load xml2 <filename>");
  1041. }
  1042. }
  1043. else
  1044. {
  1045. try
  1046. {
  1047. m_sceneManager.LoadCurrentSceneFromXml2(DEFAULT_PRIM_BACKUP_FILENAME);
  1048. }
  1049. catch (FileNotFoundException)
  1050. {
  1051. MainConsole.Instance.Output("Default xml not found. Usage: load xml2 <filename>");
  1052. }
  1053. }
  1054. }
  1055. /// <summary>
  1056. /// Load a whole region from an opensimulator archive.
  1057. /// </summary>
  1058. /// <param name="cmdparams"></param>
  1059. protected void LoadOar(string module, string[] cmdparams)
  1060. {
  1061. try
  1062. {
  1063. m_sceneManager.LoadArchiveToCurrentScene(cmdparams);
  1064. }
  1065. catch (Exception e)
  1066. {
  1067. MainConsole.Instance.Output(e.Message);
  1068. }
  1069. }
  1070. /// <summary>
  1071. /// Save a region to a file, including all the assets needed to restore it.
  1072. /// </summary>
  1073. /// <param name="cmdparams"></param>
  1074. protected void SaveOar(string module, string[] cmdparams)
  1075. {
  1076. m_sceneManager.SaveCurrentSceneToArchive(cmdparams);
  1077. }
  1078. private static string CombineParams(string[] commandParams, int pos)
  1079. {
  1080. string result = String.Empty;
  1081. for (int i = pos; i < commandParams.Length; i++)
  1082. {
  1083. result += commandParams[i] + " ";
  1084. }
  1085. result = result.TrimEnd(' ');
  1086. return result;
  1087. }
  1088. /// <summary>
  1089. /// Kill an object given its UUID.
  1090. /// </summary>
  1091. /// <param name="cmdparams"></param>
  1092. protected void KillUUID(string module, string[] cmdparams)
  1093. {
  1094. if (cmdparams.Length > 2)
  1095. {
  1096. UUID id = UUID.Zero;
  1097. SceneObjectGroup grp = null;
  1098. Scene sc = null;
  1099. if (!UUID.TryParse(cmdparams[2], out id))
  1100. {
  1101. MainConsole.Instance.Output("[KillUUID]: Error bad UUID format!");
  1102. return;
  1103. }
  1104. m_sceneManager.ForEachScene(
  1105. delegate(Scene scene)
  1106. {
  1107. SceneObjectPart part = scene.GetSceneObjectPart(id);
  1108. if (part == null)
  1109. return;
  1110. grp = part.ParentGroup;
  1111. sc = scene;
  1112. });
  1113. if (grp == null)
  1114. {
  1115. MainConsole.Instance.Output(String.Format("[KillUUID]: Given UUID {0} not found!", id));
  1116. }
  1117. else
  1118. {
  1119. MainConsole.Instance.Output(String.Format("[KillUUID]: Found UUID {0} in scene {1}", id, sc.RegionInfo.RegionName));
  1120. try
  1121. {
  1122. sc.DeleteSceneObject(grp, false);
  1123. }
  1124. catch (Exception e)
  1125. {
  1126. m_log.ErrorFormat("[KillUUID]: Error while removing objects from scene: " + e);
  1127. }
  1128. }
  1129. }
  1130. else
  1131. {
  1132. MainConsole.Instance.Output("[KillUUID]: Usage: kill uuid <UUID>");
  1133. }
  1134. }
  1135. #endregion
  1136. }
  1137. }