diff options
author | onefang | 2019-05-19 21:24:15 +1000 |
---|---|---|
committer | onefang | 2019-05-19 21:24:15 +1000 |
commit | 5e4d6cab00cb29cd088ab7b62ab13aff103b64cb (patch) | |
tree | a9fbc62df9eb2d1d9ba2698d8552eae71eca20d8 /OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs | |
parent | Add a build script. (diff) | |
download | opensim-SC-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.zip opensim-SC-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.gz opensim-SC-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.bz2 opensim-SC-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.xz |
Dump OpenSim 0.9.0.1 into it's own branch.
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs | 132 |
1 files changed, 102 insertions, 30 deletions
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; | |||
39 | 39 | ||
40 | namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | 40 | namespace OpenSim.Region.CoreModules.Avatar.InstantMessage |
41 | { | 41 | { |
42 | public struct SendReply | ||
43 | { | ||
44 | public bool Success; | ||
45 | public string Message; | ||
46 | public int Disposition; | ||
47 | } | ||
48 | |||
42 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "OfflineMessageModule")] | 49 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "OfflineMessageModule")] |
43 | public class OfflineMessageModule : ISharedRegionModule | 50 | public class OfflineMessageModule : ISharedRegionModule |
44 | { | 51 | { |
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 52 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
46 | 53 | ||
47 | private bool enabled = true; | 54 | private bool enabled = true; |
55 | private bool m_UseNewAvnCode = false; | ||
48 | private List<Scene> m_SceneList = new List<Scene>(); | 56 | private List<Scene> m_SceneList = new List<Scene>(); |
49 | private string m_RestURL = String.Empty; | 57 | private string m_RestURL = String.Empty; |
50 | IMessageTransferModule m_TransferModule = null; | 58 | IMessageTransferModule m_TransferModule = null; |
51 | private bool m_ForwardOfflineGroupMessages = true; | 59 | private bool m_ForwardOfflineGroupMessages = true; |
60 | private Dictionary<IClientAPI, List<UUID>> m_repliesSent= new Dictionary<IClientAPI, List<UUID>>(); | ||
52 | 61 | ||
53 | public void Initialise(IConfigSource config) | 62 | public void Initialise(IConfigSource config) |
54 | { | 63 | { |
@@ -74,6 +83,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
74 | } | 83 | } |
75 | 84 | ||
76 | m_ForwardOfflineGroupMessages = cnf.GetBoolean("ForwardOfflineGroupMessages", m_ForwardOfflineGroupMessages); | 85 | m_ForwardOfflineGroupMessages = cnf.GetBoolean("ForwardOfflineGroupMessages", m_ForwardOfflineGroupMessages); |
86 | m_UseNewAvnCode = cnf.GetBoolean("UseNewAvnCode", m_UseNewAvnCode); | ||
77 | } | 87 | } |
78 | 88 | ||
79 | public void AddRegion(Scene scene) | 89 | public void AddRegion(Scene scene) |
@@ -138,7 +148,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
138 | { | 148 | { |
139 | get { return null; } | 149 | get { return null; } |
140 | } | 150 | } |
141 | 151 | ||
142 | public void Close() | 152 | public void Close() |
143 | { | 153 | { |
144 | } | 154 | } |
@@ -168,11 +178,21 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
168 | private void OnNewClient(IClientAPI client) | 178 | private void OnNewClient(IClientAPI client) |
169 | { | 179 | { |
170 | client.OnRetrieveInstantMessages += RetrieveInstantMessages; | 180 | client.OnRetrieveInstantMessages += RetrieveInstantMessages; |
181 | client.OnLogout += OnClientLoggedOut; | ||
182 | } | ||
183 | |||
184 | public void OnClientLoggedOut(IClientAPI client) | ||
185 | { | ||
186 | m_repliesSent.Remove(client); | ||
171 | } | 187 | } |
172 | 188 | ||
173 | private void RetrieveInstantMessages(IClientAPI client) | 189 | private void RetrieveInstantMessages(IClientAPI client) |
174 | { | 190 | { |
175 | if (m_RestURL != "") | 191 | if (m_RestURL == String.Empty) |
192 | { | ||
193 | return; | ||
194 | } | ||
195 | else | ||
176 | { | 196 | { |
177 | m_log.DebugFormat("[OFFLINE MESSAGING]: Retrieving stored messages for {0}", client.AgentId); | 197 | m_log.DebugFormat("[OFFLINE MESSAGING]: Retrieving stored messages for {0}", client.AgentId); |
178 | 198 | ||
@@ -180,28 +200,28 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
180 | = SynchronousRestObjectRequester.MakeRequest<UUID, List<GridInstantMessage>>( | 200 | = SynchronousRestObjectRequester.MakeRequest<UUID, List<GridInstantMessage>>( |
181 | "POST", m_RestURL + "/RetrieveMessages/", client.AgentId); | 201 | "POST", m_RestURL + "/RetrieveMessages/", client.AgentId); |
182 | 202 | ||
183 | if (msglist == null) | 203 | if (msglist != null) |
184 | { | ||
185 | m_log.WarnFormat("[OFFLINE MESSAGING]: WARNING null message list."); | ||
186 | return; | ||
187 | } | ||
188 | |||
189 | foreach (GridInstantMessage im in msglist) | ||
190 | { | 204 | { |
191 | if (im.dialog == (byte)InstantMessageDialog.InventoryOffered) | 205 | foreach (GridInstantMessage im in msglist) |
192 | // send it directly or else the item will be given twice | ||
193 | client.SendInstantMessage(im); | ||
194 | else | ||
195 | { | 206 | { |
196 | // Send through scene event manager so all modules get a chance | 207 | if (im.dialog == (byte)InstantMessageDialog.InventoryOffered) |
197 | // to look at this message before it gets delivered. | 208 | // send it directly or else the item will be given twice |
198 | // | 209 | client.SendInstantMessage(im); |
199 | // Needed for proper state management for stored group | 210 | else |
200 | // invitations | 211 | { |
201 | // | 212 | // Send through scene event manager so all modules get a chance |
202 | Scene s = FindScene(client.AgentId); | 213 | // to look at this message before it gets delivered. |
203 | if (s != null) | 214 | // |
204 | s.EventManager.TriggerIncomingInstantMessage(im); | 215 | // Needed for proper state management for stored group |
216 | // invitations | ||
217 | // | ||
218 | |||
219 | im.offline = 1; | ||
220 | |||
221 | Scene s = FindScene(client.AgentId); | ||
222 | if (s != null) | ||
223 | s.EventManager.TriggerIncomingInstantMessage(im); | ||
224 | } | ||
205 | } | 225 | } |
206 | } | 226 | } |
207 | } | 227 | } |
@@ -213,7 +233,8 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
213 | im.dialog != (byte)InstantMessageDialog.MessageFromAgent && | 233 | im.dialog != (byte)InstantMessageDialog.MessageFromAgent && |
214 | im.dialog != (byte)InstantMessageDialog.GroupNotice && | 234 | im.dialog != (byte)InstantMessageDialog.GroupNotice && |
215 | im.dialog != (byte)InstantMessageDialog.GroupInvitation && | 235 | im.dialog != (byte)InstantMessageDialog.GroupInvitation && |
216 | im.dialog != (byte)InstantMessageDialog.InventoryOffered) | 236 | im.dialog != (byte)InstantMessageDialog.InventoryOffered && |
237 | im.dialog != (byte)InstantMessageDialog.TaskInventoryOffered) | ||
217 | { | 238 | { |
218 | return; | 239 | return; |
219 | } | 240 | } |
@@ -225,22 +246,73 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
225 | return; | 246 | return; |
226 | } | 247 | } |
227 | 248 | ||
228 | bool success = SynchronousRestObjectRequester.MakeRequest<GridInstantMessage, bool>( | 249 | if(m_UseNewAvnCode) |
229 | "POST", m_RestURL+"/SaveMessage/", im, 10000); | 250 | { |
251 | Scene scene = FindScene(new UUID(im.fromAgentID)); | ||
252 | if (scene == null) | ||
253 | scene = m_SceneList[0]; | ||
230 | 254 | ||
231 | if (im.dialog == (byte)InstantMessageDialog.MessageFromAgent) | 255 | UUID scopeID = scene.RegionInfo.ScopeID; |
256 | SendReply reply = SynchronousRestObjectRequester.MakeRequest<GridInstantMessage, SendReply>( | ||
257 | "POST", m_RestURL+"/SaveMessage/?scope=" + scopeID.ToString(), im, 20000); | ||
258 | |||
259 | if (im.dialog == (byte)InstantMessageDialog.MessageFromAgent) | ||
260 | { | ||
261 | IClientAPI client = FindClient(new UUID(im.fromAgentID)); | ||
262 | if (client == null) | ||
263 | return; | ||
264 | |||
265 | if (string.IsNullOrEmpty(reply.Message)) | ||
266 | reply.Message = "User is not logged in. " + (reply.Success ? "Message saved." : "Message not saved"); | ||
267 | |||
268 | bool sendReply = true; | ||
269 | |||
270 | switch (reply.Disposition) | ||
271 | { | ||
272 | case 0: // Normal | ||
273 | break; | ||
274 | case 1: // Only once per user | ||
275 | if (m_repliesSent.ContainsKey(client) && m_repliesSent[client].Contains(new UUID(im.toAgentID))) | ||
276 | sendReply = false; | ||
277 | else | ||
278 | { | ||
279 | if (!m_repliesSent.ContainsKey(client)) | ||
280 | m_repliesSent[client] = new List<UUID>(); | ||
281 | m_repliesSent[client].Add(new UUID(im.toAgentID)); | ||
282 | } | ||
283 | break; | ||
284 | } | ||
285 | |||
286 | if (sendReply) | ||
287 | { | ||
288 | client.SendInstantMessage(new GridInstantMessage( | ||
289 | null, new UUID(im.toAgentID), | ||
290 | "System", new UUID(im.fromAgentID), | ||
291 | (byte)InstantMessageDialog.MessageFromAgent, | ||
292 | reply.Message, | ||
293 | false, new Vector3())); | ||
294 | } | ||
295 | } | ||
296 | } | ||
297 | else | ||
232 | { | 298 | { |
233 | IClientAPI client = FindClient(new UUID(im.fromAgentID)); | 299 | bool success = SynchronousRestObjectRequester.MakeRequest<GridInstantMessage, bool>( |
234 | if (client == null) | 300 | "POST", m_RestURL+"/SaveMessage/", im, 20000); |
235 | return; | 301 | |
302 | if (im.dialog == (byte)InstantMessageDialog.MessageFromAgent) | ||
303 | { | ||
304 | IClientAPI client = FindClient(new UUID(im.fromAgentID)); | ||
305 | if (client == null) | ||
306 | return; | ||
236 | 307 | ||
237 | client.SendInstantMessage(new GridInstantMessage( | 308 | client.SendInstantMessage(new GridInstantMessage( |
238 | null, new UUID(im.toAgentID), | 309 | null, new UUID(im.toAgentID), |
239 | "System", new UUID(im.fromAgentID), | 310 | "System", new UUID(im.fromAgentID), |
240 | (byte)InstantMessageDialog.MessageFromAgent, | 311 | (byte)InstantMessageDialog.MessageFromAgent, |
241 | "User is not logged in. "+ | 312 | "User is not logged in. "+ |
242 | (success ? "Message saved." : "Message not saved"), | 313 | (success ? "Message saved." : "Message not saved"), |
243 | false, new Vector3())); | 314 | false, new Vector3())); |
315 | } | ||
244 | } | 316 | } |
245 | } | 317 | } |
246 | } | 318 | } |