diff options
Diffstat (limited to 'OpenSim/Region/OptionalModules/World/SceneCommands/SceneCommandsModule.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/World/SceneCommands/SceneCommandsModule.cs | 235 |
1 files changed, 235 insertions, 0 deletions
diff --git a/OpenSim/Region/OptionalModules/World/SceneCommands/SceneCommandsModule.cs b/OpenSim/Region/OptionalModules/World/SceneCommands/SceneCommandsModule.cs new file mode 100644 index 0000000..5fb74b0 --- /dev/null +++ b/OpenSim/Region/OptionalModules/World/SceneCommands/SceneCommandsModule.cs | |||
@@ -0,0 +1,235 @@ | |||
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 System.Linq; | ||
31 | using System.Reflection; | ||
32 | using System.Text; | ||
33 | using log4net; | ||
34 | using Mono.Addins; | ||
35 | using Nini.Config; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Console; | ||
39 | using OpenSim.Framework.Monitoring; | ||
40 | using OpenSim.Region.Framework.Interfaces; | ||
41 | using OpenSim.Region.Framework.Scenes; | ||
42 | |||
43 | namespace OpenSim.Region.OptionalModules.Avatar.Attachments | ||
44 | { | ||
45 | /// <summary> | ||
46 | /// A module that just holds commands for inspecting avatar appearance. | ||
47 | /// </summary> | ||
48 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "SceneCommandsModule")] | ||
49 | public class SceneCommandsModule : ISceneCommandsModule, INonSharedRegionModule | ||
50 | { | ||
51 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
52 | |||
53 | private Scene m_scene; | ||
54 | |||
55 | public string Name { get { return "Scene Commands Module"; } } | ||
56 | |||
57 | public Type ReplaceableInterface { get { return null; } } | ||
58 | |||
59 | public void Initialise(IConfigSource source) | ||
60 | { | ||
61 | // m_log.DebugFormat("[SCENE COMMANDS MODULE]: INITIALIZED MODULE"); | ||
62 | } | ||
63 | |||
64 | public void PostInitialise() | ||
65 | { | ||
66 | // m_log.DebugFormat("[SCENE COMMANDS MODULE]: POST INITIALIZED MODULE"); | ||
67 | } | ||
68 | |||
69 | public void Close() | ||
70 | { | ||
71 | // m_log.DebugFormat("[SCENE COMMANDS MODULE]: CLOSED MODULE"); | ||
72 | } | ||
73 | |||
74 | public void AddRegion(Scene scene) | ||
75 | { | ||
76 | // m_log.DebugFormat("[SCENE COMMANDS MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName); | ||
77 | |||
78 | m_scene = scene; | ||
79 | |||
80 | m_scene.RegisterModuleInterface<ISceneCommandsModule>(this); | ||
81 | } | ||
82 | |||
83 | public void RemoveRegion(Scene scene) | ||
84 | { | ||
85 | // m_log.DebugFormat("[SCENE COMMANDS MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName); | ||
86 | } | ||
87 | |||
88 | public void RegionLoaded(Scene scene) | ||
89 | { | ||
90 | // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName); | ||
91 | |||
92 | scene.AddCommand( | ||
93 | "Debug", this, "debug scene get", | ||
94 | "debug scene get", | ||
95 | "List current scene options.", | ||
96 | "If active is false then main scene update and maintenance loops are suspended.\n" | ||
97 | + "If animations is true then extra animations debug information is logged.\n" | ||
98 | + "If collisions is false then collisions with other objects are turned off.\n" | ||
99 | + "If pbackup is false then periodic scene backup is turned off.\n" | ||
100 | + "If physics is false then all physics objects are non-physical.\n" | ||
101 | + "If scripting is false then no scripting operations happen.\n" | ||
102 | + "If teleport is true then some extra teleport debug information is logged.\n" | ||
103 | + "If updates is true then any frame which exceeds double the maximum desired frame time is logged.", | ||
104 | HandleDebugSceneGetCommand); | ||
105 | |||
106 | scene.AddCommand( | ||
107 | "Debug", this, "debug scene set", | ||
108 | "debug scene set active|collisions|pbackup|physics|scripting|teleport|updates true|false", | ||
109 | "Turn on scene debugging options.", | ||
110 | "If active is false then main scene update and maintenance loops are suspended.\n" | ||
111 | + "If animations is true then extra animations debug information is logged.\n" | ||
112 | + "If collisions is false then collisions with other objects are turned off.\n" | ||
113 | + "If pbackup is false then periodic scene backup is turned off.\n" | ||
114 | + "If physics is false then all physics objects are non-physical.\n" | ||
115 | + "If scripting is false then no scripting operations happen.\n" | ||
116 | + "If teleport is true then some extra teleport debug information is logged.\n" | ||
117 | + "If updates is true then any frame which exceeds double the maximum desired frame time is logged.", | ||
118 | HandleDebugSceneSetCommand); | ||
119 | } | ||
120 | |||
121 | private void HandleDebugSceneGetCommand(string module, string[] args) | ||
122 | { | ||
123 | if (args.Length == 3) | ||
124 | { | ||
125 | if (MainConsole.Instance.ConsoleScene != m_scene && MainConsole.Instance.ConsoleScene != null) | ||
126 | return; | ||
127 | |||
128 | OutputSceneDebugOptions(); | ||
129 | } | ||
130 | else | ||
131 | { | ||
132 | MainConsole.Instance.Output("Usage: debug scene get"); | ||
133 | } | ||
134 | } | ||
135 | |||
136 | private void OutputSceneDebugOptions() | ||
137 | { | ||
138 | ConsoleDisplayList cdl = new ConsoleDisplayList(); | ||
139 | cdl.AddRow("active", m_scene.Active); | ||
140 | cdl.AddRow("animations", m_scene.DebugAnimations); | ||
141 | cdl.AddRow("pbackup", m_scene.PeriodicBackup); | ||
142 | cdl.AddRow("physics", m_scene.PhysicsEnabled); | ||
143 | cdl.AddRow("scripting", m_scene.ScriptsEnabled); | ||
144 | cdl.AddRow("teleport", m_scene.DebugTeleporting); | ||
145 | cdl.AddRow("updates", m_scene.DebugUpdates); | ||
146 | |||
147 | MainConsole.Instance.OutputFormat("Scene {0} options:", m_scene.Name); | ||
148 | MainConsole.Instance.Output(cdl.ToString()); | ||
149 | } | ||
150 | |||
151 | private void HandleDebugSceneSetCommand(string module, string[] args) | ||
152 | { | ||
153 | if (args.Length == 5) | ||
154 | { | ||
155 | if (MainConsole.Instance.ConsoleScene != m_scene && MainConsole.Instance.ConsoleScene != null) | ||
156 | return; | ||
157 | |||
158 | string key = args[3]; | ||
159 | string value = args[4]; | ||
160 | SetSceneDebugOptions(new Dictionary<string, string>() { { key, value } }); | ||
161 | |||
162 | MainConsole.Instance.OutputFormat("Set {0} debug scene {1} = {2}", m_scene.Name, key, value); | ||
163 | } | ||
164 | else | ||
165 | { | ||
166 | MainConsole.Instance.Output( | ||
167 | "Usage: debug scene set active|collisions|pbackup|physics|scripting|teleport|updates true|false"); | ||
168 | } | ||
169 | } | ||
170 | |||
171 | public void SetSceneDebugOptions(Dictionary<string, string> options) | ||
172 | { | ||
173 | if (options.ContainsKey("active")) | ||
174 | { | ||
175 | bool active; | ||
176 | |||
177 | if (bool.TryParse(options["active"], out active)) | ||
178 | m_scene.Active = active; | ||
179 | } | ||
180 | |||
181 | if (options.ContainsKey("animations")) | ||
182 | { | ||
183 | bool active; | ||
184 | |||
185 | if (bool.TryParse(options["animations"], out active)) | ||
186 | m_scene.DebugAnimations = active; | ||
187 | } | ||
188 | |||
189 | if (options.ContainsKey("pbackup")) | ||
190 | { | ||
191 | bool active; | ||
192 | |||
193 | if (bool.TryParse(options["pbackup"], out active)) | ||
194 | m_scene.PeriodicBackup = active; | ||
195 | } | ||
196 | |||
197 | if (options.ContainsKey("scripting")) | ||
198 | { | ||
199 | bool enableScripts = true; | ||
200 | if (bool.TryParse(options["scripting"], out enableScripts)) | ||
201 | m_scene.ScriptsEnabled = enableScripts; | ||
202 | } | ||
203 | |||
204 | if (options.ContainsKey("physics")) | ||
205 | { | ||
206 | bool enablePhysics; | ||
207 | if (bool.TryParse(options["physics"], out enablePhysics)) | ||
208 | m_scene.PhysicsEnabled = enablePhysics; | ||
209 | } | ||
210 | |||
211 | // if (options.ContainsKey("collisions")) | ||
212 | // { | ||
213 | // // TODO: Implement. If false, should stop objects colliding, though possibly should still allow | ||
214 | // // the avatar themselves to collide with the ground. | ||
215 | // } | ||
216 | |||
217 | if (options.ContainsKey("teleport")) | ||
218 | { | ||
219 | bool enableTeleportDebugging; | ||
220 | if (bool.TryParse(options["teleport"], out enableTeleportDebugging)) | ||
221 | m_scene.DebugTeleporting = enableTeleportDebugging; | ||
222 | } | ||
223 | |||
224 | if (options.ContainsKey("updates")) | ||
225 | { | ||
226 | bool enableUpdateDebugging; | ||
227 | if (bool.TryParse(options["updates"], out enableUpdateDebugging)) | ||
228 | { | ||
229 | m_scene.DebugUpdates = enableUpdateDebugging; | ||
230 | GcNotify.Enabled = enableUpdateDebugging; | ||
231 | } | ||
232 | } | ||
233 | } | ||
234 | } | ||
235 | } \ No newline at end of file | ||