From 60214e6e81109b14bec7e7803cb51580da1ce90d Mon Sep 17 00:00:00 2001
From: Adil El Farissi <144741970+AdilElFarissi@users.noreply.github.com>
Date: Sun, 25 Feb 2024 07:14:49 +0000
Subject: [PATCH] Add 2 OSSL functions to the LinkInventory collection
Add Functions:
+ osGiveLinkInventoryList(integer linkNumber, key destination, string category, list inventory)
Give a group of items located in a child prim inventory
+ osRemoveLinkInventory(integer linkNumber, string name)
Remove an item from a child prim inventory
LSL Script example:
default
{
touch_start(integer a){
integer linkNumber = llDetectedLinkNumber(0);
list linkInventoryNames = osGetLinkInventoryNames(linkNumber, INVENTORY_ALL);
osGiveLinkInventoryList(linkNumber, llDetectedKey(0), llGetLinkName(linkNumber), linkInventoryNames);
for(integer i = 0; i < llGetListLength(linkInventoryNames); i++){
osRemoveLinkInventory(linkNumber, llList2String(linkInventoryNames, i));
}
}
}
---
.../Shared/Api/Implementation/OSSL_Api.cs | 111 ++++++++++++++++++
.../Shared/Api/Interface/IOSSL_Api.cs | 2 +
.../Shared/Api/Runtime/OSSL_Stub.cs | 11 ++
bin/ScriptSyntax.xml | 16 +++
4 files changed, 140 insertions(+)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 5536f82fdd..76a859875c 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -5635,6 +5635,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return ret;
}
+ public void osRemoveLinkInventory(LSL_Integer linkNumber, LSL_String name)
+ {
+
+ SceneObjectPart part = GetSingleLinkPart(linkNumber);
+ if(part == null)
+ return;
+
+ TaskInventoryItem item = part.Inventory.GetInventoryItem(name);
+ if (item == null)
+ return;
+
+ if (item.ItemID == m_item.ItemID)
+ throw new ScriptDeleteException();
+ else
+ part.Inventory.RemoveInventoryItem(item.ItemID);
+ }
+
///
/// Give a specified item from a child prim inventory
/// to a destination (object or avatar).
@@ -5703,6 +5720,100 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
}
+ public void osGiveLinkInventoryList(LSL_Integer linkNumber, LSL_Key destination, LSL_String category, LSL_List inventory)
+ {
+ if (inventory.Length == 0)
+ return;
+
+ SceneObjectPart part = GetSingleLinkPart(linkNumber);
+ if(part == null)
+ return;
+
+ if (!UUID.TryParse(destination, out UUID destID) || destID.IsZero())
+ return;
+
+ bool isNotOwner = true;
+ if (!World.TryGetSceneObjectPart(destID, out SceneObjectPart destSop))
+ {
+ if (!World.TryGetScenePresence(destID, out ScenePresence sp))
+ {
+ // we could check if it is a grid user and allow the transfer as in older code
+ // but that increases security risk
+ OSSLShoutError("osGiveLinkInventoryList: Unable to give list, destination not found");
+ ScriptSleep(100);
+ return;
+ }
+ isNotOwner = sp.UUID.NotEqual(m_host.OwnerID);
+ }
+
+ List itemList = new(inventory.Length);
+ foreach (object item in inventory.Data)
+ {
+ string rawItemString = item.ToString();
+ TaskInventoryItem taskItem = (UUID.TryParse(rawItemString, out UUID itemID)) ?
+ part.Inventory.GetInventoryItem(itemID) : part.Inventory.GetInventoryItem(rawItemString);
+
+ if(taskItem is null)
+ continue;
+
+ if ((taskItem.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
+ continue;
+
+ if (destSop is not null)
+ {
+ if(!World.Permissions.CanDoObjectInvToObjectInv(taskItem, m_host, destSop))
+ continue;
+ }
+ else
+ {
+ if(isNotOwner)
+ {
+ if ((taskItem.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
+ continue;
+ }
+ }
+
+ itemList.Add(taskItem.ItemID);
+ }
+
+ if (itemList.Count == 0)
+ {
+ OSSLShoutError("osGiveLinkInventoryList: Unable to give list, no items found");
+ ScriptSleep(100);
+ return;
+ }
+
+ UUID folderID = m_ScriptEngine.World.MoveTaskInventoryItems(destID, category, part, itemList, false);
+
+ if (folderID.IsZero())
+ {
+ OSSLShoutError("osGiveLinkInventoryList: Unable to give list");
+ ScriptSleep(100);
+ return;
+ }
+
+ if (destSop is not null)
+ {
+ ScriptSleep(100);
+ return;
+ }
+
+ if (m_TransferModule != null)
+ {
+ byte[] bucket = new byte[] { (byte)AssetType.Folder };
+
+ Vector3 pos = m_host.AbsolutePosition;
+
+ GridInstantMessage msg = new(World, m_host.OwnerID, m_host.Name, destID,
+ (byte)InstantMessageDialog.TaskInventoryOffered,
+ m_host.OwnerID.Equals(m_host.GroupID), string.Format("'{0}'", category), folderID, false, pos,bucket, false);
+
+ m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
+ }
+
+ ScriptSleep(3000);
+ }
+
public LSL_Key osGetLastChangedEventKey()
{
DetectParams detectedParams = m_ScriptEngine.GetDetectParams(m_item.ItemID, 0);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index aaa79c64ee..d92f50c23f 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -570,7 +570,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
LSL_List osGetLinkInventoryKeys(LSL_Integer linkNumber, LSL_Integer type);
LSL_List osGetInventoryNames(LSL_Integer type);
LSL_List osGetLinkInventoryNames(LSL_Integer linkNumber, LSL_Integer type);
+ void osRemoveLinkInventory(LSL_Integer linkNumber, LSL_String name);
void osGiveLinkInventory(LSL_Integer linkNumber, LSL_Key destination, LSL_String inventory);
+ void osGiveLinkInventoryList(LSL_Integer linkNumber, LSL_Key destination, LSL_String category, LSL_List inventory);
LSL_Key osGetLastChangedEventKey();
LSL_Float osGetPSTWallclock();
LSL_Rotation osSlerp(LSL_Rotation a, LSL_Rotation b, LSL_Float amount);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index 9f31f80d67..56a44219bc 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -1515,12 +1515,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
return m_OSSL_Functions.osGetLinkInventoryDesc(linkNumber, itemNameOrId);
}
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public void osRemoveLinkInventory(LSL_Integer linkNumber, LSL_String name)
+ {
+ m_OSSL_Functions.osRemoveLinkInventory(linkNumber, name);
+ }
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void osGiveLinkInventory(LSL_Integer linkNumber, LSL_Key destination, LSL_String inventory)
{
m_OSSL_Functions.osGiveLinkInventory(linkNumber, destination, inventory);
}
+ public void osGiveLinkInventoryList(LSL_Integer linkNumber, LSL_Key destination, LSL_String category, LSL_List inventory)
+ {
+ m_OSSL_Functions.osGiveLinkInventoryList(linkNumber, destination, category, inventory);
+ }
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LSL_Key osGetLastChangedEventKey()
{
diff --git a/bin/ScriptSyntax.xml b/bin/ScriptSyntax.xml
index b53d6dd1b8..0461263f1d 100644
--- a/bin/ScriptSyntax.xml
+++ b/bin/ScriptSyntax.xml
@@ -7378,6 +7378,13 @@ fc2639fd-5d16-66bf-d8ab-2e4d754c816d
+ osRemoveLinkInventory
+
+ arguments
+ linkNumbertypeinteger
+ nametypeinteger
+
+
osGiveLinkInventory
arguments
@@ -7386,6 +7393,15 @@ fc2639fd-5d16-66bf-d8ab-2e4d754c816d
inventorytypestring
+ osGiveLinkInventoryList
+
+ arguments
+ linkNumbertypeinteger
+ destinationtypekey
+ categorytypestring
+ inventorytypestring
+
+
osGetLastChangedEventKey
returnkey