From 27e557eb9857ccc34ae3588c4e0ff43bd5e6644a Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Sun, 16 Nov 2008 00:47:21 +0000 Subject: Introduces the message transfer module. It splits the transfer mechanics off the IM module and makes it into a module of it's own, which can be used by all other modules. Removes some ugly hacks. Refer to the IM module to see how it's used. Also fixes the persistence issue (Mantis #2598) --- .../Modules/Avatar/Friends/FriendsModule.cs | 58 ++++++++++++++-------- 1 file changed, 38 insertions(+), 20 deletions(-) (limited to 'OpenSim/Region/Environment/Modules/Avatar/Friends') diff --git a/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs index 58251cb..72c64ad 100644 --- a/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs @@ -36,6 +36,7 @@ using Nwc.XmlRpc; using OpenSim.Framework; using OpenSim.Framework.Communications.Cache; using OpenSim.Framework.Servers; +using OpenSim.Region.Interfaces; using OpenSim.Region.Environment.Interfaces; using OpenSim.Region.Environment.Scenes; @@ -105,6 +106,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends private Scene m_initialScene; // saves a lookup if we don't have a specific scene private Dictionary m_scenes = new Dictionary(); + private IMessageTransferModule m_TransferModule = null; #region IRegionModule Members @@ -124,7 +126,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends m_scenes[scene.RegionInfo.RegionHandle] = scene; } scene.EventManager.OnNewClient += OnNewClient; - scene.EventManager.OnGridInstantMessage += OnGridInstantMessage; + scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage; scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel; scene.EventManager.OnMakeChildAgent += MakeChildAgent; scene.EventManager.OnClientClosed += ClientClosed; @@ -132,6 +134,10 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends public void PostInitialise() { + List scenes = new List(m_scenes.Values); + m_TransferModule = scenes[0].RequestModuleInterface(); + if (m_TransferModule == null) + m_log.Error("[FRIENDS]: Unable to find a message transfer module, friendship offers will not work"); } public void Close() @@ -434,11 +440,14 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends // we don't want to get that new IM into here if we aren't local, as only on the destination // should receive it. If we *are* local, *we* are the destination, so we have to receive it. // As grid-IMs are routed to all modules (in contrast to local IMs), we have to decide here. - InstantMessageReceiver recv = InstantMessageReceiver.IMModule; - if (GetAnyPresenceFromAgentID(toAgentID) != null) recv |= InstantMessageReceiver.FriendsModule; // We don't really care which local scene we pipe it through. - m_initialScene.TriggerGridInstantMessage(msg, recv); + if (m_TransferModule != null) + { + m_TransferModule.SendInstantMessage(msg, + delegate(bool success) {} + ); + } } else { @@ -531,17 +540,20 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends } } - private void OnGridInstantMessage(GridInstantMessage msg, InstantMessageReceiver whichModule) + private void OnGridInstantMessage(GridInstantMessage msg) { - if ((whichModule & InstantMessageReceiver.FriendsModule) == 0) - return; - - // Trigger the above event handler - OnInstantMessage(null, new UUID(msg.fromAgentID), new UUID(msg.fromAgentSession), - new UUID(msg.toAgentID), new UUID(msg.imSessionID), msg.timestamp, msg.fromAgentName, - msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID, - new Vector3(msg.Position.X, msg.Position.Y, msg.Position.Z), new UUID(msg.RegionID), - msg.binaryBucket); + // Just call the IM handler above + // This event won't be raised unless we have that agent, + // so we can depend on the above not trying to send + // via grid again + // + OnInstantMessage(null, new UUID(msg.fromAgentID), + new UUID(msg.fromAgentSession), + new UUID(msg.toAgentID), new UUID(msg.imSessionID), + msg.timestamp, msg.fromAgentName, msg.message, + msg.dialog, msg.fromGroup, msg.offline, + msg.ParentEstateID, msg.Position, + new UUID(msg.RegionID), msg.binaryBucket); } private void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID transactionID, List callingCardFolders) @@ -607,12 +619,15 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends // we don't want to get that new IM into here if we aren't local, as only on the destination // should receive it. If we *are* local, *we* are the destination, so we have to receive it. // As grid-IMs are routed to all modules (in contrast to local IMs), we have to decide here. - InstantMessageReceiver recv = InstantMessageReceiver.IMModule; - if (GetAnyPresenceFromAgentID(friendID) != null) recv |= InstantMessageReceiver.FriendsModule; // now we have to inform the agent about the friend. For the opposite direction, this happens in the handler // of the type 39 IM - SceneAgentIn.TriggerGridInstantMessage(msg, recv); + if (m_TransferModule != null) + { + m_TransferModule.SendInstantMessage(msg, + delegate(bool success) {} + ); + } // tell client that new friend is online client.SendAgentOnline(new UUID[] { friendID }); @@ -664,12 +679,15 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends // we don't want to get that new IM into here if we aren't local, as only on the destination // should receive it. If we *are* local, *we* are the destination, so we have to receive it. // As grid-IMs are routed to all modules (in contrast to local IMs), we have to decide here. - InstantMessageReceiver recv = InstantMessageReceiver.IMModule; - if (GetAnyPresenceFromAgentID(friendID) != null) recv |= InstantMessageReceiver.FriendsModule; // now we have to inform the agent about the friend. For the opposite direction, this happens in the handler // of the type 39 IM - SceneAgentIn.TriggerGridInstantMessage(msg, recv); + if (m_TransferModule != null) + { + m_TransferModule.SendInstantMessage(msg, + delegate(bool success) {} + ); + } } private void OnTerminateFriendship(IClientAPI client, UUID agentID, UUID exfriendID) -- cgit v1.1