diff options
author | Justin Clark-Casey (justincc) | 2012-05-10 22:48:03 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-05-10 22:48:03 +0100 |
commit | bce3e7cb06611db887ee50c793d72674ad326ba7 (patch) | |
tree | 20fd0e8a567fd527fcc6d4b58db1084973f9a254 /OpenSim/Region/OptionalModules/Avatar/Attachments | |
parent | Saving estate state is really slow (relatively) and it gets (diff) | |
download | opensim-SC-bce3e7cb06611db887ee50c793d72674ad326ba7.zip opensim-SC-bce3e7cb06611db887ee50c793d72674ad326ba7.tar.gz opensim-SC-bce3e7cb06611db887ee50c793d72674ad326ba7.tar.bz2 opensim-SC-bce3e7cb06611db887ee50c793d72674ad326ba7.tar.xz |
Add "attachments" show console command that will show the server's record of which attachments an in-scene avatar has.
For debugging purposes.
Diffstat (limited to 'OpenSim/Region/OptionalModules/Avatar/Attachments')
-rw-r--r-- | OpenSim/Region/OptionalModules/Avatar/Attachments/AttachmentsCommandModule.cs | 177 |
1 files changed, 177 insertions, 0 deletions
diff --git a/OpenSim/Region/OptionalModules/Avatar/Attachments/AttachmentsCommandModule.cs b/OpenSim/Region/OptionalModules/Avatar/Attachments/AttachmentsCommandModule.cs new file mode 100644 index 0000000..ce23613 --- /dev/null +++ b/OpenSim/Region/OptionalModules/Avatar/Attachments/AttachmentsCommandModule.cs | |||
@@ -0,0 +1,177 @@ | |||
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.Statistics; | ||
40 | using OpenSim.Region.ClientStack.LindenUDP; | ||
41 | using OpenSim.Region.Framework.Interfaces; | ||
42 | using OpenSim.Region.Framework.Scenes; | ||
43 | |||
44 | namespace OpenSim.Region.OptionalModules.Avatar.Attachments | ||
45 | { | ||
46 | /// <summary> | ||
47 | /// A module that just holds commands for inspecting avatar appearance. | ||
48 | /// </summary> | ||
49 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "AttachmentsCommandModule")] | ||
50 | public class AttachmentsCommandModule : ISharedRegionModule | ||
51 | { | ||
52 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
53 | |||
54 | private List<Scene> m_scenes = new List<Scene>(); | ||
55 | // private IAvatarFactoryModule m_avatarFactory; | ||
56 | |||
57 | public string Name { get { return "Attachments Command Module"; } } | ||
58 | |||
59 | public Type ReplaceableInterface { get { return null; } } | ||
60 | |||
61 | public void Initialise(IConfigSource source) | ||
62 | { | ||
63 | // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: INITIALIZED MODULE"); | ||
64 | } | ||
65 | |||
66 | public void PostInitialise() | ||
67 | { | ||
68 | // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: POST INITIALIZED MODULE"); | ||
69 | } | ||
70 | |||
71 | public void Close() | ||
72 | { | ||
73 | // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: CLOSED MODULE"); | ||
74 | } | ||
75 | |||
76 | public void AddRegion(Scene scene) | ||
77 | { | ||
78 | // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName); | ||
79 | } | ||
80 | |||
81 | public void RemoveRegion(Scene scene) | ||
82 | { | ||
83 | // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName); | ||
84 | |||
85 | lock (m_scenes) | ||
86 | m_scenes.Remove(scene); | ||
87 | } | ||
88 | |||
89 | public void RegionLoaded(Scene scene) | ||
90 | { | ||
91 | // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName); | ||
92 | |||
93 | lock (m_scenes) | ||
94 | m_scenes.Add(scene); | ||
95 | |||
96 | scene.AddCommand( | ||
97 | "Users", this, "attachments show", | ||
98 | "attachments show [<first-name> <last-name>]", | ||
99 | "Show attachment information for avatars in this simulator.", | ||
100 | HandleShowAttachmentsCommand); | ||
101 | } | ||
102 | |||
103 | protected void HandleShowAttachmentsCommand(string module, string[] cmd) | ||
104 | { | ||
105 | if (cmd.Length != 2 && cmd.Length < 4) | ||
106 | { | ||
107 | MainConsole.Instance.OutputFormat("Usage: attachments show [<first-name> <last-name>]"); | ||
108 | return; | ||
109 | } | ||
110 | |||
111 | bool targetNameSupplied = false; | ||
112 | string optionalTargetFirstName = null; | ||
113 | string optionalTargetLastName = null; | ||
114 | |||
115 | if (cmd.Length >= 4) | ||
116 | { | ||
117 | targetNameSupplied = true; | ||
118 | optionalTargetFirstName = cmd[2]; | ||
119 | optionalTargetLastName = cmd[3]; | ||
120 | } | ||
121 | |||
122 | StringBuilder sb = new StringBuilder(); | ||
123 | |||
124 | lock (m_scenes) | ||
125 | { | ||
126 | foreach (Scene scene in m_scenes) | ||
127 | { | ||
128 | if (targetNameSupplied) | ||
129 | { | ||
130 | ScenePresence sp = scene.GetScenePresence(optionalTargetFirstName, optionalTargetLastName); | ||
131 | if (sp != null && !sp.IsChildAgent) | ||
132 | GetAttachmentsReport(sp, sb); | ||
133 | } | ||
134 | else | ||
135 | { | ||
136 | scene.ForEachRootScenePresence(sp => GetAttachmentsReport(sp, sb)); | ||
137 | } | ||
138 | } | ||
139 | } | ||
140 | |||
141 | MainConsole.Instance.Output(sb.ToString()); | ||
142 | } | ||
143 | |||
144 | private void GetAttachmentsReport(ScenePresence sp, StringBuilder sb) | ||
145 | { | ||
146 | sb.AppendFormat("Attachments for {0}\n", sp.Name); | ||
147 | |||
148 | sb.AppendFormat( | ||
149 | " {0,-36} {1,-10} {2,-36} {3,-14} {4,-15}\n", | ||
150 | "Attachment Name", "Local ID", "Item ID", "Attach Point", "Position"); | ||
151 | |||
152 | List<SceneObjectGroup> attachmentObjects = sp.GetAttachments(); | ||
153 | foreach (SceneObjectGroup attachmentObject in attachmentObjects) | ||
154 | { | ||
155 | // InventoryItemBase attachmentItem | ||
156 | // = m_scenes[0].InventoryService.GetItem(new InventoryItemBase(attachmentObject.FromItemID)); | ||
157 | |||
158 | // if (attachmentItem == null) | ||
159 | // { | ||
160 | // sb.AppendFormat( | ||
161 | // "WARNING: Couldn't find attachment for item {0} at point {1}\n", | ||
162 | // attachmentData.ItemID, (AttachmentPoint)attachmentData.AttachPoint); | ||
163 | // continue; | ||
164 | // } | ||
165 | // else | ||
166 | // { | ||
167 | sb.AppendFormat( | ||
168 | " {0,-36} {1,-10} {2,-36} {3,-14} {4,-15}\n", | ||
169 | attachmentObject.Name, attachmentObject.LocalId, attachmentObject.FromItemID, | ||
170 | (AttachmentPoint)attachmentObject.AttachmentPoint, attachmentObject.RootPart.AttachedPos); | ||
171 | // } | ||
172 | } | ||
173 | |||
174 | sb.Append("\n"); | ||
175 | } | ||
176 | } | ||
177 | } \ No newline at end of file | ||