From 951b45b80fd504b4874b9ec3e0fbff49a25cb46f Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Thu, 5 Jul 2012 00:05:06 +0100
Subject: Add OSSL function osForceAttachToAvatarFromInventory()
This works like osForceAttachToAvatar() but allows an object to be directly specified from the script object's inventory rather than forcing it to be rezzed in the scene first.
Still only attaches objects to the owner of the script.
This allows one to bypass the complicated co-ordination of first rezzing objects in the scene before attaching them.
Threat level high.
---
.../Shared/Api/Implementation/OSSL_Api.cs | 54 +++++++++++++++++++++-
.../ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 7 +++
.../ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | 5 ++
3 files changed, 65 insertions(+), 1 deletion(-)
(limited to 'OpenSim/Region/ScriptEngine/Shared/Api')
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 7fa25f5..fa9364d 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -126,7 +126,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
[Serializable]
public class OSSL_Api : MarshalByRefObject, IOSSL_Api, IScriptApi
{
-// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
+ private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public const string GridInfoServiceConfigSectionName = "GridInfoService";
@@ -3151,6 +3151,58 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
((LSL_Api)m_LSL_Api).AttachToAvatar(attachmentPoint);
}
+ public void osForceAttachToAvatarFromInventory(string itemName, int attachmentPoint)
+ {
+ CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatarFromInventory");
+
+ IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
+
+ if (attachmentsModule == null)
+ return;
+
+ m_host.AddScriptLPS(1);
+
+ InitLSL();
+
+ TaskInventoryItem item = m_host.Inventory.GetInventoryItem(itemName);
+
+ if (item == null)
+ {
+ ((LSL_Api)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)
+ ((LSL_Api)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));
+
+ return;
+ }
+
+ ScenePresence sp = World.GetScenePresence(m_host.OwnerID);
+
+ if (sp == null)
+ return;
+
+ InventoryItemBase newItem = World.MoveTaskInventoryItem(sp.UUID, UUID.Zero, m_host, item.ItemID);
+
+ if (newItem == null)
+ {
+ m_log.ErrorFormat(
+ "[OSSL API]: Could not create user inventory item {0} for {1}, attach point {2} in {3}",
+ itemName, m_host.Name, attachmentPoint, World.Name);
+
+ return;
+ }
+
+ attachmentsModule.RezSingleAttachmentFromInventory(sp, newItem.ID, (uint)attachmentPoint);
+ }
+
public void osForceDetachFromAvatar()
{
CheckThreatLevel(ThreatLevel.High, "osForceDetachFromAvatar");
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index e92518d..a8335aa 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -107,6 +107,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
void osForceAttachToAvatar(int attachment);
///
+ /// Attach the inventory item in the object containing this script to the avatar that owns it without checking for PERMISSION_ATTACH
+ ///
+ /// Tha name of the item. If this is not found then a warning is said to the owner
+ /// The attachment point. For example, ATTACH_CHEST
+ void osForceAttachToAvatarFromInventory(string itemName, int attachment);
+
+ ///
/// Detach the object containing this script from the avatar it is attached to without checking for PERMISSION_ATTACH
///
/// Nothing happens if the object is not attached.
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index d230662..500ed96 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -296,6 +296,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
m_OSSL_Functions.osForceAttachToAvatar(attachmentPoint);
}
+ public void osForceAttachToAvatarFromInventory(string itemName, int attachmentPoint)
+ {
+ m_OSSL_Functions.osForceAttachToAvatarFromInventory(itemName, attachmentPoint);
+ }
+
public void osForceDetachFromAvatar()
{
m_OSSL_Functions.osForceDetachFromAvatar();
--
cgit v1.1