From 60065f06b3fd6f680202405e117402b22d62f902 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Mon, 23 Apr 2012 22:23:47 +0100
Subject: refactor: Replace calls to InventorySelf() with existing m_itemID in
LSL_Api
There's no point look up an item ID that we already have.
---
.../Shared/Api/Implementation/LSL_Api.cs | 136 +++++++--------------
1 file changed, 42 insertions(+), 94 deletions(-)
(limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs')
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 36c9d5e..6000293 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -85,7 +85,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
protected IScriptEngine m_ScriptEngine;
protected SceneObjectPart m_host;
protected uint m_localID;
+
+ ///
+ /// The UUID of the item that hosts this script
+ ///
protected UUID m_itemID;
+
protected bool throwErrorOnNotImplemented = true;
protected AsyncCommandManager AsyncCommands = null;
protected float m_ScriptDelayFactor = 1.0f;
@@ -267,25 +272,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
}
- protected UUID InventorySelf()
- {
- UUID invItemID = new UUID();
-
- lock (m_host.TaskInventory)
- {
- foreach (KeyValuePair inv in m_host.TaskInventory)
- {
- if (inv.Value.Type == 10 && inv.Value.ItemID == m_itemID)
- {
- invItemID = inv.Key;
- break;
- }
- }
- }
-
- return invItemID;
- }
-
protected UUID InventoryKey(string name, int type)
{
m_host.AddScriptLPS(1);
@@ -2697,17 +2683,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public LSL_Integer llGiveMoney(string destination, int amount)
{
- UUID invItemID=InventorySelf();
- if (invItemID == UUID.Zero)
- return 0;
-
m_host.AddScriptLPS(1);
- TaskInventoryItem item = m_host.TaskInventory[invItemID];
+ TaskInventoryItem item;
lock (m_host.TaskInventory)
{
- item = m_host.TaskInventory[invItemID];
+ item = m_host.TaskInventory[m_itemID];
}
if (item.PermsGranter == UUID.Zero)
@@ -2955,10 +2937,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
lock (m_host.TaskInventory)
{
- if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
+ if (!m_host.TaskInventory.ContainsKey(m_itemID))
return;
else
- item = m_host.TaskInventory[InventorySelf()];
+ item = m_host.TaskInventory[m_itemID];
}
if (item.PermsGranter != UUID.Zero)
@@ -2983,10 +2965,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
lock (m_host.TaskInventory)
{
- if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
+ if (!m_host.TaskInventory.ContainsKey(m_itemID))
return;
else
- item = m_host.TaskInventory[InventorySelf()];
+ item = m_host.TaskInventory[m_itemID];
}
m_host.AddScriptLPS(1);
@@ -3026,10 +3008,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
lock (m_host.TaskInventory)
{
- if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
+ if (!m_host.TaskInventory.ContainsKey(m_itemID))
return;
else
- item = m_host.TaskInventory[InventorySelf()];
+ item = m_host.TaskInventory[m_itemID];
}
if (item.PermsGranter != m_host.OwnerID)
@@ -3058,10 +3040,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
lock (m_host.TaskInventory)
{
- if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
+ if (!m_host.TaskInventory.ContainsKey(m_itemID))
return;
else
- item = m_host.TaskInventory[InventorySelf()];
+ item = m_host.TaskInventory[m_itemID];
}
if (item.PermsGranter != m_host.OwnerID)
@@ -3313,18 +3295,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
- UUID invItemID = InventorySelf();
- if (invItemID == UUID.Zero)
- return;
-
TaskInventoryItem item;
lock (m_host.TaskInventory)
{
- if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
+ if (!m_host.TaskInventory.ContainsKey(m_itemID))
return;
else
- item = m_host.TaskInventory[InventorySelf()];
+ item = m_host.TaskInventory[m_itemID];
}
if (item.PermsGranter == UUID.Zero)
@@ -3350,18 +3328,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
- UUID invItemID=InventorySelf();
- if (invItemID == UUID.Zero)
- return;
-
TaskInventoryItem item;
lock (m_host.TaskInventory)
{
- if (!m_host.TaskInventory.ContainsKey(InventorySelf()))
+ if (!m_host.TaskInventory.ContainsKey(m_itemID))
return;
else
- item = m_host.TaskInventory[InventorySelf()];
+ item = m_host.TaskInventory[m_itemID];
}
if (item.PermsGranter == UUID.Zero)
@@ -3417,21 +3391,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public void llRequestPermissions(string agent, int perm)
{
- UUID agentID = new UUID();
+ UUID agentID;
if (!UUID.TryParse(agent, out agentID))
return;
- UUID invItemID = InventorySelf();
-
- if (invItemID == UUID.Zero)
- return; // Not in a prim? How??
-
TaskInventoryItem item;
lock (m_host.TaskInventory)
{
- item = m_host.TaskInventory[invItemID];
+ item = m_host.TaskInventory[m_itemID];
}
if (agentID == UUID.Zero || perm == 0) // Releasing permissions
@@ -3466,8 +3435,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
lock (m_host.TaskInventory)
{
- m_host.TaskInventory[invItemID].PermsGranter = agentID;
- m_host.TaskInventory[invItemID].PermsMask = perm;
+ m_host.TaskInventory[m_itemID].PermsGranter = agentID;
+ m_host.TaskInventory[m_itemID].PermsMask = perm;
}
m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
@@ -3490,8 +3459,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
lock (m_host.TaskInventory)
{
- m_host.TaskInventory[invItemID].PermsGranter = agentID;
- m_host.TaskInventory[invItemID].PermsMask = perm;
+ m_host.TaskInventory[m_itemID].PermsGranter = agentID;
+ m_host.TaskInventory[m_itemID].PermsMask = perm;
}
m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
@@ -3515,8 +3484,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
lock (m_host.TaskInventory)
{
- m_host.TaskInventory[invItemID].PermsGranter = agentID;
- m_host.TaskInventory[invItemID].PermsMask = 0;
+ m_host.TaskInventory[m_itemID].PermsGranter = agentID;
+ m_host.TaskInventory[m_itemID].PermsMask = 0;
}
presence.ControllingClient.OnScriptAnswer += handleScriptAnswer;
@@ -3524,7 +3493,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
presence.ControllingClient.SendScriptQuestion(
- m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, invItemID, perm);
+ m_host.UUID, m_host.ParentGroup.RootPart.Name, ownerName, m_itemID, perm);
return;
}
@@ -3541,20 +3510,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
if (taskID != m_host.UUID)
return;
- UUID invItemID = InventorySelf();
-
- if (invItemID == UUID.Zero)
- return;
-
- client.OnScriptAnswer-=handleScriptAnswer;
- m_waitingForScriptAnswer=false;
+ client.OnScriptAnswer -= handleScriptAnswer;
+ m_waitingForScriptAnswer = false;
if ((answer & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) == 0)
llReleaseControls();
lock (m_host.TaskInventory)
{
- m_host.TaskInventory[invItemID].PermsMask = answer;
+ m_host.TaskInventory[m_itemID].PermsMask = answer;
}
m_ScriptEngine.PostScriptEvent(m_itemID, new EventParams(
@@ -3627,7 +3591,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public void llCreateLink(string target, int parent)
{
m_host.AddScriptLPS(1);
- UUID invItemID = InventorySelf();
+
UUID targetID;
if (!UUID.TryParse(target, out targetID))
@@ -3636,7 +3600,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
TaskInventoryItem item;
lock (m_host.TaskInventory)
{
- item = m_host.TaskInventory[invItemID];
+ item = m_host.TaskInventory[m_itemID];
}
if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
@@ -3688,11 +3652,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public void llBreakLink(int linknum)
{
m_host.AddScriptLPS(1);
- UUID invItemID = InventorySelf();
lock (m_host.TaskInventory)
{
- if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
+ if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
&& !m_automaticLinkPermission)
{
ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
@@ -9691,17 +9654,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public LSL_Vector llGetCameraPos()
{
m_host.AddScriptLPS(1);
- UUID invItemID = InventorySelf();
-
- if (invItemID == UUID.Zero)
- return new LSL_Vector();
lock (m_host.TaskInventory)
{
- if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
+ if (m_host.TaskInventory[m_itemID].PermsGranter == UUID.Zero)
return new LSL_Vector();
- if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
+ if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
{
ShoutError("No permissions to track the camera");
return new LSL_Vector();
@@ -9720,16 +9679,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public LSL_Rotation llGetCameraRot()
{
m_host.AddScriptLPS(1);
- UUID invItemID = InventorySelf();
- if (invItemID == UUID.Zero)
- return new LSL_Rotation();
lock (m_host.TaskInventory)
{
- if (m_host.TaskInventory[invItemID].PermsGranter == UUID.Zero)
+ if (m_host.TaskInventory[m_itemID].PermsGranter == UUID.Zero)
return new LSL_Rotation();
- if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
+ if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
{
ShoutError("No permissions to track the camera");
return new LSL_Rotation();
@@ -9907,10 +9863,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
- // our key in the object we are in
- UUID invItemID = InventorySelf();
- if (invItemID == UUID.Zero) return;
-
// the object we are in
UUID objectID = m_host.ParentUUID;
if (objectID == UUID.Zero) return;
@@ -9919,10 +9871,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
lock (m_host.TaskInventory)
{
// we need the permission first, to know which avatar we want to set the camera for
- agentID = m_host.TaskInventory[invItemID].PermsGranter;
+ agentID = m_host.TaskInventory[m_itemID].PermsGranter;
if (agentID == UUID.Zero) return;
- if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return;
+ if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return;
}
ScenePresence presence = World.GetScenePresence(agentID);
@@ -9963,10 +9915,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
- // our key in the object we are in
- UUID invItemID=InventorySelf();
- if (invItemID == UUID.Zero) return;
-
// the object we are in
UUID objectID = m_host.ParentUUID;
if (objectID == UUID.Zero) return;
@@ -9975,9 +9923,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
UUID agentID;
lock (m_host.TaskInventory)
{
- agentID = m_host.TaskInventory[invItemID].PermsGranter;
+ agentID = m_host.TaskInventory[m_itemID].PermsGranter;
if (agentID == UUID.Zero) return;
- if ((m_host.TaskInventory[invItemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return;
+ if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return;
}
ScenePresence presence = World.GetScenePresence(agentID);
--
cgit v1.1
From 1f8d1bcdcf7ae48ad0b3609e532ad87859f6300b Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Mon, 23 Apr 2012 22:52:46 +0100
Subject: Replace common code to fetch self inventory item (as opposed to uuid)
with GetSelfInventoryItem()
However, at some point it would be far more convenient to receive the TaskInventoryItem in the constructor rather than just the item UUID, so we don't have to constantly refetch our self item.
---
.../Shared/Api/Implementation/LSL_Api.cs | 231 +++++++--------------
1 file changed, 76 insertions(+), 155 deletions(-)
(limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs')
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 6000293..a353b25 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -272,6 +272,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
}
+ ///
+ /// Get the inventory item that hosts ourselves.
+ ///
+ ///
+ /// FIXME: It would be far easier to pass in TaskInventoryItem rather than just m_itemID so that we don't need
+ /// to keep looking ourselves up.
+ ///
+ ///
+ protected TaskInventoryItem GetSelfInventoryItem()
+ {
+ lock (m_host.TaskInventory)
+ return m_host.TaskInventory[m_itemID];
+ }
+
protected UUID InventoryKey(string name, int type)
{
m_host.AddScriptLPS(1);
@@ -2685,12 +2699,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
- TaskInventoryItem item;
-
- lock (m_host.TaskInventory)
- {
- item = m_host.TaskInventory[m_itemID];
- }
+ TaskInventoryItem item = GetSelfInventoryItem();
if (item.PermsGranter == UUID.Zero)
return 0;
@@ -2933,15 +2942,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public void llTakeControls(int controls, int accept, int pass_on)
{
- TaskInventoryItem item;
-
- lock (m_host.TaskInventory)
- {
- if (!m_host.TaskInventory.ContainsKey(m_itemID))
- return;
- else
- item = m_host.TaskInventory[m_itemID];
- }
+ TaskInventoryItem item = GetSelfInventoryItem();
if (item.PermsGranter != UUID.Zero)
{
@@ -2961,18 +2962,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public void llReleaseControls()
{
- TaskInventoryItem item;
-
- lock (m_host.TaskInventory)
- {
- if (!m_host.TaskInventory.ContainsKey(m_itemID))
- return;
- else
- item = m_host.TaskInventory[m_itemID];
- }
-
m_host.AddScriptLPS(1);
+ TaskInventoryItem item = GetSelfInventoryItem();
+
if (item.PermsGranter != UUID.Zero)
{
ScenePresence presence = World.GetScenePresence(item.PermsGranter);
@@ -3004,15 +2997,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
// if (m_host.ParentGroup.RootPart.AttachmentPoint == 0)
// return;
- TaskInventoryItem item;
-
- lock (m_host.TaskInventory)
- {
- if (!m_host.TaskInventory.ContainsKey(m_itemID))
- return;
- else
- item = m_host.TaskInventory[m_itemID];
- }
+ TaskInventoryItem item = GetSelfInventoryItem();
if (item.PermsGranter != m_host.OwnerID)
return;
@@ -3036,15 +3021,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
if (m_host.ParentGroup.AttachmentPoint == 0)
return;
- TaskInventoryItem item;
-
- lock (m_host.TaskInventory)
- {
- if (!m_host.TaskInventory.ContainsKey(m_itemID))
- return;
- else
- item = m_host.TaskInventory[m_itemID];
- }
+ TaskInventoryItem item = GetSelfInventoryItem();
if (item.PermsGranter != m_host.OwnerID)
return;
@@ -3295,15 +3272,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
- TaskInventoryItem item;
-
- lock (m_host.TaskInventory)
- {
- if (!m_host.TaskInventory.ContainsKey(m_itemID))
- return;
- else
- item = m_host.TaskInventory[m_itemID];
- }
+ TaskInventoryItem item = GetSelfInventoryItem();
if (item.PermsGranter == UUID.Zero)
return;
@@ -3328,15 +3297,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
- TaskInventoryItem item;
-
- lock (m_host.TaskInventory)
- {
- if (!m_host.TaskInventory.ContainsKey(m_itemID))
- return;
- else
- item = m_host.TaskInventory[m_itemID];
- }
+ TaskInventoryItem item = GetSelfInventoryItem();
if (item.PermsGranter == UUID.Zero)
return;
@@ -3396,12 +3357,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
if (!UUID.TryParse(agent, out agentID))
return;
- TaskInventoryItem item;
-
- lock (m_host.TaskInventory)
- {
- item = m_host.TaskInventory[m_itemID];
- }
+ TaskInventoryItem item = GetSelfInventoryItem();
if (agentID == UUID.Zero || perm == 0) // Releasing permissions
{
@@ -3531,39 +3487,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
- lock (m_host.TaskInventory)
- {
- foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
- {
- if (item.Type == 10 && item.ItemID == m_itemID)
- {
- return item.PermsGranter.ToString();
- }
- }
- }
-
- return UUID.Zero.ToString();
+ return GetSelfInventoryItem().PermsGranter.ToString();
}
public LSL_Integer llGetPermissions()
{
m_host.AddScriptLPS(1);
- lock (m_host.TaskInventory)
- {
- foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
- {
- if (item.Type == 10 && item.ItemID == m_itemID)
- {
- int perms = item.PermsMask;
- if (m_automaticLinkPermission)
- perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
- return perms;
- }
- }
- }
+ int perms = GetSelfInventoryItem().PermsMask;
- return 0;
+ if (m_automaticLinkPermission)
+ perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
+
+ return perms;
}
public LSL_Integer llGetLinkNumber()
@@ -3597,11 +3533,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
if (!UUID.TryParse(target, out targetID))
return;
- TaskInventoryItem item;
- lock (m_host.TaskInventory)
- {
- item = m_host.TaskInventory[m_itemID];
- }
+ TaskInventoryItem item = GetSelfInventoryItem();
if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
&& !m_automaticLinkPermission)
@@ -3653,14 +3585,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
- lock (m_host.TaskInventory)
+ if ((GetSelfInventoryItem().PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
+ && !m_automaticLinkPermission)
{
- if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
- && !m_automaticLinkPermission)
- {
- ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
- return;
- }
+ ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
+ return;
}
if (linknum < ScriptBaseClass.LINK_THIS)
@@ -4537,23 +4466,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public LSL_String llGetScriptName()
{
- string result = String.Empty;
-
m_host.AddScriptLPS(1);
- lock (m_host.TaskInventory)
- {
- foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
- {
- if (item.Type == 10 && item.ItemID == m_itemID)
- {
- result = item.Name != null ? item.Name : String.Empty;
- break;
- }
- }
- }
+ TaskInventoryItem item = GetSelfInventoryItem();
- return result;
+ return item.Name != null ? item.Name : String.Empty;
}
public LSL_Integer llGetLinkNumberOfSides(int link)
@@ -9655,16 +9572,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
- lock (m_host.TaskInventory)
- {
- if (m_host.TaskInventory[m_itemID].PermsGranter == UUID.Zero)
- return new LSL_Vector();
+ TaskInventoryItem item = GetSelfInventoryItem();
- if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
- {
- ShoutError("No permissions to track the camera");
- return new LSL_Vector();
- }
+ if (item.PermsGranter == UUID.Zero)
+ return new LSL_Vector();
+
+ if ((item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
+ {
+ ShoutError("No permissions to track the camera");
+ return new LSL_Vector();
}
ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
@@ -9680,16 +9596,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
- lock (m_host.TaskInventory)
- {
- if (m_host.TaskInventory[m_itemID].PermsGranter == UUID.Zero)
- return new LSL_Rotation();
+ TaskInventoryItem item = GetSelfInventoryItem();
- if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
- {
- ShoutError("No permissions to track the camera");
- return new LSL_Rotation();
- }
+ if (item.PermsGranter == UUID.Zero)
+ return new LSL_Rotation();
+
+ if ((item.PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
+ {
+ ShoutError("No permissions to track the camera");
+ return new LSL_Rotation();
}
ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
@@ -9865,17 +9780,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
// the object we are in
UUID objectID = m_host.ParentUUID;
- if (objectID == UUID.Zero) return;
+ if (objectID == UUID.Zero)
+ return;
- UUID agentID;
- lock (m_host.TaskInventory)
- {
- // we need the permission first, to know which avatar we want to set the camera for
- agentID = m_host.TaskInventory[m_itemID].PermsGranter;
+ TaskInventoryItem item = GetSelfInventoryItem();
- if (agentID == UUID.Zero) return;
- if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return;
- }
+ // we need the permission first, to know which avatar we want to set the camera for
+ UUID agentID = item.PermsGranter;
+
+ if (agentID == UUID.Zero)
+ return;
+
+ if ((item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
+ return;
ScenePresence presence = World.GetScenePresence(agentID);
@@ -9917,21 +9834,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
// the object we are in
UUID objectID = m_host.ParentUUID;
- if (objectID == UUID.Zero) return;
+ if (objectID == UUID.Zero)
+ return;
+
+ TaskInventoryItem item = GetSelfInventoryItem();
// we need the permission first, to know which avatar we want to clear the camera for
- UUID agentID;
- lock (m_host.TaskInventory)
- {
- agentID = m_host.TaskInventory[m_itemID].PermsGranter;
- if (agentID == UUID.Zero) return;
- if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return;
- }
+ UUID agentID = item.PermsGranter;
+
+ if (agentID == UUID.Zero)
+ return;
+
+ if ((item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
+ return;
ScenePresence presence = World.GetScenePresence(agentID);
// we are not interested in child-agents
- if (presence.IsChildAgent) return;
+ if (presence.IsChildAgent)
+ return;
presence.ControllingClient.SendClearFollowCamProperties(objectID);
}
--
cgit v1.1
From 40e37d8b78379db08de541c8c7a9fed1d22ec5ef Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Tue, 24 Apr 2012 00:03:57 +0100
Subject: Add osForceAttachToAvatar() and osForceDetachFromAvatar()
These behave identically to llAttachToAvatar() and llDetachFromAvatar() except that they do not enforce the PERMISSION_ATTACH check
Intended for use in completely controlled dedicated environments where these checks are more a UI hinderance than a help.
Threat level high.
---
.../Shared/Api/Implementation/LSL_Api.cs | 73 +++++++++++++---------
1 file changed, 45 insertions(+), 28 deletions(-)
(limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs')
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 9cb97f9..d4c872c 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -2994,7 +2994,49 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
m_UrlModule.ReleaseURL(url);
}
- public void llAttachToAvatar(int attachment)
+ ///
+ /// Attach the object containing this script to the avatar that owns it.
+ ///
+ /// The attachment point (e.g. ATTACH_CHEST)
+ /// true if the attach suceeded, false if it did not
+ public bool AttachToAvatar(int attachmentPoint)
+ {
+ SceneObjectGroup grp = m_host.ParentGroup;
+ ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
+
+ IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
+
+ if (attachmentsModule != null)
+ return attachmentsModule.AttachObject(presence, grp, (uint)attachmentPoint, false);
+ else
+ return false;
+ }
+
+ ///
+ /// Detach the object containing this script from the avatar it is attached to.
+ ///
+ ///
+ /// Nothing happens if the object is not attached.
+ ///
+ public void DetachFromAvatar()
+ {
+ Util.FireAndForget(DetachWrapper, m_host);
+ }
+
+ private void DetachWrapper(object o)
+ {
+ SceneObjectPart host = (SceneObjectPart)o;
+
+ SceneObjectGroup grp = host.ParentGroup;
+ UUID itemID = grp.FromItemID;
+ ScenePresence presence = World.GetScenePresence(host.OwnerID);
+
+ IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
+ if (attachmentsModule != null)
+ attachmentsModule.DetachSingleAttachmentToInv(presence, itemID);
+ }
+
+ public void llAttachToAvatar(int attachmentPoint)
{
m_host.AddScriptLPS(1);
@@ -3007,15 +3049,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return;
if ((item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
- {
- SceneObjectGroup grp = m_host.ParentGroup;
-
- ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
-
- IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
- if (attachmentsModule != null)
- attachmentsModule.AttachObject(presence, grp, (uint)attachment, false);
- }
+ AttachToAvatar(attachmentPoint);
}
public void llDetachFromAvatar()
@@ -3031,24 +3065,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return;
if ((item.PermsMask & ScriptBaseClass.PERMISSION_ATTACH) != 0)
- {
- IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
- if (attachmentsModule != null)
- Util.FireAndForget(DetachWrapper, m_host);
- }
- }
-
- private void DetachWrapper(object o)
- {
- SceneObjectPart host = (SceneObjectPart)o;
-
- SceneObjectGroup grp = host.ParentGroup;
- UUID itemID = grp.FromItemID;
- ScenePresence presence = World.GetScenePresence(host.OwnerID);
-
- IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
- if (attachmentsModule != null)
- attachmentsModule.DetachSingleAttachmentToInv(presence, itemID);
+ DetachFromAvatar();
}
public void llTakeCamera(string avatar)
--
cgit v1.1