From 52d92303926c8be46af734707274e6d8ecd70602 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 15 Apr 2011 22:47:47 +0100
Subject: refactor: split out some rez code into a separate
CreateItemForObject() method
---
.../InventoryAccess/InventoryAccessModule.cs | 302 +++++++++++----------
1 file changed, 159 insertions(+), 143 deletions(-)
(limited to 'OpenSim')
diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs
index c0946f4..0f2b9a6 100644
--- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs
@@ -274,154 +274,22 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
foreach (SceneObjectGroup objectGroup in objlist)
objectGroup.AbsolutePosition = originalPositions[objectGroup.UUID];
- // Get the user info of the item destination
- //
- UUID userID = UUID.Zero;
-
- if (action == DeRezAction.Take || action == DeRezAction.TakeCopy ||
- action == DeRezAction.SaveToExistingUserInventoryItem)
- {
- // Take or take copy require a taker
- // Saving changes requires a local user
- //
- if (remoteClient == null)
- return UUID.Zero;
-
- userID = remoteClient.AgentId;
- }
- else
- {
- // All returns / deletes go to the object owner
- //
- userID = objlist[0].RootPart.OwnerID;
- }
-
- if (userID == UUID.Zero) // Can't proceed
- {
+ InventoryItemBase item = CreateItemForObject(action, remoteClient, objlist[0], folderID);
+ if (item == null)
return UUID.Zero;
- }
-
- // If we're returning someone's item, it goes back to the
- // owner's Lost And Found folder.
- // Delete is treated like return in this case
- // Deleting your own items makes them go to trash
- //
-
- InventoryFolderBase folder = null;
- InventoryItemBase item = null;
-
- if (DeRezAction.SaveToExistingUserInventoryItem == action)
+
+ // Can't know creator is the same, so null it in inventory
+ if (objlist.Count > 1)
{
- item = new InventoryItemBase(objlist[0].RootPart.FromUserInventoryItemID, userID);
- item = m_Scene.InventoryService.GetItem(item);
-
- //item = userInfo.RootFolder.FindItem(
- // objectGroup.RootPart.FromUserInventoryItemID);
-
- if (null == item)
- {
- m_log.DebugFormat(
- "[AGENT INVENTORY]: Object {0} {1} scheduled for save to inventory has already been deleted.",
- objlist[0].Name, objlist[0].UUID);
- return UUID.Zero;
- }
+ item.CreatorId = UUID.Zero.ToString();
+ item.Flags = (uint)InventoryItemFlags.ObjectHasMultipleItems;
}
else
{
- // Folder magic
- //
- if (action == DeRezAction.Delete)
- {
- // Deleting someone else's item
- //
- if (remoteClient == null ||
- objlist[0].OwnerID != remoteClient.AgentId)
- {
-
- folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder);
- }
- else
- {
- folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.TrashFolder);
- }
- }
- else if (action == DeRezAction.Return)
- {
-
- // Dump to lost + found unconditionally
- //
- folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder);
- }
-
- if (folderID == UUID.Zero && folder == null)
- {
- if (action == DeRezAction.Delete)
- {
- // Deletes go to trash by default
- //
- folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.TrashFolder);
- }
- else
- {
- if (remoteClient == null ||
- objlist[0].OwnerID != remoteClient.AgentId)
- {
- // Taking copy of another person's item. Take to
- // Objects folder.
- folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.Object);
- }
- else
- {
- // Catch all. Use lost & found
- //
-
- folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder);
- }
- }
- }
-
- // Override and put into where it came from, if it came
- // from anywhere in inventory
- //
- if (action == DeRezAction.Take || action == DeRezAction.TakeCopy)
- {
- if (objlist[0].RootPart.FromFolderID != UUID.Zero)
- {
- InventoryFolderBase f = new InventoryFolderBase(objlist[0].RootPart.FromFolderID, userID);
- folder = m_Scene.InventoryService.GetFolder(f);
- }
- }
-
- if (folder == null) // None of the above
- {
- folder = new InventoryFolderBase(folderID);
-
- if (folder == null) // Nowhere to put it
- {
- return UUID.Zero;
- }
- }
-
- item = new InventoryItemBase();
- // Can't know creator is the same, so null it in inventory
- if (objlist.Count > 1)
- item.CreatorId = UUID.Zero.ToString();
- else
- item.CreatorId = objlist[0].RootPart.CreatorID.ToString();
- item.ID = UUID.Random();
- item.InvType = (int)InventoryType.Object;
- item.Folder = folder.ID;
- item.Owner = userID;
- if (objlist.Count > 1)
- {
- item.Flags = (uint)InventoryItemFlags.ObjectHasMultipleItems;
- }
- else
- {
- item.SaleType = objlist[0].RootPart.ObjectSaleType;
- item.SalePrice = objlist[0].RootPart.SalePrice;
- }
- }
+ item.CreatorId = objlist[0].RootPart.CreatorID.ToString();
+ item.SaleType = objlist[0].RootPart.ObjectSaleType;
+ item.SalePrice = objlist[0].RootPart.SalePrice;
+ }
AssetBase asset = CreateAsset(
objlist[0].GetPartName(objlist[0].RootPart.LocalId),
@@ -505,8 +373,156 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
}
}
}
+
return assetID;
}
+
+ ///
+ /// Create an item using details for the given scene object.
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ protected InventoryItemBase CreateItemForObject(
+ DeRezAction action, IClientAPI remoteClient, SceneObjectGroup so, UUID folderID)
+ {
+ // Get the user info of the item destination
+ //
+ UUID userID = UUID.Zero;
+
+ if (action == DeRezAction.Take || action == DeRezAction.TakeCopy ||
+ action == DeRezAction.SaveToExistingUserInventoryItem)
+ {
+ // Take or take copy require a taker
+ // Saving changes requires a local user
+ //
+ if (remoteClient == null)
+ return null;
+
+ userID = remoteClient.AgentId;
+ }
+ else
+ {
+ // All returns / deletes go to the object owner
+ //
+ userID = so.RootPart.OwnerID;
+ }
+
+ if (userID == UUID.Zero) // Can't proceed
+ {
+ return null;
+ }
+
+ // If we're returning someone's item, it goes back to the
+ // owner's Lost And Found folder.
+ // Delete is treated like return in this case
+ // Deleting your own items makes them go to trash
+ //
+
+ InventoryFolderBase folder = null;
+ InventoryItemBase item = null;
+
+ if (DeRezAction.SaveToExistingUserInventoryItem == action)
+ {
+ item = new InventoryItemBase(so.RootPart.FromUserInventoryItemID, userID);
+ item = m_Scene.InventoryService.GetItem(item);
+
+ //item = userInfo.RootFolder.FindItem(
+ // objectGroup.RootPart.FromUserInventoryItemID);
+
+ if (null == item)
+ {
+ m_log.DebugFormat(
+ "[AGENT INVENTORY]: Object {0} {1} scheduled for save to inventory has already been deleted.",
+ so.Name, so.UUID);
+
+ return null;
+ }
+ }
+ else
+ {
+ // Folder magic
+ //
+ if (action == DeRezAction.Delete)
+ {
+ // Deleting someone else's item
+ //
+ if (remoteClient == null ||
+ so.OwnerID != remoteClient.AgentId)
+ {
+ folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder);
+ }
+ else
+ {
+ folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.TrashFolder);
+ }
+ }
+ else if (action == DeRezAction.Return)
+ {
+ // Dump to lost + found unconditionally
+ //
+ folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder);
+ }
+
+ if (folderID == UUID.Zero && folder == null)
+ {
+ if (action == DeRezAction.Delete)
+ {
+ // Deletes go to trash by default
+ //
+ folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.TrashFolder);
+ }
+ else
+ {
+ if (remoteClient == null || so.OwnerID != remoteClient.AgentId)
+ {
+ // Taking copy of another person's item. Take to
+ // Objects folder.
+ folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.Object);
+ }
+ else
+ {
+ // Catch all. Use lost & found
+ //
+
+ folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder);
+ }
+ }
+ }
+
+ // Override and put into where it came from, if it came
+ // from anywhere in inventory
+ //
+ if (action == DeRezAction.Take || action == DeRezAction.TakeCopy)
+ {
+ if (so.RootPart.FromFolderID != UUID.Zero)
+ {
+ InventoryFolderBase f = new InventoryFolderBase(so.RootPart.FromFolderID, userID);
+ folder = m_Scene.InventoryService.GetFolder(f);
+ }
+ }
+
+ if (folder == null) // None of the above
+ {
+ folder = new InventoryFolderBase(folderID);
+
+ if (folder == null) // Nowhere to put it
+ {
+ return null;
+ }
+ }
+
+ item = new InventoryItemBase();
+ item.ID = UUID.Random();
+ item.InvType = (int)InventoryType.Object;
+ item.Folder = folder.ID;
+ item.Owner = userID;
+ }
+
+ return item;
+ }
///
/// Rez an object into the scene from the user's inventory
--
cgit v1.1