diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs | 83 |
1 files changed, 77 insertions, 6 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 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.IO; | ||
30 | using System.Reflection; | 31 | using System.Reflection; |
31 | using System.Threading; | 32 | using System.Threading; |
33 | using System.Xml; | ||
34 | |||
32 | using log4net; | 35 | using log4net; |
33 | using OpenMetaverse; | 36 | using OpenMetaverse; |
34 | using OpenSim.Framework; | 37 | using OpenSim.Framework; |
@@ -52,14 +55,16 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
52 | // private Dictionary<string, InventoryClient> m_inventoryServers = new Dictionary<string, InventoryClient>(); | 55 | // private Dictionary<string, InventoryClient> m_inventoryServers = new Dictionary<string, InventoryClient>(); |
53 | 56 | ||
54 | private Scene m_scene; | 57 | private Scene m_scene; |
58 | private string m_ProfileServerURI; | ||
55 | 59 | ||
56 | #endregion | 60 | #endregion |
57 | 61 | ||
58 | #region Constructor | 62 | #region Constructor |
59 | 63 | ||
60 | public HGAssetMapper(Scene scene) | 64 | public HGAssetMapper(Scene scene, string profileURL) |
61 | { | 65 | { |
62 | m_scene = scene; | 66 | m_scene = scene; |
67 | m_ProfileServerURI = profileURL; | ||
63 | } | 68 | } |
64 | 69 | ||
65 | #endregion | 70 | #endregion |
@@ -95,16 +100,18 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
95 | try | 100 | try |
96 | { | 101 | { |
97 | asset1.ID = url + "/" + asset.ID; | 102 | asset1.ID = url + "/" + asset.ID; |
98 | // UUID temp = UUID.Zero; | ||
99 | // TODO: if the creator is local, stick this grid's URL in front | ||
100 | //if (UUID.TryParse(asset.Metadata.CreatorID, out temp)) | ||
101 | // asset1.Metadata.CreatorID = ??? + "/" + asset.Metadata.CreatorID; | ||
102 | } | 103 | } |
103 | catch | 104 | catch |
104 | { | 105 | { |
105 | m_log.Warn("[HG ASSET MAPPER]: Oops."); | 106 | m_log.Warn("[HG ASSET MAPPER]: Oops."); |
106 | } | 107 | } |
107 | 108 | ||
109 | AdjustIdentifiers(asset1.Metadata); | ||
110 | if (asset1.Metadata.Type == (sbyte)AssetType.Object) | ||
111 | asset1.Data = AdjustIdentifiers(asset.Data); | ||
112 | else | ||
113 | asset1.Data = asset.Data; | ||
114 | |||
108 | m_scene.AssetService.Store(asset1); | 115 | m_scene.AssetService.Store(asset1); |
109 | m_log.DebugFormat("[HG ASSET MAPPER]: Posted copy of asset {0} from local asset server to {1}", asset1.ID, url); | 116 | m_log.DebugFormat("[HG ASSET MAPPER]: Posted copy of asset {0} from local asset server to {1}", asset1.ID, url); |
110 | } | 117 | } |
@@ -118,7 +125,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
118 | 125 | ||
119 | private void Copy(AssetBase from, AssetBase to) | 126 | private void Copy(AssetBase from, AssetBase to) |
120 | { | 127 | { |
121 | to.Data = from.Data; | 128 | //to.Data = from.Data; // don't copy this, it's copied elsewhere |
122 | to.Description = from.Description; | 129 | to.Description = from.Description; |
123 | to.FullID = from.FullID; | 130 | to.FullID = from.FullID; |
124 | to.ID = from.ID; | 131 | to.ID = from.ID; |
@@ -129,6 +136,70 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
129 | 136 | ||
130 | } | 137 | } |
131 | 138 | ||
139 | private void AdjustIdentifiers(AssetMetadata meta) | ||
140 | { | ||
141 | if (meta.CreatorID != null && meta.CreatorID != string.Empty) | ||
142 | { | ||
143 | UUID uuid = UUID.Zero; | ||
144 | UUID.TryParse(meta.CreatorID, out uuid); | ||
145 | UserAccount creator = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, uuid); | ||
146 | if (creator != null) | ||
147 | meta.CreatorID = m_ProfileServerURI + "/" + meta.CreatorID + ";" + creator.FirstName + " " + creator.LastName; | ||
148 | } | ||
149 | } | ||
150 | |||
151 | protected byte[] AdjustIdentifiers(byte[] data) | ||
152 | { | ||
153 | string xml = Utils.BytesToString(data); | ||
154 | return Utils.StringToBytes(RewriteSOP(xml)); | ||
155 | } | ||
156 | |||
157 | protected string RewriteSOP(string xml) | ||
158 | { | ||
159 | XmlDocument doc = new XmlDocument(); | ||
160 | doc.LoadXml(xml); | ||
161 | XmlNodeList sops = doc.GetElementsByTagName("SceneObjectPart"); | ||
162 | |||
163 | foreach (XmlNode sop in sops) | ||
164 | { | ||
165 | UserAccount creator = null; | ||
166 | bool hasCreatorData = false; | ||
167 | XmlNodeList nodes = sop.ChildNodes; | ||
168 | foreach (XmlNode node in nodes) | ||
169 | { | ||
170 | if (node.Name == "CreatorID") | ||
171 | { | ||
172 | UUID uuid = UUID.Zero; | ||
173 | UUID.TryParse(node.InnerText, out uuid); | ||
174 | creator = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, uuid); | ||
175 | } | ||
176 | if (node.Name == "CreatorData" && node.InnerText != null && node.InnerText != string.Empty) | ||
177 | hasCreatorData = true; | ||
178 | |||
179 | //if (node.Name == "OwnerID") | ||
180 | //{ | ||
181 | // UserAccount owner = GetUser(node.InnerText); | ||
182 | // if (owner != null) | ||
183 | // node.InnerText = m_ProfileServiceURL + "/" + node.InnerText + "/" + owner.FirstName + " " + owner.LastName; | ||
184 | //} | ||
185 | } | ||
186 | |||
187 | if (!hasCreatorData && creator != null) | ||
188 | { | ||
189 | XmlElement creatorData = doc.CreateElement("CreatorData"); | ||
190 | creatorData.InnerText = m_ProfileServerURI + "/" + creator.PrincipalID + ";" + creator.FirstName + " " + creator.LastName; | ||
191 | sop.AppendChild(creatorData); | ||
192 | } | ||
193 | } | ||
194 | |||
195 | using (StringWriter wr = new StringWriter()) | ||
196 | { | ||
197 | doc.Save(wr); | ||
198 | return wr.ToString(); | ||
199 | } | ||
200 | |||
201 | } | ||
202 | |||
132 | // TODO: unused | 203 | // TODO: unused |
133 | // private void Dump(Dictionary<UUID, bool> lst) | 204 | // private void Dump(Dictionary<UUID, bool> lst) |
134 | // { | 205 | // { |