From 8060d132b943f183bc75cbbcfeaa0b8b9631bc5e Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 6 Feb 2020 19:16:23 +0000 Subject: [PATCH] mantis 8651: try to improve notecards HG sharing ( not tested) --- OpenSim/Framework/SLUtil.cs | 64 +++++++++++++++++++ .../Region/Framework/Scenes/UuidGatherer.cs | 18 +++++- 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/OpenSim/Framework/SLUtil.cs b/OpenSim/Framework/SLUtil.cs index 0acb3b2ca0..da07f791e6 100644 --- a/OpenSim/Framework/SLUtil.cs +++ b/OpenSim/Framework/SLUtil.cs @@ -29,6 +29,7 @@ using OpenMetaverse; using System; using System.Collections.Generic; using System.Globalization; +using System.Text.RegularExpressions; namespace OpenSim.Framework { @@ -795,5 +796,68 @@ namespace OpenSim.Framework item.ID = UUID.Random(); return item; } + + public static List GetEmbeddedAssetIDs(byte[] data) + { + if (data == null || data.Length < 60) + return null; + + string note = Util.UTF8.GetString(data); + if (String.IsNullOrWhiteSpace(note)) + return null; + + // waste some time checking rigid versions + string tmpStr = note.Substring(0, 21); + if (!tmpStr.Equals("Linden text version 2")) + return null; + + tmpStr = note.Substring(24, 25); + if (!tmpStr.Equals("LLEmbeddedItems version 1")) + return null; + + tmpStr = note.Substring(52,5); + if (!tmpStr.Equals("count")) + return null; + + int limit = note.Length - 57 - 2; + if (limit > 8) + limit = 8; + + int indx = note.IndexOfAny(seps, 57, limit); + if(indx < 0) + return null; + + if (!int.TryParse(note.Substring(57, indx - 57), out int count)) + return null; + + List ids = new List(); + while(count > 0) + { + string valuestr; + UUID assetID = UUID.Zero; + indx = note.IndexOf('}'); // skip to end of permissions + indx = getField(note, indx, "asset_id", false, out valuestr); + if (indx < 0) + { + indx = getField(note, indx, "shadow_id", false, out valuestr); + if (indx < 0) + return null; + if (!UUID.TryParse(valuestr, out assetID)) + return null; + assetID = deMoronize(assetID); + } + else + { + if (!UUID.TryParse(valuestr, out assetID)) + return null; + } + ids.Add(assetID); + --count; + } + + if(ids.Count == 0) + return null; + return ids; + } } } diff --git a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs index d0c48b7f7e..3807c21813 100644 --- a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs +++ b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs @@ -364,7 +364,7 @@ namespace OpenSim.Region.Framework.Scenes } else if ((sbyte)AssetType.Notecard == assetType) { - RecordTextEmbeddedAssetUuids(assetBase); + RecordNoteCardEmbeddedAssetUuids(assetBase); } else if ((sbyte)AssetType.LSLText == assetType) { @@ -546,6 +546,22 @@ namespace OpenSim.Region.Framework.Scenes } } + private void RecordNoteCardEmbeddedAssetUuids(AssetBase textAsset) + { + List ids = SLUtil.GetEmbeddedAssetIDs(textAsset.Data); + if(ids == null) + return; + + for(int i = 0; i < ids.Count; ++i) + { + if (ids[i] == UUID.Zero) + continue; + if (!UncertainAssetsUUIDs.Contains(ids[i])) + UncertainAssetsUUIDs.Add(ids[i]); + AddForInspection(ids[i]); + } + } + /// /// Record the uuids referenced by the given wearable asset ///