From 5e4d6cab00cb29cd088ab7b62ab13aff103b64cb Mon Sep 17 00:00:00 2001 From: onefang Date: Sun, 19 May 2019 21:24:15 +1000 Subject: Dump OpenSim 0.9.0.1 into it's own branch. --- .../Avatar/InstantMessage/OfflineMessageModule.cs | 132 ++++++++++++++++----- 1 file changed, 102 insertions(+), 30 deletions(-) (limited to 'OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs') diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs index 9cdb1c2..315ce1b 100644 --- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs @@ -39,16 +39,25 @@ using OpenSim.Region.Framework.Scenes; namespace OpenSim.Region.CoreModules.Avatar.InstantMessage { + public struct SendReply + { + public bool Success; + public string Message; + public int Disposition; + } + [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "OfflineMessageModule")] public class OfflineMessageModule : ISharedRegionModule { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private bool enabled = true; + private bool m_UseNewAvnCode = false; private List m_SceneList = new List(); private string m_RestURL = String.Empty; IMessageTransferModule m_TransferModule = null; private bool m_ForwardOfflineGroupMessages = true; + private Dictionary> m_repliesSent= new Dictionary>(); public void Initialise(IConfigSource config) { @@ -74,6 +83,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage } m_ForwardOfflineGroupMessages = cnf.GetBoolean("ForwardOfflineGroupMessages", m_ForwardOfflineGroupMessages); + m_UseNewAvnCode = cnf.GetBoolean("UseNewAvnCode", m_UseNewAvnCode); } public void AddRegion(Scene scene) @@ -138,7 +148,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage { get { return null; } } - + public void Close() { } @@ -168,11 +178,21 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage private void OnNewClient(IClientAPI client) { client.OnRetrieveInstantMessages += RetrieveInstantMessages; + client.OnLogout += OnClientLoggedOut; + } + + public void OnClientLoggedOut(IClientAPI client) + { + m_repliesSent.Remove(client); } private void RetrieveInstantMessages(IClientAPI client) { - if (m_RestURL != "") + if (m_RestURL == String.Empty) + { + return; + } + else { m_log.DebugFormat("[OFFLINE MESSAGING]: Retrieving stored messages for {0}", client.AgentId); @@ -180,28 +200,28 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage = SynchronousRestObjectRequester.MakeRequest>( "POST", m_RestURL + "/RetrieveMessages/", client.AgentId); - if (msglist == null) - { - m_log.WarnFormat("[OFFLINE MESSAGING]: WARNING null message list."); - return; - } - - foreach (GridInstantMessage im in msglist) + if (msglist != null) { - if (im.dialog == (byte)InstantMessageDialog.InventoryOffered) - // send it directly or else the item will be given twice - client.SendInstantMessage(im); - else + foreach (GridInstantMessage im in msglist) { - // Send through scene event manager so all modules get a chance - // to look at this message before it gets delivered. - // - // Needed for proper state management for stored group - // invitations - // - Scene s = FindScene(client.AgentId); - if (s != null) - s.EventManager.TriggerIncomingInstantMessage(im); + if (im.dialog == (byte)InstantMessageDialog.InventoryOffered) + // send it directly or else the item will be given twice + client.SendInstantMessage(im); + else + { + // Send through scene event manager so all modules get a chance + // to look at this message before it gets delivered. + // + // Needed for proper state management for stored group + // invitations + // + + im.offline = 1; + + Scene s = FindScene(client.AgentId); + if (s != null) + s.EventManager.TriggerIncomingInstantMessage(im); + } } } } @@ -213,7 +233,8 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage im.dialog != (byte)InstantMessageDialog.MessageFromAgent && im.dialog != (byte)InstantMessageDialog.GroupNotice && im.dialog != (byte)InstantMessageDialog.GroupInvitation && - im.dialog != (byte)InstantMessageDialog.InventoryOffered) + im.dialog != (byte)InstantMessageDialog.InventoryOffered && + im.dialog != (byte)InstantMessageDialog.TaskInventoryOffered) { return; } @@ -225,22 +246,73 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage return; } - bool success = SynchronousRestObjectRequester.MakeRequest( - "POST", m_RestURL+"/SaveMessage/", im, 10000); + if(m_UseNewAvnCode) + { + Scene scene = FindScene(new UUID(im.fromAgentID)); + if (scene == null) + scene = m_SceneList[0]; - if (im.dialog == (byte)InstantMessageDialog.MessageFromAgent) + UUID scopeID = scene.RegionInfo.ScopeID; + SendReply reply = SynchronousRestObjectRequester.MakeRequest( + "POST", m_RestURL+"/SaveMessage/?scope=" + scopeID.ToString(), im, 20000); + + if (im.dialog == (byte)InstantMessageDialog.MessageFromAgent) + { + IClientAPI client = FindClient(new UUID(im.fromAgentID)); + if (client == null) + return; + + if (string.IsNullOrEmpty(reply.Message)) + reply.Message = "User is not logged in. " + (reply.Success ? "Message saved." : "Message not saved"); + + bool sendReply = true; + + switch (reply.Disposition) + { + case 0: // Normal + break; + case 1: // Only once per user + if (m_repliesSent.ContainsKey(client) && m_repliesSent[client].Contains(new UUID(im.toAgentID))) + sendReply = false; + else + { + if (!m_repliesSent.ContainsKey(client)) + m_repliesSent[client] = new List(); + m_repliesSent[client].Add(new UUID(im.toAgentID)); + } + break; + } + + if (sendReply) + { + client.SendInstantMessage(new GridInstantMessage( + null, new UUID(im.toAgentID), + "System", new UUID(im.fromAgentID), + (byte)InstantMessageDialog.MessageFromAgent, + reply.Message, + false, new Vector3())); + } + } + } + else { - IClientAPI client = FindClient(new UUID(im.fromAgentID)); - if (client == null) - return; + bool success = SynchronousRestObjectRequester.MakeRequest( + "POST", m_RestURL+"/SaveMessage/", im, 20000); + + if (im.dialog == (byte)InstantMessageDialog.MessageFromAgent) + { + IClientAPI client = FindClient(new UUID(im.fromAgentID)); + if (client == null) + return; - client.SendInstantMessage(new GridInstantMessage( + client.SendInstantMessage(new GridInstantMessage( null, new UUID(im.toAgentID), "System", new UUID(im.fromAgentID), (byte)InstantMessageDialog.MessageFromAgent, "User is not logged in. "+ (success ? "Message saved." : "Message not saved"), false, new Vector3())); + } } } } -- cgit v1.1