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) protected UUID InventoryKey(string name, int type)
{ {
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
@ -2685,12 +2699,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{ {
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
TaskInventoryItem item; TaskInventoryItem item = GetSelfInventoryItem();
lock (m_host.TaskInventory)
{
item = m_host.TaskInventory[m_itemID];
}
if (item.PermsGranter == UUID.Zero) if (item.PermsGranter == UUID.Zero)
return 0; return 0;
@ -2933,15 +2942,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public void llTakeControls(int controls, int accept, int pass_on) public void llTakeControls(int controls, int accept, int pass_on)
{ {
TaskInventoryItem item; TaskInventoryItem item = GetSelfInventoryItem();
lock (m_host.TaskInventory)
{
if (!m_host.TaskInventory.ContainsKey(m_itemID))
return;
else
item = m_host.TaskInventory[m_itemID];
}
if (item.PermsGranter != UUID.Zero) if (item.PermsGranter != UUID.Zero)
{ {
@ -2961,18 +2962,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public void llReleaseControls() 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); m_host.AddScriptLPS(1);
TaskInventoryItem item = GetSelfInventoryItem();
if (item.PermsGranter != UUID.Zero) if (item.PermsGranter != UUID.Zero)
{ {
ScenePresence presence = World.GetScenePresence(item.PermsGranter); ScenePresence presence = World.GetScenePresence(item.PermsGranter);
@ -3004,15 +2997,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
// if (m_host.ParentGroup.RootPart.AttachmentPoint == 0) // if (m_host.ParentGroup.RootPart.AttachmentPoint == 0)
// return; // return;
TaskInventoryItem item; TaskInventoryItem item = GetSelfInventoryItem();
lock (m_host.TaskInventory)
{
if (!m_host.TaskInventory.ContainsKey(m_itemID))
return;
else
item = m_host.TaskInventory[m_itemID];
}
if (item.PermsGranter != m_host.OwnerID) if (item.PermsGranter != m_host.OwnerID)
return; return;
@ -3036,15 +3021,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
if (m_host.ParentGroup.AttachmentPoint == 0) if (m_host.ParentGroup.AttachmentPoint == 0)
return; return;
TaskInventoryItem item; TaskInventoryItem item = GetSelfInventoryItem();
lock (m_host.TaskInventory)
{
if (!m_host.TaskInventory.ContainsKey(m_itemID))
return;
else
item = m_host.TaskInventory[m_itemID];
}
if (item.PermsGranter != m_host.OwnerID) if (item.PermsGranter != m_host.OwnerID)
return; return;
@ -3295,15 +3272,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{ {
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
TaskInventoryItem item; TaskInventoryItem item = GetSelfInventoryItem();
lock (m_host.TaskInventory)
{
if (!m_host.TaskInventory.ContainsKey(m_itemID))
return;
else
item = m_host.TaskInventory[m_itemID];
}
if (item.PermsGranter == UUID.Zero) if (item.PermsGranter == UUID.Zero)
return; return;
@ -3328,15 +3297,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{ {
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
TaskInventoryItem item; TaskInventoryItem item = GetSelfInventoryItem();
lock (m_host.TaskInventory)
{
if (!m_host.TaskInventory.ContainsKey(m_itemID))
return;
else
item = m_host.TaskInventory[m_itemID];
}
if (item.PermsGranter == UUID.Zero) if (item.PermsGranter == UUID.Zero)
return; return;
@ -3396,12 +3357,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
if (!UUID.TryParse(agent, out agentID)) if (!UUID.TryParse(agent, out agentID))
return; return;
TaskInventoryItem item; TaskInventoryItem item = GetSelfInventoryItem();
lock (m_host.TaskInventory)
{
item = m_host.TaskInventory[m_itemID];
}
if (agentID == UUID.Zero || perm == 0) // Releasing permissions if (agentID == UUID.Zero || perm == 0) // Releasing permissions
{ {
@ -3531,39 +3487,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{ {
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
lock (m_host.TaskInventory) return GetSelfInventoryItem().PermsGranter.ToString();
{
foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
{
if (item.Type == 10 && item.ItemID == m_itemID)
{
return item.PermsGranter.ToString();
}
}
}
return UUID.Zero.ToString();
} }
public LSL_Integer llGetPermissions() public LSL_Integer llGetPermissions()
{ {
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
lock (m_host.TaskInventory) int perms = GetSelfInventoryItem().PermsMask;
{
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;
}
}
}
return 0; if (m_automaticLinkPermission)
perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
return perms;
} }
public LSL_Integer llGetLinkNumber() public LSL_Integer llGetLinkNumber()
@ -3597,11 +3533,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
if (!UUID.TryParse(target, out targetID)) if (!UUID.TryParse(target, out targetID))
return; return;
TaskInventoryItem item; TaskInventoryItem item = GetSelfInventoryItem();
lock (m_host.TaskInventory)
{
item = m_host.TaskInventory[m_itemID];
}
if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 if ((item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
&& !m_automaticLinkPermission) && !m_automaticLinkPermission)
@ -3653,14 +3585,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{ {
m_host.AddScriptLPS(1); 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 ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
&& !m_automaticLinkPermission) return;
{
ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
return;
}
} }
if (linknum < ScriptBaseClass.LINK_THIS) if (linknum < ScriptBaseClass.LINK_THIS)
@ -4537,23 +4466,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public LSL_String llGetScriptName() public LSL_String llGetScriptName()
{ {
string result = String.Empty;
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
lock (m_host.TaskInventory) TaskInventoryItem item = GetSelfInventoryItem();
{
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;
}
}
}
return result; return item.Name != null ? item.Name : String.Empty;
} }
public LSL_Integer llGetLinkNumberOfSides(int link) public LSL_Integer llGetLinkNumberOfSides(int link)
@ -9655,16 +9572,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{ {
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
lock (m_host.TaskInventory) TaskInventoryItem item = GetSelfInventoryItem();
{
if (m_host.TaskInventory[m_itemID].PermsGranter == UUID.Zero)
return new LSL_Vector();
if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0) if (item.PermsGranter == UUID.Zero)
{ return new LSL_Vector();
ShoutError("No permissions to track the camera");
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); ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
@ -9680,16 +9596,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{ {
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
lock (m_host.TaskInventory) TaskInventoryItem item = GetSelfInventoryItem();
{
if (m_host.TaskInventory[m_itemID].PermsGranter == UUID.Zero)
return new LSL_Rotation();
if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_TRACK_CAMERA) == 0) if (item.PermsGranter == UUID.Zero)
{ return new LSL_Rotation();
ShoutError("No permissions to track the camera");
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); ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
@ -9865,17 +9780,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
// the object we are in // the object we are in
UUID objectID = m_host.ParentUUID; UUID objectID = m_host.ParentUUID;
if (objectID == UUID.Zero) return; if (objectID == UUID.Zero)
return;
UUID agentID; TaskInventoryItem item = GetSelfInventoryItem();
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;
if (agentID == UUID.Zero) return; // we need the permission first, to know which avatar we want to set the camera for
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); ScenePresence presence = World.GetScenePresence(agentID);
@ -9917,21 +9834,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
// the object we are in // the object we are in
UUID objectID = m_host.ParentUUID; 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 // we need the permission first, to know which avatar we want to clear the camera for
UUID agentID; UUID agentID = item.PermsGranter;
lock (m_host.TaskInventory)
{ if (agentID == UUID.Zero)
agentID = m_host.TaskInventory[m_itemID].PermsGranter; return;
if (agentID == UUID.Zero) return;
if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return; if ((item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
} return;
ScenePresence presence = World.GetScenePresence(agentID); ScenePresence presence = World.GetScenePresence(agentID);
// we are not interested in child-agents // we are not interested in child-agents
if (presence.IsChildAgent) return; if (presence.IsChildAgent)
return;
presence.ControllingClient.SendClearFollowCamProperties(objectID); presence.ControllingClient.SendClearFollowCamProperties(objectID);
} }