OpenSim.cs 44 KB

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