aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs')
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs216
1 files changed, 98 insertions, 118 deletions
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs
index 533815f..17a5349 100644
--- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs
@@ -49,14 +49,9 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
49 49
50 private List<Scene> m_sceneList = new List<Scene>(); 50 private List<Scene> m_sceneList = new List<Scene>();
51 51
52 private IMessageTransferModule m_msgTransferModule = null; 52 private IMessageTransferModule m_msgTransferModule = null;
53 53
54 private IGroupsModule m_groupsModule = null; 54 private IGroupsServicesConnector m_groupData = null;
55
56 // TODO: Move this off to the Groups Server
57 public Dictionary<Guid, List<Guid>> m_agentsInGroupSession = new Dictionary<Guid, List<Guid>>();
58 public Dictionary<Guid, List<Guid>> m_agentsDroppedSession = new Dictionary<Guid, List<Guid>>();
59
60 55
61 // Config Options 56 // Config Options
62 private bool m_groupMessagingEnabled = false; 57 private bool m_groupMessagingEnabled = false;
@@ -113,14 +108,14 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
113 if (!m_groupMessagingEnabled) 108 if (!m_groupMessagingEnabled)
114 return; 109 return;
115 110
116 if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name); 111 if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
117 112
118 m_groupsModule = scene.RequestModuleInterface<IGroupsModule>(); 113 m_groupData = scene.RequestModuleInterface<IGroupsServicesConnector>();
119 114
120 // No groups module, no groups messaging 115 // No groups module, no groups messaging
121 if (m_groupsModule == null) 116 if (m_groupData == null)
122 { 117 {
123 m_log.Error("[GROUPS-MESSAGING]: Could not get IGroupsModule, GroupsMessagingModule is now disabled."); 118 m_log.Error("[GROUPS-MESSAGING]: Could not get IGroupsServicesConnector, GroupsMessagingModule is now disabled.");
124 Close(); 119 Close();
125 m_groupMessagingEnabled = false; 120 m_groupMessagingEnabled = false;
126 return; 121 return;
@@ -142,7 +137,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
142 137
143 scene.EventManager.OnNewClient += OnNewClient; 138 scene.EventManager.OnNewClient += OnNewClient;
144 scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage; 139 scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage;
145 140 scene.EventManager.OnClientLogin += OnClientLogin;
146 } 141 }
147 142
148 public void RemoveRegion(Scene scene) 143 public void RemoveRegion(Scene scene)
@@ -170,7 +165,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
170 165
171 m_sceneList.Clear(); 166 m_sceneList.Clear();
172 167
173 m_groupsModule = null; 168 m_groupData = null;
174 m_msgTransferModule = null; 169 m_msgTransferModule = null;
175 } 170 }
176 171
@@ -195,16 +190,18 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
195 190
196 #endregion 191 #endregion
197 192
193 /// <summary>
194 /// Not really needed, but does confirm that the group exists.
195 /// </summary>
198 public bool StartGroupChatSession(UUID agentID, UUID groupID) 196 public bool StartGroupChatSession(UUID agentID, UUID groupID)
199 { 197 {
200 if (m_debugEnabled) 198 if (m_debugEnabled)
201 m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name); 199 m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
202 200
203 GroupRecord groupInfo = m_groupsModule.GetGroupRecord(groupID); 201 GroupRecord groupInfo = m_groupData.GetGroupRecord(agentID, groupID, null);
204 202
205 if (groupInfo != null) 203 if (groupInfo != null)
206 { 204 {
207 AddAgentToGroupSession(agentID.Guid, groupID.Guid);
208 return true; 205 return true;
209 } 206 }
210 else 207 else
@@ -216,11 +213,12 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
216 public void SendMessageToGroup(GridInstantMessage im, UUID groupID) 213 public void SendMessageToGroup(GridInstantMessage im, UUID groupID)
217 { 214 {
218 if (m_debugEnabled) 215 if (m_debugEnabled)
219 m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name); 216 m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
220 217
221 foreach (GroupMembersData member in m_groupsModule.GroupMembersRequest(null, groupID)) 218
222 { 219 foreach (GroupMembersData member in m_groupData.GetGroupMembers(UUID.Zero, groupID))
223 if (!m_agentsDroppedSession.ContainsKey(im.imSessionID) || m_agentsDroppedSession[im.imSessionID].Contains(member.AgentID.Guid)) 220 {
221 if (m_groupData.hasAgentDroppedGroupChatSession(member.AgentID, groupID))
224 { 222 {
225 // Don't deliver messages to people who have dropped this session 223 // Don't deliver messages to people who have dropped this session
226 if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: {0} has dropped session, not delivering to them", member.AgentID); 224 if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: {0} has dropped session, not delivering to them", member.AgentID);
@@ -228,8 +226,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
228 } 226 }
229 227
230 // Copy Message 228 // Copy Message
231 GridInstantMessage msg = new GridInstantMessage(); 229 GridInstantMessage msg = new GridInstantMessage();
232 msg.imSessionID = im.imSessionID; 230 msg.imSessionID = groupID.Guid;
233 msg.fromAgentName = im.fromAgentName; 231 msg.fromAgentName = im.fromAgentName;
234 msg.message = im.message; 232 msg.message = im.message;
235 msg.dialog = im.dialog; 233 msg.dialog = im.dialog;
@@ -240,8 +238,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
240 msg.binaryBucket = im.binaryBucket; 238 msg.binaryBucket = im.binaryBucket;
241 msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); 239 msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
242 240
243 // Updat Pertinate fields to make it a "group message" 241 msg.fromAgentID = im.fromAgentID;
244 msg.fromAgentID = groupID.Guid;
245 msg.fromGroup = true; 242 msg.fromGroup = true;
246 243
247 msg.toAgentID = member.AgentID.Guid; 244 msg.toAgentID = member.AgentID.Guid;
@@ -262,7 +259,14 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
262 } 259 }
263 } 260 }
264 261
265 #region SimGridEventHandlers 262 #region SimGridEventHandlers
263
264 void OnClientLogin(IClientAPI client)
265 {
266 if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: OnInstantMessage registered for {0}", client.Name);
267
268
269 }
266 270
267 private void OnNewClient(IClientAPI client) 271 private void OnNewClient(IClientAPI client)
268 { 272 {
@@ -299,44 +303,48 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
299 303
300 private void ProcessMessageFromGroupSession(GridInstantMessage msg) 304 private void ProcessMessageFromGroupSession(GridInstantMessage msg)
301 { 305 {
302 if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: Session message from {0} going to agent {1}", msg.fromAgentName, msg.toAgentID); 306 if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: Session message from {0} going to agent {1}", msg.fromAgentName, msg.toAgentID);
307
308 UUID AgentID = new UUID(msg.fromAgentID);
309 UUID GroupID = new UUID(msg.imSessionID);
303 310
304 switch (msg.dialog) 311 switch (msg.dialog)
305 { 312 {
306 case (byte)InstantMessageDialog.SessionAdd: 313 case (byte)InstantMessageDialog.SessionAdd:
307 AddAgentToGroupSession(msg.fromAgentID, msg.imSessionID); 314 m_groupData.AgentInvitedToGroupChatSession(AgentID, GroupID);
308 break; 315 break;
309 316
310 case (byte)InstantMessageDialog.SessionDrop: 317 case (byte)InstantMessageDialog.SessionDrop:
311 RemoveAgentFromGroupSession(msg.fromAgentID, msg.imSessionID); 318 m_groupData.AgentDroppedFromGroupChatSession(AgentID, GroupID);
312 break; 319 break;
313 320
314 case (byte)InstantMessageDialog.SessionSend: 321 case (byte)InstantMessageDialog.SessionSend:
315 if (!m_agentsInGroupSession.ContainsKey(msg.toAgentID) 322 if (!m_groupData.hasAgentDroppedGroupChatSession(AgentID, GroupID)
316 && !m_agentsDroppedSession.ContainsKey(msg.toAgentID)) 323 && !m_groupData.hasAgentBeenInvitedToGroupChatSession(AgentID, GroupID)
324 )
317 { 325 {
318 // Agent not in session and hasn't dropped from session 326 // Agent not in session and hasn't dropped from session
319 // Add them to the session for now, and Invite them 327 // Add them to the session for now, and Invite them
320 AddAgentToGroupSession(msg.toAgentID, msg.imSessionID); 328 m_groupData.AgentInvitedToGroupChatSession(AgentID, GroupID);
321 329
322 UUID toAgentID = new UUID(msg.toAgentID); 330 UUID toAgentID = new UUID(msg.toAgentID);
323 IClientAPI activeClient = GetActiveClient(toAgentID); 331 IClientAPI activeClient = GetActiveClient(toAgentID);
324 if (activeClient != null) 332 if (activeClient != null)
325 { 333 {
326 UUID groupID = new UUID(msg.fromAgentID); 334 GroupRecord groupInfo = m_groupData.GetGroupRecord(UUID.Zero, GroupID, null);
327
328 GroupRecord groupInfo = m_groupsModule.GetGroupRecord(groupID);
329 if (groupInfo != null) 335 if (groupInfo != null)
330 { 336 {
331 if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: Sending chatterbox invite instant message"); 337 if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: Sending chatterbox invite instant message");
332 338
333 // Force? open the group session dialog??? 339 // Force? open the group session dialog???
340 // and simultanously deliver the message, so we don't need to do a seperate client.SendInstantMessage(msg);
334 IEventQueue eq = activeClient.Scene.RequestModuleInterface<IEventQueue>(); 341 IEventQueue eq = activeClient.Scene.RequestModuleInterface<IEventQueue>();
335 eq.ChatterboxInvitation( 342 eq.ChatterboxInvitation(
336 groupID 343 GroupID
337 , groupInfo.GroupName 344 , groupInfo.GroupName
338 , new UUID(msg.fromAgentID) 345 , new UUID(msg.fromAgentID)
339 , msg.message, new UUID(msg.toAgentID) 346 , msg.message
347 , new UUID(msg.toAgentID)
340 , msg.fromAgentName 348 , msg.fromAgentName
341 , msg.dialog 349 , msg.dialog
342 , msg.timestamp 350 , msg.timestamp
@@ -349,8 +357,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
349 , Utils.StringToBytes(groupInfo.GroupName) 357 , Utils.StringToBytes(groupInfo.GroupName)
350 ); 358 );
351 359
352 eq.ChatterBoxSessionAgentListUpdates( 360 eq.ChatterBoxSessionAgentListUpdates(
353 new UUID(groupID) 361 new UUID(GroupID)
354 , new UUID(msg.fromAgentID) 362 , new UUID(msg.fromAgentID)
355 , new UUID(msg.toAgentID) 363 , new UUID(msg.toAgentID)
356 , false //canVoiceChat 364 , false //canVoiceChat
@@ -359,8 +367,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
359 ); 367 );
360 } 368 }
361 } 369 }
362 } 370 }
363 else if (!m_agentsDroppedSession.ContainsKey(msg.toAgentID)) 371 else if (!m_groupData.hasAgentDroppedGroupChatSession(AgentID, GroupID))
364 { 372 {
365 // User hasn't dropped, so they're in the session, 373 // User hasn't dropped, so they're in the session,
366 // maybe we should deliver it. 374 // maybe we should deliver it.
@@ -386,56 +394,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
386 394
387 #endregion 395 #endregion
388 396
389 #region ClientEvents 397
390 398 #region ClientEvents
391 private void RemoveAgentFromGroupSession(Guid agentID, Guid sessionID)
392 {
393 if (m_agentsInGroupSession.ContainsKey(sessionID))
394 {
395 // If in session remove
396 if (m_agentsInGroupSession[sessionID].Contains(agentID))
397 {
398 m_agentsInGroupSession[sessionID].Remove(agentID);
399 }
400
401 // If not in dropped list, add
402 if (!m_agentsDroppedSession[sessionID].Contains(agentID))
403 {
404 if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: Dropped {1} from session {0}", sessionID, agentID);
405 m_agentsDroppedSession[sessionID].Add(agentID);
406 }
407 }
408 }
409
410 private void AddAgentToGroupSession(Guid agentID, Guid sessionID)
411 {
412 // Add Session Status if it doesn't exist for this session
413 CreateGroupSessionTracking(sessionID);
414
415 // If nessesary, remove from dropped list
416 if (m_agentsDroppedSession[sessionID].Contains(agentID))
417 {
418 m_agentsDroppedSession[sessionID].Remove(agentID);
419 }
420
421 // If nessesary, add to in session list
422 if (!m_agentsInGroupSession[sessionID].Contains(agentID))
423 {
424 if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: Added {1} to session {0}", sessionID, agentID);
425 m_agentsInGroupSession[sessionID].Add(agentID);
426 }
427 }
428
429 private void CreateGroupSessionTracking(Guid sessionID)
430 {
431 if (!m_agentsInGroupSession.ContainsKey(sessionID))
432 {
433 if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: Creating session tracking for : {0}", sessionID);
434 m_agentsInGroupSession.Add(sessionID, new List<Guid>());
435 m_agentsDroppedSession.Add(sessionID, new List<Guid>());
436 }
437 }
438
439 private void OnInstantMessage(IClientAPI remoteClient, GridInstantMessage im) 399 private void OnInstantMessage(IClientAPI remoteClient, GridInstantMessage im)
440 { 400 {
441 if (m_debugEnabled) 401 if (m_debugEnabled)
@@ -447,20 +407,24 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
447 407
448 // Start group IM session 408 // Start group IM session
449 if ((im.dialog == (byte)InstantMessageDialog.SessionGroupStart)) 409 if ((im.dialog == (byte)InstantMessageDialog.SessionGroupStart))
450 { 410 {
451 UUID groupID = new UUID(im.toAgentID); 411 if (m_debugEnabled) m_log.InfoFormat("[GROUPS-MESSAGING]: imSessionID({0}) toAgentID({1})", im.imSessionID, im.toAgentID);
452 GroupRecord groupInfo = m_groupsModule.GetGroupRecord(groupID); 412
413 UUID GroupID = new UUID(im.imSessionID);
414 UUID AgentID = new UUID(im.fromAgentID);
415
416 GroupRecord groupInfo = m_groupData.GetGroupRecord(UUID.Zero, GroupID, null);
453 417
454 if (groupInfo != null) 418 if (groupInfo != null)
455 { 419 {
456 AddAgentToGroupSession(im.fromAgentID, groupInfo.GroupID.Guid); 420 m_groupData.AgentInvitedToGroupChatSession(AgentID, GroupID);
457 421
458 ChatterBoxSessionStartReplyViaCaps(remoteClient, groupInfo.GroupName, groupID); 422 ChatterBoxSessionStartReplyViaCaps(remoteClient, groupInfo.GroupName, GroupID);
459 423
460 IEventQueue queue = remoteClient.Scene.RequestModuleInterface<IEventQueue>(); 424 IEventQueue queue = remoteClient.Scene.RequestModuleInterface<IEventQueue>();
461 queue.ChatterBoxSessionAgentListUpdates( 425 queue.ChatterBoxSessionAgentListUpdates(
462 new UUID(groupID) 426 GroupID
463 , new UUID(im.fromAgentID) 427 , AgentID
464 , new UUID(im.toAgentID) 428 , new UUID(im.toAgentID)
465 , false //canVoiceChat 429 , false //canVoiceChat
466 , false //isModerator 430 , false //isModerator
@@ -471,13 +435,17 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
471 435
472 // Send a message from locally connected client to a group 436 // Send a message from locally connected client to a group
473 if ((im.dialog == (byte)InstantMessageDialog.SessionSend)) 437 if ((im.dialog == (byte)InstantMessageDialog.SessionSend))
474 { 438 {
475 UUID groupID = new UUID(im.toAgentID); 439 UUID GroupID = new UUID(im.imSessionID);
440 UUID AgentID = new UUID(im.fromAgentID);
476 441
477 if (m_debugEnabled) 442 if (m_debugEnabled)
478 m_log.DebugFormat("[GROUPS-MESSAGING]: Send message to session for group {0} with session ID {1}", groupID, im.imSessionID.ToString()); 443 m_log.DebugFormat("[GROUPS-MESSAGING]: Send message to session for group {0} with session ID {1}", GroupID, im.imSessionID.ToString());
479 444
480 SendMessageToGroup(im, groupID); 445 //If this agent is sending a message, then they want to be in the session
446 m_groupData.AgentInvitedToGroupChatSession(AgentID, GroupID);
447
448 SendMessageToGroup(im, GroupID);
481 } 449 }
482 } 450 }
483 451
@@ -533,7 +501,9 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
533 /// Try to find an active IClientAPI reference for agentID giving preference to root connections 501 /// Try to find an active IClientAPI reference for agentID giving preference to root connections
534 /// </summary> 502 /// </summary>
535 private IClientAPI GetActiveClient(UUID agentID) 503 private IClientAPI GetActiveClient(UUID agentID)
536 { 504 {
505 if (m_debugEnabled) m_log.WarnFormat("[GROUPS-MESSAGING]: Looking for local client {0}", agentID);
506
537 IClientAPI child = null; 507 IClientAPI child = null;
538 508
539 // Try root avatar first 509 // Try root avatar first
@@ -544,17 +514,27 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
544 { 514 {
545 ScenePresence user = (ScenePresence)scene.Entities[agentID]; 515 ScenePresence user = (ScenePresence)scene.Entities[agentID];
546 if (!user.IsChildAgent) 516 if (!user.IsChildAgent)
547 { 517 {
518 if (m_debugEnabled) m_log.WarnFormat("[GROUPS-MESSAGING]: Found root agent for client : {0}", user.ControllingClient.Name);
548 return user.ControllingClient; 519 return user.ControllingClient;
549 } 520 }
550 else 521 else
551 { 522 {
523 if (m_debugEnabled) m_log.WarnFormat("[GROUPS-MESSAGING]: Found child agent for client : {0}", user.ControllingClient.Name);
552 child = user.ControllingClient; 524 child = user.ControllingClient;
553 } 525 }
554 } 526 }
555 } 527 }
556 528
557 // If we didn't find a root, then just return whichever child we found, or null if none 529 // If we didn't find a root, then just return whichever child we found, or null if none
530 if (child == null)
531 {
532 if (m_debugEnabled) m_log.WarnFormat("[GROUPS-MESSAGING]: Could not find local client for agent : {0}", agentID);
533 }
534 else
535 {
536 if (m_debugEnabled) m_log.WarnFormat("[GROUPS-MESSAGING]: Returning child agent for client : {0}", child.Name);
537 }
558 return child; 538 return child;
559 } 539 }
560 540