diff --git a/OpenSim/Framework/IScene.cs b/OpenSim/Framework/IScene.cs index 27b3d478eb..86d63f88a8 100644 --- a/OpenSim/Framework/IScene.cs +++ b/OpenSim/Framework/IScene.cs @@ -91,6 +91,8 @@ namespace OpenSim.Framework /// bool PresenceChildStatus(UUID agentId); + bool TryGetAvatar(UUID agentID, out object scenePresence); + T RequestModuleInterface(); T[] RequestModuleInterfaces(); diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 10af9253d6..64f6118cfc 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -29,6 +29,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.Data; +using System.Diagnostics; using System.Globalization; using System.IO; using System.IO.Compression; @@ -1443,6 +1444,7 @@ namespace OpenSim.Framework } #endregion FireAndForget Threading Pattern + /// /// Environment.TickCount is an int but it counts all 32 bits so it goes positive /// and negative every 24.9 days. This trims down TickCount so it doesn't wrap @@ -1467,5 +1469,21 @@ namespace OpenSim.Framework Int32 diff = EnvironmentTickCount() - prevValue; return (diff >= 0) ? diff : (diff + EnvironmentTickCountMask + 1); } + + /// + /// Prints the call stack at any given point. Useful for debugging. + /// + public static void PrintCallStack() + { + StackTrace stackTrace = new StackTrace(); // get call stack + StackFrame[] stackFrames = stackTrace.GetFrames(); // get method calls (frames) + + // write call stack method names + foreach (StackFrame stackFrame in stackFrames) + { + m_log.Debug(stackFrame.GetMethod().DeclaringType + "." + stackFrame.GetMethod().Name); // write method name + } + } + } } diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/PresenceDetector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/PresenceDetector.cs index 891fc14750..e98df286fc 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/PresenceDetector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/PresenceDetector.cs @@ -77,23 +77,28 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence public void OnNewClient(IClientAPI client) { - client.OnLogout += OnLogout; + client.OnConnectionClosed += OnConnectionClose; } - public void OnLogout(IClientAPI client) + public void OnConnectionClose(IClientAPI client) { - client.OnLogout -= OnLogout; - - ScenePresence sp = null; - Vector3 position = new Vector3(128, 128, 0); - Vector3 lookat = new Vector3(0, 1, 0); - - if (m_aScene.TryGetAvatar(client.AgentId, out sp)) + if (client.IsLoggingOut) { - position = sp.AbsolutePosition; - lookat = sp.Lookat; + object sp = null; + Vector3 position = new Vector3(128, 128, 0); + Vector3 lookat = new Vector3(0, 1, 0); + + if (client.Scene.TryGetAvatar(client.AgentId, out sp)) + { + if (sp is ScenePresence) + { + position = ((ScenePresence)sp).AbsolutePosition; + lookat = ((ScenePresence)sp).Lookat; + } + } + + m_PresenceService.LogoutAgent(client.SessionId, position, lookat); } - m_PresenceService.LogoutAgent(client.SessionId, position, lookat); } } diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 30c69a865c..1eb3117a83 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -4216,7 +4216,7 @@ namespace OpenSim.Region.Framework.Scenes return m_sceneGraph.GetGroupByPrim(localID); } - public bool TryGetAvatar(UUID avatarId, out ScenePresence avatar) + public override bool TryGetAvatar(UUID avatarId, out ScenePresence avatar) { return m_sceneGraph.TryGetAvatar(avatarId, out avatar); } diff --git a/OpenSim/Region/Framework/Scenes/SceneBase.cs b/OpenSim/Region/Framework/Scenes/SceneBase.cs index 4f6e824e9f..74476edd3e 100644 --- a/OpenSim/Region/Framework/Scenes/SceneBase.cs +++ b/OpenSim/Region/Framework/Scenes/SceneBase.cs @@ -190,6 +190,21 @@ namespace OpenSim.Region.Framework.Scenes /// public abstract void RemoveClient(UUID agentID); + public bool TryGetAvatar(UUID agentID, out object scenePresence) + { + scenePresence = null; + ScenePresence sp = null; + if (TryGetAvatar(agentID, out sp)) + { + scenePresence = sp; + return true; + } + + return false; + } + + public abstract bool TryGetAvatar(UUID agentID, out ScenePresence scenePresence); + #endregion /// diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneBaseTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneBaseTests.cs index 8230f32c92..840039ca2a 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/SceneBaseTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneBaseTests.cs @@ -65,6 +65,11 @@ namespace OpenSim.Region.Framework.Scenes.Tests { throw new NotImplementedException(); } + + public override bool TryGetAvatar(UUID agentID, out ScenePresence scenePresence) + { + throw new NotImplementedException(); + } } [Test]