From 34073607a2e3a0c2452603a48c3ab8d45aee8f3f Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Wed, 27 Feb 2008 17:41:42 +0000 Subject: * Turned Friends Module into a shared module (to comply with Scene.AddXmlRPCHandler being shared). * Fixed a null ref issue in Scene.Close() --- .../Region/Environment/Modules/FriendsModule.cs | 79 ++++++++++++++++++---- OpenSim/Region/Environment/Scenes/Scene.cs | 7 +- 2 files changed, 73 insertions(+), 13 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Environment/Modules/FriendsModule.cs b/OpenSim/Region/Environment/Modules/FriendsModule.cs index 9a03aaf..53ed74a 100644 --- a/OpenSim/Region/Environment/Modules/FriendsModule.cs +++ b/OpenSim/Region/Environment/Modules/FriendsModule.cs @@ -35,6 +35,7 @@ using OpenSim.Framework.Console; using OpenSim.Region.Environment.Interfaces; using OpenSim.Region.Environment.Scenes; using libsecondlife; +using Nwc.XmlRpc; namespace OpenSim.Region.Environment.Modules { @@ -42,17 +43,31 @@ namespace OpenSim.Region.Environment.Modules { private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - private Scene m_scene; + private List m_scene = new List(); Dictionary m_pendingFriendRequests = new Dictionary(); public void Initialise(Scene scene, IConfigSource config) { - m_scene = scene; + lock (m_scene) + { + if (m_scene.Count == 0) + { + scene.AddXmlRPCHandler("presence_update", processPresenceUpdate); + } + + if (!m_scene.Contains(scene)) + m_scene.Add(scene); + } scene.EventManager.OnNewClient += OnNewClient; scene.EventManager.OnGridInstantMessageToFriendsModule += OnGridInstantMessage; + + } + public XmlRpcResponse processPresenceUpdate(XmlRpcRequest req) + { + m_log.Info("[FRIENDS]: Got Notification about a user! OMG"); + return new XmlRpcResponse(); } - private void OnNewClient(IClientAPI client) { // All friends establishment protocol goes over instant message @@ -112,7 +127,8 @@ namespace OpenSim.Region.Environment.Modules msg.Position = new sLLVector3(Position); msg.RegionID = RegionID.UUID; msg.binaryBucket = binaryBucket; - m_scene.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); + // We don't really care which scene we pipe it through. + m_scene[0].TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); } // 39 == Accept Friendship @@ -133,6 +149,14 @@ namespace OpenSim.Region.Environment.Modules if (m_pendingFriendRequests.ContainsKey(transactionID)) { // Found Pending Friend Request with that Transaction.. + Scene SceneAgentIn = m_scene[0]; + + // Found Pending Friend Request with that Transaction.. + ScenePresence agentpresence = GetPresenceFromAgentID(agentID); + if (agentpresence != null) + { + SceneAgentIn = agentpresence.Scene; + } // Compose response to other agent. GridInstantMessage msg = new GridInstantMessage(); @@ -145,13 +169,15 @@ namespace OpenSim.Region.Environment.Modules msg.message = agentID.UUID.ToString(); msg.ParentEstateID = 0; msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); - msg.RegionID = m_scene.RegionInfo.RegionID.UUID; + msg.RegionID = SceneAgentIn.RegionInfo.RegionID.UUID; msg.dialog = (byte)39;// Approved friend request msg.Position = new sLLVector3(); msg.offline = (byte)0; msg.binaryBucket = new byte[0]; - m_scene.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); - m_scene.StoreAddFriendship(m_pendingFriendRequests[transactionID], agentID, (uint)1); + // We don't really care which scene we pipe it through, it goes to the shared IM Module and/or the database + + SceneAgentIn.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); + SceneAgentIn.StoreAddFriendship(m_pendingFriendRequests[transactionID], agentID, (uint)1); m_pendingFriendRequests.Remove(transactionID); // TODO: Inform agent that the friend is online @@ -162,8 +188,14 @@ namespace OpenSim.Region.Environment.Modules { if (m_pendingFriendRequests.ContainsKey(transactionID)) { - // Found Pending Friend Request with that Transaction.. + Scene SceneAgentIn = m_scene[0]; + // Found Pending Friend Request with that Transaction.. + ScenePresence agentpresence = GetPresenceFromAgentID(agentID); + if (agentpresence != null) + { + SceneAgentIn = agentpresence.Scene; + } // Compose response to other agent. GridInstantMessage msg = new GridInstantMessage(); msg.toAgentID = m_pendingFriendRequests[transactionID].UUID; @@ -175,19 +207,19 @@ namespace OpenSim.Region.Environment.Modules msg.message = agentID.UUID.ToString(); msg.ParentEstateID = 0; msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); - msg.RegionID = m_scene.RegionInfo.RegionID.UUID; + msg.RegionID = SceneAgentIn.RegionInfo.RegionID.UUID; msg.dialog = (byte)40;// Deny friend request msg.Position = new sLLVector3(); msg.offline = (byte)0; msg.binaryBucket = new byte[0]; - m_scene.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); + SceneAgentIn.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); m_pendingFriendRequests.Remove(transactionID); } } private void OnTerminateFriendship(IClientAPI client, LLUUID agent, LLUUID exfriendID) { - m_scene.StoreRemoveFriendship(agent, exfriendID); + m_scene[0].StoreRemoveFriendship(agent, exfriendID); // TODO: Inform the client that the ExFriend is offline } @@ -201,6 +233,29 @@ namespace OpenSim.Region.Environment.Modules msg.binaryBucket); } + private ScenePresence GetPresenceFromAgentID(LLUUID AgentID) + { + ScenePresence returnAgent = null; + lock (m_scene) + { + ScenePresence queryagent = null; + for (int i = 0; i < m_scene.Count; i++) + { + queryagent = m_scene[i].GetScenePresence(AgentID); + if (queryagent != null) + { + if (!queryagent.IsChildAgent) + { + returnAgent = queryagent; + break; + } + } + } + } + return returnAgent; + + } + public void PostInitialise() { } @@ -216,7 +271,7 @@ namespace OpenSim.Region.Environment.Modules public bool IsSharedModule { - get { return false; } + get { return true; } } } } diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 32136be..f6e3d82 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -1466,7 +1466,12 @@ namespace OpenSim.Region.Environment.Scenes /// public override void RemoveClient(LLUUID agentID) { + bool childagentYN = false; ScenePresence avatar = GetScenePresence(agentID); + if (avatar != null) + { + childagentYN = avatar.IsChildAgent; + } try { if (avatar.IsChildAgent) @@ -1555,7 +1560,7 @@ namespace OpenSim.Region.Environment.Scenes } // Remove client agent from profile, so new logins will work - if (!avatar.IsChildAgent) + if (!childagentYN) { m_sceneGridService.ClearUserAgent(agentID); } -- cgit v1.1