public void UpdateTaskInventory(IClientAPI remoteClient, UUID transactionID, TaskInventoryItem itemInfo,
uint primLocalID)
{
UUID itemID = itemInfo.ItemID;
// Find the prim we're dealing with
SceneObjectPart part = GetSceneObjectPart(primLocalID);
if (part != null)
{
TaskInventoryItem currentItem = part.Inventory.GetInventoryItem(itemID);
bool allowInventoryDrop = (part.GetEffectiveObjectFlags()
& (uint)PrimFlags.AllowInventoryDrop) != 0;
// Explicity allow anyone to add to the inventory if the
// AllowInventoryDrop flag has been set. Don't however let
// them update an item unless they pass the external checks
//
if (!Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId)
&& (currentItem != null || !allowInventoryDrop))
return;
if (currentItem == null)
{
UUID copyID = UUID.Random();
if (itemID != UUID.Zero)
{
InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
item = InventoryService.GetItem(item);
// Try library
if (null == item && LibraryService != null && LibraryService.LibraryRootFolder != null)
{
item = LibraryService.LibraryRootFolder.FindItem(itemID);
}
// 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);
m_log.InfoFormat(
"[PRIM INVENTORY]: Update with item {0} requested of prim {1} for {2}",
item.Name, primLocalID, remoteClient.Name);
part.GetProperties(remoteClient);
if (!Permissions.BypassPermissions())
{
if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
{
List<UUID> uuids = new List<UUID>();
uuids.Add(itemID);
RemoveInventoryItem(remoteClient, uuids);
}
}
}
else
{
m_log.ErrorFormat(
"[PRIM INVENTORY]: Could not find inventory item {0} to update for {1}!",
itemID, remoteClient.Name);
}
}
}
else // Updating existing item with new perms etc
{
IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>();
if (agentTransactions != null)
{
agentTransactions.HandleTaskItemUpdateFromTransaction(
remoteClient, part, transactionID, currentItem);
if ((InventoryType)itemInfo.InvType == InventoryType.Notecard)
remoteClient.SendAgentAlertMessage("Notecard saved", false);
else if ((InventoryType)itemInfo.InvType == InventoryType.LSL)
remoteClient.SendAgentAlertMessage("Script saved", false);
else
remoteClient.SendAgentAlertMessage("Item saved", false);
}
// Base ALWAYS has move
currentItem.BasePermissions |= (uint)PermissionMask.Move;
// Check if we're allowed to mess with permissions
if (!Permissions.IsGod(remoteClient.AgentId)) // Not a god
{
if (remoteClient.AgentId != part.OwnerID) // Not owner
{
// Friends and group members can't change any perms
itemInfo.BasePermissions = currentItem.BasePermissions;
itemInfo.EveryonePermissions = currentItem.EveryonePermissions;
itemInfo.GroupPermissions = currentItem.GroupPermissions;
itemInfo.NextPermissions = currentItem.NextPermissions;
itemInfo.CurrentPermissions = currentItem.CurrentPermissions;
}
else
{
// Owner can't change base, and can change other
// only up to base
itemInfo.BasePermissions = currentItem.BasePermissions;
itemInfo.EveryonePermissions &= currentItem.BasePermissions;
itemInfo.GroupPermissions &= currentItem.BasePermissions;
itemInfo.CurrentPermissions &= currentItem.BasePermissions;
itemInfo.NextPermissions &= currentItem.BasePermissions;
}
}
// Next ALWAYS has move
itemInfo.NextPermissions |= (uint)PermissionMask.Move;
if (part.Inventory.UpdateInventoryItem(itemInfo))
{
part.GetProperties(remoteClient);
}
}
}
else
{
m_log.WarnFormat(
"[PRIM INVENTORY]: " +
"Update with item {0} requested of prim {1} for {2} but this prim does not exist",
itemID, primLocalID, remoteClient.Name);
}
}