OpenSim.cs 42 KB

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