diff options
Diffstat (limited to 'OpenSim/Region/OptionalModules/World/SceneCommands/SceneCommandsModule.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/World/SceneCommands/SceneCommandsModule.cs | 236 |
1 files changed, 236 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..5dbf207 --- /dev/null +++ b/OpenSim/Region/OptionalModules/World/SceneCommands/SceneCommandsModule.cs | |||
@@ -0,0 +1,236 @@ | |||
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 | // private IAvatarFactoryModule m_avatarFactory; | ||
55 | |||
56 | public string Name { get { return "Scene Commands Module"; } } | ||
57 | |||
58 | public Type ReplaceableInterface { get { return null; } } | ||
59 | |||
60 | public void Initialise(IConfigSource source) | ||
61 | { | ||
62 | // m_log.DebugFormat("[SCENE COMMANDS MODULE]: INITIALIZED MODULE"); | ||
63 | } | ||
64 | |||
65 | public void PostInitialise() | ||
66 | { | ||
67 | // m_log.DebugFormat("[SCENE COMMANDS MODULE]: POST INITIALIZED MODULE"); | ||
68 | } | ||
69 | |||
70 | public void Close() | ||
71 | { | ||
72 | // m_log.DebugFormat("[SCENE COMMANDS MODULE]: CLOSED MODULE"); | ||
73 | } | ||
74 | |||
75 | public void AddRegion(Scene scene) | ||
76 | { | ||
77 | // m_log.DebugFormat("[SCENE COMMANDS MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName); | ||
78 | |||
79 | m_scene = scene; | ||
80 | } | ||
81 | |||
82 | public void RemoveRegion(Scene scene) | ||
83 | { | ||
84 | // m_log.DebugFormat("[SCENE COMMANDS MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName); | ||
85 | } | ||
86 | |||
87 | public void RegionLoaded(Scene scene) | ||
88 | { | ||
89 | // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName); | ||
90 | |||
91 | scene.AddCommand( | ||
92 | "Debug", this, "debug scene set", | ||
93 | "debug scene set active|collisions|pbackup|physics|scripting|teleport|updates true|false", | ||
94 | "Turn on scene debugging options.", | ||
95 | "If active is false then main scene update and maintenance loops are suspended.\n" | ||
96 | + "If collisions is false then collisions with other objects are turned off.\n" | ||
97 | + "If pbackup is false then periodic scene backup is turned off.\n" | ||
98 | + "If physics is false then all physics objects are non-physical.\n" | ||
99 | + "If scripting is false then no scripting operations happen.\n" | ||
100 | + "If teleport is true then some extra teleport debug information is logged.\n" | ||
101 | + "If updates is true then any frame which exceeds double the maximum desired frame time is logged.", | ||
102 | HandleDebugSceneCommand); | ||
103 | } | ||
104 | |||
105 | private void HandleDebugSceneCommand(string module, string[] args) | ||
106 | { | ||
107 | if (args.Length == 5) | ||
108 | { | ||
109 | if (MainConsole.Instance.ConsoleScene == null) | ||
110 | { | ||
111 | MainConsole.Instance.Output("Please use 'change region <regioname>' first"); | ||
112 | } | ||
113 | else | ||
114 | { | ||
115 | string key = args[3]; | ||
116 | string value = args[4]; | ||
117 | SetSceneDebugOptions(new Dictionary<string, string>() { { key, value } }); | ||
118 | |||
119 | MainConsole.Instance.OutputFormat("Set debug scene {0} = {1}", key, value); | ||
120 | } | ||
121 | } | ||
122 | else | ||
123 | { | ||
124 | MainConsole.Instance.Output( | ||
125 | "Usage: debug scene set active|collisions|pbackup|physics|scripting|teleport|updates true|false"); | ||
126 | } | ||
127 | } | ||
128 | |||
129 | public void SetSceneDebugOptions(Dictionary<string, string> options) | ||
130 | { | ||
131 | if (options.ContainsKey("active")) | ||
132 | { | ||
133 | bool active; | ||
134 | |||
135 | if (bool.TryParse(options["active"], out active)) | ||
136 | m_scene.Active = active; | ||
137 | } | ||
138 | |||
139 | if (options.ContainsKey("pbackup")) | ||
140 | { | ||
141 | bool active; | ||
142 | |||
143 | if (bool.TryParse(options["pbackup"], out active)) | ||
144 | m_scene.PeriodicBackup = active; | ||
145 | } | ||
146 | |||
147 | if (options.ContainsKey("scripting")) | ||
148 | { | ||
149 | bool enableScripts = true; | ||
150 | if (bool.TryParse(options["scripting"], out enableScripts)) | ||
151 | m_scene.ScriptsEnabled = enableScripts; | ||
152 | } | ||
153 | |||
154 | if (options.ContainsKey("physics")) | ||
155 | { | ||
156 | bool enablePhysics; | ||
157 | if (bool.TryParse(options["physics"], out enablePhysics)) | ||
158 | m_scene.PhysicsEnabled = enablePhysics; | ||
159 | } | ||
160 | |||
161 | // if (options.ContainsKey("collisions")) | ||
162 | // { | ||
163 | // // TODO: Implement. If false, should stop objects colliding, though possibly should still allow | ||
164 | // // the avatar themselves to collide with the ground. | ||
165 | // } | ||
166 | |||
167 | if (options.ContainsKey("teleport")) | ||
168 | { | ||
169 | bool enableTeleportDebugging; | ||
170 | if (bool.TryParse(options["teleport"], out enableTeleportDebugging)) | ||
171 | m_scene.DebugTeleporting = enableTeleportDebugging; | ||
172 | } | ||
173 | |||
174 | if (options.ContainsKey("updates")) | ||
175 | { | ||
176 | bool enableUpdateDebugging; | ||
177 | if (bool.TryParse(options["updates"], out enableUpdateDebugging)) | ||
178 | { | ||
179 | m_scene.DebugUpdates = enableUpdateDebugging; | ||
180 | GcNotify.Enabled = enableUpdateDebugging; | ||
181 | } | ||
182 | } | ||
183 | } | ||
184 | |||
185 | private void GetAttachmentsReport(ScenePresence sp, StringBuilder sb) | ||
186 | { | ||
187 | sb.AppendFormat("Attachments for {0}\n", sp.Name); | ||
188 | |||
189 | ConsoleDisplayTable ct = new ConsoleDisplayTable() { Indent = 2 }; | ||
190 | ct.Columns.Add(new ConsoleDisplayTableColumn("Attachment Name", 50)); | ||
191 | ct.Columns.Add(new ConsoleDisplayTableColumn("Local ID", 10)); | ||
192 | ct.Columns.Add(new ConsoleDisplayTableColumn("Item ID", 36)); | ||
193 | ct.Columns.Add(new ConsoleDisplayTableColumn("Attach Point", 14)); | ||
194 | ct.Columns.Add(new ConsoleDisplayTableColumn("Position", 15)); | ||
195 | |||
196 | // sb.AppendFormat( | ||
197 | // " {0,-36} {1,-10} {2,-36} {3,-14} {4,-15}\n", | ||
198 | // "Attachment Name", "Local ID", "Item ID", "Attach Point", "Position"); | ||
199 | |||
200 | List<SceneObjectGroup> attachmentObjects = sp.GetAttachments(); | ||
201 | foreach (SceneObjectGroup attachmentObject in attachmentObjects) | ||
202 | { | ||
203 | // InventoryItemBase attachmentItem | ||
204 | // = m_scenes[0].InventoryService.GetItem(new InventoryItemBase(attachmentObject.FromItemID)); | ||
205 | |||
206 | // if (attachmentItem == null) | ||
207 | // { | ||
208 | // sb.AppendFormat( | ||
209 | // "WARNING: Couldn't find attachment for item {0} at point {1}\n", | ||
210 | // attachmentData.ItemID, (AttachmentPoint)attachmentData.AttachPoint); | ||
211 | // continue; | ||
212 | // } | ||
213 | // else | ||
214 | // { | ||
215 | // sb.AppendFormat( | ||
216 | // " {0,-36} {1,-10} {2,-36} {3,-14} {4,-15}\n", | ||
217 | // attachmentObject.Name, attachmentObject.LocalId, attachmentObject.FromItemID, | ||
218 | // (AttachmentPoint)attachmentObject.AttachmentPoint, attachmentObject.RootPart.AttachedPos); | ||
219 | ct.Rows.Add( | ||
220 | new ConsoleDisplayTableRow( | ||
221 | new List<string>() | ||
222 | { | ||
223 | attachmentObject.Name, | ||
224 | attachmentObject.LocalId.ToString(), | ||
225 | attachmentObject.FromItemID.ToString(), | ||
226 | ((AttachmentPoint)attachmentObject.AttachmentPoint).ToString(), | ||
227 | attachmentObject.RootPart.AttachedPos.ToString() | ||
228 | })); | ||
229 | // } | ||
230 | } | ||
231 | |||
232 | ct.AddToStringBuilder(sb); | ||
233 | sb.Append("\n"); | ||
234 | } | ||
235 | } | ||
236 | } \ No newline at end of file | ||