AppearanceInfoModule.cs 20 KB

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