1
0

GroupsMessagingModule.cs 26 KB

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