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.
iar_mods
Justin Clark-Casey (justincc) 2012-01-26 00:10:37 +00:00
parent 8e5502fdc2
commit 55c6cbabfd
3 changed files with 40 additions and 37 deletions

View File

@ -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))");

View File

@ -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>

View File

@ -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);