From fb6d314d4db0a157799a1d49a5f467f1c051ec9b Mon Sep 17 00:00:00 2001 From: diva Date: Sat, 23 May 2009 17:51:13 +0000 Subject: This should make HG asset transfers work much better. It now uses HGUuidGatherer, which is a subclass of UuidGatherer. Hence, on-line HG asset transfers use exactly the same UUID collection code as save oar/xml. If it doesn't work, it's Justin's fault :D --- .../Framework/Scenes/Hypergrid/HGAssetMapper.cs | 122 ++++----------------- .../Scenes/Hypergrid/HGScene.Inventory.cs | 34 +++--- .../Framework/Scenes/Hypergrid/HGUuidGatherer.cs | 29 +++++ OpenSim/Region/Framework/Scenes/UuidGatherer.cs | 2 +- 4 files changed, 72 insertions(+), 115 deletions(-) create mode 100644 OpenSim/Region/Framework/Scenes/Hypergrid/HGUuidGatherer.cs (limited to 'OpenSim/Region/Framework/Scenes') diff --git a/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs b/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs index 720a09b..1d4bc9c 100644 --- a/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs +++ b/OpenSim/Region/Framework/Scenes/Hypergrid/HGAssetMapper.cs @@ -97,7 +97,7 @@ namespace OpenSim.Region.Framework.Scenes.Hypergrid return false; } - private AssetBase FetchAsset(string url, UUID assetID, bool isTexture) + public AssetBase FetchAsset(string url, UUID assetID) { AssetBase asset = m_scene.AssetService.Get(url + "/" + assetID.ToString()); @@ -109,7 +109,7 @@ namespace OpenSim.Region.Framework.Scenes.Hypergrid return null; } - private bool PostAsset(string url, AssetBase asset) + public bool PostAsset(string url, AssetBase asset) { if (asset != null) { @@ -129,7 +129,7 @@ namespace OpenSim.Region.Framework.Scenes.Hypergrid } catch { - m_log.Warn("[HGScene]: This won't work until Melanie kills a few more dragons"); + m_log.Warn("[HGScene]: Oops."); } m_scene.AssetService.Store(asset1); @@ -155,86 +155,6 @@ namespace OpenSim.Region.Framework.Scenes.Hypergrid } - private void _guardedAdd(Dictionary lst, UUID obj, bool val) - { - if (!lst.ContainsKey(obj)) - lst.Add(obj, val); - } - - private void SniffTextureUUIDs(Dictionary uuids, SceneObjectGroup sog) - { - try - { - _guardedAdd(uuids, sog.RootPart.Shape.Textures.DefaultTexture.TextureID, true); - } - catch (Exception) { } - - foreach (Primitive.TextureEntryFace tface in sog.RootPart.Shape.Textures.FaceTextures) - { - try - { - _guardedAdd(uuids, tface.TextureID, true); - } - catch (Exception) { } - } - - foreach (SceneObjectPart sop in sog.Children.Values) - { - try - { - _guardedAdd(uuids, sop.Shape.Textures.DefaultTexture.TextureID, true); - } - catch (Exception) { } - foreach (Primitive.TextureEntryFace tface in sop.Shape.Textures.FaceTextures) - { - try - { - _guardedAdd(uuids, tface.TextureID, true); - } - catch (Exception) { } - } - } - } - - private void SniffTaskInventoryUUIDs(Dictionary uuids, SceneObjectGroup sog) - { - TaskInventoryDictionary tinv = sog.RootPart.TaskInventory; - - lock (tinv) - { - foreach (TaskInventoryItem titem in tinv.Values) - { - uuids.Add(titem.AssetID, (InventoryType)titem.Type == InventoryType.Texture); - } - } - } - - private Dictionary SniffUUIDs(AssetBase asset) - { - Dictionary uuids = new Dictionary(); - if ((asset != null) && ((AssetType)asset.Type == AssetType.Object)) - { - string ass_str = Utils.BytesToString(asset.Data); - SceneObjectGroup sog = SceneObjectSerializer.FromOriginalXmlFormat(ass_str); - - SniffTextureUUIDs(uuids, sog); - - // We need to sniff further... - SniffTaskInventoryUUIDs(uuids, sog); - } - - return uuids; - } - - private Dictionary SniffUUIDs(UUID assetID) - { - //Dictionary uuids = new Dictionary(); - - AssetBase asset = m_scene.AssetService.Get(assetID.ToString()); - - return SniffUUIDs(asset); - } - private void Dump(Dictionary lst) { m_log.Debug("XXX -------- UUID DUMP ------- XXX"); @@ -259,16 +179,18 @@ namespace OpenSim.Region.Framework.Scenes.Hypergrid if (userAssetURL != null) { m_log.Debug("[HGScene]: Fetching object " + assetID + " to asset server " + userAssetURL); - AssetBase asset = FetchAsset(userAssetURL, assetID, false); + AssetBase asset = FetchAsset(userAssetURL, assetID); if (asset != null) { m_log.Debug("[HGScene]: Successfully fetched item from remote asset server " + userAssetURL); + // OK, now fetch the inside. - Dictionary ids = SniffUUIDs(asset); - Dump(ids); - foreach (KeyValuePair kvp in ids) - FetchAsset(userAssetURL, kvp.Key, kvp.Value); + Dictionary ids = new Dictionary(); + HGUuidGatherer uuidGatherer = new HGUuidGatherer(this, m_scene.AssetService, userAssetURL); + uuidGatherer.GatherAssetUuids(asset.FullID, (AssetType)asset.Type, ids); + foreach (UUID uuid in ids.Keys) + FetchAsset(userAssetURL, uuid); } else m_log.Warn("[HGScene]: Could not fetch asset from remote asset server " + userAssetURL); @@ -315,21 +237,23 @@ namespace OpenSim.Region.Framework.Scenes.Hypergrid if (userAssetURL != null) { m_log.Debug("[HGScene]: Posting object " + assetID + " to asset server " + userAssetURL); - AssetBase ass1 = m_scene.AssetService.Get(assetID.ToString()); - if (ass1 != null) + AssetBase asset = m_scene.AssetService.Get(assetID.ToString()); + if (asset != null) { - bool success = PostAsset(userAssetURL, ass1); - - // Now the inside - Dictionary ids = SniffUUIDs(assetID); - Dump(ids); - foreach (KeyValuePair kvp in ids) + Dictionary ids = new Dictionary(); + HGUuidGatherer uuidGatherer = new HGUuidGatherer(this, m_scene.AssetService, string.Empty); + uuidGatherer.GatherAssetUuids(asset.FullID, (AssetType)asset.Type, ids); + foreach (UUID uuid in ids.Keys) { - ass1 = m_scene.AssetService.Get(kvp.Key.ToString()); - PostAsset(userAssetURL, ass1); + asset = m_scene.AssetService.Get(uuid.ToString()); + if (asset != null) + m_log.DebugFormat("[HGScene]: Posting {0} {1}", asset.Type.ToString(), asset.Name); + else + m_log.DebugFormat("[HGScene]: Could not find asset {0}", uuid); + PostAsset(userAssetURL, asset); } - if (success) + if (ids.Count > 0) // maybe it succeeded... m_log.DebugFormat("[HGScene]: Successfully posted item {0} to remote asset server {1}", assetID, userAssetURL); else m_log.WarnFormat("[HGScene]: Could not post asset {0} to remote asset server {1}", assetID, userAssetURL); diff --git a/OpenSim/Region/Framework/Scenes/Hypergrid/HGScene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Hypergrid/HGScene.Inventory.cs index 4fde9bb..da9b5ec 100644 --- a/OpenSim/Region/Framework/Scenes/Hypergrid/HGScene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Hypergrid/HGScene.Inventory.cs @@ -113,24 +113,28 @@ namespace OpenSim.Region.Framework.Scenes.Hypergrid UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection, bool RezSelected, bool RemoveItem, UUID fromTaskID, bool attachment) { - CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId); - if (userInfo != null) + //m_log.DebugFormat("[HGScene] RezObject itemID={0} fromTaskID={1}", itemID, fromTaskID); + + if (fromTaskID.Equals(UUID.Zero)) { - if (userInfo.RootFolder != null) + CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId); + if (userInfo != null) { - InventoryItemBase item = userInfo.RootFolder.FindItem(itemID); - - if (item == null) - { // Fetch the item - item = new InventoryItemBase(); - item.Owner = remoteClient.AgentId; - item.ID = itemID; - item = m_assMapper.Get(item, userInfo.RootFolder.ID, userInfo); - } - if (item != null) + if (userInfo.RootFolder != null) { - m_assMapper.Get(item.AssetID, remoteClient.AgentId); - + InventoryItemBase item = userInfo.RootFolder.FindItem(itemID); + if (item == null) + { // Fetch the item + item = new InventoryItemBase(); + item.Owner = remoteClient.AgentId; + item.ID = itemID; + item = m_assMapper.Get(item, userInfo.RootFolder.ID, userInfo); + } + if (item != null) + { + m_assMapper.Get(item.AssetID, remoteClient.AgentId); + + } } } } diff --git a/OpenSim/Region/Framework/Scenes/Hypergrid/HGUuidGatherer.cs b/OpenSim/Region/Framework/Scenes/Hypergrid/HGUuidGatherer.cs new file mode 100644 index 0000000..e83478d --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Hypergrid/HGUuidGatherer.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; + +using OpenSim.Framework; +using OpenSim.Services.Interfaces; +using OpenMetaverse; + +namespace OpenSim.Region.Framework.Scenes.Hypergrid +{ + public class HGUuidGatherer : UuidGatherer + { + protected string m_assetServerURL; + protected HGAssetMapper m_assetMapper; + + public HGUuidGatherer(HGAssetMapper assMap, IAssetService assetCache, string assetServerURL) : base(assetCache) + { + m_assetMapper = assMap; + m_assetServerURL = assetServerURL; + } + + protected override AssetBase GetAsset(UUID uuid) + { + if (string.Empty == m_assetServerURL) + return m_assetCache.Get(uuid.ToString()); + else + return m_assetMapper.FetchAsset(m_assetServerURL, uuid); + } + } +} diff --git a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs index 5eb42f7..1324978 100644 --- a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs +++ b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs @@ -187,7 +187,7 @@ namespace OpenSim.Region.Framework.Scenes /// /// /// - protected AssetBase GetAsset(UUID uuid) + protected virtual AssetBase GetAsset(UUID uuid) { m_waitingForObjectAsset = true; m_assetCache.Get(uuid.ToString(), this, AssetReceived); -- cgit v1.1