aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Framework/InventoryItemBase.cs11
-rw-r--r--OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs47
-rw-r--r--OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs51
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs7
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Gestures/GesturesModule.cs39
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs141
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs1
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.Inventory.cs1015
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs27
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs96
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneGraph.cs4
11 files changed, 580 insertions, 859 deletions
diff --git a/OpenSim/Framework/InventoryItemBase.cs b/OpenSim/Framework/InventoryItemBase.cs
index 4307fe2..b5bf92f 100644
--- a/OpenSim/Framework/InventoryItemBase.cs
+++ b/OpenSim/Framework/InventoryItemBase.cs
@@ -354,7 +354,16 @@ namespace OpenSim.Framework
354 } 354 }
355 } 355 }
356 protected int m_creationDate = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; 356 protected int m_creationDate = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
357 357
358 public InventoryItemBase()
359 {
360 }
361
362 public InventoryItemBase(UUID id)
363 {
364 ID = id;
365 }
366
358 public object Clone() 367 public object Clone()
359 { 368 {
360 return MemberwiseClone(); 369 return MemberwiseClone();
diff --git a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs
index 8d586c4..c9ee54f 100644
--- a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs
+++ b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AgentAssetsTransactions.cs
@@ -192,40 +192,29 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
192 { 192 {
193 if (XferUploaders.ContainsKey(transactionID)) 193 if (XferUploaders.ContainsKey(transactionID))
194 { 194 {
195 CachedUserInfo userInfo = Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails( 195 UUID assetID = UUID.Combine(transactionID, remoteClient.SecureSessionId);
196 remoteClient.AgentId);
197 196
198 if (userInfo != null) 197 AssetBase asset = Manager.MyScene.AssetService.Get(assetID.ToString());
199 {
200 UUID assetID = UUID.Combine(transactionID, remoteClient.SecureSessionId);
201
202 AssetBase asset = Manager.MyScene.AssetService.Get(assetID.ToString());
203
204 if (asset == null)
205 {
206 asset = GetTransactionAsset(transactionID);
207 }
208
209 if (asset != null && asset.FullID == assetID)
210 {
211 // Assets never get updated, new ones get created
212 asset.FullID = UUID.Random();
213 asset.Name = item.Name;
214 asset.Description = item.Description;
215 asset.Type = (sbyte)item.AssetType;
216 item.AssetID = asset.FullID;
217
218 Manager.MyScene.AssetService.Store(asset);
219 }
220 198
221 userInfo.UpdateItem(item); 199 if (asset == null)
200 {
201 asset = GetTransactionAsset(transactionID);
222 } 202 }
223 else 203
204 if (asset != null && asset.FullID == assetID)
224 { 205 {
225 m_log.ErrorFormat( 206 // Assets never get updated, new ones get created
226 "[ASSET TRANSACTIONS]: Could not find user {0} for inventory item update", 207 asset.FullID = UUID.Random();
227 remoteClient.AgentId); 208 asset.Name = item.Name;
209 asset.Description = item.Description;
210 asset.Type = (sbyte)item.AssetType;
211 item.AssetID = asset.FullID;
212
213 Manager.MyScene.AssetService.Store(asset);
228 } 214 }
215
216 IInventoryService invService = Manager.MyScene.InventoryService;
217 invService.UpdateItem(item);
229 } 218 }
230 } 219 }
231 } 220 }
diff --git a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs
index afd9f5a..e192b81 100644
--- a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs
+++ b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetXferUploader.cs
@@ -32,6 +32,7 @@ using log4net;
32using OpenMetaverse; 32using OpenMetaverse;
33using OpenSim.Framework; 33using OpenSim.Framework;
34using OpenSim.Framework.Communications.Cache; 34using OpenSim.Framework.Communications.Cache;
35using OpenSim.Services.Interfaces;
35 36
36namespace OpenSim.Region.CoreModules.Agent.AssetTransaction 37namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
37{ 38{
@@ -214,39 +215,31 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
214 private void DoCreateItem(uint callbackID) 215 private void DoCreateItem(uint callbackID)
215 { 216 {
216 m_userTransactions.Manager.MyScene.AssetService.Store(m_asset); 217 m_userTransactions.Manager.MyScene.AssetService.Store(m_asset);
217 CachedUserInfo userInfo =
218 m_userTransactions.Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails(
219 ourClient.AgentId);
220 218
221 if (userInfo != null) 219 IInventoryService invService = m_userTransactions.Manager.MyScene.InventoryService;
222 { 220
223 InventoryItemBase item = new InventoryItemBase(); 221 InventoryItemBase item = new InventoryItemBase();
224 item.Owner = ourClient.AgentId; 222 item.Owner = ourClient.AgentId;
225 item.CreatorId = ourClient.AgentId.ToString(); 223 item.CreatorId = ourClient.AgentId.ToString();
226 item.ID = UUID.Random(); 224 item.ID = UUID.Random();
227 item.AssetID = m_asset.FullID; 225 item.AssetID = m_asset.FullID;
228 item.Description = m_description; 226 item.Description = m_description;
229 item.Name = m_name; 227 item.Name = m_name;
230 item.AssetType = type; 228 item.AssetType = type;
231 item.InvType = invType; 229 item.InvType = invType;
232 item.Folder = InventFolder; 230 item.Folder = InventFolder;
233 item.BasePermissions = 0x7fffffff; 231 item.BasePermissions = 0x7fffffff;
234 item.CurrentPermissions = 0x7fffffff; 232 item.CurrentPermissions = 0x7fffffff;
235 item.GroupPermissions=0; 233 item.GroupPermissions=0;
236 item.EveryOnePermissions=0; 234 item.EveryOnePermissions=0;
237 item.NextPermissions = nextPerm; 235 item.NextPermissions = nextPerm;
238 item.Flags = (uint) wearableType; 236 item.Flags = (uint) wearableType;
239 item.CreationDate = Util.UnixTimeSinceEpoch(); 237 item.CreationDate = Util.UnixTimeSinceEpoch();
240 238
241 userInfo.AddItem(item); 239 if (invService.AddItem(item))
242 ourClient.SendInventoryItemCreateUpdate(item, callbackID); 240 ourClient.SendInventoryItemCreateUpdate(item, callbackID);
243 }
244 else 241 else
245 { 242 ourClient.SendAlertMessage("Unable to create inventory item");
246 m_log.ErrorFormat(
247 "[ASSET TRANSACTIONS]: Could not find user {0} for inventory item creation",
248 ourClient.AgentId);
249 }
250 } 243 }
251 244
252 /// <summary> 245 /// <summary>
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
index b6250a2..49b2b5c 100644
--- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
@@ -39,6 +39,7 @@ using OpenSim.Framework.Communications;
39using OpenSim.Framework.Communications.Cache; 39using OpenSim.Framework.Communications.Cache;
40using OpenSim.Region.Framework.Interfaces; 40using OpenSim.Region.Framework.Interfaces;
41using OpenSim.Region.Framework.Scenes; 41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Services.Interfaces;
42 43
43namespace OpenSim.Region.CoreModules.Avatar.Friends 44namespace OpenSim.Region.CoreModules.Avatar.Friends
44{ 45{
@@ -654,8 +655,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
654 initiator.ControllingClient.SendAgentOnline(new UUID[] { fromAgentID }); 655 initiator.ControllingClient.SendAgentOnline(new UUID[] { fromAgentID });
655 656
656 // find the folder for the friend... 657 // find the folder for the friend...
657 InventoryFolderImpl folder = 658 //InventoryFolderImpl folder =
658 initiator.Scene.CommsManager.UserProfileCacheService.GetUserDetails(toAgentID).FindFolderForType((int)InventoryType.CallingCard); 659 // initiator.Scene.CommsManager.UserProfileCacheService.GetUserDetails(toAgentID).FindFolderForType((int)InventoryType.CallingCard);
660 IInventoryService invService = initiator.Scene.InventoryService;
661 InventoryFolderBase folder = invService.GetFolderForType(toAgentID, AssetType.CallingCard);
659 if (folder != null) 662 if (folder != null)
660 { 663 {
661 // ... and add the calling card 664 // ... and add the calling card
diff --git a/OpenSim/Region/CoreModules/Avatar/Gestures/GesturesModule.cs b/OpenSim/Region/CoreModules/Avatar/Gestures/GesturesModule.cs
index 102feaf..e61648c 100644
--- a/OpenSim/Region/CoreModules/Avatar/Gestures/GesturesModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Gestures/GesturesModule.cs
@@ -33,6 +33,7 @@ using OpenSim.Framework;
33using OpenSim.Framework.Communications.Cache; 33using OpenSim.Framework.Communications.Cache;
34using OpenSim.Region.Framework.Interfaces; 34using OpenSim.Region.Framework.Interfaces;
35using OpenSim.Region.Framework.Scenes; 35using OpenSim.Region.Framework.Scenes;
36using OpenSim.Services.Interfaces;
36 37
37namespace OpenSim.Region.CoreModules.Avatar.Gestures 38namespace OpenSim.Region.CoreModules.Avatar.Gestures
38{ 39{
@@ -62,42 +63,32 @@ namespace OpenSim.Region.CoreModules.Avatar.Gestures
62 63
63 public virtual void ActivateGesture(IClientAPI client, UUID assetId, UUID gestureId) 64 public virtual void ActivateGesture(IClientAPI client, UUID assetId, UUID gestureId)
64 { 65 {
65 CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(client.AgentId); 66 IInventoryService invService = m_scene.InventoryService;
66 67
67 if (userInfo != null) 68 InventoryItemBase item = invService.QueryItem(new InventoryItemBase(gestureId));
69 if (item != null)
68 { 70 {
69 InventoryItemBase item = userInfo.RootFolder.FindItem(gestureId); 71 item.Flags = 1;
70 if (item != null) 72 invService.UpdateItem(item);
71 {
72 item.Flags = 1;
73 userInfo.UpdateItem(item);
74 }
75 else
76 m_log.ErrorFormat(
77 "[GESTURES]: Unable to find gesture to activate {0} for {1}", gestureId, client.Name);
78 } 73 }
79 else 74 else
80 m_log.ErrorFormat("[GESTURES]: Unable to find user {0}", client.Name); 75 m_log.WarnFormat(
76 "[GESTURES]: Unable to find gesture {0} to activate for {1}", gestureId, client.Name);
81 } 77 }
82 78
83 public virtual void DeactivateGesture(IClientAPI client, UUID gestureId) 79 public virtual void DeactivateGesture(IClientAPI client, UUID gestureId)
84 { 80 {
85 CachedUserInfo userInfo = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(client.AgentId); 81 IInventoryService invService = m_scene.InventoryService;
86 82
87 if (userInfo != null) 83 InventoryItemBase item = invService.QueryItem(new InventoryItemBase(gestureId));
84 if (item != null)
88 { 85 {
89 InventoryItemBase item = userInfo.RootFolder.FindItem(gestureId); 86 item.Flags = 0;
90 if (item != null) 87 invService.UpdateItem(item);
91 {
92 item.Flags = 0;
93 userInfo.UpdateItem(item);
94 }
95 else
96 m_log.ErrorFormat(
97 "[GESTURES]: Unable to find gesture to deactivate {0} for {1}", gestureId, client.Name);
98 } 88 }
99 else 89 else
100 m_log.ErrorFormat("[GESTURES]: Unable to find user {0}", client.Name); 90 m_log.ErrorFormat(
91 "[GESTURES]: Unable to find gesture to deactivate {0} for {1}", gestureId, client.Name);
101 } 92 }
102 } 93 }
103} \ No newline at end of file 94} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs
index 811d4cc..b5650fd 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs
@@ -35,6 +35,7 @@ using OpenSim.Framework;
35using OpenSim.Framework.Communications.Cache; 35using OpenSim.Framework.Communications.Cache;
36using OpenSim.Region.Framework.Interfaces; 36using OpenSim.Region.Framework.Interfaces;
37using OpenSim.Region.Framework.Scenes; 37using OpenSim.Region.Framework.Scenes;
38using OpenSim.Services.Interfaces;
38 39
39namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer 40namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
40{ 41{
@@ -154,7 +155,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
154 "into agent {1}'s inventory", 155 "into agent {1}'s inventory",
155 folderID, new UUID(im.toAgentID)); 156 folderID, new UUID(im.toAgentID));
156 157
157 InventoryFolderImpl folderCopy 158 InventoryFolderBase folderCopy
158 = scene.GiveInventoryFolder(new UUID(im.toAgentID), client.AgentId, folderID, UUID.Zero); 159 = scene.GiveInventoryFolder(new UUID(im.toAgentID), client.AgentId, folderID, UUID.Zero);
159 160
160 if (folderCopy == null) 161 if (folderCopy == null)
@@ -247,52 +248,51 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
247 // It will have been pushed to the client, too 248 // It will have been pushed to the client, too
248 // 249 //
249 250
250 CachedUserInfo userInfo = 251 //CachedUserInfo userInfo =
251 scene.CommsManager.UserProfileCacheService. 252 // scene.CommsManager.UserProfileCacheService.
252 GetUserDetails(client.AgentId); 253 // GetUserDetails(client.AgentId);
254 IInventoryService invService = scene.InventoryService;
253 255
254 if (userInfo != null) 256 InventoryFolderBase trashFolder =
255 { 257 invService.GetFolderForType(client.AgentId, AssetType.TrashFolder);
256 InventoryFolderImpl trashFolder = 258
257 userInfo.FindFolderForType((int)AssetType.TrashFolder); 259 UUID inventoryEntityID = new UUID(im.imSessionID); // The inventory item/folder, back from it's trip
258
259 UUID inventoryEntityID = new UUID(im.imSessionID); // The inventory item/folder, back from it's trip
260
261 InventoryItemBase item = userInfo.RootFolder.FindItem(inventoryEntityID);
262 InventoryFolderBase folder = null;
263 260
264 if (item != null && trashFolder != null) 261 InventoryItemBase item = invService.QueryItem(new InventoryItemBase(inventoryEntityID));
265 { 262 InventoryFolderBase folder = null;
266 item.Folder = trashFolder.ID; 263
267 264 if (item != null && trashFolder != null)
268 userInfo.DeleteItem(inventoryEntityID); 265 {
266 item.Folder = trashFolder.ID;
269 267
270 scene.AddInventoryItem(client, item); 268 // Diva comment: can't we just update this item???
271 } 269 invService.DeleteItem(item);
272 else 270 scene.AddInventoryItem(client, item);
271 }
272 else
273 {
274 folder = invService.QueryFolder(new InventoryFolderBase(inventoryEntityID));
275
276 if (folder != null & trashFolder != null)
273 { 277 {
274 folder = userInfo.RootFolder.FindFolder(inventoryEntityID); 278 folder.ParentID = trashFolder.ID;
275 279 invService.MoveFolder(folder);
276 if (folder != null & trashFolder != null)
277 {
278 userInfo.MoveFolder(inventoryEntityID, trashFolder.ID);
279 }
280 } 280 }
281 }
282
283 if ((null == item && null == folder) | null == trashFolder)
284 {
285 string reason = String.Empty;
281 286
282 if ((null == item && null == folder) | null == trashFolder) 287 if (trashFolder == null)
283 { 288 reason += " Trash folder not found.";
284 string reason = String.Empty; 289 if (item == null)
285 290 reason += " Item not found.";
286 if (trashFolder == null) 291 if (folder == null)
287 reason += " Trash folder not found."; 292 reason += " Folder not found.";
288 if (item == null) 293
289 reason += " Item not found."; 294 client.SendAgentAlertMessage("Unable to delete "+
290 if (folder == null) 295 "received inventory" + reason, false);
291 reason += " Folder not found.";
292
293 client.SendAgentAlertMessage("Unable to delete "+
294 "received inventory" + reason, false);
295 }
296 } 296 }
297 297
298 ScenePresence user = scene.GetScenePresence(new UUID(im.toAgentID)); 298 ScenePresence user = scene.GetScenePresence(new UUID(im.toAgentID));
@@ -405,17 +405,18 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
405 return; 405 return;
406 } 406 }
407 407
408 CachedUserInfo userInfo = 408 //CachedUserInfo userInfo =
409 scene.CommsManager.UserProfileCacheService. 409 // scene.CommsManager.UserProfileCacheService.
410 GetUserDetails(user.ControllingClient.AgentId); 410 // GetUserDetails(user.ControllingClient.AgentId);
411 411
412 if (userInfo == null) 412 //if (userInfo == null)
413 { 413 //{
414 m_log.Debug("[INVENTORY TRANSFER] Can't find user info of recipient"); 414 // m_log.Debug("[INVENTORY TRANSFER] Can't find user info of recipient");
415 return; 415 // return;
416 } 416 //}
417 417
418 AssetType assetType = (AssetType)msg.binaryBucket[0]; 418 AssetType assetType = (AssetType)msg.binaryBucket[0];
419 IInventoryService invService = scene.InventoryService;
419 420
420 if (AssetType.Folder == assetType) 421 if (AssetType.Folder == assetType)
421 { 422 {
@@ -425,31 +426,23 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
425 folder.ID = folderID; 426 folder.ID = folderID;
426 folder.Owner = user.ControllingClient.AgentId; 427 folder.Owner = user.ControllingClient.AgentId;
427 428
428 // Fetch from database 429 // Fetch from service
429 // 430 //
430 if (!userInfo.QueryFolder(folder)) 431 folder = invService.QueryFolder(folder);
432 if (folder == null)
431 { 433 {
432 m_log.Debug("[INVENTORY TRANSFER] Can't find folder to give"); 434 m_log.Debug("[INVENTORY TRANSFER] Can't find folder to give");
433 return; 435 return;
434 } 436 }
435 437
436 // Get folder info 438 user.ControllingClient.SendBulkUpdateInventory(folder);
437 //
438 InventoryFolderImpl folderInfo = userInfo.RootFolder.FindFolder(folder.ID);
439 if (folderInfo == null)
440 {
441 m_log.Debug("[INVENTORY TRANSFER] Can't retrieve folder to give");
442 return;
443 }
444
445 user.ControllingClient.SendBulkUpdateInventory(folderInfo);
446 439
447 // This unelegant, slow kludge is to reload the folders and 440 //// This unelegant, slow kludge is to reload the folders and
448 // items. Since a folder give can transfer subfolders and 441 //// items. Since a folder give can transfer subfolders and
449 // items, this is the easiest way to pull that stuff in 442 //// items, this is the easiest way to pull that stuff in
450 // 443 ////
451 userInfo.DropInventory(); 444 //userInfo.DropInventory();
452 userInfo.FetchInventory(); 445 //userInfo.FetchInventory();
453 446
454 // Deliver message 447 // Deliver message
455 // 448 //
@@ -463,20 +456,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer
463 item.ID = itemID; 456 item.ID = itemID;
464 item.Owner = user.ControllingClient.AgentId; 457 item.Owner = user.ControllingClient.AgentId;
465 458
466 // Fetch from database 459 // Fetch from service
467 //
468 if (!userInfo.QueryItem(item))
469 {
470 m_log.Debug("[INVENTORY TRANSFER] Can't find item to give");
471 return;
472 }
473
474 // Get item info
475 // 460 //
476 item = userInfo.RootFolder.FindItem(item.ID); 461 item = invService.QueryItem(item);
477 if (item == null) 462 if (item == null)
478 { 463 {
479 m_log.Debug("[INVENTORY TRANSFER] Can't retrieve item to give"); 464 m_log.Debug("[INVENTORY TRANSFER] Can't find item to give");
480 return; 465 return;
481 } 466 }
482 467
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs
index c16e92e..c8f04a5 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs
@@ -91,6 +91,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
91 Dictionary<AssetType, InventoryFolderBase> folders = m_Connector.GetSystemFolders(presence.UUID); 91 Dictionary<AssetType, InventoryFolderBase> folders = m_Connector.GetSystemFolders(presence.UUID);
92 m_log.DebugFormat("[INVENTORY CACHE]: OnMakeRootAgent in {0}, fetched system folders for {1} {2}: count {3}", 92 m_log.DebugFormat("[INVENTORY CACHE]: OnMakeRootAgent in {0}, fetched system folders for {1} {2}: count {3}",
93 presence.Scene.RegionInfo.RegionName, presence.Firstname, presence.Lastname, folders.Count); 93 presence.Scene.RegionInfo.RegionName, presence.Firstname, presence.Lastname, folders.Count);
94
94 if (folders.Count > 0) 95 if (folders.Count > 0)
95 lock (m_InventoryCache) 96 lock (m_InventoryCache)
96 m_InventoryCache.Add(presence.UUID, folders); 97 m_InventoryCache.Add(presence.UUID, folders);
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
index facd301..80f71b3 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
@@ -80,17 +80,12 @@ namespace OpenSim.Region.Framework.Scenes
80 80
81 public bool AddInventoryItemReturned(UUID AgentId, InventoryItemBase item) 81 public bool AddInventoryItemReturned(UUID AgentId, InventoryItemBase item)
82 { 82 {
83 CachedUserInfo userInfo 83 if (InventoryService.AddItem(item))
84 = CommsManager.UserProfileCacheService.GetUserDetails(AgentId);
85 if (userInfo != null)
86 {
87 userInfo.AddItem(item);
88 return true; 84 return true;
89 }
90 else 85 else
91 { 86 {
92 m_log.ErrorFormat( 87 m_log.WarnFormat(
93 "[AGENT INVENTORY]: Agent was not found for add of item {1} {2}", item.Name, item.ID); 88 "[AGENT INVENTORY]: Unable to add item {1} to agent {2} inventory", item.Name, AgentId);
94 89
95 return false; 90 return false;
96 } 91 }
@@ -98,13 +93,9 @@ namespace OpenSim.Region.Framework.Scenes
98 93
99 public void AddInventoryItem(UUID AgentID, InventoryItemBase item) 94 public void AddInventoryItem(UUID AgentID, InventoryItemBase item)
100 { 95 {
101 CachedUserInfo userInfo
102 = CommsManager.UserProfileCacheService.GetUserDetails(AgentID);
103 96
104 if (userInfo != null) 97 if (InventoryService.AddItem(item))
105 { 98 {
106 userInfo.AddItem(item);
107
108 int userlevel = 0; 99 int userlevel = 0;
109 if (Permissions.IsGod(AgentID)) 100 if (Permissions.IsGod(AgentID))
110 { 101 {
@@ -120,8 +111,8 @@ namespace OpenSim.Region.Framework.Scenes
120 } 111 }
121 else 112 else
122 { 113 {
123 m_log.ErrorFormat( 114 m_log.WarnFormat(
124 "[AGENT INVENTORY]: Agent {1} was not found for add of item {2} {3}", 115 "[AGENT INVENTORY]: Agent {1} could not add item {2} {3}",
125 AgentID, item.Name, item.ID); 116 AgentID, item.Name, item.ID);
126 117
127 return; 118 return;
@@ -136,20 +127,8 @@ namespace OpenSim.Region.Framework.Scenes
136 /// in which the item is to be placed.</param> 127 /// in which the item is to be placed.</param>
137 public void AddInventoryItem(IClientAPI remoteClient, InventoryItemBase item) 128 public void AddInventoryItem(IClientAPI remoteClient, InventoryItemBase item)
138 { 129 {
139 CachedUserInfo userInfo 130 AddInventoryItem(remoteClient.AgentId, item);
140 = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId); 131 remoteClient.SendInventoryItemCreateUpdate(item, 0);
141
142 if (userInfo != null)
143 {
144 AddInventoryItem(remoteClient.AgentId, item);
145 remoteClient.SendInventoryItemCreateUpdate(item, 0);
146 }
147 else
148 {
149 m_log.ErrorFormat(
150 "[AGENT INVENTORY]: Could not resolve user {0} for adding an inventory item",
151 remoteClient.AgentId);
152 }
153 } 132 }
154 133
155 /// <summary> 134 /// <summary>
@@ -161,47 +140,40 @@ namespace OpenSim.Region.Framework.Scenes
161 /// <returns></returns> 140 /// <returns></returns>
162 public virtual UUID CapsUpdateInventoryItemAsset(IClientAPI remoteClient, UUID itemID, byte[] data) 141 public virtual UUID CapsUpdateInventoryItemAsset(IClientAPI remoteClient, UUID itemID, byte[] data)
163 { 142 {
164 CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId); 143 InventoryItemBase item = InventoryService.QueryItem(new InventoryItemBase(itemID));
165 if (userInfo != null) 144
145 if (item != null)
166 { 146 {
167 if (userInfo.RootFolder != null) 147 if ((InventoryType)item.InvType == InventoryType.Notecard)
168 { 148 {
169 InventoryItemBase item = userInfo.RootFolder.FindItem(itemID); 149 if (!Permissions.CanEditNotecard(itemID, UUID.Zero, remoteClient.AgentId))
170
171 if (item != null)
172 { 150 {
173 if ((InventoryType)item.InvType == InventoryType.Notecard) 151 remoteClient.SendAgentAlertMessage("Insufficient permissions to edit notecard", false);
174 { 152 return UUID.Zero;
175 if (!Permissions.CanEditNotecard(itemID, UUID.Zero, remoteClient.AgentId)) 153 }
176 {
177 remoteClient.SendAgentAlertMessage("Insufficient permissions to edit notecard", false);
178 return UUID.Zero;
179 }
180 154
181 remoteClient.SendAgentAlertMessage("Notecard saved", false); 155 remoteClient.SendAgentAlertMessage("Notecard saved", false);
182 } 156 }
183 else if ((InventoryType)item.InvType == InventoryType.LSL) 157 else if ((InventoryType)item.InvType == InventoryType.LSL)
184 { 158 {
185 if (!Permissions.CanEditScript(itemID, UUID.Zero, remoteClient.AgentId)) 159 if (!Permissions.CanEditScript(itemID, UUID.Zero, remoteClient.AgentId))
186 { 160 {
187 remoteClient.SendAgentAlertMessage("Insufficient permissions to edit script", false); 161 remoteClient.SendAgentAlertMessage("Insufficient permissions to edit script", false);
188 return UUID.Zero; 162 return UUID.Zero;
189 } 163 }
190 164
191 remoteClient.SendAgentAlertMessage("Script saved", false); 165 remoteClient.SendAgentAlertMessage("Script saved", false);
192 } 166 }
193 167
194 AssetBase asset = 168 AssetBase asset =
195 CreateAsset(item.Name, item.Description, (sbyte)item.AssetType, data); 169 CreateAsset(item.Name, item.Description, (sbyte)item.AssetType, data);
196 item.AssetID = asset.FullID; 170 item.AssetID = asset.FullID;
197 AssetService.Store(asset); 171 AssetService.Store(asset);
198 172
199 userInfo.UpdateItem(item); 173 InventoryService.UpdateItem(item);
200 174
201 // remoteClient.SendInventoryItemCreateUpdate(item); 175 // remoteClient.SendInventoryItemCreateUpdate(item);
202 return (asset.FullID); 176 return (asset.FullID);
203 }
204 }
205 } 177 }
206 else 178 else
207 { 179 {
@@ -343,63 +315,52 @@ namespace OpenSim.Region.Framework.Scenes
343 public void UpdateInventoryItemAsset(IClientAPI remoteClient, UUID transactionID, 315 public void UpdateInventoryItemAsset(IClientAPI remoteClient, UUID transactionID,
344 UUID itemID, InventoryItemBase itemUpd) 316 UUID itemID, InventoryItemBase itemUpd)
345 { 317 {
346 CachedUserInfo userInfo 318 InventoryItemBase item = InventoryService.QueryItem(new InventoryItemBase(itemID));
347 = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
348 319
349 if (userInfo != null && userInfo.RootFolder != null) 320 if (item != null)
350 { 321 {
351 InventoryItemBase item = userInfo.RootFolder.FindItem(itemID); 322 if (UUID.Zero == transactionID)
352
353 if (item != null)
354 { 323 {
355 if (UUID.Zero == transactionID) 324 item.Name = itemUpd.Name;
356 { 325 item.Description = itemUpd.Description;
357 item.Name = itemUpd.Name; 326 item.NextPermissions = itemUpd.NextPermissions;
358 item.Description = itemUpd.Description; 327 item.CurrentPermissions |= 8; // Slam!
359 item.NextPermissions = itemUpd.NextPermissions; 328 item.EveryOnePermissions = itemUpd.EveryOnePermissions;
360 item.CurrentPermissions |= 8; // Slam! 329 item.GroupPermissions = itemUpd.GroupPermissions;
361 item.EveryOnePermissions = itemUpd.EveryOnePermissions;
362 item.GroupPermissions = itemUpd.GroupPermissions;
363
364 item.GroupID = itemUpd.GroupID;
365 item.GroupOwned = itemUpd.GroupOwned;
366 item.CreationDate = itemUpd.CreationDate;
367 // The client sends zero if its newly created?
368
369 if (itemUpd.CreationDate == 0)
370 item.CreationDate = Util.UnixTimeSinceEpoch();
371 else
372 item.CreationDate = itemUpd.CreationDate;
373 330
374 // TODO: Check if folder changed and move item 331 item.GroupID = itemUpd.GroupID;
375 //item.NextPermissions = itemUpd.Folder; 332 item.GroupOwned = itemUpd.GroupOwned;
376 item.InvType = itemUpd.InvType; 333 item.CreationDate = itemUpd.CreationDate;
377 item.SalePrice = itemUpd.SalePrice; 334 // The client sends zero if its newly created?
378 item.SaleType = itemUpd.SaleType;
379 item.Flags = itemUpd.Flags;
380 335
381 userInfo.UpdateItem(item); 336 if (itemUpd.CreationDate == 0)
382 } 337 item.CreationDate = Util.UnixTimeSinceEpoch();
383 else 338 else
384 { 339 item.CreationDate = itemUpd.CreationDate;
385 IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>(); 340
386 if (agentTransactions != null) 341 // TODO: Check if folder changed and move item
387 { 342 //item.NextPermissions = itemUpd.Folder;
388 agentTransactions.HandleItemUpdateFromTransaction( 343 item.InvType = itemUpd.InvType;
389 remoteClient, transactionID, item); 344 item.SalePrice = itemUpd.SalePrice;
390 } 345 item.SaleType = itemUpd.SaleType;
391 } 346 item.Flags = itemUpd.Flags;
347
348 InventoryService.UpdateItem(item);
392 } 349 }
393 else 350 else
394 { 351 {
395 m_log.Error( 352 IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>();
396 "[AGENTINVENTORY]: Item ID " + itemID + " not found for an inventory item update."); 353 if (agentTransactions != null)
354 {
355 agentTransactions.HandleItemUpdateFromTransaction(
356 remoteClient, transactionID, item);
357 }
397 } 358 }
398 } 359 }
399 else 360 else
400 { 361 {
401 m_log.Error( 362 m_log.Error(
402 "[AGENT INVENTORY]: Agent ID " + remoteClient.AgentId + " not found for an inventory item update."); 363 "[AGENTINVENTORY]: Item ID " + itemID + " not found for an inventory item update.");
403 } 364 }
404 } 365 }
405 366
@@ -445,123 +406,85 @@ namespace OpenSim.Region.Framework.Scenes
445 public virtual InventoryItemBase GiveInventoryItem( 406 public virtual InventoryItemBase GiveInventoryItem(
446 UUID recipient, UUID senderId, UUID itemId, UUID recipientFolderId) 407 UUID recipient, UUID senderId, UUID itemId, UUID recipientFolderId)
447 { 408 {
448 // Retrieve the item from the sender
449 CachedUserInfo senderUserInfo = CommsManager.UserProfileCacheService.GetUserDetails(senderId);
450
451 Console.WriteLine("Scene.Inventory.cs: GiveInventoryItem"); 409 Console.WriteLine("Scene.Inventory.cs: GiveInventoryItem");
452 410
453 if (senderUserInfo == null) 411 InventoryItemBase item = InventoryService.QueryItem(new InventoryItemBase(itemId));
454 {
455 m_log.ErrorFormat(
456 "[AGENT INVENTORY]: Failed to find sending user {0} for item {1}", senderId, itemId);
457
458 return null;
459 }
460 412
461 if (senderUserInfo.RootFolder != null) 413 if ((item != null) && (item.Owner == senderId))
462 { 414 {
463 InventoryItemBase item = senderUserInfo.RootFolder.FindItem(itemId); 415 if (!Permissions.BypassPermissions())
464
465 if (item != null)
466 { 416 {
467 if (!Permissions.BypassPermissions()) 417 if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
468 { 418 return null;
469 if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0) 419 }
470 return null;
471 }
472 420
473 CachedUserInfo recipientUserInfo 421 // Insert a copy of the item into the recipient
474 = CommsManager.UserProfileCacheService.GetUserDetails(recipient); 422 InventoryItemBase itemCopy = new InventoryItemBase();
423 itemCopy.Owner = recipient;
424 itemCopy.CreatorId = item.CreatorId;
425 itemCopy.ID = UUID.Random();
426 itemCopy.AssetID = item.AssetID;
427 itemCopy.Description = item.Description;
428 itemCopy.Name = item.Name;
429 itemCopy.AssetType = item.AssetType;
430 itemCopy.InvType = item.InvType;
431 itemCopy.Folder = recipientFolderId;
475 432
476 if (recipientUserInfo != null) 433 if (Permissions.PropagatePermissions())
434 {
435 if (item.InvType == (int)InventoryType.Object)
477 { 436 {
478 if (!recipientUserInfo.HasReceivedInventory) 437 itemCopy.BasePermissions &= ~(uint)(PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer);
479 recipientUserInfo.FetchInventory(); 438 itemCopy.BasePermissions |= (item.CurrentPermissions & 7) << 13;
480
481 // Insert a copy of the item into the recipient
482 InventoryItemBase itemCopy = new InventoryItemBase();
483 itemCopy.Owner = recipient;
484 itemCopy.CreatorId = item.CreatorId;
485 itemCopy.ID = UUID.Random();
486 itemCopy.AssetID = item.AssetID;
487 itemCopy.Description = item.Description;
488 itemCopy.Name = item.Name;
489 itemCopy.AssetType = item.AssetType;
490 itemCopy.InvType = item.InvType;
491 itemCopy.Folder = recipientFolderId;
492
493 if (Permissions.PropagatePermissions())
494 {
495 if (item.InvType == (int)InventoryType.Object)
496 {
497 itemCopy.BasePermissions &= ~(uint)(PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer);
498 itemCopy.BasePermissions |= (item.CurrentPermissions & 7) << 13;
499 }
500 else
501 {
502 itemCopy.BasePermissions = item.BasePermissions & item.NextPermissions;
503 }
504
505 itemCopy.CurrentPermissions = itemCopy.BasePermissions;
506 if ((item.CurrentPermissions & 8) != 0) // Propagate slam bit
507 {
508 itemCopy.BasePermissions &= item.NextPermissions;
509 itemCopy.CurrentPermissions = itemCopy.BasePermissions;
510 itemCopy.CurrentPermissions |= 8;
511 }
512
513 itemCopy.NextPermissions = item.NextPermissions;
514 itemCopy.EveryOnePermissions = item.EveryOnePermissions & item.NextPermissions;
515 itemCopy.GroupPermissions = item.GroupPermissions & item.NextPermissions;
516 }
517 else
518 {
519 itemCopy.CurrentPermissions = item.CurrentPermissions;
520 itemCopy.NextPermissions = item.NextPermissions;
521 itemCopy.EveryOnePermissions = item.EveryOnePermissions & item.NextPermissions;
522 itemCopy.GroupPermissions = item.GroupPermissions & item.NextPermissions;
523 itemCopy.BasePermissions = item.BasePermissions;
524 }
525
526 itemCopy.GroupID = UUID.Zero;
527 itemCopy.GroupOwned = false;
528 itemCopy.Flags = item.Flags;
529 itemCopy.SalePrice = item.SalePrice;
530 itemCopy.SaleType = item.SaleType;
531
532 recipientUserInfo.AddItem(itemCopy);
533
534 if (!Permissions.BypassPermissions())
535 {
536 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
537 senderUserInfo.DeleteItem(itemId);
538 }
539
540 return itemCopy;
541 } 439 }
542 else 440 else
543 { 441 {
544 m_log.ErrorFormat( 442 itemCopy.BasePermissions = item.BasePermissions & item.NextPermissions;
545 "[AGENT INVENTORY]: Could not find userinfo for recipient user {0} of item {1}, {2} from {3}",
546 recipient, item.Name,
547 item.ID, senderId);
548 } 443 }
444
445 itemCopy.CurrentPermissions = itemCopy.BasePermissions;
446 if ((item.CurrentPermissions & 8) != 0) // Propagate slam bit
447 {
448 itemCopy.BasePermissions &= item.NextPermissions;
449 itemCopy.CurrentPermissions = itemCopy.BasePermissions;
450 itemCopy.CurrentPermissions |= 8;
451 }
452
453 itemCopy.NextPermissions = item.NextPermissions;
454 itemCopy.EveryOnePermissions = item.EveryOnePermissions & item.NextPermissions;
455 itemCopy.GroupPermissions = item.GroupPermissions & item.NextPermissions;
549 } 456 }
550 else 457 else
551 { 458 {
552 m_log.ErrorFormat( 459 itemCopy.CurrentPermissions = item.CurrentPermissions;
553 "[AGENT INVENTORY]: Failed to find item {0} to give to {1}", itemId, senderId); 460 itemCopy.NextPermissions = item.NextPermissions;
461 itemCopy.EveryOnePermissions = item.EveryOnePermissions & item.NextPermissions;
462 itemCopy.GroupPermissions = item.GroupPermissions & item.NextPermissions;
463 itemCopy.BasePermissions = item.BasePermissions;
464 }
465
466 itemCopy.GroupID = UUID.Zero;
467 itemCopy.GroupOwned = false;
468 itemCopy.Flags = item.Flags;
469 itemCopy.SalePrice = item.SalePrice;
470 itemCopy.SaleType = item.SaleType;
554 471
555 return null; 472 InventoryService.AddItem(itemCopy);
473
474 if (!Permissions.BypassPermissions())
475 {
476 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
477 InventoryService.DeleteItem(new InventoryItemBase(itemId));
556 } 478 }
479
480 return itemCopy;
557 } 481 }
558 else 482 else
559 { 483 {
560 m_log.Error("[AGENT INVENTORY]: Failed to find item " + itemId.ToString() + ", no root folder"); 484 m_log.WarnFormat("[AGENT INVENTORY]: Failed to find item {0} or item does not belong to giver ", itemId);
561 return null; 485 return null;
562 } 486 }
563 487
564 return null;
565 } 488 }
566 489
567 /// <summary> 490 /// <summary>
@@ -578,31 +501,11 @@ namespace OpenSim.Region.Framework.Scenes
578 /// <returns> 501 /// <returns>
579 /// The inventory folder copy given, null if the copy was unsuccessful 502 /// The inventory folder copy given, null if the copy was unsuccessful
580 /// </returns> 503 /// </returns>
581 public virtual InventoryFolderImpl GiveInventoryFolder( 504 public virtual InventoryFolderBase GiveInventoryFolder(
582 UUID recipientId, UUID senderId, UUID folderId, UUID recipientParentFolderId) 505 UUID recipientId, UUID senderId, UUID folderId, UUID recipientParentFolderId)
583 { 506 {
584 // Retrieve the folder from the sender 507 //// Retrieve the folder from the sender
585 CachedUserInfo senderUserInfo = CommsManager.UserProfileCacheService.GetUserDetails(senderId); 508 InventoryFolderBase folder = InventoryService.QueryFolder(new InventoryFolderBase(folderId));
586
587 if (null == senderUserInfo)
588 {
589 m_log.ErrorFormat(
590 "[AGENT INVENTORY]: Failed to find sending user {0} for folder {1}", senderId, folderId);
591
592 return null;
593 }
594
595 if (!senderUserInfo.HasReceivedInventory)
596 {
597 m_log.DebugFormat(
598 "[AGENT INVENTORY]: Could not give inventory folder - have not yet received inventory for {0}",
599 senderId);
600
601 return null;
602 }
603
604 InventoryFolderImpl folder = senderUserInfo.RootFolder.FindFolder(folderId);
605
606 if (null == folder) 509 if (null == folder)
607 { 510 {
608 m_log.ErrorFormat( 511 m_log.ErrorFormat(
@@ -611,48 +514,37 @@ namespace OpenSim.Region.Framework.Scenes
611 return null; 514 return null;
612 } 515 }
613 516
614 CachedUserInfo recipientUserInfo
615 = CommsManager.UserProfileCacheService.GetUserDetails(recipientId);
616
617 if (null == recipientUserInfo)
618 {
619 m_log.ErrorFormat(
620 "[AGENT INVENTORY]: Failed to find receiving user {0} for folder {1}", recipientId, folderId);
621
622 return null;
623 }
624 517
625 if (!recipientUserInfo.HasReceivedInventory) 518 if (recipientParentFolderId == UUID.Zero)
626 { 519 {
627 recipientUserInfo.FetchInventory(); 520 InventoryFolderBase recipientRootFolder = InventoryService.GetRootFolder(recipientId);
628 if (!WaitForInventory(recipientUserInfo)) 521 if (recipientRootFolder != null)
522 recipientParentFolderId = recipientRootFolder.ID;
523 else
524 {
525 m_log.WarnFormat("[AGENT INVENTORY]: Unable to find root folder for receiving agent");
629 return null; 526 return null;
527 }
630 } 528 }
631 529
632 if (recipientParentFolderId == UUID.Zero)
633 recipientParentFolderId = recipientUserInfo.RootFolder.ID;
634
635 UUID newFolderId = UUID.Random(); 530 UUID newFolderId = UUID.Random();
636 recipientUserInfo.CreateFolder(folder.Name, newFolderId, (ushort)folder.Type, recipientParentFolderId); 531 InventoryFolderBase newFolder = new InventoryFolderBase(newFolderId, folder.Name, recipientId, folder.Type, recipientParentFolderId, folder.Version);
637 532 InventoryService.AddFolder(newFolder);
638 // XXX: Messy - we should really get this back in the CreateFolder call
639 InventoryFolderImpl copiedFolder = recipientUserInfo.RootFolder.FindFolder(newFolderId);
640 533
641 // Give all the subfolders 534 // Give all the subfolders
642 List<InventoryFolderImpl> subFolders = folder.RequestListOfFolderImpls(); 535 InventoryCollection contents = InventoryService.GetFolderContent(senderId, folderId);
643 foreach (InventoryFolderImpl childFolder in subFolders) 536 foreach (InventoryFolderBase childFolder in contents.Folders)
644 { 537 {
645 GiveInventoryFolder(recipientId, senderId, childFolder.ID, copiedFolder.ID); 538 GiveInventoryFolder(recipientId, senderId, childFolder.ID, newFolder.ID);
646 } 539 }
647 540
648 // Give all the items 541 // Give all the items
649 List<InventoryItemBase> items = folder.RequestListOfItems(); 542 foreach (InventoryItemBase item in contents.Items)
650 foreach (InventoryItemBase item in items)
651 { 543 {
652 GiveInventoryItem(recipientId, senderId, item.ID, copiedFolder.ID); 544 GiveInventoryItem(recipientId, senderId, item.ID, newFolder.ID);
653 } 545 }
654 546
655 return copiedFolder; 547 return newFolder;
656 } 548 }
657 549
658 public void CopyInventoryItem(IClientAPI remoteClient, uint callbackID, UUID oldAgentID, UUID oldItemID, 550 public void CopyInventoryItem(IClientAPI remoteClient, uint callbackID, UUID oldAgentID, UUID oldItemID,
@@ -759,41 +651,24 @@ namespace OpenSim.Region.Framework.Scenes
759 m_log.DebugFormat( 651 m_log.DebugFormat(
760 "[AGENT INVENTORY]: Moving item {0} to {1} for {2}", itemID, folderID, remoteClient.AgentId); 652 "[AGENT INVENTORY]: Moving item {0} to {1} for {2}", itemID, folderID, remoteClient.AgentId);
761 653
762 CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId); 654 InventoryItemBase item = InventoryService.QueryItem(new InventoryItemBase(itemID));
763
764 if (userInfo == null)
765 {
766 m_log.Error("[AGENT INVENTORY]: Failed to find user " + remoteClient.AgentId.ToString());
767 655
768 return; 656 if (item != null)
769 }
770
771 if (userInfo.RootFolder != null)
772 { 657 {
773 InventoryItemBase item = userInfo.RootFolder.FindItem(itemID); 658 if (newName != String.Empty)
774
775 if (item != null)
776 { 659 {
777 if (newName != String.Empty) 660 item.Name = newName;
778 {
779 item.Name = newName;
780 }
781 item.Folder = folderID;
782
783 userInfo.DeleteItem(item.ID);
784
785 AddInventoryItem(remoteClient, item);
786 } 661 }
787 else 662 item.Folder = folderID;
788 {
789 m_log.Error("[AGENT INVENTORY]: Failed to find item " + itemID.ToString());
790 663
791 return; 664 // Diva comment: can't we just update?
792 } 665 InventoryService.DeleteItem(item);
666
667 AddInventoryItem(remoteClient, item);
793 } 668 }
794 else 669 else
795 { 670 {
796 m_log.Error("[AGENT INVENTORY]: Failed to find item " + itemID.ToString() + ", no root folder"); 671 m_log.Warn("[AGENT INVENTORY]: Failed to find item " + itemID.ToString());
797 672
798 return; 673 return;
799 } 674 }
@@ -830,37 +705,32 @@ namespace OpenSim.Region.Framework.Scenes
830 IClientAPI remoteClient, string creatorID, UUID folderID, string name, uint flags, uint callbackID, AssetBase asset, sbyte invType, 705 IClientAPI remoteClient, string creatorID, UUID folderID, string name, uint flags, uint callbackID, AssetBase asset, sbyte invType,
831 uint baseMask, uint currentMask, uint everyoneMask, uint nextOwnerMask, uint groupMask, int creationDate) 706 uint baseMask, uint currentMask, uint everyoneMask, uint nextOwnerMask, uint groupMask, int creationDate)
832 { 707 {
833 CachedUserInfo userInfo 708 InventoryItemBase item = new InventoryItemBase();
834 = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId); 709 item.Owner = remoteClient.AgentId;
835 710 item.CreatorId = creatorID;
836 if (userInfo != null) 711 item.ID = UUID.Random();
837 { 712 item.AssetID = asset.FullID;
838 InventoryItemBase item = new InventoryItemBase(); 713 item.Description = asset.Description;
839 item.Owner = remoteClient.AgentId; 714 item.Name = name;
840 item.CreatorId = creatorID; 715 item.Flags = flags;
841 item.ID = UUID.Random(); 716 item.AssetType = asset.Type;
842 item.AssetID = asset.FullID; 717 item.InvType = invType;
843 item.Description = asset.Description; 718 item.Folder = folderID;
844 item.Name = name; 719 item.CurrentPermissions = currentMask;
845 item.Flags = flags; 720 item.NextPermissions = nextOwnerMask;
846 item.AssetType = asset.Type; 721 item.EveryOnePermissions = everyoneMask;
847 item.InvType = invType; 722 item.GroupPermissions = groupMask;
848 item.Folder = folderID; 723 item.BasePermissions = baseMask;
849 item.CurrentPermissions = currentMask; 724 item.CreationDate = creationDate;
850 item.NextPermissions = nextOwnerMask; 725
851 item.EveryOnePermissions = everyoneMask; 726 if (InventoryService.AddItem(item))
852 item.GroupPermissions = groupMask;
853 item.BasePermissions = baseMask;
854 item.CreationDate = creationDate;
855
856 userInfo.AddItem(item);
857 remoteClient.SendInventoryItemCreateUpdate(item, callbackID); 727 remoteClient.SendInventoryItemCreateUpdate(item, callbackID);
858 }
859 else 728 else
860 { 729 {
730 m_dialogModule.SendAlertToUser(remoteClient, "Failed to create item");
861 m_log.WarnFormat( 731 m_log.WarnFormat(
862 "No user details associated with client {0} uuid {1} in CreateNewInventoryItem!", 732 "Failed to add item for {0} in CreateNewInventoryItem!",
863 remoteClient.Name, remoteClient.AgentId); 733 remoteClient.Name);
864 } 734 }
865 } 735 }
866 736
@@ -941,19 +811,7 @@ namespace OpenSim.Region.Framework.Scenes
941 /// <param name="itemID"></param> 811 /// <param name="itemID"></param>
942 private void RemoveInventoryItem(IClientAPI remoteClient, UUID itemID) 812 private void RemoveInventoryItem(IClientAPI remoteClient, UUID itemID)
943 { 813 {
944 CachedUserInfo userInfo 814 InventoryService.DeleteItem(new InventoryItemBase(itemID));
945 = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
946
947 if (userInfo == null)
948 {
949 m_log.WarnFormat(
950 "[AGENT INVENTORY]: Failed to find user {0} {1} to delete inventory item {2}",
951 remoteClient.Name, remoteClient.AgentId, itemID);
952
953 return;
954 }
955
956 userInfo.DeleteItem(itemID);
957 } 815 }
958 816
959 /// <summary> 817 /// <summary>
@@ -1332,19 +1190,12 @@ namespace OpenSim.Region.Framework.Scenes
1332 1190
1333 public UUID MoveTaskInventoryItems(UUID destID, string category, SceneObjectPart host, List<UUID> items) 1191 public UUID MoveTaskInventoryItems(UUID destID, string category, SceneObjectPart host, List<UUID> items)
1334 { 1192 {
1335 CachedUserInfo profile = CommsManager.UserProfileCacheService.GetUserDetails(destID); 1193 InventoryFolderBase rootFolder = InventoryService.GetRootFolder(destID);
1336 if (profile == null || profile.RootFolder == null)
1337 {
1338 m_log.ErrorFormat(
1339 "[PRIM INVENTORY]: " +
1340 "Avatar {0} cannot be found to add items",
1341 destID);
1342 return UUID.Zero;
1343 }
1344 1194
1345 UUID newFolderID = UUID.Random(); 1195 UUID newFolderID = UUID.Random();
1346 1196
1347 profile.CreateFolder(category, newFolderID, 0xffff, profile.RootFolder.ID); 1197 InventoryFolderBase newFolder = new InventoryFolderBase(newFolderID, category, destID, 0xff, rootFolder.ID, rootFolder.Version);
1198 InventoryService.AddFolder(newFolder);
1348 1199
1349 foreach (UUID itemID in items) 1200 foreach (UUID itemID in items)
1350 { 1201 {
@@ -1358,19 +1209,27 @@ namespace OpenSim.Region.Framework.Scenes
1358 } 1209 }
1359 } 1210 }
1360 1211
1361 ScenePresence avatar; 1212 ScenePresence avatar = null;
1362
1363 if (TryGetAvatar(destID, out avatar)) 1213 if (TryGetAvatar(destID, out avatar))
1364 { 1214 {
1365 profile.SendInventoryDecendents(avatar.ControllingClient, 1215 //profile.SendInventoryDecendents(avatar.ControllingClient,
1366 profile.RootFolder.ID, true, false); 1216 // profile.RootFolder.ID, true, false);
1367 profile.SendInventoryDecendents(avatar.ControllingClient, 1217 //profile.SendInventoryDecendents(avatar.ControllingClient,
1368 newFolderID, false, true); 1218 // newFolderID, false, true);
1219
1220 SendInventoryUpdate(avatar.ControllingClient, rootFolder, true, false);
1221 SendInventoryUpdate(avatar.ControllingClient, newFolder, false, true);
1369 } 1222 }
1370 1223
1371 return newFolderID; 1224 return newFolderID;
1372 } 1225 }
1373 1226
1227 private void SendInventoryUpdate(IClientAPI client, InventoryFolderBase folder, bool fetchFolders, bool fetchItems)
1228 {
1229 InventoryCollection contents = InventoryService.GetFolderContent(client.AgentId, folder.ID);
1230 client.SendInventoryFolderDetails(client.AgentId, folder.ID, contents.Items, contents.Folders, fetchFolders, fetchItems);
1231 }
1232
1374 /// <summary> 1233 /// <summary>
1375 /// Update an item in a prim (task) inventory. 1234 /// Update an item in a prim (task) inventory.
1376 /// This method does not handle scripts, <see>RezScript(IClientAPI, UUID, unit)</see> 1235 /// This method does not handle scripts, <see>RezScript(IClientAPI, UUID, unit)</see>
@@ -1848,7 +1707,7 @@ namespace OpenSim.Region.Framework.Scenes
1848 1707
1849 // Get the user info of the item destination 1708 // Get the user info of the item destination
1850 // 1709 //
1851 CachedUserInfo userInfo; 1710 UUID userID = UUID.Zero;
1852 1711
1853 if (action == DeRezAction.Take || action == DeRezAction.TakeCopy || 1712 if (action == DeRezAction.Take || action == DeRezAction.TakeCopy ||
1854 action == DeRezAction.SaveToExistingUserInventoryItem) 1713 action == DeRezAction.SaveToExistingUserInventoryItem)
@@ -1859,28 +1718,19 @@ namespace OpenSim.Region.Framework.Scenes
1859 if (remoteClient == null) 1718 if (remoteClient == null)
1860 return UUID.Zero; 1719 return UUID.Zero;
1861 1720
1862 userInfo = CommsManager.UserProfileCacheService.GetUserDetails( 1721 userID = remoteClient.AgentId;
1863 remoteClient.AgentId);
1864 } 1722 }
1865 else 1723 else
1866 { 1724 {
1867 // All returns / deletes go to the object owner 1725 // All returns / deletes go to the object owner
1868 // 1726 //
1869 userInfo = CommsManager.UserProfileCacheService.GetUserDetails(
1870 objectGroup.RootPart.OwnerID);
1871 }
1872 1727
1873 if (userInfo == null) // Can't proceed 1728 userID = objectGroup.RootPart.OwnerID;
1874 {
1875 return UUID.Zero;
1876 } 1729 }
1877 1730
1878 if (!userInfo.HasReceivedInventory) 1731 if (userID == UUID.Zero) // Can't proceed
1879 { 1732 {
1880 // Async inventory requests will queue, but they will never 1733 return UUID.Zero;
1881 // execute unless inventory is actually fetched
1882 //
1883 userInfo.FetchInventory();
1884 } 1734 }
1885 1735
1886 // If we're returning someone's item, it goes back to the 1736 // If we're returning someone's item, it goes back to the
@@ -1894,8 +1744,11 @@ namespace OpenSim.Region.Framework.Scenes
1894 1744
1895 if (DeRezAction.SaveToExistingUserInventoryItem == action) 1745 if (DeRezAction.SaveToExistingUserInventoryItem == action)
1896 { 1746 {
1897 item = userInfo.RootFolder.FindItem( 1747 item = new InventoryItemBase(objectGroup.RootPart.FromUserInventoryItemID);
1898 objectGroup.RootPart.FromUserInventoryItemID); 1748 item = InventoryService.QueryItem(item);
1749
1750 //item = userInfo.RootFolder.FindItem(
1751 // objectGroup.RootPart.FromUserInventoryItemID);
1899 1752
1900 if (null == item) 1753 if (null == item)
1901 { 1754 {
@@ -1920,53 +1773,36 @@ namespace OpenSim.Region.Framework.Scenes
1920 // have to wait for the inventory to find 1773 // have to wait for the inventory to find
1921 // the destination folder 1774 // the destination folder
1922 // 1775 //
1923 if (!WaitForInventory(userInfo)) 1776 folder = InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder);
1924 return UUID.Zero;
1925 folder = userInfo.FindFolderForType(
1926 (int)AssetType.LostAndFoundFolder);
1927 } 1777 }
1928 else 1778 else
1929 { 1779 {
1930 // Assume inventory skeleton was loaded during login 1780 // Assume inventory skeleton was loaded during login
1931 // and all folders can be found 1781 // and all folders can be found
1932 // 1782 //
1933 folder = userInfo.FindFolderForType( 1783 folder = InventoryService.GetFolderForType(userID, AssetType.TrashFolder);
1934 (int)AssetType.TrashFolder);
1935 } 1784 }
1936 } 1785 }
1937 else if (action == DeRezAction.Return) 1786 else if (action == DeRezAction.Return)
1938 { 1787 {
1939 // Wait if needed
1940 //
1941 if (!userInfo.HasReceivedInventory)
1942 {
1943 if (!WaitForInventory(userInfo))
1944 return UUID.Zero;
1945 }
1946 1788
1947 // Dump to lost + found unconditionally 1789 // Dump to lost + found unconditionally
1948 // 1790 //
1949 folder = userInfo.FindFolderForType( 1791 folder = InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder);
1950 (int)AssetType.LostAndFoundFolder);
1951 } 1792 }
1952 1793
1953 if (folderID == UUID.Zero && folder == null) 1794 if (folderID == UUID.Zero && folder == null)
1954 { 1795 {
1955 // Catch all. Use lost & found 1796 // Catch all. Use lost & found
1956 // 1797 //
1957 if (!userInfo.HasReceivedInventory)
1958 {
1959 if (!WaitForInventory(userInfo))
1960 return UUID.Zero;
1961 }
1962 1798
1963 folder = userInfo.FindFolderForType( 1799 folder = InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder);
1964 (int)AssetType.LostAndFoundFolder);
1965 } 1800 }
1966 1801
1967 if (folder == null) // None of the above 1802 if (folder == null) // None of the above
1968 { 1803 {
1969 folder = userInfo.RootFolder.FindFolder(folderID); 1804 //folder = userInfo.RootFolder.FindFolder(folderID);
1805 folder = new InventoryFolderBase(folderID);
1970 1806
1971 if (folder == null) // Nowhere to put it 1807 if (folder == null) // Nowhere to put it
1972 { 1808 {
@@ -1979,7 +1815,7 @@ namespace OpenSim.Region.Framework.Scenes
1979 item.ID = UUID.Random(); 1815 item.ID = UUID.Random();
1980 item.InvType = (int)InventoryType.Object; 1816 item.InvType = (int)InventoryType.Object;
1981 item.Folder = folder.ID; 1817 item.Folder = folder.ID;
1982 item.Owner = userInfo.UserProfile.ID; 1818 item.Owner = userID;
1983 } 1819 }
1984 1820
1985 AssetBase asset = CreateAsset( 1821 AssetBase asset = CreateAsset(
@@ -1993,7 +1829,7 @@ namespace OpenSim.Region.Framework.Scenes
1993 if (DeRezAction.SaveToExistingUserInventoryItem == action) 1829 if (DeRezAction.SaveToExistingUserInventoryItem == action)
1994 { 1830 {
1995 item.AssetID = asset.FullID; 1831 item.AssetID = asset.FullID;
1996 userInfo.UpdateItem(item); 1832 InventoryService.UpdateItem(item);
1997 } 1833 }
1998 else 1834 else
1999 { 1835 {
@@ -2034,7 +1870,7 @@ namespace OpenSim.Region.Framework.Scenes
2034 item.Name = asset.Name; 1870 item.Name = asset.Name;
2035 item.AssetType = asset.Type; 1871 item.AssetType = asset.Type;
2036 1872
2037 userInfo.AddItem(item); 1873 InventoryService.AddItem(item);
2038 1874
2039 if (remoteClient != null && item.Owner == remoteClient.AgentId) 1875 if (remoteClient != null && item.Owner == remoteClient.AgentId)
2040 { 1876 {
@@ -2053,7 +1889,7 @@ namespace OpenSim.Region.Framework.Scenes
2053 return assetID; 1889 return assetID;
2054 } 1890 }
2055 1891
2056 public void updateKnownAsset(IClientAPI remoteClient, SceneObjectGroup grp, UUID assetID, UUID agentID) 1892 public void UpdateKnownItem(IClientAPI remoteClient, SceneObjectGroup grp, UUID itemID, UUID agentID)
2057 { 1893 {
2058 SceneObjectGroup objectGroup = grp; 1894 SceneObjectGroup objectGroup = grp;
2059 if (objectGroup != null) 1895 if (objectGroup != null)
@@ -2070,65 +1906,29 @@ namespace OpenSim.Region.Framework.Scenes
2070 1906
2071 string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(objectGroup); 1907 string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(objectGroup);
2072 1908
2073 CachedUserInfo userInfo = 1909 InventoryItemBase item = InventoryService.QueryItem(new InventoryItemBase(itemID));
2074 CommsManager.UserProfileCacheService.GetUserDetails(agentID); 1910
2075 if (userInfo != null && userInfo.RootFolder != null) 1911 if (item != null)
2076 { 1912 {
2077 Queue<InventoryFolderImpl> searchfolders = new Queue<InventoryFolderImpl>(); 1913 AssetBase asset = CreateAsset(
2078 searchfolders.Enqueue(userInfo.RootFolder); 1914 objectGroup.GetPartName(objectGroup.LocalId),
1915 objectGroup.GetPartDescription(objectGroup.LocalId),
1916 (sbyte)AssetType.Object,
1917 Utils.StringToBytes(sceneObjectXml));
1918 AssetService.Store(asset);
2079 1919
2080 UUID foundFolder = UUID.Zero; 1920 item.AssetID = asset.FullID;
2081 InventoryItemBase item = null; 1921 item.Description = asset.Description;
1922 item.Name = asset.Name;
1923 item.AssetType = asset.Type;
1924 item.InvType = (int)InventoryType.Object;
2082 1925
2083 // search through folders to find the asset. 1926 InventoryService.UpdateItem(item);
2084 while (searchfolders.Count > 0)
2085 {
2086 InventoryFolderImpl fld = searchfolders.Dequeue();
2087 lock (fld)
2088 {
2089 if (fld != null)
2090 {
2091 if (fld.Items.ContainsKey(assetID))
2092 {
2093 item = fld.Items[assetID];
2094 foundFolder = fld.ID;
2095 searchfolders.Clear();
2096 break;
2097 }
2098 else
2099 {
2100 foreach (InventoryFolderImpl subfld in fld.RequestListOfFolderImpls())
2101 {
2102 searchfolders.Enqueue(subfld);
2103 }
2104 }
2105 }
2106 }
2107 }
2108 1927
2109 if (foundFolder != UUID.Zero && item != null) 1928 // this gets called when the agent loggs off!
1929 if (remoteClient != null)
2110 { 1930 {
2111 AssetBase asset = CreateAsset( 1931 remoteClient.SendInventoryItemCreateUpdate(item, 0);
2112 objectGroup.GetPartName(objectGroup.LocalId),
2113 objectGroup.GetPartDescription(objectGroup.LocalId),
2114 (sbyte)AssetType.Object,
2115 Utils.StringToBytes(sceneObjectXml));
2116 AssetService.Store(asset);
2117
2118 item.AssetID = asset.FullID;
2119 item.Description = asset.Description;
2120 item.Name = asset.Name;
2121 item.AssetType = asset.Type;
2122 item.InvType = (int)InventoryType.Object;
2123 item.Folder = foundFolder;
2124
2125 userInfo.UpdateItem(item);
2126
2127 // this gets called when the agent loggs off!
2128 if (remoteClient != null)
2129 {
2130 remoteClient.SendInventoryItemCreateUpdate(item, 0);
2131 }
2132 } 1932 }
2133 } 1933 }
2134 } 1934 }
@@ -2140,59 +1940,54 @@ namespace OpenSim.Region.Framework.Scenes
2140 if (grp != null) 1940 if (grp != null)
2141 { 1941 {
2142 string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp); 1942 string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp);
1943
1944 AssetBase asset = CreateAsset(
1945 grp.GetPartName(grp.LocalId),
1946 grp.GetPartDescription(grp.LocalId),
1947 (sbyte)AssetType.Object,
1948 Utils.StringToBytes(sceneObjectXml));
1949 AssetService.Store(asset);
2143 1950
2144 CachedUserInfo userInfo = 1951 InventoryItemBase item = new InventoryItemBase();
2145 CommsManager.UserProfileCacheService.GetUserDetails(AgentId); 1952 item.CreatorId = grp.RootPart.CreatorID.ToString();
2146 1953 item.Owner = remoteClient.AgentId;
2147 if (userInfo != null) 1954 item.ID = UUID.Random();
2148 { 1955 item.AssetID = asset.FullID;
2149 AssetBase asset = CreateAsset( 1956 item.Description = asset.Description;
2150 grp.GetPartName(grp.LocalId), 1957 item.Name = asset.Name;
2151 grp.GetPartDescription(grp.LocalId), 1958 item.AssetType = asset.Type;
2152 (sbyte)AssetType.Object, 1959 item.InvType = (int)InventoryType.Object;
2153 Utils.StringToBytes(sceneObjectXml));
2154 AssetService.Store(asset);
2155
2156 InventoryItemBase item = new InventoryItemBase();
2157 item.CreatorId = grp.RootPart.CreatorID.ToString();
2158 item.Owner = remoteClient.AgentId;
2159 item.ID = UUID.Random();
2160 item.AssetID = asset.FullID;
2161 item.Description = asset.Description;
2162 item.Name = asset.Name;
2163 item.AssetType = asset.Type;
2164 item.InvType = (int)InventoryType.Object;
2165 1960
2166 item.Folder = UUID.Zero; // Objects folder! 1961 item.Folder = UUID.Zero; // Objects folder!
2167 1962
2168 if ((remoteClient.AgentId != grp.RootPart.OwnerID) && Permissions.PropagatePermissions()) 1963 if ((remoteClient.AgentId != grp.RootPart.OwnerID) && Permissions.PropagatePermissions())
2169 { 1964 {
2170 item.BasePermissions = grp.RootPart.NextOwnerMask; 1965 item.BasePermissions = grp.RootPart.NextOwnerMask;
2171 item.CurrentPermissions = grp.RootPart.NextOwnerMask; 1966 item.CurrentPermissions = grp.RootPart.NextOwnerMask;
2172 item.NextPermissions = grp.RootPart.NextOwnerMask; 1967 item.NextPermissions = grp.RootPart.NextOwnerMask;
2173 item.EveryOnePermissions = grp.RootPart.EveryoneMask & grp.RootPart.NextOwnerMask; 1968 item.EveryOnePermissions = grp.RootPart.EveryoneMask & grp.RootPart.NextOwnerMask;
2174 item.GroupPermissions = grp.RootPart.GroupMask & grp.RootPart.NextOwnerMask; 1969 item.GroupPermissions = grp.RootPart.GroupMask & grp.RootPart.NextOwnerMask;
2175 } 1970 }
2176 else 1971 else
2177 { 1972 {
2178 item.BasePermissions = grp.RootPart.BaseMask; 1973 item.BasePermissions = grp.RootPart.BaseMask;
2179 item.CurrentPermissions = grp.RootPart.OwnerMask; 1974 item.CurrentPermissions = grp.RootPart.OwnerMask;
2180 item.NextPermissions = grp.RootPart.NextOwnerMask; 1975 item.NextPermissions = grp.RootPart.NextOwnerMask;
2181 item.EveryOnePermissions = grp.RootPart.EveryoneMask; 1976 item.EveryOnePermissions = grp.RootPart.EveryoneMask;
2182 item.GroupPermissions = grp.RootPart.GroupMask; 1977 item.GroupPermissions = grp.RootPart.GroupMask;
2183 } 1978 }
2184 item.CreationDate = Util.UnixTimeSinceEpoch(); 1979 item.CreationDate = Util.UnixTimeSinceEpoch();
2185 1980
2186 // sets assetID so client can show asset as 'attached' in inventory 1981 // sets assetID so client can show asset as 'attached' in inventory
2187 grp.SetFromAssetID(item.ID); 1982 grp.SetFromAssetID(item.ID);
2188 1983
2189 userInfo.AddItem(item); 1984 if (InventoryService.AddItem(item))
2190 remoteClient.SendInventoryItemCreateUpdate(item, 0); 1985 remoteClient.SendInventoryItemCreateUpdate(item, 0);
1986 else
1987 m_dialogModule.SendAlertToUser(remoteClient, "Operation failed");
2191 1988
2192 itemID = item.ID; 1989 itemID = item.ID;
2193 return item.AssetID; 1990 return item.AssetID;
2194 }
2195 return UUID.Zero;
2196 } 1991 }
2197 return UUID.Zero; 1992 return UUID.Zero;
2198 } 1993 }
@@ -2261,180 +2056,164 @@ namespace OpenSim.Region.Framework.Scenes
2261 BypassRayCast, bRayEndIsIntersection,true,scale, false); 2056 BypassRayCast, bRayEndIsIntersection,true,scale, false);
2262 2057
2263 // Rez object 2058 // Rez object
2264 CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId); 2059 InventoryItemBase item = InventoryService.QueryItem(new InventoryItemBase(itemID));
2265 if (userInfo != null) 2060
2061 if (item != null)
2266 { 2062 {
2267 // Do NOT use HasReceivedInventory here, this is called 2063 AssetBase rezAsset = AssetService.Get(item.AssetID.ToString());
2268 // from within ItemReceive during login for attachments. 2064
2269 // Using HasReceivedInventory here will break attachment 2065 if (rezAsset != null)
2270 // persistence!
2271 //
2272 if (userInfo.RootFolder != null)
2273 { 2066 {
2274 InventoryItemBase item = userInfo.RootFolder.FindItem(itemID); 2067 UUID itemId = UUID.Zero;
2275 2068
2276 if (item != null) 2069 // If we have permission to copy then link the rezzed object back to the user inventory
2070 // item that it came from. This allows us to enable 'save object to inventory'
2071 if (!Permissions.BypassPermissions())
2277 { 2072 {
2278 AssetBase rezAsset = AssetService.Get(item.AssetID.ToString()); 2073 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == (uint)PermissionMask.Copy)
2279
2280 if (rezAsset != null)
2281 { 2074 {
2282 UUID itemId = UUID.Zero; 2075 itemId = item.ID;
2283 2076 }
2284 // If we have permission to copy then link the rezzed object back to the user inventory 2077 }
2285 // item that it came from. This allows us to enable 'save object to inventory' 2078 else
2286 if (!Permissions.BypassPermissions()) 2079 {
2287 { 2080 // Brave new fullperm world
2288 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == (uint)PermissionMask.Copy) 2081 //
2289 { 2082 itemId = item.ID;
2290 itemId = item.ID; 2083 }
2291 }
2292 }
2293 else
2294 {
2295 // Brave new fullperm world
2296 //
2297 itemId = item.ID;
2298 }
2299
2300 string xmlData = Utils.BytesToString(rezAsset.Data);
2301 SceneObjectGroup group
2302 = SceneObjectSerializer.FromOriginalXmlFormat(itemId, xmlData);
2303 2084
2304 if (!Permissions.CanRezObject( 2085 string xmlData = Utils.BytesToString(rezAsset.Data);
2305 group.Children.Count, remoteClient.AgentId, pos) 2086 SceneObjectGroup group
2306 && !attachment) 2087 = SceneObjectSerializer.FromOriginalXmlFormat(itemId, xmlData);
2307 {
2308 return null;
2309 }
2310 2088
2311 group.ResetIDs(); 2089 if (!Permissions.CanRezObject(
2090 group.Children.Count, remoteClient.AgentId, pos)
2091 && !attachment)
2092 {
2093 return null;
2094 }
2312 2095
2313 if (attachment) 2096 group.ResetIDs();
2314 group.RootPart.ObjectFlags |= (uint)PrimFlags.Phantom;
2315 2097
2316 AddNewSceneObject(group, true); 2098 if (attachment)
2099 group.RootPart.ObjectFlags |= (uint)PrimFlags.Phantom;
2317 2100
2318 // m_log.InfoFormat("ray end point for inventory rezz is {0} {1} {2} ", RayEnd.X, RayEnd.Y, RayEnd.Z); 2101 AddNewSceneObject(group, true);
2319 // if attachment we set it's asset id so object updates can reflect that
2320 // if not, we set it's position in world.
2321 if (!attachment)
2322 {
2323 float offsetHeight = 0;
2324 pos = GetNewRezLocation(
2325 RayStart, RayEnd, RayTargetID, Quaternion.Identity,
2326 BypassRayCast, bRayEndIsIntersection, true, group.GetAxisAlignedBoundingBox(out offsetHeight), false);
2327 pos.Z += offsetHeight;
2328 group.AbsolutePosition = pos;
2329 // m_log.InfoFormat("rezx point for inventory rezz is {0} {1} {2} and offsetheight was {3}", pos.X, pos.Y, pos.Z, offsetHeight);
2330 2102
2331 } 2103 // m_log.InfoFormat("ray end point for inventory rezz is {0} {1} {2} ", RayEnd.X, RayEnd.Y, RayEnd.Z);
2332 else 2104 // if attachment we set it's asset id so object updates can reflect that
2333 { 2105 // if not, we set it's position in world.
2334 group.SetFromAssetID(itemID); 2106 if (!attachment)
2335 } 2107 {
2108 float offsetHeight = 0;
2109 pos = GetNewRezLocation(
2110 RayStart, RayEnd, RayTargetID, Quaternion.Identity,
2111 BypassRayCast, bRayEndIsIntersection, true, group.GetAxisAlignedBoundingBox(out offsetHeight), false);
2112 pos.Z += offsetHeight;
2113 group.AbsolutePosition = pos;
2114 // m_log.InfoFormat("rezx point for inventory rezz is {0} {1} {2} and offsetheight was {3}", pos.X, pos.Y, pos.Z, offsetHeight);
2336 2115
2337 SceneObjectPart rootPart = null; 2116 }
2338 try 2117 else
2339 { 2118 {
2340 rootPart = group.GetChildPart(group.UUID); 2119 group.SetFromAssetID(itemID);
2341 } 2120 }
2342 catch (NullReferenceException)
2343 {
2344 string isAttachment = "";
2345 2121
2346 if (attachment) 2122 SceneObjectPart rootPart = null;
2347 isAttachment = " Object was an attachment"; 2123 try
2124 {
2125 rootPart = group.GetChildPart(group.UUID);
2126 }
2127 catch (NullReferenceException)
2128 {
2129 string isAttachment = "";
2348 2130
2349 m_log.Error("[AGENT INVENTORY]: Error rezzing ItemID: " + itemID + " object has no rootpart." + isAttachment); 2131 if (attachment)
2350 } 2132 isAttachment = " Object was an attachment";
2351 2133
2352 // Since renaming the item in the inventory does not affect the name stored 2134 m_log.Error("[AGENT INVENTORY]: Error rezzing ItemID: " + itemID + " object has no rootpart." + isAttachment);
2353 // in the serialization, transfer the correct name from the inventory to the 2135 }
2354 // object itself before we rez.
2355 rootPart.Name = item.Name;
2356 rootPart.Description = item.Description;
2357 2136
2358 List<SceneObjectPart> partList = new List<SceneObjectPart>(group.Children.Values); 2137 // Since renaming the item in the inventory does not affect the name stored
2138 // in the serialization, transfer the correct name from the inventory to the
2139 // object itself before we rez.
2140 rootPart.Name = item.Name;
2141 rootPart.Description = item.Description;
2359 2142
2360 group.SetGroup(remoteClient.ActiveGroupId, remoteClient); 2143 List<SceneObjectPart> partList = new List<SceneObjectPart>(group.Children.Values);
2361 if (rootPart.OwnerID != item.Owner)
2362 {
2363 //Need to kill the for sale here
2364 rootPart.ObjectSaleType = 0;
2365 rootPart.SalePrice = 10;
2366 2144
2367 if (Permissions.PropagatePermissions()) 2145 group.SetGroup(remoteClient.ActiveGroupId, remoteClient);
2368 { 2146 if (rootPart.OwnerID != item.Owner)
2369 if ((item.CurrentPermissions & 8) != 0) 2147 {
2370 { 2148 //Need to kill the for sale here
2371 foreach (SceneObjectPart part in partList) 2149 rootPart.ObjectSaleType = 0;
2372 { 2150 rootPart.SalePrice = 10;
2373 part.EveryoneMask = item.EveryOnePermissions;
2374 part.NextOwnerMask = item.NextPermissions;
2375 part.GroupMask = 0; // DO NOT propagate here
2376 }
2377 }
2378 group.ApplyNextOwnerPermissions();
2379 }
2380 }
2381 2151
2382 foreach (SceneObjectPart part in partList) 2152 if (Permissions.PropagatePermissions())
2153 {
2154 if ((item.CurrentPermissions & 8) != 0)
2383 { 2155 {
2384 if (part.OwnerID != item.Owner) 2156 foreach (SceneObjectPart part in partList)
2385 {
2386 part.LastOwnerID = part.OwnerID;
2387 part.OwnerID = item.Owner;
2388 part.Inventory.ChangeInventoryOwner(item.Owner);
2389 }
2390 else if (((item.CurrentPermissions & 8) != 0) && (!attachment)) // Slam!
2391 { 2157 {
2392 part.EveryoneMask = item.EveryOnePermissions; 2158 part.EveryoneMask = item.EveryOnePermissions;
2393 part.NextOwnerMask = item.NextPermissions; 2159 part.NextOwnerMask = item.NextPermissions;
2394
2395 part.GroupMask = 0; // DO NOT propagate here 2160 part.GroupMask = 0; // DO NOT propagate here
2396 } 2161 }
2397 } 2162 }
2163 group.ApplyNextOwnerPermissions();
2164 }
2165 }
2398 2166
2399 rootPart.TrimPermissions(); 2167 foreach (SceneObjectPart part in partList)
2168 {
2169 if (part.OwnerID != item.Owner)
2170 {
2171 part.LastOwnerID = part.OwnerID;
2172 part.OwnerID = item.Owner;
2173 part.Inventory.ChangeInventoryOwner(item.Owner);
2174 }
2175 else if (((item.CurrentPermissions & 8) != 0) && (!attachment)) // Slam!
2176 {
2177 part.EveryoneMask = item.EveryOnePermissions;
2178 part.NextOwnerMask = item.NextPermissions;
2400 2179
2401 if (!attachment) 2180 part.GroupMask = 0; // DO NOT propagate here
2402 { 2181 }
2403 if (group.RootPart.Shape.PCode == (byte)PCode.Prim) 2182 }
2404 {
2405 group.ClearPartAttachmentData();
2406 }
2407 }
2408 2183
2409 if (!attachment) 2184 rootPart.TrimPermissions();
2410 {
2411 // Fire on_rez
2412 group.CreateScriptInstances(0, true, DefaultScriptEngine, 0);
2413 2185
2414 rootPart.ScheduleFullUpdate(); 2186 if (!attachment)
2415 } 2187 {
2188 if (group.RootPart.Shape.PCode == (byte)PCode.Prim)
2189 {
2190 group.ClearPartAttachmentData();
2191 }
2192 }
2416 2193
2417 if (!Permissions.BypassPermissions()) 2194 if (!attachment)
2418 { 2195 {
2419 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) 2196 // Fire on_rez
2420 { 2197 group.CreateScriptInstances(0, true, DefaultScriptEngine, 0);
2421 // If this is done on attachments, no 2198
2422 // copy ones will be lost, so avoid it 2199 rootPart.ScheduleFullUpdate();
2423 // 2200 }
2424 if (!attachment)
2425 userInfo.DeleteItem(item.ID);
2426 }
2427 }
2428 2201
2429 return rootPart.ParentGroup; 2202 if (!Permissions.BypassPermissions())
2203 {
2204 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
2205 {
2206 // If this is done on attachments, no
2207 // copy ones will be lost, so avoid it
2208 //
2209 if (!attachment)
2210 InventoryService.DeleteItem(item);
2430 } 2211 }
2431 } 2212 }
2213
2214 return rootPart.ParentGroup;
2432 } 2215 }
2433 else
2434 m_log.WarnFormat("[AGENT INVENTORY]: Root folder not found in {0}", RegionInfo.RegionName);
2435 } 2216 }
2436 else
2437 m_log.WarnFormat("[AGENT INVENTORY]: User profile not found in {0}", RegionInfo.RegionName);
2438 2217
2439 return null; 2218 return null;
2440 } 2219 }
@@ -2681,13 +2460,9 @@ namespace OpenSim.Region.Framework.Scenes
2681 ava.UpdateDatabase(remoteClient.AgentId, presence.Appearance); 2460 ava.UpdateDatabase(remoteClient.AgentId, presence.Appearance);
2682 } 2461 }
2683 part.ParentGroup.DetachToGround(); 2462 part.ParentGroup.DetachToGround();
2684 CachedUserInfo userInfo = 2463
2685 CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId); 2464 InventoryService.DeleteItem(new InventoryItemBase(inventoryID));
2686 if (userInfo != null) 2465 remoteClient.SendRemoveInventoryItem(inventoryID);
2687 {
2688 userInfo.DeleteItem(inventoryID);
2689 remoteClient.SendRemoveInventoryItem(inventoryID);
2690 }
2691 } 2466 }
2692 SendAttachEvent(part.ParentGroup.LocalId, itemID, UUID.Zero); 2467 SendAttachEvent(part.ParentGroup.LocalId, itemID, UUID.Zero);
2693 } 2468 }
diff --git a/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs
index 113918d..ba858ed 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs
@@ -435,17 +435,7 @@ namespace OpenSim.Region.Framework.Scenes
435 return; 435 return;
436 } 436 }
437 437
438 CachedUserInfo userProfile = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId); 438 SendInventoryUpdate(remoteClient, new InventoryFolderBase(folderID), fetchFolders, fetchItems);
439
440 if (null == userProfile)
441 {
442 m_log.ErrorFormat(
443 "[AGENT INVENTORY]: Could not find user profile for {0} {1}",
444 remoteClient.Name, remoteClient.AgentId);
445 return;
446 }
447
448 userProfile.SendInventoryDecendents(remoteClient, folderID, fetchFolders, fetchItems);
449 } 439 }
450 440
451 /// <summary> 441 /// <summary>
@@ -543,19 +533,10 @@ namespace OpenSim.Region.Framework.Scenes
543 public void HandleCreateInventoryFolder(IClientAPI remoteClient, UUID folderID, ushort folderType, 533 public void HandleCreateInventoryFolder(IClientAPI remoteClient, UUID folderID, ushort folderType,
544 string folderName, UUID parentID) 534 string folderName, UUID parentID)
545 { 535 {
546 CachedUserInfo userProfile = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId); 536 InventoryFolderBase folder = new InventoryFolderBase(folderID, folderName, remoteClient.AgentId, (short)folderType, parentID, 1);
547 537 if (!InventoryService.AddFolder(folder))
548 if (null == userProfile)
549 {
550 m_log.ErrorFormat(
551 "[AGENT INVENTORY]: Could not find user profile for {0} {1}",
552 remoteClient.Name, remoteClient.AgentId);
553 return;
554 }
555
556 if (!userProfile.CreateFolder(folderName, folderID, folderType, parentID))
557 { 538 {
558 m_log.ErrorFormat( 539 m_log.WarnFormat(
559 "[AGENT INVENTORY]: Failed to move create folder for user {0} {1}", 540 "[AGENT INVENTORY]: Failed to move create folder for user {0} {1}",
560 remoteClient.Name, remoteClient.AgentId); 541 remoteClient.Name, remoteClient.AgentId);
561 } 542 }
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 919075c..0c99166 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -3510,59 +3510,53 @@ namespace OpenSim.Region.Framework.Scenes
3510 case 2: // Sell a copy 3510 case 2: // Sell a copy
3511 string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(group); 3511 string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(group);
3512 3512
3513 CachedUserInfo userInfo = 3513 uint perms=group.GetEffectivePermissions();
3514 CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
3515 3514
3516 if (userInfo != null) 3515 if ((perms & (uint)PermissionMask.Transfer) == 0)
3517 { 3516 {
3518 uint perms=group.GetEffectivePermissions(); 3517 m_dialogModule.SendAlertToUser(remoteClient, "This item doesn't appear to be for sale");
3519 3518 return false;
3520 if ((perms & (uint)PermissionMask.Transfer) == 0) 3519 }
3521 {
3522 m_dialogModule.SendAlertToUser(remoteClient, "This item doesn't appear to be for sale");
3523 return false;
3524 }
3525 3520
3526 AssetBase asset = CreateAsset( 3521 AssetBase asset = CreateAsset(
3527 group.GetPartName(localID), 3522 group.GetPartName(localID),
3528 group.GetPartDescription(localID), 3523 group.GetPartDescription(localID),
3529 (sbyte)AssetType.Object, 3524 (sbyte)AssetType.Object,
3530 Utils.StringToBytes(sceneObjectXml)); 3525 Utils.StringToBytes(sceneObjectXml));
3531 AssetService.Store(asset); 3526 AssetService.Store(asset);
3532 3527
3533 InventoryItemBase item = new InventoryItemBase(); 3528 InventoryItemBase item = new InventoryItemBase();
3534 item.CreatorId = part.CreatorID.ToString(); 3529 item.CreatorId = part.CreatorID.ToString();
3535 3530
3536 item.ID = UUID.Random(); 3531 item.ID = UUID.Random();
3537 item.Owner = remoteClient.AgentId; 3532 item.Owner = remoteClient.AgentId;
3538 item.AssetID = asset.FullID; 3533 item.AssetID = asset.FullID;
3539 item.Description = asset.Description; 3534 item.Description = asset.Description;
3540 item.Name = asset.Name; 3535 item.Name = asset.Name;
3541 item.AssetType = asset.Type; 3536 item.AssetType = asset.Type;
3542 item.InvType = (int)InventoryType.Object; 3537 item.InvType = (int)InventoryType.Object;
3543 item.Folder = categoryID; 3538 item.Folder = categoryID;
3544 3539
3545 uint nextPerms=(perms & 7) << 13; 3540 uint nextPerms=(perms & 7) << 13;
3546 if ((nextPerms & (uint)PermissionMask.Copy) == 0) 3541 if ((nextPerms & (uint)PermissionMask.Copy) == 0)
3547 perms &= ~(uint)PermissionMask.Copy; 3542 perms &= ~(uint)PermissionMask.Copy;
3548 if ((nextPerms & (uint)PermissionMask.Transfer) == 0) 3543 if ((nextPerms & (uint)PermissionMask.Transfer) == 0)
3549 perms &= ~(uint)PermissionMask.Transfer; 3544 perms &= ~(uint)PermissionMask.Transfer;
3550 if ((nextPerms & (uint)PermissionMask.Modify) == 0) 3545 if ((nextPerms & (uint)PermissionMask.Modify) == 0)
3551 perms &= ~(uint)PermissionMask.Modify; 3546 perms &= ~(uint)PermissionMask.Modify;
3552 3547
3553 item.BasePermissions = perms & part.NextOwnerMask; 3548 item.BasePermissions = perms & part.NextOwnerMask;
3554 item.CurrentPermissions = perms & part.NextOwnerMask; 3549 item.CurrentPermissions = perms & part.NextOwnerMask;
3555 item.NextPermissions = part.NextOwnerMask; 3550 item.NextPermissions = part.NextOwnerMask;
3556 item.EveryOnePermissions = part.EveryoneMask & 3551 item.EveryOnePermissions = part.EveryoneMask &
3557 part.NextOwnerMask; 3552 part.NextOwnerMask;
3558 item.GroupPermissions = part.GroupMask & 3553 item.GroupPermissions = part.GroupMask &
3559 part.NextOwnerMask; 3554 part.NextOwnerMask;
3560 item.CurrentPermissions |= 8; // Slam! 3555 item.CurrentPermissions |= 8; // Slam!
3561 item.CreationDate = Util.UnixTimeSinceEpoch(); 3556 item.CreationDate = Util.UnixTimeSinceEpoch();
3562 3557
3563 userInfo.AddItem(item); 3558 if (InventoryService.AddItem(item))
3564 remoteClient.SendInventoryItemCreateUpdate(item, 0); 3559 remoteClient.SendInventoryItemCreateUpdate(item, 0);
3565 }
3566 else 3560 else
3567 { 3561 {
3568 m_dialogModule.SendAlertToUser(remoteClient, "Cannot buy now. Your inventory is unavailable"); 3562 m_dialogModule.SendAlertToUser(remoteClient, "Cannot buy now. Your inventory is unavailable");
@@ -3577,8 +3571,8 @@ namespace OpenSim.Region.Framework.Scenes
3577 3571
3578 foreach (UUID invID in invList) 3572 foreach (UUID invID in invList)
3579 { 3573 {
3580 TaskInventoryItem item = part.Inventory.GetInventoryItem(invID); 3574 TaskInventoryItem item1 = part.Inventory.GetInventoryItem(invID);
3581 if ((item.CurrentPermissions & 3575 if ((item1.CurrentPermissions &
3582 (uint)PermissionMask.Transfer) == 0) 3576 (uint)PermissionMask.Transfer) == 0)
3583 { 3577 {
3584 okToSell = false; 3578 okToSell = false;
diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
index 0e0999a..9599379 100644
--- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
@@ -542,7 +542,7 @@ namespace OpenSim.Region.Framework.Scenes
542 group.DetachToInventoryPrep(); 542 group.DetachToInventoryPrep();
543 m_log.Debug("[DETACH]: Saving attachpoint: " + 543 m_log.Debug("[DETACH]: Saving attachpoint: " +
544 ((uint)group.GetAttachmentPoint()).ToString()); 544 ((uint)group.GetAttachmentPoint()).ToString());
545 m_parentScene.updateKnownAsset(remoteClient, group, 545 m_parentScene.UpdateKnownItem(remoteClient, group,
546 group.GetFromAssetID(), group.OwnerID); 546 group.GetFromAssetID(), group.OwnerID);
547 m_parentScene.DeleteSceneObject(group, false); 547 m_parentScene.DeleteSceneObject(group, false);
548 return; 548 return;
@@ -1307,7 +1307,7 @@ namespace OpenSim.Region.Framework.Scenes
1307 group.UpdateGroupPosition(pos); 1307 group.UpdateGroupPosition(pos);
1308 group.RootPart.IsAttachment = false; 1308 group.RootPart.IsAttachment = false;
1309 group.AbsolutePosition = group.RootPart.AttachedPos; 1309 group.AbsolutePosition = group.RootPart.AttachedPos;
1310 m_parentScene.updateKnownAsset(remoteClient, group, group.GetFromAssetID(), group.OwnerID); 1310 m_parentScene.UpdateKnownItem(remoteClient, group, group.GetFromAssetID(), group.OwnerID);
1311 group.SetAttachmentPoint(attachmentPoint); 1311 group.SetAttachmentPoint(attachmentPoint);
1312 1312
1313 } 1313 }