OpenSim.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  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.Threading;
  34. using libsecondlife;
  35. using log4net;
  36. using Nini.Config;
  37. using OpenSim.Framework;
  38. using OpenSim.Framework.Console;
  39. using OpenSim.Framework.Statistics;
  40. using OpenSim.Region.Environment.Interfaces;
  41. using OpenSim.Region.Environment.Scenes;
  42. using Timer=System.Timers.Timer;
  43. namespace OpenSim
  44. {
  45. /// <summary>
  46. /// Interactive OpenSim region server
  47. /// </summary>
  48. public class OpenSim : OpenSimBase, conscmd_callback
  49. {
  50. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  51. protected string m_startupCommandsFile;
  52. protected string m_shutdownCommandsFile;
  53. private string m_timedScript = "disabled";
  54. private Timer m_scriptTimer;
  55. /// <summary>
  56. /// List of Console Plugin Commands
  57. /// </summary>
  58. private static List<ConsolePluginCommand> m_PluginCommandInfos = new List<ConsolePluginCommand>();
  59. public OpenSim(IConfigSource configSource) : base(configSource)
  60. {
  61. }
  62. protected override void ReadConfigSettings()
  63. {
  64. IConfig startupConfig = m_config.Source.Configs["Startup"];
  65. if (startupConfig != null)
  66. {
  67. m_startupCommandsFile = startupConfig.GetString("startup_console_commands_file", String.Empty);
  68. m_shutdownCommandsFile = startupConfig.GetString("shutdown_console_commands_file", String.Empty);
  69. m_timedScript = startupConfig.GetString("timer_Script", "disabled");
  70. }
  71. base.ReadConfigSettings();
  72. }
  73. /// <summary>
  74. /// Performs initialisation of the scene, such as loading configuration from disk.
  75. /// </summary>
  76. public override void Startup()
  77. {
  78. m_log.Info("====================================================================");
  79. m_log.Info("========================= STARTING OPENSIM =========================");
  80. m_log.Info("====================================================================");
  81. m_log.InfoFormat("[OPENSIM MAIN]: Running in {0} mode", (m_sandbox ? "sandbox" : "grid"));
  82. m_console = CreateConsole();
  83. MainConsole.Instance = m_console;
  84. base.Startup();
  85. //Run Startup Commands
  86. if (m_startupCommandsFile != String.Empty)
  87. {
  88. RunCommandScript(m_startupCommandsFile);
  89. }
  90. else
  91. {
  92. m_log.Info("[STARTUP]: No startup command script specified. Moving on...");
  93. }
  94. // Start timer script (run a script every xx seconds)
  95. if (m_timedScript != "disabled")
  96. {
  97. m_scriptTimer = new Timer();
  98. m_scriptTimer.Enabled = true;
  99. m_scriptTimer.Interval = 1200 * 1000;
  100. m_scriptTimer.Elapsed += RunAutoTimerScript;
  101. }
  102. PrintFileToConsole("startuplogo.txt");
  103. RegisterCmd("echoTest", RunEchoTest, "this echos your command args to see how they are parsed");
  104. RegisterCmd("kickuser", KickUserCommand, "kickuser [first] [last] - attempts to log off a user from any region we are serving");
  105. }
  106. protected ConsoleBase CreateConsole()
  107. {
  108. return new ConsoleBase("Region", this);
  109. }
  110. private void RunAutoTimerScript(object sender, EventArgs e)
  111. {
  112. if (m_timedScript != "disabled")
  113. {
  114. RunCommandScript(m_timedScript);
  115. }
  116. }
  117. #region Console Commands
  118. private void RunEchoTest(string[] cmdparams)
  119. {
  120. for (int i = 0; i < cmdparams.Length; i++)
  121. {
  122. m_log.Info("[EchoTest]: <arg" + i + ">"+cmdparams[i]+"</arg" + i + ">");
  123. }
  124. }
  125. private void KickUserCommand(string[] cmdparams)
  126. {
  127. if (cmdparams.Length < 2)
  128. return;
  129. IList agents = m_sceneManager.GetCurrentSceneAvatars();
  130. foreach (ScenePresence presence in agents)
  131. {
  132. RegionInfo regionInfo = m_sceneManager.GetRegionInfo(presence.RegionHandle);
  133. if (presence.Firstname.ToLower().Contains(cmdparams[0].ToLower()) && presence.Lastname.ToLower().Contains(cmdparams[1].ToLower()))
  134. {
  135. m_console.Notice(
  136. String.Format(
  137. "Kicking user: {0,-16}{1,-16}{2,-37} in region: {3,-16}",
  138. presence.Firstname,
  139. presence.Lastname,
  140. presence.UUID,
  141. regionInfo.RegionName));
  142. presence.Scene.CloseConnection(regionInfo.RegionHandle, presence.UUID);
  143. }
  144. }
  145. m_console.Notice("");
  146. }
  147. /// <summary>
  148. ///
  149. /// </summary>
  150. /// <param name="fileName"></param>
  151. private void RunCommandScript(string fileName)
  152. {
  153. m_log.Info("[COMMANDFILE]: Running " + fileName);
  154. if (File.Exists(fileName))
  155. {
  156. StreamReader readFile = File.OpenText(fileName);
  157. string currentCommand;
  158. while ((currentCommand = readFile.ReadLine()) != null)
  159. {
  160. if (currentCommand != String.Empty)
  161. {
  162. m_log.Info("[COMMANDFILE]: Running '" + currentCommand + "'");
  163. m_console.RunCommand(currentCommand);
  164. }
  165. }
  166. }
  167. else
  168. {
  169. m_log.Error("[COMMANDFILE]: Command script missing. Can not run commands");
  170. }
  171. }
  172. private static void PrintFileToConsole(string fileName)
  173. {
  174. if (File.Exists(fileName))
  175. {
  176. StreamReader readFile = File.OpenText(fileName);
  177. string currentLine;
  178. while ((currentLine = readFile.ReadLine()) != null)
  179. {
  180. m_log.Info("[!]" + currentLine);
  181. }
  182. }
  183. }
  184. /// <summary>
  185. /// Runs commands issued by the server console from the operator
  186. /// </summary>
  187. /// <param name="command">The first argument of the parameter (the command)</param>
  188. /// <param name="cmdparams">Additional arguments passed to the command</param>
  189. public override void RunCmd(string command, string[] cmdparams)
  190. {
  191. base.RunCmd(command, cmdparams);
  192. RunPluginCommands(command , cmdparams);
  193. switch (command)
  194. {
  195. case "clear-assets":
  196. m_assetCache.Clear();
  197. break;
  198. case "set-time":
  199. m_sceneManager.SetCurrentSceneTimePhase(Convert.ToInt32(cmdparams[0]));
  200. break;
  201. case "force-update":
  202. m_console.Notice("Updating all clients");
  203. m_sceneManager.ForceCurrentSceneClientUpdate();
  204. break;
  205. case "edit-scale":
  206. if (cmdparams.Length == 4)
  207. {
  208. m_sceneManager.HandleEditCommandOnCurrentScene(cmdparams);
  209. }
  210. break;
  211. case "debug":
  212. Debug(cmdparams);
  213. break;
  214. case "help":
  215. m_console.Notice("alert - send alert to a designated user or all users.");
  216. m_console.Notice(" alert [First] [Last] [Message] - send an alert to a user. Case sensitive.");
  217. m_console.Notice(" alert general [Message] - send an alert to all users.");
  218. m_console.Notice("backup - trigger a simulator backup");
  219. m_console.Notice("clear-assets - clear asset cache");
  220. m_console.Notice("create-region <name> <regionfile.xml> - creates a new region");
  221. m_console.Notice("create user - adds a new user.");
  222. m_console.Notice("change-region [name] - sets the region that many of these commands affect.");
  223. m_console.Notice("command-script [filename] - Execute command in a file.");
  224. m_console.Notice("debug - debugging commands");
  225. m_console.Notice(" debug packet 0..255 - print incoming/outgoing packets (0=off)");
  226. m_console.Notice(" debug scene [scripting] [collision] [physics] - Enable/Disable debug stuff, each can be True/False");
  227. m_console.Notice("edit-scale [prim name] [x] [y] [z] - resize given prim");
  228. m_console.Notice("export-map [filename] - save image of world map");
  229. m_console.Notice("force-update - force an update of prims in the scene");
  230. m_console.Notice("restart - disconnects all clients and restarts the sims in the instance.");
  231. m_console.Notice("remove-region [name] - remove a region");
  232. m_console.Notice("load-xml [filename] - load prims from XML (DEPRECATED)");
  233. m_console.Notice("save-xml [filename] - save prims to XML (DEPRECATED)");
  234. m_console.Notice("save-xml2 [filename] - save prims to XML using version 2 format");
  235. m_console.Notice("load-xml2 [filename] - load prims from XML using version 2 format");
  236. m_console.Notice("load-oar [filename] - load an OpenSimulator region archive. This replaces everything in the current region.");
  237. m_console.Notice("save-oar [filename] - Save the current region to an OpenSimulator region archive.");
  238. m_console.Notice("script - manually trigger scripts? or script commands?");
  239. m_console.Notice("set-time [x] - set the current scene time phase");
  240. m_console.Notice("show assets - show state of asset cache.");
  241. m_console.Notice("show users - show info about connected users.");
  242. m_console.Notice("show modules - shows info about loaded modules.");
  243. m_console.Notice("show regions - show running region information.");
  244. m_console.Notice("config set section field value - set a config value");
  245. m_console.Notice("config get section field - get a config value");
  246. m_console.Notice("config save - save OpenSim.ini");
  247. m_console.Notice("terrain help - show help for terrain commands.");
  248. ShowPluginCommandsHelp(CombineParams(cmdparams, 0), m_console);
  249. break;
  250. case "save-xml":
  251. SaveXml(cmdparams);
  252. break;
  253. case "load-xml":
  254. LoadXml(cmdparams);
  255. break;
  256. case "save-xml2":
  257. SaveXml2(cmdparams);
  258. break;
  259. case "load-xml2":
  260. LoadXml2(cmdparams);
  261. break;
  262. case "save-prims-xml2":
  263. if (cmdparams.Length > 1)
  264. {
  265. m_sceneManager.SaveNamedPrimsToXml2(cmdparams[0], cmdparams[1]);
  266. }
  267. else
  268. {
  269. m_sceneManager.SaveNamedPrimsToXml2("Primitive", DEFAULT_PRIM_BACKUP_FILENAME);
  270. }
  271. break;
  272. case "load-oar":
  273. LoadOar(cmdparams);
  274. break;
  275. case "save-oar":
  276. SaveOar(cmdparams);
  277. break;
  278. case "plugin":
  279. m_sceneManager.SendCommandToPluginModules(cmdparams);
  280. break;
  281. case "command-script":
  282. if (cmdparams.Length > 0)
  283. {
  284. RunCommandScript(cmdparams[0]);
  285. }
  286. break;
  287. case "backup":
  288. m_sceneManager.BackupCurrentScene();
  289. break;
  290. case "alert":
  291. m_sceneManager.HandleAlertCommandOnCurrentScene(cmdparams);
  292. break;
  293. case "create":
  294. CreateAccount(cmdparams);
  295. break;
  296. case "create-region":
  297. CreateRegion(new RegionInfo(cmdparams[0], "Regions/" + cmdparams[1],false), true);
  298. break;
  299. case "remove-region":
  300. string regName = CombineParams(cmdparams, 0);
  301. Scene killScene;
  302. if (m_sceneManager.TryGetScene(regName, out killScene))
  303. {
  304. // only need to check this if we are not at the
  305. // root level
  306. if ((m_sceneManager.CurrentScene != null) &&
  307. (m_sceneManager.CurrentScene.RegionInfo.RegionID == killScene.RegionInfo.RegionID))
  308. {
  309. m_sceneManager.TrySetCurrentScene("..");
  310. }
  311. m_regionData.Remove(killScene.RegionInfo);
  312. m_sceneManager.CloseScene(killScene);
  313. }
  314. break;
  315. case "restart":
  316. m_sceneManager.RestartCurrentScene();
  317. break;
  318. case "change-region":
  319. if (cmdparams.Length > 0)
  320. {
  321. string regionName = CombineParams(cmdparams, 0);
  322. if (!m_sceneManager.TrySetCurrentScene(regionName))
  323. {
  324. m_console.Error("Couldn't set current region to: " + regionName);
  325. }
  326. }
  327. if (m_sceneManager.CurrentScene == null)
  328. {
  329. m_console.Error("CONSOLE", "Currently at Root level. To change region please use 'change-region <regioname>'");
  330. }
  331. else
  332. {
  333. m_console.Error("CONSOLE", "Current Region: " + m_sceneManager.CurrentScene.RegionInfo.RegionName +
  334. ". To change region please use 'change-region <regioname>'");
  335. }
  336. break;
  337. case "export-map":
  338. if (cmdparams.Length > 0)
  339. {
  340. m_sceneManager.CurrentOrFirstScene.ExportWorldMap(cmdparams[0]);
  341. }
  342. else
  343. {
  344. m_sceneManager.CurrentOrFirstScene.ExportWorldMap("exportmap.jpg");
  345. }
  346. break;
  347. case "config":
  348. string n = command.ToUpper();
  349. if (cmdparams.Length > 0)
  350. {
  351. switch (cmdparams[0].ToLower())
  352. {
  353. case "set":
  354. if (cmdparams.Length < 4)
  355. {
  356. m_console.Error(n, "SYNTAX: " + n + " SET SECTION KEY VALUE");
  357. m_console.Error(n, "EXAMPLE: " + n + " SET ScriptEngine.DotNetEngine NumberOfScriptThreads 5");
  358. }
  359. else
  360. {
  361. IConfig c = DefaultConfig().Configs[cmdparams[1]];
  362. if (c == null)
  363. c = DefaultConfig().AddConfig(cmdparams[1]);
  364. string _value = String.Join(" ", cmdparams, 3, cmdparams.Length - 3);
  365. c.Set(cmdparams[2], _value);
  366. m_config.Source.Merge(c.ConfigSource);
  367. m_console.Error(n, n + " " + n + " " + cmdparams[1] + " " + cmdparams[2] + " " +
  368. _value);
  369. }
  370. break;
  371. case "get":
  372. if (cmdparams.Length < 3)
  373. {
  374. m_console.Error(n, "SYNTAX: " + n + " GET SECTION KEY");
  375. m_console.Error(n, "EXAMPLE: " + n + " GET ScriptEngine.DotNetEngine NumberOfScriptThreads");
  376. }
  377. else
  378. {
  379. IConfig c = DefaultConfig().Configs[cmdparams[1]];
  380. if (c == null)
  381. {
  382. m_console.Notice(n, "Section \"" + cmdparams[1] + "\" does not exist.");
  383. break;
  384. }
  385. else
  386. {
  387. m_console.Notice(n + " GET " + cmdparams[1] + " " + cmdparams[2] + ": " +
  388. c.GetString(cmdparams[2]));
  389. }
  390. }
  391. break;
  392. case "save":
  393. m_console.Notice("Saving configuration file: " + Application.iniFilePath);
  394. m_config.Save(Application.iniFilePath);
  395. break;
  396. }
  397. }
  398. break;
  399. case "modules":
  400. if (cmdparams.Length > 0)
  401. {
  402. switch (cmdparams[0].ToLower())
  403. {
  404. case "list":
  405. foreach (IRegionModule irm in m_moduleLoader.GetLoadedSharedModules)
  406. {
  407. m_console.Notice("Shared region module: " + irm.Name);
  408. }
  409. break;
  410. case "unload":
  411. if (cmdparams.Length > 1)
  412. {
  413. foreach (IRegionModule rm in new ArrayList(m_moduleLoader.GetLoadedSharedModules))
  414. {
  415. if (rm.Name.ToLower() == cmdparams[1].ToLower())
  416. {
  417. m_console.Notice("Unloading module: " + rm.Name);
  418. m_moduleLoader.UnloadModule(rm);
  419. }
  420. }
  421. }
  422. break;
  423. case "load":
  424. if (cmdparams.Length > 1)
  425. {
  426. foreach (Scene s in new ArrayList(m_sceneManager.Scenes))
  427. {
  428. m_console.Notice("Loading module: " + cmdparams[1]);
  429. m_moduleLoader.LoadRegionModules(cmdparams[1], s);
  430. }
  431. }
  432. break;
  433. }
  434. }
  435. break;
  436. case "Add-InventoryHost":
  437. if (cmdparams.Length > 0)
  438. {
  439. m_commsManager.AddInventoryService(cmdparams[0]);
  440. }
  441. break;
  442. default:
  443. string[] tmpPluginArgs = new string[cmdparams.Length + 1];
  444. cmdparams.CopyTo(tmpPluginArgs, 1);
  445. tmpPluginArgs[0] = command;
  446. m_sceneManager.SendCommandToPluginModules(tmpPluginArgs);
  447. break;
  448. }
  449. }
  450. /// <summary>
  451. /// Turn on some debugging values for OpenSim.
  452. /// </summary>
  453. /// <param name="args"></param>
  454. protected void Debug(string[] args)
  455. {
  456. if (args.Length == 0)
  457. return;
  458. switch (args[0])
  459. {
  460. case "packet":
  461. if (args.Length > 1)
  462. {
  463. int newDebug;
  464. if (int.TryParse(args[1], out newDebug))
  465. {
  466. m_sceneManager.SetDebugPacketOnCurrentScene(newDebug);
  467. }
  468. else
  469. {
  470. m_console.Error("packet debug should be 0..2");
  471. }
  472. m_console.Notice("New packet debug: " + newDebug.ToString());
  473. }
  474. break;
  475. case "scene":
  476. if (args.Length == 4)
  477. {
  478. if (m_sceneManager.CurrentScene == null)
  479. {
  480. m_console.Error("CONSOLE", "Please use 'change-region <regioname>' first");
  481. }
  482. else
  483. {
  484. bool scriptingOn = !Convert.ToBoolean(args[1]);
  485. bool collisionsOn = !Convert.ToBoolean(args[2]);
  486. bool physicsOn = !Convert.ToBoolean(args[3]);
  487. m_sceneManager.CurrentScene.SetSceneCoreDebug(scriptingOn, collisionsOn, physicsOn);
  488. m_console.Notice(
  489. "CONSOLE",
  490. String.Format(
  491. "Set debug scene scripting = {0}, collisions = {1}, physics = {2}",
  492. !scriptingOn, !collisionsOn, !physicsOn));
  493. }
  494. }
  495. else
  496. {
  497. m_console.Error("debug scene <scripting> <collisions> <physics> (where inside <> is true/false)");
  498. }
  499. break;
  500. default:
  501. m_console.Error("Unknown debug");
  502. break;
  503. }
  504. }
  505. // see BaseOpenSimServer
  506. public override void Show(string ShowWhat)
  507. {
  508. base.Show(ShowWhat);
  509. switch (ShowWhat)
  510. {
  511. case "assets":
  512. m_assetCache.ShowState();
  513. break;
  514. case "users":
  515. IList agents = m_sceneManager.GetCurrentSceneAvatars();
  516. m_console.Notice(String.Format("\nAgents connected: {0}\n", agents.Count));
  517. m_console.Notice(
  518. String.Format("{0,-16}{1,-16}{2,-37}{3,-16}", "Firstname", "Lastname",
  519. "Agent ID","Region"));
  520. foreach (ScenePresence presence in agents)
  521. {
  522. RegionInfo regionInfo = m_sceneManager.GetRegionInfo(presence.RegionHandle);
  523. string regionName;
  524. if (regionInfo == null)
  525. {
  526. regionName = "Unresolvable";
  527. }
  528. else
  529. {
  530. regionName = regionInfo.RegionName;
  531. }
  532. m_console.Notice(
  533. String.Format(
  534. "{0,-16}{1,-16}{2,-37}{3,-16}",
  535. presence.Firstname,
  536. presence.Lastname,
  537. presence.UUID,
  538. regionName));
  539. }
  540. m_console.Notice("");
  541. break;
  542. case "modules":
  543. m_console.Notice("The currently loaded shared modules are:");
  544. foreach (IRegionModule module in m_moduleLoader.GetLoadedSharedModules)
  545. {
  546. m_console.Notice("Shared Module: " + module.Name);
  547. }
  548. break;
  549. case "regions":
  550. m_sceneManager.ForEachScene(
  551. delegate(Scene scene)
  552. {
  553. m_console.Notice("Region Name: " + scene.RegionInfo.RegionName + " , Region XLoc: " +
  554. scene.RegionInfo.RegionLocX + " , Region YLoc: " +
  555. scene.RegionInfo.RegionLocY + " , Region Port: " + scene.RegionInfo.InternalEndPoint.Port.ToString());
  556. });
  557. break;
  558. }
  559. }
  560. protected void SaveXml(string[] cmdparams)
  561. {
  562. 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.");
  563. if (cmdparams.Length > 0)
  564. {
  565. m_sceneManager.SaveCurrentSceneToXml(cmdparams[0]);
  566. }
  567. else
  568. {
  569. m_sceneManager.SaveCurrentSceneToXml(DEFAULT_PRIM_BACKUP_FILENAME);
  570. }
  571. }
  572. protected void LoadXml(string[] cmdparams)
  573. {
  574. 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.");
  575. LLVector3 loadOffset = new LLVector3(0, 0, 0);
  576. if (cmdparams.Length > 0)
  577. {
  578. bool generateNewIDS = false;
  579. if (cmdparams.Length > 1)
  580. {
  581. if (cmdparams[1] == "-newUID")
  582. {
  583. generateNewIDS = true;
  584. }
  585. if (cmdparams.Length > 2)
  586. {
  587. loadOffset.X = (float) Convert.ToDecimal(cmdparams[2]);
  588. if (cmdparams.Length > 3)
  589. {
  590. loadOffset.Y = (float) Convert.ToDecimal(cmdparams[3]);
  591. }
  592. if (cmdparams.Length > 4)
  593. {
  594. loadOffset.Z = (float) Convert.ToDecimal(cmdparams[4]);
  595. }
  596. m_console.Error("loadOffsets <X,Y,Z> = <" + loadOffset.X + "," + loadOffset.Y + "," +
  597. loadOffset.Z + ">");
  598. }
  599. }
  600. m_sceneManager.LoadCurrentSceneFromXml(cmdparams[0], generateNewIDS, loadOffset);
  601. }
  602. else
  603. {
  604. m_sceneManager.LoadCurrentSceneFromXml(DEFAULT_PRIM_BACKUP_FILENAME, false, loadOffset);
  605. }
  606. }
  607. protected void SaveXml2(string[] cmdparams)
  608. {
  609. if (cmdparams.Length > 0)
  610. {
  611. m_sceneManager.SaveCurrentSceneToXml2(cmdparams[0]);
  612. }
  613. else
  614. {
  615. m_sceneManager.SaveCurrentSceneToXml2(DEFAULT_PRIM_BACKUP_FILENAME);
  616. }
  617. }
  618. protected void LoadXml2(string[] cmdparams)
  619. {
  620. if (cmdparams.Length > 0)
  621. {
  622. m_sceneManager.LoadCurrentSceneFromXml2(cmdparams[0]);
  623. }
  624. else
  625. {
  626. m_sceneManager.LoadCurrentSceneFromXml2(DEFAULT_PRIM_BACKUP_FILENAME);
  627. }
  628. }
  629. protected void LoadOar(string[] cmdparams)
  630. {
  631. m_log.Warn("[CONSOLE]: Highly experimental functionality. Please don't rely on this.");
  632. if (cmdparams.Length > 0)
  633. {
  634. m_sceneManager.LoadArchiveToCurrentScene(cmdparams[0]);
  635. }
  636. else
  637. {
  638. m_sceneManager.LoadArchiveToCurrentScene(DEFAULT_OAR_BACKUP_FILENAME);
  639. }
  640. }
  641. protected void SaveOar(string[] cmdparams)
  642. {
  643. m_log.Warn("[CONSOLE]: Highly experimental functionality. Please don't rely on this.");
  644. if (cmdparams.Length > 0)
  645. {
  646. m_sceneManager.SaveCurrentSceneToArchive(cmdparams[0]);
  647. }
  648. else
  649. {
  650. m_sceneManager.SaveCurrentSceneToArchive(DEFAULT_OAR_BACKUP_FILENAME);
  651. }
  652. }
  653. private static string CombineParams(string[] commandParams, int pos)
  654. {
  655. string result = String.Empty;
  656. for (int i = pos; i < commandParams.Length; i++)
  657. {
  658. result += commandParams[i] + " ";
  659. }
  660. result = result.TrimEnd(' ');
  661. return result;
  662. }
  663. /// <summary>
  664. /// Runs the best matching plugin command
  665. ///
  666. /// returns true if a match was found, false otherwise.
  667. /// </summary>
  668. public bool RunPluginCommands(string cmd, string[] withParams)
  669. {
  670. ConsolePluginCommand bestMatch = null;
  671. int bestLength = 0;
  672. String cmdWithParams = cmd + " " + String.Join(" ",withParams);
  673. foreach (ConsolePluginCommand cmdinfo in m_PluginCommandInfos)
  674. {
  675. int matchLen = cmdinfo.matchLength(cmdWithParams);
  676. if (matchLen > bestLength)
  677. {
  678. bestMatch = cmdinfo;
  679. bestLength = matchLen;
  680. }
  681. }
  682. if (bestMatch == null) return false;
  683. bestMatch.Run(cmd,withParams);//.Substring(bestLength));
  684. return true;
  685. }
  686. /// <summary>
  687. /// Show the matching plugins command help
  688. /// </summary>
  689. public void ShowPluginCommandsHelp(string cmdWithParams, ConsoleBase console)
  690. {
  691. foreach (ConsolePluginCommand cmdinfo in m_PluginCommandInfos)
  692. {
  693. if (cmdinfo.IsHelpfull(cmdWithParams))
  694. {
  695. cmdinfo.ShowHelp(console);
  696. }
  697. }
  698. }
  699. /// <summary>
  700. /// Registers a new console plugin command
  701. /// </summary>
  702. public static void RegisterCmd(string cmd, ConsoleCommand deligate, string help)
  703. {
  704. RegisterConsolePluginCommand(new ConsolePluginCommand(cmd, deligate, help));
  705. }
  706. /// <summary>
  707. /// Registers a new console plugin command
  708. /// </summary>
  709. public static void RegisterConsolePluginCommand(ConsolePluginCommand pluginCommand)
  710. {
  711. m_PluginCommandInfos.Add(pluginCommand);
  712. }
  713. #endregion
  714. }
  715. }