aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs
diff options
context:
space:
mode:
authorUbitUmarov2015-09-01 14:54:35 +0100
committerUbitUmarov2015-09-01 14:54:35 +0100
commit371c9dd2af01a2e7422ec901ee1f80757284a78c (patch)
tree058d2a513cacb12efcce0c0df0ae14ad135dbfe2 /OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs
parentremove lixo (diff)
parentdont change camera on crossings (diff)
downloadopensim-SC_OLD-371c9dd2af01a2e7422ec901ee1f80757284a78c.zip
opensim-SC_OLD-371c9dd2af01a2e7422ec901ee1f80757284a78c.tar.gz
opensim-SC_OLD-371c9dd2af01a2e7422ec901ee1f80757284a78c.tar.bz2
opensim-SC_OLD-371c9dd2af01a2e7422ec901ee1f80757284a78c.tar.xz
bad merge?
Diffstat (limited to 'OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs')
-rw-r--r--OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs206
1 files changed, 190 insertions, 16 deletions
diff --git a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs
index 49a96f4..345b53d 100644
--- a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs
+++ b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs
@@ -28,6 +28,7 @@
28using System; 28using System;
29using System.IO; 29using System.IO;
30using System.Reflection; 30using System.Reflection;
31using System.Collections.Generic;
31using log4net; 32using log4net;
32using OpenMetaverse; 33using OpenMetaverse;
33using OpenSim.Framework; 34using OpenSim.Framework;
@@ -40,6 +41,13 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
40{ 41{
41 public class AssetXferUploader 42 public class AssetXferUploader
42 { 43 {
44 // Viewer's notion of the default texture
45 private List<UUID> defaultIDs = new List<UUID> {
46 new UUID("5748decc-f629-461c-9a36-a35a221fe21f"),
47 new UUID("7ca39b4c-bd19-4699-aff7-f93fd03d3e7b"),
48 new UUID("6522e74d-1660-4e7f-b601-6f48c1659a77"),
49 new UUID("c228d1cf-4b5d-4ba8-84f4-899a0796aa97")
50 };
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 51 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44 52
45 /// <summary> 53 /// <summary>
@@ -87,6 +95,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
87 95
88 private sbyte type = 0; 96 private sbyte type = 0;
89 private byte wearableType = 0; 97 private byte wearableType = 0;
98 private byte[] m_oldData = null;
90 public ulong XferID; 99 public ulong XferID;
91 private Scene m_Scene; 100 private Scene m_Scene;
92 101
@@ -129,18 +138,27 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
129 138
130 if (XferID == xferID) 139 if (XferID == xferID)
131 { 140 {
132 if (m_asset.Data.Length > 1) 141 lock (this)
133 { 142 {
134 byte[] destinationArray = new byte[m_asset.Data.Length + data.Length]; 143 int assetLength = m_asset.Data.Length;
135 Array.Copy(m_asset.Data, 0, destinationArray, 0, m_asset.Data.Length); 144 int dataLength = data.Length;
136 Array.Copy(data, 0, destinationArray, m_asset.Data.Length, data.Length); 145
137 m_asset.Data = destinationArray; 146 if (m_asset.Data.Length > 1)
138 } 147 {
139 else 148 byte[] destinationArray = new byte[assetLength + dataLength];
140 { 149 Array.Copy(m_asset.Data, 0, destinationArray, 0, assetLength);
141 byte[] buffer2 = new byte[data.Length - 4]; 150 Array.Copy(data, 0, destinationArray, assetLength, dataLength);
142 Array.Copy(data, 4, buffer2, 0, data.Length - 4); 151 m_asset.Data = destinationArray;
143 m_asset.Data = buffer2; 152 }
153 else
154 {
155 if (dataLength > 4)
156 {
157 byte[] buffer2 = new byte[dataLength - 4];
158 Array.Copy(data, 4, buffer2, 0, dataLength - 4);
159 m_asset.Data = buffer2;
160 }
161 }
144 } 162 }
145 163
146 ourClient.SendConfirmXfer(xferID, packetID); 164 ourClient.SendConfirmXfer(xferID, packetID);
@@ -244,10 +262,10 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
244 { 262 {
245 CompleteTaskItemUpdate(m_updateTaskItemData); 263 CompleteTaskItemUpdate(m_updateTaskItemData);
246 } 264 }
247// else if (m_storeLocal) 265 else if (m_asset.Local)
248// { 266 {
249// m_Scene.AssetService.Store(m_asset); 267 m_Scene.AssetService.Store(m_asset);
250// } 268 }
251 } 269 }
252 270
253 m_log.DebugFormat( 271 m_log.DebugFormat(
@@ -374,7 +392,13 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
374// "[ASSET XFER UPLOADER]: Storing asset {0} for earlier item update for {1} for {2}", 392// "[ASSET XFER UPLOADER]: Storing asset {0} for earlier item update for {1} for {2}",
375// m_asset.FullID, item.Name, ourClient.Name); 393// m_asset.FullID, item.Name, ourClient.Name);
376 394
395 ValidateAssets();
377 m_Scene.AssetService.Store(m_asset); 396 m_Scene.AssetService.Store(m_asset);
397 if (m_asset.FullID != UUID.Zero)
398 {
399 item.AssetID = m_asset.FullID;
400 m_Scene.InventoryService.UpdateItem(item);
401 }
378 402
379 m_transactions.RemoveXferUploader(m_transactionID); 403 m_transactions.RemoveXferUploader(m_transactionID);
380 404
@@ -391,6 +415,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
391// "[ASSET XFER UPLOADER]: Storing asset {0} for earlier task item update for {1} for {2}", 415// "[ASSET XFER UPLOADER]: Storing asset {0} for earlier task item update for {1} for {2}",
392// m_asset.FullID, taskItem.Name, ourClient.Name); 416// m_asset.FullID, taskItem.Name, ourClient.Name);
393 417
418 ValidateAssets();
394 m_Scene.AssetService.Store(m_asset); 419 m_Scene.AssetService.Store(m_asset);
395 420
396 m_transactions.RemoveXferUploader(m_transactionID); 421 m_transactions.RemoveXferUploader(m_transactionID);
@@ -398,6 +423,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
398 423
399 private void CompleteCreateItem(uint callbackID) 424 private void CompleteCreateItem(uint callbackID)
400 { 425 {
426 ValidateAssets();
401 m_Scene.AssetService.Store(m_asset); 427 m_Scene.AssetService.Store(m_asset);
402 428
403 InventoryItemBase item = new InventoryItemBase(); 429 InventoryItemBase item = new InventoryItemBase();
@@ -418,6 +444,9 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
418 item.Flags = (uint) wearableType; 444 item.Flags = (uint) wearableType;
419 item.CreationDate = Util.UnixTimeSinceEpoch(); 445 item.CreationDate = Util.UnixTimeSinceEpoch();
420 446
447 m_log.DebugFormat("[XFER]: Created item {0} with asset {1}",
448 item.ID, item.AssetID);
449
421 if (m_Scene.AddInventoryItem(item)) 450 if (m_Scene.AddInventoryItem(item))
422 ourClient.SendInventoryItemCreateUpdate(item, callbackID); 451 ourClient.SendInventoryItemCreateUpdate(item, callbackID);
423 else 452 else
@@ -426,5 +455,150 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
426 m_transactions.RemoveXferUploader(m_transactionID); 455 m_transactions.RemoveXferUploader(m_transactionID);
427 } 456 }
428 457
458<<<<<<< HEAD
459=======
460 private void ValidateAssets()
461 {
462 if (m_asset.Type == (sbyte)CustomAssetType.AnimationSet)
463 {
464 AnimationSet animSet = new AnimationSet(m_asset.Data);
465
466 bool allOk = animSet.Validate(x => {
467 int perms = m_Scene.InventoryService.GetAssetPermissions(ourClient.AgentId, x);
468 int required = (int)(PermissionMask.Transfer | PermissionMask.Copy);
469 if ((perms & required) != required)
470 return false;
471 return true;
472 });
473
474 if (!allOk)
475 m_asset.Data = animSet.ToBytes();
476 }
477
478 if (m_asset.Type == (sbyte)AssetType.Clothing ||
479 m_asset.Type == (sbyte)AssetType.Bodypart)
480 {
481 string content = System.Text.Encoding.ASCII.GetString(m_asset.Data);
482 string[] lines = content.Split(new char[] {'\n'});
483
484 List<string> validated = new List<string>();
485
486 Dictionary<int, UUID> allowed = ExtractTexturesFromOldData();
487
488 int textures = 0;
489
490 foreach (string line in lines)
491 {
492 try
493 {
494 if (line.StartsWith("textures "))
495 {
496 textures = Convert.ToInt32(line.Substring(9));
497 validated.Add(line);
498 }
499 else if (textures > 0)
500 {
501 string[] parts = line.Split(new char[] {' '});
502
503 UUID tx = new UUID(parts[1]);
504 int id = Convert.ToInt32(parts[0]);
505
506 if (defaultIDs.Contains(tx) || tx == UUID.Zero ||
507 (allowed.ContainsKey(id) && allowed[id] == tx))
508 {
509 validated.Add(parts[0] + " " + tx.ToString());
510 }
511 else
512 {
513 int perms = m_Scene.InventoryService.GetAssetPermissions(ourClient.AgentId, tx);
514 int full = (int)(PermissionMask.Modify | PermissionMask.Transfer | PermissionMask.Copy);
515
516 if ((perms & full) != full)
517 {
518 m_log.ErrorFormat("[ASSET UPLOADER]: REJECTED update with texture {0} from {1} because they do not own the texture", tx, ourClient.AgentId);
519 validated.Add(parts[0] + " " + UUID.Zero.ToString());
520 }
521 else
522 {
523 validated.Add(line);
524 }
525 }
526 textures--;
527 }
528 else
529 {
530 validated.Add(line);
531 }
532 }
533 catch
534 {
535 // If it's malformed, skip it
536 }
537 }
538
539 string final = String.Join("\n", validated.ToArray());
540
541 m_asset.Data = System.Text.Encoding.ASCII.GetBytes(final);
542 }
543 }
544
545 /// <summary>
546 /// Get the asset data uploaded in this transfer.
547 /// </summary>
548 /// <returns>null if the asset has not finished uploading</returns>
549 public AssetBase GetAssetData()
550 {
551 if (m_uploadState == UploadState.Complete)
552 {
553 ValidateAssets();
554 return m_asset;
555 }
556
557 return null;
558 }
559
560 public void SetOldData(byte[] d)
561 {
562 m_oldData = d;
563 }
564
565 private Dictionary<int,UUID> ExtractTexturesFromOldData()
566 {
567 Dictionary<int,UUID> result = new Dictionary<int,UUID>();
568 if (m_oldData == null)
569 return result;
570
571 string content = System.Text.Encoding.ASCII.GetString(m_oldData);
572 string[] lines = content.Split(new char[] {'\n'});
573
574 int textures = 0;
575
576 foreach (string line in lines)
577 {
578 try
579 {
580 if (line.StartsWith("textures "))
581 {
582 textures = Convert.ToInt32(line.Substring(9));
583 }
584 else if (textures > 0)
585 {
586 string[] parts = line.Split(new char[] {' '});
587
588 UUID tx = new UUID(parts[1]);
589 int id = Convert.ToInt32(parts[0]);
590 result[id] = tx;
591 textures--;
592 }
593 }
594 catch
595 {
596 // If it's malformed, skip it
597 }
598 }
599
600 return result;
601 }
602>>>>>>> avn/ubitvar
429 } 603 }
430} \ No newline at end of file 604}