diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Addons/Groups/GroupsMessagingModule.cs | 435 |
1 files changed, 315 insertions, 120 deletions
diff --git a/OpenSim/Addons/Groups/GroupsMessagingModule.cs b/OpenSim/Addons/Groups/GroupsMessagingModule.cs index d172d48..5de1fb4 100644 --- a/OpenSim/Addons/Groups/GroupsMessagingModule.cs +++ b/OpenSim/Addons/Groups/GroupsMessagingModule.cs | |||
@@ -39,6 +39,7 @@ using OpenSim.Region.Framework.Interfaces; | |||
39 | using OpenSim.Region.Framework.Scenes; | 39 | using OpenSim.Region.Framework.Scenes; |
40 | using OpenSim.Services.Interfaces; | 40 | using OpenSim.Services.Interfaces; |
41 | using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo; | 41 | using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo; |
42 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
42 | 43 | ||
43 | namespace OpenSim.Groups | 44 | namespace OpenSim.Groups |
44 | { | 45 | { |
@@ -51,7 +52,7 @@ namespace OpenSim.Groups | |||
51 | private IPresenceService m_presenceService; | 52 | private IPresenceService m_presenceService; |
52 | 53 | ||
53 | private IMessageTransferModule m_msgTransferModule = null; | 54 | private IMessageTransferModule m_msgTransferModule = null; |
54 | 55 | private IUserManagement m_UserManagement = null; | |
55 | private IGroupsServicesConnector m_groupData = null; | 56 | private IGroupsServicesConnector m_groupData = null; |
56 | 57 | ||
57 | // Config Options | 58 | // Config Options |
@@ -79,6 +80,10 @@ namespace OpenSim.Groups | |||
79 | 80 | ||
80 | private int m_usersOnlineCacheExpirySeconds = 20; | 81 | private int m_usersOnlineCacheExpirySeconds = 20; |
81 | 82 | ||
83 | private Dictionary<UUID, List<string>> m_groupsAgentsDroppedFromChatSession = new Dictionary<UUID, List<string>>(); | ||
84 | private Dictionary<UUID, List<string>> m_groupsAgentsInvitedToChatSession = new Dictionary<UUID, List<string>>(); | ||
85 | |||
86 | |||
82 | #region Region Module interfaceBase Members | 87 | #region Region Module interfaceBase Members |
83 | 88 | ||
84 | public void Initialise(IConfigSource config) | 89 | public void Initialise(IConfigSource config) |
@@ -124,10 +129,12 @@ namespace OpenSim.Groups | |||
124 | m_sceneList.Add(scene); | 129 | m_sceneList.Add(scene); |
125 | 130 | ||
126 | scene.EventManager.OnNewClient += OnNewClient; | 131 | scene.EventManager.OnNewClient += OnNewClient; |
132 | scene.EventManager.OnMakeRootAgent += OnMakeRootAgent; | ||
133 | scene.EventManager.OnMakeChildAgent += OnMakeChildAgent; | ||
127 | scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage; | 134 | scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage; |
128 | scene.EventManager.OnClientLogin += OnClientLogin; | 135 | scene.EventManager.OnClientLogin += OnClientLogin; |
129 | } | 136 | } |
130 | 137 | ||
131 | public void RegionLoaded(Scene scene) | 138 | public void RegionLoaded(Scene scene) |
132 | { | 139 | { |
133 | if (!m_groupMessagingEnabled) | 140 | if (!m_groupMessagingEnabled) |
@@ -155,6 +162,17 @@ namespace OpenSim.Groups | |||
155 | return; | 162 | return; |
156 | } | 163 | } |
157 | 164 | ||
165 | m_UserManagement = scene.RequestModuleInterface<IUserManagement>(); | ||
166 | |||
167 | // No groups module, no groups messaging | ||
168 | if (m_UserManagement == null) | ||
169 | { | ||
170 | m_log.Error("[Groups.Messaging]: Could not get IUserManagement, GroupsMessagingModule is now disabled."); | ||
171 | RemoveRegion(scene); | ||
172 | return; | ||
173 | } | ||
174 | |||
175 | |||
158 | if (m_presenceService == null) | 176 | if (m_presenceService == null) |
159 | m_presenceService = scene.PresenceService; | 177 | m_presenceService = scene.PresenceService; |
160 | 178 | ||
@@ -227,87 +245,106 @@ namespace OpenSim.Groups | |||
227 | 245 | ||
228 | public void SendMessageToGroup(GridInstantMessage im, UUID groupID) | 246 | public void SendMessageToGroup(GridInstantMessage im, UUID groupID) |
229 | { | 247 | { |
230 | List<GroupMembersData> groupMembers = m_groupData.GetGroupMembers(new UUID(im.fromAgentID).ToString(), groupID); | 248 | UUID fromAgentID = new UUID(im.fromAgentID); |
249 | List<GroupMembersData> groupMembers = m_groupData.GetGroupMembers("all", groupID); | ||
231 | int groupMembersCount = groupMembers.Count; | 250 | int groupMembersCount = groupMembers.Count; |
251 | PresenceInfo[] onlineAgents = null; | ||
232 | 252 | ||
233 | if (m_messageOnlineAgentsOnly) | 253 | // In V2 we always only send to online members. |
234 | { | 254 | // Sending to offline members is not an option. |
235 | string[] t1 = groupMembers.ConvertAll<string>(gmd => gmd.AgentID.ToString()).ToArray(); | 255 | string[] t1 = groupMembers.ConvertAll<string>(gmd => gmd.AgentID.ToString()).ToArray(); |
236 | 256 | ||
237 | // We cache in order not to overwhlem the presence service on large grids with many groups. This does | 257 | // We cache in order not to overwhlem the presence service on large grids with many groups. This does |
238 | // mean that members coming online will not see all group members until after m_usersOnlineCacheExpirySeconds has elapsed. | 258 | // mean that members coming online will not see all group members until after m_usersOnlineCacheExpirySeconds has elapsed. |
239 | // (assuming this is the same across all grid simulators). | 259 | // (assuming this is the same across all grid simulators). |
240 | PresenceInfo[] onlineAgents; | 260 | if (!m_usersOnlineCache.TryGetValue(groupID, out onlineAgents)) |
241 | if (!m_usersOnlineCache.TryGetValue(groupID, out onlineAgents)) | 261 | { |
242 | { | 262 | onlineAgents = m_presenceService.GetAgents(t1); |
243 | onlineAgents = m_presenceService.GetAgents(t1); | 263 | m_usersOnlineCache.Add(groupID, onlineAgents, m_usersOnlineCacheExpirySeconds); |
244 | m_usersOnlineCache.Add(groupID, onlineAgents, m_usersOnlineCacheExpirySeconds); | 264 | } |
245 | } | ||
246 | 265 | ||
247 | HashSet<string> onlineAgentsUuidSet = new HashSet<string>(); | 266 | HashSet<string> onlineAgentsUuidSet = new HashSet<string>(); |
248 | Array.ForEach<PresenceInfo>(onlineAgents, pi => onlineAgentsUuidSet.Add(pi.UserID)); | 267 | Array.ForEach<PresenceInfo>(onlineAgents, pi => onlineAgentsUuidSet.Add(pi.UserID)); |
249 | 268 | ||
250 | groupMembers = groupMembers.Where(gmd => onlineAgentsUuidSet.Contains(gmd.AgentID.ToString())).ToList(); | 269 | groupMembers = groupMembers.Where(gmd => onlineAgentsUuidSet.Contains(gmd.AgentID.ToString())).ToList(); |
251 | 270 | ||
252 | // if (m_debugEnabled) | 271 | // if (m_debugEnabled) |
253 | // m_log.DebugFormat( | 272 | // m_log.DebugFormat( |
254 | // "[Groups.Messaging]: SendMessageToGroup called for group {0} with {1} visible members, {2} online", | 273 | // "[Groups.Messaging]: SendMessageToGroup called for group {0} with {1} visible members, {2} online", |
255 | // groupID, groupMembersCount, groupMembers.Count()); | 274 | // groupID, groupMembersCount, groupMembers.Count()); |
256 | } | 275 | |
257 | else | 276 | int requestStartTick = Environment.TickCount; |
277 | |||
278 | im.imSessionID = groupID.Guid; | ||
279 | im.fromGroup = true; | ||
280 | IClientAPI thisClient = GetActiveClient(fromAgentID); | ||
281 | if (thisClient != null) | ||
258 | { | 282 | { |
259 | if (m_debugEnabled) | 283 | im.RegionID = thisClient.Scene.RegionInfo.RegionID.Guid; |
260 | m_log.DebugFormat( | ||
261 | "[Groups.Messaging]: SendMessageToGroup called for group {0} with {1} visible members", | ||
262 | groupID, groupMembers.Count); | ||
263 | } | 284 | } |
264 | 285 | ||
265 | int requestStartTick = Environment.TickCount; | 286 | // Send to self first of all |
287 | im.toAgentID = im.fromAgentID; | ||
288 | im.fromGroup = true; | ||
289 | ProcessMessageFromGroupSession(im); | ||
266 | 290 | ||
291 | List<UUID> regions = new List<UUID>(); | ||
292 | List<UUID> clientsAlreadySent = new List<UUID>(); | ||
293 | |||
294 | // Then send to everybody else | ||
267 | foreach (GroupMembersData member in groupMembers) | 295 | foreach (GroupMembersData member in groupMembers) |
268 | { | 296 | { |
269 | if (m_groupData.hasAgentDroppedGroupChatSession(member.AgentID.ToString(), groupID)) | 297 | if (member.AgentID.Guid == im.fromAgentID) |
298 | continue; | ||
299 | |||
300 | if (hasAgentDroppedGroupChatSession(member.AgentID.ToString(), groupID)) | ||
270 | { | 301 | { |
271 | // Don't deliver messages to people who have dropped this session | 302 | // Don't deliver messages to people who have dropped this session |
272 | if (m_debugEnabled) m_log.DebugFormat("[Groups.Messaging]: {0} has dropped session, not delivering to them", member.AgentID); | 303 | if (m_debugEnabled) m_log.DebugFormat("[Groups.Messaging]: {0} has dropped session, not delivering to them", member.AgentID); |
273 | continue; | 304 | continue; |
274 | } | 305 | } |
275 | 306 | ||
276 | // Copy Message | 307 | im.toAgentID = member.AgentID.Guid; |
277 | GridInstantMessage msg = new GridInstantMessage(); | ||
278 | msg.imSessionID = groupID.Guid; | ||
279 | msg.fromAgentName = im.fromAgentName; | ||
280 | msg.message = im.message; | ||
281 | msg.dialog = im.dialog; | ||
282 | msg.offline = im.offline; | ||
283 | msg.ParentEstateID = im.ParentEstateID; | ||
284 | msg.Position = im.Position; | ||
285 | msg.RegionID = im.RegionID; | ||
286 | msg.binaryBucket = im.binaryBucket; | ||
287 | msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); | ||
288 | |||
289 | msg.fromAgentID = im.fromAgentID; | ||
290 | msg.fromGroup = true; | ||
291 | |||
292 | msg.toAgentID = member.AgentID.Guid; | ||
293 | 308 | ||
294 | IClientAPI client = GetActiveClient(member.AgentID); | 309 | IClientAPI client = GetActiveClient(member.AgentID); |
295 | if (client == null) | 310 | if (client == null) |
296 | { | 311 | { |
297 | // If they're not local, forward across the grid | 312 | // If they're not local, forward across the grid |
313 | // BUT do it only once per region, please! Sim would be even better! | ||
298 | if (m_debugEnabled) m_log.DebugFormat("[Groups.Messaging]: Delivering to {0} via Grid", member.AgentID); | 314 | if (m_debugEnabled) m_log.DebugFormat("[Groups.Messaging]: Delivering to {0} via Grid", member.AgentID); |
299 | m_msgTransferModule.SendInstantMessage(msg, delegate(bool success) { }); | 315 | |
316 | bool reallySend = true; | ||
317 | if (onlineAgents != null) | ||
318 | { | ||
319 | PresenceInfo presence = onlineAgents.First(p => p.UserID == member.AgentID.ToString()); | ||
320 | if (regions.Contains(presence.RegionID)) | ||
321 | reallySend = false; | ||
322 | else | ||
323 | regions.Add(presence.RegionID); | ||
324 | } | ||
325 | |||
326 | if (reallySend) | ||
327 | { | ||
328 | // We have to create a new IM structure because the transfer module | ||
329 | // uses async send | ||
330 | GridInstantMessage msg = new GridInstantMessage(im, true); | ||
331 | m_msgTransferModule.SendInstantMessage(msg, delegate(bool success) { }); | ||
332 | } | ||
300 | } | 333 | } |
301 | else | 334 | else |
302 | { | 335 | { |
303 | // Deliver locally, directly | 336 | // Deliver locally, directly |
304 | if (m_debugEnabled) m_log.DebugFormat("[Groups.Messaging]: Passing to ProcessMessageFromGroupSession to deliver to {0} locally", client.Name); | 337 | if (m_debugEnabled) m_log.DebugFormat("[Groups.Messaging]: Passing to ProcessMessageFromGroupSession to deliver to {0} locally", client.Name); |
305 | ProcessMessageFromGroupSession(msg); | 338 | |
339 | if (clientsAlreadySent.Contains(member.AgentID)) | ||
340 | continue; | ||
341 | clientsAlreadySent.Add(member.AgentID); | ||
342 | |||
343 | ProcessMessageFromGroupSession(im); | ||
306 | } | 344 | } |
307 | } | 345 | } |
308 | 346 | ||
309 | // Temporary for assessing how long it still takes to send messages to large online groups. | 347 | if (m_debugEnabled) |
310 | if (m_messageOnlineAgentsOnly) | ||
311 | m_log.DebugFormat( | 348 | m_log.DebugFormat( |
312 | "[Groups.Messaging]: SendMessageToGroup for group {0} with {1} visible members, {2} online took {3}ms", | 349 | "[Groups.Messaging]: SendMessageToGroup for group {0} with {1} visible members, {2} online took {3}ms", |
313 | groupID, groupMembersCount, groupMembers.Count(), Environment.TickCount - requestStartTick); | 350 | groupID, groupMembersCount, groupMembers.Count(), Environment.TickCount - requestStartTick); |
@@ -324,9 +361,20 @@ namespace OpenSim.Groups | |||
324 | { | 361 | { |
325 | if (m_debugEnabled) m_log.DebugFormat("[Groups.Messaging]: OnInstantMessage registered for {0}", client.Name); | 362 | if (m_debugEnabled) m_log.DebugFormat("[Groups.Messaging]: OnInstantMessage registered for {0}", client.Name); |
326 | 363 | ||
327 | client.OnInstantMessage += OnInstantMessage; | 364 | ResetAgentGroupChatSessions(client.AgentId.ToString()); |
328 | } | 365 | } |
329 | 366 | ||
367 | void OnMakeRootAgent(ScenePresence sp) | ||
368 | { | ||
369 | sp.ControllingClient.OnInstantMessage += OnInstantMessage; | ||
370 | } | ||
371 | |||
372 | void OnMakeChildAgent(ScenePresence sp) | ||
373 | { | ||
374 | sp.ControllingClient.OnInstantMessage -= OnInstantMessage; | ||
375 | } | ||
376 | |||
377 | |||
330 | private void OnGridInstantMessage(GridInstantMessage msg) | 378 | private void OnGridInstantMessage(GridInstantMessage msg) |
331 | { | 379 | { |
332 | // The instant message module will only deliver messages of dialog types: | 380 | // The instant message module will only deliver messages of dialog types: |
@@ -335,21 +383,97 @@ namespace OpenSim.Groups | |||
335 | // Any other message type will not be delivered to a client by the | 383 | // Any other message type will not be delivered to a client by the |
336 | // Instant Message Module | 384 | // Instant Message Module |
337 | 385 | ||
338 | 386 | UUID regionID = new UUID(msg.RegionID); | |
339 | if (m_debugEnabled) | 387 | if (m_debugEnabled) |
340 | { | 388 | { |
341 | m_log.DebugFormat("[Groups.Messaging]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name); | 389 | m_log.DebugFormat("[Groups.Messaging]: {0} called, IM from region {1}", |
390 | System.Reflection.MethodBase.GetCurrentMethod().Name, regionID); | ||
342 | 391 | ||
343 | DebugGridInstantMessage(msg); | 392 | DebugGridInstantMessage(msg); |
344 | } | 393 | } |
345 | 394 | ||
346 | // Incoming message from a group | 395 | // Incoming message from a group |
347 | if ((msg.fromGroup == true) && | 396 | if ((msg.fromGroup == true) && (msg.dialog == (byte)InstantMessageDialog.SessionSend)) |
348 | ((msg.dialog == (byte)InstantMessageDialog.SessionSend) | ||
349 | || (msg.dialog == (byte)InstantMessageDialog.SessionAdd) | ||
350 | || (msg.dialog == (byte)InstantMessageDialog.SessionDrop))) | ||
351 | { | 397 | { |
352 | ProcessMessageFromGroupSession(msg); | 398 | // We have to redistribute the message across all members of the group who are here |
399 | // on this sim | ||
400 | |||
401 | UUID GroupID = new UUID(msg.imSessionID); | ||
402 | |||
403 | Scene aScene = m_sceneList[0]; | ||
404 | GridRegion regionOfOrigin = aScene.GridService.GetRegionByUUID(aScene.RegionInfo.ScopeID, regionID); | ||
405 | |||
406 | List<GroupMembersData> groupMembers = m_groupData.GetGroupMembers("all", GroupID); | ||
407 | List<UUID> alreadySeen = new List<UUID>(); | ||
408 | |||
409 | //if (m_debugEnabled) | ||
410 | // foreach (GroupMembersData m in groupMembers) | ||
411 | // m_log.DebugFormat("[Groups.Messaging]: member {0}", m.AgentID); | ||
412 | |||
413 | foreach (Scene s in m_sceneList) | ||
414 | { | ||
415 | s.ForEachScenePresence(sp => | ||
416 | { | ||
417 | // We need this, because we are searching through all | ||
418 | // SPs, both root and children | ||
419 | if (alreadySeen.Contains(sp.UUID)) | ||
420 | { | ||
421 | if (m_debugEnabled) | ||
422 | m_log.DebugFormat("[Groups.Messaging]: skipping agent {0} because we've already seen it", sp.UUID); | ||
423 | return; | ||
424 | } | ||
425 | alreadySeen.Add(sp.UUID); | ||
426 | |||
427 | GroupMembersData m = groupMembers.Find(gmd => | ||
428 | { | ||
429 | return gmd.AgentID == sp.UUID; | ||
430 | }); | ||
431 | if (m.AgentID == UUID.Zero) | ||
432 | { | ||
433 | if (m_debugEnabled) | ||
434 | m_log.DebugFormat("[Groups.Messaging]: skipping agent {0} because he is not a member of the group", sp.UUID); | ||
435 | return; | ||
436 | } | ||
437 | |||
438 | // Check if the user has an agent in the region where | ||
439 | // the IM came from, and if so, skip it, because the IM | ||
440 | // was already sent via that agent | ||
441 | if (regionOfOrigin != null) | ||
442 | { | ||
443 | AgentCircuitData aCircuit = s.AuthenticateHandler.GetAgentCircuitData(sp.UUID); | ||
444 | if (aCircuit != null) | ||
445 | { | ||
446 | if (aCircuit.ChildrenCapSeeds.Keys.Contains(regionOfOrigin.RegionHandle)) | ||
447 | { | ||
448 | if (m_debugEnabled) | ||
449 | m_log.DebugFormat("[Groups.Messaging]: skipping agent {0} because he has an agent in region of origin", sp.UUID); | ||
450 | return; | ||
451 | } | ||
452 | else | ||
453 | { | ||
454 | if (m_debugEnabled) | ||
455 | m_log.DebugFormat("[Groups.Messaging]: not skipping agent {0}", sp.UUID); | ||
456 | } | ||
457 | } | ||
458 | } | ||
459 | |||
460 | UUID AgentID = sp.UUID; | ||
461 | msg.toAgentID = AgentID.Guid; | ||
462 | |||
463 | if (!hasAgentDroppedGroupChatSession(AgentID.ToString(), GroupID)) | ||
464 | { | ||
465 | if (!hasAgentBeenInvitedToGroupChatSession(AgentID.ToString(), GroupID)) | ||
466 | AddAgentToSession(AgentID, GroupID, msg); | ||
467 | else | ||
468 | { | ||
469 | if (m_debugEnabled) m_log.DebugFormat("[Groups.Messaging]: Passing to ProcessMessageFromGroupSession to deliver to {0} locally", sp.Name); | ||
470 | |||
471 | ProcessMessageFromGroupSession(msg); | ||
472 | } | ||
473 | } | ||
474 | }); | ||
475 | |||
476 | } | ||
353 | } | 477 | } |
354 | } | 478 | } |
355 | 479 | ||
@@ -359,82 +483,40 @@ namespace OpenSim.Groups | |||
359 | 483 | ||
360 | UUID AgentID = new UUID(msg.fromAgentID); | 484 | UUID AgentID = new UUID(msg.fromAgentID); |
361 | UUID GroupID = new UUID(msg.imSessionID); | 485 | UUID GroupID = new UUID(msg.imSessionID); |
486 | UUID toAgentID = new UUID(msg.toAgentID); | ||
362 | 487 | ||
363 | switch (msg.dialog) | 488 | switch (msg.dialog) |
364 | { | 489 | { |
365 | case (byte)InstantMessageDialog.SessionAdd: | 490 | case (byte)InstantMessageDialog.SessionAdd: |
366 | m_groupData.AgentInvitedToGroupChatSession(AgentID.ToString(), GroupID); | 491 | AgentInvitedToGroupChatSession(AgentID.ToString(), GroupID); |
367 | break; | 492 | break; |
368 | 493 | ||
369 | case (byte)InstantMessageDialog.SessionDrop: | 494 | case (byte)InstantMessageDialog.SessionDrop: |
370 | m_groupData.AgentDroppedFromGroupChatSession(AgentID.ToString(), GroupID); | 495 | AgentDroppedFromGroupChatSession(AgentID.ToString(), GroupID); |
371 | break; | 496 | break; |
372 | 497 | ||
373 | case (byte)InstantMessageDialog.SessionSend: | 498 | case (byte)InstantMessageDialog.SessionSend: |
374 | if (!m_groupData.hasAgentDroppedGroupChatSession(AgentID.ToString(), GroupID) | 499 | // User hasn't dropped, so they're in the session, |
375 | && !m_groupData.hasAgentBeenInvitedToGroupChatSession(AgentID.ToString(), GroupID) | 500 | // maybe we should deliver it. |
376 | ) | 501 | IClientAPI client = GetActiveClient(new UUID(msg.toAgentID)); |
502 | if (client != null) | ||
377 | { | 503 | { |
378 | // Agent not in session and hasn't dropped from session | 504 | // Deliver locally, directly |
379 | // Add them to the session for now, and Invite them | 505 | if (m_debugEnabled) m_log.DebugFormat("[Groups.Messaging]: Delivering to {0} locally", client.Name); |
380 | m_groupData.AgentInvitedToGroupChatSession(AgentID.ToString(), GroupID); | ||
381 | 506 | ||
382 | UUID toAgentID = new UUID(msg.toAgentID); | 507 | if (!hasAgentDroppedGroupChatSession(toAgentID.ToString(), GroupID)) |
383 | IClientAPI activeClient = GetActiveClient(toAgentID); | ||
384 | if (activeClient != null) | ||
385 | { | 508 | { |
386 | GroupRecord groupInfo = m_groupData.GetGroupRecord(UUID.Zero.ToString(), GroupID, null); | 509 | if (!hasAgentBeenInvitedToGroupChatSession(toAgentID.ToString(), GroupID)) |
387 | if (groupInfo != null) | 510 | // This actually sends the message too, so no need to resend it |
388 | { | 511 | // with client.SendInstantMessage |
389 | if (m_debugEnabled) m_log.DebugFormat("[Groups.Messaging]: Sending chatterbox invite instant message"); | 512 | AddAgentToSession(toAgentID, GroupID, msg); |
390 | 513 | else | |
391 | // Force? open the group session dialog??? | 514 | client.SendInstantMessage(msg); |
392 | // and simultanously deliver the message, so we don't need to do a seperate client.SendInstantMessage(msg); | ||
393 | IEventQueue eq = activeClient.Scene.RequestModuleInterface<IEventQueue>(); | ||
394 | eq.ChatterboxInvitation( | ||
395 | GroupID | ||
396 | , groupInfo.GroupName | ||
397 | , new UUID(msg.fromAgentID) | ||
398 | , msg.message | ||
399 | , new UUID(msg.toAgentID) | ||
400 | , msg.fromAgentName | ||
401 | , msg.dialog | ||
402 | , msg.timestamp | ||
403 | , msg.offline == 1 | ||
404 | , (int)msg.ParentEstateID | ||
405 | , msg.Position | ||
406 | , 1 | ||
407 | , new UUID(msg.imSessionID) | ||
408 | , msg.fromGroup | ||
409 | , OpenMetaverse.Utils.StringToBytes(groupInfo.GroupName) | ||
410 | ); | ||
411 | |||
412 | eq.ChatterBoxSessionAgentListUpdates( | ||
413 | new UUID(GroupID) | ||
414 | , new UUID(msg.fromAgentID) | ||
415 | , new UUID(msg.toAgentID) | ||
416 | , false //canVoiceChat | ||
417 | , false //isModerator | ||
418 | , false //text mute | ||
419 | ); | ||
420 | } | ||
421 | } | 515 | } |
422 | } | 516 | } |
423 | else if (!m_groupData.hasAgentDroppedGroupChatSession(AgentID.ToString(), GroupID)) | 517 | else |
424 | { | 518 | { |
425 | // User hasn't dropped, so they're in the session, | 519 | m_log.WarnFormat("[Groups.Messaging]: Received a message over the grid for a client that isn't here: {0}", msg.toAgentID); |
426 | // maybe we should deliver it. | ||
427 | IClientAPI client = GetActiveClient(new UUID(msg.toAgentID)); | ||
428 | if (client != null) | ||
429 | { | ||
430 | // Deliver locally, directly | ||
431 | if (m_debugEnabled) m_log.DebugFormat("[Groups.Messaging]: Delivering to {0} locally", client.Name); | ||
432 | client.SendInstantMessage(msg); | ||
433 | } | ||
434 | else | ||
435 | { | ||
436 | m_log.WarnFormat("[Groups.Messaging]: Received a message over the grid for a client that isn't here: {0}", msg.toAgentID); | ||
437 | } | ||
438 | } | 520 | } |
439 | break; | 521 | break; |
440 | 522 | ||
@@ -444,6 +526,53 @@ namespace OpenSim.Groups | |||
444 | } | 526 | } |
445 | } | 527 | } |
446 | 528 | ||
529 | private void AddAgentToSession(UUID AgentID, UUID GroupID, GridInstantMessage msg) | ||
530 | { | ||
531 | // Agent not in session and hasn't dropped from session | ||
532 | // Add them to the session for now, and Invite them | ||
533 | AgentInvitedToGroupChatSession(AgentID.ToString(), GroupID); | ||
534 | |||
535 | IClientAPI activeClient = GetActiveClient(AgentID); | ||
536 | if (activeClient != null) | ||
537 | { | ||
538 | GroupRecord groupInfo = m_groupData.GetGroupRecord(UUID.Zero.ToString(), GroupID, null); | ||
539 | if (groupInfo != null) | ||
540 | { | ||
541 | if (m_debugEnabled) m_log.DebugFormat("[Groups.Messaging]: Sending chatterbox invite instant message"); | ||
542 | |||
543 | // Force? open the group session dialog??? | ||
544 | // and simultanously deliver the message, so we don't need to do a seperate client.SendInstantMessage(msg); | ||
545 | IEventQueue eq = activeClient.Scene.RequestModuleInterface<IEventQueue>(); | ||
546 | eq.ChatterboxInvitation( | ||
547 | GroupID | ||
548 | , groupInfo.GroupName | ||
549 | , new UUID(msg.fromAgentID) | ||
550 | , msg.message | ||
551 | , AgentID | ||
552 | , msg.fromAgentName | ||
553 | , msg.dialog | ||
554 | , msg.timestamp | ||
555 | , msg.offline == 1 | ||
556 | , (int)msg.ParentEstateID | ||
557 | , msg.Position | ||
558 | , 1 | ||
559 | , new UUID(msg.imSessionID) | ||
560 | , msg.fromGroup | ||
561 | , OpenMetaverse.Utils.StringToBytes(groupInfo.GroupName) | ||
562 | ); | ||
563 | |||
564 | eq.ChatterBoxSessionAgentListUpdates( | ||
565 | new UUID(GroupID) | ||
566 | , AgentID | ||
567 | , new UUID(msg.toAgentID) | ||
568 | , false //canVoiceChat | ||
569 | , false //isModerator | ||
570 | , false //text mute | ||
571 | ); | ||
572 | } | ||
573 | } | ||
574 | } | ||
575 | |||
447 | #endregion | 576 | #endregion |
448 | 577 | ||
449 | 578 | ||
@@ -469,7 +598,7 @@ namespace OpenSim.Groups | |||
469 | 598 | ||
470 | if (groupInfo != null) | 599 | if (groupInfo != null) |
471 | { | 600 | { |
472 | m_groupData.AgentInvitedToGroupChatSession(AgentID.ToString(), GroupID); | 601 | AgentInvitedToGroupChatSession(AgentID.ToString(), GroupID); |
473 | 602 | ||
474 | ChatterBoxSessionStartReplyViaCaps(remoteClient, groupInfo.GroupName, GroupID); | 603 | ChatterBoxSessionStartReplyViaCaps(remoteClient, groupInfo.GroupName, GroupID); |
475 | 604 | ||
@@ -495,7 +624,7 @@ namespace OpenSim.Groups | |||
495 | m_log.DebugFormat("[Groups.Messaging]: Send message to session for group {0} with session ID {1}", GroupID, im.imSessionID.ToString()); | 624 | m_log.DebugFormat("[Groups.Messaging]: Send message to session for group {0} with session ID {1}", GroupID, im.imSessionID.ToString()); |
496 | 625 | ||
497 | //If this agent is sending a message, then they want to be in the session | 626 | //If this agent is sending a message, then they want to be in the session |
498 | m_groupData.AgentInvitedToGroupChatSession(AgentID.ToString(), GroupID); | 627 | AgentInvitedToGroupChatSession(AgentID.ToString(), GroupID); |
499 | 628 | ||
500 | SendMessageToGroup(im, GroupID); | 629 | SendMessageToGroup(im, GroupID); |
501 | } | 630 | } |
@@ -566,12 +695,12 @@ namespace OpenSim.Groups | |||
566 | { | 695 | { |
567 | if (!sp.IsChildAgent) | 696 | if (!sp.IsChildAgent) |
568 | { | 697 | { |
569 | if (m_debugEnabled) m_log.WarnFormat("[Groups.Messaging]: Found root agent for client : {0}", sp.ControllingClient.Name); | 698 | if (m_debugEnabled) m_log.DebugFormat("[Groups.Messaging]: Found root agent for client : {0}", sp.ControllingClient.Name); |
570 | return sp.ControllingClient; | 699 | return sp.ControllingClient; |
571 | } | 700 | } |
572 | else | 701 | else |
573 | { | 702 | { |
574 | if (m_debugEnabled) m_log.WarnFormat("[Groups.Messaging]: Found child agent for client : {0}", sp.ControllingClient.Name); | 703 | if (m_debugEnabled) m_log.DebugFormat("[Groups.Messaging]: Found child agent for client : {0}", sp.ControllingClient.Name); |
575 | child = sp.ControllingClient; | 704 | child = sp.ControllingClient; |
576 | } | 705 | } |
577 | } | 706 | } |
@@ -590,5 +719,71 @@ namespace OpenSim.Groups | |||
590 | } | 719 | } |
591 | 720 | ||
592 | #endregion | 721 | #endregion |
722 | |||
723 | #region GroupSessionTracking | ||
724 | |||
725 | public void ResetAgentGroupChatSessions(string agentID) | ||
726 | { | ||
727 | foreach (List<string> agentList in m_groupsAgentsDroppedFromChatSession.Values) | ||
728 | agentList.Remove(agentID); | ||
729 | |||
730 | foreach (List<string> agentList in m_groupsAgentsInvitedToChatSession.Values) | ||
731 | agentList.Remove(agentID); | ||
732 | } | ||
733 | |||
734 | public bool hasAgentBeenInvitedToGroupChatSession(string agentID, UUID groupID) | ||
735 | { | ||
736 | // If we're tracking this group, and we can find them in the tracking, then they've been invited | ||
737 | return m_groupsAgentsInvitedToChatSession.ContainsKey(groupID) | ||
738 | && m_groupsAgentsInvitedToChatSession[groupID].Contains(agentID); | ||
739 | } | ||
740 | |||
741 | public bool hasAgentDroppedGroupChatSession(string agentID, UUID groupID) | ||
742 | { | ||
743 | // If we're tracking drops for this group, | ||
744 | // and we find them, well... then they've dropped | ||
745 | return m_groupsAgentsDroppedFromChatSession.ContainsKey(groupID) | ||
746 | && m_groupsAgentsDroppedFromChatSession[groupID].Contains(agentID); | ||
747 | } | ||
748 | |||
749 | public void AgentDroppedFromGroupChatSession(string agentID, UUID groupID) | ||
750 | { | ||
751 | if (m_groupsAgentsDroppedFromChatSession.ContainsKey(groupID)) | ||
752 | { | ||
753 | // If not in dropped list, add | ||
754 | if (!m_groupsAgentsDroppedFromChatSession[groupID].Contains(agentID)) | ||
755 | { | ||
756 | m_groupsAgentsDroppedFromChatSession[groupID].Add(agentID); | ||
757 | } | ||
758 | } | ||
759 | } | ||
760 | |||
761 | public void AgentInvitedToGroupChatSession(string agentID, UUID groupID) | ||
762 | { | ||
763 | // Add Session Status if it doesn't exist for this session | ||
764 | CreateGroupChatSessionTracking(groupID); | ||
765 | |||
766 | // If nessesary, remove from dropped list | ||
767 | if (m_groupsAgentsDroppedFromChatSession[groupID].Contains(agentID)) | ||
768 | { | ||
769 | m_groupsAgentsDroppedFromChatSession[groupID].Remove(agentID); | ||
770 | } | ||
771 | |||
772 | // Add to invited | ||
773 | if (!m_groupsAgentsInvitedToChatSession[groupID].Contains(agentID)) | ||
774 | m_groupsAgentsInvitedToChatSession[groupID].Add(agentID); | ||
775 | } | ||
776 | |||
777 | private void CreateGroupChatSessionTracking(UUID groupID) | ||
778 | { | ||
779 | if (!m_groupsAgentsDroppedFromChatSession.ContainsKey(groupID)) | ||
780 | { | ||
781 | m_groupsAgentsDroppedFromChatSession.Add(groupID, new List<string>()); | ||
782 | m_groupsAgentsInvitedToChatSession.Add(groupID, new List<string>()); | ||
783 | } | ||
784 | |||
785 | } | ||
786 | #endregion | ||
787 | |||
593 | } | 788 | } |
594 | } | 789 | } |