mantis 9036: do not allow ForceAttachToAvatarFromInventory to attach coalesced inventory assets

This commit is contained in:
UbitUmarov
2022-11-12 19:35:45 +00:00
parent 86a8b68e01
commit 209b6babb5

View File

@@ -4236,43 +4236,42 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public void ForceAttachToAvatarFromInventory(UUID avatarId, string itemName, int attachmentPoint)
{
IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
if (attachmentsModule == null)
if (attachmentsModule is null)
return;
InitLSL();
TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
if (item == null)
if (item is null)
{
m_LSL_Api.llSay(0, string.Format("Could not find object '{0}'", itemName));
m_LSL_Api?.llSay(0, string.Format("Could not find object '{0}'", itemName));
throw new Exception(String.Format("The inventory item '{0}' could not be found", itemName));
}
if (item.InvType != (int)InventoryType.Object)
{
// FIXME: Temporary null check for regression tests since they dont' have the infrastructure to set
// up the api reference.
if (m_LSL_Api != null)
m_LSL_Api.llSay(0, string.Format("Unable to attach, item '{0}' is not an object.", itemName));
m_LSL_Api?.llSay(0, string.Format("Unable to attach, item '{0}' is not an object.", itemName));
throw new Exception(String.Format("The inventory item '{0}' is not an object", itemName));
}
ScenePresence sp = World.GetScenePresence(avatarId);
if ((item.Flags & (uint)InventoryItemFlags.ObjectHasMultipleItems) != 0)
{
m_LSL_Api?.llSay(0, string.Format("Unable to attach coalesced object, item '{0}' ", itemName));
throw new Exception(String.Format("The inventory item '{0}' is a coalesced object", itemName));
}
if (sp == null)
ScenePresence sp = World.GetScenePresence(avatarId);
if (sp is null)
return;
InventoryItemBase newItem = World.MoveTaskInventoryItem(sp.UUID, UUID.Zero, m_host, item.ItemID, out string message);
if (newItem == null)
if (newItem is null)
{
m_log.ErrorFormat(
"[OSSL API]: Could not create user inventory item {0} for {1}, attach point {2} in {3}: {4}",
itemName, m_host.Name, attachmentPoint, World.Name, message);
m_LSL_Api.llSay(0, message);
m_LSL_Api?.llSay(0, message);
return;
}