From 9ffe4d850e9ccf2fc40901e186af3d38c31b9a6d Mon Sep 17 00:00:00 2001 From: Alan Webb Date: Mon, 3 Aug 2009 21:43:08 -0400 Subject: This change adds support for the attach event in scripts. [1] Added a new OnAttach event to Scene/EventManager [2] Hooked up existing attach event handler in XEngine. [3] Modified SceneGraph and Scene.Inventory to trigger attach events at the appropriate places. I was forced to distribut the changes across two files because of the way attach processing is distributed across the two files. [4] In the case of RezSingleAttachmentFromInventory it is necessary to handle event scheduling in a special way. There is no synchronous path available, so the fact that this object is attached, and who it is attached to, is cached when the ScriptInstance is created. When the script is started, the attached handler is driven after on_rez (but before changed, this should be reviewed). Signed-off-by: dr scofield (aka dirk husemann) --- OpenSim/Region/Framework/Scenes/EventManager.cs | 16 ++++++++++++++++ OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | 6 ++++++ OpenSim/Region/Framework/Scenes/SceneGraph.cs | 2 ++ 3 files changed, 24 insertions(+) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs index 4b3e45f..086496e 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 15009a3..facd301 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 3f63481..5752a88 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()); -- cgit v1.1