opensim-development – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 eva 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.ClientStack.LindenUDP;
41 using OpenSim.Region.Framework.Interfaces;
42 using OpenSim.Region.Framework.Scenes;
43  
44 namespace OpenSim.Region.OptionalModules.Avatar.Appearance
45 {
46 /// <summary>
47 /// A module that just holds commands for inspecting avatar appearance.
48 /// </summary>
49 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "AppearanceInfoModule")]
50 public class AppearanceInfoModule : ISharedRegionModule
51 {
52 // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53  
54 private Dictionary<UUID, Scene> m_scenes = new Dictionary<UUID, Scene>();
55 // private IAvatarFactoryModule m_avatarFactory;
56  
57 public string Name { get { return "Appearance Information Module"; } }
58  
59 public Type ReplaceableInterface { get { return null; } }
60  
61 public void Initialise(IConfigSource source)
62 {
63 // m_log.DebugFormat("[APPEARANCE INFO MODULE]: INITIALIZED MODULE");
64 }
65  
66 public void PostInitialise()
67 {
68 // m_log.DebugFormat("[APPEARANCE INFO MODULE]: POST INITIALIZED MODULE");
69 }
70  
71 public void Close()
72 {
73 // m_log.DebugFormat("[APPEARANCE INFO MODULE]: CLOSED MODULE");
74 }
75  
76 public void AddRegion(Scene scene)
77 {
78 // m_log.DebugFormat("[APPEARANCE INFO MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName);
79 }
80  
81 public void RemoveRegion(Scene scene)
82 {
83 // m_log.DebugFormat("[APPEARANCE INFO MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
84  
85 lock (m_scenes)
86 m_scenes.Remove(scene.RegionInfo.RegionID);
87 }
88  
89 public void RegionLoaded(Scene scene)
90 {
91 // m_log.DebugFormat("[APPEARANCE INFO MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName);
92  
93 lock (m_scenes)
94 m_scenes[scene.RegionInfo.RegionID] = scene;
95  
96 scene.AddCommand(
97 "Users", this, "show appearance",
98 "show appearance [<first-name> <last-name>]",
99 "Synonym for 'appearance show'",
100 HandleShowAppearanceCommand);
101  
102 scene.AddCommand(
103 "Users", this, "appearance show",
104 "appearance show [<first-name> <last-name>]",
105 "Show appearance information for each avatar in the simulator.",
106 "This command checks whether the simulator has all the baked textures required to display an avatar to other viewers. "
107 + "\nIf not, then appearance is 'corrupt' and other avatars will continue to see it as a cloud."
108 + "\nOptionally, you can view just a particular avatar's appearance information."
109 + "\nIn this case, the texture UUID for each bake type is also shown and whether the simulator can find the referenced texture.",
110 HandleShowAppearanceCommand);
111  
112 scene.AddCommand(
113 "Users", this, "appearance send",
114 "appearance send [<first-name> <last-name>]",
115 "Send appearance data for each avatar in the simulator to other viewers.",
116 "Optionally, you can specify that only a particular avatar's appearance data is sent.",
117 HandleSendAppearanceCommand);
118  
119 scene.AddCommand(
120 "Users", this, "appearance rebake",
121 "appearance rebake <first-name> <last-name>",
122 "Send a request to the user's viewer for it to rebake and reupload its appearance textures.",
123 "This is currently done for all baked texture references previously received, whether the simulator can find the asset or not."
124 + "\nThis will only work for texture ids that the viewer has already uploaded."
125 + "\nIf the viewer has not yet sent the server any texture ids then nothing will happen"
126 + "\nsince requests can only be made for ids that the client has already sent us",
127 HandleRebakeAppearanceCommand);
128  
129 scene.AddCommand(
130 "Users", this, "appearance find",
131 "appearance find <uuid-or-start-of-uuid>",
132 "Find out which avatar uses the given asset as a baked texture, if any.",
133 "You can specify just the beginning of the uuid, e.g. 2008a8d. A longer UUID must be in dashed format.",
134 HandleFindAppearanceCommand);
135 }
136  
137 private void HandleSendAppearanceCommand(string module, string[] cmd)
138 {
139 if (cmd.Length != 2 && cmd.Length < 4)
140 {
141 MainConsole.Instance.OutputFormat("Usage: appearance send [<first-name> <last-name>]");
142 return;
143 }
144  
145 bool targetNameSupplied = false;
146 string optionalTargetFirstName = null;
147 string optionalTargetLastName = null;
148  
149 if (cmd.Length >= 4)
150 {
151 targetNameSupplied = true;
152 optionalTargetFirstName = cmd[2];
153 optionalTargetLastName = cmd[3];
154 }
155  
156 lock (m_scenes)
157 {
158 foreach (Scene scene in m_scenes.Values)
159 {
160 if (targetNameSupplied)
161 {
162 ScenePresence sp = scene.GetScenePresence(optionalTargetFirstName, optionalTargetLastName);
163 if (sp != null && !sp.IsChildAgent)
164 {
165 MainConsole.Instance.OutputFormat(
166 "Sending appearance information for {0} to all other avatars in {1}",
167 sp.Name, scene.RegionInfo.RegionName);
168  
169 scene.AvatarFactory.SendAppearance(sp.UUID);
170 }
171 }
172 else
173 {
174 scene.ForEachRootScenePresence(
175 sp =>
176 {
177 MainConsole.Instance.OutputFormat(
178 "Sending appearance information for {0} to all other avatars in {1}",
179 sp.Name, scene.RegionInfo.RegionName);
180  
181 scene.AvatarFactory.SendAppearance(sp.UUID);
182 }
183 );
184 }
185 }
186 }
187 }
188  
189 protected void HandleShowAppearanceCommand(string module, string[] cmd)
190 {
191 if (cmd.Length != 2 && cmd.Length < 4)
192 {
193 MainConsole.Instance.OutputFormat("Usage: appearance show [<first-name> <last-name>]");
194 return;
195 }
196  
197 bool targetNameSupplied = false;
198 string optionalTargetFirstName = null;
199 string optionalTargetLastName = null;
200  
201 if (cmd.Length >= 4)
202 {
203 targetNameSupplied = true;
204 optionalTargetFirstName = cmd[2];
205 optionalTargetLastName = cmd[3];
206 }
207  
208 lock (m_scenes)
209 {
210 foreach (Scene scene in m_scenes.Values)
211 {
212 if (targetNameSupplied)
213 {
214 ScenePresence sp = scene.GetScenePresence(optionalTargetFirstName, optionalTargetLastName);
215 if (sp != null && !sp.IsChildAgent)
216 scene.AvatarFactory.WriteBakedTexturesReport(sp, MainConsole.Instance.OutputFormat);
217 }
218 else
219 {
220 scene.ForEachRootScenePresence(
221 sp =>
222 {
223 bool bakedTextureValid = scene.AvatarFactory.ValidateBakedTextureCache(sp);
224 MainConsole.Instance.OutputFormat(
225 "{0} baked appearance texture is {1}", sp.Name, bakedTextureValid ? "OK" : "incomplete");
226 }
227 );
228 }
229 }
230 }
231 }
232  
233 private void HandleRebakeAppearanceCommand(string module, string[] cmd)
234 {
235 if (cmd.Length != 4)
236 {
237 MainConsole.Instance.OutputFormat("Usage: appearance rebake <first-name> <last-name>");
238 return;
239 }
240  
241 string firstname = cmd[2];
242 string lastname = cmd[3];
243  
244 lock (m_scenes)
245 {
246 foreach (Scene scene in m_scenes.Values)
247 {
248 ScenePresence sp = scene.GetScenePresence(firstname, lastname);
249 if (sp != null && !sp.IsChildAgent)
250 {
251 int rebakesRequested = scene.AvatarFactory.RequestRebake(sp, false);
252  
253 if (rebakesRequested > 0)
254 MainConsole.Instance.OutputFormat(
255 "Requesting rebake of {0} uploaded textures for {1} in {2}",
256 rebakesRequested, sp.Name, scene.RegionInfo.RegionName);
257 else
258 MainConsole.Instance.OutputFormat(
259 "No texture IDs available for rebake request for {0} in {1}",
260 sp.Name, scene.RegionInfo.RegionName);
261 }
262 }
263 }
264 }
265  
266 protected void HandleFindAppearanceCommand(string module, string[] cmd)
267 {
268 if (cmd.Length != 3)
269 {
270 MainConsole.Instance.OutputFormat("Usage: appearance find <uuid-or-start-of-uuid>");
271 return;
272 }
273  
274 string rawUuid = cmd[2];
275  
276 HashSet<ScenePresence> matchedAvatars = new HashSet<ScenePresence>();
277  
278 lock (m_scenes)
279 {
280 foreach (Scene scene in m_scenes.Values)
281 {
282 scene.ForEachRootScenePresence(
283 sp =>
284 {
285 Dictionary<BakeType, Primitive.TextureEntryFace> bakedFaces = scene.AvatarFactory.GetBakedTextureFaces(sp.UUID);
286 foreach (Primitive.TextureEntryFace face in bakedFaces.Values)
287 {
288 if (face != null && face.TextureID.ToString().StartsWith(rawUuid))
289 matchedAvatars.Add(sp);
290 }
291 });
292 }
293 }
294  
295 if (matchedAvatars.Count == 0)
296 {
297 MainConsole.Instance.OutputFormat("{0} did not match any baked avatar textures in use", rawUuid);
298 }
299 else
300 {
301 MainConsole.Instance.OutputFormat(
302 "{0} matched {1}",
303 rawUuid,
304 string.Join(", ", matchedAvatars.ToList().ConvertAll<string>(sp => sp.Name).ToArray()));
305 }
306 }
307 }
308 }