From 3292a2255882018b7fed3e80f430dc26892b92ea Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Fri, 26 Nov 2010 22:06:34 -0800 Subject: Creator information preserved upon HG transfers. --- .../Framework/InventoryAccess/HGAssetMapper.cs | 83 ++++++++++++++++++++-- .../InventoryAccess/HGInventoryAccessModule.cs | 12 +++- .../Services/HypergridService/HGAssetService.cs | 1 - bin/config-include/GridCommon.ini.example | 8 +++ bin/config-include/StandaloneCommon.ini.example | 2 + 5 files changed, 97 insertions(+), 9 deletions(-) diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs index ccb892e..81b65c5 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs @@ -27,8 +27,11 @@ using System; using System.Collections.Generic; +using System.IO; using System.Reflection; using System.Threading; +using System.Xml; + using log4net; using OpenMetaverse; using OpenSim.Framework; @@ -52,14 +55,16 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess // private Dictionary m_inventoryServers = new Dictionary(); private Scene m_scene; + private string m_ProfileServerURI; #endregion #region Constructor - public HGAssetMapper(Scene scene) + public HGAssetMapper(Scene scene, string profileURL) { m_scene = scene; + m_ProfileServerURI = profileURL; } #endregion @@ -95,16 +100,18 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess try { asset1.ID = url + "/" + asset.ID; -// UUID temp = UUID.Zero; - // TODO: if the creator is local, stick this grid's URL in front - //if (UUID.TryParse(asset.Metadata.CreatorID, out temp)) - // asset1.Metadata.CreatorID = ??? + "/" + asset.Metadata.CreatorID; } catch { m_log.Warn("[HG ASSET MAPPER]: Oops."); } + AdjustIdentifiers(asset1.Metadata); + if (asset1.Metadata.Type == (sbyte)AssetType.Object) + asset1.Data = AdjustIdentifiers(asset.Data); + else + asset1.Data = asset.Data; + m_scene.AssetService.Store(asset1); m_log.DebugFormat("[HG ASSET MAPPER]: Posted copy of asset {0} from local asset server to {1}", asset1.ID, url); } @@ -118,7 +125,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess private void Copy(AssetBase from, AssetBase to) { - to.Data = from.Data; + //to.Data = from.Data; // don't copy this, it's copied elsewhere to.Description = from.Description; to.FullID = from.FullID; to.ID = from.ID; @@ -129,6 +136,70 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess } + private void AdjustIdentifiers(AssetMetadata meta) + { + if (meta.CreatorID != null && meta.CreatorID != string.Empty) + { + UUID uuid = UUID.Zero; + UUID.TryParse(meta.CreatorID, out uuid); + UserAccount creator = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, uuid); + if (creator != null) + meta.CreatorID = m_ProfileServerURI + "/" + meta.CreatorID + ";" + creator.FirstName + " " + creator.LastName; + } + } + + protected byte[] AdjustIdentifiers(byte[] data) + { + string xml = Utils.BytesToString(data); + return Utils.StringToBytes(RewriteSOP(xml)); + } + + protected string RewriteSOP(string xml) + { + XmlDocument doc = new XmlDocument(); + doc.LoadXml(xml); + XmlNodeList sops = doc.GetElementsByTagName("SceneObjectPart"); + + foreach (XmlNode sop in sops) + { + UserAccount creator = null; + bool hasCreatorData = false; + XmlNodeList nodes = sop.ChildNodes; + foreach (XmlNode node in nodes) + { + if (node.Name == "CreatorID") + { + UUID uuid = UUID.Zero; + UUID.TryParse(node.InnerText, out uuid); + creator = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, uuid); + } + if (node.Name == "CreatorData" && node.InnerText != null && node.InnerText != string.Empty) + hasCreatorData = true; + + //if (node.Name == "OwnerID") + //{ + // UserAccount owner = GetUser(node.InnerText); + // if (owner != null) + // node.InnerText = m_ProfileServiceURL + "/" + node.InnerText + "/" + owner.FirstName + " " + owner.LastName; + //} + } + + if (!hasCreatorData && creator != null) + { + XmlElement creatorData = doc.CreateElement("CreatorData"); + creatorData.InnerText = m_ProfileServerURI + "/" + creator.PrincipalID + ";" + creator.FirstName + " " + creator.LastName; + sop.AppendChild(creatorData); + } + } + + using (StringWriter wr = new StringWriter()) + { + doc.Save(wr); + return wr.ToString(); + } + + } + // TODO: unused // private void Dump(Dictionary lst) // { diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs index 125a397..34b8114 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs @@ -54,6 +54,8 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess get { return m_assMapper; } } + private string m_ProfileServerURI; + // private bool m_Initialized = false; #region INonSharedRegionModule @@ -73,6 +75,12 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess { m_Enabled = true; m_log.InfoFormat("[HG INVENTORY ACCESS MODULE]: {0} enabled.", Name); + + IConfig thisModuleConfig = source.Configs["HGInventoryAccessModule"]; + if (thisModuleConfig != null) + m_ProfileServerURI = thisModuleConfig.GetString("ProfileServerURI", string.Empty); + else + m_log.Warn("[HG INVENTORY ACCESS MODULE]: HGInventoryAccessModule configs not found. ProfileServerURI not set!"); } } } @@ -83,7 +91,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess return; base.AddRegion(scene); - m_assMapper = new HGAssetMapper(scene); + m_assMapper = new HGAssetMapper(scene, m_ProfileServerURI); scene.EventManager.OnNewInventoryItemUploadComplete += UploadInventoryItem; } @@ -97,7 +105,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess string userAssetServer = string.Empty; if (IsForeignUser(avatarID, out userAssetServer)) { - m_assMapper.Post(assetID, avatarID, userAssetServer); + Util.FireAndForget(delegate { m_assMapper.Post(assetID, avatarID, userAssetServer); }); } } diff --git a/OpenSim/Services/HypergridService/HGAssetService.cs b/OpenSim/Services/HypergridService/HGAssetService.cs index 6e0d4cd..9b098a0 100644 --- a/OpenSim/Services/HypergridService/HGAssetService.cs +++ b/OpenSim/Services/HypergridService/HGAssetService.cs @@ -126,7 +126,6 @@ namespace OpenSim.Services.HypergridService UserAccount creator = m_Cache.GetUser(meta.CreatorID); if (creator != null) meta.CreatorID = m_ProfileServiceURL + "/" + meta.CreatorID + ";" + creator.FirstName + " " + creator.LastName; - } protected byte[] AdjustIdentifiers(byte[] data) diff --git a/bin/config-include/GridCommon.ini.example b/bin/config-include/GridCommon.ini.example index cb771b8..762b09a 100644 --- a/bin/config-include/GridCommon.ini.example +++ b/bin/config-include/GridCommon.ini.example @@ -78,6 +78,14 @@ ; FriendsServerURI = "http://mygridserver.com:8003" +[HGInventoryAccessModule] + ; + ; === HG ONLY === + ; Change this to your profile server + ; accessible from other grids + ; + ProfileServerURI = "http://mygridserver.com:8002/profiles" + [Modules] ;; Choose 0 or 1 cache modules, and the corresponding config file, if it exists. ;; Copy the config .example file into your own .ini file and change configs there diff --git a/bin/config-include/StandaloneCommon.ini.example b/bin/config-include/StandaloneCommon.ini.example index d002d49..58059f5 100644 --- a/bin/config-include/StandaloneCommon.ini.example +++ b/bin/config-include/StandaloneCommon.ini.example @@ -31,6 +31,8 @@ [HGAssetService] ProfileServerURI = "http://127.0.0.1:9000/profiles" +[HGInventoryAccessModule] + ProfileServerURI = "http://127.0.0.1:9000/profiles" [Modules] ;; Choose 0 or 1 cache modules, and the corresponding config file, if it exists. -- cgit v1.1