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.
0.7.4.1
Justin Clark-Casey (justincc) 2012-04-23 22:52:46 +01:00
parent 60065f06b3
commit 1f8d1bcdcf
1 changed files with 76 additions and 155 deletions

View File

@ -272,6 +272,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
}
/// <summary>
/// Get the inventory item that hosts ourselves.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
/// <returns></returns>
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;
int perms = GetSelfInventoryItem().PermsMask;
if (m_automaticLinkPermission)
perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
return perms;
}
}
}
return 0;
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,15 +3585,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
lock (m_host.TaskInventory)
{
if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
if ((GetSelfInventoryItem().PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
&& !m_automaticLinkPermission)
{
ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
return;
}
}
if (linknum < ScriptBaseClass.LINK_THIS)
return;
@ -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,17 +9572,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
lock (m_host.TaskInventory)
{
if (m_host.TaskInventory[m_itemID].PermsGranter == UUID.Zero)
TaskInventoryItem item = GetSelfInventoryItem();
if (item.PermsGranter == UUID.Zero)
return new LSL_Vector();
if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
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);
if (presence != null)
@ -9680,17 +9596,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
lock (m_host.TaskInventory)
{
if (m_host.TaskInventory[m_itemID].PermsGranter == UUID.Zero)
TaskInventoryItem item = GetSelfInventoryItem();
if (item.PermsGranter == UUID.Zero)
return new LSL_Rotation();
if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0)
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);
if (presence != null)
@ -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;
TaskInventoryItem item = GetSelfInventoryItem();
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;
UUID agentID = item.PermsGranter;
if (agentID == UUID.Zero) return;
if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return;
}
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);
}