diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs | 410 |
1 files changed, 410 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs b/OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs new file mode 100644 index 0000000..e3d04cd --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs | |||
@@ -0,0 +1,410 @@ | |||
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.Reflection; | ||
31 | using System.Text; | ||
32 | using log4net; | ||
33 | using Mono.Addins; | ||
34 | using Nini.Config; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Framework.Console; | ||
38 | using OpenSim.Framework.Statistics; | ||
39 | using OpenSim.Region.Framework.Interfaces; | ||
40 | using OpenSim.Region.Framework.Scenes; | ||
41 | |||
42 | namespace OpenSim.Region.CoreModules.World.Objects.Commands | ||
43 | { | ||
44 | /// <summary> | ||
45 | /// A module that holds commands for manipulating objects in the scene. | ||
46 | /// </summary> | ||
47 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ObjectCommandsModule")] | ||
48 | public class ObjectCommandsModule : INonSharedRegionModule | ||
49 | { | ||
50 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | private Scene m_scene; | ||
53 | private ICommandConsole m_console; | ||
54 | |||
55 | public string Name { get { return "Object Commands Module"; } } | ||
56 | |||
57 | public Type ReplaceableInterface { get { return null; } } | ||
58 | |||
59 | public void Initialise(IConfigSource source) | ||
60 | { | ||
61 | // m_log.DebugFormat("[OBJECT COMMANDS MODULE]: INITIALIZED MODULE"); | ||
62 | } | ||
63 | |||
64 | public void PostInitialise() | ||
65 | { | ||
66 | // m_log.DebugFormat("[OBJECT COMMANDS MODULE]: POST INITIALIZED MODULE"); | ||
67 | } | ||
68 | |||
69 | public void Close() | ||
70 | { | ||
71 | // m_log.DebugFormat("[OBJECT COMMANDS MODULE]: CLOSED MODULE"); | ||
72 | } | ||
73 | |||
74 | public void AddRegion(Scene scene) | ||
75 | { | ||
76 | // m_log.DebugFormat("[OBJECT COMMANDS MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName); | ||
77 | |||
78 | m_scene = scene; | ||
79 | m_console = MainConsole.Instance; | ||
80 | |||
81 | m_console.Commands.AddCommand("region", false, "delete object owner", | ||
82 | "delete object owner <UUID>", | ||
83 | "Delete a scene object by owner", HandleDeleteObject); | ||
84 | m_console.Commands.AddCommand("region", false, "delete object creator", | ||
85 | "delete object creator <UUID>", | ||
86 | "Delete a scene object by creator", HandleDeleteObject); | ||
87 | m_console.Commands.AddCommand("region", false, "delete object uuid", | ||
88 | "delete object uuid <UUID>", | ||
89 | "Delete a scene object by uuid", HandleDeleteObject); | ||
90 | m_console.Commands.AddCommand("region", false, "delete object name", | ||
91 | "delete object name <name>", | ||
92 | "Delete a scene object by name", HandleDeleteObject); | ||
93 | m_console.Commands.AddCommand("region", false, "delete object outside", | ||
94 | "delete object outside", | ||
95 | "Delete all scene objects outside region boundaries", HandleDeleteObject); | ||
96 | |||
97 | m_console.Commands.AddCommand( | ||
98 | "region", | ||
99 | false, | ||
100 | "show object uuid", | ||
101 | "show object uuid <UUID>", | ||
102 | "Show details of a scene object with the given UUID", HandleShowObjectByUuid); | ||
103 | |||
104 | m_console.Commands.AddCommand( | ||
105 | "region", | ||
106 | false, | ||
107 | "show object name", | ||
108 | "show object name <name>", | ||
109 | "Show details of scene objects with the given name", HandleShowObjectByName); | ||
110 | |||
111 | m_console.Commands.AddCommand( | ||
112 | "region", | ||
113 | false, | ||
114 | "show part uuid", | ||
115 | "show part uuid <UUID>", | ||
116 | "Show details of a scene object parts with the given UUID", HandleShowPartByUuid); | ||
117 | |||
118 | m_console.Commands.AddCommand( | ||
119 | "region", | ||
120 | false, | ||
121 | "show part name", | ||
122 | "show part name <name>", | ||
123 | "Show details of scene object parts with the given name", HandleShowPartByName); | ||
124 | } | ||
125 | |||
126 | public void RemoveRegion(Scene scene) | ||
127 | { | ||
128 | // m_log.DebugFormat("[OBJECTS COMMANDS MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName); | ||
129 | } | ||
130 | |||
131 | public void RegionLoaded(Scene scene) | ||
132 | { | ||
133 | // m_log.DebugFormat("[OBJECTS COMMANDS MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName); | ||
134 | } | ||
135 | |||
136 | private void HandleShowObjectByUuid(string module, string[] cmd) | ||
137 | { | ||
138 | if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene)) | ||
139 | return; | ||
140 | |||
141 | if (cmd.Length < 4) | ||
142 | { | ||
143 | m_console.OutputFormat("Usage: show object uuid <uuid>"); | ||
144 | return; | ||
145 | } | ||
146 | |||
147 | UUID objectUuid; | ||
148 | if (!UUID.TryParse(cmd[3], out objectUuid)) | ||
149 | { | ||
150 | m_console.OutputFormat("{0} is not a valid uuid", cmd[3]); | ||
151 | return; | ||
152 | } | ||
153 | |||
154 | SceneObjectGroup so = m_scene.GetSceneObjectGroup(objectUuid); | ||
155 | |||
156 | if (so == null) | ||
157 | { | ||
158 | // m_console.OutputFormat("No part found with uuid {0}", objectUuid); | ||
159 | return; | ||
160 | } | ||
161 | |||
162 | StringBuilder sb = new StringBuilder(); | ||
163 | AddSceneObjectReport(sb, so); | ||
164 | |||
165 | m_console.OutputFormat(sb.ToString()); | ||
166 | } | ||
167 | |||
168 | private void HandleShowObjectByName(string module, string[] cmd) | ||
169 | { | ||
170 | if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene)) | ||
171 | return; | ||
172 | |||
173 | if (cmd.Length < 4) | ||
174 | { | ||
175 | m_console.OutputFormat("Usage: show object name <name>"); | ||
176 | return; | ||
177 | } | ||
178 | |||
179 | string name = cmd[3]; | ||
180 | |||
181 | List<SceneObjectGroup> sceneObjects = new List<SceneObjectGroup>(); | ||
182 | |||
183 | m_scene.ForEachSOG(so => { if (so.Name == name) { sceneObjects.Add(so); }}); | ||
184 | |||
185 | if (sceneObjects.Count == 0) | ||
186 | { | ||
187 | m_console.OutputFormat("No objects with name {0} found in {1}", name, m_scene.RegionInfo.RegionName); | ||
188 | return; | ||
189 | } | ||
190 | |||
191 | StringBuilder sb = new StringBuilder(); | ||
192 | |||
193 | foreach (SceneObjectGroup so in sceneObjects) | ||
194 | { | ||
195 | AddSceneObjectReport(sb, so); | ||
196 | sb.Append("\n"); | ||
197 | } | ||
198 | |||
199 | m_console.OutputFormat(sb.ToString()); | ||
200 | } | ||
201 | |||
202 | private void HandleShowPartByUuid(string module, string[] cmd) | ||
203 | { | ||
204 | if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene)) | ||
205 | return; | ||
206 | |||
207 | if (cmd.Length < 4) | ||
208 | { | ||
209 | m_console.OutputFormat("Usage: show part uuid <uuid>"); | ||
210 | return; | ||
211 | } | ||
212 | |||
213 | UUID objectUuid; | ||
214 | if (!UUID.TryParse(cmd[3], out objectUuid)) | ||
215 | { | ||
216 | m_console.OutputFormat("{0} is not a valid uuid", cmd[3]); | ||
217 | return; | ||
218 | } | ||
219 | |||
220 | SceneObjectPart sop = m_scene.GetSceneObjectPart(objectUuid); | ||
221 | |||
222 | if (sop == null) | ||
223 | { | ||
224 | // m_console.OutputFormat("No part found with uuid {0}", objectUuid); | ||
225 | return; | ||
226 | } | ||
227 | |||
228 | StringBuilder sb = new StringBuilder(); | ||
229 | AddScenePartReport(sb, sop); | ||
230 | |||
231 | m_console.OutputFormat(sb.ToString()); | ||
232 | } | ||
233 | |||
234 | private void HandleShowPartByName(string module, string[] cmd) | ||
235 | { | ||
236 | if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene)) | ||
237 | return; | ||
238 | |||
239 | if (cmd.Length < 4) | ||
240 | { | ||
241 | m_console.OutputFormat("Usage: show part name <name>"); | ||
242 | return; | ||
243 | } | ||
244 | |||
245 | string name = cmd[3]; | ||
246 | |||
247 | List<SceneObjectPart> parts = new List<SceneObjectPart>(); | ||
248 | |||
249 | m_scene.ForEachSOG(so => so.ForEachPart(sop => { if (sop.Name == name) { parts.Add(sop); } })); | ||
250 | |||
251 | if (parts.Count == 0) | ||
252 | { | ||
253 | m_console.OutputFormat("No parts with name {0} found in {1}", name, m_scene.RegionInfo.RegionName); | ||
254 | return; | ||
255 | } | ||
256 | |||
257 | StringBuilder sb = new StringBuilder(); | ||
258 | |||
259 | foreach (SceneObjectPart part in parts) | ||
260 | { | ||
261 | AddScenePartReport(sb, part); | ||
262 | sb.Append("\n"); | ||
263 | } | ||
264 | |||
265 | m_console.OutputFormat(sb.ToString()); | ||
266 | } | ||
267 | |||
268 | private StringBuilder AddSceneObjectReport(StringBuilder sb, SceneObjectGroup so) | ||
269 | { | ||
270 | sb.AppendFormat("Name: {0}\n", so.Name); | ||
271 | sb.AppendFormat("Description: {0}\n", so.Description); | ||
272 | sb.AppendFormat("Location: {0} @ {1}\n", so.AbsolutePosition, so.Scene.RegionInfo.RegionName); | ||
273 | sb.AppendFormat("Parts: {0}\n", so.PrimCount); | ||
274 | |||
275 | return sb; | ||
276 | } | ||
277 | |||
278 | private StringBuilder AddScenePartReport(StringBuilder sb, SceneObjectPart sop) | ||
279 | { | ||
280 | sb.AppendFormat("Name: {0}\n", sop.Name); | ||
281 | sb.AppendFormat("Description: {0}\n", sop.Description); | ||
282 | sb.AppendFormat("Location: {0} @ {1}\n", sop.AbsolutePosition, sop.ParentGroup.Scene.RegionInfo.RegionName); | ||
283 | sb.AppendFormat("Parent: {0}", | ||
284 | sop.IsRoot ? "Is Root\n" : string.Format("{0} {1}\n", sop.ParentGroup.Name, sop.ParentGroup.UUID)); | ||
285 | sb.AppendFormat("Parts: {0}\n", !sop.IsRoot ? "1" : sop.ParentGroup.PrimCount.ToString());; | ||
286 | |||
287 | return sb; | ||
288 | } | ||
289 | |||
290 | private void HandleDeleteObject(string module, string[] cmd) | ||
291 | { | ||
292 | if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene)) | ||
293 | return; | ||
294 | |||
295 | if (cmd.Length < 3) | ||
296 | return; | ||
297 | |||
298 | string mode = cmd[2]; | ||
299 | string o = ""; | ||
300 | |||
301 | if (mode != "outside") | ||
302 | { | ||
303 | if (cmd.Length < 4) | ||
304 | return; | ||
305 | |||
306 | o = cmd[3]; | ||
307 | } | ||
308 | |||
309 | List<SceneObjectGroup> deletes = new List<SceneObjectGroup>(); | ||
310 | |||
311 | UUID match; | ||
312 | |||
313 | switch (mode) | ||
314 | { | ||
315 | case "owner": | ||
316 | if (!UUID.TryParse(o, out match)) | ||
317 | return; | ||
318 | |||
319 | m_scene.ForEachSOG(delegate (SceneObjectGroup g) | ||
320 | { | ||
321 | if (g.OwnerID == match && !g.IsAttachment) | ||
322 | deletes.Add(g); | ||
323 | }); | ||
324 | |||
325 | // if (deletes.Count == 0) | ||
326 | // m_console.OutputFormat("No objects were found with owner {0}", match); | ||
327 | |||
328 | break; | ||
329 | |||
330 | case "creator": | ||
331 | if (!UUID.TryParse(o, out match)) | ||
332 | return; | ||
333 | |||
334 | m_scene.ForEachSOG(delegate (SceneObjectGroup g) | ||
335 | { | ||
336 | if (g.RootPart.CreatorID == match && !g.IsAttachment) | ||
337 | deletes.Add(g); | ||
338 | }); | ||
339 | |||
340 | // if (deletes.Count == 0) | ||
341 | // m_console.OutputFormat("No objects were found with creator {0}", match); | ||
342 | |||
343 | break; | ||
344 | |||
345 | case "uuid": | ||
346 | if (!UUID.TryParse(o, out match)) | ||
347 | return; | ||
348 | |||
349 | m_scene.ForEachSOG(delegate (SceneObjectGroup g) | ||
350 | { | ||
351 | if (g.UUID == match && !g.IsAttachment) | ||
352 | deletes.Add(g); | ||
353 | }); | ||
354 | |||
355 | // if (deletes.Count == 0) | ||
356 | // m_console.OutputFormat("No objects were found with uuid {0}", match); | ||
357 | |||
358 | break; | ||
359 | |||
360 | case "name": | ||
361 | m_scene.ForEachSOG(delegate (SceneObjectGroup g) | ||
362 | { | ||
363 | if (g.RootPart.Name == o && !g.IsAttachment) | ||
364 | deletes.Add(g); | ||
365 | }); | ||
366 | |||
367 | // if (deletes.Count == 0) | ||
368 | // m_console.OutputFormat("No objects were found with name {0}", o); | ||
369 | |||
370 | break; | ||
371 | |||
372 | case "outside": | ||
373 | m_scene.ForEachSOG(delegate (SceneObjectGroup g) | ||
374 | { | ||
375 | SceneObjectPart rootPart = g.RootPart; | ||
376 | bool delete = false; | ||
377 | |||
378 | if (rootPart.GroupPosition.Z < 0.0 || rootPart.GroupPosition.Z > 10000.0) | ||
379 | { | ||
380 | delete = true; | ||
381 | } | ||
382 | else | ||
383 | { | ||
384 | ILandObject parcel | ||
385 | = m_scene.LandChannel.GetLandObject(rootPart.GroupPosition.X, rootPart.GroupPosition.Y); | ||
386 | |||
387 | if (parcel == null || parcel.LandData.Name == "NO LAND") | ||
388 | delete = true; | ||
389 | } | ||
390 | |||
391 | if (delete && !g.IsAttachment && !deletes.Contains(g)) | ||
392 | deletes.Add(g); | ||
393 | }); | ||
394 | |||
395 | // if (deletes.Count == 0) | ||
396 | // m_console.OutputFormat("No objects were found outside region bounds"); | ||
397 | |||
398 | break; | ||
399 | } | ||
400 | |||
401 | m_console.OutputFormat("Deleting {0} objects in {1}", deletes.Count, m_scene.RegionInfo.RegionName); | ||
402 | |||
403 | foreach (SceneObjectGroup g in deletes) | ||
404 | { | ||
405 | m_console.OutputFormat("Deleting object {0} {1}", g.UUID, g.Name); | ||
406 | m_scene.DeleteSceneObject(g, false); | ||
407 | } | ||
408 | } | ||
409 | } | ||
410 | } \ No newline at end of file | ||