From 2de3a1b9dad25855cb18a29f2c43ad67cfb0730c Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 25 Jan 2012 23:22:07 +0000 Subject: refactor: decompose most of RezScript() into RezScriptFromAgentInventory(), RezNewScript() and rename one RezScript() to RezScriptFromPrim() --- OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | 174 +++++++++++---------- 1 file changed, 95 insertions(+), 79 deletions(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index 2444367..f4f37ac 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -1560,104 +1560,120 @@ namespace OpenSim.Region.Framework.Scenes /// Rez a script into a prim's inventory, either ex nihilo or from an existing avatar inventory /// </summary> /// <param name="remoteClient"></param> - /// <param name="itemID"> </param> + /// <param name="itemBase"> </param> + /// <param name="transactionID"></param> /// <param name="localID"></param> public void RezScript(IClientAPI remoteClient, InventoryItemBase itemBase, UUID transactionID, uint localID) { - UUID itemID = itemBase.ID; + if (itemBase.ID != UUID.Zero) + RezScriptFromAgentInventory(remoteClient, itemBase.ID, localID); + else + RezNewScript(remoteClient, itemBase); + } + + /// <summary> + /// Rez a script into a prim from an agent inventory. + /// </summary> + /// <param name="remoteClient"></param> + /// <param name="fromItemID"></param> + /// <param name="localID"></param> + public void RezScriptFromAgentInventory(IClientAPI remoteClient, UUID fromItemID, uint localID) + { UUID copyID = UUID.Random(); + InventoryItemBase item = new InventoryItemBase(fromItemID, remoteClient.AgentId); + item = InventoryService.GetItem(item); - if (itemID != UUID.Zero) // transferred from an avatar inventory to the prim's inventory + // Try library + // XXX clumsy, possibly should be one call + if (null == item && LibraryService != null && LibraryService.LibraryRootFolder != null) { - InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId); - item = InventoryService.GetItem(item); - - // Try library - // XXX clumsy, possibly should be one call - if (null == item && LibraryService != null && LibraryService.LibraryRootFolder != null) - { - item = LibraryService.LibraryRootFolder.FindItem(itemID); - } + item = LibraryService.LibraryRootFolder.FindItem(fromItemID); + } - if (item != null) + if (item != null) + { + SceneObjectPart part = GetSceneObjectPart(localID); + if (part != null) { - SceneObjectPart part = GetSceneObjectPart(localID); - if (part != null) - { - if (!Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId)) - return; + if (!Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId)) + return; - part.ParentGroup.AddInventoryItem(remoteClient, localID, item, copyID); - // TODO: switch to posting on_rez here when scripts - // have state in inventory - part.Inventory.CreateScriptInstance(copyID, 0, false, DefaultScriptEngine, 0); + part.ParentGroup.AddInventoryItem(remoteClient, localID, item, copyID); + // TODO: switch to posting on_rez here when scripts + // have state in inventory + part.Inventory.CreateScriptInstance(copyID, 0, false, DefaultScriptEngine, 0); - // m_log.InfoFormat("[PRIMINVENTORY]: " + - // "Rezzed script {0} into prim local ID {1} for user {2}", - // item.inventoryName, localID, remoteClient.Name); - part.SendPropertiesToClient(remoteClient); - part.ParentGroup.ResumeScripts(); - } - else - { - m_log.ErrorFormat( - "[PRIM INVENTORY]: " + - "Could not rez script {0} into prim local ID {1} for user {2}" - + " because the prim could not be found in the region!", - item.Name, localID, remoteClient.Name); - } + // m_log.InfoFormat("[PRIMINVENTORY]: " + + // "Rezzed script {0} into prim local ID {1} for user {2}", + // item.inventoryName, localID, remoteClient.Name); + part.SendPropertiesToClient(remoteClient); + part.ParentGroup.ResumeScripts(); } else { m_log.ErrorFormat( - "[PRIM INVENTORY]: Could not find script inventory item {0} to rez for {1}!", - itemID, remoteClient.Name); + "[PRIM INVENTORY]: " + + "Could not rez script {0} into prim local ID {1} for user {2}" + + " because the prim could not be found in the region!", + item.Name, localID, remoteClient.Name); } } - else // script has been rezzed directly into a prim's inventory + else { - SceneObjectPart part = GetSceneObjectPart(itemBase.Folder); - if (part == null) - return; + m_log.ErrorFormat( + "[PRIM INVENTORY]: Could not find script inventory item {0} to rez for {1}!", + fromItemID, remoteClient.Name); + } + } - if (!Permissions.CanCreateObjectInventory( - itemBase.InvType, part.UUID, remoteClient.AgentId)) - return; + /// <summary> + /// Rez a new script from nothing. + /// </summary> + /// <param name="remoteClient"></param> + /// <param name="itemBase"></param> + public void RezNewScript(IClientAPI remoteClient, InventoryItemBase itemBase) + { + SceneObjectPart part = GetSceneObjectPart(itemBase.Folder); + if (part == null) + return; - AssetBase asset = CreateAsset(itemBase.Name, itemBase.Description, (sbyte)itemBase.AssetType, - Encoding.ASCII.GetBytes("default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}"), - remoteClient.AgentId); - AssetService.Store(asset); - - TaskInventoryItem taskItem = new TaskInventoryItem(); - - taskItem.ResetIDs(itemBase.Folder); - taskItem.ParentID = itemBase.Folder; - taskItem.CreationDate = (uint)itemBase.CreationDate; - taskItem.Name = itemBase.Name; - taskItem.Description = itemBase.Description; - taskItem.Type = itemBase.AssetType; - taskItem.InvType = itemBase.InvType; - taskItem.OwnerID = itemBase.Owner; - taskItem.CreatorID = itemBase.CreatorIdAsUuid; - taskItem.BasePermissions = itemBase.BasePermissions; - taskItem.CurrentPermissions = itemBase.CurrentPermissions; - taskItem.EveryonePermissions = itemBase.EveryOnePermissions; - taskItem.GroupPermissions = itemBase.GroupPermissions; - taskItem.NextPermissions = itemBase.NextPermissions; - taskItem.GroupID = itemBase.GroupID; - taskItem.GroupPermissions = 0; - taskItem.Flags = itemBase.Flags; - taskItem.PermsGranter = UUID.Zero; - taskItem.PermsMask = 0; - taskItem.AssetID = asset.FullID; - - part.Inventory.AddInventoryItem(taskItem, false); - part.SendPropertiesToClient(remoteClient); + if (!Permissions.CanCreateObjectInventory( + itemBase.InvType, part.UUID, remoteClient.AgentId)) + return; - part.Inventory.CreateScriptInstance(taskItem, 0, false, DefaultScriptEngine, 0); - part.ParentGroup.ResumeScripts(); - } + AssetBase asset = CreateAsset(itemBase.Name, itemBase.Description, (sbyte)itemBase.AssetType, + Encoding.ASCII.GetBytes("default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}"), + remoteClient.AgentId); + AssetService.Store(asset); + + TaskInventoryItem taskItem = new TaskInventoryItem(); + + taskItem.ResetIDs(itemBase.Folder); + taskItem.ParentID = itemBase.Folder; + taskItem.CreationDate = (uint)itemBase.CreationDate; + taskItem.Name = itemBase.Name; + taskItem.Description = itemBase.Description; + taskItem.Type = itemBase.AssetType; + taskItem.InvType = itemBase.InvType; + taskItem.OwnerID = itemBase.Owner; + taskItem.CreatorID = itemBase.CreatorIdAsUuid; + taskItem.BasePermissions = itemBase.BasePermissions; + taskItem.CurrentPermissions = itemBase.CurrentPermissions; + taskItem.EveryonePermissions = itemBase.EveryOnePermissions; + taskItem.GroupPermissions = itemBase.GroupPermissions; + taskItem.NextPermissions = itemBase.NextPermissions; + taskItem.GroupID = itemBase.GroupID; + taskItem.GroupPermissions = 0; + taskItem.Flags = itemBase.Flags; + taskItem.PermsGranter = UUID.Zero; + taskItem.PermsMask = 0; + taskItem.AssetID = asset.FullID; + + part.Inventory.AddInventoryItem(taskItem, false); + part.SendPropertiesToClient(remoteClient); + + part.Inventory.CreateScriptInstance(taskItem, 0, false, DefaultScriptEngine, 0); + part.ParentGroup.ResumeScripts(); } /// <summary> @@ -1666,7 +1682,7 @@ namespace OpenSim.Region.Framework.Scenes /// <param name="remoteClient"></param> /// <param name="itemID"> </param> /// <param name="localID"></param> - public void RezScript(UUID srcId, SceneObjectPart srcPart, UUID destId, int pin, int running, int start_param) + public void RezScriptFromPrim(UUID srcId, SceneObjectPart srcPart, UUID destId, int pin, int running, int start_param) { TaskInventoryItem srcTaskItem = srcPart.Inventory.GetInventoryItem(srcId); -- cgit v1.1 From 55c6cbabfd04599030548983f376f60acdf607e7 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 26 Jan 2012 00:10:37 +0000 Subject: refactor: change RezScriptFromAgentInventory(), RezNewScript() and AddInventoryItem() to accept an agent id rather than a full IClientAPI. This stops some code having to make spurious client == null checks and reduces regression test complexity. --- OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | 50 +++++++++++++--------- .../Framework/Scenes/SceneObjectGroup.Inventory.cs | 15 ++----- 2 files changed, 34 insertions(+), 31 deletions(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index f4f37ac..9293aeb 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -1444,7 +1444,7 @@ namespace OpenSim.Region.Framework.Scenes // If we've found the item in the user's inventory or in the library if (item != null) { - part.ParentGroup.AddInventoryItem(remoteClient, primLocalID, item, copyID); + part.ParentGroup.AddInventoryItem(remoteClient.AgentId, primLocalID, item, copyID); m_log.InfoFormat( "[PRIM INVENTORY]: Update with item {0} requested of prim {1} for {2}", item.Name, primLocalID, remoteClient.Name); @@ -1565,22 +1565,28 @@ namespace OpenSim.Region.Framework.Scenes /// <param name="localID"></param> public void RezScript(IClientAPI remoteClient, InventoryItemBase itemBase, UUID transactionID, uint localID) { + SceneObjectPart partWhereRezzed; + if (itemBase.ID != UUID.Zero) - RezScriptFromAgentInventory(remoteClient, itemBase.ID, localID); + partWhereRezzed = RezScriptFromAgentInventory(remoteClient.AgentId, itemBase.ID, localID); else - RezNewScript(remoteClient, itemBase); + partWhereRezzed = RezNewScript(remoteClient.AgentId, itemBase); + + if (partWhereRezzed != null) + partWhereRezzed.SendPropertiesToClient(remoteClient); } /// <summary> /// Rez a script into a prim from an agent inventory. /// </summary> - /// <param name="remoteClient"></param> + /// <param name="agentID"></param> /// <param name="fromItemID"></param> /// <param name="localID"></param> - public void RezScriptFromAgentInventory(IClientAPI remoteClient, UUID fromItemID, uint localID) + /// <returns>The part where the script was rezzed if successful. False otherwise.</returns> + public SceneObjectPart RezScriptFromAgentInventory(UUID agentID, UUID fromItemID, uint localID) { UUID copyID = UUID.Random(); - InventoryItemBase item = new InventoryItemBase(fromItemID, remoteClient.AgentId); + InventoryItemBase item = new InventoryItemBase(fromItemID, agentID); item = InventoryService.GetItem(item); // Try library @@ -1595,10 +1601,10 @@ namespace OpenSim.Region.Framework.Scenes SceneObjectPart part = GetSceneObjectPart(localID); if (part != null) { - if (!Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId)) - return; + if (!Permissions.CanEditObjectInventory(part.UUID, agentID)) + return null; - part.ParentGroup.AddInventoryItem(remoteClient, localID, item, copyID); + part.ParentGroup.AddInventoryItem(agentID, localID, item, copyID); // TODO: switch to posting on_rez here when scripts // have state in inventory part.Inventory.CreateScriptInstance(copyID, 0, false, DefaultScriptEngine, 0); @@ -1606,8 +1612,9 @@ namespace OpenSim.Region.Framework.Scenes // m_log.InfoFormat("[PRIMINVENTORY]: " + // "Rezzed script {0} into prim local ID {1} for user {2}", // item.inventoryName, localID, remoteClient.Name); - part.SendPropertiesToClient(remoteClient); part.ParentGroup.ResumeScripts(); + + return part; } else { @@ -1615,15 +1622,17 @@ namespace OpenSim.Region.Framework.Scenes "[PRIM INVENTORY]: " + "Could not rez script {0} into prim local ID {1} for user {2}" + " because the prim could not be found in the region!", - item.Name, localID, remoteClient.Name); + item.Name, localID, agentID); } } else { m_log.ErrorFormat( "[PRIM INVENTORY]: Could not find script inventory item {0} to rez for {1}!", - fromItemID, remoteClient.Name); + fromItemID, agentID); } + + return null; } /// <summary> @@ -1631,19 +1640,20 @@ namespace OpenSim.Region.Framework.Scenes /// </summary> /// <param name="remoteClient"></param> /// <param name="itemBase"></param> - public void RezNewScript(IClientAPI remoteClient, InventoryItemBase itemBase) + /// <returns>The part where the script was rezzed if successful. False otherwise.</returns> + public SceneObjectPart RezNewScript(UUID agentID, InventoryItemBase itemBase) { + // The part ID is the folder ID! SceneObjectPart part = GetSceneObjectPart(itemBase.Folder); if (part == null) - return; + return null; - if (!Permissions.CanCreateObjectInventory( - itemBase.InvType, part.UUID, remoteClient.AgentId)) - return; + if (!Permissions.CanCreateObjectInventory(itemBase.InvType, part.UUID, agentID)) + return null; AssetBase asset = CreateAsset(itemBase.Name, itemBase.Description, (sbyte)itemBase.AssetType, Encoding.ASCII.GetBytes("default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}"), - remoteClient.AgentId); + agentID); AssetService.Store(asset); TaskInventoryItem taskItem = new TaskInventoryItem(); @@ -1670,10 +1680,10 @@ namespace OpenSim.Region.Framework.Scenes taskItem.AssetID = asset.FullID; part.Inventory.AddInventoryItem(taskItem, false); - part.SendPropertiesToClient(remoteClient); - part.Inventory.CreateScriptInstance(taskItem, 0, false, DefaultScriptEngine, 0); part.ParentGroup.ResumeScripts(); + + return part; } /// <summary> diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs index 905ecc9..f173c95 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs @@ -83,13 +83,12 @@ namespace OpenSim.Region.Framework.Scenes /// <summary> /// Add an inventory item from a user's inventory to a prim in this scene object. /// </summary> - /// <param name="remoteClient">The client adding the item.</param> + /// <param name="agentID">The agent adding the item.</param> /// <param name="localID">The local ID of the part receiving the add.</param> /// <param name="item">The user inventory item being added.</param> /// <param name="copyItemID">The item UUID that should be used by the new item.</param> /// <returns></returns> - public bool AddInventoryItem(IClientAPI remoteClient, uint localID, - InventoryItemBase item, UUID copyItemID) + public bool AddInventoryItem(UUID agentID, uint localID, InventoryItemBase item, UUID copyItemID) { // m_log.DebugFormat( // "[PRIM INVENTORY]: Adding inventory item {0} from {1} to part with local ID {2}", @@ -111,9 +110,7 @@ namespace OpenSim.Region.Framework.Scenes taskItem.Type = item.AssetType; taskItem.InvType = item.InvType; - if (remoteClient != null && - remoteClient.AgentId != part.OwnerID && - m_scene.Permissions.PropagatePermissions()) + if (agentID != part.OwnerID && m_scene.Permissions.PropagatePermissions()) { taskItem.BasePermissions = item.BasePermissions & item.NextPermissions; @@ -148,11 +145,7 @@ namespace OpenSim.Region.Framework.Scenes // taskItem.SaleType = item.SaleType; taskItem.CreationDate = (uint)item.CreationDate; - bool addFromAllowedDrop = false; - if (remoteClient != null) - { - addFromAllowedDrop = remoteClient.AgentId != part.OwnerID; - } + bool addFromAllowedDrop = agentID != part.OwnerID; part.Inventory.AddInventoryItem(taskItem, addFromAllowedDrop); -- cgit v1.1