aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs
diff options
context:
space:
mode:
authorUbitUmarov2015-09-01 11:43:07 +0100
committerUbitUmarov2015-09-01 11:43:07 +0100
commitfb78b182520fc9bb0f971afd0322029c70278ea6 (patch)
treeb4e30d383938fdeef8c92d1d1c2f44bb61d329bd /OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs
parentlixo (diff)
parentMantis #7713: fixed bug introduced by 1st MOSES patch. (diff)
downloadopensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.zip
opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.gz
opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.bz2
opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.xz
Merge remote-tracking branch 'os/master'
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs249
1 files changed, 249 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs
new file mode 100644
index 0000000..c75920d
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs
@@ -0,0 +1,249 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27using System;
28using System.Collections.Generic;
29using System.Reflection;
30using log4net;
31using Mono.Addins;
32using Nini.Config;
33using OpenMetaverse;
34using OpenSim.Framework;
35using OpenSim.Framework.Communications;
36using OpenSim.Framework.Servers;
37using OpenSim.Framework.Client;
38using OpenSim.Region.Framework.Interfaces;
39using OpenSim.Region.Framework.Scenes;
40
41namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
42{
43 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "OfflineMessageModule")]
44 public class OfflineMessageModule : ISharedRegionModule
45 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47
48 private bool enabled = true;
49 private List<Scene> m_SceneList = new List<Scene>();
50 private string m_RestURL = String.Empty;
51 IMessageTransferModule m_TransferModule = null;
52 private bool m_ForwardOfflineGroupMessages = true;
53
54 public void Initialise(IConfigSource config)
55 {
56 IConfig cnf = config.Configs["Messaging"];
57 if (cnf == null)
58 {
59 enabled = false;
60 return;
61 }
62 if (cnf != null && cnf.GetString("OfflineMessageModule", "None") !=
63 "OfflineMessageModule")
64 {
65 enabled = false;
66 return;
67 }
68
69 m_RestURL = cnf.GetString("OfflineMessageURL", "");
70 if (m_RestURL == "")
71 {
72 m_log.Error("[OFFLINE MESSAGING] Module was enabled, but no URL is given, disabling");
73 enabled = false;
74 return;
75 }
76
77 m_ForwardOfflineGroupMessages = cnf.GetBoolean("ForwardOfflineGroupMessages", m_ForwardOfflineGroupMessages);
78 }
79
80 public void AddRegion(Scene scene)
81 {
82 if (!enabled)
83 return;
84
85 lock (m_SceneList)
86 {
87 m_SceneList.Add(scene);
88
89 scene.EventManager.OnNewClient += OnNewClient;
90 }
91 }
92
93 public void RegionLoaded(Scene scene)
94 {
95 if (!enabled)
96 return;
97
98 if (m_TransferModule == null)
99 {
100 m_TransferModule = scene.RequestModuleInterface<IMessageTransferModule>();
101 if (m_TransferModule == null)
102 {
103 scene.EventManager.OnNewClient -= OnNewClient;
104
105 enabled = false;
106 m_SceneList.Clear();
107
108 m_log.Error("[OFFLINE MESSAGING] No message transfer module is enabled. Diabling offline messages");
109 }
110 m_TransferModule.OnUndeliveredMessage += UndeliveredMessage;
111 }
112 }
113
114 public void RemoveRegion(Scene scene)
115 {
116 if (!enabled)
117 return;
118
119 lock (m_SceneList)
120 {
121 m_SceneList.Remove(scene);
122 }
123 }
124
125 public void PostInitialise()
126 {
127 if (!enabled)
128 return;
129
130 m_log.Debug("[OFFLINE MESSAGING] Offline messages enabled");
131 }
132
133 public string Name
134 {
135 get { return "OfflineMessageModule"; }
136 }
137
138 public Type ReplaceableInterface
139 {
140 get { return null; }
141 }
142
143 public void Close()
144 {
145 }
146
147 private Scene FindScene(UUID agentID)
148 {
149 foreach (Scene s in m_SceneList)
150 {
151 ScenePresence presence = s.GetScenePresence(agentID);
152 if (presence != null && !presence.IsChildAgent)
153 return s;
154 }
155 return null;
156 }
157
158 private IClientAPI FindClient(UUID agentID)
159 {
160 foreach (Scene s in m_SceneList)
161 {
162 ScenePresence presence = s.GetScenePresence(agentID);
163 if (presence != null && !presence.IsChildAgent)
164 return presence.ControllingClient;
165 }
166 return null;
167 }
168
169 private void OnNewClient(IClientAPI client)
170 {
171 client.OnRetrieveInstantMessages += RetrieveInstantMessages;
172 }
173
174 private void RetrieveInstantMessages(IClientAPI client)
175 {
176 if (m_RestURL != "")
177 {
178 m_log.DebugFormat("[OFFLINE MESSAGING]: Retrieving stored messages for {0}", client.AgentId);
179
180 List<GridInstantMessage> msglist
181 = SynchronousRestObjectRequester.MakeRequest<UUID, List<GridInstantMessage>>(
182 "POST", m_RestURL + "/RetrieveMessages/", client.AgentId);
183
184 if (msglist == null)
185 {
186 m_log.WarnFormat("[OFFLINE MESSAGING]: WARNING null message list.");
187 return;
188 }
189
190 foreach (GridInstantMessage im in msglist)
191 {
192 if (im.dialog == (byte)InstantMessageDialog.InventoryOffered)
193 // send it directly or else the item will be given twice
194 client.SendInstantMessage(im);
195 else
196 {
197 // Send through scene event manager so all modules get a chance
198 // to look at this message before it gets delivered.
199 //
200 // Needed for proper state management for stored group
201 // invitations
202 //
203 Scene s = FindScene(client.AgentId);
204 if (s != null)
205 s.EventManager.TriggerIncomingInstantMessage(im);
206 }
207 }
208 }
209 }
210
211 private void UndeliveredMessage(GridInstantMessage im)
212 {
213 if (im.dialog != (byte)InstantMessageDialog.MessageFromObject &&
214 im.dialog != (byte)InstantMessageDialog.MessageFromAgent &&
215 im.dialog != (byte)InstantMessageDialog.GroupNotice &&
216 im.dialog != (byte)InstantMessageDialog.GroupInvitation &&
217 im.dialog != (byte)InstantMessageDialog.InventoryOffered)
218 {
219 return;
220 }
221
222 if (!m_ForwardOfflineGroupMessages)
223 {
224 if (im.dialog == (byte)InstantMessageDialog.GroupNotice ||
225 im.dialog == (byte)InstantMessageDialog.GroupInvitation)
226 return;
227 }
228
229 bool success = SynchronousRestObjectRequester.MakeRequest<GridInstantMessage, bool>(
230 "POST", m_RestURL+"/SaveMessage/", im, 10000);
231
232 if (im.dialog == (byte)InstantMessageDialog.MessageFromAgent)
233 {
234 IClientAPI client = FindClient(new UUID(im.fromAgentID));
235 if (client == null)
236 return;
237
238 client.SendInstantMessage(new GridInstantMessage(
239 null, new UUID(im.toAgentID),
240 "System", new UUID(im.fromAgentID),
241 (byte)InstantMessageDialog.MessageFromAgent,
242 "User is not logged in. "+
243 (success ? "Message saved." : "Message not saved"),
244 false, new Vector3()));
245 }
246 }
247 }
248}
249