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.3-extended
Justin Clark-Casey (justincc) 2012-04-23 22:52:46 +01:00
parent 6610cd2332
commit 2657aa6987
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);
@ -2684,12 +2698,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;
@ -2908,15 +2917,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)
{
@ -2936,18 +2937,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);
@ -2979,15 +2972,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;
@ -3011,15 +2996,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;
@ -3270,15 +3247,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;
@ -3303,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;
@ -3371,12 +3332,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
{
@ -3506,39 +3462,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()
@ -3572,11 +3508,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)
@ -3628,14 +3560,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)
@ -4519,23 +4448,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)
@ -9636,16 +9553,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);
@ -9661,16 +9577,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);
@ -9846,17 +9761,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);
@ -9898,21 +9815,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);
}