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) protected UUID InventoryKey(string name, int type)
{ {
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
@ -2684,12 +2698,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;
@ -2908,15 +2917,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)
{ {
@ -2936,18 +2937,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);
@ -2979,15 +2972,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;
@ -3011,15 +2996,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;
@ -3270,15 +3247,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;
@ -3303,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;
@ -3371,12 +3332,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
{ {
@ -3506,39 +3462,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) if (m_automaticLinkPermission)
perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS; perms |= ScriptBaseClass.PERMISSION_CHANGE_LINKS;
return perms;
}
}
}
return 0; return perms;
} }
public LSL_Integer llGetLinkNumber() public LSL_Integer llGetLinkNumber()
@ -3572,11 +3508,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)
@ -3628,15 +3560,12 @@ 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
{
if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0
&& !m_automaticLinkPermission) && !m_automaticLinkPermission)
{ {
ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!"); ShoutError("Script trying to link but PERMISSION_CHANGE_LINKS permission not set!");
return; return;
} }
}
if (linknum < ScriptBaseClass.LINK_THIS) if (linknum < ScriptBaseClass.LINK_THIS)
return; return;
@ -4519,23 +4448,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)
@ -9636,17 +9553,16 @@ 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) if (item.PermsGranter == UUID.Zero)
return new LSL_Vector(); 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"); ShoutError("No permissions to track the camera");
return new LSL_Vector(); return new LSL_Vector();
} }
}
ScenePresence presence = World.GetScenePresence(m_host.OwnerID); ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
if (presence != null) if (presence != null)
@ -9661,17 +9577,16 @@ 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) if (item.PermsGranter == UUID.Zero)
return new LSL_Rotation(); 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"); ShoutError("No permissions to track the camera");
return new LSL_Rotation(); return new LSL_Rotation();
} }
}
ScenePresence presence = World.GetScenePresence(m_host.OwnerID); ScenePresence presence = World.GetScenePresence(m_host.OwnerID);
if (presence != null) if (presence != null)
@ -9846,17 +9761,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;
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 // 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 (agentID == UUID.Zero)
if ((m_host.TaskInventory[m_itemID].PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0) return; return;
}
if ((item.PermsMask & ScriptBaseClass.PERMISSION_CONTROL_CAMERA) == 0)
return;
ScenePresence presence = World.GetScenePresence(agentID); ScenePresence presence = World.GetScenePresence(agentID);
@ -9898,21 +9815,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);
} }