From 20952c75c526180a0286fb9634b94ac1354a2770 Mon Sep 17 00:00:00 2001
From: Dan Lake
Date: Tue, 8 May 2012 16:05:34 -0700
Subject: Trigger event when scene presences are updated

---
 OpenSim/Region/Framework/Scenes/EventManager.cs  | 24 ++++++++++++++++++++++++
 OpenSim/Region/Framework/Scenes/ScenePresence.cs | 10 ++++++++++
 2 files changed, 34 insertions(+)

(limited to 'OpenSim')

diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs
index b3debb0..ace8313 100644
--- a/OpenSim/Region/Framework/Scenes/EventManager.cs
+++ b/OpenSim/Region/Framework/Scenes/EventManager.cs
@@ -480,6 +480,9 @@ namespace OpenSim.Region.Framework.Scenes
         public delegate void SceneObjectPartUpdated(SceneObjectPart sop);
         public event SceneObjectPartUpdated OnSceneObjectPartUpdated;
 
+        public delegate void ScenePresenceUpdated(ScenePresence sp);
+        public event ScenePresenceUpdated OnScenePresenceUpdated;
+
         public delegate void RegionUp(GridRegion region);
         public event RegionUp OnRegionUp;
 
@@ -2343,6 +2346,27 @@ namespace OpenSim.Region.Framework.Scenes
             }
         }
 
+        public void TriggerScenePresenceUpdated(ScenePresence sp)
+        {
+            ScenePresenceUpdated handler = OnScenePresenceUpdated;
+            if (handler != null)
+            {
+                foreach (ScenePresenceUpdated d in handler.GetInvocationList())
+                {
+                    try
+                    {
+                        d(sp);
+                    }
+                    catch (Exception e)
+                    {
+                        m_log.ErrorFormat(
+                            "[EVENT MANAGER]: Delegate for TriggerScenePresenceUpdated failed - continuing.  {0} {1}",
+                            e.Message, e.StackTrace);
+                    }
+                }
+            }
+        }
+
         public void TriggerOnParcelPropertiesUpdateRequest(LandUpdateArgs args,
                         int local_id, IClientAPI remote_client)
         {
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 7e49a5e..c552447 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -76,6 +76,11 @@ namespace OpenSim.Region.Framework.Scenes
 //        {
 //            m_log.Debug("[SCENE PRESENCE] Destructor called");
 //        }
+        private void TriggerScenePresenceUpdated()
+        {
+            if (m_scene != null)
+                m_scene.EventManager.TriggerScenePresenceUpdated(this);
+        }
 
         private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
 
@@ -489,6 +494,7 @@ namespace OpenSim.Region.Framework.Scenes
                 //m_log.DebugFormat(
                 //    "[ENTITY BASE]: In {0} set AbsolutePosition of {1} to {2}",
                 //    Scene.RegionInfo.RegionName, Name, m_pos);
+                TriggerScenePresenceUpdated();
             }
         }
 
@@ -508,6 +514,7 @@ namespace OpenSim.Region.Framework.Scenes
                     return;
 
                 m_pos = value;
+                TriggerScenePresenceUpdated();
             }
         }
 
@@ -1523,6 +1530,7 @@ namespace OpenSim.Region.Framework.Scenes
             }
 
             m_scene.EventManager.TriggerOnClientMovement(this);
+            TriggerScenePresenceUpdated();
         }
 
         /// <summary>
@@ -2419,6 +2427,7 @@ namespace OpenSim.Region.Framework.Scenes
 
                 m_scene.ForEachClient(SendTerseUpdateToClient);
             }
+            TriggerScenePresenceUpdated();
         }
 
         public void SendCoarseLocations(List<Vector3> coarseLocations, List<UUID> avatarUUIDs)
@@ -3195,6 +3204,7 @@ namespace OpenSim.Region.Framework.Scenes
                 Velocity = force;
 
                 m_forceToApply = null;
+                TriggerScenePresenceUpdated();
             }
         }
 
-- 
cgit v1.1