Save attachments on detach/exit if a contained script state has been changed.

This involves making Attachments module listen for start/stop script changes.
It also involves removing the script from the region on detach in the same manner as every other DeleteSceneObject() call rather than simply stopping it
This is necessary tue to the bad assymetry of start and stop script triggers but it appears to be the correct behaviour anyway, as detached objects are completely gone from the sim.
Not just in a state where their scripts have been stopped.
0.7.4-extended
Justin Clark-Casey (justincc) 2013-01-11 01:46:36 +00:00
parent 3ad03d41e6
commit d51aee876d
2 changed files with 20 additions and 1 deletions

View File

@ -75,11 +75,27 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
m_scene.RegisterModuleInterface<IAttachmentsModule>(this); m_scene.RegisterModuleInterface<IAttachmentsModule>(this);
if (Enabled) if (Enabled)
{
m_scene.EventManager.OnNewClient += SubscribeToClientEvents; m_scene.EventManager.OnNewClient += SubscribeToClientEvents;
m_scene.EventManager.OnStartScript += HandleScriptStateChange;
m_scene.EventManager.OnStopScript += HandleScriptStateChange;
}
// TODO: Should probably be subscribing to CloseClient too, but this doesn't yet give us IClientAPI // TODO: Should probably be subscribing to CloseClient too, but this doesn't yet give us IClientAPI
} }
/// <summary>
/// Listen for client triggered running state changes so that we can persist the script's object if necessary.
/// </summary>
/// <param name='localID'></param>
/// <param name='itemID'></param>
private void HandleScriptStateChange(uint localID, UUID itemID)
{
SceneObjectGroup sog = m_scene.GetGroupByPrim(localID);
if (sog != null && sog.IsAttachment)
sog.HasGroupChanged = true;
}
public void RemoveRegion(Scene scene) public void RemoveRegion(Scene scene)
{ {
m_scene.UnregisterModuleInterface<IAttachmentsModule>(this); m_scene.UnregisterModuleInterface<IAttachmentsModule>(this);
@ -711,7 +727,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
// Remove the object from the scene so no more updates // Remove the object from the scene so no more updates
// are sent. Doing this before the below changes will ensure // are sent. Doing this before the below changes will ensure
// updates can't cause "HUD artefacts" // updates can't cause "HUD artefacts"
m_scene.DeleteSceneObject(so, false, false); m_scene.DeleteSceneObject(so, false);
// Prepare sog for storage // Prepare sog for storage
so.AttachedAvatar = UUID.Zero; so.AttachedAvatar = UUID.Zero;

View File

@ -339,6 +339,8 @@ namespace OpenSim.Region.Framework.Scenes
/// in <see cref="Scene.SetScriptRunning"/> /// in <see cref="Scene.SetScriptRunning"/>
/// via <see cref="OpenSim.Framework.IClientAPI.OnSetScriptRunning"/>, /// via <see cref="OpenSim.Framework.IClientAPI.OnSetScriptRunning"/>,
/// via <see cref="OpenSim.Region.ClientStack.LindenUDP.HandleSetScriptRunning"/> /// via <see cref="OpenSim.Region.ClientStack.LindenUDP.HandleSetScriptRunning"/>
/// XXX: This is only triggered when it is the client that starts the script, not in other situations where
/// a script is started, unlike OnStopScript!
/// </remarks> /// </remarks>
public event StartScript OnStartScript; public event StartScript OnStartScript;
@ -352,6 +354,7 @@ namespace OpenSim.Region.Framework.Scenes
/// in <see cref="SceneObjectPartInventory.CreateScriptInstance"/>, /// in <see cref="SceneObjectPartInventory.CreateScriptInstance"/>,
/// <see cref="SceneObjectPartInventory.StopScriptInstance"/>, /// <see cref="SceneObjectPartInventory.StopScriptInstance"/>,
/// <see cref="Scene.SetScriptRunning"/> /// <see cref="Scene.SetScriptRunning"/>
/// XXX: This is triggered when a sciprt is stopped for any reason, unlike OnStartScript!
/// </remarks> /// </remarks>
public event StopScript OnStopScript; public event StopScript OnStopScript;