OpenSim.cs 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130
  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.IncomingCloseAgent(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 "force-update":
  207. m_console.Notice("Updating all clients");
  208. m_sceneManager.ForceCurrentSceneClientUpdate();
  209. break;
  210. case "edit-scale":
  211. if (cmdparams.Length == 4)
  212. {
  213. m_sceneManager.HandleEditCommandOnCurrentScene(cmdparams);
  214. }
  215. break;
  216. case "debug":
  217. Debug(cmdparams);
  218. break;
  219. case "save-xml":
  220. SaveXml(cmdparams);
  221. break;
  222. case "load-xml":
  223. LoadXml(cmdparams);
  224. break;
  225. case "save-xml2":
  226. SaveXml2(cmdparams);
  227. break;
  228. case "load-xml2":
  229. LoadXml2(cmdparams);
  230. break;
  231. case "save-prims-xml2":
  232. if (cmdparams.Length > 1)
  233. {
  234. m_sceneManager.SaveNamedPrimsToXml2(cmdparams[0], cmdparams[1]);
  235. }
  236. else
  237. {
  238. m_sceneManager.SaveNamedPrimsToXml2("Primitive", DEFAULT_PRIM_BACKUP_FILENAME);
  239. }
  240. break;
  241. case "load-oar":
  242. LoadOar(cmdparams);
  243. break;
  244. case "save-oar":
  245. SaveOar(cmdparams);
  246. break;
  247. case "save-inv":
  248. SaveInv(cmdparams);
  249. break;
  250. case "load-inv":
  251. LoadInv(cmdparams);
  252. break;
  253. case "plugin":
  254. m_sceneManager.SendCommandToPluginModules(cmdparams);
  255. break;
  256. case "command-script":
  257. if (cmdparams.Length > 0)
  258. {
  259. RunCommandScript(cmdparams[0]);
  260. }
  261. break;
  262. case "backup":
  263. m_sceneManager.BackupCurrentScene();
  264. break;
  265. case "alert":
  266. m_sceneManager.HandleAlertCommandOnCurrentScene(cmdparams);
  267. break;
  268. case "create":
  269. Create(cmdparams);
  270. break;
  271. case "login-enable":
  272. ProcessLogin(true);
  273. break;
  274. case "login-disable":
  275. ProcessLogin(false);
  276. break;
  277. case "login-status":
  278. if (m_commsManager.GridService.RegionLoginsEnabled == false)
  279. m_log.Info("[ Login ] Login are disabled ");
  280. else
  281. m_log.Info("[ Login ] Login are enabled");
  282. break;
  283. case "create-region":
  284. if (cmdparams.Length < 2)
  285. {
  286. m_console.Error("Usage: create-region <region name> <region_file.xml>");
  287. break;
  288. }
  289. string regionsDir = ConfigSource.Source.Configs["Startup"].GetString("regionload_regionsdir", "Regions").Trim();
  290. string regionFile = String.Format("{0}/{1}", regionsDir, cmdparams[1]);
  291. // Allow absolute and relative specifiers
  292. if (cmdparams[1].StartsWith("/") || cmdparams[1].StartsWith("\\") || cmdparams[1].StartsWith(".."))
  293. regionFile = cmdparams[1];
  294. CreateRegion(new RegionInfo(cmdparams[0], regionFile, false, ConfigSource.Source), true);
  295. break;
  296. case "remove-region":
  297. string regRemoveName = CombineParams(cmdparams, 0);
  298. Scene removeScene;
  299. if (m_sceneManager.TryGetScene(regRemoveName, out removeScene))
  300. RemoveRegion(removeScene, false);
  301. else
  302. m_console.Error("no region with that name");
  303. break;
  304. case "delete-region":
  305. string regDeleteName = CombineParams(cmdparams, 0);
  306. Scene killScene;
  307. if (m_sceneManager.TryGetScene(regDeleteName, out killScene))
  308. RemoveRegion(killScene, true);
  309. else
  310. m_console.Error("no region with that name");
  311. break;
  312. case "restart":
  313. m_sceneManager.RestartCurrentScene();
  314. break;
  315. case "change-region":
  316. ChangeSelectedRegion(cmdparams);
  317. break;
  318. case "export-map":
  319. if (cmdparams.Length > 0)
  320. {
  321. m_sceneManager.CurrentOrFirstScene.ExportWorldMap(cmdparams[0]);
  322. }
  323. else
  324. {
  325. m_sceneManager.CurrentOrFirstScene.ExportWorldMap("exportmap.jpg");
  326. }
  327. break;
  328. case "config":
  329. string n = command.ToUpper();
  330. if (cmdparams.Length > 0)
  331. {
  332. switch (cmdparams[0].ToLower())
  333. {
  334. case "set":
  335. if (cmdparams.Length < 4)
  336. {
  337. m_console.Error(n, "SYNTAX: " + n + " SET SECTION KEY VALUE");
  338. m_console.Error(n, "EXAMPLE: " + n + " SET ScriptEngine.DotNetEngine NumberOfScriptThreads 5");
  339. }
  340. else
  341. {
  342. // IConfig c = DefaultConfig().Configs[cmdparams[1]];
  343. // if (c == null)
  344. // c = DefaultConfig().AddConfig(cmdparams[1]);
  345. IConfig c;
  346. IConfigSource source = new IniConfigSource();
  347. c = source.AddConfig(cmdparams[1]);
  348. if (c != null)
  349. {
  350. string _value = String.Join(" ", cmdparams, 3, cmdparams.Length - 3);
  351. c.Set(cmdparams[2], _value);
  352. m_config.Source.Merge(source);
  353. m_console.Error(n, n + " " + n + " " + cmdparams[1] + " " + cmdparams[2] + " " +
  354. _value);
  355. }
  356. }
  357. break;
  358. case "get":
  359. if (cmdparams.Length < 3)
  360. {
  361. m_console.Error(n, "SYNTAX: " + n + " GET SECTION KEY");
  362. m_console.Error(n, "EXAMPLE: " + n + " GET ScriptEngine.DotNetEngine NumberOfScriptThreads");
  363. }
  364. else
  365. {
  366. IConfig c = m_config.Source.Configs[cmdparams[1]]; // DefaultConfig().Configs[cmdparams[1]];
  367. if (c == null)
  368. {
  369. m_console.Notice(n, "Section \"" + cmdparams[1] + "\" does not exist.");
  370. break;
  371. }
  372. else
  373. {
  374. m_console.Notice(n + " GET " + cmdparams[1] + " " + cmdparams[2] + ": " +
  375. c.GetString(cmdparams[2]));
  376. }
  377. }
  378. break;
  379. case "save":
  380. m_console.Notice("Saving configuration file: " + Application.iniFilePath);
  381. m_config.Save(Application.iniFilePath);
  382. break;
  383. }
  384. }
  385. break;
  386. case "modules":
  387. if (cmdparams.Length > 0)
  388. {
  389. switch (cmdparams[0].ToLower())
  390. {
  391. case "list":
  392. foreach (IRegionModule irm in m_moduleLoader.GetLoadedSharedModules)
  393. {
  394. m_console.Notice("Shared region module: " + irm.Name);
  395. }
  396. break;
  397. case "unload":
  398. if (cmdparams.Length > 1)
  399. {
  400. foreach (IRegionModule rm in new ArrayList(m_moduleLoader.GetLoadedSharedModules))
  401. {
  402. if (rm.Name.ToLower() == cmdparams[1].ToLower())
  403. {
  404. m_console.Notice("Unloading module: " + rm.Name);
  405. m_moduleLoader.UnloadModule(rm);
  406. }
  407. }
  408. }
  409. break;
  410. case "load":
  411. if (cmdparams.Length > 1)
  412. {
  413. foreach (Scene s in new ArrayList(m_sceneManager.Scenes))
  414. {
  415. m_console.Notice("Loading module: " + cmdparams[1]);
  416. m_moduleLoader.LoadRegionModules(cmdparams[1], s);
  417. }
  418. }
  419. break;
  420. }
  421. }
  422. break;
  423. case "Add-InventoryHost":
  424. if (cmdparams.Length > 0)
  425. {
  426. m_commsManager.AddInventoryService(cmdparams[0]);
  427. }
  428. break;
  429. case "reset":
  430. Reset(cmdparams);
  431. break;
  432. default:
  433. string[] tmpPluginArgs = new string[cmdparams.Length + 1];
  434. cmdparams.CopyTo(tmpPluginArgs, 1);
  435. tmpPluginArgs[0] = command;
  436. m_sceneManager.SendCommandToPluginModules(tmpPluginArgs);
  437. break;
  438. }
  439. }
  440. /// <summary>
  441. /// Change the currently selected region. The selected region is that operated upon by single region commands.
  442. /// </summary>
  443. /// <param name="cmdParams"></param>
  444. protected void ChangeSelectedRegion(string[] cmdparams)
  445. {
  446. if (cmdparams.Length > 0)
  447. {
  448. string newRegionName = CombineParams(cmdparams, 0);
  449. if (!m_sceneManager.TrySetCurrentScene(newRegionName))
  450. m_console.Error("Couldn't select region " + newRegionName);
  451. }
  452. else
  453. {
  454. m_console.Error("Usage: change-region <region name>");
  455. }
  456. string regionName = (m_sceneManager.CurrentScene == null ? "root" : m_sceneManager.CurrentScene.RegionInfo.RegionName);
  457. m_console.Notice(String.Format("Currently selected region is {0}", regionName));
  458. m_console.DefaultPrompt = String.Format("Region ({0}) ", regionName);
  459. }
  460. /// <summary>
  461. /// Execute switch for some of the create commands
  462. /// </summary>
  463. /// <param name="args"></param>
  464. protected void Create(string[] args)
  465. {
  466. if (args.Length == 0)
  467. return;
  468. switch (args[0])
  469. {
  470. case "user":
  471. if (ConfigurationSettings.Standalone)
  472. {
  473. CreateUser(args);
  474. }
  475. else
  476. {
  477. m_console.Notice("Create user is not available in grid mode, use the user server.");
  478. }
  479. break;
  480. }
  481. }
  482. /// <summary>
  483. /// Execute switch for some of the reset commands
  484. /// </summary>
  485. /// <param name="args"></param>
  486. protected void Reset(string[] args)
  487. {
  488. if (args.Length == 0)
  489. return;
  490. switch (args[0])
  491. {
  492. case "user":
  493. switch (args[1])
  494. {
  495. case "password":
  496. if (ConfigurationSettings.Standalone)
  497. {
  498. ResetUserPassword(args);
  499. }
  500. else
  501. {
  502. m_console.Notice("Reset user password is not available in grid mode, use the user-server.");
  503. }
  504. break;
  505. }
  506. break;
  507. }
  508. }
  509. /// <summary>
  510. /// Turn on some debugging values for OpenSim.
  511. /// </summary>
  512. /// <param name="args"></param>
  513. protected void Debug(string[] args)
  514. {
  515. if (args.Length == 0)
  516. return;
  517. switch (args[0])
  518. {
  519. case "packet":
  520. if (args.Length > 1)
  521. {
  522. int newDebug;
  523. if (int.TryParse(args[1], out newDebug))
  524. {
  525. m_sceneManager.SetDebugPacketLevelOnCurrentScene(newDebug);
  526. }
  527. else
  528. {
  529. m_console.Error("packet debug should be 0..255");
  530. }
  531. m_console.Notice("New packet debug: " + newDebug.ToString());
  532. }
  533. break;
  534. case "scene":
  535. if (args.Length == 4)
  536. {
  537. if (m_sceneManager.CurrentScene == null)
  538. {
  539. m_console.Error("CONSOLE", "Please use 'change-region <regioname>' first");
  540. }
  541. else
  542. {
  543. bool scriptingOn = !Convert.ToBoolean(args[1]);
  544. bool collisionsOn = !Convert.ToBoolean(args[2]);
  545. bool physicsOn = !Convert.ToBoolean(args[3]);
  546. m_sceneManager.CurrentScene.SetSceneCoreDebug(scriptingOn, collisionsOn, physicsOn);
  547. m_console.Notice(
  548. "CONSOLE",
  549. String.Format(
  550. "Set debug scene scripting = {0}, collisions = {1}, physics = {2}",
  551. !scriptingOn, !collisionsOn, !physicsOn));
  552. }
  553. }
  554. else
  555. {
  556. m_console.Error("debug scene <scripting> <collisions> <physics> (where inside <> is true/false)");
  557. }
  558. break;
  559. default:
  560. m_console.Error("Unknown debug");
  561. break;
  562. }
  563. }
  564. protected override void ShowHelp(string[] helpArgs)
  565. {
  566. base.ShowHelp(helpArgs);
  567. m_console.Notice("alert - send alert to a designated user or all users.");
  568. m_console.Notice(" alert [First] [Last] [Message] - send an alert to a user. Case sensitive.");
  569. m_console.Notice(" alert general [Message] - send an alert to all users.");
  570. m_console.Notice("backup - persist simulator objects to the database ahead of the normal schedule.");
  571. m_console.Notice("clear-assets - clear the asset cache");
  572. m_console.Notice("create-region <name> <regionfile.xml> - create a new region");
  573. m_console.Notice("change-region <name> - select the region that single region commands operate upon.");
  574. m_console.Notice("command-script [filename] - Execute command in a file.");
  575. m_console.Notice("debug - debugging commands");
  576. m_console.Notice(" debug packet 0..255 - print incoming/outgoing packets (0=off)");
  577. m_console.Notice(" debug scene [scripting] [collision] [physics] - Enable/Disable debug stuff, each can be True/False");
  578. m_console.Notice("edit-scale [prim name] [x] [y] [z] - resize given prim");
  579. m_console.Notice("export-map [filename] - save image of world map");
  580. m_console.Notice("force-update - force an update of prims in the scene");
  581. m_console.Notice("restart - disconnects all clients and restarts the sims in the instance.");
  582. m_console.Notice("remove-region [name] - remove a region");
  583. m_console.Notice("delete-region [name] - delete a region and its associated region file");
  584. m_console.Notice("load-xml [filename] - load prims from XML (DEPRECATED)");
  585. m_console.Notice("save-xml [filename] - save prims to XML (DEPRECATED)");
  586. m_console.Notice("save-xml2 [filename] - save prims to XML using version 2 format");
  587. m_console.Notice("load-xml2 [filename] - load prims from XML using version 2 format");
  588. m_console.Notice("load-oar [filename] - load an OpenSimulator region archive. This replaces everything in the current region.");
  589. m_console.Notice("save-oar [filename] - Save the current region to an OpenSimulator region archive.");
  590. m_console.Notice("script - manually trigger scripts? or script commands?");
  591. m_console.Notice("show assets - show state of asset cache.");
  592. m_console.Notice("show modules - shows info about loaded modules.");
  593. m_console.Notice("show queues - show packet queues length for all clients.");
  594. m_console.Notice("show regions - show running region information.");
  595. m_console.Notice("show users - show info about connected users (only root agents).");
  596. m_console.Notice("show users full - show info about connected users (root and child agents).");
  597. m_console.Notice("config set section field value - set a config value");
  598. m_console.Notice("config get section field - get a config value");
  599. m_console.Notice("config save - save OpenSim.ini");
  600. m_console.Notice("terrain help - show help for terrain commands.");
  601. m_console.Notice("login-enable - Allows login at sim level");
  602. m_console.Notice("login-disable - Disable login at sim level");
  603. m_console.Notice("login-status - Show the actual login status");
  604. ShowPluginCommandsHelp(CombineParams(helpArgs, 0), m_console);
  605. if (ConfigurationSettings.Standalone)
  606. {
  607. m_console.Notice("");
  608. m_console.Notice("create user - adds a new user.");
  609. m_console.Notice("reset user password - reset a user's password.");
  610. }
  611. }
  612. // see BaseOpenSimServer
  613. public override void Show(string[] showParams)
  614. {
  615. base.Show(showParams);
  616. switch (showParams[0])
  617. {
  618. case "assets":
  619. m_assetCache.ShowState();
  620. break;
  621. case "users":
  622. IList agents;
  623. if (showParams.Length > 1 && showParams[1] == "full")
  624. {
  625. agents = m_sceneManager.GetCurrentScenePresences();
  626. }
  627. else
  628. {
  629. agents = m_sceneManager.GetCurrentSceneAvatars();
  630. }
  631. m_console.Notice(String.Format("\nAgents connected: {0}\n", agents.Count));
  632. m_console.Notice(
  633. String.Format("{0,-16}{1,-16}{2,-37}{3,-11}{4,-16}", "Firstname", "Lastname",
  634. "Agent ID", "Root/Child", "Region"));
  635. foreach (ScenePresence presence in agents)
  636. {
  637. RegionInfo regionInfo = m_sceneManager.GetRegionInfo(presence.RegionHandle);
  638. string regionName;
  639. if (regionInfo == null)
  640. {
  641. regionName = "Unresolvable";
  642. }
  643. else
  644. {
  645. regionName = regionInfo.RegionName;
  646. }
  647. m_console.Notice(
  648. String.Format(
  649. "{0,-16}{1,-16}{2,-37}{3,-11}{4,-16}",
  650. presence.Firstname,
  651. presence.Lastname,
  652. presence.UUID,
  653. presence.IsChildAgent ? "Child" : "Root",
  654. regionName));
  655. }
  656. m_console.Notice("");
  657. break;
  658. case "modules":
  659. m_console.Notice("The currently loaded shared modules are:");
  660. foreach (IRegionModule module in m_moduleLoader.GetLoadedSharedModules)
  661. {
  662. m_console.Notice("Shared Module: " + module.Name);
  663. }
  664. break;
  665. case "regions":
  666. m_sceneManager.ForEachScene(
  667. delegate(Scene scene)
  668. {
  669. m_console.Notice("Region Name: " + scene.RegionInfo.RegionName + " , Region XLoc: " +
  670. scene.RegionInfo.RegionLocX + " , Region YLoc: " +
  671. scene.RegionInfo.RegionLocY + " , Region Port: " + scene.RegionInfo.InternalEndPoint.Port.ToString());
  672. });
  673. break;
  674. case "queues":
  675. Notice(GetQueuesReport());
  676. break;
  677. }
  678. }
  679. private string GetQueuesReport()
  680. {
  681. string report = String.Empty;
  682. m_sceneManager.ForEachScene(delegate(Scene scene)
  683. {
  684. scene.ForEachClient(delegate(IClientAPI client)
  685. {
  686. if (client is IStatsCollector)
  687. {
  688. report = report + client.FirstName +
  689. " " + client.LastName + "\n";
  690. IStatsCollector stats =
  691. (IStatsCollector) client;
  692. 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",
  693. "Send",
  694. "In",
  695. "Out",
  696. "Resend",
  697. "Land",
  698. "Wind",
  699. "Cloud",
  700. "Task",
  701. "Texture",
  702. "Asset");
  703. report = report + stats.Report() +
  704. "\n\n";
  705. }
  706. });
  707. });
  708. return report;
  709. }
  710. /// <summary>
  711. /// Create a new user
  712. /// </summary>
  713. /// <param name="cmdparams">string array with parameters: firstname, lastname, password, locationX, locationY, email</param>
  714. protected void CreateUser(string[] cmdparams)
  715. {
  716. string firstName;
  717. string lastName;
  718. string password;
  719. string email;
  720. uint regX = 1000;
  721. uint regY = 1000;
  722. if (cmdparams.Length < 2)
  723. firstName = MainConsole.Instance.CmdPrompt("First name", "Default");
  724. else firstName = cmdparams[1];
  725. if ( cmdparams.Length < 3 )
  726. lastName = MainConsole.Instance.CmdPrompt("Last name", "User");
  727. else lastName = cmdparams[2];
  728. if (cmdparams.Length < 4)
  729. password = MainConsole.Instance.PasswdPrompt("Password");
  730. else password = cmdparams[3];
  731. if ( cmdparams.Length < 5 )
  732. regX = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region X", regX.ToString()));
  733. else regX = Convert.ToUInt32(cmdparams[4]);
  734. if ( cmdparams.Length < 6 )
  735. regY = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region Y", regY.ToString()));
  736. else regY = Convert.ToUInt32(cmdparams[5]);
  737. if (cmdparams.Length < 7)
  738. email = MainConsole.Instance.CmdPrompt("Email", "");
  739. else email = cmdparams[6];
  740. if (null == m_commsManager.UserService.GetUserProfile(firstName, lastName))
  741. {
  742. m_commsManager.UserAdminService.AddUser(firstName, lastName, password, email, regX, regY);
  743. }
  744. else
  745. {
  746. m_log.ErrorFormat("[CONSOLE]: A user with the name {0} {1} already exists!", firstName, lastName);
  747. }
  748. }
  749. /// <summary>
  750. /// Reset a user password.
  751. /// </summary>
  752. /// <param name="cmdparams"></param>
  753. private void ResetUserPassword(string[] cmdparams)
  754. {
  755. string firstName;
  756. string lastName;
  757. string newPassword;
  758. if (cmdparams.Length < 3)
  759. firstName = MainConsole.Instance.CmdPrompt("First name");
  760. else firstName = cmdparams[2];
  761. if ( cmdparams.Length < 4 )
  762. lastName = MainConsole.Instance.CmdPrompt("Last name");
  763. else lastName = cmdparams[3];
  764. if ( cmdparams.Length < 5 )
  765. newPassword = MainConsole.Instance.PasswdPrompt("New password");
  766. else newPassword = cmdparams[4];
  767. m_commsManager.UserAdminService.ResetUserPassword(firstName, lastName, newPassword);
  768. }
  769. protected void SaveXml(string[] cmdparams)
  770. {
  771. 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.");
  772. if (cmdparams.Length > 0)
  773. {
  774. m_sceneManager.SaveCurrentSceneToXml(cmdparams[0]);
  775. }
  776. else
  777. {
  778. m_sceneManager.SaveCurrentSceneToXml(DEFAULT_PRIM_BACKUP_FILENAME);
  779. }
  780. }
  781. protected void LoadXml(string[] cmdparams)
  782. {
  783. 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.");
  784. Vector3 loadOffset = new Vector3(0, 0, 0);
  785. if (cmdparams.Length > 0)
  786. {
  787. bool generateNewIDS = false;
  788. if (cmdparams.Length > 1)
  789. {
  790. if (cmdparams[1] == "-newUID")
  791. {
  792. generateNewIDS = true;
  793. }
  794. if (cmdparams.Length > 2)
  795. {
  796. loadOffset.X = (float) Convert.ToDecimal(cmdparams[2]);
  797. if (cmdparams.Length > 3)
  798. {
  799. loadOffset.Y = (float) Convert.ToDecimal(cmdparams[3]);
  800. }
  801. if (cmdparams.Length > 4)
  802. {
  803. loadOffset.Z = (float) Convert.ToDecimal(cmdparams[4]);
  804. }
  805. m_console.Error("loadOffsets <X,Y,Z> = <" + loadOffset.X + "," + loadOffset.Y + "," +
  806. loadOffset.Z + ">");
  807. }
  808. }
  809. m_sceneManager.LoadCurrentSceneFromXml(cmdparams[0], generateNewIDS, loadOffset);
  810. }
  811. else
  812. {
  813. try
  814. {
  815. m_sceneManager.LoadCurrentSceneFromXml(DEFAULT_PRIM_BACKUP_FILENAME, false, loadOffset);
  816. }
  817. catch
  818. {
  819. m_console.Error("Default xml not found. Usage: load-xml <filename>");
  820. }
  821. }
  822. }
  823. protected void SaveXml2(string[] cmdparams)
  824. {
  825. if (cmdparams.Length > 0)
  826. {
  827. m_sceneManager.SaveCurrentSceneToXml2(cmdparams[0]);
  828. }
  829. else
  830. {
  831. m_sceneManager.SaveCurrentSceneToXml2(DEFAULT_PRIM_BACKUP_FILENAME);
  832. }
  833. }
  834. protected void LoadXml2(string[] cmdparams)
  835. {
  836. if (cmdparams.Length > 0)
  837. {
  838. m_sceneManager.LoadCurrentSceneFromXml2(cmdparams[0]);
  839. }
  840. else
  841. {
  842. try
  843. {
  844. m_sceneManager.LoadCurrentSceneFromXml2(DEFAULT_PRIM_BACKUP_FILENAME);
  845. }
  846. catch
  847. {
  848. m_console.Error("Default xml not found. Usage: load-xml2 <filename>");
  849. }
  850. }
  851. }
  852. /// <summary>
  853. /// Load a whole region from an opensim archive.
  854. /// </summary>
  855. /// <param name="cmdparams"></param>
  856. protected void LoadOar(string[] cmdparams)
  857. {
  858. if (cmdparams.Length > 0)
  859. {
  860. m_sceneManager.LoadArchiveToCurrentScene(cmdparams[0]);
  861. }
  862. else
  863. {
  864. try
  865. {
  866. m_sceneManager.LoadArchiveToCurrentScene(DEFAULT_OAR_BACKUP_FILENAME);
  867. }
  868. catch
  869. {
  870. m_console.Error("Default oar not found. Usage: load-oar <filename>");
  871. }
  872. }
  873. }
  874. /// <summary>
  875. /// Save a region to a file, including all the assets needed to restore it.
  876. /// </summary>
  877. /// <param name="cmdparams"></param>
  878. protected void SaveOar(string[] cmdparams)
  879. {
  880. if (cmdparams.Length > 0)
  881. {
  882. m_sceneManager.SaveCurrentSceneToArchive(cmdparams[0]);
  883. }
  884. else
  885. {
  886. m_sceneManager.SaveCurrentSceneToArchive(DEFAULT_OAR_BACKUP_FILENAME);
  887. }
  888. }
  889. /// <summary>
  890. /// Load inventory from an inventory file archive
  891. /// </summary>
  892. /// <param name="cmdparams"></param>
  893. protected void LoadInv(string[] cmdparams)
  894. {
  895. m_log.Error("[CONSOLE]: This command has not yet been implemented!");
  896. if (cmdparams.Length < 3)
  897. {
  898. m_log.Error("[CONSOLE]: usage is load-inv <first name> <last name> <inventory path> [<load file path>]");
  899. return;
  900. }
  901. string firstName = cmdparams[0];
  902. string lastName = cmdparams[1];
  903. string invPath = cmdparams[2];
  904. string loadPath = (cmdparams.Length > 3 ? cmdparams[3] : DEFAULT_INV_BACKUP_FILENAME);
  905. new InventoryArchiveReadRequest(
  906. m_sceneManager.CurrentOrFirstScene, m_commsManager).execute(
  907. firstName, lastName, invPath, loadPath);
  908. }
  909. /// <summary>
  910. /// Save inventory to a file archive
  911. /// </summary>
  912. /// <param name="cmdparams"></param>
  913. protected void SaveInv(string[] cmdparams)
  914. {
  915. m_log.Error("[CONSOLE]: This command has not yet been implemented!");
  916. if (cmdparams.Length < 3)
  917. {
  918. m_log.Error("[CONSOLE]: usage is save-inv <first name> <last name> <inventory path> [<save file path>]");
  919. return;
  920. }
  921. string firstName = cmdparams[0];
  922. string lastName = cmdparams[1];
  923. string invPath = cmdparams[2];
  924. string savePath = (cmdparams.Length > 3 ? cmdparams[3] : DEFAULT_INV_BACKUP_FILENAME);
  925. new InventoryArchiveWriteRequest(
  926. m_sceneManager.CurrentOrFirstScene,m_commsManager).execute(
  927. firstName, lastName, invPath, savePath);
  928. }
  929. private static string CombineParams(string[] commandParams, int pos)
  930. {
  931. string result = String.Empty;
  932. for (int i = pos; i < commandParams.Length; i++)
  933. {
  934. result += commandParams[i] + " ";
  935. }
  936. result = result.TrimEnd(' ');
  937. return result;
  938. }
  939. /// <summary>
  940. /// Runs the best matching plugin command
  941. ///
  942. /// returns true if a match was found, false otherwise.
  943. /// </summary>
  944. public bool RunPluginCommands(string cmd, string[] withParams)
  945. {
  946. ConsolePluginCommand bestMatch = null;
  947. int bestLength = 0;
  948. String cmdWithParams = cmd + " " + String.Join(" ",withParams);
  949. foreach (ConsolePluginCommand cmdinfo in m_PluginCommandInfos)
  950. {
  951. int matchLen = cmdinfo.matchLength(cmdWithParams);
  952. if (matchLen > bestLength)
  953. {
  954. bestMatch = cmdinfo;
  955. bestLength = matchLen;
  956. }
  957. }
  958. if (bestMatch == null) return false;
  959. bestMatch.Run(cmd,withParams);//.Substring(bestLength));
  960. return true;
  961. }
  962. /// <summary>
  963. /// Show the matching plugins command help
  964. /// </summary>
  965. public void ShowPluginCommandsHelp(string cmdWithParams, ConsoleBase console)
  966. {
  967. foreach (ConsolePluginCommand cmdinfo in m_PluginCommandInfos)
  968. {
  969. if (cmdinfo.IsHelpfull(cmdWithParams))
  970. {
  971. cmdinfo.ShowHelp(console);
  972. }
  973. }
  974. }
  975. /// <summary>
  976. /// Registers a new console plugin command
  977. /// </summary>
  978. public static void RegisterCmd(string cmd, ConsoleCommand deligate, string help)
  979. {
  980. RegisterConsolePluginCommand(new ConsolePluginCommand(cmd, deligate, help));
  981. }
  982. /// <summary>
  983. /// Registers a new console plugin command
  984. /// </summary>
  985. public static void RegisterConsolePluginCommand(ConsolePluginCommand pluginCommand)
  986. {
  987. m_PluginCommandInfos.Add(pluginCommand);
  988. }
  989. #endregion
  990. }
  991. }