UuidGatherer.cs 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350
  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.Reflection;
  30. using System.Runtime.CompilerServices;
  31. using System.Text;
  32. using log4net;
  33. using OpenMetaverse;
  34. using OpenMetaverse.StructuredData;
  35. using OpenSim.Framework;
  36. using OpenSim.Services.Interfaces;
  37. namespace OpenSim.Region.Framework.Scenes
  38. {
  39. /// <summary>
  40. /// Gather uuids for a given entity.
  41. /// </summary>
  42. /// <remarks>
  43. /// This does a deep inspection of the entity to retrieve all the assets it uses (whether as textures, as scripts
  44. /// contained in inventory, as scripts contained in objects contained in another object's inventory, etc. Assets
  45. /// are only retrieved when they are necessary to carry out the inspection (i.e. a serialized object needs to be
  46. /// retrieved to work out which assets it references).
  47. /// </remarks>
  48. public class UuidGatherer
  49. {
  50. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  51. private static readonly HashSet<UUID> ToSkip = new()
  52. {
  53. new UUID("11111111-1111-0000-0000-000100bba000"),
  54. new UUID("5a9f4a74-30f2-821c-b88d-70499d3e7183"),
  55. new UUID("ae2de45c-d252-50b8-5c6e-19f39ce79317"),
  56. new UUID("24daea5f-0539-cfcf-047f-fbc40b2786ba"),
  57. new UUID("52cc6bb6-2ee5-e632-d3ad-50197b1dcb8a"),
  58. new UUID("43529ce8-7faa-ad92-165a-bc4078371687"),
  59. new UUID("09aac1fb-6bce-0bee-7d44-caac6dbb6c63"),
  60. new UUID("ff62763f-d60a-9855-890b-0c96f8f8cd98"),
  61. new UUID("8e915e25-31d1-cc95-ae08-d58a47488251"),
  62. new UUID("9742065b-19b5-297c-858a-29711d539043"),
  63. new UUID("03642e83-2bd1-4eb9-34b4-4c47ed586d2d"),
  64. new UUID("edd51b77-fc10-ce7a-4b3d-011dfc349e4f"),
  65. new UUID("44e87126-e794-4ded-05b3-7c42da3d5cdb"),
  66. new UUID("3d6181b0-6a4b-97ef-18d8-722652995cf1"),
  67. new UUID("b4ba225c-373f-446d-9f7e-6cb7b5cf9b3d"),
  68. new UUID("d2114404-dd59-4a4d-8e6c-49359e91bbf0"),
  69. new UUID("c228d1cf-4b5d-4ba8-84f4-899a0796aa97"),
  70. new UUID("e97cf410-8e61-7005-ec06-629eba4cd1fb"),
  71. new UUID("38b86f85-2575-52a9-a531-23108d8da837"),
  72. new UUID("8dcd4a48-2d37-4909-9f78-f7a9eb4ef903"),
  73. new UUID("3c59f7fe-9dc8-47f9-8aaf-a9dd1fbc3bef"),
  74. new UUID("0bc58228-74a0-7e83-89bc-5c23464bcec5"),
  75. new UUID("63338ede-0037-c4fd-855b-015d77112fc8"),
  76. new UUID("303cd381-8560-7579-23f1-f0a880799740"),
  77. new UUID("53a2f406-4895-1d13-d541-d2e3b86bc19c"),
  78. new UUID("822ded49-9a6c-f61c-cb89-6df54f42cdf4"),
  79. new UUID("6b61c8e8-4747-0d75-12d7-e49ff207a4ca"),
  80. new UUID("b5b4a67d-0aee-30d2-72cd-77b333e932ef"),
  81. new UUID("46bb4359-de38-4ed8-6a22-f1f52fe8f506"),
  82. new UUID("3147d815-6338-b932-f011-16b56d9ac18b"),
  83. new UUID("ea633413-8006-180a-c3ba-96dd1d756720"),
  84. new UUID("5747a48e-073e-c331-f6f3-7c2149613d3e"),
  85. new UUID("fd037134-85d4-f241-72c6-4f42164fedee"),
  86. new UUID("c4ca6188-9127-4f31-0158-23c4e2f93304"),
  87. new UUID("18b3a4b5-b463-bd48-e4b6-71eaac76c515"),
  88. new UUID("db84829b-462c-ee83-1e27-9bbee66bd624"),
  89. new UUID("b906c4ba-703b-1940-32a3-0c7f7d791510"),
  90. new UUID("82e99230-c906-1403-4d9c-3889dd98daba"),
  91. new UUID("349a3801-54f9-bf2c-3bd0-1ac89772af01"),
  92. new UUID("efcf670c-2d18-8128-973a-034ebc806b67"),
  93. new UUID("9b0c1c4e-8ac7-7969-1494-28c874c4f668"),
  94. new UUID("9ba1c942-08be-e43a-fb29-16ad440efc50"),
  95. new UUID("201f3fdf-cb1f-dbec-201f-7333e328ae7c"),
  96. new UUID("47f5f6fb-22e5-ae44-f871-73aaaf4a6022"),
  97. new UUID("92624d3e-1068-f1aa-a5ec-8244585193ed"),
  98. new UUID("038fcec9-5ebd-8a8e-0e2e-6e71a0a1ac53"),
  99. new UUID("6883a61a-b27b-5914-a61e-dda118a9ee2c"),
  100. new UUID("b68a3d7c-de9e-fc87-eec8-543d787e5b0d"),
  101. new UUID("928cae18-e31d-76fd-9cc9-2f55160ff818"),
  102. new UUID("30047778-10ea-1af7-6881-4db7a3a5a114"),
  103. new UUID("951469f4-c7b2-c818-9dee-ad7eea8c30b7"),
  104. new UUID("4bd69a1d-1114-a0b4-625f-84e0a5237155"),
  105. new UUID("cd28b69b-9c95-bb78-3f94-8d605ff1bb12"),
  106. new UUID("a54d8ee2-28bb-80a9-7f0c-7afbbe24a5d6"),
  107. new UUID("b0dc417c-1f11-af36-2e80-7e7489fa7cdc"),
  108. new UUID("57abaae6-1d17-7b1b-5f98-6d11a6411276"),
  109. new UUID("0f86e355-dd31-a61c-fdb0-3a96b9aad05f"),
  110. new UUID("514af488-9051-044a-b3fc-d4dbf76377c6"),
  111. new UUID("aa2df84d-cf8f-7218-527b-424a52de766e"),
  112. new UUID("1a03b575-9634-b62a-5767-3a679e81f4de"),
  113. new UUID("214aa6c1-ba6a-4578-f27c-ce7688f61d0d"),
  114. new UUID("d535471b-85bf-3b4d-a542-93bea4f59d33"),
  115. new UUID("d4416ff1-09d3-300f-4183-1b68a19b9fc1"),
  116. new UUID("0b8c8211-d78c-33e8-fa28-c51a9594e424"),
  117. new UUID("fee3df48-fa3d-1015-1e26-a205810e3001"),
  118. new UUID("1e8d90cc-a84e-e135-884c-7c82c8b03a14"),
  119. new UUID("62570842-0950-96f8-341c-809e65110823"),
  120. new UUID("d63bc1f9-fc81-9625-a0c6-007176d82eb7"),
  121. new UUID("f76cda94-41d4-a229-2872-e0296e58afe1"),
  122. new UUID("eb6ebfb2-a4b3-a19c-d388-4dd5c03823f7"),
  123. new UUID("a351b1bc-cc94-aac2-7bea-a7e6ebad15ef"),
  124. new UUID("b7c7c833-e3d3-c4e3-9fc0-131237446312"),
  125. new UUID("728646d9-cc79-08b2-32d6-937f0a835c24"),
  126. new UUID("835965c6-7f2f-bda2-5deb-2478737f91bf"),
  127. new UUID("b92ec1a5-e7ce-a76b-2b05-bcdb9311417e"),
  128. new UUID("da020525-4d94-59d6-23d7-81fdebf33148"),
  129. new UUID("9c05e5c7-6f07-6ca4-ed5a-b230390c3950"),
  130. new UUID("666307d9-a860-572d-6fd4-c3ab8865c094"),
  131. new UUID("85995026-eade-5d78-d364-94a64512cb66"),
  132. new UUID("f5fc7433-043d-e819-8298-f519a119b688"),
  133. new UUID("d60c41d2-7c24-7074-d3fa-6101cea22a51"),
  134. new UUID("c1bc7f36-3ba0-d844-f93c-93be945d644f"),
  135. new UUID("7db00ccd-f380-f3ee-439d-61968ec69c8a"),
  136. new UUID("aec4610c-757f-bc4e-c092-c6e9caf18daf"),
  137. new UUID("2b5a38b2-5e00-3a97-a495-4c826bc443e6"),
  138. new UUID("9b29cd61-c45b-5689-ded2-91756b8d76a9"),
  139. new UUID("ef62d355-c815-4816-2474-b1acc21094a6"),
  140. new UUID("8b102617-bcba-037b-86c1-b76219f90c88"),
  141. new UUID("efdc1727-8b8a-c800-4077-975fc27ee2f2"),
  142. new UUID("3d94bad0-c55b-7dcc-8763-033c59405d33"),
  143. new UUID("7570c7b5-1f22-56dd-56ef-a9168241bbb6"),
  144. new UUID("4ae8016b-31b9-03bb-c401-b1ea941db41d"),
  145. new UUID("20f063ea-8306-2562-0b07-5c853b37b31e"),
  146. new UUID("62c5de58-cb33-5743-3d07-9e4cd4352864"),
  147. new UUID("5ea3991f-c293-392e-6860-91dfa01278a3"),
  148. new UUID("2305bd75-1ca9-b03b-1faa-b176b8a8c49e"),
  149. new UUID("709ea28e-1573-c023-8bf8-520c8bc637fa"),
  150. new UUID("19999406-3a3a-d58c-a2ac-d72e555dcf51"),
  151. new UUID("7a17b059-12b2-41b1-570a-186368b6aa6f"),
  152. new UUID("ca5b3f14-3194-7a2b-c894-aa699b718d1f"),
  153. new UUID("f4f00d6e-b9fe-9292-f4cb-0ae06ea58d57"),
  154. new UUID("08464f78-3a8e-2944-cba5-0c94aff3af29"),
  155. new UUID("315c3a41-a5f3-0ba4-27da-f893f769e69b"),
  156. new UUID("5a977ed9-7f72-44e9-4c4c-6e913df8ae74"),
  157. new UUID("d83fa0e5-97ed-7eb2-e798-7bd006215cb4"),
  158. new UUID("f061723d-0a18-754f-66ee-29a44795a32f"),
  159. new UUID("eefc79be-daae-a239-8c04-890f5d23654a"),
  160. new UUID("b312b10e-65ab-a0a4-8b3c-1326ea8e3ed9"),
  161. new UUID("17c024cc-eef2-f6a0-3527-9869876d7752"),
  162. new UUID("ec952cca-61ef-aa3b-2789-4d1344f016de"),
  163. new UUID("7a4e87fe-de39-6fcb-6223-024b00893244"),
  164. new UUID("f3300ad9-3462-1d07-2044-0fef80062da0"),
  165. new UUID("c8e42d32-7310-6906-c903-cab5d4a34656"),
  166. new UUID("36f81a92-f076-5893-dc4b-7c3795e487cf"),
  167. new UUID("49aea43b-5ac3-8a44-b595-96100af0beda"),
  168. new UUID("35db4f7e-28c2-6679-cea9-3ee108f7fc7f"),
  169. new UUID("0836b67f-7f7b-f37b-c00a-460dc1521f5a"),
  170. new UUID("42dd95d5-0bc6-6392-f650-777304946c0f"),
  171. new UUID("16803a9f-5140-e042-4d7b-d28ba247c325"),
  172. new UUID("05ddbff8-aaa9-92a1-2b74-8fe77a29b445"),
  173. new UUID("1ab1b236-cd08-21e6-0cbc-0d923fc6eca2"),
  174. new UUID("0eb702e2-cc5a-9a88-56a5-661a55c0676a"),
  175. new UUID("cd7668a6-7011-d7e2-ead8-fc69eff1a104"),
  176. new UUID("e04d450d-fdb5-0432-fd68-818aaf5935f8"),
  177. new UUID("6bd01860-4ebd-127a-bb3d-d1427e8e0c42"),
  178. new UUID("70ea714f-3a97-d742-1b01-590a8fcd1db5"),
  179. new UUID("1a5fe8ac-a804-8a5d-7cbd-56bd83184568"),
  180. new UUID("b1709c8d-ecd3-54a1-4f28-d55ac0840782"),
  181. new UUID("245f3c54-f1c0-bf2e-811f-46d8eeb386e7"),
  182. new UUID("1c7600d6-661f-b87b-efe2-d7421eb93c86"),
  183. new UUID("1a2bd58e-87ff-0df8-0b4c-53e047b0bb6e"),
  184. new UUID("a8dee56f-2eae-9e7a-05a2-6fb92b97e21e"),
  185. new UUID("f2bed5f9-9d44-39af-b0cd-257b2a17fe40"),
  186. new UUID("d2f2ee58-8ad1-06c9-d8d3-3827ba31567a"),
  187. new UUID("6802d553-49da-0778-9f85-1599a2266526"),
  188. new UUID("0a9fb970-8b44-9114-d3a9-bf69cfe804d6"),
  189. new UUID("eae8905b-271a-99e2-4c0e-31106afd100c"),
  190. new UUID("2408fe9e-df1d-1d7d-f4ff-1384fa7b350f"),
  191. new UUID("3da1d753-028a-5446-24f3-9c9b856d9422"),
  192. new UUID("15468e00-3400-bb66-cecc-646d7c14458e"),
  193. new UUID("370f3a20-6ca6-9971-848c-9a01bc42ae3c"),
  194. new UUID("42b46214-4b44-79ae-deb8-0df61424ff4b"),
  195. new UUID("f22fed8b-a5ed-2c93-64d5-bdd8b93c889f"),
  196. new UUID("80700431-74ec-a008-14f8-77575e73693f"),
  197. new UUID("1cb562b0-ba21-2202-efb3-30f82cdf9595"),
  198. new UUID("41426836-7437-7e89-025d-0aa4d10f1d69"),
  199. new UUID("313b9881-4302-73c0-c7d0-0e7a36b6c224"),
  200. new UUID("85428680-6bf9-3e64-b489-6f81087c24bd"),
  201. new UUID("5c682a95-6da4-a463-0bf6-0f5b7be129d1"),
  202. new UUID("11000694-3f41-adc2-606b-eee1d66f3724"),
  203. new UUID("aa134404-7dac-7aca-2cba-435f9db875ca"),
  204. new UUID("83ff59fe-2346-f236-9009-4e3608af64c1"),
  205. new UUID("56e0ba0d-4a9f-7f27-6117-32f2ebbf6135"),
  206. new UUID("2d6daa51-3192-6794-8e2e-a15f8338ec30"),
  207. new UUID("c541c47f-e0c0-058b-ad1a-d6ae3a4584d9"),
  208. new UUID("6ed24bd8-91aa-4b12-ccc7-c97c857ab4e0"),
  209. new UUID("33339176-7ddc-9397-94a4-bf3403cbc8f5"),
  210. new UUID("7693f268-06c7-ea71-fa21-2b30d6533f8f"),
  211. new UUID("b1ed7982-c68e-a982-7561-52a88a5298c0"),
  212. new UUID("869ecdad-a44b-671e-3266-56aef2e3ac2e"),
  213. new UUID("c0c4030f-c02b-49de-24ba-2331f43fe41c"),
  214. new UUID("9f496bd2-589a-709f-16cc-69bf7df1d36c"),
  215. new UUID("15dd911d-be82-2856-26db-27659b142875"),
  216. new UUID("b8c8b2a3-9008-1771-3bfc-90924955ab2d"),
  217. new UUID("42ecd00b-9947-a97c-400a-bbc9174c7aeb"),
  218. new UUID("ffffffff-ffff-ffff-ffff-ffffffffffff"),
  219. Constants.DefaultMaterialID
  220. };
  221. /// <summary>
  222. /// Is gathering complete?
  223. /// </summary>
  224. public bool Complete { get { return m_assetUuidsToInspect.Count <= 0; } }
  225. /// <summary>
  226. /// The dictionary of UUIDs gathered so far. If Complete == true then this is all the reachable UUIDs.
  227. /// </summary>
  228. /// <value>The gathered uuids.</value>
  229. public IDictionary<UUID, sbyte> GatheredUuids { get; private set; }
  230. public HashSet<UUID> FailedUUIDs { get; private set; }
  231. public HashSet<UUID> UncertainAssetsUUIDs { get; private set; }
  232. public int possibleNotAssetCount { get; set; }
  233. public int ErrorCount { get; private set; }
  234. public int AssetGetCount;
  235. private bool verbose = true;
  236. /// <summary>
  237. /// Gets the next UUID to inspect.
  238. /// </summary>
  239. /// <value>If there is no next UUID then returns null</value>
  240. public UUID? NextUuidToInspect
  241. {
  242. get
  243. {
  244. return Complete ? null : m_assetUuidsToInspect.Peek();
  245. }
  246. }
  247. protected IAssetService m_assetService;
  248. protected Queue<UUID> m_assetUuidsToInspect;
  249. /// <summary>
  250. /// Initializes a new instance of the <see cref="OpenSim.Region.Framework.Scenes.UuidGatherer"/> class.
  251. /// </summary>
  252. /// <remarks>In this case the collection of gathered assets will start out blank.</remarks>
  253. /// <param name="assetService">
  254. /// Asset service.
  255. /// </param>
  256. public UuidGatherer(IAssetService assetService) : this(assetService, new Dictionary<UUID, sbyte>(),
  257. new HashSet <UUID>(),new HashSet <UUID>()) {}
  258. public UuidGatherer(IAssetService assetService, IDictionary<UUID, sbyte> collector) : this(assetService, collector,
  259. new HashSet <UUID>(), new HashSet <UUID>()) {}
  260. /// <summary>
  261. /// Initializes a new instance of the <see cref="OpenSim.Region.Framework.Scenes.UuidGatherer"/> class.
  262. /// </summary>
  263. /// <param name="assetService">
  264. /// Asset service.
  265. /// </param>
  266. /// <param name="collector">
  267. /// Gathered UUIDs will be collected in this dictionary.
  268. /// It can be pre-populated if you want to stop the gatherer from analyzing assets that have already been fetched and inspected.
  269. /// </param>
  270. public UuidGatherer(IAssetService assetService, IDictionary<UUID, sbyte> collector, HashSet <UUID> failedIDs, HashSet <UUID> uncertainAssetsUUIDs)
  271. {
  272. m_assetService = assetService;
  273. GatheredUuids = collector;
  274. // FIXME: Not efficient for searching, can improve.
  275. m_assetUuidsToInspect = new Queue<UUID>();
  276. FailedUUIDs = failedIDs;
  277. UncertainAssetsUUIDs = uncertainAssetsUUIDs;
  278. ErrorCount = 0;
  279. possibleNotAssetCount = 0;
  280. AssetGetCount = 0;
  281. }
  282. public bool AddGathered(UUID uuid, sbyte type)
  283. {
  284. if (uuid.IsZero())
  285. return false;
  286. if (ToSkip.Contains(uuid))
  287. return false;
  288. if (FailedUUIDs.Contains(uuid))
  289. {
  290. if (UncertainAssetsUUIDs.Contains(uuid))
  291. possibleNotAssetCount++;
  292. else
  293. ErrorCount++;
  294. return false;
  295. }
  296. if (GatheredUuids.ContainsKey(uuid))
  297. return false;
  298. if (m_assetUuidsToInspect.Contains(uuid))
  299. return false;
  300. //m_log.DebugFormat("[UUID GATHERER]: Adding asset {0} for inspection", uuid);
  301. GatheredUuids[uuid] = type;
  302. return true;
  303. }
  304. /// <summary>
  305. /// Adds the asset uuid for inspection during the gathering process.
  306. /// </summary>
  307. /// <returns><c>true</c>, if for inspection was added, <c>false</c> otherwise.</returns>
  308. /// <param name="uuid">UUID.</param>
  309. public bool AddForInspection(UUID uuid)
  310. {
  311. if(uuid.IsZero())
  312. return false;
  313. if(ToSkip.Contains(uuid))
  314. return false;
  315. if(FailedUUIDs.Contains(uuid))
  316. {
  317. if(UncertainAssetsUUIDs.Contains(uuid))
  318. possibleNotAssetCount++;
  319. else
  320. ErrorCount++;
  321. return false;
  322. }
  323. if(GatheredUuids.ContainsKey(uuid))
  324. return false;
  325. if (m_assetUuidsToInspect.Contains(uuid))
  326. return false;
  327. //m_log.DebugFormat("[UUID GATHERER]: Adding asset {0} for inspection", uuid);
  328. m_assetUuidsToInspect.Enqueue(uuid);
  329. return true;
  330. }
  331. /// <summary>
  332. /// Gather all the asset uuids associated with a given object.
  333. /// </summary>
  334. /// <remarks>
  335. /// This includes both those directly associated with
  336. /// it (e.g. face textures) and recursively, those of items within it's inventory (e.g. objects contained
  337. /// within this object).
  338. /// </remarks>
  339. /// <param name="sceneObject">The scene object for which to gather assets</param>
  340. public void AddForInspection(SceneObjectGroup sceneObject)
  341. {
  342. //m_log.DebugFormat(
  343. // "[UUID GATHERER]: Getting assets for object {0}, {1}", sceneObject.Name, sceneObject.UUID);
  344. if(sceneObject.IsDeleted)
  345. return;
  346. SceneObjectPart[] parts = sceneObject.Parts;
  347. for (int i = 0; i < parts.Length; ++i)
  348. {
  349. SceneObjectPart part = parts[i];
  350. // m_log.DebugFormat(
  351. // "[UUID GATHERER]: Getting part {0}, {1} for object {2}", part.Name, part.UUID, sceneObject.UUID);
  352. try
  353. {
  354. Primitive.TextureEntry textureEntry = part.Shape.Textures;
  355. if (textureEntry is not null)
  356. {
  357. // Get the prim's default texture. This will be used for faces which don't have their own texture
  358. if (textureEntry.DefaultTexture is not null)
  359. RecordTextureEntryAssetUuids(textureEntry.DefaultTexture);
  360. if (textureEntry.FaceTextures is not null)
  361. {
  362. // Loop through the rest of the texture faces (a non-null face means the face is different from DefaultTexture)
  363. int nsides = part.GetNumberOfSides();
  364. foreach (Primitive.TextureEntryFace texture in textureEntry.FaceTextures)
  365. {
  366. if (texture is not null)
  367. RecordTextureEntryAssetUuids(texture);
  368. if(--nsides <= 0)
  369. break;
  370. }
  371. }
  372. }
  373. if (part.Shape.SculptTexture.IsNotZero())
  374. GatheredUuids[part.Shape.SculptTexture] = (sbyte)AssetType.Texture;
  375. if (part.Shape.ProjectionTextureUUID.IsNotZero())
  376. GatheredUuids[part.Shape.ProjectionTextureUUID] = (sbyte)AssetType.Texture;
  377. if(part.Shape.RenderMaterials is not null)
  378. {
  379. if (part.Shape.RenderMaterials.entries is not null)
  380. {
  381. for (int j = 0; j < part.Shape.RenderMaterials.entries.Length; ++j)
  382. {
  383. if (part.Shape.RenderMaterials.entries[j].id.IsNotZero())
  384. AddForInspection(part.Shape.RenderMaterials.entries[j].id, (sbyte)AssetType.Material);
  385. }
  386. }
  387. if (part.Shape.RenderMaterials.overrides is not null)
  388. {
  389. for (int j = 0; j < part.Shape.RenderMaterials.overrides.Length; ++j)
  390. {
  391. if(!string.IsNullOrEmpty(part.Shape.RenderMaterials.overrides[j].data))
  392. RecordEmbeddedAssetDataUuids(part.Shape.RenderMaterials.overrides[j].data);
  393. }
  394. }
  395. }
  396. UUID collisionSound = part.CollisionSound;
  397. if (collisionSound.IsNotZero() && collisionSound.NotEqual(part.invalidCollisionSoundUUID))
  398. GatheredUuids[collisionSound] = (sbyte)AssetType.Sound;
  399. UUID soundID = part.Sound;
  400. if (soundID.IsNotZero())
  401. GatheredUuids[soundID] = (sbyte)AssetType.Sound;
  402. if (part.ParticleSystem.Length > 0)
  403. {
  404. try
  405. {
  406. Primitive.ParticleSystem ps = new(part.ParticleSystem, 0);
  407. if (ps.Texture.IsNotZero())
  408. GatheredUuids[ps.Texture] = (sbyte)AssetType.Texture;
  409. }
  410. catch (Exception)
  411. {
  412. m_log.WarnFormat(
  413. "[UUID GATHERER]: Could not check particle system for part {0} {1} in object {2} {3} since it is corrupt. Continuing.",
  414. part.Name, part.UUID, sceneObject.Name, sceneObject.UUID);
  415. }
  416. }
  417. List<TaskInventoryItem> items = part.TaskInventory.GetItems();
  418. // Now analyze this prim's inventory items to preserve all the uuids that they reference
  419. for(int j = 0; j < items.Count; ++j)
  420. {
  421. TaskInventoryItem tii = items[j];
  422. AddForInspection(tii.AssetID, (sbyte)tii.Type);
  423. }
  424. if(part.Animations is not null && part.Animations.Count > 0)
  425. {
  426. foreach(UUID id in part.Animations.Keys)
  427. {
  428. if(id.IsNotZero() && !ToSkip.Contains(id) && !FailedUUIDs.Contains(id))
  429. {
  430. GatheredUuids[id] = (sbyte)AssetType.Animation;
  431. }
  432. }
  433. }
  434. RecordMaterialsUuids(part);
  435. }
  436. catch (Exception e)
  437. {
  438. m_log.Error($"[UUID GATHERER]: Failed to get part - {e.Message}");
  439. }
  440. }
  441. if(sceneObject.TemporaryInstance)
  442. sceneObject.Dispose();
  443. }
  444. /// <summary>
  445. /// Gathers the next set of assets returned by the next uuid to get from the asset service.
  446. /// </summary>
  447. /// <returns>false if gathering is already complete, true otherwise</returns>
  448. public bool GatherNext()
  449. {
  450. if (Complete)
  451. return false;
  452. UUID nextToInspect = m_assetUuidsToInspect.Dequeue();
  453. // m_log.DebugFormat("[UUID GATHERER]: Inspecting asset {0}", nextToInspect);
  454. GetAssetUuids(nextToInspect);
  455. return m_assetUuidsToInspect.Count > 0;
  456. }
  457. /// <summary>
  458. /// Gathers all remaining asset UUIDS no matter how many calls are required to the asset service.
  459. /// </summary>
  460. /// <returns>false if gathering is already complete, true otherwise</returns>
  461. public bool GatherAll(bool report = false)
  462. {
  463. if (Complete)
  464. return false;
  465. if(report)
  466. verbose = false;
  467. while (GatherNext());
  468. if (report && FailedUUIDs.Count > 0)
  469. {
  470. StringBuilder sb = new(512);
  471. int i = FailedUUIDs.Count;
  472. sb.Append("[UUID GATHERER]: UUIDs that are not assets or really missing assets:\n\t");
  473. foreach (UUID id in FailedUUIDs)
  474. {
  475. sb.Append(id);
  476. if (--i > 0)
  477. sb.Append(',');
  478. }
  479. m_log.Debug(sb.ToString());
  480. }
  481. return true;
  482. }
  483. /// <summary>
  484. /// Gather all the asset uuids associated with the asset referenced by a given uuid
  485. /// </summary>
  486. /// <remarks>
  487. /// This includes both those directly associated with
  488. /// it (e.g. face textures) and recursively, those of items within it's inventory (e.g. objects contained
  489. /// within this object).
  490. /// This method assumes that the asset type associated with this asset in persistent storage is correct (which
  491. /// should always be the case). So with this method we always need to retrieve asset data even if the asset
  492. /// is of a type which is known not to reference any other assets
  493. /// </remarks>
  494. /// <param name="assetUuid">The uuid of the asset for which to gather referenced assets</param>
  495. private void GetAssetUuids(UUID assetUuid)
  496. {
  497. if(assetUuid.IsZero())
  498. return;
  499. if(FailedUUIDs.Contains(assetUuid))
  500. {
  501. if(UncertainAssetsUUIDs.Contains(assetUuid))
  502. possibleNotAssetCount++;
  503. else
  504. ErrorCount++;
  505. return;
  506. }
  507. if (GatheredUuids.ContainsKey(assetUuid))
  508. return;
  509. AssetBase assetBase;
  510. try
  511. {
  512. assetBase = GetAsset(assetUuid);
  513. }
  514. catch (Exception e)
  515. {
  516. if(verbose)
  517. m_log.Error($"[UUID GATHERER]: Failed to get asset {assetUuid} : {e.Message}");
  518. ErrorCount++;
  519. FailedUUIDs.Add(assetUuid);
  520. return;
  521. }
  522. if(assetBase == null)
  523. {
  524. // m_log.ErrorFormat("[UUID GATHERER]: asset {0} not found", assetUuid);
  525. FailedUUIDs.Add(assetUuid);
  526. if(UncertainAssetsUUIDs.Contains(assetUuid))
  527. possibleNotAssetCount++;
  528. else
  529. ErrorCount++;
  530. return;
  531. }
  532. ++AssetGetCount;
  533. if(UncertainAssetsUUIDs.Contains(assetUuid))
  534. UncertainAssetsUUIDs.Remove(assetUuid);
  535. if(assetBase.Data == null || assetBase.Data.Length == 0)
  536. {
  537. // m_log.ErrorFormat("[UUID GATHERER]: asset {0}, type {1} has no data", assetUuid, assetType);
  538. ErrorCount++;
  539. FailedUUIDs.Add(assetUuid);
  540. return;
  541. }
  542. sbyte assetType = assetBase.Type;
  543. GatheredUuids[assetUuid] = assetType;
  544. if (assetBase.Data.Length < 36)
  545. return;
  546. try
  547. {
  548. switch ((AssetType)assetType)
  549. {
  550. case AssetType.Bodypart:
  551. case AssetType.Clothing:
  552. RecordWearableAssetUuids(assetBase);
  553. break;
  554. case AssetType.Gesture:
  555. RecordGestureAssetUuids(assetBase);
  556. break;
  557. case AssetType.Notecard:
  558. RecordNoteCardEmbeddedAssetUuids(assetBase);
  559. break;
  560. case AssetType.LSLText:
  561. RecordEmbeddedAssetDataUuids(assetBase);
  562. break;
  563. case (AssetType)AssetType.OSMaterial:
  564. RecordMaterialAssetUuids(assetBase);
  565. break;
  566. case AssetType.Object:
  567. RecordSceneObjectAssetUuids(assetBase);
  568. break;
  569. case AssetType.Settings:
  570. RecordEmbeddedAssetDataUuids(assetBase); // BAD to do
  571. break;
  572. case AssetType.Material:
  573. RecordEmbeddedAssetDataUuids(assetBase);
  574. break;
  575. default:
  576. break;
  577. }
  578. }
  579. catch (Exception e)
  580. {
  581. if(verbose)
  582. m_log.Error($"[UUID GATHERER]: Failed to gather uuids for asset with id {assetUuid} type {assetType}: {e.Message}");
  583. GatheredUuids.Remove(assetUuid);
  584. ErrorCount++;
  585. FailedUUIDs.Add(assetUuid);
  586. }
  587. }
  588. private void AddForInspection(UUID assetUuid, sbyte assetType)
  589. {
  590. if(assetUuid.IsZero())
  591. return;
  592. // Here, we want to collect uuids which require further asset fetches but mark the others as gathered
  593. if(FailedUUIDs.Contains(assetUuid))
  594. {
  595. if(UncertainAssetsUUIDs.Contains(assetUuid))
  596. possibleNotAssetCount++;
  597. else
  598. ErrorCount++;
  599. return;
  600. }
  601. if(GatheredUuids.ContainsKey(assetUuid))
  602. return;
  603. try
  604. {
  605. switch (assetType)
  606. {
  607. case (sbyte)AssetType.Bodypart:
  608. case (sbyte)AssetType.Clothing:
  609. case (sbyte)AssetType.Gesture:
  610. case (sbyte)AssetType.Notecard:
  611. case (sbyte)AssetType.LSLText:
  612. case (sbyte)AssetType.OSMaterial:
  613. case (sbyte)AssetType.Object:
  614. case (sbyte)AssetType.Settings:
  615. case (sbyte)AssetType.Material:
  616. AddForInspection(assetUuid);
  617. break;
  618. default:
  619. GatheredUuids[assetUuid] = assetType;
  620. break;
  621. }
  622. }
  623. catch (Exception)
  624. {
  625. m_log.Error(
  626. $"[UUID GATHERER]: Failed to gather uuids for asset id {assetUuid}, type {assetType}");
  627. throw;
  628. }
  629. }
  630. /// <summary>
  631. /// Collect all the asset uuids found in one face of a Texture Entry.
  632. /// </summary>
  633. private void RecordTextureEntryAssetUuids(Primitive.TextureEntryFace texture)
  634. {
  635. UUID teid = texture.TextureID;
  636. if (!teid.IsZero() &&
  637. !ToSkip.Contains(teid) &&
  638. !FailedUUIDs.Contains(teid))
  639. {
  640. GatheredUuids[teid] = (sbyte)AssetType.Texture;
  641. }
  642. if (!texture.MaterialID.IsZero())
  643. AddForInspection(texture.MaterialID);
  644. }
  645. /// <summary>
  646. /// Gather all of the texture asset UUIDs used to reference "Materials" such as normal and specular maps
  647. /// stored in legacy format in part.DynAttrs
  648. /// </summary>
  649. /// <param name="part"></param>
  650. private void RecordMaterialsUuids(SceneObjectPart part)
  651. {
  652. // scan thru the dynAttrs map of this part for any textures used as materials
  653. if(part.DynAttrs == null)
  654. return;
  655. lock (part.DynAttrs)
  656. {
  657. if (!part.DynAttrs.TryGetStore("OpenSim", "Materials", out OSDMap materialsStore))
  658. return;
  659. if (materialsStore == null)
  660. return;
  661. materialsStore.TryGetValue("Materials", out OSD osdMaterials);
  662. if (osdMaterials is OSDArray matsArr)
  663. {
  664. //m_log.Info("[UUID Gatherer]: found Materials: " + OSDParser.SerializeJsonString(osd));
  665. foreach (OSDMap matMap in matsArr)
  666. {
  667. try
  668. {
  669. if (matMap.ContainsKey("Material"))
  670. {
  671. OSDMap mat = matMap["Material"] as OSDMap;
  672. if (mat.TryGetValue("NormMap", out OSD tmap))
  673. {
  674. UUID normalMapId = tmap.AsUUID();
  675. if (normalMapId.IsNotZero())
  676. {
  677. GatheredUuids[normalMapId] = (sbyte)AssetType.Texture;
  678. //m_log.Info("[UUID Gatherer]: found normal map ID: " + normalMapId.ToString());
  679. }
  680. }
  681. if (mat.TryGetValue("SpecMap", out OSD tsmap))
  682. {
  683. UUID specularMapId = tsmap.AsUUID();
  684. if (specularMapId.IsNotZero())
  685. {
  686. GatheredUuids[specularMapId] = (sbyte)AssetType.Texture;
  687. //m_log.Info("[UUID Gatherer]: found specular map ID: " + specularMapId.ToString());
  688. }
  689. }
  690. }
  691. }
  692. catch (Exception e)
  693. {
  694. m_log.Warn($"[UUID Gatherer]: exception getting materials: {e.Message}");
  695. }
  696. }
  697. }
  698. }
  699. }
  700. /// <summary>
  701. /// Get an asset synchronously, potentially using an asynchronous callback. If the
  702. /// asynchronous callback is used, we will wait for it to complete.
  703. /// </summary>
  704. /// <param name="uuid"></param>
  705. /// <returns></returns>
  706. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  707. protected virtual AssetBase GetAsset(UUID uuid)
  708. {
  709. return m_assetService.Get(uuid.ToString());
  710. }
  711. /// <summary>
  712. /// Record the asset uuids embedded within the given text (e.g. a script).
  713. /// </summary>
  714. /// <param name="textAsset"></param>
  715. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  716. private void RecordEmbeddedAssetDataUuids(AssetBase textAsset)
  717. {
  718. RecordEmbeddedAssetDataUuids(new osUTF8(textAsset.Data));
  719. }
  720. private unsafe void RecordEmbeddedAssetDataUuids(osUTF8 data)
  721. {
  722. //if (data.Length < 36)
  723. // return;
  724. int indx = 8;
  725. while(indx < data.Length - 28)
  726. {
  727. if (data[indx] == (byte)'-')
  728. {
  729. if (osUTF8Slice.TryParseUUID(new osUTF8Slice(data.GetArray(), indx - 8 , 36), out UUID id))
  730. {
  731. if (id.IsNotZero())
  732. {
  733. UncertainAssetsUUIDs.Add(id);
  734. AddForInspection(id);
  735. }
  736. indx += 37;
  737. }
  738. else
  739. indx += 9;
  740. }
  741. else
  742. indx++;
  743. }
  744. }
  745. private void RecordEmbeddedAssetDataUuids(ReadOnlySpan<char> data)
  746. {
  747. if (data.Length < 36)
  748. return;
  749. int indx = 8;
  750. while (indx < data.Length - 28)
  751. {
  752. if (data[indx] == '-')
  753. {
  754. if (UUID.TryParse(data.Slice(indx - 8, 36), out UUID id))
  755. {
  756. if (id.IsNotZero())
  757. {
  758. UncertainAssetsUUIDs.Add(id);
  759. AddForInspection(id);
  760. }
  761. indx += 37;
  762. }
  763. else
  764. indx += 9;
  765. }
  766. else
  767. indx++;
  768. }
  769. }
  770. private void RecordNoteCardEmbeddedAssetUuids(AssetBase textAsset)
  771. {
  772. List<UUID> ids = SLUtil.GetEmbeddedAssetIDs(textAsset.Data);
  773. if(ids is null)
  774. return;
  775. for(int i = 0; i < ids.Count; ++i)
  776. {
  777. if (ids[i].IsZero())
  778. continue;
  779. UncertainAssetsUUIDs.Add(ids[i]);
  780. AddForInspection(ids[i]);
  781. }
  782. }
  783. private static readonly byte[] wearableSeps = new byte[]{(byte)' ', (byte)'\t'};
  784. /// <summary>
  785. /// Record the uuids referenced by the given wearable asset
  786. /// </summary>
  787. /// <param name="asset"></param>
  788. private void RecordWearableAssetUuids(AssetBase asset)
  789. {
  790. if (asset.Data is null || asset.Data.Length < 64)
  791. return;
  792. try
  793. {
  794. osUTF8Slice ostmp = new(asset.Data);
  795. if (!ostmp.SkipLine()) // version
  796. return;
  797. if (!ostmp.SkipLine()) // name
  798. return;
  799. if (!ostmp.SkipLine()) // description
  800. return;
  801. if (!ostmp.SkipLine())
  802. return;
  803. while (ostmp.ReadLine(out osUTF8Slice line))
  804. {
  805. line.SelfTrim(wearableSeps);
  806. osUTF8Slice[] parts = line.Split(wearableSeps);
  807. if(parts[0].Length == 0)
  808. continue;
  809. parts[0].SelfTrim(wearableSeps);
  810. if (parts[0].Equals(parametersB))
  811. {
  812. if (parts[1].Length == 0)
  813. return;
  814. parts[1].SelfTrim(wearableSeps);
  815. if (!osUTF8Slice.TryParseInt(parts[1], out int count))
  816. return;
  817. for (int i = 0; i < count; ++i)
  818. {
  819. if (!ostmp.SkipLine())
  820. return;
  821. }
  822. }
  823. else if (parts[0].Equals(texturesB))
  824. {
  825. if(parts[1].Length == 0)
  826. return;
  827. parts[1].SelfTrim(wearableSeps);
  828. if (!osUTF8Slice.TryParseInt(parts[1], out int count) || count == 0)
  829. return;
  830. for(int i = 0; i < count; ++i)
  831. {
  832. if(!ostmp.ReadLine(out osUTF8Slice texline))
  833. return;
  834. texline.SelfTrim(wearableSeps);
  835. osUTF8Slice[] texparts = texline.Split(wearableSeps);
  836. if(texparts.Length <2 || texparts[1].Length < 36)
  837. continue;
  838. texparts[1].SelfTrim(wearableSeps);
  839. if (UUID.TryParse(texparts[1].ToString(), out UUID id) && id.IsNotZero())
  840. GatheredUuids[id] = (sbyte)AssetType.Texture;
  841. }
  842. }
  843. }
  844. }
  845. catch
  846. {
  847. }
  848. }
  849. private int getxmlNode(osUTF8Slice data, out osUTF8Slice h)
  850. {
  851. h = data;
  852. int st;
  853. while ((st = data.IndexOf('<')) >= 0)
  854. {
  855. if (st > 0 && data[st - 1] == (byte)'\\')
  856. data.SubUTF8Self(st + 1);
  857. break;
  858. }
  859. if (st < 0)
  860. return -1;
  861. ++st;
  862. int ed;
  863. while ((ed = data.IndexOf('>')) >= 0)
  864. {
  865. if (data[st - 1] == (byte)'\\')
  866. data.SubUTF8Self(st + 1);
  867. break;
  868. }
  869. if (ed < 0)
  870. return -1;
  871. h = data.SubUTF8(st, ed - st);
  872. h.SelfTrim();
  873. ++ed;
  874. data.SubUTF8Self(ed);
  875. return ed;
  876. }
  877. private bool TryGetxmlUUIDValue(osUTF8Slice data, out UUID id)
  878. {
  879. id = UUID.Zero;
  880. if(getxmlNode(data, out osUTF8Slice h) < 0)
  881. return false;
  882. if (h.StartsWith(UUIDB))
  883. {
  884. if (h.EndsWith((byte)'/'))
  885. return true;
  886. int indx = data.IndexOf((byte)'<');
  887. if (indx < 0)
  888. return false;
  889. osUTF8Slice tmp = data.SubUTF8(0, indx);
  890. data.SubUTF8Self(indx);
  891. return osUTF8Slice.TryParseUUID(tmp, out id);
  892. }
  893. if (h.StartsWith(uuidB))
  894. {
  895. if (h.EndsWith((byte)'/'))
  896. return true;
  897. int indx = data.IndexOf((byte)'<');
  898. if (indx < 0)
  899. return false;
  900. osUTF8Slice tmp = data.SubUTF8(0, indx);
  901. data.SubUTF8Self(indx);
  902. return osUTF8Slice.TryParseUUID(tmp, out id);
  903. }
  904. return false;
  905. }
  906. private bool TryGetXMLBinary(osUTF8Slice data, out byte[] te)
  907. {
  908. te = null;
  909. int indx = data.IndexOf((byte)'<');
  910. if(indx <= 0)
  911. return false;
  912. osUTF8Slice tmp = data.SubUTF8(0, indx);
  913. data.SubUTF8Self(indx);
  914. tmp.SelfTrim();
  915. if(tmp.Length == 0)
  916. return false;
  917. try
  918. {
  919. te = Convert.FromBase64String(tmp.ToString()); // need to replace
  920. return true;
  921. }
  922. catch { }
  923. return false;
  924. }
  925. // bad ugly
  926. private static readonly byte[] UUIDB = osUTF8.GetASCIIBytes("UUID");
  927. private static readonly byte[] uuidB = osUTF8.GetASCIIBytes("uuid");
  928. private static readonly byte[] SOPAnimsB = osUTF8.GetASCIIBytes("SOPAnims");
  929. private static readonly byte[] CollisionSoundB = osUTF8.GetASCIIBytes("CollisionSound");
  930. private static readonly byte[] SoundIDB = osUTF8.GetASCIIBytes("SoundID");
  931. private static readonly byte[] SculptTextureB = osUTF8.GetASCIIBytes("SculptTexture");
  932. private static readonly byte[] ExtraParamsB = osUTF8.GetASCIIBytes("ExtraParams");
  933. private static readonly byte[] ParticleSystemB = osUTF8.GetASCIIBytes("ParticleSystem");
  934. private static readonly byte[] TextureEntryB = osUTF8.GetASCIIBytes("TextureEntry");
  935. private static readonly byte[] TaskInventoryB = osUTF8.GetASCIIBytes("TaskInventory");
  936. private static readonly byte[] endTaskInventoryB = osUTF8.GetASCIIBytes("/TaskInventory");
  937. private static readonly byte[] AssetIDB = osUTF8.GetASCIIBytes("AssetID");
  938. private static readonly byte[] texturesB = osUTF8.GetASCIIBytes("textures");
  939. private static readonly byte[] parametersB = osUTF8.GetASCIIBytes("parameters");
  940. private static readonly byte[] MatOvrdB = osUTF8.GetASCIIBytes("MatOvrd");
  941. /// <summary>
  942. /// Get all the asset uuids associated with a given object. This includes both those directly associated with
  943. /// it (e.g. face textures) and recursively, those of items within it's inventory (e.g. objects contained
  944. /// within this object).
  945. /// </summary>
  946. /// <param name="sceneObjectAsset"></param>
  947. private void RecordSceneObjectAssetUuids(AssetBase sceneObjectAsset)
  948. {
  949. osUTF8Slice data = new(sceneObjectAsset.Data);
  950. while (getxmlNode(data, out osUTF8Slice nodeName) > 0)
  951. {
  952. if (nodeName.StartsWith((byte)'/'))
  953. continue;
  954. if (nodeName.StartsWith(SOPAnimsB))
  955. {
  956. if (nodeName.EndsWith((byte)'/'))
  957. continue;
  958. if (TryGetXMLBinary(data, out byte[] abytes) && abytes != null && abytes.Length > 16)
  959. {
  960. try
  961. {
  962. int count = Utils.BytesToUInt16(abytes, 0);
  963. if (count >0)
  964. {
  965. int pos = 2;
  966. while (--count >= 0)
  967. {
  968. UUID id = new(abytes, pos);
  969. if (id.IsZero())
  970. break;
  971. if (!ToSkip.Contains(id) &&
  972. !FailedUUIDs.Contains(id))
  973. {
  974. GatheredUuids[id] = (sbyte)AssetType.Animation;
  975. }
  976. pos += 16;
  977. int strlen = data[pos++];
  978. pos += strlen;
  979. }
  980. }
  981. abytes = null;
  982. }
  983. catch { }
  984. }
  985. }
  986. else if (nodeName.StartsWith(CollisionSoundB))
  987. {
  988. if (!nodeName.EndsWith((byte)'d'))
  989. continue;
  990. if (TryGetxmlUUIDValue(data, out UUID id) && id.IsNotZero())
  991. GatheredUuids[id] = (sbyte)AssetType.Sound;
  992. }
  993. else if (nodeName.StartsWith(SoundIDB))
  994. {
  995. if (nodeName.EndsWith((byte)'/'))
  996. continue;
  997. if (TryGetxmlUUIDValue(data, out UUID id) && id.IsNotZero())
  998. GatheredUuids[id] = (sbyte)AssetType.Sound;
  999. }
  1000. else if (nodeName.StartsWith(SculptTextureB))
  1001. {
  1002. if (nodeName.EndsWith((byte)'/'))
  1003. continue;
  1004. if (TryGetxmlUUIDValue(data, out UUID id) && id.IsNotZero())
  1005. GatheredUuids[id] = (sbyte)AssetType.Texture; // can be mesh but no prob
  1006. }
  1007. else if (nodeName.StartsWith(ExtraParamsB))
  1008. {
  1009. if (nodeName.EndsWith((byte)'/'))
  1010. continue;
  1011. if (TryGetXMLBinary(data, out byte[] exbytes) && exbytes != null && exbytes.Length > 16)
  1012. {
  1013. try
  1014. {
  1015. PrimitiveBaseShape ps = new();
  1016. ps.ReadInExtraParamsBytes(exbytes);
  1017. UUID teid = ps.ProjectionTextureUUID;
  1018. if (teid.IsNotZero() &&
  1019. !ToSkip.Contains(teid) &&
  1020. !FailedUUIDs.Contains(teid))
  1021. {
  1022. GatheredUuids[teid] = (sbyte)AssetType.Texture;
  1023. }
  1024. if(ps.RenderMaterials is not null)
  1025. {
  1026. if (ps.RenderMaterials.entries is not null)
  1027. {
  1028. for (int j = 0; j < ps.RenderMaterials.entries.Length; ++j)
  1029. {
  1030. if (ps.RenderMaterials.entries[j].id.IsNotZero())
  1031. AddForInspection(ps.RenderMaterials.entries[j].id, (sbyte)AssetType.Material);
  1032. }
  1033. }
  1034. }
  1035. /* multiple store
  1036. teid = ps.SculptTexture; //??
  1037. if (teid != UUID.Zero &&
  1038. !ToSkip.Contains(teid) &&
  1039. !FailedUUIDs.Contains(teid))
  1040. {
  1041. GatheredUuids[teid] = (sbyte)AssetType.Texture;
  1042. }
  1043. */
  1044. ps = null;
  1045. exbytes = null;
  1046. }
  1047. catch { }
  1048. }
  1049. }
  1050. else if (nodeName.StartsWith(ParticleSystemB))
  1051. {
  1052. if (nodeName.EndsWith((byte)'/'))
  1053. continue;
  1054. if (TryGetXMLBinary(data, out byte[] psbytes) && psbytes != null && psbytes.Length > 16)
  1055. {
  1056. try
  1057. {
  1058. Primitive.ParticleSystem ps = new(psbytes, 0);
  1059. UUID teid = ps.Texture;
  1060. if (teid.IsNotZero() &&
  1061. !ToSkip.Contains(teid) &&
  1062. !FailedUUIDs.Contains(teid))
  1063. {
  1064. GatheredUuids[teid] = (sbyte)AssetType.Texture;
  1065. }
  1066. psbytes = null;
  1067. }
  1068. catch { }
  1069. }
  1070. }
  1071. else if (nodeName.StartsWith(TextureEntryB))
  1072. {
  1073. if (nodeName.EndsWith((byte)'/'))
  1074. continue;
  1075. if (TryGetXMLBinary(data, out byte[] tebytes) && tebytes != null && tebytes.Length > 16)
  1076. {
  1077. try
  1078. {
  1079. Primitive.TextureEntry te = new(tebytes, 0, tebytes.Length);
  1080. if (te is not null)
  1081. {
  1082. // Get the prim's default texture. This will be used for faces which don't have their own texture
  1083. if (te.DefaultTexture is not null)
  1084. RecordTextureEntryAssetUuids(te.DefaultTexture);
  1085. if (te.FaceTextures is not null)
  1086. {
  1087. // Loop through the rest of the texture faces (a non-null face means the face is different from DefaultTexture)
  1088. foreach (Primitive.TextureEntryFace texture in te.FaceTextures)
  1089. {
  1090. if (texture is not null)
  1091. RecordTextureEntryAssetUuids(texture);
  1092. }
  1093. }
  1094. }
  1095. te = null;
  1096. }
  1097. catch { }
  1098. }
  1099. }
  1100. else if (nodeName.StartsWith(TaskInventoryB))
  1101. {
  1102. if (nodeName.EndsWith((byte)'/'))
  1103. continue;
  1104. while (getxmlNode(data, out nodeName) > 0)
  1105. {
  1106. if (nodeName.StartsWith(AssetIDB))
  1107. {
  1108. if (TryGetxmlUUIDValue(data, out UUID id) && id.IsNotZero())
  1109. AddForInspection(id);
  1110. }
  1111. else if (nodeName.StartsWith(endTaskInventoryB))
  1112. break;
  1113. }
  1114. }
  1115. else if (nodeName.StartsWith(MatOvrdB))
  1116. {
  1117. if (nodeName.EndsWith((byte)'/'))
  1118. continue;
  1119. if (TryGetXMLBinary(data, out byte[] ovrbytes) && ovrbytes != null && ovrbytes.Length > 36)
  1120. {
  1121. RecordEmbeddedAssetDataUuids(new osUTF8(ovrbytes));
  1122. }
  1123. }
  1124. }
  1125. }
  1126. /// <summary>
  1127. /// Get the asset uuid associated with a gesture
  1128. /// </summary>
  1129. /// <param name="gestureAsset"></param>
  1130. private void RecordGestureAssetUuids(AssetBase gestureAsset)
  1131. {
  1132. osUTF8Slice osdata = new(gestureAsset.Data);
  1133. if (!osdata.SkipLine()) // version
  1134. return;
  1135. if (!osdata.SkipLine()) // key
  1136. return;
  1137. if (!osdata.SkipLine()) // mask
  1138. return;
  1139. if (!osdata.SkipLine()) // trigger
  1140. return;
  1141. if (!osdata.SkipLine()) // replace
  1142. return;
  1143. if (!osdata.ReadLine(out osUTF8Slice line))
  1144. return;
  1145. if(!osUTF8Slice.TryParseInt(line, out int scount) || scount == 0)
  1146. return;
  1147. for(int i = 0; i < scount; ++i)
  1148. {
  1149. if (!osdata.ReadLine(out osUTF8Slice typeline)) // type
  1150. return;
  1151. typeline.SelfTrim();
  1152. if (!osUTF8Slice.TryParseInt(typeline, out int type))
  1153. return;
  1154. osUTF8Slice id;
  1155. switch(type)
  1156. {
  1157. case 0: // animation
  1158. case 1: // sound
  1159. if (!osdata.SkipLine()) // name
  1160. return;
  1161. if (!osdata.ReadLine(out id)) // uuid
  1162. return;
  1163. if (osUTF8Slice.TryParseUUID(id, out UUID uid) && uid.IsNotZero())
  1164. GatheredUuids[uid] = type == 0 ? (sbyte)AssetType.Animation : (sbyte)AssetType.Sound;
  1165. if (!osdata.SkipLine()) // flags
  1166. return;
  1167. break;
  1168. case 2: // chat
  1169. case 3: // wait
  1170. if (!osdata.SkipLine()) // chat text or wait time
  1171. return;
  1172. if (!osdata.SkipLine()) // flags
  1173. return;
  1174. break;
  1175. default:
  1176. return; // no idea
  1177. }
  1178. }
  1179. }
  1180. /// <summary>
  1181. /// Get the asset uuid's referenced in a material.
  1182. /// </summary>
  1183. private void RecordMaterialAssetUuids(AssetBase materialAsset)
  1184. {
  1185. osUTF8Slice data = new(materialAsset.Data);
  1186. while (getxmlNode(data, out osUTF8Slice header) > 0)
  1187. {
  1188. if (header.StartsWith((byte)'/'))
  1189. continue;
  1190. if (header.StartsWith(uuidB))
  1191. {
  1192. if(header.EndsWith((byte)'/'))
  1193. continue;
  1194. int indx = data.IndexOf((byte)'<');
  1195. if(indx < 0)
  1196. continue;
  1197. osUTF8Slice tmp = data.SubUTF8(0, indx);
  1198. if(osUTF8Slice.TryParseUUID(tmp, out UUID id) && id.IsNotZero())
  1199. GatheredUuids[id] = (sbyte)AssetType.Texture;
  1200. data.SubUTF8Self(indx);
  1201. }
  1202. }
  1203. }
  1204. }
  1205. public class HGUuidGatherer : UuidGatherer
  1206. {
  1207. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  1208. protected string m_assetServerURL;
  1209. public HGUuidGatherer(IAssetService assetService, string assetServerURL)
  1210. : this(assetService, assetServerURL, new Dictionary<UUID, sbyte>()) {}
  1211. public HGUuidGatherer(IAssetService assetService, string assetServerURL, IDictionary<UUID, sbyte> collector)
  1212. : base(assetService, collector)
  1213. {
  1214. m_assetServerURL = assetServerURL;
  1215. }
  1216. protected override AssetBase GetAsset(UUID uuid)
  1217. {
  1218. if (string.IsNullOrWhiteSpace(m_assetServerURL))
  1219. return base.GetAsset(uuid);
  1220. else
  1221. return FetchAsset(uuid);
  1222. }
  1223. public AssetBase FetchAsset(UUID assetID)
  1224. {
  1225. string IDstr = assetID.ToString();
  1226. AssetBase asset = m_assetService.Get(IDstr, m_assetServerURL, true);
  1227. if (asset is null)
  1228. m_log.Debug($"[HGUUIDGatherer]: Failed to fetch asset {IDstr} from {m_assetServerURL}");
  1229. else
  1230. m_log.Debug($"[HGUUIDGatherer]: Copied asset {IDstr} from {m_assetServerURL} to local asset server");
  1231. return asset;
  1232. }
  1233. }
  1234. }