mirror of
https://github.com/opensim/opensim.git
synced 2026-08-04 16:22:50 +08:00
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:
<pre><code>
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));
}
}
}
</code></pre>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
///<summary>
|
||||
/// 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<UUID> 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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user