diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Agent')
-rw-r--r-- | OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs | 16 | ||||
-rw-r--r-- | OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs | 127 |
2 files changed, 143 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs index 9d8082b..ff4ec4c 100644 --- a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs +++ b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs | |||
@@ -168,6 +168,19 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction | |||
168 | { | 168 | { |
169 | if (XferUploaders.ContainsKey(transactionID)) | 169 | if (XferUploaders.ContainsKey(transactionID)) |
170 | { | 170 | { |
171 | // m_log.DebugFormat("[XFER]: Asked to update item {0} ({1})", | ||
172 | // item.Name, item.ID); | ||
173 | |||
174 | // Here we need to get the old asset to extract the | ||
175 | // texture UUIDs if it's a wearable. | ||
176 | if (item.AssetType == (int)AssetType.Bodypart || | ||
177 | item.AssetType == (int)AssetType.Clothing) | ||
178 | { | ||
179 | AssetBase oldAsset = m_Scene.AssetService.Get(item.AssetID.ToString()); | ||
180 | if (oldAsset != null) | ||
181 | XferUploaders[transactionID].SetOldData(oldAsset.Data); | ||
182 | } | ||
183 | |||
171 | AssetBase asset = GetTransactionAsset(transactionID); | 184 | AssetBase asset = GetTransactionAsset(transactionID); |
172 | 185 | ||
173 | if (asset != null) | 186 | if (asset != null) |
@@ -182,6 +195,9 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction | |||
182 | 195 | ||
183 | IInventoryService invService = m_Scene.InventoryService; | 196 | IInventoryService invService = m_Scene.InventoryService; |
184 | invService.UpdateItem(item); | 197 | invService.UpdateItem(item); |
198 | |||
199 | // m_log.DebugFormat("[XFER]: Updated item {0} ({1}) with asset {2}", | ||
200 | // item.Name, item.ID, asset.FullID); | ||
185 | } | 201 | } |
186 | } | 202 | } |
187 | } | 203 | } |
diff --git a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs index a7929ba..a5dcdcc 100644 --- a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs +++ b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs | |||
@@ -28,6 +28,7 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.IO; | 29 | using System.IO; |
30 | using System.Reflection; | 30 | using System.Reflection; |
31 | using System.Collections.Generic; | ||
31 | using log4net; | 32 | using log4net; |
32 | using OpenMetaverse; | 33 | using OpenMetaverse; |
33 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
@@ -38,6 +39,13 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction | |||
38 | { | 39 | { |
39 | public class AssetXferUploader | 40 | public class AssetXferUploader |
40 | { | 41 | { |
42 | // Viewer's notion of the default texture | ||
43 | private List<UUID> defaultIDs = new List<UUID> { | ||
44 | new UUID("5748decc-f629-461c-9a36-a35a221fe21f"), | ||
45 | new UUID("7ca39b4c-bd19-4699-aff7-f93fd03d3e7b"), | ||
46 | new UUID("6522e74d-1660-4e7f-b601-6f48c1659a77"), | ||
47 | new UUID("c228d1cf-4b5d-4ba8-84f4-899a0796aa97") | ||
48 | }; | ||
41 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 49 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
42 | 50 | ||
43 | private AssetBase m_asset; | 51 | private AssetBase m_asset; |
@@ -55,6 +63,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction | |||
55 | private UUID TransactionID = UUID.Zero; | 63 | private UUID TransactionID = UUID.Zero; |
56 | private sbyte type = 0; | 64 | private sbyte type = 0; |
57 | private byte wearableType = 0; | 65 | private byte wearableType = 0; |
66 | private byte[] m_oldData = null; | ||
58 | public ulong XferID; | 67 | public ulong XferID; |
59 | private Scene m_Scene; | 68 | private Scene m_Scene; |
60 | 69 | ||
@@ -219,6 +228,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction | |||
219 | 228 | ||
220 | private void DoCreateItem(uint callbackID) | 229 | private void DoCreateItem(uint callbackID) |
221 | { | 230 | { |
231 | ValidateAssets(); | ||
222 | m_Scene.AssetService.Store(m_asset); | 232 | m_Scene.AssetService.Store(m_asset); |
223 | 233 | ||
224 | InventoryItemBase item = new InventoryItemBase(); | 234 | InventoryItemBase item = new InventoryItemBase(); |
@@ -239,12 +249,84 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction | |||
239 | item.Flags = (uint) wearableType; | 249 | item.Flags = (uint) wearableType; |
240 | item.CreationDate = Util.UnixTimeSinceEpoch(); | 250 | item.CreationDate = Util.UnixTimeSinceEpoch(); |
241 | 251 | ||
252 | m_log.DebugFormat("[XFER]: Created item {0} with asset {1}", | ||
253 | item.ID, item.AssetID); | ||
254 | |||
242 | if (m_Scene.AddInventoryItem(item)) | 255 | if (m_Scene.AddInventoryItem(item)) |
243 | ourClient.SendInventoryItemCreateUpdate(item, callbackID); | 256 | ourClient.SendInventoryItemCreateUpdate(item, callbackID); |
244 | else | 257 | else |
245 | ourClient.SendAlertMessage("Unable to create inventory item"); | 258 | ourClient.SendAlertMessage("Unable to create inventory item"); |
246 | } | 259 | } |
247 | 260 | ||
261 | private void ValidateAssets() | ||
262 | { | ||
263 | if (m_asset.Type == (sbyte)AssetType.Clothing || | ||
264 | m_asset.Type == (sbyte)AssetType.Bodypart) | ||
265 | { | ||
266 | string content = System.Text.Encoding.ASCII.GetString(m_asset.Data); | ||
267 | string[] lines = content.Split(new char[] {'\n'}); | ||
268 | |||
269 | List<string> validated = new List<string>(); | ||
270 | |||
271 | Dictionary<int, UUID> allowed = ExtractTexturesFromOldData(); | ||
272 | |||
273 | int textures = 0; | ||
274 | |||
275 | foreach (string line in lines) | ||
276 | { | ||
277 | try | ||
278 | { | ||
279 | if (line.StartsWith("textures ")) | ||
280 | { | ||
281 | textures = Convert.ToInt32(line.Substring(9)); | ||
282 | validated.Add(line); | ||
283 | } | ||
284 | else if (textures > 0) | ||
285 | { | ||
286 | string[] parts = line.Split(new char[] {' '}); | ||
287 | |||
288 | UUID tx = new UUID(parts[1]); | ||
289 | int id = Convert.ToInt32(parts[0]); | ||
290 | |||
291 | if (defaultIDs.Contains(tx) || tx == UUID.Zero || | ||
292 | (allowed.ContainsKey(id) && allowed[id] == tx)) | ||
293 | { | ||
294 | validated.Add(parts[0] + " " + tx.ToString()); | ||
295 | } | ||
296 | else | ||
297 | { | ||
298 | int perms = m_Scene.InventoryService.GetAssetPermissions(ourClient.AgentId, tx); | ||
299 | int full = (int)(PermissionMask.Modify | PermissionMask.Transfer | PermissionMask.Copy); | ||
300 | |||
301 | if ((perms & full) != full) | ||
302 | { | ||
303 | m_log.ErrorFormat("[ASSET UPLOADER]: REJECTED update with texture {0} from {1} because they do not own the texture", tx, ourClient.AgentId); | ||
304 | validated.Add(parts[0] + " " + UUID.Zero.ToString()); | ||
305 | } | ||
306 | else | ||
307 | { | ||
308 | validated.Add(line); | ||
309 | } | ||
310 | } | ||
311 | textures--; | ||
312 | } | ||
313 | else | ||
314 | { | ||
315 | validated.Add(line); | ||
316 | } | ||
317 | } | ||
318 | catch | ||
319 | { | ||
320 | // If it's malformed, skip it | ||
321 | } | ||
322 | } | ||
323 | |||
324 | string final = String.Join("\n", validated.ToArray()); | ||
325 | |||
326 | m_asset.Data = System.Text.Encoding.ASCII.GetBytes(final); | ||
327 | } | ||
328 | } | ||
329 | |||
248 | /// <summary> | 330 | /// <summary> |
249 | /// Get the asset data uploaded in this transfer. | 331 | /// Get the asset data uploaded in this transfer. |
250 | /// </summary> | 332 | /// </summary> |
@@ -253,10 +335,55 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction | |||
253 | { | 335 | { |
254 | if (m_finished) | 336 | if (m_finished) |
255 | { | 337 | { |
338 | ValidateAssets(); | ||
256 | return m_asset; | 339 | return m_asset; |
257 | } | 340 | } |
258 | 341 | ||
259 | return null; | 342 | return null; |
260 | } | 343 | } |
344 | |||
345 | public void SetOldData(byte[] d) | ||
346 | { | ||
347 | m_oldData = d; | ||
348 | } | ||
349 | |||
350 | private Dictionary<int,UUID> ExtractTexturesFromOldData() | ||
351 | { | ||
352 | Dictionary<int,UUID> result = new Dictionary<int,UUID>(); | ||
353 | if (m_oldData == null) | ||
354 | return result; | ||
355 | |||
356 | string content = System.Text.Encoding.ASCII.GetString(m_oldData); | ||
357 | string[] lines = content.Split(new char[] {'\n'}); | ||
358 | |||
359 | int textures = 0; | ||
360 | |||
361 | foreach (string line in lines) | ||
362 | { | ||
363 | try | ||
364 | { | ||
365 | if (line.StartsWith("textures ")) | ||
366 | { | ||
367 | textures = Convert.ToInt32(line.Substring(9)); | ||
368 | } | ||
369 | else if (textures > 0) | ||
370 | { | ||
371 | string[] parts = line.Split(new char[] {' '}); | ||
372 | |||
373 | UUID tx = new UUID(parts[1]); | ||
374 | int id = Convert.ToInt32(parts[0]); | ||
375 | result[id] = tx; | ||
376 | textures--; | ||
377 | } | ||
378 | } | ||
379 | catch | ||
380 | { | ||
381 | // If it's malformed, skip it | ||
382 | } | ||
383 | } | ||
384 | |||
385 | return result; | ||
386 | } | ||
261 | } | 387 | } |
262 | } | 388 | } |
389 | |||