GroupsMessagingModule.cs 28 KB

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