diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs index 4b3e45f957..086496ed80 100644 --- a/OpenSim/Region/Framework/Scenes/EventManager.cs +++ b/OpenSim/Region/Framework/Scenes/EventManager.cs @@ -298,6 +298,13 @@ namespace OpenSim.Region.Framework.Scenes public delegate void EmptyScriptCompileQueue(int numScriptsFailed, string message); public event EmptyScriptCompileQueue OnEmptyScriptCompileQueue; + /// + /// Called whenever an object is attached, or detached + /// from an in-world presence. + /// + public delegate void Attach(uint localID, UUID itemID, UUID avatarID); + public event Attach OnAttach; + public class MoneyTransferArgs : EventArgs { public UUID sender; @@ -438,6 +445,15 @@ namespace OpenSim.Region.Framework.Scenes private EmptyScriptCompileQueue handlerEmptyScriptCompileQueue = null; + private Attach handlerOnAttach = null; + + public void TriggerOnAttach(uint localID, UUID itemID, UUID avatarID) + { + handlerOnAttach = OnAttach; + if (handlerOnAttach != null) + handlerOnAttach(localID, itemID, avatarID); + } + public void TriggerGetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID) { handlerGetScriptRunning = OnGetScriptRunning; diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index 15009a3767..facd3019c2 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -2574,6 +2574,11 @@ namespace OpenSim.Region.Framework.Scenes EventManager.TriggerStopScript(part.LocalId, itemID); } + internal void SendAttachEvent(uint localID, UUID itemID, UUID avatarID) + { + EventManager.TriggerOnAttach(localID, itemID, avatarID); + } + public UUID RezSingleAttachment(IClientAPI remoteClient, UUID itemID, uint AttachmentPt) { @@ -2684,6 +2689,7 @@ namespace OpenSim.Region.Framework.Scenes remoteClient.SendRemoveInventoryItem(inventoryID); } } + SendAttachEvent(part.ParentGroup.LocalId, itemID, UUID.Zero); } public void DetachSingleAttachmentToInv(UUID itemID, IClientAPI remoteClient) diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs index 3f634814fb..5752a88587 100644 --- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs +++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs @@ -489,6 +489,7 @@ namespace OpenSim.Region.Framework.Scenes // Calls attach with a Zero position // AttachObject(remoteClient, objectLocalID, AttachmentPt, rot, Vector3.Zero, false); + m_parentScene.SendAttachEvent(objectLocalID, part.ParentGroup.GetFromAssetID(), remoteClient.AgentId); } public SceneObjectGroup RezSingleAttachment( @@ -537,6 +538,7 @@ namespace OpenSim.Region.Framework.Scenes group = (SceneObjectGroup)entity; if (group.GetFromAssetID() == itemID) { + m_parentScene.SendAttachEvent(group.LocalId, itemID, UUID.Zero); group.DetachToInventoryPrep(); m_log.Debug("[DETACH]: Saving attachpoint: " + ((uint)group.GetAttachmentPoint()).ToString()); diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index 42d61a7b17..586f926518 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -89,6 +89,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance private long m_eventDelayTicks = 0; private long m_nextEventTimeTicks = 0; private bool m_startOnInit = true; + private bool m_isAttachment = false; + private UUID m_attachedAvatar = UUID.Zero; private StateSource m_stateSource; private bool m_postOnRez; private bool m_startedFromSavedState = false; @@ -232,6 +234,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance m_MaxScriptQueue = maxScriptQueue; m_stateSource = stateSource; m_postOnRez = postOnRez; + m_isAttachment = part.IsAttachment; + m_attachedAvatar = part.AttachedAvatar; m_RegionID = part.ParentGroup.Scene.RegionInfo.RegionID; if (part != null) @@ -379,6 +383,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance new Object[] {new LSL_Types.LSLInteger(m_StartParam)}, new DetectParams[0])); } + if (m_isAttachment) + { + PostEvent(new EventParams("attach", + new object[] { new LSL_Types.LSLString(m_attachedAvatar.ToString()) }, new DetectParams[0])); + } + if (m_stateSource == StateSource.NewRez) { // m_log.Debug("[Script] Posted changed(CHANGED_REGION_RESTART) to script"); @@ -403,6 +413,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance new Object[] {new LSL_Types.LSLInteger(m_StartParam)}, new DetectParams[0])); } + if (m_isAttachment) + { + PostEvent(new EventParams("attach", + new object[] { new LSL_Types.LSLString(m_attachedAvatar.ToString()) }, new DetectParams[0])); + } + } } diff --git a/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs b/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs index 3b9ff2ef32..7142c8c352 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs @@ -53,6 +53,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine myScriptEngine = _ScriptEngine; m_log.Info("[XEngine] Hooking up to server events"); + myScriptEngine.World.EventManager.OnAttach += attach; myScriptEngine.World.EventManager.OnObjectGrab += touch_start; myScriptEngine.World.EventManager.OnObjectDeGrab += touch_end; myScriptEngine.World.EventManager.OnScriptChangedEvent += changed;