diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine/XEngine')
-rw-r--r-- | OpenSim/Region/ScriptEngine/XEngine/ScriptEngineConsoleCommands.cs | 126 | ||||
-rw-r--r-- | OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 69 |
2 files changed, 164 insertions, 31 deletions
diff --git a/OpenSim/Region/ScriptEngine/XEngine/ScriptEngineConsoleCommands.cs b/OpenSim/Region/ScriptEngine/XEngine/ScriptEngineConsoleCommands.cs new file mode 100644 index 0000000..efb854d --- /dev/null +++ b/OpenSim/Region/ScriptEngine/XEngine/ScriptEngineConsoleCommands.cs | |||
@@ -0,0 +1,126 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using OpenSim.Framework; | ||
31 | using OpenSim.Framework.Console; | ||
32 | using OpenSim.Region.ScriptEngine.Interfaces; | ||
33 | using OpenSim.Region.ScriptEngine.Shared.Api; | ||
34 | using OpenSim.Region.ScriptEngine.Shared.Api.Plugins; | ||
35 | |||
36 | namespace OpenSim.Region.ScriptEngine.XEngine | ||
37 | { | ||
38 | public class ScriptEngineConsoleCommands | ||
39 | { | ||
40 | IScriptEngine m_engine; | ||
41 | |||
42 | public ScriptEngineConsoleCommands(IScriptEngine engine) | ||
43 | { | ||
44 | m_engine = engine; | ||
45 | } | ||
46 | |||
47 | public void RegisterCommands() | ||
48 | { | ||
49 | MainConsole.Instance.Commands.AddCommand( | ||
50 | "Scripts", false, "show script sensors", "show script sensors", "Show script sensors information", | ||
51 | HandleShowSensors); | ||
52 | |||
53 | MainConsole.Instance.Commands.AddCommand( | ||
54 | "Scripts", false, "show script timers", "show script timers", "Show script sensors information", | ||
55 | HandleShowTimers); | ||
56 | } | ||
57 | |||
58 | private bool IsSceneSelected() | ||
59 | { | ||
60 | return MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_engine.World; | ||
61 | } | ||
62 | |||
63 | private void HandleShowSensors(string module, string[] cmdparams) | ||
64 | { | ||
65 | if (!IsSceneSelected()) | ||
66 | return; | ||
67 | |||
68 | SensorRepeat sr = AsyncCommandManager.GetSensorRepeatPlugin(m_engine); | ||
69 | |||
70 | if (sr == null) | ||
71 | { | ||
72 | MainConsole.Instance.Output("Plugin not yet initialized"); | ||
73 | return; | ||
74 | } | ||
75 | |||
76 | List<SensorRepeat.SensorInfo> sensorInfo = sr.GetSensorInfo(); | ||
77 | |||
78 | ConsoleDisplayTable cdt = new ConsoleDisplayTable(); | ||
79 | cdt.AddColumn("Part name", 40); | ||
80 | cdt.AddColumn("Script item ID", 36); | ||
81 | cdt.AddColumn("Type", 4); | ||
82 | cdt.AddColumn("Interval", 8); | ||
83 | cdt.AddColumn("Range", 8); | ||
84 | cdt.AddColumn("Arc", 8); | ||
85 | |||
86 | foreach (SensorRepeat.SensorInfo s in sensorInfo) | ||
87 | { | ||
88 | cdt.AddRow(s.host.Name, s.itemID, s.type, s.interval, s.range, s.arc); | ||
89 | } | ||
90 | |||
91 | MainConsole.Instance.Output(cdt.ToString()); | ||
92 | MainConsole.Instance.OutputFormat("Total: {0}", sensorInfo.Count); | ||
93 | } | ||
94 | |||
95 | private void HandleShowTimers(string module, string[] cmdparams) | ||
96 | { | ||
97 | if (!IsSceneSelected()) | ||
98 | return; | ||
99 | |||
100 | Timer timerPlugin = AsyncCommandManager.GetTimerPlugin(m_engine); | ||
101 | |||
102 | if (timerPlugin == null) | ||
103 | { | ||
104 | MainConsole.Instance.Output("Plugin not yet initialized"); | ||
105 | return; | ||
106 | } | ||
107 | |||
108 | List<Timer.TimerInfo> timersInfo = timerPlugin.GetTimersInfo(); | ||
109 | |||
110 | ConsoleDisplayTable cdt = new ConsoleDisplayTable(); | ||
111 | cdt.AddColumn("Part local ID", 13); | ||
112 | cdt.AddColumn("Script item ID", 36); | ||
113 | cdt.AddColumn("Interval", 10); | ||
114 | cdt.AddColumn("Next", 8); | ||
115 | |||
116 | foreach (Timer.TimerInfo t in timersInfo) | ||
117 | { | ||
118 | // Convert from 100 ns ticks back to seconds | ||
119 | cdt.AddRow(t.localID, t.itemID, (double)t.interval / 10000000, t.next); | ||
120 | } | ||
121 | |||
122 | MainConsole.Instance.Output(cdt.ToString()); | ||
123 | MainConsole.Instance.OutputFormat("Total: {0}", timersInfo.Count); | ||
124 | } | ||
125 | } | ||
126 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 05dd7ab..34fcf0c 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | |||
@@ -237,6 +237,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
237 | } | 237 | } |
238 | } | 238 | } |
239 | 239 | ||
240 | private ScriptEngineConsoleCommands m_consoleCommands; | ||
241 | |||
240 | public string ScriptEngineName | 242 | public string ScriptEngineName |
241 | { | 243 | { |
242 | get { return "XEngine"; } | 244 | get { return "XEngine"; } |
@@ -386,50 +388,53 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
386 | OnObjectRemoved += m_XmlRpcRouter.ObjectRemoved; | 388 | OnObjectRemoved += m_XmlRpcRouter.ObjectRemoved; |
387 | } | 389 | } |
388 | 390 | ||
391 | m_consoleCommands = new ScriptEngineConsoleCommands(this); | ||
392 | m_consoleCommands.RegisterCommands(); | ||
393 | |||
389 | MainConsole.Instance.Commands.AddCommand( | 394 | MainConsole.Instance.Commands.AddCommand( |
390 | "Scripts", false, "xengine status", "xengine status", "Show status information", | 395 | "Scripts", false, "xengine status", "xengine status", "Show status information", |
391 | "Show status information on the script engine.", | 396 | "Show status information on the script engine.", |
392 | HandleShowStatus); | 397 | HandleShowStatus); |
393 | 398 | ||
394 | MainConsole.Instance.Commands.AddCommand( | 399 | MainConsole.Instance.Commands.AddCommand( |
395 | "Scripts", false, "scripts show", "scripts show [<script-item-uuid>]", "Show script information", | 400 | "Scripts", false, "scripts show", "scripts show [<script-item-uuid>+]", "Show script information", |
396 | "Show information on all scripts known to the script engine.\n" | 401 | "Show information on all scripts known to the script engine.\n" |
397 | + "If a <script-item-uuid> is given then only information on that script will be shown.", | 402 | + "If one or more <script-item-uuid>s are given then only information on that script will be shown.", |
398 | HandleShowScripts); | 403 | HandleShowScripts); |
399 | 404 | ||
400 | MainConsole.Instance.Commands.AddCommand( | 405 | MainConsole.Instance.Commands.AddCommand( |
401 | "Scripts", false, "show scripts", "show scripts [<script-item-uuid>]", "Show script information", | 406 | "Scripts", false, "show scripts", "show scripts [<script-item-uuid>+]", "Show script information", |
402 | "Synonym for scripts show command", HandleShowScripts); | 407 | "Synonym for scripts show command", HandleShowScripts); |
403 | 408 | ||
404 | MainConsole.Instance.Commands.AddCommand( | 409 | MainConsole.Instance.Commands.AddCommand( |
405 | "Scripts", false, "scripts suspend", "scripts suspend [<script-item-uuid>]", "Suspends all running scripts", | 410 | "Scripts", false, "scripts suspend", "scripts suspend [<script-item-uuid>+]", "Suspends all running scripts", |
406 | "Suspends all currently running scripts. This only suspends event delivery, it will not suspend a" | 411 | "Suspends all currently running scripts. This only suspends event delivery, it will not suspend a" |
407 | + " script that is currently processing an event.\n" | 412 | + " script that is currently processing an event.\n" |
408 | + "Suspended scripts will continue to accumulate events but won't process them.\n" | 413 | + "Suspended scripts will continue to accumulate events but won't process them.\n" |
409 | + "If a <script-item-uuid> is given then only that script will be suspended. Otherwise, all suitable scripts are suspended.", | 414 | + "If one or more <script-item-uuid>s are given then only that script will be suspended. Otherwise, all suitable scripts are suspended.", |
410 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleSuspendScript)); | 415 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleSuspendScript)); |
411 | 416 | ||
412 | MainConsole.Instance.Commands.AddCommand( | 417 | MainConsole.Instance.Commands.AddCommand( |
413 | "Scripts", false, "scripts resume", "scripts resume [<script-item-uuid>]", "Resumes all suspended scripts", | 418 | "Scripts", false, "scripts resume", "scripts resume [<script-item-uuid>+]", "Resumes all suspended scripts", |
414 | "Resumes all currently suspended scripts.\n" | 419 | "Resumes all currently suspended scripts.\n" |
415 | + "Resumed scripts will process all events accumulated whilst suspended.\n" | 420 | + "Resumed scripts will process all events accumulated whilst suspended.\n" |
416 | + "If a <script-item-uuid> is given then only that script will be resumed. Otherwise, all suitable scripts are resumed.", | 421 | + "If one or more <script-item-uuid>s are given then only that script will be resumed. Otherwise, all suitable scripts are resumed.", |
417 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleResumeScript)); | 422 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleResumeScript)); |
418 | 423 | ||
419 | MainConsole.Instance.Commands.AddCommand( | 424 | MainConsole.Instance.Commands.AddCommand( |
420 | "Scripts", false, "scripts stop", "scripts stop [<script-item-uuid>]", "Stops all running scripts", | 425 | "Scripts", false, "scripts stop", "scripts stop [<script-item-uuid>+]", "Stops all running scripts", |
421 | "Stops all running scripts.\n" | 426 | "Stops all running scripts.\n" |
422 | + "If a <script-item-uuid> is given then only that script will be stopped. Otherwise, all suitable scripts are stopped.", | 427 | + "If one or more <script-item-uuid>s are given then only that script will be stopped. Otherwise, all suitable scripts are stopped.", |
423 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStopScript)); | 428 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStopScript)); |
424 | 429 | ||
425 | MainConsole.Instance.Commands.AddCommand( | 430 | MainConsole.Instance.Commands.AddCommand( |
426 | "Scripts", false, "scripts start", "scripts start [<script-item-uuid>]", "Starts all stopped scripts", | 431 | "Scripts", false, "scripts start", "scripts start [<script-item-uuid>+]", "Starts all stopped scripts", |
427 | "Starts all stopped scripts.\n" | 432 | "Starts all stopped scripts.\n" |
428 | + "If a <script-item-uuid> is given then only that script will be started. Otherwise, all suitable scripts are started.", | 433 | + "If one or more <script-item-uuid>s are given then only that script will be started. Otherwise, all suitable scripts are started.", |
429 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStartScript)); | 434 | (module, cmdparams) => HandleScriptsAction(cmdparams, HandleStartScript)); |
430 | 435 | ||
431 | MainConsole.Instance.Commands.AddCommand( | 436 | MainConsole.Instance.Commands.AddCommand( |
432 | "Scripts", false, "debug script log", "debug scripts log <item-id> <log-level>", "Extra debug logging for a script", | 437 | "Scripts", false, "debug scripts log", "debug scripts log <item-id> <log-level>", "Extra debug logging for a script", |
433 | "Activates or deactivates extra debug logging for the given script.\n" | 438 | "Activates or deactivates extra debug logging for the given script.\n" |
434 | + "Level == 0, deactivate extra debug logging.\n" | 439 | + "Level == 0, deactivate extra debug logging.\n" |
435 | + "Level >= 1, log state changes.\n" | 440 | + "Level >= 1, log state changes.\n" |
@@ -546,29 +551,31 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
546 | return; | 551 | return; |
547 | } | 552 | } |
548 | 553 | ||
549 | rawItemId = cmdparams[2]; | 554 | for (int i = 2; i < cmdparams.Length; i++) |
550 | |||
551 | if (!UUID.TryParse(rawItemId, out itemId)) | ||
552 | { | 555 | { |
553 | MainConsole.Instance.OutputFormat("ERROR: {0} is not a valid UUID", rawItemId); | 556 | rawItemId = cmdparams[i]; |
554 | return; | 557 | |
555 | } | 558 | if (!UUID.TryParse(rawItemId, out itemId)) |
556 | |||
557 | if (itemId != UUID.Zero) | ||
558 | { | ||
559 | IScriptInstance instance = GetInstance(itemId); | ||
560 | if (instance == null) | ||
561 | { | 559 | { |
562 | // Commented out for now since this will cause false reports on simulators with more than | 560 | MainConsole.Instance.OutputFormat("ERROR: {0} is not a valid UUID", rawItemId); |
563 | // one scene where the current command line set region is 'root' (which causes commands to | 561 | continue; |
564 | // go to both regions... (sigh) | ||
565 | // MainConsole.Instance.OutputFormat("Error - No item found with id {0}", itemId); | ||
566 | return; | ||
567 | } | 562 | } |
568 | else | 563 | |
564 | if (itemId != UUID.Zero) | ||
569 | { | 565 | { |
570 | action(instance); | 566 | IScriptInstance instance = GetInstance(itemId); |
571 | return; | 567 | if (instance == null) |
568 | { | ||
569 | // Commented out for now since this will cause false reports on simulators with more than | ||
570 | // one scene where the current command line set region is 'root' (which causes commands to | ||
571 | // go to both regions... (sigh) | ||
572 | // MainConsole.Instance.OutputFormat("Error - No item found with id {0}", itemId); | ||
573 | continue; | ||
574 | } | ||
575 | else | ||
576 | { | ||
577 | action(instance); | ||
578 | } | ||
572 | } | 579 | } |
573 | } | 580 | } |
574 | } | 581 | } |