aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Agent
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Agent')
-rw-r--r--OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs28
-rw-r--r--OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetTransactionModule.cs4
-rw-r--r--OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs206
-rw-r--r--OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs11
4 files changed, 225 insertions, 24 deletions
diff --git a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs
index f56d17d..1a19585 100644
--- a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs
+++ b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs
@@ -152,7 +152,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
152 } 152 }
153 } 153 }
154 154
155 public void RequestCreateInventoryItem(IClientAPI remoteClient, 155 public bool RequestCreateInventoryItem(IClientAPI remoteClient,
156 UUID transactionID, UUID folderID, uint callbackID, 156 UUID transactionID, UUID folderID, uint callbackID,
157 string description, string name, sbyte invType, 157 string description, string name, sbyte invType,
158 sbyte type, byte wearableType, uint nextOwnerMask) 158 sbyte type, byte wearableType, uint nextOwnerMask)
@@ -162,6 +162,8 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
162 uploader.RequestCreateInventoryItem( 162 uploader.RequestCreateInventoryItem(
163 remoteClient, folderID, callbackID, 163 remoteClient, folderID, callbackID,
164 description, name, invType, type, wearableType, nextOwnerMask); 164 description, name, invType, type, wearableType, nextOwnerMask);
165
166 return true;
165 } 167 }
166 168
167 public void RequestUpdateTaskInventoryItem(IClientAPI remoteClient, 169 public void RequestUpdateTaskInventoryItem(IClientAPI remoteClient,
@@ -170,6 +172,17 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
170 { 172 {
171 AssetXferUploader uploader = RequestXferUploader(transactionID); 173 AssetXferUploader uploader = RequestXferUploader(transactionID);
172 174
175 // Here we need to get the old asset to extract the
176 // texture UUIDs if it's a wearable.
177 if (item.Type == (int)AssetType.Bodypart ||
178 item.Type == (int)AssetType.Clothing ||
179 item.Type == (int)CustomAssetType.AnimationSet)
180 {
181 AssetBase oldAsset = m_Scene.AssetService.Get(item.AssetID.ToString());
182 if (oldAsset != null)
183 uploader.SetOldData(oldAsset.Data);
184 }
185
173 uploader.RequestUpdateTaskInventoryItem(remoteClient, item); 186 uploader.RequestUpdateTaskInventoryItem(remoteClient, item);
174 } 187 }
175 188
@@ -178,7 +191,18 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
178 { 191 {
179 AssetXferUploader uploader = RequestXferUploader(transactionID); 192 AssetXferUploader uploader = RequestXferUploader(transactionID);
180 193
194 // Here we need to get the old asset to extract the
195 // texture UUIDs if it's a wearable.
196 if (item.AssetType == (int)AssetType.Bodypart ||
197 item.AssetType == (int)AssetType.Clothing ||
198 item.AssetType == (int)CustomAssetType.AnimationSet)
199 {
200 AssetBase oldAsset = m_Scene.AssetService.Get(item.AssetID.ToString());
201 if (oldAsset != null)
202 uploader.SetOldData(oldAsset.Data);
203 }
204
181 uploader.RequestUpdateInventoryItem(remoteClient, item); 205 uploader.RequestUpdateInventoryItem(remoteClient, item);
182 } 206 }
183 } 207 }
184} \ No newline at end of file 208}
diff --git a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetTransactionModule.cs b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetTransactionModule.cs
index b67c0df..f489262 100644
--- a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetTransactionModule.cs
+++ b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetTransactionModule.cs
@@ -158,7 +158,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
158 /// <param name="type"></param> 158 /// <param name="type"></param>
159 /// <param name="wearableType"></param> 159 /// <param name="wearableType"></param>
160 /// <param name="nextOwnerMask"></param> 160 /// <param name="nextOwnerMask"></param>
161 public void HandleItemCreationFromTransaction(IClientAPI remoteClient, 161 public bool HandleItemCreationFromTransaction(IClientAPI remoteClient,
162 UUID transactionID, UUID folderID, uint callbackID, 162 UUID transactionID, UUID folderID, uint callbackID,
163 string description, string name, sbyte invType, 163 string description, string name, sbyte invType,
164 sbyte type, byte wearableType, uint nextOwnerMask) 164 sbyte type, byte wearableType, uint nextOwnerMask)
@@ -169,7 +169,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
169 AgentAssetTransactions transactions = 169 AgentAssetTransactions transactions =
170 GetUserTransactions(remoteClient.AgentId); 170 GetUserTransactions(remoteClient.AgentId);
171 171
172 transactions.RequestCreateInventoryItem(remoteClient, transactionID, 172 return transactions.RequestCreateInventoryItem(remoteClient, transactionID,
173 folderID, callbackID, description, name, invType, type, 173 folderID, callbackID, description, name, invType, type,
174 wearableType, nextOwnerMask); 174 wearableType, nextOwnerMask);
175 } 175 }
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}
diff --git a/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs b/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs
index 4299726..7113f4f 100644
--- a/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs
+++ b/OpenSim/Region/CoreModules/Agent/Xfer/XferModule.cs
@@ -160,6 +160,8 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
160 { 160 {
161 byte[] fileData = NewFiles[fileName].Data; 161 byte[] fileData = NewFiles[fileName].Data;
162 XferDownLoad transaction = new XferDownLoad(fileName, fileData, xferID, remoteClient); 162 XferDownLoad transaction = new XferDownLoad(fileName, fileData, xferID, remoteClient);
163 if (fileName.StartsWith("inventory_"))
164 transaction.isTaskInventory = true;
163 165
164 Transfers.Add(xferID, transaction); 166 Transfers.Add(xferID, transaction);
165 167
@@ -243,6 +245,7 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
243 public uint Packet = 0; 245 public uint Packet = 0;
244 public uint Serial = 1; 246 public uint Serial = 1;
245 public ulong XferID = 0; 247 public ulong XferID = 0;
248 public bool isTaskInventory = false;
246 249
247 public XferDownLoad(string fileName, byte[] data, ulong xferID, IClientAPI client) 250 public XferDownLoad(string fileName, byte[] data, ulong xferID, IClientAPI client)
248 { 251 {
@@ -268,7 +271,7 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
268 byte[] transferData = new byte[Data.Length + 4]; 271 byte[] transferData = new byte[Data.Length + 4];
269 Array.Copy(Utils.IntToBytes(Data.Length), 0, transferData, 0, 4); 272 Array.Copy(Utils.IntToBytes(Data.Length), 0, transferData, 0, 4);
270 Array.Copy(Data, 0, transferData, 4, Data.Length); 273 Array.Copy(Data, 0, transferData, 4, Data.Length);
271 Client.SendXferPacket(XferID, 0 + 0x80000000, transferData); 274 Client.SendXferPacket(XferID, 0 + 0x80000000, transferData, isTaskInventory);
272 complete = true; 275 complete = true;
273 } 276 }
274 else 277 else
@@ -276,7 +279,7 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
276 byte[] transferData = new byte[1000 + 4]; 279 byte[] transferData = new byte[1000 + 4];
277 Array.Copy(Utils.IntToBytes(Data.Length), 0, transferData, 0, 4); 280 Array.Copy(Utils.IntToBytes(Data.Length), 0, transferData, 0, 4);
278 Array.Copy(Data, 0, transferData, 4, 1000); 281 Array.Copy(Data, 0, transferData, 4, 1000);
279 Client.SendXferPacket(XferID, 0, transferData); 282 Client.SendXferPacket(XferID, 0, transferData, isTaskInventory);
280 Packet++; 283 Packet++;
281 DataPointer = 1000; 284 DataPointer = 1000;
282 } 285 }
@@ -297,7 +300,7 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
297 { 300 {
298 byte[] transferData = new byte[1000]; 301 byte[] transferData = new byte[1000];
299 Array.Copy(Data, DataPointer, transferData, 0, 1000); 302 Array.Copy(Data, DataPointer, transferData, 0, 1000);
300 Client.SendXferPacket(XferID, Packet, transferData); 303 Client.SendXferPacket(XferID, Packet, transferData, isTaskInventory);
301 Packet++; 304 Packet++;
302 DataPointer += 1000; 305 DataPointer += 1000;
303 } 306 }
@@ -306,7 +309,7 @@ namespace OpenSim.Region.CoreModules.Agent.Xfer
306 byte[] transferData = new byte[Data.Length - DataPointer]; 309 byte[] transferData = new byte[Data.Length - DataPointer];
307 Array.Copy(Data, DataPointer, transferData, 0, Data.Length - DataPointer); 310 Array.Copy(Data, DataPointer, transferData, 0, Data.Length - DataPointer);
308 uint endPacket = Packet |= (uint) 0x80000000; 311 uint endPacket = Packet |= (uint) 0x80000000;
309 Client.SendXferPacket(XferID, endPacket, transferData); 312 Client.SendXferPacket(XferID, endPacket, transferData, isTaskInventory);
310 Packet++; 313 Packet++;
311 DataPointer += (Data.Length - DataPointer); 314 DataPointer += (Data.Length - DataPointer);
312 315