ScriptEngineConsoleCommands.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 OpenSimulator 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.Generic;
  29. using OpenSim.Framework;
  30. using OpenSim.Framework.Console;
  31. using OpenSim.Region.ScriptEngine.Interfaces;
  32. using OpenSim.Region.ScriptEngine.Shared.Api;
  33. using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
  34. namespace OpenSim.Region.ScriptEngine.XEngine
  35. {
  36. public class ScriptEngineConsoleCommands
  37. {
  38. IScriptEngine m_engine;
  39. public ScriptEngineConsoleCommands(IScriptEngine engine)
  40. {
  41. m_engine = engine;
  42. }
  43. public void RegisterCommands()
  44. {
  45. MainConsole.Instance.Commands.AddCommand(
  46. "Scripts", false, "show script sensors", "show script sensors", "Show script sensors information",
  47. HandleShowSensors);
  48. MainConsole.Instance.Commands.AddCommand(
  49. "Scripts", false, "show script timers", "show script timers", "Show script sensors information",
  50. HandleShowTimers);
  51. }
  52. private bool IsSceneSelected()
  53. {
  54. return MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_engine.World;
  55. }
  56. private void HandleShowSensors(string module, string[] cmdparams)
  57. {
  58. if (!IsSceneSelected())
  59. return;
  60. SensorRepeat sr = AsyncCommandManager.GetSensorRepeatPlugin(m_engine);
  61. if (sr == null)
  62. {
  63. MainConsole.Instance.Output("Plugin not yet initialized");
  64. return;
  65. }
  66. List<SensorRepeat.SensorInfo> sensorInfo = sr.GetSensorInfo();
  67. ConsoleDisplayTable cdt = new ConsoleDisplayTable();
  68. cdt.AddColumn("Part name", 40);
  69. cdt.AddColumn("Script item ID", 36);
  70. cdt.AddColumn("Type", 4);
  71. cdt.AddColumn("Interval", 8);
  72. cdt.AddColumn("Range", 8);
  73. cdt.AddColumn("Arc", 8);
  74. foreach (SensorRepeat.SensorInfo s in sensorInfo)
  75. {
  76. cdt.AddRow(s.host.Name, s.itemID, s.type, s.interval, s.range, s.arc);
  77. }
  78. MainConsole.Instance.Output(cdt.ToString());
  79. MainConsole.Instance.OutputFormat("Total: {0}", sensorInfo.Count);
  80. }
  81. private void HandleShowTimers(string module, string[] cmdparams)
  82. {
  83. if (!IsSceneSelected())
  84. return;
  85. Timer timerPlugin = AsyncCommandManager.GetTimerPlugin(m_engine);
  86. if (timerPlugin == null)
  87. {
  88. MainConsole.Instance.Output("Plugin not yet initialized");
  89. return;
  90. }
  91. List<Timer.TimerInfo> timersInfo = timerPlugin.GetTimersInfo();
  92. ConsoleDisplayTable cdt = new ConsoleDisplayTable();
  93. cdt.AddColumn("Part local ID", 13);
  94. cdt.AddColumn("Script item ID", 36);
  95. cdt.AddColumn("Interval", 10);
  96. cdt.AddColumn("Next", 8);
  97. foreach (Timer.TimerInfo t in timersInfo)
  98. {
  99. // Convert from 100 ns ticks back to seconds
  100. cdt.AddRow(t.localID, t.itemID, (double)t.interval / 10000000, t.next);
  101. }
  102. MainConsole.Instance.Output(cdt.ToString());
  103. MainConsole.Instance.OutputFormat("Total: {0}", timersInfo.Count);
  104. }
  105. }
  106. }