opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | eva | 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 | */ |
||
27 | |||
28 | using System; |
||
29 | using System.Collections.Generic; |
||
30 | using System.Linq; |
||
31 | using System.Reflection; |
||
32 | using log4net; |
||
33 | using Mono.Addins; |
||
34 | using Nini.Config; |
||
35 | using OpenMetaverse; |
||
36 | using OpenMetaverse.StructuredData; |
||
37 | using OpenSim.Framework; |
||
38 | using OpenSim.Region.Framework.Interfaces; |
||
39 | using OpenSim.Region.Framework.Scenes; |
||
40 | using OpenSim.Services.Interfaces; |
||
41 | using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo; |
||
42 | |||
43 | namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups |
||
44 | { |
||
45 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GroupsMessagingModule")] |
||
46 | public class GroupsMessagingModule : ISharedRegionModule, IGroupsMessagingModule |
||
47 | { |
||
48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
||
49 | |||
50 | private List<Scene> m_sceneList = new List<Scene>(); |
||
51 | private IPresenceService m_presenceService; |
||
52 | |||
53 | private IMessageTransferModule m_msgTransferModule = null; |
||
54 | |||
55 | private IGroupsServicesConnector m_groupData = null; |
||
56 | |||
57 | // Config Options |
||
58 | private bool m_groupMessagingEnabled = false; |
||
59 | private bool m_debugEnabled = true; |
||
60 | |||
61 | /// <summary> |
||
62 | /// If enabled, module only tries to send group IMs to online users by querying cached presence information. |
||
63 | /// </summary> |
||
64 | private bool m_messageOnlineAgentsOnly; |
||
65 | |||
66 | /// <summary> |
||
67 | /// Cache for online users. |
||
68 | /// </summary> |
||
69 | /// <remarks> |
||
70 | /// Group ID is key, presence information for online members is value. |
||
71 | /// Will only be non-null if m_messageOnlineAgentsOnly = true |
||
72 | /// We cache here so that group messages don't constantly have to re-request the online user list to avoid |
||
73 | /// attempted expensive sending of messages to offline users. |
||
74 | /// The tradeoff is that a user that comes online will not receive messages consistently from all other users |
||
75 | /// until caches have updated. |
||
76 | /// Therefore, we set the cache expiry to just 20 seconds. |
||
77 | /// </remarks> |
||
78 | private ExpiringCache<UUID, PresenceInfo[]> m_usersOnlineCache; |
||
79 | |||
80 | private int m_usersOnlineCacheExpirySeconds = 20; |
||
81 | |||
82 | #region Region Module interfaceBase Members |
||
83 | |||
84 | public void Initialise(IConfigSource config) |
||
85 | { |
||
86 | IConfig groupsConfig = config.Configs["Groups"]; |
||
87 | |||
88 | if (groupsConfig == null) |
||
89 | { |
||
90 | // Do not run this module by default. |
||
91 | return; |
||
92 | } |
||
93 | else |
||
94 | { |
||
95 | // if groups aren't enabled, we're not needed. |
||
96 | // if we're not specified as the connector to use, then we're not wanted |
||
97 | if ((groupsConfig.GetBoolean("Enabled", false) == false) |
||
98 | || (groupsConfig.GetString("MessagingModule", "") != Name)) |
||
99 | { |
||
100 | m_groupMessagingEnabled = false; |
||
101 | return; |
||
102 | } |
||
103 | |||
104 | m_groupMessagingEnabled = groupsConfig.GetBoolean("MessagingEnabled", true); |
||
105 | |||
106 | if (!m_groupMessagingEnabled) |
||
107 | { |
||
108 | return; |
||
109 | } |
||
110 | |||
111 | m_messageOnlineAgentsOnly = groupsConfig.GetBoolean("MessageOnlineUsersOnly", false); |
||
112 | |||
113 | if (m_messageOnlineAgentsOnly) |
||
114 | m_usersOnlineCache = new ExpiringCache<UUID, PresenceInfo[]>(); |
||
115 | |||
116 | m_debugEnabled = groupsConfig.GetBoolean("DebugEnabled", true); |
||
117 | } |
||
118 | |||
119 | m_log.InfoFormat( |
||
120 | "[GROUPS-MESSAGING]: GroupsMessagingModule enabled with MessageOnlineOnly = {0}, DebugEnabled = {1}", |
||
121 | m_messageOnlineAgentsOnly, m_debugEnabled); |
||
122 | } |
||
123 | |||
124 | public void AddRegion(Scene scene) |
||
125 | { |
||
126 | if (!m_groupMessagingEnabled) |
||
127 | return; |
||
128 | |||
129 | scene.RegisterModuleInterface<IGroupsMessagingModule>(this); |
||
130 | } |
||
131 | |||
132 | public void RegionLoaded(Scene scene) |
||
133 | { |
||
134 | if (!m_groupMessagingEnabled) |
||
135 | return; |
||
136 | |||
137 | if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name); |
||
138 | |||
139 | m_groupData = scene.RequestModuleInterface<IGroupsServicesConnector>(); |
||
140 | |||
141 | // No groups module, no groups messaging |
||
142 | if (m_groupData == null) |
||
143 | { |
||
144 | m_log.Error("[GROUPS-MESSAGING]: Could not get IGroupsServicesConnector, GroupsMessagingModule is now disabled."); |
||
145 | Close(); |
||
146 | m_groupMessagingEnabled = false; |
||
147 | return; |
||
148 | } |
||
149 | |||
150 | m_msgTransferModule = scene.RequestModuleInterface<IMessageTransferModule>(); |
||
151 | |||
152 | // No message transfer module, no groups messaging |
||
153 | if (m_msgTransferModule == null) |
||
154 | { |
||
155 | m_log.Error("[GROUPS-MESSAGING]: Could not get MessageTransferModule"); |
||
156 | Close(); |
||
157 | m_groupMessagingEnabled = false; |
||
158 | return; |
||
159 | } |
||
160 | |||
161 | if (m_presenceService == null) |
||
162 | m_presenceService = scene.PresenceService; |
||
163 | |||
164 | m_sceneList.Add(scene); |
||
165 | |||
166 | scene.EventManager.OnNewClient += OnNewClient; |
||
167 | scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage; |
||
168 | scene.EventManager.OnClientLogin += OnClientLogin; |
||
169 | } |
||
170 | |||
171 | public void RemoveRegion(Scene scene) |
||
172 | { |
||
173 | if (!m_groupMessagingEnabled) |
||
174 | return; |
||
175 | |||
176 | if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name); |
||
177 | |||
178 | m_sceneList.Remove(scene); |
||
179 | } |
||
180 | |||
181 | public void Close() |
||
182 | { |
||
183 | if (!m_groupMessagingEnabled) |
||
184 | return; |
||
185 | |||
186 | if (m_debugEnabled) m_log.Debug("[GROUPS-MESSAGING]: Shutting down GroupsMessagingModule module."); |
||
187 | |||
188 | foreach (Scene scene in m_sceneList) |
||
189 | { |
||
190 | scene.EventManager.OnNewClient -= OnNewClient; |
||
191 | scene.EventManager.OnIncomingInstantMessage -= OnGridInstantMessage; |
||
192 | } |
||
193 | |||
194 | m_sceneList.Clear(); |
||
195 | |||
196 | m_groupData = null; |
||
197 | m_msgTransferModule = null; |
||
198 | } |
||
199 | |||
200 | public Type ReplaceableInterface |
||
201 | { |
||
202 | get { return null; } |
||
203 | } |
||
204 | |||
205 | public string Name |
||
206 | { |
||
207 | get { return "GroupsMessagingModule"; } |
||
208 | } |
||
209 | |||
210 | #endregion |
||
211 | |||
212 | #region ISharedRegionModule Members |
||
213 | |||
214 | public void PostInitialise() |
||
215 | { |
||
216 | // NoOp |
||
217 | } |
||
218 | |||
219 | #endregion |
||
220 | |||
221 | /// <summary> |
||
222 | /// Not really needed, but does confirm that the group exists. |
||
223 | /// </summary> |
||
224 | public bool StartGroupChatSession(UUID agentID, UUID groupID) |
||
225 | { |
||
226 | if (m_debugEnabled) |
||
227 | m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name); |
||
228 | |||
229 | GroupRecord groupInfo = m_groupData.GetGroupRecord(agentID, groupID, null); |
||
230 | |||
231 | if (groupInfo != null) |
||
232 | { |
||
233 | return true; |
||
234 | } |
||
235 | else |
||
236 | { |
||
237 | return false; |
||
238 | } |
||
239 | } |
||
240 | |||
241 | public void SendMessageToGroup(GridInstantMessage im, UUID groupID) |
||
242 | { |
||
243 | List<GroupMembersData> groupMembers = m_groupData.GetGroupMembers(new UUID(im.fromAgentID), groupID); |
||
244 | int groupMembersCount = groupMembers.Count; |
||
245 | |||
246 | if (m_messageOnlineAgentsOnly) |
||
247 | { |
||
248 | string[] t1 = groupMembers.ConvertAll<string>(gmd => gmd.AgentID.ToString()).ToArray(); |
||
249 | |||
250 | // We cache in order not to overwhlem the presence service on large grids with many groups. This does |
||
251 | // mean that members coming online will not see all group members until after m_usersOnlineCacheExpirySeconds has elapsed. |
||
252 | // (assuming this is the same across all grid simulators). |
||
253 | PresenceInfo[] onlineAgents; |
||
254 | if (!m_usersOnlineCache.TryGetValue(groupID, out onlineAgents)) |
||
255 | { |
||
256 | onlineAgents = m_presenceService.GetAgents(t1); |
||
257 | m_usersOnlineCache.Add(groupID, onlineAgents, m_usersOnlineCacheExpirySeconds); |
||
258 | } |
||
259 | |||
260 | HashSet<string> onlineAgentsUuidSet = new HashSet<string>(); |
||
261 | Array.ForEach<PresenceInfo>(onlineAgents, pi => onlineAgentsUuidSet.Add(pi.UserID)); |
||
262 | |||
263 | groupMembers = groupMembers.Where(gmd => onlineAgentsUuidSet.Contains(gmd.AgentID.ToString())).ToList(); |
||
264 | |||
265 | // if (m_debugEnabled) |
||
266 | // m_log.DebugFormat( |
||
267 | // "[GROUPS-MESSAGING]: SendMessageToGroup called for group {0} with {1} visible members, {2} online", |
||
268 | // groupID, groupMembersCount, groupMembers.Count()); |
||
269 | } |
||
270 | else |
||
271 | { |
||
272 | if (m_debugEnabled) |
||
273 | m_log.DebugFormat( |
||
274 | "[GROUPS-MESSAGING]: SendMessageToGroup called for group {0} with {1} visible members", |
||
275 | groupID, groupMembers.Count); |
||
276 | } |
||
277 | |||
278 | int requestStartTick = Environment.TickCount; |
||
279 | |||
280 | foreach (GroupMembersData member in groupMembers) |
||
281 | { |
||
282 | if (m_groupData.hasAgentDroppedGroupChatSession(member.AgentID, groupID)) |
||
283 | { |
||
284 | // Don't deliver messages to people who have dropped this session |
||
285 | if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: {0} has dropped session, not delivering to them", member.AgentID); |
||
286 | continue; |
||
287 | } |
||
288 | |||
289 | // Copy Message |
||
290 | GridInstantMessage msg = new GridInstantMessage(); |
||
291 | msg.imSessionID = groupID.Guid; |
||
292 | msg.fromAgentName = im.fromAgentName; |
||
293 | msg.message = im.message; |
||
294 | msg.dialog = im.dialog; |
||
295 | msg.offline = im.offline; |
||
296 | msg.ParentEstateID = im.ParentEstateID; |
||
297 | msg.Position = im.Position; |
||
298 | msg.RegionID = im.RegionID; |
||
299 | msg.binaryBucket = im.binaryBucket; |
||
300 | msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); |
||
301 | |||
302 | msg.fromAgentID = im.fromAgentID; |
||
303 | msg.fromGroup = true; |
||
304 | |||
305 | msg.toAgentID = member.AgentID.Guid; |
||
306 | |||
307 | IClientAPI client = GetActiveClient(member.AgentID); |
||
308 | if (client == null) |
||
309 | { |
||
310 | // If they're not local, forward across the grid |
||
311 | if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: Delivering to {0} via Grid", member.AgentID); |
||
312 | m_msgTransferModule.SendInstantMessage(msg, delegate(bool success) { }); |
||
313 | } |
||
314 | else |
||
315 | { |
||
316 | // Deliver locally, directly |
||
317 | if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: Passing to ProcessMessageFromGroupSession to deliver to {0} locally", client.Name); |
||
318 | ProcessMessageFromGroupSession(msg); |
||
319 | } |
||
320 | } |
||
321 | |||
322 | // Temporary for assessing how long it still takes to send messages to large online groups. |
||
323 | if (m_messageOnlineAgentsOnly) |
||
324 | m_log.DebugFormat( |
||
325 | "[GROUPS-MESSAGING]: SendMessageToGroup for group {0} with {1} visible members, {2} online took {3}ms", |
||
326 | groupID, groupMembersCount, groupMembers.Count(), Environment.TickCount - requestStartTick); |
||
327 | } |
||
328 | |||
329 | #region SimGridEventHandlers |
||
330 | |||
331 | void OnClientLogin(IClientAPI client) |
||
332 | { |
||
333 | if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: OnInstantMessage registered for {0}", client.Name); |
||
334 | } |
||
335 | |||
336 | private void OnNewClient(IClientAPI client) |
||
337 | { |
||
338 | if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: OnInstantMessage registered for {0}", client.Name); |
||
339 | |||
340 | client.OnInstantMessage += OnInstantMessage; |
||
341 | } |
||
342 | |||
343 | private void OnGridInstantMessage(GridInstantMessage msg) |
||
344 | { |
||
345 | // The instant message module will only deliver messages of dialog types: |
||
346 | // MessageFromAgent, StartTyping, StopTyping, MessageFromObject |
||
347 | // |
||
348 | // Any other message type will not be delivered to a client by the |
||
349 | // Instant Message Module |
||
350 | |||
351 | |||
352 | if (m_debugEnabled) |
||
353 | { |
||
354 | m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name); |
||
355 | |||
356 | DebugGridInstantMessage(msg); |
||
357 | } |
||
358 | |||
359 | // Incoming message from a group |
||
360 | if ((msg.fromGroup == true) && |
||
361 | ((msg.dialog == (byte)InstantMessageDialog.SessionSend) |
||
362 | || (msg.dialog == (byte)InstantMessageDialog.SessionAdd) |
||
363 | || (msg.dialog == (byte)InstantMessageDialog.SessionDrop))) |
||
364 | { |
||
365 | ProcessMessageFromGroupSession(msg); |
||
366 | } |
||
367 | } |
||
368 | |||
369 | private void ProcessMessageFromGroupSession(GridInstantMessage msg) |
||
370 | { |
||
371 | if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: Session message from {0} going to agent {1}", msg.fromAgentName, msg.toAgentID); |
||
372 | |||
373 | UUID AgentID = new UUID(msg.fromAgentID); |
||
374 | UUID GroupID = new UUID(msg.imSessionID); |
||
375 | |||
376 | switch (msg.dialog) |
||
377 | { |
||
378 | case (byte)InstantMessageDialog.SessionAdd: |
||
379 | m_groupData.AgentInvitedToGroupChatSession(AgentID, GroupID); |
||
380 | break; |
||
381 | |||
382 | case (byte)InstantMessageDialog.SessionDrop: |
||
383 | m_groupData.AgentDroppedFromGroupChatSession(AgentID, GroupID); |
||
384 | break; |
||
385 | |||
386 | case (byte)InstantMessageDialog.SessionSend: |
||
387 | if (!m_groupData.hasAgentDroppedGroupChatSession(AgentID, GroupID) |
||
388 | && !m_groupData.hasAgentBeenInvitedToGroupChatSession(AgentID, GroupID) |
||
389 | ) |
||
390 | { |
||
391 | // Agent not in session and hasn't dropped from session |
||
392 | // Add them to the session for now, and Invite them |
||
393 | m_groupData.AgentInvitedToGroupChatSession(AgentID, GroupID); |
||
394 | |||
395 | UUID toAgentID = new UUID(msg.toAgentID); |
||
396 | IClientAPI activeClient = GetActiveClient(toAgentID); |
||
397 | if (activeClient != null) |
||
398 | { |
||
399 | GroupRecord groupInfo = m_groupData.GetGroupRecord(UUID.Zero, GroupID, null); |
||
400 | if (groupInfo != null) |
||
401 | { |
||
402 | if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: Sending chatterbox invite instant message"); |
||
403 | |||
404 | // Force? open the group session dialog??? |
||
405 | // and simultanously deliver the message, so we don't need to do a seperate client.SendInstantMessage(msg); |
||
406 | IEventQueue eq = activeClient.Scene.RequestModuleInterface<IEventQueue>(); |
||
407 | eq.ChatterboxInvitation( |
||
408 | GroupID |
||
409 | , groupInfo.GroupName |
||
410 | , new UUID(msg.fromAgentID) |
||
411 | , msg.message |
||
412 | , new UUID(msg.toAgentID) |
||
413 | , msg.fromAgentName |
||
414 | , msg.dialog |
||
415 | , msg.timestamp |
||
416 | , msg.offline == 1 |
||
417 | , (int)msg.ParentEstateID |
||
418 | , msg.Position |
||
419 | , 1 |
||
420 | , new UUID(msg.imSessionID) |
||
421 | , msg.fromGroup |
||
422 | , Utils.StringToBytes(groupInfo.GroupName) |
||
423 | ); |
||
424 | |||
425 | eq.ChatterBoxSessionAgentListUpdates( |
||
426 | new UUID(GroupID) |
||
427 | , new UUID(msg.fromAgentID) |
||
428 | , new UUID(msg.toAgentID) |
||
429 | , false //canVoiceChat |
||
430 | , false //isModerator |
||
431 | , false //text mute |
||
432 | ); |
||
433 | } |
||
434 | } |
||
435 | } |
||
436 | else if (!m_groupData.hasAgentDroppedGroupChatSession(AgentID, GroupID)) |
||
437 | { |
||
438 | // User hasn't dropped, so they're in the session, |
||
439 | // maybe we should deliver it. |
||
440 | IClientAPI client = GetActiveClient(new UUID(msg.toAgentID)); |
||
441 | if (client != null) |
||
442 | { |
||
443 | // Deliver locally, directly |
||
444 | if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: Delivering to {0} locally", client.Name); |
||
445 | client.SendInstantMessage(msg); |
||
446 | } |
||
447 | else |
||
448 | { |
||
449 | m_log.WarnFormat("[GROUPS-MESSAGING]: Received a message over the grid for a client that isn't here: {0}", msg.toAgentID); |
||
450 | } |
||
451 | } |
||
452 | break; |
||
453 | |||
454 | default: |
||
455 | m_log.WarnFormat("[GROUPS-MESSAGING]: I don't know how to proccess a {0} message.", ((InstantMessageDialog)msg.dialog).ToString()); |
||
456 | break; |
||
457 | } |
||
458 | } |
||
459 | |||
460 | #endregion |
||
461 | |||
462 | |||
463 | #region ClientEvents |
||
464 | private void OnInstantMessage(IClientAPI remoteClient, GridInstantMessage im) |
||
465 | { |
||
466 | if (m_debugEnabled) |
||
467 | { |
||
468 | m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name); |
||
469 | |||
470 | DebugGridInstantMessage(im); |
||
471 | } |
||
472 | |||
473 | // Start group IM session |
||
474 | if ((im.dialog == (byte)InstantMessageDialog.SessionGroupStart)) |
||
475 | { |
||
476 | if (m_debugEnabled) m_log.InfoFormat("[GROUPS-MESSAGING]: imSessionID({0}) toAgentID({1})", im.imSessionID, im.toAgentID); |
||
477 | |||
478 | UUID GroupID = new UUID(im.imSessionID); |
||
479 | UUID AgentID = new UUID(im.fromAgentID); |
||
480 | |||
481 | GroupRecord groupInfo = m_groupData.GetGroupRecord(UUID.Zero, GroupID, null); |
||
482 | |||
483 | if (groupInfo != null) |
||
484 | { |
||
485 | m_groupData.AgentInvitedToGroupChatSession(AgentID, GroupID); |
||
486 | |||
487 | ChatterBoxSessionStartReplyViaCaps(remoteClient, groupInfo.GroupName, GroupID); |
||
488 | |||
489 | IEventQueue queue = remoteClient.Scene.RequestModuleInterface<IEventQueue>(); |
||
490 | queue.ChatterBoxSessionAgentListUpdates( |
||
491 | GroupID |
||
492 | , AgentID |
||
493 | , new UUID(im.toAgentID) |
||
494 | , false //canVoiceChat |
||
495 | , false //isModerator |
||
496 | , false //text mute |
||
497 | ); |
||
498 | } |
||
499 | } |
||
500 | |||
501 | // Send a message from locally connected client to a group |
||
502 | if ((im.dialog == (byte)InstantMessageDialog.SessionSend)) |
||
503 | { |
||
504 | UUID GroupID = new UUID(im.imSessionID); |
||
505 | UUID AgentID = new UUID(im.fromAgentID); |
||
506 | |||
507 | if (m_debugEnabled) |
||
508 | m_log.DebugFormat("[GROUPS-MESSAGING]: Send message to session for group {0} with session ID {1}", GroupID, im.imSessionID.ToString()); |
||
509 | |||
510 | //If this agent is sending a message, then they want to be in the session |
||
511 | m_groupData.AgentInvitedToGroupChatSession(AgentID, GroupID); |
||
512 | |||
513 | SendMessageToGroup(im, GroupID); |
||
514 | } |
||
515 | } |
||
516 | |||
517 | #endregion |
||
518 | |||
519 | void ChatterBoxSessionStartReplyViaCaps(IClientAPI remoteClient, string groupName, UUID groupID) |
||
520 | { |
||
521 | if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name); |
||
522 | |||
523 | OSDMap moderatedMap = new OSDMap(4); |
||
524 | moderatedMap.Add("voice", OSD.FromBoolean(false)); |
||
525 | |||
526 | OSDMap sessionMap = new OSDMap(4); |
||
527 | sessionMap.Add("moderated_mode", moderatedMap); |
||
528 | sessionMap.Add("session_name", OSD.FromString(groupName)); |
||
529 | sessionMap.Add("type", OSD.FromInteger(0)); |
||
530 | sessionMap.Add("voice_enabled", OSD.FromBoolean(false)); |
||
531 | |||
532 | OSDMap bodyMap = new OSDMap(4); |
||
533 | bodyMap.Add("session_id", OSD.FromUUID(groupID)); |
||
534 | bodyMap.Add("temp_session_id", OSD.FromUUID(groupID)); |
||
535 | bodyMap.Add("success", OSD.FromBoolean(true)); |
||
536 | bodyMap.Add("session_info", sessionMap); |
||
537 | |||
538 | IEventQueue queue = remoteClient.Scene.RequestModuleInterface<IEventQueue>(); |
||
539 | |||
540 | if (queue != null) |
||
541 | { |
||
542 | queue.Enqueue(queue.BuildEvent("ChatterBoxSessionStartReply", bodyMap), remoteClient.AgentId); |
||
543 | } |
||
544 | } |
||
545 | |||
546 | private void DebugGridInstantMessage(GridInstantMessage im) |
||
547 | { |
||
548 | // Don't log any normal IMs (privacy!) |
||
549 | if (m_debugEnabled && im.dialog != (byte)InstantMessageDialog.MessageFromAgent) |
||
550 | { |
||
551 | m_log.WarnFormat("[GROUPS-MESSAGING]: IM: fromGroup({0})", im.fromGroup ? "True" : "False"); |
||
552 | m_log.WarnFormat("[GROUPS-MESSAGING]: IM: Dialog({0})", ((InstantMessageDialog)im.dialog).ToString()); |
||
553 | m_log.WarnFormat("[GROUPS-MESSAGING]: IM: fromAgentID({0})", im.fromAgentID.ToString()); |
||
554 | m_log.WarnFormat("[GROUPS-MESSAGING]: IM: fromAgentName({0})", im.fromAgentName.ToString()); |
||
555 | m_log.WarnFormat("[GROUPS-MESSAGING]: IM: imSessionID({0})", im.imSessionID.ToString()); |
||
556 | m_log.WarnFormat("[GROUPS-MESSAGING]: IM: message({0})", im.message.ToString()); |
||
557 | m_log.WarnFormat("[GROUPS-MESSAGING]: IM: offline({0})", im.offline.ToString()); |
||
558 | m_log.WarnFormat("[GROUPS-MESSAGING]: IM: toAgentID({0})", im.toAgentID.ToString()); |
||
559 | m_log.WarnFormat("[GROUPS-MESSAGING]: IM: binaryBucket({0})", OpenMetaverse.Utils.BytesToHexString(im.binaryBucket, "BinaryBucket")); |
||
560 | } |
||
561 | } |
||
562 | |||
563 | #region Client Tools |
||
564 | |||
565 | /// <summary> |
||
566 | /// Try to find an active IClientAPI reference for agentID giving preference to root connections |
||
567 | /// </summary> |
||
568 | private IClientAPI GetActiveClient(UUID agentID) |
||
569 | { |
||
570 | if (m_debugEnabled) m_log.WarnFormat("[GROUPS-MESSAGING]: Looking for local client {0}", agentID); |
||
571 | |||
572 | IClientAPI child = null; |
||
573 | |||
574 | // Try root avatar first |
||
575 | foreach (Scene scene in m_sceneList) |
||
576 | { |
||
577 | ScenePresence sp = scene.GetScenePresence(agentID); |
||
578 | if (sp != null) |
||
579 | { |
||
580 | if (!sp.IsChildAgent) |
||
581 | { |
||
582 | if (m_debugEnabled) m_log.WarnFormat("[GROUPS-MESSAGING]: Found root agent for client : {0}", sp.ControllingClient.Name); |
||
583 | return sp.ControllingClient; |
||
584 | } |
||
585 | else |
||
586 | { |
||
587 | if (m_debugEnabled) m_log.WarnFormat("[GROUPS-MESSAGING]: Found child agent for client : {0}", sp.ControllingClient.Name); |
||
588 | child = sp.ControllingClient; |
||
589 | } |
||
590 | } |
||
591 | } |
||
592 | |||
593 | // If we didn't find a root, then just return whichever child we found, or null if none |
||
594 | if (child == null) |
||
595 | { |
||
596 | if (m_debugEnabled) m_log.WarnFormat("[GROUPS-MESSAGING]: Could not find local client for agent : {0}", agentID); |
||
597 | } |
||
598 | else |
||
599 | { |
||
600 | if (m_debugEnabled) m_log.WarnFormat("[GROUPS-MESSAGING]: Returning child agent for client : {0}", child.Name); |
||
601 | } |
||
602 | return child; |
||
603 | } |
||
604 | |||
605 | #endregion |
||
606 | } |
||
607 | } |