a few changes to script engines releasecontrols

master
UbitUmarov 2020-02-20 08:20:15 +00:00
parent 8d8b5b756f
commit d7671f3c01
2 changed files with 37 additions and 34 deletions

View File

@ -459,23 +459,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
}
}
private void ReleaseControls()
private void ReleaseControlsorPermissions(bool fullpermissions)
{
SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
if (part != null)
if (part != null && part.TaskInventory != null)
{
int permsMask;
UUID permsGranter;
part.TaskInventory.LockItemsForRead(true);
if (!part.TaskInventory.ContainsKey(ItemID))
part.TaskInventory.LockItemsForWrite(true);
if (!part.TaskInventory.TryGetValue(ItemID, out TaskInventoryItem item))
{
part.TaskInventory.LockItemsForRead(false);
part.TaskInventory.LockItemsForWrite(false);
return;
}
permsGranter = part.TaskInventory[ItemID].PermsGranter;
permsMask = part.TaskInventory[ItemID].PermsMask;
part.TaskInventory.LockItemsForRead(false);
permsGranter = item.PermsGranter;
permsMask = item.PermsMask;
if(fullpermissions)
{
item.PermsGranter = UUID.Zero;
item.PermsMask = 0;
}
else
item.PermsMask = permsMask & ~(ScriptBaseClass.PERMISSION_TAKE_CONTROLS | ScriptBaseClass.PERMISSION_CONTROL_CAMERA);
part.TaskInventory.LockItemsForWrite(false);
if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
{
@ -488,7 +495,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
public void DestroyScriptInstance()
{
ReleaseControls();
ReleaseControlsorPermissions(false);
AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID);
SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
if (part != null)
@ -1062,12 +1069,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
bool running = Running;
RemoveState();
ReleaseControls();
ReleaseControlsorPermissions(true);
Stop(timeout);
SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
part.Inventory.GetInventoryItem(ItemID).PermsMask = 0;
part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero;
part.CollisionSound = UUID.Zero;
AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID);
@ -1097,12 +1102,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
// bool running = Running;
RemoveState();
ReleaseControls();
ReleaseControlsorPermissions(true);
m_Script.ResetVars();
SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
part.Inventory.GetInventoryItem(ItemID).PermsMask = 0;
part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero;
part.CollisionSound = UUID.Zero;
AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID);
@ -1114,8 +1117,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
StartParam = 0;
State = "default";
part.SetScriptEvents(ItemID,
(int)m_Script.GetStateEventFlags(State));
part.SetScriptEvents(ItemID, m_Script.GetStateEventFlags(State));
if (m_CurrentEvent != "state_entry" || oldState != "default")
{

View File

@ -871,11 +871,10 @@ namespace OpenSim.Region.ScriptEngine.Yengine
private void ResetLocked(string from)
{
m_RunOnePhase = "ResetLocked: releasing controls";
ReleaseControls();
ReleaseControlsOrPermissions(true);
m_Part.CollisionSound = UUID.Zero;
m_RunOnePhase = "ResetLocked: removing script";
m_Part.Inventory.GetInventoryItem(m_ItemID).PermsMask = 0;
m_Part.Inventory.GetInventoryItem(m_ItemID).PermsGranter = UUID.Zero;
IUrlModule urlModule = m_Engine.World.RequestModuleInterface<IUrlModule>();
if(urlModule != null)
urlModule.ScriptRemoved(m_ItemID);
@ -916,28 +915,30 @@ namespace OpenSim.Region.ScriptEngine.Yengine
m_RunOnePhase = "ResetLocked: reset complete";
}
private void ReleaseControls()
private void ReleaseControlsOrPermissions(bool fullPermissions)
{
if(m_Part != null)
if(m_Part != null && m_Part.TaskInventory != null)
{
bool found;
int permsMask;
UUID permsGranter;
try
m_Part.TaskInventory.LockItemsForWrite(true);
if (!m_Part.TaskInventory.TryGetValue(m_ItemID, out TaskInventoryItem item))
{
permsGranter = m_Part.TaskInventory[m_ItemID].PermsGranter;
permsMask = m_Part.TaskInventory[m_ItemID].PermsMask;
found = true;
m_Part.TaskInventory.LockItemsForWrite(false);
return;
}
catch
permsGranter = item.PermsGranter;
permsMask = item.PermsMask;
if(fullPermissions)
{
permsGranter = UUID.Zero;
permsMask = 0;
found = false;
item.PermsGranter = UUID.Zero;
item.PermsMask = 0;
}
else
item.PermsMask = permsMask & ~(ScriptBaseClass.PERMISSION_TAKE_CONTROLS | ScriptBaseClass.PERMISSION_CONTROL_CAMERA);
m_Part.TaskInventory.LockItemsForWrite(false);
if(found && ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0))
if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
{
ScenePresence presence = m_Engine.World.GetScenePresence(permsGranter);
if (presence != null)