AppearanceInfoModule.cs 13 KB

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