OpenSim.cs 37 KB

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