1
0

AppearanceInfoModule.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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 List<Scene> m_scenes = new List<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);
  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.Add(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 avatars.",
  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. scene.AddCommand(
  118. "Users", this, "wearables show",
  119. "wearables show [<first-name> <last-name>]",
  120. "Show information about wearables for avatars.",
  121. "If no avatar name is given then a general summary for all avatars in the scene is shown.\n"
  122. + "If an avatar name is given then specific information about current wearables is shown.",
  123. HandleShowWearablesCommand);
  124. scene.AddCommand(
  125. "Users", this, "wearables check",
  126. "wearables check <first-name> <last-name>",
  127. "Check that the wearables of a given avatar in the scene are valid.",
  128. "This currently checks that the wearable assets themselves and any assets referenced by them exist.",
  129. HandleCheckWearablesCommand);
  130. }
  131. private void HandleSendAppearanceCommand(string module, string[] cmd)
  132. {
  133. if (cmd.Length != 2 && cmd.Length < 4)
  134. {
  135. MainConsole.Instance.Output("Usage: appearance send [<first-name> <last-name>]");
  136. return;
  137. }
  138. bool targetNameSupplied = false;
  139. string optionalTargetFirstName = null;
  140. string optionalTargetLastName = null;
  141. if (cmd.Length >= 4)
  142. {
  143. targetNameSupplied = true;
  144. optionalTargetFirstName = cmd[2];
  145. optionalTargetLastName = cmd[3];
  146. }
  147. lock (m_scenes)
  148. {
  149. foreach (Scene scene in m_scenes)
  150. {
  151. if (targetNameSupplied)
  152. {
  153. ScenePresence sp = scene.GetScenePresence(optionalTargetFirstName, optionalTargetLastName);
  154. if (sp != null && !sp.IsChildAgent)
  155. {
  156. MainConsole.Instance.Output(
  157. "Sending appearance information for {0} to all other avatars in {1}",
  158. sp.Name, scene.RegionInfo.RegionName);
  159. scene.AvatarFactory.SendAppearance(sp.UUID);
  160. }
  161. }
  162. else
  163. {
  164. scene.ForEachRootScenePresence(
  165. sp =>
  166. {
  167. MainConsole.Instance.Output(
  168. "Sending appearance information for {0} to all other avatars in {1}",
  169. sp.Name, scene.RegionInfo.RegionName);
  170. scene.AvatarFactory.SendAppearance(sp.UUID);
  171. }
  172. );
  173. }
  174. }
  175. }
  176. }
  177. private void HandleShowAppearanceCommand(string module, string[] cmd)
  178. {
  179. if (cmd.Length != 2 && cmd.Length < 4)
  180. {
  181. MainConsole.Instance.Output("Usage: appearance show [<first-name> <last-name>]");
  182. return;
  183. }
  184. bool targetNameSupplied = false;
  185. string optionalTargetFirstName = null;
  186. string optionalTargetLastName = null;
  187. if (cmd.Length >= 4)
  188. {
  189. targetNameSupplied = true;
  190. optionalTargetFirstName = cmd[2];
  191. optionalTargetLastName = cmd[3];
  192. }
  193. lock (m_scenes)
  194. {
  195. foreach (Scene scene in m_scenes)
  196. {
  197. if (targetNameSupplied)
  198. {
  199. ScenePresence sp = scene.GetScenePresence(optionalTargetFirstName, optionalTargetLastName);
  200. if (sp != null && !sp.IsChildAgent)
  201. scene.AvatarFactory.WriteBakedTexturesReport(sp, MainConsole.Instance.Output);
  202. }
  203. else
  204. {
  205. scene.ForEachRootScenePresence(
  206. sp =>
  207. {
  208. bool bakedTextureValid = scene.AvatarFactory.ValidateBakedTextureCache(sp);
  209. MainConsole.Instance.Output(
  210. "{0} baked appearance texture is {1}", sp.Name, bakedTextureValid ? "OK" : "incomplete");
  211. }
  212. );
  213. }
  214. }
  215. }
  216. }
  217. private void HandleRebakeAppearanceCommand(string module, string[] cmd)
  218. {
  219. if (cmd.Length != 4)
  220. {
  221. MainConsole.Instance.Output("Usage: appearance rebake <first-name> <last-name>");
  222. return;
  223. }
  224. string firstname = cmd[2];
  225. string lastname = cmd[3];
  226. lock (m_scenes)
  227. {
  228. foreach (Scene scene in m_scenes)
  229. {
  230. ScenePresence sp = scene.GetScenePresence(firstname, lastname);
  231. if (sp != null && !sp.IsChildAgent)
  232. {
  233. int rebakesRequested = scene.AvatarFactory.RequestRebake(sp, false);
  234. if (rebakesRequested > 0)
  235. MainConsole.Instance.Output(
  236. "Requesting rebake of {0} uploaded textures for {1} in {2}",
  237. rebakesRequested, sp.Name, scene.RegionInfo.RegionName);
  238. else
  239. MainConsole.Instance.Output(
  240. "No texture IDs available for rebake request for {0} in {1}",
  241. sp.Name, scene.RegionInfo.RegionName);
  242. }
  243. }
  244. }
  245. }
  246. private void HandleFindAppearanceCommand(string module, string[] cmd)
  247. {
  248. if (cmd.Length != 3)
  249. {
  250. MainConsole.Instance.Output("Usage: appearance find <uuid-or-start-of-uuid>");
  251. return;
  252. }
  253. string rawUuid = cmd[2];
  254. HashSet<ScenePresence> matchedAvatars = new HashSet<ScenePresence>();
  255. lock (m_scenes)
  256. {
  257. foreach (Scene scene in m_scenes)
  258. {
  259. scene.ForEachRootScenePresence(
  260. sp =>
  261. {
  262. Dictionary<BakeType, Primitive.TextureEntryFace> bakedFaces = scene.AvatarFactory.GetBakedTextureFaces(sp.UUID);
  263. foreach (Primitive.TextureEntryFace face in bakedFaces.Values)
  264. {
  265. if (face != null && face.TextureID.ToString().StartsWith(rawUuid))
  266. matchedAvatars.Add(sp);
  267. }
  268. });
  269. }
  270. }
  271. if (matchedAvatars.Count == 0)
  272. {
  273. MainConsole.Instance.Output("{0} did not match any baked avatar textures in use", null, rawUuid);
  274. }
  275. else
  276. {
  277. MainConsole.Instance.Output(
  278. "{0} matched {1}",
  279. rawUuid,
  280. string.Join(", ", matchedAvatars.ToList().ConvertAll<string>(sp => sp.Name).ToArray()));
  281. }
  282. }
  283. protected void HandleShowWearablesCommand(string module, string[] cmd)
  284. {
  285. if (cmd.Length != 2 && cmd.Length < 4)
  286. {
  287. MainConsole.Instance.Output("Usage: wearables show [<first-name> <last-name>]");
  288. return;
  289. }
  290. bool targetNameSupplied = false;
  291. string optionalTargetFirstName = null;
  292. string optionalTargetLastName = null;
  293. if (cmd.Length >= 4)
  294. {
  295. targetNameSupplied = true;
  296. optionalTargetFirstName = cmd[2];
  297. optionalTargetLastName = cmd[3];
  298. }
  299. StringBuilder sb = new StringBuilder();
  300. if (targetNameSupplied)
  301. {
  302. lock (m_scenes)
  303. {
  304. foreach (Scene scene in m_scenes)
  305. {
  306. ScenePresence sp = scene.GetScenePresence(optionalTargetFirstName, optionalTargetLastName);
  307. if (sp != null && !sp.IsChildAgent)
  308. AppendWearablesDetailReport(sp, sb);
  309. }
  310. }
  311. }
  312. else
  313. {
  314. ConsoleDisplayTable cdt = new ConsoleDisplayTable();
  315. cdt.AddColumn("Name", ConsoleDisplayUtil.UserNameSize);
  316. cdt.AddColumn("Wearables", 2);
  317. lock (m_scenes)
  318. {
  319. foreach (Scene scene in m_scenes)
  320. {
  321. scene.ForEachRootScenePresence(
  322. sp =>
  323. {
  324. int count = 0;
  325. for (int i = (int)WearableType.Shape; i < (int)WearableType.Physics; i++)
  326. count += sp.Appearance.Wearables[i].Count;
  327. cdt.AddRow(sp.Name, count);
  328. }
  329. );
  330. }
  331. }
  332. sb.Append(cdt.ToString());
  333. }
  334. MainConsole.Instance.Output(sb.ToString());
  335. }
  336. private void HandleCheckWearablesCommand(string module, string[] cmd)
  337. {
  338. if (cmd.Length != 4)
  339. {
  340. MainConsole.Instance.Output("Usage: wearables check <first-name> <last-name>");
  341. return;
  342. }
  343. string firstname = cmd[2];
  344. string lastname = cmd[3];
  345. StringBuilder sb = new StringBuilder();
  346. UuidGatherer uuidGatherer = new UuidGatherer(m_scenes[0].AssetService);
  347. lock (m_scenes)
  348. {
  349. foreach (Scene scene in m_scenes)
  350. {
  351. ScenePresence sp = scene.GetScenePresence(firstname, lastname);
  352. if (sp != null && !sp.IsChildAgent)
  353. {
  354. sb.AppendFormat("Wearables checks for {0}\n\n", sp.Name);
  355. AvatarWearable[] wearables = sp.Appearance.Wearables;
  356. if(wearables.Length == 0)
  357. {
  358. MainConsole.Instance.Output("avatar has no wearables");
  359. return;
  360. }
  361. for (int i = 0; i < wearables.Length; i++)
  362. {
  363. AvatarWearable aw = wearables[i];
  364. sb.Append(Enum.GetName(typeof(WearableType), i));
  365. sb.Append("\n");
  366. if (aw.Count > 0)
  367. {
  368. for (int j = 0; j < aw.Count; j++)
  369. {
  370. WearableItem wi = aw[j];
  371. ConsoleDisplayList cdl = new ConsoleDisplayList();
  372. cdl.Indent = 2;
  373. cdl.AddRow("Item UUID", wi.ItemID);
  374. cdl.AddRow("Assets", "");
  375. sb.Append(cdl.ToString());
  376. uuidGatherer.AddForInspection(wi.AssetID);
  377. uuidGatherer.GatherAll();
  378. string[] assetStrings
  379. = Array.ConvertAll<UUID, string>(uuidGatherer.GatheredUuids.Keys.ToArray(), u => u.ToString());
  380. bool[] existChecks = scene.AssetService.AssetsExist(assetStrings);
  381. ConsoleDisplayTable cdt = new ConsoleDisplayTable();
  382. cdt.Indent = 4;
  383. cdt.AddColumn("Type", 10);
  384. cdt.AddColumn("UUID", ConsoleDisplayUtil.UuidSize);
  385. cdt.AddColumn("Found", 5);
  386. for (int k = 0; k < existChecks.Length; k++)
  387. cdt.AddRow(
  388. (AssetType)uuidGatherer.GatheredUuids[new UUID(assetStrings[k])],
  389. assetStrings[k], existChecks[k] ? "yes" : "no");
  390. sb.Append(cdt.ToString());
  391. sb.Append("\n");
  392. }
  393. }
  394. else
  395. sb.Append(" Empty\n");
  396. }
  397. }
  398. }
  399. }
  400. MainConsole.Instance.Output(sb.ToString());
  401. }
  402. private void AppendWearablesDetailReport(ScenePresence sp, StringBuilder sb)
  403. {
  404. sb.AppendFormat("\nWearables for {0}\n", sp.Name);
  405. ConsoleDisplayTable cdt = new ConsoleDisplayTable();
  406. cdt.AddColumn("Type", 10);
  407. cdt.AddColumn("Item UUID", ConsoleDisplayUtil.UuidSize);
  408. cdt.AddColumn("Asset UUID", ConsoleDisplayUtil.UuidSize);
  409. AvatarWearable[] wearables = sp.Appearance.Wearables;
  410. for (int i = 0; i < wearables.Length; i++)
  411. {
  412. AvatarWearable aw = sp.Appearance.Wearables[i];
  413. for (int j = 0; j < aw.Count; j++)
  414. {
  415. WearableItem wi = aw[j];
  416. cdt.AddRow(Enum.GetName(typeof(WearableType), i), wi.ItemID, wi.AssetID);
  417. }
  418. }
  419. sb.Append(cdt.ToString());
  420. }
  421. }
  422. }