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/Data/Tests/RegionTests.cs | 12 +++--- OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | 50 +++++++++++++--------- .../Framework/Scenes/SceneObjectGroup.Inventory.cs | 15 ++----- 3 files changed, 40 insertions(+), 37 deletions(-) diff --git a/OpenSim/Data/Tests/RegionTests.cs b/OpenSim/Data/Tests/RegionTests.cs index 1b93176..1d806fc 100644 --- a/OpenSim/Data/Tests/RegionTests.cs +++ b/OpenSim/Data/Tests/RegionTests.cs @@ -685,7 +685,7 @@ namespace OpenSim.Data.Tests SceneObjectGroup sog = GetMySOG("object1"); InventoryItemBase i = NewItem(item1, zero, zero, itemname1, zero); - Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, i, zero), Is.True); + Assert.That(sog.AddInventoryItem(zero, sog.RootPart.LocalId, i, zero), Is.True); TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1); Assert.That(t.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))"); @@ -762,7 +762,7 @@ namespace OpenSim.Data.Tests i.CreationDate = creationd; SceneObjectGroup sog = GetMySOG("object1"); - Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, i, zero), Is.True); + Assert.That(sog.AddInventoryItem(zero, sog.RootPart.LocalId, i, zero), Is.True); TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, id); Assert.That(t.Name, Is.EqualTo(name), "Assert.That(t.Name, Is.EqualTo(name))"); @@ -807,10 +807,10 @@ namespace OpenSim.Data.Tests SceneObjectGroup sog = FindSOG("object1", region1); - Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, ib1, zero), Is.True); - Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, ib2, zero), Is.True); - Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, ib3, zero), Is.True); - Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, ib4, zero), Is.True); + Assert.That(sog.AddInventoryItem(zero, sog.RootPart.LocalId, ib1, zero), Is.True); + Assert.That(sog.AddInventoryItem(zero, sog.RootPart.LocalId, ib2, zero), Is.True); + Assert.That(sog.AddInventoryItem(zero, sog.RootPart.LocalId, ib3, zero), Is.True); + Assert.That(sog.AddInventoryItem(zero, sog.RootPart.LocalId, ib4, zero), Is.True); TaskInventoryItem t1 = sog.GetInventoryItem(sog.RootPart.LocalId, i1); Assert.That(t1.Name, Is.EqualTo(ib1.Name), "Assert.That(t1.Name, Is.EqualTo(ib1.Name))"); 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 /// 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); } /// /// Rez a script into a prim from an agent inventory. /// - /// + /// /// /// - public void RezScriptFromAgentInventory(IClientAPI remoteClient, UUID fromItemID, uint localID) + /// The part where the script was rezzed if successful. False otherwise. + 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; } /// @@ -1631,19 +1640,20 @@ namespace OpenSim.Region.Framework.Scenes /// /// /// - public void RezNewScript(IClientAPI remoteClient, InventoryItemBase itemBase) + /// The part where the script was rezzed if successful. False otherwise. + 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; } /// 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 /// /// Add an inventory item from a user's inventory to a prim in this scene object. /// - /// The client adding the item. + /// The agent adding the item. /// The local ID of the part receiving the add. /// The user inventory item being added. /// The item UUID that should be used by the new item. /// - 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