OpenSim.cs 43 KB

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