From 46c6c35d4868e4ff538bdc2c65a7fade936c0ce1 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Wed, 25 Aug 2010 22:46:49 +0100
Subject: refactor: Push item retrieval and fixing part of Scene.RezObject()
 down into SceneObjectPartInventory

---
 .../Framework/Interfaces/IEntityInventory.cs       | 12 ++++
 OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | 59 ++-----------------
 .../Framework/Scenes/SceneObjectPartInventory.cs   | 66 +++++++++++++++++++++-
 3 files changed, 82 insertions(+), 55 deletions(-)

diff --git a/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs b/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs
index fd43923..ae2e844 100644
--- a/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs
+++ b/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs
@@ -29,6 +29,7 @@ using System.Collections.Generic;
 using System.Collections;
 using OpenMetaverse;
 using OpenSim.Framework;
+using OpenSim.Region.Framework.Scenes;
 
 namespace OpenSim.Region.Framework.Interfaces
 {
@@ -153,6 +154,17 @@ namespace OpenSim.Region.Framework.Interfaces
         /// If no inventory item has that name then an empty list is returned.
         /// </returns>
         IList<TaskInventoryItem> GetInventoryItems(string name);
+        
+        /// <summary>
+        /// Get the scene object referenced by an inventory item.
+        /// </summary>
+        /// 
+        /// This is returned in a 'rez ready' state.  That is, name, description, permissions and other details have
+        /// been adjusted to reflect the part and item from which it originates.
+        /// 
+        /// <param name="item"></param>
+        /// <returns>The scene object.  Null if the scene object asset couldn't be found</returns>
+        SceneObjectGroup GetRezReadySceneObject(TaskInventoryItem item);
 
         /// <summary>
         /// Update an existing inventory item.
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
index 01be491..9fef8f4 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
@@ -1969,60 +1969,13 @@ namespace OpenSim.Region.Framework.Scenes
             if (null == item)
                 return null;
             
-            UUID ownerID = item.OwnerID;
-            AssetBase rezAsset = AssetService.Get(item.AssetID.ToString());
-
-            if (null == rezAsset)
-                return null;
-
-            string xmlData = Utils.BytesToString(rezAsset.Data);
-            SceneObjectGroup group = SceneObjectSerializer.FromOriginalXmlFormat(xmlData);
-
-            if (!Permissions.CanRezObject(group.Children.Count, ownerID, pos))
+            SceneObjectGroup group = sourcePart.Inventory.GetRezReadySceneObject(item);
+            
+            if (null == group)
                 return null;
-
-            group.ResetIDs();
-
-            SceneObjectPart rootPart = group.GetChildPart(group.UUID);
-
-            // Since renaming the item in the inventory does not affect the name stored
-            // in the serialization, transfer the correct name from the inventory to the
-            // object itself before we rez.
-            rootPart.Name = item.Name;
-            rootPart.Description = item.Description;
-
-            List<SceneObjectPart> partList = new List<SceneObjectPart>(group.Children.Values);
-
-            group.SetGroup(sourcePart.GroupID, null);
-
-            if ((rootPart.OwnerID != item.OwnerID) || (item.CurrentPermissions & 16) != 0)
-            {
-                if (Permissions.PropagatePermissions())
-                {
-                    foreach (SceneObjectPart part in partList)
-                    {
-                        part.EveryoneMask = item.EveryonePermissions;
-                        part.NextOwnerMask = item.NextPermissions;
-                    }
-                    
-                    group.ApplyNextOwnerPermissions();
-                }
-            }
-
-            foreach (SceneObjectPart part in partList)
-            {
-                if ((part.OwnerID != item.OwnerID) || (item.CurrentPermissions & 16) != 0)
-                {
-                    part.LastOwnerID = part.OwnerID;
-                    part.OwnerID = item.OwnerID;
-                    part.Inventory.ChangeInventoryOwner(item.OwnerID);
-                }
-                
-                part.EveryoneMask = item.EveryonePermissions;
-                part.NextOwnerMask = item.NextPermissions;
-            }
             
-            rootPart.TrimPermissions();                        
+            if (!Permissions.CanRezObject(group.Children.Count, item.OwnerID, pos))
+                return null;            
 
             if (!Permissions.BypassPermissions())
             {
@@ -2038,7 +1991,7 @@ namespace OpenSim.Region.Framework.Scenes
             
             group.ScheduleGroupForFullUpdate();
         
-            return rootPart.ParentGroup;
+            return group;
         }
 
         public virtual bool returnObjects(SceneObjectGroup[] returnobjects, UUID AgentId)
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
index 4ae53a2..84b7365 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
@@ -37,6 +37,7 @@ using log4net;
 using OpenSim.Framework;
 using OpenSim.Region.Framework.Interfaces;
 using OpenSim.Region.Framework.Scenes.Scripting;
+using OpenSim.Region.Framework.Scenes.Serialization;
 
 namespace OpenSim.Region.Framework.Scenes
 {
@@ -574,6 +575,68 @@ namespace OpenSim.Region.Framework.Scenes
             return items;
         }
         
+        public SceneObjectGroup GetRezReadySceneObject(TaskInventoryItem item)
+        {            
+            UUID ownerID = item.OwnerID;
+            AssetBase rezAsset = m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString());
+
+            if (null == rezAsset)
+            {
+                m_log.WarnFormat(
+                    "[PRIM INVENTORY]: Could not find asset {0} for inventory item {1} in {2}", 
+                    item.AssetID, item.Name, m_part.Name);
+                return null;
+            }
+
+            string xmlData = Utils.BytesToString(rezAsset.Data);
+            SceneObjectGroup group = SceneObjectSerializer.FromOriginalXmlFormat(xmlData);
+
+            group.ResetIDs();
+
+            SceneObjectPart rootPart = group.GetChildPart(group.UUID);
+
+            // Since renaming the item in the inventory does not affect the name stored
+            // in the serialization, transfer the correct name from the inventory to the
+            // object itself before we rez.
+            rootPart.Name = item.Name;
+            rootPart.Description = item.Description;
+
+            List<SceneObjectPart> partList = new List<SceneObjectPart>(group.Children.Values);
+
+            group.SetGroup(m_part.GroupID, null);
+
+            if ((rootPart.OwnerID != item.OwnerID) || (item.CurrentPermissions & 16) != 0)
+            {
+                if (m_part.ParentGroup.Scene.Permissions.PropagatePermissions())
+                {
+                    foreach (SceneObjectPart part in partList)
+                    {
+                        part.EveryoneMask = item.EveryonePermissions;
+                        part.NextOwnerMask = item.NextPermissions;
+                    }
+                    
+                    group.ApplyNextOwnerPermissions();
+                }
+            }
+
+            foreach (SceneObjectPart part in partList)
+            {
+                if ((part.OwnerID != item.OwnerID) || (item.CurrentPermissions & 16) != 0)
+                {
+                    part.LastOwnerID = part.OwnerID;
+                    part.OwnerID = item.OwnerID;
+                    part.Inventory.ChangeInventoryOwner(item.OwnerID);
+                }
+                
+                part.EveryoneMask = item.EveryonePermissions;
+                part.NextOwnerMask = item.NextPermissions;
+            }
+            
+            rootPart.TrimPermissions(); 
+            
+            return group;
+        }
+        
         /// <summary>
         /// Update an existing inventory item.
         /// </summary>
@@ -1029,6 +1092,5 @@ namespace OpenSim.Region.Framework.Scenes
                 }  
             }
         }
-
     }
-}
+}
\ No newline at end of file
-- 
cgit v1.1