GroupsMessagingModule.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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.OutputFormat("{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. //Array.ForEach<PresenceInfo>(onlineAgents, pi => attemptDeliveryUuidSet.Add(pi.UserID));
  243. //groupMembers = groupMembers.Where(gmd => onlineAgentsUuidSet.Contains(gmd.AgentID.ToString())).ToList();
  244. // if (m_debugEnabled)
  245. // m_log.DebugFormat(
  246. // "[GROUPS-MESSAGING]: SendMessageToGroup called for group {0} with {1} visible members, {2} online",
  247. // groupID, groupMembersCount, groupMembers.Count());
  248. }
  249. else
  250. {
  251. attemptDeliveryUuidSet
  252. = new HashSet<string>(groupMembers.ConvertAll<string>(gmd => gmd.AgentID.ToString()));
  253. if (m_debugEnabled)
  254. m_log.DebugFormat(
  255. "[GROUPS-MESSAGING]: SendMessageToGroup called for group {0} with {1} visible members",
  256. groupID, groupMembers.Count);
  257. }
  258. foreach (GroupMembersData member in groupMembers)
  259. {
  260. if (sendCondition != null)
  261. {
  262. if (!sendCondition(member))
  263. {
  264. if (m_debugEnabled)
  265. m_log.DebugFormat(
  266. "[GROUPS-MESSAGING]: Not sending to {0} as they do not fulfill send condition",
  267. member.AgentID);
  268. continue;
  269. }
  270. }
  271. else if (m_groupData.hasAgentDroppedGroupChatSession(member.AgentID, groupID))
  272. {
  273. // Don't deliver messages to people who have dropped this session
  274. if (m_debugEnabled)
  275. m_log.DebugFormat(
  276. "[GROUPS-MESSAGING]: {0} has dropped session, not delivering to them", member.AgentID);
  277. continue;
  278. }
  279. // Copy Message
  280. GridInstantMessage msg = new GridInstantMessage();
  281. msg.imSessionID = im.imSessionID;
  282. msg.fromAgentName = im.fromAgentName;
  283. msg.message = im.message;
  284. msg.dialog = im.dialog;
  285. msg.offline = im.offline;
  286. msg.ParentEstateID = im.ParentEstateID;
  287. msg.Position = im.Position;
  288. msg.RegionID = im.RegionID;
  289. msg.binaryBucket = im.binaryBucket;
  290. msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
  291. msg.fromAgentID = im.fromAgentID;
  292. msg.fromGroup = true;
  293. msg.toAgentID = member.AgentID.Guid;
  294. if (attemptDeliveryUuidSet.Contains(member.AgentID.ToString()))
  295. {
  296. IClientAPI client = GetActiveClient(member.AgentID);
  297. if (client == null)
  298. {
  299. int startTick = Environment.TickCount;
  300. // If they're not local, forward across the grid
  301. m_msgTransferModule.SendInstantMessage(msg, delegate(bool success) { });
  302. if (m_debugEnabled)
  303. m_log.DebugFormat(
  304. "[GROUPS-MESSAGING]: Delivering to {0} via grid took {1} ms",
  305. member.AgentID, Environment.TickCount - startTick);
  306. }
  307. else
  308. {
  309. int startTick = Environment.TickCount;
  310. ProcessMessageFromGroupSession(msg, client);
  311. // Deliver locally, directly
  312. if (m_debugEnabled)
  313. m_log.DebugFormat(
  314. "[GROUPS-MESSAGING]: Delivering to {0} locally took {1} ms",
  315. member.AgentID, Environment.TickCount - startTick);
  316. }
  317. }
  318. else
  319. {
  320. int startTick = Environment.TickCount;
  321. m_msgTransferModule.HandleUndeliverableMessage(msg, delegate(bool success) { });
  322. if (m_debugEnabled)
  323. m_log.DebugFormat(
  324. "[GROUPS-MESSAGING]: Handling undeliverable message for {0} took {1} ms",
  325. member.AgentID, Environment.TickCount - startTick);
  326. }
  327. }
  328. if (m_debugEnabled)
  329. m_log.DebugFormat(
  330. "[GROUPS-MESSAGING]: Total SendMessageToGroup for group {0} with {1} members, {2} candidates for delivery took {3} ms",
  331. groupID, groupMembersCount, attemptDeliveryUuidSet.Count(), Environment.TickCount - requestStartTick);
  332. }
  333. #region SimGridEventHandlers
  334. void OnClientLogin(IClientAPI client)
  335. {
  336. if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: OnInstantMessage registered for {0}", client.Name);
  337. }
  338. private void OnNewClient(IClientAPI client)
  339. {
  340. if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: OnInstantMessage registered for {0}", client.Name);
  341. client.OnInstantMessage += OnInstantMessage;
  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. if (m_debugEnabled)
  351. {
  352. m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  353. DebugGridInstantMessage(msg);
  354. }
  355. // Incoming message from a group
  356. if ((msg.fromGroup == true) &&
  357. ((msg.dialog == (byte)InstantMessageDialog.SessionSend)
  358. || (msg.dialog == (byte)InstantMessageDialog.SessionAdd)
  359. || (msg.dialog == (byte)InstantMessageDialog.SessionDrop)))
  360. {
  361. IClientAPI client = null;
  362. if (msg.dialog == (byte)InstantMessageDialog.SessionSend)
  363. {
  364. client = GetActiveClient(new UUID(msg.toAgentID));
  365. if (client != null)
  366. {
  367. if (m_debugEnabled)
  368. m_log.DebugFormat("[GROUPS-MESSAGING]: Delivering to {0} locally", client.Name);
  369. }
  370. else
  371. {
  372. m_log.WarnFormat("[GROUPS-MESSAGING]: Received a message over the grid for a client that isn't here: {0}", msg.toAgentID);
  373. return;
  374. }
  375. }
  376. ProcessMessageFromGroupSession(msg, client);
  377. }
  378. }
  379. private void ProcessMessageFromGroupSession(GridInstantMessage msg, IClientAPI client)
  380. {
  381. if (m_debugEnabled)
  382. m_log.DebugFormat(
  383. "[GROUPS-MESSAGING]: Session message from {0} going to agent {1}, sessionID {2}, type {3}",
  384. msg.fromAgentName, msg.toAgentID, msg.imSessionID, (InstantMessageDialog)msg.dialog);
  385. UUID AgentID = new UUID(msg.fromAgentID);
  386. UUID GroupID = new UUID(msg.imSessionID);
  387. switch (msg.dialog)
  388. {
  389. case (byte)InstantMessageDialog.SessionAdd:
  390. m_groupData.AgentInvitedToGroupChatSession(AgentID, GroupID);
  391. break;
  392. case (byte)InstantMessageDialog.SessionDrop:
  393. m_groupData.AgentDroppedFromGroupChatSession(AgentID, GroupID);
  394. break;
  395. case (byte)InstantMessageDialog.SessionSend:
  396. if (!m_groupData.hasAgentDroppedGroupChatSession(AgentID, GroupID)
  397. && !m_groupData.hasAgentBeenInvitedToGroupChatSession(AgentID, GroupID)
  398. )
  399. {
  400. // Agent not in session and hasn't dropped from session
  401. // Add them to the session for now, and Invite them
  402. m_groupData.AgentInvitedToGroupChatSession(AgentID, GroupID);
  403. GroupRecord groupInfo = m_groupData.GetGroupRecord(UUID.Zero, GroupID, null);
  404. if (groupInfo != null)
  405. {
  406. if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: Sending chatterbox invite instant message");
  407. // Force? open the group session dialog???
  408. // and simultanously deliver the message, so we don't need to do a seperate client.SendInstantMessage(msg);
  409. IEventQueue eq = client.Scene.RequestModuleInterface<IEventQueue>();
  410. eq.ChatterboxInvitation(
  411. GroupID
  412. , groupInfo.GroupName
  413. , new UUID(msg.fromAgentID)
  414. , msg.message
  415. , new UUID(msg.toAgentID)
  416. , msg.fromAgentName
  417. , msg.dialog
  418. , msg.timestamp
  419. , msg.offline == 1
  420. , (int)msg.ParentEstateID
  421. , msg.Position
  422. , 1
  423. , new UUID(msg.imSessionID)
  424. , msg.fromGroup
  425. , Utils.StringToBytes(groupInfo.GroupName)
  426. );
  427. eq.ChatterBoxSessionAgentListUpdates(
  428. new UUID(GroupID)
  429. , new UUID(msg.fromAgentID)
  430. , new UUID(msg.toAgentID)
  431. , false //canVoiceChat
  432. , false //isModerator
  433. , false //text mute
  434. );
  435. }
  436. break;
  437. }
  438. else if (!m_groupData.hasAgentDroppedGroupChatSession(AgentID, GroupID))
  439. {
  440. // User hasn't dropped, so they're in the session,
  441. // maybe we should deliver it.
  442. client.SendInstantMessage(msg);
  443. }
  444. break;
  445. default:
  446. client.SendInstantMessage(msg);
  447. break;;
  448. }
  449. }
  450. #endregion
  451. #region ClientEvents
  452. private void OnInstantMessage(IClientAPI remoteClient, GridInstantMessage im)
  453. {
  454. if (m_debugEnabled)
  455. {
  456. m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  457. DebugGridInstantMessage(im);
  458. }
  459. // Start group IM session
  460. if ((im.dialog == (byte)InstantMessageDialog.SessionGroupStart))
  461. {
  462. if (m_debugEnabled) m_log.InfoFormat("[GROUPS-MESSAGING]: imSessionID({0}) toAgentID({1})", im.imSessionID, im.toAgentID);
  463. UUID GroupID = new UUID(im.imSessionID);
  464. UUID AgentID = new UUID(im.fromAgentID);
  465. GroupRecord groupInfo = m_groupData.GetGroupRecord(UUID.Zero, GroupID, null);
  466. if (groupInfo != null)
  467. {
  468. m_groupData.AgentInvitedToGroupChatSession(AgentID, GroupID);
  469. ChatterBoxSessionStartReplyViaCaps(remoteClient, groupInfo.GroupName, GroupID);
  470. IEventQueue queue = remoteClient.Scene.RequestModuleInterface<IEventQueue>();
  471. queue.ChatterBoxSessionAgentListUpdates(
  472. GroupID
  473. , AgentID
  474. , new UUID(im.toAgentID)
  475. , false //canVoiceChat
  476. , false //isModerator
  477. , false //text mute
  478. );
  479. }
  480. }
  481. // Send a message from locally connected client to a group
  482. if ((im.dialog == (byte)InstantMessageDialog.SessionSend))
  483. {
  484. UUID GroupID = new UUID(im.imSessionID);
  485. UUID AgentID = new UUID(im.fromAgentID);
  486. if (m_debugEnabled)
  487. m_log.DebugFormat("[GROUPS-MESSAGING]: Send message to session for group {0} with session ID {1}", GroupID, im.imSessionID.ToString());
  488. //If this agent is sending a message, then they want to be in the session
  489. m_groupData.AgentInvitedToGroupChatSession(AgentID, GroupID);
  490. SendMessageToGroup(im, GroupID);
  491. }
  492. }
  493. #endregion
  494. void ChatterBoxSessionStartReplyViaCaps(IClientAPI remoteClient, string groupName, UUID groupID)
  495. {
  496. if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  497. OSDMap moderatedMap = new OSDMap(4);
  498. moderatedMap.Add("voice", OSD.FromBoolean(false));
  499. OSDMap sessionMap = new OSDMap(4);
  500. sessionMap.Add("moderated_mode", moderatedMap);
  501. sessionMap.Add("session_name", OSD.FromString(groupName));
  502. sessionMap.Add("type", OSD.FromInteger(0));
  503. sessionMap.Add("voice_enabled", OSD.FromBoolean(false));
  504. OSDMap bodyMap = new OSDMap(4);
  505. bodyMap.Add("session_id", OSD.FromUUID(groupID));
  506. bodyMap.Add("temp_session_id", OSD.FromUUID(groupID));
  507. bodyMap.Add("success", OSD.FromBoolean(true));
  508. bodyMap.Add("session_info", sessionMap);
  509. IEventQueue queue = remoteClient.Scene.RequestModuleInterface<IEventQueue>();
  510. if (queue != null)
  511. {
  512. queue.Enqueue(queue.BuildEvent("ChatterBoxSessionStartReply", bodyMap), remoteClient.AgentId);
  513. }
  514. }
  515. private void DebugGridInstantMessage(GridInstantMessage im)
  516. {
  517. // Don't log any normal IMs (privacy!)
  518. if (m_debugEnabled && im.dialog != (byte)InstantMessageDialog.MessageFromAgent)
  519. {
  520. m_log.DebugFormat("[GROUPS-MESSAGING]: IM: fromGroup({0})", im.fromGroup ? "True" : "False");
  521. m_log.DebugFormat("[GROUPS-MESSAGING]: IM: Dialog({0})", (InstantMessageDialog)im.dialog);
  522. m_log.DebugFormat("[GROUPS-MESSAGING]: IM: fromAgentID({0})", im.fromAgentID);
  523. m_log.DebugFormat("[GROUPS-MESSAGING]: IM: fromAgentName({0})", im.fromAgentName);
  524. m_log.DebugFormat("[GROUPS-MESSAGING]: IM: imSessionID({0})", im.imSessionID);
  525. m_log.DebugFormat("[GROUPS-MESSAGING]: IM: message({0})", im.message);
  526. m_log.DebugFormat("[GROUPS-MESSAGING]: IM: offline({0})", im.offline);
  527. m_log.DebugFormat("[GROUPS-MESSAGING]: IM: toAgentID({0})", im.toAgentID);
  528. m_log.DebugFormat("[GROUPS-MESSAGING]: IM: binaryBucket({0})", OpenMetaverse.Utils.BytesToHexString(im.binaryBucket, "BinaryBucket"));
  529. }
  530. }
  531. #region Client Tools
  532. /// <summary>
  533. /// Try to find an active IClientAPI reference for agentID giving preference to root connections
  534. /// </summary>
  535. private IClientAPI GetActiveClient(UUID agentID)
  536. {
  537. if (m_debugEnabled)
  538. m_log.DebugFormat("[GROUPS-MESSAGING]: Looking for local client {0}", agentID);
  539. IClientAPI child = null;
  540. // Try root avatar first
  541. foreach (Scene scene in m_sceneList)
  542. {
  543. ScenePresence sp = scene.GetScenePresence(agentID);
  544. if (sp != null)
  545. {
  546. if (!sp.IsChildAgent)
  547. {
  548. if (m_debugEnabled)
  549. m_log.DebugFormat("[GROUPS-MESSAGING]: Found root agent for client : {0}", sp.ControllingClient.Name);
  550. return sp.ControllingClient;
  551. }
  552. else
  553. {
  554. if (m_debugEnabled)
  555. m_log.DebugFormat("[GROUPS-MESSAGING]: Found child agent for client : {0}", sp.ControllingClient.Name);
  556. child = sp.ControllingClient;
  557. }
  558. }
  559. }
  560. // If we didn't find a root, then just return whichever child we found, or null if none
  561. if (child == null)
  562. {
  563. if (m_debugEnabled)
  564. m_log.DebugFormat("[GROUPS-MESSAGING]: Could not find local client for agent : {0}", agentID);
  565. }
  566. else
  567. {
  568. if (m_debugEnabled)
  569. m_log.DebugFormat("[GROUPS-MESSAGING]: Returning child agent for client : {0}", child.Name);
  570. }
  571. return child;
  572. }
  573. #endregion
  574. }
  575. }