GroupsMessagingModule.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  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 = false;
  53. private bool m_debugEnabled = true;
  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("DebugEnabled", true);
  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. }
  111. public void RegionLoaded(Scene scene)
  112. {
  113. if (!m_groupMessagingEnabled)
  114. return;
  115. if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  116. m_groupData = scene.RequestModuleInterface<IGroupsServicesConnector>();
  117. // No groups module, no groups messaging
  118. if (m_groupData == null)
  119. {
  120. m_log.Error("[GROUPS-MESSAGING]: Could not get IGroupsServicesConnector, GroupsMessagingModule is now disabled.");
  121. Close();
  122. m_groupMessagingEnabled = false;
  123. return;
  124. }
  125. m_msgTransferModule = scene.RequestModuleInterface<IMessageTransferModule>();
  126. // No message transfer module, no groups messaging
  127. if (m_msgTransferModule == null)
  128. {
  129. m_log.Error("[GROUPS-MESSAGING]: Could not get MessageTransferModule");
  130. Close();
  131. m_groupMessagingEnabled = false;
  132. return;
  133. }
  134. if (m_presenceService == null)
  135. m_presenceService = scene.PresenceService;
  136. m_sceneList.Add(scene);
  137. scene.EventManager.OnNewClient += OnNewClient;
  138. scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage;
  139. scene.EventManager.OnClientLogin += OnClientLogin;
  140. }
  141. public void RemoveRegion(Scene scene)
  142. {
  143. if (!m_groupMessagingEnabled)
  144. return;
  145. if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  146. m_sceneList.Remove(scene);
  147. }
  148. public void Close()
  149. {
  150. if (!m_groupMessagingEnabled)
  151. return;
  152. if (m_debugEnabled) m_log.Debug("[GROUPS-MESSAGING]: Shutting down GroupsMessagingModule module.");
  153. foreach (Scene scene in m_sceneList)
  154. {
  155. scene.EventManager.OnNewClient -= OnNewClient;
  156. scene.EventManager.OnIncomingInstantMessage -= OnGridInstantMessage;
  157. }
  158. m_sceneList.Clear();
  159. m_groupData = null;
  160. m_msgTransferModule = null;
  161. }
  162. public Type ReplaceableInterface
  163. {
  164. get { return null; }
  165. }
  166. public string Name
  167. {
  168. get { return "GroupsMessagingModule"; }
  169. }
  170. #endregion
  171. #region ISharedRegionModule Members
  172. public void PostInitialise()
  173. {
  174. // NoOp
  175. }
  176. #endregion
  177. /// <summary>
  178. /// Not really needed, but does confirm that the group exists.
  179. /// </summary>
  180. public bool StartGroupChatSession(UUID agentID, UUID groupID)
  181. {
  182. if (m_debugEnabled)
  183. m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  184. GroupRecord groupInfo = m_groupData.GetGroupRecord(agentID, groupID, null);
  185. if (groupInfo != null)
  186. {
  187. return true;
  188. }
  189. else
  190. {
  191. return false;
  192. }
  193. }
  194. public void SendMessageToGroup(GridInstantMessage im, UUID groupID)
  195. {
  196. List<GroupMembersData> groupMembers = m_groupData.GetGroupMembers(new UUID(im.fromAgentID), groupID);
  197. int groupMembersCount = groupMembers.Count;
  198. if (m_messageOnlineAgentsOnly)
  199. {
  200. string[] t1 = groupMembers.ConvertAll<string>(gmd => gmd.AgentID.ToString()).ToArray();
  201. // We cache in order not to overwhlem the presence service on large grids with many groups. This does
  202. // mean that members coming online will not see all group members until after m_usersOnlineCacheExpirySeconds has elapsed.
  203. // (assuming this is the same across all grid simulators).
  204. PresenceInfo[] onlineAgents;
  205. if (!m_usersOnlineCache.TryGetValue(groupID, out onlineAgents))
  206. {
  207. onlineAgents = m_presenceService.GetAgents(t1);
  208. m_usersOnlineCache.Add(groupID, onlineAgents, m_usersOnlineCacheExpirySeconds);
  209. }
  210. HashSet<string> onlineAgentsUuidSet = new HashSet<string>();
  211. Array.ForEach<PresenceInfo>(onlineAgents, pi => onlineAgentsUuidSet.Add(pi.UserID));
  212. groupMembers = groupMembers.Where(gmd => onlineAgentsUuidSet.Contains(gmd.AgentID.ToString())).ToList();
  213. // if (m_debugEnabled)
  214. // m_log.DebugFormat(
  215. // "[GROUPS-MESSAGING]: SendMessageToGroup called for group {0} with {1} visible members, {2} online",
  216. // groupID, groupMembersCount, groupMembers.Count());
  217. }
  218. else
  219. {
  220. if (m_debugEnabled)
  221. m_log.DebugFormat(
  222. "[GROUPS-MESSAGING]: SendMessageToGroup called for group {0} with {1} visible members",
  223. groupID, groupMembers.Count);
  224. }
  225. int requestStartTick = Environment.TickCount;
  226. foreach (GroupMembersData member in groupMembers)
  227. {
  228. if (m_groupData.hasAgentDroppedGroupChatSession(member.AgentID, groupID))
  229. {
  230. // Don't deliver messages to people who have dropped this session
  231. if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: {0} has dropped session, not delivering to them", member.AgentID);
  232. continue;
  233. }
  234. // Copy Message
  235. GridInstantMessage msg = new GridInstantMessage();
  236. msg.imSessionID = groupID.Guid;
  237. msg.fromAgentName = im.fromAgentName;
  238. msg.message = im.message;
  239. msg.dialog = im.dialog;
  240. msg.offline = im.offline;
  241. msg.ParentEstateID = im.ParentEstateID;
  242. msg.Position = im.Position;
  243. msg.RegionID = im.RegionID;
  244. msg.binaryBucket = im.binaryBucket;
  245. msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
  246. msg.fromAgentID = im.fromAgentID;
  247. msg.fromGroup = true;
  248. msg.toAgentID = member.AgentID.Guid;
  249. IClientAPI client = GetActiveClient(member.AgentID);
  250. if (client == null)
  251. {
  252. // If they're not local, forward across the grid
  253. if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: Delivering to {0} via Grid", member.AgentID);
  254. m_msgTransferModule.SendInstantMessage(msg, delegate(bool success) { });
  255. }
  256. else
  257. {
  258. // Deliver locally, directly
  259. if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: Passing to ProcessMessageFromGroupSession to deliver to {0} locally", client.Name);
  260. ProcessMessageFromGroupSession(msg);
  261. }
  262. }
  263. // Temporary for assessing how long it still takes to send messages to large online groups.
  264. if (m_messageOnlineAgentsOnly)
  265. m_log.DebugFormat(
  266. "[GROUPS-MESSAGING]: SendMessageToGroup for group {0} with {1} visible members, {2} online took {3}ms",
  267. groupID, groupMembersCount, groupMembers.Count(), Environment.TickCount - requestStartTick);
  268. }
  269. #region SimGridEventHandlers
  270. void OnClientLogin(IClientAPI client)
  271. {
  272. if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: OnInstantMessage registered for {0}", client.Name);
  273. }
  274. private void OnNewClient(IClientAPI client)
  275. {
  276. if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: OnInstantMessage registered for {0}", client.Name);
  277. client.OnInstantMessage += OnInstantMessage;
  278. }
  279. private void OnGridInstantMessage(GridInstantMessage msg)
  280. {
  281. // The instant message module will only deliver messages of dialog types:
  282. // MessageFromAgent, StartTyping, StopTyping, MessageFromObject
  283. //
  284. // Any other message type will not be delivered to a client by the
  285. // Instant Message Module
  286. if (m_debugEnabled)
  287. {
  288. m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  289. DebugGridInstantMessage(msg);
  290. }
  291. // Incoming message from a group
  292. if ((msg.fromGroup == true) &&
  293. ((msg.dialog == (byte)InstantMessageDialog.SessionSend)
  294. || (msg.dialog == (byte)InstantMessageDialog.SessionAdd)
  295. || (msg.dialog == (byte)InstantMessageDialog.SessionDrop)))
  296. {
  297. ProcessMessageFromGroupSession(msg);
  298. }
  299. }
  300. private void ProcessMessageFromGroupSession(GridInstantMessage msg)
  301. {
  302. if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: Session message from {0} going to agent {1}", msg.fromAgentName, msg.toAgentID);
  303. UUID AgentID = new UUID(msg.fromAgentID);
  304. UUID GroupID = new UUID(msg.imSessionID);
  305. switch (msg.dialog)
  306. {
  307. case (byte)InstantMessageDialog.SessionAdd:
  308. m_groupData.AgentInvitedToGroupChatSession(AgentID, GroupID);
  309. break;
  310. case (byte)InstantMessageDialog.SessionDrop:
  311. m_groupData.AgentDroppedFromGroupChatSession(AgentID, GroupID);
  312. break;
  313. case (byte)InstantMessageDialog.SessionSend:
  314. if (!m_groupData.hasAgentDroppedGroupChatSession(AgentID, GroupID)
  315. && !m_groupData.hasAgentBeenInvitedToGroupChatSession(AgentID, GroupID)
  316. )
  317. {
  318. // Agent not in session and hasn't dropped from session
  319. // Add them to the session for now, and Invite them
  320. m_groupData.AgentInvitedToGroupChatSession(AgentID, GroupID);
  321. UUID toAgentID = new UUID(msg.toAgentID);
  322. IClientAPI activeClient = GetActiveClient(toAgentID);
  323. if (activeClient != null)
  324. {
  325. GroupRecord groupInfo = m_groupData.GetGroupRecord(UUID.Zero, GroupID, null);
  326. if (groupInfo != null)
  327. {
  328. if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: Sending chatterbox invite instant message");
  329. // Force? open the group session dialog???
  330. // and simultanously deliver the message, so we don't need to do a seperate client.SendInstantMessage(msg);
  331. IEventQueue eq = activeClient.Scene.RequestModuleInterface<IEventQueue>();
  332. eq.ChatterboxInvitation(
  333. GroupID
  334. , groupInfo.GroupName
  335. , new UUID(msg.fromAgentID)
  336. , msg.message
  337. , new UUID(msg.toAgentID)
  338. , msg.fromAgentName
  339. , msg.dialog
  340. , msg.timestamp
  341. , msg.offline == 1
  342. , (int)msg.ParentEstateID
  343. , msg.Position
  344. , 1
  345. , new UUID(msg.imSessionID)
  346. , msg.fromGroup
  347. , Utils.StringToBytes(groupInfo.GroupName)
  348. );
  349. eq.ChatterBoxSessionAgentListUpdates(
  350. new UUID(GroupID)
  351. , new UUID(msg.fromAgentID)
  352. , new UUID(msg.toAgentID)
  353. , false //canVoiceChat
  354. , false //isModerator
  355. , false //text mute
  356. );
  357. }
  358. }
  359. }
  360. else if (!m_groupData.hasAgentDroppedGroupChatSession(AgentID, GroupID))
  361. {
  362. // User hasn't dropped, so they're in the session,
  363. // maybe we should deliver it.
  364. IClientAPI client = GetActiveClient(new UUID(msg.toAgentID));
  365. if (client != null)
  366. {
  367. // Deliver locally, directly
  368. if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: Delivering to {0} locally", client.Name);
  369. client.SendInstantMessage(msg);
  370. }
  371. else
  372. {
  373. m_log.WarnFormat("[GROUPS-MESSAGING]: Received a message over the grid for a client that isn't here: {0}", msg.toAgentID);
  374. }
  375. }
  376. break;
  377. default:
  378. m_log.WarnFormat("[GROUPS-MESSAGING]: I don't know how to proccess a {0} message.", ((InstantMessageDialog)msg.dialog).ToString());
  379. break;
  380. }
  381. }
  382. #endregion
  383. #region ClientEvents
  384. private void OnInstantMessage(IClientAPI remoteClient, GridInstantMessage im)
  385. {
  386. if (m_debugEnabled)
  387. {
  388. m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  389. DebugGridInstantMessage(im);
  390. }
  391. // Start group IM session
  392. if ((im.dialog == (byte)InstantMessageDialog.SessionGroupStart))
  393. {
  394. if (m_debugEnabled) m_log.InfoFormat("[GROUPS-MESSAGING]: imSessionID({0}) toAgentID({1})", im.imSessionID, im.toAgentID);
  395. UUID GroupID = new UUID(im.imSessionID);
  396. UUID AgentID = new UUID(im.fromAgentID);
  397. GroupRecord groupInfo = m_groupData.GetGroupRecord(UUID.Zero, GroupID, null);
  398. if (groupInfo != null)
  399. {
  400. m_groupData.AgentInvitedToGroupChatSession(AgentID, GroupID);
  401. ChatterBoxSessionStartReplyViaCaps(remoteClient, groupInfo.GroupName, GroupID);
  402. IEventQueue queue = remoteClient.Scene.RequestModuleInterface<IEventQueue>();
  403. queue.ChatterBoxSessionAgentListUpdates(
  404. GroupID
  405. , AgentID
  406. , new UUID(im.toAgentID)
  407. , false //canVoiceChat
  408. , false //isModerator
  409. , false //text mute
  410. );
  411. }
  412. }
  413. // Send a message from locally connected client to a group
  414. if ((im.dialog == (byte)InstantMessageDialog.SessionSend))
  415. {
  416. UUID GroupID = new UUID(im.imSessionID);
  417. UUID AgentID = new UUID(im.fromAgentID);
  418. if (m_debugEnabled)
  419. m_log.DebugFormat("[GROUPS-MESSAGING]: Send message to session for group {0} with session ID {1}", GroupID, im.imSessionID.ToString());
  420. //If this agent is sending a message, then they want to be in the session
  421. m_groupData.AgentInvitedToGroupChatSession(AgentID, GroupID);
  422. SendMessageToGroup(im, GroupID);
  423. }
  424. }
  425. #endregion
  426. void ChatterBoxSessionStartReplyViaCaps(IClientAPI remoteClient, string groupName, UUID groupID)
  427. {
  428. if (m_debugEnabled) m_log.DebugFormat("[GROUPS-MESSAGING]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  429. OSDMap moderatedMap = new OSDMap(4);
  430. moderatedMap.Add("voice", OSD.FromBoolean(false));
  431. OSDMap sessionMap = new OSDMap(4);
  432. sessionMap.Add("moderated_mode", moderatedMap);
  433. sessionMap.Add("session_name", OSD.FromString(groupName));
  434. sessionMap.Add("type", OSD.FromInteger(0));
  435. sessionMap.Add("voice_enabled", OSD.FromBoolean(false));
  436. OSDMap bodyMap = new OSDMap(4);
  437. bodyMap.Add("session_id", OSD.FromUUID(groupID));
  438. bodyMap.Add("temp_session_id", OSD.FromUUID(groupID));
  439. bodyMap.Add("success", OSD.FromBoolean(true));
  440. bodyMap.Add("session_info", sessionMap);
  441. IEventQueue queue = remoteClient.Scene.RequestModuleInterface<IEventQueue>();
  442. if (queue != null)
  443. {
  444. queue.Enqueue(queue.BuildEvent("ChatterBoxSessionStartReply", bodyMap), remoteClient.AgentId);
  445. }
  446. }
  447. private void DebugGridInstantMessage(GridInstantMessage im)
  448. {
  449. // Don't log any normal IMs (privacy!)
  450. if (m_debugEnabled && im.dialog != (byte)InstantMessageDialog.MessageFromAgent)
  451. {
  452. m_log.WarnFormat("[GROUPS-MESSAGING]: IM: fromGroup({0})", im.fromGroup ? "True" : "False");
  453. m_log.WarnFormat("[GROUPS-MESSAGING]: IM: Dialog({0})", ((InstantMessageDialog)im.dialog).ToString());
  454. m_log.WarnFormat("[GROUPS-MESSAGING]: IM: fromAgentID({0})", im.fromAgentID.ToString());
  455. m_log.WarnFormat("[GROUPS-MESSAGING]: IM: fromAgentName({0})", im.fromAgentName.ToString());
  456. m_log.WarnFormat("[GROUPS-MESSAGING]: IM: imSessionID({0})", im.imSessionID.ToString());
  457. m_log.WarnFormat("[GROUPS-MESSAGING]: IM: message({0})", im.message.ToString());
  458. m_log.WarnFormat("[GROUPS-MESSAGING]: IM: offline({0})", im.offline.ToString());
  459. m_log.WarnFormat("[GROUPS-MESSAGING]: IM: toAgentID({0})", im.toAgentID.ToString());
  460. m_log.WarnFormat("[GROUPS-MESSAGING]: IM: binaryBucket({0})", OpenMetaverse.Utils.BytesToHexString(im.binaryBucket, "BinaryBucket"));
  461. }
  462. }
  463. #region Client Tools
  464. /// <summary>
  465. /// Try to find an active IClientAPI reference for agentID giving preference to root connections
  466. /// </summary>
  467. private IClientAPI GetActiveClient(UUID agentID)
  468. {
  469. if (m_debugEnabled) m_log.WarnFormat("[GROUPS-MESSAGING]: Looking for local client {0}", agentID);
  470. IClientAPI child = null;
  471. // Try root avatar first
  472. foreach (Scene scene in m_sceneList)
  473. {
  474. ScenePresence sp = scene.GetScenePresence(agentID);
  475. if (sp != null)
  476. {
  477. if (!sp.IsChildAgent)
  478. {
  479. if (m_debugEnabled) m_log.WarnFormat("[GROUPS-MESSAGING]: Found root agent for client : {0}", sp.ControllingClient.Name);
  480. return sp.ControllingClient;
  481. }
  482. else
  483. {
  484. if (m_debugEnabled) m_log.WarnFormat("[GROUPS-MESSAGING]: Found child agent for client : {0}", sp.ControllingClient.Name);
  485. child = sp.ControllingClient;
  486. }
  487. }
  488. }
  489. // If we didn't find a root, then just return whichever child we found, or null if none
  490. if (child == null)
  491. {
  492. if (m_debugEnabled) m_log.WarnFormat("[GROUPS-MESSAGING]: Could not find local client for agent : {0}", agentID);
  493. }
  494. else
  495. {
  496. if (m_debugEnabled) m_log.WarnFormat("[GROUPS-MESSAGING]: Returning child agent for client : {0}", child.Name);
  497. }
  498. return child;
  499. }
  500. #endregion
  501. }
  502. }