From c2392697628a76d8dcd7bee8fd94c4af3a36ff45 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sat, 8 Feb 2020 18:45:38 +0000 Subject: [PATCH] change uuids on scripts gather --- OpenSim/Framework/Util.cs | 124 ++++++++++++++++++ .../Region/Framework/Scenes/UuidGatherer.cs | 9 +- 2 files changed, 128 insertions(+), 5 deletions(-) diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index cc5a16b384..fe95b8883d 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -843,6 +843,130 @@ namespace OpenSim.Framework return ids; } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static bool IsHexa(byte c) + { + if (c >= '0' && c <= '9') + return true; + if (c >= 'a' && c <= 'f') + return true; + if (c >= 'A' && c <= 'F') + return true; + + return false; + } + + public static List GetUUIDsOnData(byte[] s, int indx, int len) + { + var ids = new List(); + + int endA = indx + len; + if (endA > s.Length) + endA = s.Length; + if (endA - indx < 36) + return ids; + + int endB = endA - 26; + endA -= 35; + + int idbase; + int next; + int retry; + + while (indx < endA) + { + for (; indx < endA; ++indx) + { + if (IsHexa(s[indx])) + break; + } + if (indx == endA) + break; + + idbase = indx; + for (; indx < endB; ++indx) + { + if (!IsHexa(s[indx])) + break; + if (indx - idbase >= 8) + ++idbase; + } + + if (s[indx] != '-') + continue; + + ++indx; + retry = indx; + next = indx + 4; + for (; indx < next; ++indx) + { + if (!IsHexa(s[indx])) + break; + } + if (indx != next) + continue; + + if (s[indx] != '-') + { + indx = retry; + continue; + } + + ++indx; + retry = indx; + next = indx + 4; + for (; indx < next; ++indx) + { + if (!IsHexa(s[indx])) + break; + } + if (indx != next) + continue; + + if (s[indx] != '-') + { + indx = retry; + continue; + } + + ++indx; + retry = indx; + next = indx + 4; + for (; indx < next; ++indx) + { + if (!IsHexa(s[indx])) + break; + } + if (indx != next) + continue; + + if (s[indx] != '-') + { + indx = retry; + continue; + } + ++indx; + retry = indx; + + next = indx + 12; + for (; indx < next; ++indx) + { + if (!IsHexa(s[indx])) + break; + } + if (indx != next) + continue; + + if (UUID.TryParse(Encoding.ASCII.GetString(s, idbase, 36), out UUID u)) + { + ids.Add(u); + } + ++indx; + } + + return ids; + } + /// /// Is the platform Windows? /// diff --git a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs index de71ae7fe9..9f8b209345 100644 --- a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs +++ b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs @@ -558,7 +558,7 @@ namespace OpenSim.Region.Framework.Scenes } else if ((sbyte)AssetType.LSLText == assetType) { - RecordTextEmbeddedAssetUuids(assetBase); + RecordEmbeddedAssetDataUuids(assetBase); } else if ((sbyte)OpenSimAssetType.Material == assetType) { @@ -716,15 +716,14 @@ namespace OpenSim.Region.Framework.Scenes /// Record the asset uuids embedded within the given text (e.g. a script). /// /// - private void RecordTextEmbeddedAssetUuids(AssetBase textAsset) + private void RecordEmbeddedAssetDataUuids(AssetBase textAsset) { // m_log.DebugFormat("[ASSET GATHERER]: Getting assets for uuid references in asset {0}", embeddingAssetId); - string text = Utils.BytesToString(textAsset.Data); - if(text.Length < 36) + if(textAsset.Data.Length < 36) return; - List ids = Util.GetUUIDsOnString(ref text, 0, text.Length); + List ids = Util.GetUUIDsOnData(textAsset.Data, 0, textAsset.Data.Length); if (ids == null || ids.Count == 0) return;