diff options
author | Justin Clark-Casey (justincc) | 2010-04-01 22:37:20 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2010-04-01 22:37:20 +0100 |
commit | c33b1de9dfc238ca38a0f145160de2648189dd16 (patch) | |
tree | c11d3cd4479aa2e587b97d72244578625261009a /OpenSim | |
parent | When saving an oar/iar, don't attempt to write out the data byte array if it'... (diff) | |
download | opensim-SC-c33b1de9dfc238ca38a0f145160de2648189dd16.zip opensim-SC-c33b1de9dfc238ca38a0f145160de2648189dd16.tar.gz opensim-SC-c33b1de9dfc238ca38a0f145160de2648189dd16.tar.bz2 opensim-SC-c33b1de9dfc238ca38a0f145160de2648189dd16.tar.xz |
expose methods that allow region modules to send messages to groups
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs | 144 |
1 files changed, 81 insertions, 63 deletions
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs index 00fe5df..e0840b1 100644 --- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs | |||
@@ -28,29 +28,23 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Reflection; | 30 | using System.Reflection; |
31 | |||
32 | |||
33 | using log4net; | 31 | using log4net; |
34 | using Mono.Addins; | 32 | using Mono.Addins; |
35 | using Nini.Config; | 33 | using Nini.Config; |
36 | |||
37 | using OpenMetaverse; | 34 | using OpenMetaverse; |
38 | using OpenMetaverse.StructuredData; | 35 | using OpenMetaverse.StructuredData; |
39 | |||
40 | using OpenSim.Framework; | 36 | using OpenSim.Framework; |
41 | using OpenSim.Region.CoreModules.Framework.EventQueue; | 37 | using OpenSim.Region.CoreModules.Framework.EventQueue; |
42 | using OpenSim.Region.Framework.Interfaces; | 38 | using OpenSim.Region.Framework.Interfaces; |
43 | using OpenSim.Region.Framework.Scenes; | 39 | using OpenSim.Region.Framework.Scenes; |
44 | 40 | ||
45 | |||
46 | using Caps = OpenSim.Framework.Capabilities.Caps; | 41 | using Caps = OpenSim.Framework.Capabilities.Caps; |
47 | 42 | ||
48 | namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | 43 | namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups |
49 | { | 44 | { |
50 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] | 45 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] |
51 | public class GroupsMessagingModule : ISharedRegionModule | 46 | public class GroupsMessagingModule : ISharedRegionModule, IGroupsMessagingModule |
52 | { | 47 | { |
53 | |||
54 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
55 | 49 | ||
56 | private List<Scene> m_sceneList = new List<Scene>(); | 50 | private List<Scene> m_sceneList = new List<Scene>(); |
@@ -108,8 +102,12 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
108 | 102 | ||
109 | public void AddRegion(Scene scene) | 103 | public void AddRegion(Scene scene) |
110 | { | 104 | { |
111 | // NoOp | 105 | if (!m_groupMessagingEnabled) |
106 | return; | ||
107 | |||
108 | scene.RegisterModuleInterface<IGroupsMessagingModule>(this); | ||
112 | } | 109 | } |
110 | |||
113 | public void RegionLoaded(Scene scene) | 111 | public void RegionLoaded(Scene scene) |
114 | { | 112 | { |
115 | if (!m_groupMessagingEnabled) | 113 | if (!m_groupMessagingEnabled) |
@@ -197,6 +195,75 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
197 | 195 | ||
198 | #endregion | 196 | #endregion |
199 | 197 | ||
198 | public bool StartGroupChatSession(UUID agentID, UUID groupID) | ||
199 | { | ||
200 | if (m_debugEnabled) | ||
201 | m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name); | ||
202 | |||
203 | GroupRecord groupInfo = m_groupsModule.GetGroupRecord(groupID); | ||
204 | |||
205 | if (groupInfo != null) | ||
206 | return StartGroupChatSession(agentID.Guid, groupInfo); | ||
207 | else | ||
208 | return false; | ||
209 | } | ||
210 | |||
211 | protected bool StartGroupChatSession(Guid agentID, GroupRecord groupInfo) | ||
212 | { | ||
213 | AddAgentToGroupSession(agentID, groupInfo.GroupID.Guid); | ||
214 | |||
215 | return true; | ||
216 | } | ||
217 | |||
218 | public void SendMessageToGroup(GridInstantMessage im, UUID groupID) | ||
219 | { | ||
220 | if (m_debugEnabled) | ||
221 | m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name); | ||
222 | |||
223 | foreach (GroupMembersData member in m_groupsModule.GroupMembersRequest(null, groupID)) | ||
224 | { | ||
225 | if (!m_agentsDroppedSession.ContainsKey(im.imSessionID) || m_agentsDroppedSession[im.imSessionID].Contains(member.AgentID.Guid)) | ||
226 | { | ||
227 | // Don't deliver messages to people who have dropped this session | ||
228 | if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: {0} has dropped session, not delivering to them", member.AgentID); | ||
229 | continue; | ||
230 | } | ||
231 | |||
232 | // Copy Message | ||
233 | GridInstantMessage msg = new GridInstantMessage(); | ||
234 | msg.imSessionID = im.imSessionID; | ||
235 | msg.fromAgentName = im.fromAgentName; | ||
236 | msg.message = im.message; | ||
237 | msg.dialog = im.dialog; | ||
238 | msg.offline = im.offline; | ||
239 | msg.ParentEstateID = im.ParentEstateID; | ||
240 | msg.Position = im.Position; | ||
241 | msg.RegionID = im.RegionID; | ||
242 | msg.binaryBucket = im.binaryBucket; | ||
243 | msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); | ||
244 | |||
245 | // Updat Pertinate fields to make it a "group message" | ||
246 | msg.fromAgentID = groupID.Guid; | ||
247 | msg.fromGroup = true; | ||
248 | |||
249 | msg.toAgentID = member.AgentID.Guid; | ||
250 | |||
251 | IClientAPI client = GetActiveClient(member.AgentID); | ||
252 | if (client == null) | ||
253 | { | ||
254 | // If they're not local, forward across the grid | ||
255 | if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: Delivering to {0} via Grid", member.AgentID); | ||
256 | m_msgTransferModule.SendInstantMessage(msg, delegate(bool success) { }); | ||
257 | } | ||
258 | else | ||
259 | { | ||
260 | // Deliver locally, directly | ||
261 | if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: Passing to ProcessMessageFromGroupSession to deliver to {0} locally", client.Name); | ||
262 | ProcessMessageFromGroupSession(msg); | ||
263 | } | ||
264 | } | ||
265 | } | ||
266 | |||
200 | #region SimGridEventHandlers | 267 | #region SimGridEventHandlers |
201 | 268 | ||
202 | private void OnNewClient(IClientAPI client) | 269 | private void OnNewClient(IClientAPI client) |
@@ -370,7 +437,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
370 | m_agentsDroppedSession.Add(sessionID, new List<Guid>()); | 437 | m_agentsDroppedSession.Add(sessionID, new List<Guid>()); |
371 | } | 438 | } |
372 | } | 439 | } |
373 | 440 | ||
374 | private void OnInstantMessage(IClientAPI remoteClient, GridInstantMessage im) | 441 | private void OnInstantMessage(IClientAPI remoteClient, GridInstantMessage im) |
375 | { | 442 | { |
376 | if (m_debugEnabled) | 443 | if (m_debugEnabled) |
@@ -384,13 +451,11 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
384 | if ((im.dialog == (byte)InstantMessageDialog.SessionGroupStart)) | 451 | if ((im.dialog == (byte)InstantMessageDialog.SessionGroupStart)) |
385 | { | 452 | { |
386 | UUID groupID = new UUID(im.toAgentID); | 453 | UUID groupID = new UUID(im.toAgentID); |
387 | |||
388 | GroupRecord groupInfo = m_groupsModule.GetGroupRecord(groupID); | 454 | GroupRecord groupInfo = m_groupsModule.GetGroupRecord(groupID); |
455 | |||
389 | if (groupInfo != null) | 456 | if (groupInfo != null) |
390 | { | 457 | { |
391 | if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: Start Group Session for {0}", groupInfo.GroupName); | 458 | StartGroupChatSession(im.fromAgentID, groupInfo); |
392 | |||
393 | AddAgentToGroupSession(im.fromAgentID, im.imSessionID); | ||
394 | 459 | ||
395 | ChatterBoxSessionStartReplyViaCaps(remoteClient, groupInfo.GroupName, groupID); | 460 | ChatterBoxSessionStartReplyViaCaps(remoteClient, groupInfo.GroupName, groupID); |
396 | 461 | ||
@@ -411,7 +476,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
411 | { | 476 | { |
412 | UUID groupID = new UUID(im.toAgentID); | 477 | UUID groupID = new UUID(im.toAgentID); |
413 | 478 | ||
414 | if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: Send message to session for group {0} with session ID {1}", groupID, im.imSessionID.ToString()); | 479 | if (m_debugEnabled) |
480 | m_log.DebugFormat("[GROUPS-MESSAGING]: Send message to session for group {0} with session ID {1}", groupID, im.imSessionID.ToString()); | ||
415 | 481 | ||
416 | SendMessageToGroup(im, groupID); | 482 | SendMessageToGroup(im, groupID); |
417 | } | 483 | } |
@@ -419,54 +485,6 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
419 | 485 | ||
420 | #endregion | 486 | #endregion |
421 | 487 | ||
422 | private void SendMessageToGroup(GridInstantMessage im, UUID groupID) | ||
423 | { | ||
424 | if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name); | ||
425 | |||
426 | foreach (GroupMembersData member in m_groupsModule.GroupMembersRequest(null, groupID)) | ||
427 | { | ||
428 | if (!m_agentsDroppedSession.ContainsKey(im.imSessionID) || m_agentsDroppedSession[im.imSessionID].Contains(member.AgentID.Guid)) | ||
429 | { | ||
430 | // Don't deliver messages to people who have dropped this session | ||
431 | if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: {0} has dropped session, not delivering to them", member.AgentID); | ||
432 | continue; | ||
433 | } | ||
434 | |||
435 | // Copy Message | ||
436 | GridInstantMessage msg = new GridInstantMessage(); | ||
437 | msg.imSessionID = im.imSessionID; | ||
438 | msg.fromAgentName = im.fromAgentName; | ||
439 | msg.message = im.message; | ||
440 | msg.dialog = im.dialog; | ||
441 | msg.offline = im.offline; | ||
442 | msg.ParentEstateID = im.ParentEstateID; | ||
443 | msg.Position = im.Position; | ||
444 | msg.RegionID = im.RegionID; | ||
445 | msg.binaryBucket = im.binaryBucket; | ||
446 | msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); | ||
447 | |||
448 | // Updat Pertinate fields to make it a "group message" | ||
449 | msg.fromAgentID = groupID.Guid; | ||
450 | msg.fromGroup = true; | ||
451 | |||
452 | msg.toAgentID = member.AgentID.Guid; | ||
453 | |||
454 | IClientAPI client = GetActiveClient(member.AgentID); | ||
455 | if (client == null) | ||
456 | { | ||
457 | // If they're not local, forward across the grid | ||
458 | if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: Delivering to {0} via Grid", member.AgentID); | ||
459 | m_msgTransferModule.SendInstantMessage(msg, delegate(bool success) { }); | ||
460 | } | ||
461 | else | ||
462 | { | ||
463 | // Deliver locally, directly | ||
464 | if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: Passing to ProcessMessageFromGroupSession to deliver to {0} locally", client.Name); | ||
465 | ProcessMessageFromGroupSession(msg); | ||
466 | } | ||
467 | } | ||
468 | } | ||
469 | |||
470 | void ChatterBoxSessionStartReplyViaCaps(IClientAPI remoteClient, string groupName, UUID groupID) | 488 | void ChatterBoxSessionStartReplyViaCaps(IClientAPI remoteClient, string groupName, UUID groupID) |
471 | { | 489 | { |
472 | if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name); | 490 | if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name); |