1
0

OpenSim.cs 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  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 OpenSim 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.Timers;
  33. using log4net;
  34. using Nini.Config;
  35. using OpenMetaverse;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Console;
  38. using OpenSim.Framework.Statistics;
  39. using OpenSim.Region.Framework.Interfaces;
  40. using OpenSim.Region.Framework.Scenes;
  41. namespace OpenSim
  42. {
  43. /// <summary>
  44. /// Interactive OpenSim region server
  45. /// </summary>
  46. public class OpenSim : OpenSimBase
  47. {
  48. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  49. protected string m_startupCommandsFile;
  50. protected string m_shutdownCommandsFile;
  51. protected bool m_gui = false;
  52. private string m_timedScript = "disabled";
  53. private Timer m_scriptTimer;
  54. public OpenSim(IConfigSource configSource) : base(configSource)
  55. {
  56. }
  57. protected override void ReadExtraConfigSettings()
  58. {
  59. base.ReadExtraConfigSettings();
  60. IConfig startupConfig = m_config.Source.Configs["Startup"];
  61. if (startupConfig != null)
  62. {
  63. m_startupCommandsFile = startupConfig.GetString("startup_console_commands_file", "startup_commands.txt");
  64. m_shutdownCommandsFile = startupConfig.GetString("shutdown_console_commands_file", "shutdown_commands.txt");
  65. m_gui = startupConfig.GetBoolean("gui", false);
  66. m_timedScript = startupConfig.GetString("timer_Script", "disabled");
  67. if (m_logFileAppender != null)
  68. {
  69. if (m_logFileAppender is log4net.Appender.FileAppender)
  70. {
  71. log4net.Appender.FileAppender appender =
  72. (log4net.Appender.FileAppender)m_logFileAppender;
  73. string fileName = startupConfig.GetString("LogFile", String.Empty);
  74. if (fileName != String.Empty)
  75. appender.File = fileName;
  76. m_log.InfoFormat("[LOGGING] Logging started to file {0}", appender.File);
  77. }
  78. }
  79. }
  80. }
  81. /// <summary>
  82. /// Performs initialisation of the scene, such as loading configuration from disk.
  83. /// </summary>
  84. protected override void StartupSpecific()
  85. {
  86. m_log.Info("====================================================================");
  87. m_log.Info("========================= STARTING OPENSIM =========================");
  88. m_log.Info("====================================================================");
  89. m_log.InfoFormat("[OPENSIM MAIN]: Running in {0} mode",
  90. (ConfigurationSettings.Standalone ? "sandbox" : "grid"));
  91. //m_log.InfoFormat("[OPENSIM MAIN]: GC Is Server GC: {0}", GCSettings.IsServerGC.ToString());
  92. // http://msdn.microsoft.com/en-us/library/bb384202.aspx
  93. //GCSettings.LatencyMode = GCLatencyMode.Batch;
  94. //m_log.InfoFormat("[OPENSIM MAIN]: GC Latency Mode: {0}", GCSettings.LatencyMode.ToString());
  95. if (m_gui) // Driven by external GUI
  96. m_console = new CommandConsole("Region");
  97. else
  98. m_console = new LocalConsole("Region");
  99. MainConsole.Instance = m_console;
  100. RegisterConsoleCommands();
  101. base.StartupSpecific();
  102. //Run Startup Commands
  103. if (String.IsNullOrEmpty(m_startupCommandsFile))
  104. {
  105. m_log.Info("[STARTUP]: No startup command script specified. Moving on...");
  106. }
  107. else
  108. {
  109. RunCommandScript(m_startupCommandsFile);
  110. }
  111. // Start timer script (run a script every xx seconds)
  112. if (m_timedScript != "disabled")
  113. {
  114. m_scriptTimer = new Timer();
  115. m_scriptTimer.Enabled = true;
  116. m_scriptTimer.Interval = 1200*1000;
  117. m_scriptTimer.Elapsed += RunAutoTimerScript;
  118. }
  119. PrintFileToConsole("startuplogo.txt");
  120. // For now, start at the 'root' level by default
  121. if (m_sceneManager.Scenes.Count == 1) // If there is only one region, select it
  122. ChangeSelectedRegion("region",
  123. new string[] {"change", "region", m_sceneManager.Scenes[0].RegionInfo.RegionName});
  124. else
  125. ChangeSelectedRegion("region", new string[] {"change", "region", "root"});
  126. }
  127. private void RegisterConsoleCommands()
  128. {
  129. m_console.Commands.AddCommand("region", false, "clear assets",
  130. "clear assets",
  131. "Clear the asset cache", HandleClearAssets);
  132. m_console.Commands.AddCommand("region", false, "force update",
  133. "force update",
  134. "Force the update of all objects on clients",
  135. HandleForceUpdate);
  136. m_console.Commands.AddCommand("region", false, "debug packet",
  137. "debug packet <level>",
  138. "Turn on packet debugging", Debug);
  139. m_console.Commands.AddCommand("region", false, "debug scene",
  140. "debug scene <cripting> <collisions> <physics>",
  141. "Turn on scene debugging", Debug);
  142. m_console.Commands.AddCommand("region", false, "change region",
  143. "change region <region name>",
  144. "Change current console region", ChangeSelectedRegion);
  145. m_console.Commands.AddCommand("region", false, "save xml",
  146. "save xml",
  147. "Save a region's data in XML format", SaveXml);
  148. m_console.Commands.AddCommand("region", false, "save xml2",
  149. "save xml2",
  150. "Save a region's data in XML2 format", SaveXml2);
  151. m_console.Commands.AddCommand("region", false, "load xml",
  152. "load xml [-newIDs [<x> <y> <z>]]",
  153. "Load a region's data from XML format", LoadXml);
  154. m_console.Commands.AddCommand("region", false, "load xml2",
  155. "load xml2",
  156. "Load a region's data from XML2 format", LoadXml2);
  157. m_console.Commands.AddCommand("region", false, "save prims xml2",
  158. "save prims xml2 [<prim name> <file name>]",
  159. "Save named prim to XML2", SavePrimsXml2);
  160. m_console.Commands.AddCommand("region", false, "load oar",
  161. "load oar <oar name>",
  162. "Load a region's data from OAR archive", LoadOar);
  163. m_console.Commands.AddCommand("region", false, "save oar",
  164. "save oar <oar name>",
  165. "Save a region's data to an OAR archive",
  166. "More information on forthcoming options here soon", SaveOar);
  167. m_console.Commands.AddCommand("region", false, "edit scale",
  168. "edit scale <name> <x> <y> <z>",
  169. "Change the scale of a named prim", HandleEditScale);
  170. m_console.Commands.AddCommand("region", false, "kick user",
  171. "kick user <first> <last> [message]",
  172. "Kick a user off the simulator", KickUserCommand);
  173. m_console.Commands.AddCommand("region", false, "show assets",
  174. "show assets",
  175. "Show asset data", HandleShow);
  176. m_console.Commands.AddCommand("region", false, "show users",
  177. "show users [full]",
  178. "Show user data", HandleShow);
  179. m_console.Commands.AddCommand("region", false, "show users full",
  180. "show users full",
  181. String.Empty, HandleShow);
  182. m_console.Commands.AddCommand("region", false, "show modules",
  183. "show modules",
  184. "Show module data", HandleShow);
  185. m_console.Commands.AddCommand("region", false, "show regions",
  186. "show regions",
  187. "Show region data", HandleShow);
  188. m_console.Commands.AddCommand("region", false, "show queues",
  189. "show queues",
  190. "Show queue data", HandleShow);
  191. m_console.Commands.AddCommand("region", false, "show ratings",
  192. "show ratings",
  193. "Show rating data", HandleShow);
  194. m_console.Commands.AddCommand("region", false, "backup",
  195. "backup",
  196. "Persist objects to the database now", RunCommand);
  197. m_console.Commands.AddCommand("region", false, "create region",
  198. "create region",
  199. "Create a new region", HandleCreateRegion);
  200. m_console.Commands.AddCommand("region", false, "login enable",
  201. "login enable",
  202. "Enable logins to the simulator", HandleLoginEnable);
  203. m_console.Commands.AddCommand("region", false, "login disable",
  204. "login disable",
  205. "Disable logins to the simulator", HandleLoginDisable);
  206. m_console.Commands.AddCommand("region", false, "login status",
  207. "login status",
  208. "Display status of logins", HandleLoginStatus);
  209. m_console.Commands.AddCommand("region", false, "restart",
  210. "restart",
  211. "Restart all sims in this instance", RunCommand);
  212. m_console.Commands.AddCommand("region", false, "config set",
  213. "config set <section> <field> <value>",
  214. "Set a config option", HandleConfig);
  215. m_console.Commands.AddCommand("region", false, "config get",
  216. "config get <section> <field>",
  217. "Read a config option", HandleConfig);
  218. m_console.Commands.AddCommand("region", false, "config save",
  219. "config save",
  220. "Save current configuration", HandleConfig);
  221. m_console.Commands.AddCommand("region", false, "command-script",
  222. "command-script <script>",
  223. "Run a command script from file", RunCommand);
  224. m_console.Commands.AddCommand("region", false, "remove-region",
  225. "remove-region <name>",
  226. "Remove a region from this simulator", RunCommand);
  227. m_console.Commands.AddCommand("region", false, "delete-region",
  228. "delete-region <name>",
  229. "Delete a region from disk", RunCommand);
  230. m_console.Commands.AddCommand("region", false, "predecode-j2k",
  231. "predecode-j2k [<num threads>]>",
  232. "Precache assets,decode j2k layerdata", RunCommand);
  233. m_console.Commands.AddCommand("region", false, "modules list",
  234. "modules list",
  235. "List modules", HandleModules);
  236. m_console.Commands.AddCommand("region", false, "modules load",
  237. "modules load <name>",
  238. "Load a module", HandleModules);
  239. m_console.Commands.AddCommand("region", false, "modules unload",
  240. "modules unload <name>",
  241. "Unload a module", HandleModules);
  242. m_console.Commands.AddCommand("region", false, "Add-InventoryHost",
  243. "Add-InventoryHost <host>",
  244. String.Empty, RunCommand);
  245. if (ConfigurationSettings.Standalone)
  246. {
  247. m_console.Commands.AddCommand("region", false, "create user",
  248. "create user [<first> [<last> [<pass> [<x> <y> [<email>]]]]]",
  249. "Create a new user", HandleCreateUser);
  250. m_console.Commands.AddCommand("region", false, "reset user password",
  251. "reset user password [<first> [<last> [<password>]]]",
  252. "Reset a user password", HandleResetUserPassword);
  253. }
  254. m_console.Commands.AddCommand("hypergrid", false, "link-mapping", "link-mapping [<x> <y>] <cr>",
  255. "Set local coordinate to map HG regions to", RunCommand);
  256. m_console.Commands.AddCommand("hypergrid", false, "link-region",
  257. "link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>] <cr>",
  258. "Link a hypergrid region", RunCommand);
  259. m_console.Commands.AddCommand("hypergrid", false, "unlink-region",
  260. "unlink-region <local name> or <HostName>:<HttpPort> <cr>",
  261. "Unlink a hypergrid region", RunCommand);
  262. }
  263. public override void ShutdownSpecific()
  264. {
  265. if (m_shutdownCommandsFile != String.Empty)
  266. {
  267. RunCommandScript(m_shutdownCommandsFile);
  268. }
  269. base.ShutdownSpecific();
  270. }
  271. private void RunAutoTimerScript(object sender, EventArgs e)
  272. {
  273. if (m_timedScript != "disabled")
  274. {
  275. RunCommandScript(m_timedScript);
  276. }
  277. }
  278. #region Console Commands
  279. private void KickUserCommand(string module, string[] cmdparams)
  280. {
  281. if (cmdparams.Length < 4)
  282. return;
  283. string alert = null;
  284. if (cmdparams.Length > 4)
  285. alert = String.Format("\n{0}\n", String.Join(" ", cmdparams, 4, cmdparams.Length - 4));
  286. IList agents = m_sceneManager.GetCurrentSceneAvatars();
  287. foreach (ScenePresence presence in agents)
  288. {
  289. RegionInfo regionInfo = m_sceneManager.GetRegionInfo(presence.RegionHandle);
  290. if (presence.Firstname.ToLower().Contains(cmdparams[2].ToLower()) &&
  291. presence.Lastname.ToLower().Contains(cmdparams[3].ToLower()))
  292. {
  293. m_console.Notice(
  294. String.Format(
  295. "Kicking user: {0,-16}{1,-16}{2,-37} in region: {3,-16}",
  296. presence.Firstname, presence.Lastname, presence.UUID, regionInfo.RegionName));
  297. // kick client...
  298. if (alert != null)
  299. presence.ControllingClient.Kick(alert);
  300. else
  301. presence.ControllingClient.Kick("\nThe OpenSim manager kicked you out.\n");
  302. // ...and close on our side
  303. presence.Scene.IncomingCloseAgent(presence.UUID);
  304. }
  305. }
  306. m_console.Notice("");
  307. }
  308. /// <summary>
  309. /// Run an optional startup list of commands
  310. /// </summary>
  311. /// <param name="fileName"></param>
  312. private void RunCommandScript(string fileName)
  313. {
  314. if (File.Exists(fileName))
  315. {
  316. m_log.Info("[COMMANDFILE]: Running " + fileName);
  317. StreamReader readFile = File.OpenText(fileName);
  318. string currentCommand;
  319. while ((currentCommand = readFile.ReadLine()) != null)
  320. {
  321. if (currentCommand != String.Empty)
  322. {
  323. m_log.Info("[COMMANDFILE]: Running '" + currentCommand + "'");
  324. m_console.RunCommand(currentCommand);
  325. }
  326. }
  327. }
  328. }
  329. private static void PrintFileToConsole(string fileName)
  330. {
  331. if (File.Exists(fileName))
  332. {
  333. StreamReader readFile = File.OpenText(fileName);
  334. string currentLine;
  335. while ((currentLine = readFile.ReadLine()) != null)
  336. {
  337. m_log.Info("[!]" + currentLine);
  338. }
  339. }
  340. }
  341. private void HandleClearAssets(string module, string[] args)
  342. {
  343. m_assetCache.Clear();
  344. }
  345. private void HandleForceUpdate(string module, string[] args)
  346. {
  347. m_console.Notice("Updating all clients");
  348. m_sceneManager.ForceCurrentSceneClientUpdate();
  349. }
  350. private void HandleEditScale(string module, string[] args)
  351. {
  352. if (args.Length == 6)
  353. {
  354. m_sceneManager.HandleEditCommandOnCurrentScene(args);
  355. }
  356. else
  357. {
  358. m_console.Notice("Argument error: edit scale <prim name> <x> <y> <z>");
  359. }
  360. }
  361. private void HandleCreateRegion(string module, string[] cmd)
  362. {
  363. if (cmd.Length < 4 || !cmd[3].EndsWith(".xml"))
  364. {
  365. m_console.Error("Usage: create region <region name> <region_file.xml>");
  366. return;
  367. }
  368. string regionsDir = ConfigSource.Source.Configs["Startup"].GetString("regionload_regionsdir", "Regions").Trim();
  369. string regionFile = String.Format("{0}/{1}", regionsDir, cmd[3]);
  370. // Allow absolute and relative specifiers
  371. if (cmd[3].StartsWith("/") || cmd[3].StartsWith("\\") || cmd[3].StartsWith(".."))
  372. regionFile = cmd[3];
  373. IScene scene;
  374. CreateRegion(new RegionInfo(cmd[2], regionFile, false, ConfigSource.Source), true, out scene);
  375. }
  376. private void HandleLoginEnable(string module, string[] cmd)
  377. {
  378. ProcessLogin(true);
  379. }
  380. private void HandleLoginDisable(string module, string[] cmd)
  381. {
  382. ProcessLogin(false);
  383. }
  384. private void HandleLoginStatus(string module, string[] cmd)
  385. {
  386. if (m_commsManager.GridService.RegionLoginsEnabled == false)
  387. m_log.Info("[ Login ] Login are disabled ");
  388. else
  389. m_log.Info("[ Login ] Login are enabled");
  390. }
  391. private void HandleConfig(string module, string[] cmd)
  392. {
  393. List<string> args = new List<string>(cmd);
  394. args.RemoveAt(0);
  395. string[] cmdparams = args.ToArray();
  396. string n = "CONFIG";
  397. if (cmdparams.Length > 0)
  398. {
  399. switch (cmdparams[0].ToLower())
  400. {
  401. case "set":
  402. if (cmdparams.Length < 4)
  403. {
  404. m_console.Error(n, "SYNTAX: " + n + " SET SECTION KEY VALUE");
  405. m_console.Error(n, "EXAMPLE: " + n + " SET ScriptEngine.DotNetEngine NumberOfScriptThreads 5");
  406. }
  407. else
  408. {
  409. // IConfig c = DefaultConfig().Configs[cmdparams[1]];
  410. // if (c == null)
  411. // c = DefaultConfig().AddConfig(cmdparams[1]);
  412. IConfig c;
  413. IConfigSource source = new IniConfigSource();
  414. c = source.AddConfig(cmdparams[1]);
  415. if (c != null)
  416. {
  417. string _value = String.Join(" ", cmdparams, 3, cmdparams.Length - 3);
  418. c.Set(cmdparams[2], _value);
  419. m_config.Source.Merge(source);
  420. m_console.Error(n, n + " " + n + " " + cmdparams[1] + " " + cmdparams[2] + " " +
  421. _value);
  422. }
  423. }
  424. break;
  425. case "get":
  426. if (cmdparams.Length < 3)
  427. {
  428. m_console.Error(n, "SYNTAX: " + n + " GET SECTION KEY");
  429. m_console.Error(n, "EXAMPLE: " + n + " GET ScriptEngine.DotNetEngine NumberOfScriptThreads");
  430. }
  431. else
  432. {
  433. IConfig c = m_config.Source.Configs[cmdparams[1]]; // DefaultConfig().Configs[cmdparams[1]];
  434. if (c == null)
  435. {
  436. m_console.Notice(n, "Section \"" + cmdparams[1] + "\" does not exist.");
  437. break;
  438. }
  439. else
  440. {
  441. m_console.Notice(n + " GET " + cmdparams[1] + " " + cmdparams[2] + ": " +
  442. c.GetString(cmdparams[2]));
  443. }
  444. }
  445. break;
  446. case "save":
  447. m_console.Notice("Saving configuration file: " + Application.iniFilePath);
  448. m_config.Save(Application.iniFilePath);
  449. break;
  450. }
  451. }
  452. }
  453. private void HandleModules(string module, string[] cmd)
  454. {
  455. List<string> args = new List<string>(cmd);
  456. args.RemoveAt(0);
  457. string[] cmdparams = args.ToArray();
  458. if (cmdparams.Length > 0)
  459. {
  460. switch (cmdparams[0].ToLower())
  461. {
  462. case "list":
  463. foreach (IRegionModule irm in m_moduleLoader.GetLoadedSharedModules)
  464. {
  465. m_console.Notice("Shared region module: " + irm.Name);
  466. }
  467. break;
  468. case "unload":
  469. if (cmdparams.Length > 1)
  470. {
  471. foreach (IRegionModule rm in new ArrayList(m_moduleLoader.GetLoadedSharedModules))
  472. {
  473. if (rm.Name.ToLower() == cmdparams[1].ToLower())
  474. {
  475. m_console.Notice("Unloading module: " + rm.Name);
  476. m_moduleLoader.UnloadModule(rm);
  477. }
  478. }
  479. }
  480. break;
  481. case "load":
  482. if (cmdparams.Length > 1)
  483. {
  484. foreach (Scene s in new ArrayList(m_sceneManager.Scenes))
  485. {
  486. m_console.Notice("Loading module: " + cmdparams[1]);
  487. m_moduleLoader.LoadRegionModules(cmdparams[1], s);
  488. }
  489. }
  490. break;
  491. }
  492. }
  493. }
  494. /// <summary>
  495. /// Runs commands issued by the server console from the operator
  496. /// </summary>
  497. /// <param name="command">The first argument of the parameter (the command)</param>
  498. /// <param name="cmdparams">Additional arguments passed to the command</param>
  499. public void RunCommand(string module, string[] cmdparams)
  500. {
  501. List<string> args = new List<string>(cmdparams);
  502. if (args.Count < 1)
  503. return;
  504. string command = args[0];
  505. args.RemoveAt(0);
  506. cmdparams = args.ToArray();
  507. switch (command)
  508. {
  509. case "command-script":
  510. if (cmdparams.Length > 0)
  511. {
  512. RunCommandScript(cmdparams[0]);
  513. }
  514. break;
  515. case "backup":
  516. m_sceneManager.BackupCurrentScene();
  517. break;
  518. case "remove-region":
  519. string regRemoveName = CombineParams(cmdparams, 0);
  520. Scene removeScene;
  521. if (m_sceneManager.TryGetScene(regRemoveName, out removeScene))
  522. RemoveRegion(removeScene, false);
  523. else
  524. m_console.Error("no region with that name");
  525. break;
  526. case "delete-region":
  527. string regDeleteName = CombineParams(cmdparams, 0);
  528. Scene killScene;
  529. if (m_sceneManager.TryGetScene(regDeleteName, out killScene))
  530. RemoveRegion(killScene, true);
  531. else
  532. m_console.Error("no region with that name");
  533. break;
  534. case "restart":
  535. m_sceneManager.RestartCurrentScene();
  536. break;
  537. case "Add-InventoryHost":
  538. if (cmdparams.Length > 0)
  539. {
  540. m_commsManager.AddInventoryService(cmdparams[0]);
  541. }
  542. break;
  543. case "predecode-j2k":
  544. if (cmdparams.Length > 0)
  545. {
  546. m_sceneManager.CacheJ2kDecode(Convert.ToInt32(cmdparams[0]));
  547. }
  548. else
  549. {
  550. m_sceneManager.CacheJ2kDecode(1);
  551. }
  552. break;
  553. case "link-region":
  554. case "unlink-region":
  555. case "link-mapping":
  556. HGCommands.RunHGCommand(command, cmdparams, m_sceneManager.CurrentOrFirstScene);
  557. break;
  558. }
  559. }
  560. /// <summary>
  561. /// Change the currently selected region. The selected region is that operated upon by single region commands.
  562. /// </summary>
  563. /// <param name="cmdParams"></param>
  564. protected void ChangeSelectedRegion(string module, string[] cmdparams)
  565. {
  566. if (cmdparams.Length > 2)
  567. {
  568. string newRegionName = CombineParams(cmdparams, 2);
  569. if (!m_sceneManager.TrySetCurrentScene(newRegionName))
  570. m_console.Error("Couldn't select region " + newRegionName);
  571. }
  572. else
  573. {
  574. m_console.Error("Usage: change region <region name>");
  575. }
  576. string regionName = (m_sceneManager.CurrentScene == null ? "root" : m_sceneManager.CurrentScene.RegionInfo.RegionName);
  577. m_console.Notice(String.Format("Currently selected region is {0}", regionName));
  578. m_console.DefaultPrompt = String.Format("Region ({0}) ", regionName);
  579. m_console.ConsoleScene = m_sceneManager.CurrentScene;
  580. }
  581. /// <summary>
  582. /// Execute switch for some of the create commands
  583. /// </summary>
  584. /// <param name="args"></param>
  585. private void HandleCreateUser(string module, string[] cmd)
  586. {
  587. if (ConfigurationSettings.Standalone)
  588. {
  589. CreateUser(cmd);
  590. }
  591. else
  592. {
  593. m_console.Notice("Create user is not available in grid mode, use the user server.");
  594. }
  595. }
  596. /// <summary>
  597. /// Execute switch for some of the reset commands
  598. /// </summary>
  599. /// <param name="args"></param>
  600. protected void HandleResetUserPassword(string module, string[] cmd)
  601. {
  602. if (ConfigurationSettings.Standalone)
  603. {
  604. ResetUserPassword(cmd);
  605. }
  606. else
  607. {
  608. m_console.Notice("Reset user password is not available in grid mode, use the user-server.");
  609. }
  610. }
  611. /// <summary>
  612. /// Turn on some debugging values for OpenSim.
  613. /// </summary>
  614. /// <param name="args"></param>
  615. protected void Debug(string module, string[] args)
  616. {
  617. if (args.Length == 1)
  618. return;
  619. switch (args[1])
  620. {
  621. case "packet":
  622. if (args.Length > 2)
  623. {
  624. int newDebug;
  625. if (int.TryParse(args[2], out newDebug))
  626. {
  627. m_sceneManager.SetDebugPacketLevelOnCurrentScene(newDebug);
  628. }
  629. else
  630. {
  631. m_console.Error("packet debug should be 0..255");
  632. }
  633. m_console.Notice("New packet debug: " + newDebug.ToString());
  634. }
  635. break;
  636. case "scene":
  637. if (args.Length == 5)
  638. {
  639. if (m_sceneManager.CurrentScene == null)
  640. {
  641. m_console.Notice("Please use 'change region <regioname>' first");
  642. }
  643. else
  644. {
  645. bool scriptingOn = !Convert.ToBoolean(args[2]);
  646. bool collisionsOn = !Convert.ToBoolean(args[3]);
  647. bool physicsOn = !Convert.ToBoolean(args[4]);
  648. m_sceneManager.CurrentScene.SetSceneCoreDebug(scriptingOn, collisionsOn, physicsOn);
  649. m_console.Notice(
  650. "CONSOLE",
  651. String.Format(
  652. "Set debug scene scripting = {0}, collisions = {1}, physics = {2}",
  653. !scriptingOn, !collisionsOn, !physicsOn));
  654. }
  655. }
  656. else
  657. {
  658. m_console.Error("debug scene <scripting> <collisions> <physics> (where inside <> is true/false)");
  659. }
  660. break;
  661. default:
  662. m_console.Error("Unknown debug");
  663. break;
  664. }
  665. }
  666. // see BaseOpenSimServer
  667. public override void HandleShow(string mod, string[] cmd)
  668. {
  669. base.HandleShow(mod, cmd);
  670. List<string> args = new List<string>(cmd);
  671. args.RemoveAt(0);
  672. string[] showParams = args.ToArray();
  673. switch (showParams[0])
  674. {
  675. case "assets":
  676. m_assetCache.ShowState();
  677. break;
  678. case "users":
  679. IList agents;
  680. if (showParams.Length > 1 && showParams[1] == "full")
  681. {
  682. agents = m_sceneManager.GetCurrentScenePresences();
  683. }
  684. else
  685. {
  686. agents = m_sceneManager.GetCurrentSceneAvatars();
  687. }
  688. m_console.Notice(String.Format("\nAgents connected: {0}\n", agents.Count));
  689. m_console.Notice(
  690. String.Format("{0,-16}{1,-16}{2,-37}{3,-11}{4,-16}", "Firstname", "Lastname",
  691. "Agent ID", "Root/Child", "Region"));
  692. foreach (ScenePresence presence in agents)
  693. {
  694. RegionInfo regionInfo = m_sceneManager.GetRegionInfo(presence.RegionHandle);
  695. string regionName;
  696. if (regionInfo == null)
  697. {
  698. regionName = "Unresolvable";
  699. }
  700. else
  701. {
  702. regionName = regionInfo.RegionName;
  703. }
  704. m_console.Notice(
  705. String.Format(
  706. "{0,-16}{1,-16}{2,-37}{3,-11}{4,-16}",
  707. presence.Firstname,
  708. presence.Lastname,
  709. presence.UUID,
  710. presence.IsChildAgent ? "Child" : "Root",
  711. regionName));
  712. }
  713. m_console.Notice("");
  714. break;
  715. case "modules":
  716. m_console.Notice("The currently loaded shared modules are:");
  717. foreach (IRegionModule module in m_moduleLoader.GetLoadedSharedModules)
  718. {
  719. m_console.Notice("Shared Module: " + module.Name);
  720. }
  721. break;
  722. case "regions":
  723. m_sceneManager.ForEachScene(
  724. delegate(Scene scene)
  725. {
  726. m_console.Notice("Region Name: " + scene.RegionInfo.RegionName + " , Region XLoc: " +
  727. scene.RegionInfo.RegionLocX + " , Region YLoc: " +
  728. scene.RegionInfo.RegionLocY + " , Region Port: " +
  729. scene.RegionInfo.InternalEndPoint.Port.ToString());
  730. });
  731. break;
  732. case "queues":
  733. Notice(GetQueuesReport());
  734. break;
  735. case "ratings":
  736. m_sceneManager.ForEachScene(
  737. delegate(Scene scene)
  738. {
  739. string rating = "";
  740. if (scene.RegionInfo.RegionSettings.Maturity == 1)
  741. {
  742. rating = "MATURE";
  743. }
  744. else if (scene.RegionInfo.RegionSettings.Maturity == 2)
  745. {
  746. rating = "ADULT";
  747. }
  748. else
  749. {
  750. rating = "PG";
  751. }
  752. m_console.Notice("Region Name: " + scene.RegionInfo.RegionName + " , Region Rating: " +
  753. rating);
  754. });
  755. break;
  756. }
  757. }
  758. private string GetQueuesReport()
  759. {
  760. string report = String.Empty;
  761. m_sceneManager.ForEachScene(delegate(Scene scene)
  762. {
  763. scene.ForEachClient(delegate(IClientAPI client)
  764. {
  765. if (client is IStatsCollector)
  766. {
  767. report = report + client.FirstName +
  768. " " + client.LastName + "\n";
  769. IStatsCollector stats =
  770. (IStatsCollector) client;
  771. report = report + string.Format("{0,7} {1,7} {2,7} {3,7} {4,7} {5,7} {6,7} {7,7} {8,7} {9,7}\n",
  772. "Send",
  773. "In",
  774. "Out",
  775. "Resend",
  776. "Land",
  777. "Wind",
  778. "Cloud",
  779. "Task",
  780. "Texture",
  781. "Asset");
  782. report = report + stats.Report() +
  783. "\n\n";
  784. }
  785. });
  786. });
  787. return report;
  788. }
  789. /// <summary>
  790. /// Create a new user
  791. /// </summary>
  792. /// <param name="cmdparams">string array with parameters: firstname, lastname, password, locationX, locationY, email</param>
  793. protected void CreateUser(string[] cmdparams)
  794. {
  795. string firstName;
  796. string lastName;
  797. string password;
  798. string email;
  799. uint regX = 1000;
  800. uint regY = 1000;
  801. if (cmdparams.Length < 3)
  802. firstName = MainConsole.Instance.CmdPrompt("First name", "Default");
  803. else firstName = cmdparams[2];
  804. if (cmdparams.Length < 4)
  805. lastName = MainConsole.Instance.CmdPrompt("Last name", "User");
  806. else lastName = cmdparams[3];
  807. if (cmdparams.Length < 5)
  808. password = MainConsole.Instance.PasswdPrompt("Password");
  809. else password = cmdparams[4];
  810. if (cmdparams.Length < 6)
  811. regX = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region X", regX.ToString()));
  812. else regX = Convert.ToUInt32(cmdparams[5]);
  813. if (cmdparams.Length < 7)
  814. regY = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region Y", regY.ToString()));
  815. else regY = Convert.ToUInt32(cmdparams[6]);
  816. if (cmdparams.Length < 8)
  817. email = MainConsole.Instance.CmdPrompt("Email", "");
  818. else email = cmdparams[7];
  819. if (null == m_commsManager.UserProfileCacheService.GetUserDetails(firstName, lastName))
  820. {
  821. m_commsManager.UserAdminService.AddUser(firstName, lastName, password, email, regX, regY);
  822. }
  823. else
  824. {
  825. m_log.ErrorFormat("[CONSOLE]: A user with the name {0} {1} already exists!", firstName, lastName);
  826. }
  827. }
  828. /// <summary>
  829. /// Reset a user password.
  830. /// </summary>
  831. /// <param name="cmdparams"></param>
  832. private void ResetUserPassword(string[] cmdparams)
  833. {
  834. string firstName;
  835. string lastName;
  836. string newPassword;
  837. if (cmdparams.Length < 4)
  838. firstName = MainConsole.Instance.CmdPrompt("First name");
  839. else firstName = cmdparams[3];
  840. if (cmdparams.Length < 5)
  841. lastName = MainConsole.Instance.CmdPrompt("Last name");
  842. else lastName = cmdparams[4];
  843. if (cmdparams.Length < 6)
  844. newPassword = MainConsole.Instance.PasswdPrompt("New password");
  845. else newPassword = cmdparams[5];
  846. m_commsManager.UserAdminService.ResetUserPassword(firstName, lastName, newPassword);
  847. }
  848. protected void SavePrimsXml2(string module, string[] cmdparams)
  849. {
  850. if (cmdparams.Length > 5)
  851. {
  852. m_sceneManager.SaveNamedPrimsToXml2(cmdparams[3], cmdparams[4]);
  853. }
  854. else
  855. {
  856. m_sceneManager.SaveNamedPrimsToXml2("Primitive", DEFAULT_PRIM_BACKUP_FILENAME);
  857. }
  858. }
  859. protected void SaveXml(string module, string[] cmdparams)
  860. {
  861. m_log.Error("[CONSOLE]: 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.");
  862. if (cmdparams.Length > 0)
  863. {
  864. m_sceneManager.SaveCurrentSceneToXml(cmdparams[2]);
  865. }
  866. else
  867. {
  868. m_sceneManager.SaveCurrentSceneToXml(DEFAULT_PRIM_BACKUP_FILENAME);
  869. }
  870. }
  871. protected void LoadXml(string module, string[] cmdparams)
  872. {
  873. m_log.Error("[CONSOLE]: 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.");
  874. Vector3 loadOffset = new Vector3(0, 0, 0);
  875. if (cmdparams.Length > 2)
  876. {
  877. bool generateNewIDS = false;
  878. if (cmdparams.Length > 3)
  879. {
  880. if (cmdparams[3] == "-newUID")
  881. {
  882. generateNewIDS = true;
  883. }
  884. if (cmdparams.Length > 4)
  885. {
  886. loadOffset.X = (float) Convert.ToDecimal(cmdparams[4]);
  887. if (cmdparams.Length > 5)
  888. {
  889. loadOffset.Y = (float) Convert.ToDecimal(cmdparams[5]);
  890. }
  891. if (cmdparams.Length > 6)
  892. {
  893. loadOffset.Z = (float) Convert.ToDecimal(cmdparams[6]);
  894. }
  895. m_console.Error("loadOffsets <X,Y,Z> = <" + loadOffset.X + "," + loadOffset.Y + "," +
  896. loadOffset.Z + ">");
  897. }
  898. }
  899. m_sceneManager.LoadCurrentSceneFromXml(cmdparams[0], generateNewIDS, loadOffset);
  900. }
  901. else
  902. {
  903. try
  904. {
  905. m_sceneManager.LoadCurrentSceneFromXml(DEFAULT_PRIM_BACKUP_FILENAME, false, loadOffset);
  906. }
  907. catch (FileNotFoundException)
  908. {
  909. m_console.Error("Default xml not found. Usage: load-xml <filename>");
  910. }
  911. }
  912. }
  913. protected void SaveXml2(string module, string[] cmdparams)
  914. {
  915. if (cmdparams.Length > 2)
  916. {
  917. m_sceneManager.SaveCurrentSceneToXml2(cmdparams[2]);
  918. }
  919. else
  920. {
  921. m_sceneManager.SaveCurrentSceneToXml2(DEFAULT_PRIM_BACKUP_FILENAME);
  922. }
  923. }
  924. protected void LoadXml2(string module, string[] cmdparams)
  925. {
  926. if (cmdparams.Length > 2)
  927. {
  928. try
  929. {
  930. m_sceneManager.LoadCurrentSceneFromXml2(cmdparams[2]);
  931. }
  932. catch (FileNotFoundException)
  933. {
  934. m_console.Error("Specified xml not found. Usage: load xml2 <filename>");
  935. }
  936. }
  937. else
  938. {
  939. try
  940. {
  941. m_sceneManager.LoadCurrentSceneFromXml2(DEFAULT_PRIM_BACKUP_FILENAME);
  942. }
  943. catch (FileNotFoundException)
  944. {
  945. m_console.Error("Default xml not found. Usage: load xml2 <filename>");
  946. }
  947. }
  948. }
  949. /// <summary>
  950. /// Load a whole region from an opensim archive.
  951. /// </summary>
  952. /// <param name="cmdparams"></param>
  953. protected void LoadOar(string module, string[] cmdparams)
  954. {
  955. if (cmdparams.Length > 2)
  956. {
  957. try
  958. {
  959. m_sceneManager.LoadArchiveToCurrentScene(cmdparams[2]);
  960. }
  961. catch (FileNotFoundException)
  962. {
  963. m_console.Error("Specified oar not found. Usage: load oar <filename>");
  964. }
  965. }
  966. else
  967. {
  968. try
  969. {
  970. m_sceneManager.LoadArchiveToCurrentScene(DEFAULT_OAR_BACKUP_FILENAME);
  971. }
  972. catch (FileNotFoundException)
  973. {
  974. m_console.Error("Default oar not found. Usage: load oar <filename>");
  975. }
  976. }
  977. }
  978. /// <summary>
  979. /// Save a region to a file, including all the assets needed to restore it.
  980. /// </summary>
  981. /// <param name="cmdparams"></param>
  982. protected void SaveOar(string module, string[] cmdparams)
  983. {
  984. if (cmdparams.Length > 2)
  985. {
  986. m_sceneManager.SaveCurrentSceneToArchive(cmdparams[2]);
  987. }
  988. else
  989. {
  990. m_sceneManager.SaveCurrentSceneToArchive(DEFAULT_OAR_BACKUP_FILENAME);
  991. }
  992. }
  993. private static string CombineParams(string[] commandParams, int pos)
  994. {
  995. string result = String.Empty;
  996. for (int i = pos; i < commandParams.Length; i++)
  997. {
  998. result += commandParams[i] + " ";
  999. }
  1000. result = result.TrimEnd(' ');
  1001. return result;
  1002. }
  1003. #endregion
  1004. }
  1005. }