GroupsModule.cs 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345
  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.Reflection;
  30. using System.Timers;
  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.Framework.Communications;
  38. using OpenSim.Region.Framework.Interfaces;
  39. using OpenSim.Region.Framework.Scenes;
  40. using OpenSim.Services.Interfaces;
  41. using DirFindFlags = OpenMetaverse.DirectoryManager.DirFindFlags;
  42. namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
  43. {
  44. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
  45. public class GroupsModule : ISharedRegionModule, IGroupsModule
  46. {
  47. /// <summary>
  48. /// ; To use this module, you must specify the following in your OpenSim.ini
  49. /// [GROUPS]
  50. /// Enabled = true
  51. ///
  52. /// Module = GroupsModule
  53. /// NoticesEnabled = true
  54. /// DebugEnabled = true
  55. ///
  56. /// GroupsServicesConnectorModule = XmlRpcGroupsServicesConnector
  57. /// XmlRpcServiceURL = http://osflotsam.org/xmlrpc.php
  58. /// XmlRpcServiceReadKey = 1234
  59. /// XmlRpcServiceWriteKey = 1234
  60. ///
  61. /// MessagingModule = GroupsMessagingModule
  62. /// MessagingEnabled = true
  63. ///
  64. /// ; Disables HTTP Keep-Alive for Groups Module HTTP Requests, work around for
  65. /// ; a problem discovered on some Windows based region servers. Only disable
  66. /// ; if you see a large number (dozens) of the following Exceptions:
  67. /// ; System.Net.WebException: The request was aborted: The request was canceled.
  68. ///
  69. /// XmlRpcDisableKeepAlive = false
  70. /// </summary>
  71. private static readonly ILog m_log =
  72. LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  73. private List<Scene> m_sceneList = new List<Scene>();
  74. private IMessageTransferModule m_msgTransferModule = null;
  75. private IGroupsServicesConnector m_groupData = null;
  76. // Configuration settings
  77. private bool m_groupsEnabled = false;
  78. private bool m_groupNoticesEnabled = true;
  79. private bool m_debugEnabled = true;
  80. #region IRegionModuleBase Members
  81. public void Initialise(IConfigSource config)
  82. {
  83. IConfig groupsConfig = config.Configs["Groups"];
  84. if (groupsConfig == null)
  85. {
  86. // Do not run this module by default.
  87. return;
  88. }
  89. else
  90. {
  91. m_groupsEnabled = groupsConfig.GetBoolean("Enabled", false);
  92. if (!m_groupsEnabled)
  93. {
  94. return;
  95. }
  96. if (groupsConfig.GetString("Module", "Default") != Name)
  97. {
  98. m_groupsEnabled = false;
  99. return;
  100. }
  101. m_log.InfoFormat("[GROUPS]: Initializing {0}", this.Name);
  102. m_groupNoticesEnabled = groupsConfig.GetBoolean("NoticesEnabled", true);
  103. m_debugEnabled = groupsConfig.GetBoolean("DebugEnabled", false);
  104. }
  105. }
  106. public void AddRegion(Scene scene)
  107. {
  108. if (m_groupsEnabled)
  109. scene.RegisterModuleInterface<IGroupsModule>(this);
  110. }
  111. public void RegionLoaded(Scene scene)
  112. {
  113. if (!m_groupsEnabled)
  114. return;
  115. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  116. if (m_groupData == null)
  117. {
  118. m_groupData = scene.RequestModuleInterface<IGroupsServicesConnector>();
  119. // No Groups Service Connector, then nothing works...
  120. if (m_groupData == null)
  121. {
  122. m_groupsEnabled = false;
  123. m_log.Error("[GROUPS]: Could not get IGroupsServicesConnector");
  124. Close();
  125. return;
  126. }
  127. }
  128. if (m_msgTransferModule == null)
  129. {
  130. m_msgTransferModule = scene.RequestModuleInterface<IMessageTransferModule>();
  131. // No message transfer module, no notices, group invites, rejects, ejects, etc
  132. if (m_msgTransferModule == null)
  133. {
  134. m_groupsEnabled = false;
  135. m_log.Warn("[GROUPS]: Could not get MessageTransferModule");
  136. }
  137. }
  138. lock (m_sceneList)
  139. {
  140. m_sceneList.Add(scene);
  141. }
  142. scene.EventManager.OnNewClient += OnNewClient;
  143. scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage;
  144. // The InstantMessageModule itself doesn't do this,
  145. // so lets see if things explode if we don't do it
  146. // scene.EventManager.OnClientClosed += OnClientClosed;
  147. }
  148. public void RemoveRegion(Scene scene)
  149. {
  150. if (!m_groupsEnabled)
  151. return;
  152. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  153. lock (m_sceneList)
  154. {
  155. m_sceneList.Remove(scene);
  156. }
  157. }
  158. public void Close()
  159. {
  160. if (!m_groupsEnabled)
  161. return;
  162. if (m_debugEnabled) m_log.Debug("[GROUPS]: Shutting down Groups module.");
  163. }
  164. public Type ReplaceableInterface
  165. {
  166. get { return null; }
  167. }
  168. public string Name
  169. {
  170. get { return "GroupsModule"; }
  171. }
  172. #endregion
  173. #region ISharedRegionModule Members
  174. public void PostInitialise()
  175. {
  176. // NoOp
  177. }
  178. #endregion
  179. #region EventHandlers
  180. private void OnNewClient(IClientAPI client)
  181. {
  182. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  183. client.OnUUIDGroupNameRequest += HandleUUIDGroupNameRequest;
  184. client.OnAgentDataUpdateRequest += OnAgentDataUpdateRequest;
  185. client.OnDirFindQuery += OnDirFindQuery;
  186. client.OnRequestAvatarProperties += OnRequestAvatarProperties;
  187. // Used for Notices and Group Invites/Accept/Reject
  188. client.OnInstantMessage += OnInstantMessage;
  189. // Send client thier groups information.
  190. SendAgentGroupDataUpdate(client, client.AgentId);
  191. }
  192. private void OnRequestAvatarProperties(IClientAPI remoteClient, UUID avatarID)
  193. {
  194. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  195. //GroupMembershipData[] avatarGroups = m_groupData.GetAgentGroupMemberships(GetRequestingAgentID(remoteClient), avatarID).ToArray();
  196. GroupMembershipData[] avatarGroups = GetProfileListedGroupMemberships(remoteClient, avatarID);
  197. remoteClient.SendAvatarGroupsReply(avatarID, avatarGroups);
  198. }
  199. /*
  200. * This becomes very problematic in a shared module. In a shared module you may have more then one
  201. * reference to IClientAPI's, one for 0 or 1 root connections, and 0 or more child connections.
  202. * The OnClientClosed event does not provide anything to indicate which one of those should be closed
  203. * nor does it provide what scene it was from so that the specific reference can be looked up.
  204. * The InstantMessageModule.cs does not currently worry about unregistering the handles,
  205. * and it should be an issue, since it's the client that references us not the other way around
  206. * , so as long as we don't keep a reference to the client laying around, the client can still be GC'ed
  207. private void OnClientClosed(UUID AgentId)
  208. {
  209. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  210. lock (m_ActiveClients)
  211. {
  212. if (m_ActiveClients.ContainsKey(AgentId))
  213. {
  214. IClientAPI client = m_ActiveClients[AgentId];
  215. client.OnUUIDGroupNameRequest -= HandleUUIDGroupNameRequest;
  216. client.OnAgentDataUpdateRequest -= OnAgentDataUpdateRequest;
  217. client.OnDirFindQuery -= OnDirFindQuery;
  218. client.OnInstantMessage -= OnInstantMessage;
  219. m_ActiveClients.Remove(AgentId);
  220. }
  221. else
  222. {
  223. if (m_debugEnabled) m_log.WarnFormat("[GROUPS]: Client closed that wasn't registered here.");
  224. }
  225. }
  226. }
  227. */
  228. void OnDirFindQuery(IClientAPI remoteClient, UUID queryID, string queryText, uint queryFlags, int queryStart)
  229. {
  230. if (((DirFindFlags)queryFlags & DirFindFlags.Groups) == DirFindFlags.Groups)
  231. {
  232. if (m_debugEnabled)
  233. m_log.DebugFormat(
  234. "[GROUPS]: {0} called with queryText({1}) queryFlags({2}) queryStart({3})",
  235. System.Reflection.MethodBase.GetCurrentMethod().Name, queryText, (DirFindFlags)queryFlags, queryStart);
  236. // TODO: This currently ignores pretty much all the query flags including Mature and sort order
  237. remoteClient.SendDirGroupsReply(queryID, m_groupData.FindGroups(GetRequestingAgentID(remoteClient), queryText).ToArray());
  238. }
  239. }
  240. private void OnAgentDataUpdateRequest(IClientAPI remoteClient, UUID dataForAgentID, UUID sessionID)
  241. {
  242. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  243. UUID activeGroupID = UUID.Zero;
  244. string activeGroupTitle = string.Empty;
  245. string activeGroupName = string.Empty;
  246. ulong activeGroupPowers = (ulong)GroupPowers.None;
  247. GroupMembershipData membership = m_groupData.GetAgentActiveMembership(GetRequestingAgentID(remoteClient), dataForAgentID);
  248. if (membership != null)
  249. {
  250. activeGroupID = membership.GroupID;
  251. activeGroupTitle = membership.GroupTitle;
  252. activeGroupPowers = membership.GroupPowers;
  253. }
  254. SendAgentDataUpdate(remoteClient, dataForAgentID, activeGroupID, activeGroupName, activeGroupPowers, activeGroupTitle);
  255. SendScenePresenceUpdate(dataForAgentID, activeGroupTitle);
  256. }
  257. private void HandleUUIDGroupNameRequest(UUID GroupID, IClientAPI remoteClient)
  258. {
  259. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  260. string GroupName;
  261. GroupRecord group = m_groupData.GetGroupRecord(GetRequestingAgentID(remoteClient), GroupID, null);
  262. if (group != null)
  263. {
  264. GroupName = group.GroupName;
  265. }
  266. else
  267. {
  268. GroupName = "Unknown";
  269. }
  270. remoteClient.SendGroupNameReply(GroupID, GroupName);
  271. }
  272. private void OnInstantMessage(IClientAPI remoteClient, GridInstantMessage im)
  273. {
  274. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  275. // Group invitations
  276. if ((im.dialog == (byte)InstantMessageDialog.GroupInvitationAccept) || (im.dialog == (byte)InstantMessageDialog.GroupInvitationDecline))
  277. {
  278. UUID inviteID = new UUID(im.imSessionID);
  279. GroupInviteInfo inviteInfo = m_groupData.GetAgentToGroupInvite(GetRequestingAgentID(remoteClient), inviteID);
  280. if (inviteInfo == null)
  281. {
  282. if (m_debugEnabled) m_log.WarnFormat("[GROUPS]: Received an Invite IM for an invite that does not exist {0}.", inviteID);
  283. return;
  284. }
  285. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: Invite is for Agent {0} to Group {1}.", inviteInfo.AgentID, inviteInfo.GroupID);
  286. UUID fromAgentID = new UUID(im.fromAgentID);
  287. if ((inviteInfo != null) && (fromAgentID == inviteInfo.AgentID))
  288. {
  289. // Accept
  290. if (im.dialog == (byte)InstantMessageDialog.GroupInvitationAccept)
  291. {
  292. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: Received an accept invite notice.");
  293. // and the sessionid is the role
  294. m_groupData.AddAgentToGroup(GetRequestingAgentID(remoteClient), inviteInfo.AgentID, inviteInfo.GroupID, inviteInfo.RoleID);
  295. GridInstantMessage msg = new GridInstantMessage();
  296. msg.imSessionID = UUID.Zero.Guid;
  297. msg.fromAgentID = UUID.Zero.Guid;
  298. msg.toAgentID = inviteInfo.AgentID.Guid;
  299. msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
  300. msg.fromAgentName = "Groups";
  301. msg.message = string.Format("You have been added to the group.");
  302. msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.MessageBox;
  303. msg.fromGroup = false;
  304. msg.offline = (byte)0;
  305. msg.ParentEstateID = 0;
  306. msg.Position = Vector3.Zero;
  307. msg.RegionID = UUID.Zero.Guid;
  308. msg.binaryBucket = new byte[0];
  309. OutgoingInstantMessage(msg, inviteInfo.AgentID);
  310. UpdateAllClientsWithGroupInfo(inviteInfo.AgentID);
  311. // TODO: If the inviter is still online, they need an agent dataupdate
  312. // and maybe group membership updates for the invitee
  313. m_groupData.RemoveAgentToGroupInvite(GetRequestingAgentID(remoteClient), inviteID);
  314. }
  315. // Reject
  316. if (im.dialog == (byte)InstantMessageDialog.GroupInvitationDecline)
  317. {
  318. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: Received a reject invite notice.");
  319. m_groupData.RemoveAgentToGroupInvite(GetRequestingAgentID(remoteClient), inviteID);
  320. }
  321. }
  322. }
  323. // Group notices
  324. if ((im.dialog == (byte)InstantMessageDialog.GroupNotice))
  325. {
  326. if (!m_groupNoticesEnabled)
  327. {
  328. return;
  329. }
  330. UUID GroupID = new UUID(im.toAgentID);
  331. if (m_groupData.GetGroupRecord(GetRequestingAgentID(remoteClient), GroupID, null) != null)
  332. {
  333. UUID NoticeID = UUID.Random();
  334. string Subject = im.message.Substring(0, im.message.IndexOf('|'));
  335. string Message = im.message.Substring(Subject.Length + 1);
  336. byte[] bucket;
  337. if ((im.binaryBucket.Length == 1) && (im.binaryBucket[0] == 0))
  338. {
  339. bucket = new byte[19];
  340. bucket[0] = 0; //dunno
  341. bucket[1] = 0; //dunno
  342. GroupID.ToBytes(bucket, 2);
  343. bucket[18] = 0; //dunno
  344. }
  345. else
  346. {
  347. string binBucket = OpenMetaverse.Utils.BytesToString(im.binaryBucket);
  348. binBucket = binBucket.Remove(0, 14).Trim();
  349. if (m_debugEnabled)
  350. {
  351. m_log.WarnFormat("I don't understand a group notice binary bucket of: {0}", binBucket);
  352. OSDMap binBucketOSD = (OSDMap)OSDParser.DeserializeLLSDXml(binBucket);
  353. foreach (string key in binBucketOSD.Keys)
  354. {
  355. if (binBucketOSD.ContainsKey(key))
  356. {
  357. m_log.WarnFormat("{0}: {1}", key, binBucketOSD[key].ToString());
  358. }
  359. }
  360. }
  361. // treat as if no attachment
  362. bucket = new byte[19];
  363. bucket[0] = 0; //dunno
  364. bucket[1] = 0; //dunno
  365. GroupID.ToBytes(bucket, 2);
  366. bucket[18] = 0; //dunno
  367. }
  368. m_groupData.AddGroupNotice(GetRequestingAgentID(remoteClient), GroupID, NoticeID, im.fromAgentName, Subject, Message, bucket);
  369. if (OnNewGroupNotice != null)
  370. {
  371. OnNewGroupNotice(GroupID, NoticeID);
  372. }
  373. // Send notice out to everyone that wants notices
  374. foreach (GroupMembersData member in m_groupData.GetGroupMembers(GetRequestingAgentID(remoteClient), GroupID))
  375. {
  376. if (m_debugEnabled)
  377. {
  378. UserAccount targetUser = m_sceneList[0].UserAccountService.GetUserAccount(remoteClient.Scene.RegionInfo.ScopeID, member.AgentID);
  379. if (targetUser != null)
  380. {
  381. m_log.DebugFormat("[GROUPS]: Prepping group notice {0} for agent: {1} who Accepts Notices ({2})", NoticeID, targetUser.FirstName + " " + targetUser.LastName, member.AcceptNotices);
  382. }
  383. else
  384. {
  385. m_log.DebugFormat("[GROUPS]: Prepping group notice {0} for agent: {1} who Accepts Notices ({2})", NoticeID, member.AgentID, member.AcceptNotices);
  386. }
  387. }
  388. if (member.AcceptNotices)
  389. {
  390. // Build notice IIM
  391. GridInstantMessage msg = CreateGroupNoticeIM(UUID.Zero, NoticeID, (byte)OpenMetaverse.InstantMessageDialog.GroupNotice);
  392. msg.toAgentID = member.AgentID.Guid;
  393. OutgoingInstantMessage(msg, member.AgentID);
  394. }
  395. }
  396. }
  397. }
  398. // Interop, received special 210 code for ejecting a group member
  399. // this only works within the comms servers domain, and won't work hypergrid
  400. // TODO:FIXME: Use a presense server of some kind to find out where the
  401. // client actually is, and try contacting that region directly to notify them,
  402. // or provide the notification via xmlrpc update queue
  403. if ((im.dialog == 210))
  404. {
  405. // This is sent from the region that the ejectee was ejected from
  406. // if it's being delivered here, then the ejectee is here
  407. // so we need to send local updates to the agent.
  408. UUID ejecteeID = new UUID(im.toAgentID);
  409. im.dialog = (byte)InstantMessageDialog.MessageFromAgent;
  410. OutgoingInstantMessage(im, ejecteeID);
  411. IClientAPI ejectee = GetActiveClient(ejecteeID);
  412. if (ejectee != null)
  413. {
  414. UUID groupID = new UUID(im.imSessionID);
  415. ejectee.SendAgentDropGroup(groupID);
  416. }
  417. }
  418. }
  419. private void OnGridInstantMessage(GridInstantMessage msg)
  420. {
  421. if (m_debugEnabled) m_log.InfoFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  422. // Trigger the above event handler
  423. OnInstantMessage(null, msg);
  424. // If a message from a group arrives here, it may need to be forwarded to a local client
  425. if (msg.fromGroup == true)
  426. {
  427. switch (msg.dialog)
  428. {
  429. case (byte)InstantMessageDialog.GroupInvitation:
  430. case (byte)InstantMessageDialog.GroupNotice:
  431. UUID toAgentID = new UUID(msg.toAgentID);
  432. IClientAPI localClient = GetActiveClient(toAgentID);
  433. if (localClient != null)
  434. {
  435. localClient.SendInstantMessage(msg);
  436. }
  437. break;
  438. }
  439. }
  440. }
  441. #endregion
  442. #region IGroupsModule Members
  443. public event NewGroupNotice OnNewGroupNotice;
  444. public GroupRecord GetGroupRecord(UUID GroupID)
  445. {
  446. return m_groupData.GetGroupRecord(UUID.Zero, GroupID, null);
  447. }
  448. public GroupRecord GetGroupRecord(string name)
  449. {
  450. return m_groupData.GetGroupRecord(UUID.Zero, UUID.Zero, name);
  451. }
  452. public void ActivateGroup(IClientAPI remoteClient, UUID groupID)
  453. {
  454. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  455. m_groupData.SetAgentActiveGroup(GetRequestingAgentID(remoteClient), GetRequestingAgentID(remoteClient), groupID);
  456. // Changing active group changes title, active powers, all kinds of things
  457. // anyone who is in any region that can see this client, should probably be
  458. // updated with new group info. At a minimum, they should get ScenePresence
  459. // updated with new title.
  460. UpdateAllClientsWithGroupInfo(GetRequestingAgentID(remoteClient));
  461. }
  462. /// <summary>
  463. /// Get the Role Titles for an Agent, for a specific group
  464. /// </summary>
  465. public List<GroupTitlesData> GroupTitlesRequest(IClientAPI remoteClient, UUID groupID)
  466. {
  467. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  468. List<GroupRolesData> agentRoles = m_groupData.GetAgentGroupRoles(GetRequestingAgentID(remoteClient), GetRequestingAgentID(remoteClient), groupID);
  469. GroupMembershipData agentMembership = m_groupData.GetAgentGroupMembership(GetRequestingAgentID(remoteClient), GetRequestingAgentID(remoteClient), groupID);
  470. List<GroupTitlesData> titles = new List<GroupTitlesData>();
  471. foreach (GroupRolesData role in agentRoles)
  472. {
  473. GroupTitlesData title = new GroupTitlesData();
  474. title.Name = role.Name;
  475. if (agentMembership != null)
  476. {
  477. title.Selected = agentMembership.ActiveRole == role.RoleID;
  478. }
  479. title.UUID = role.RoleID;
  480. titles.Add(title);
  481. }
  482. return titles;
  483. }
  484. public List<GroupMembersData> GroupMembersRequest(IClientAPI remoteClient, UUID groupID)
  485. {
  486. if (m_debugEnabled)
  487. m_log.DebugFormat(
  488. "[GROUPS]: GroupMembersRequest called for {0} from client {1}", groupID, remoteClient.Name);
  489. List<GroupMembersData> data = m_groupData.GetGroupMembers(GetRequestingAgentID(remoteClient), groupID);
  490. if (m_debugEnabled)
  491. {
  492. foreach (GroupMembersData member in data)
  493. {
  494. m_log.DebugFormat("[GROUPS]: Member({0}) - IsOwner({1})", member.AgentID, member.IsOwner);
  495. }
  496. }
  497. return data;
  498. }
  499. public List<GroupRolesData> GroupRoleDataRequest(IClientAPI remoteClient, UUID groupID)
  500. {
  501. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  502. List<GroupRolesData> data = m_groupData.GetGroupRoles(GetRequestingAgentID(remoteClient), groupID);
  503. return data;
  504. }
  505. public List<GroupRoleMembersData> GroupRoleMembersRequest(IClientAPI remoteClient, UUID groupID)
  506. {
  507. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  508. List<GroupRoleMembersData> data = m_groupData.GetGroupRoleMembers(GetRequestingAgentID(remoteClient), groupID);
  509. if (m_debugEnabled)
  510. {
  511. foreach (GroupRoleMembersData member in data)
  512. {
  513. m_log.DebugFormat("[GROUPS]: Member({0}) - Role({1})", member.MemberID, member.RoleID);
  514. }
  515. }
  516. return data;
  517. }
  518. public GroupProfileData GroupProfileRequest(IClientAPI remoteClient, UUID groupID)
  519. {
  520. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  521. GroupProfileData profile = new GroupProfileData();
  522. GroupRecord groupInfo = m_groupData.GetGroupRecord(GetRequestingAgentID(remoteClient), groupID, null);
  523. if (groupInfo != null)
  524. {
  525. profile.AllowPublish = groupInfo.AllowPublish;
  526. profile.Charter = groupInfo.Charter;
  527. profile.FounderID = groupInfo.FounderID;
  528. profile.GroupID = groupID;
  529. profile.GroupMembershipCount = m_groupData.GetGroupMembers(GetRequestingAgentID(remoteClient), groupID).Count;
  530. profile.GroupRolesCount = m_groupData.GetGroupRoles(GetRequestingAgentID(remoteClient), groupID).Count;
  531. profile.InsigniaID = groupInfo.GroupPicture;
  532. profile.MaturePublish = groupInfo.MaturePublish;
  533. profile.MembershipFee = groupInfo.MembershipFee;
  534. profile.Money = 0; // TODO: Get this from the currency server?
  535. profile.Name = groupInfo.GroupName;
  536. profile.OpenEnrollment = groupInfo.OpenEnrollment;
  537. profile.OwnerRole = groupInfo.OwnerRoleID;
  538. profile.ShowInList = groupInfo.ShowInList;
  539. }
  540. GroupMembershipData memberInfo = m_groupData.GetAgentGroupMembership(GetRequestingAgentID(remoteClient), GetRequestingAgentID(remoteClient), groupID);
  541. if (memberInfo != null)
  542. {
  543. profile.MemberTitle = memberInfo.GroupTitle;
  544. profile.PowersMask = memberInfo.GroupPowers;
  545. }
  546. return profile;
  547. }
  548. public GroupMembershipData[] GetMembershipData(UUID agentID)
  549. {
  550. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  551. return m_groupData.GetAgentGroupMemberships(UUID.Zero, agentID).ToArray();
  552. }
  553. public GroupMembershipData GetMembershipData(UUID groupID, UUID agentID)
  554. {
  555. if (m_debugEnabled)
  556. m_log.DebugFormat(
  557. "[GROUPS]: {0} called with groupID={1}, agentID={2}",
  558. System.Reflection.MethodBase.GetCurrentMethod().Name, groupID, agentID);
  559. return m_groupData.GetAgentGroupMembership(UUID.Zero, agentID, groupID);
  560. }
  561. public void UpdateGroupInfo(IClientAPI remoteClient, UUID groupID, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish)
  562. {
  563. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  564. // Note: Permissions checking for modification rights is handled by the Groups Server/Service
  565. m_groupData.UpdateGroup(GetRequestingAgentID(remoteClient), groupID, charter, showInList, insigniaID, membershipFee, openEnrollment, allowPublish, maturePublish);
  566. }
  567. public void SetGroupAcceptNotices(IClientAPI remoteClient, UUID groupID, bool acceptNotices, bool listInProfile)
  568. {
  569. // Note: Permissions checking for modification rights is handled by the Groups Server/Service
  570. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  571. m_groupData.SetAgentGroupInfo(GetRequestingAgentID(remoteClient), GetRequestingAgentID(remoteClient), groupID, acceptNotices, listInProfile);
  572. }
  573. public UUID CreateGroup(IClientAPI remoteClient, string name, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish)
  574. {
  575. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  576. if (m_groupData.GetGroupRecord(GetRequestingAgentID(remoteClient), UUID.Zero, name) != null)
  577. {
  578. remoteClient.SendCreateGroupReply(UUID.Zero, false, "A group with the same name already exists.");
  579. return UUID.Zero;
  580. }
  581. // is there is a money module present ?
  582. IMoneyModule money = remoteClient.Scene.RequestModuleInterface<IMoneyModule>();
  583. if (money != null)
  584. {
  585. // do the transaction, that is if the agent has got sufficient funds
  586. if (!money.AmountCovered(remoteClient, money.GroupCreationCharge)) {
  587. remoteClient.SendCreateGroupReply(UUID.Zero, false, "You have got issuficient funds to create a group.");
  588. return UUID.Zero;
  589. }
  590. money.ApplyCharge(GetRequestingAgentID(remoteClient), money.GroupCreationCharge, "Group Creation");
  591. }
  592. UUID groupID = m_groupData.CreateGroup(GetRequestingAgentID(remoteClient), name, charter, showInList, insigniaID, membershipFee, openEnrollment, allowPublish, maturePublish, GetRequestingAgentID(remoteClient));
  593. remoteClient.SendCreateGroupReply(groupID, true, "Group created successfullly");
  594. // Update the founder with new group information.
  595. SendAgentGroupDataUpdate(remoteClient, GetRequestingAgentID(remoteClient));
  596. return groupID;
  597. }
  598. public GroupNoticeData[] GroupNoticesListRequest(IClientAPI remoteClient, UUID groupID)
  599. {
  600. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  601. // ToDo: check if agent is a member of group and is allowed to see notices?
  602. return m_groupData.GetGroupNotices(GetRequestingAgentID(remoteClient), groupID).ToArray();
  603. }
  604. /// <summary>
  605. /// Get the title of the agent's current role.
  606. /// </summary>
  607. public string GetGroupTitle(UUID avatarID)
  608. {
  609. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  610. GroupMembershipData membership = m_groupData.GetAgentActiveMembership(UUID.Zero, avatarID);
  611. if (membership != null)
  612. {
  613. return membership.GroupTitle;
  614. }
  615. return string.Empty;
  616. }
  617. /// <summary>
  618. /// Change the current Active Group Role for Agent
  619. /// </summary>
  620. public void GroupTitleUpdate(IClientAPI remoteClient, UUID groupID, UUID titleRoleID)
  621. {
  622. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  623. m_groupData.SetAgentActiveGroupRole(GetRequestingAgentID(remoteClient), GetRequestingAgentID(remoteClient), groupID, titleRoleID);
  624. // TODO: Not sure what all is needed here, but if the active group role change is for the group
  625. // the client currently has set active, then we need to do a scene presence update too
  626. // if (m_groupData.GetAgentActiveMembership(GetRequestingAgentID(remoteClient)).GroupID == GroupID)
  627. UpdateAllClientsWithGroupInfo(GetRequestingAgentID(remoteClient));
  628. }
  629. public void GroupRoleUpdate(IClientAPI remoteClient, UUID groupID, UUID roleID, string name, string description, string title, ulong powers, byte updateType)
  630. {
  631. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  632. // Security Checks are handled in the Groups Service.
  633. switch ((OpenMetaverse.GroupRoleUpdate)updateType)
  634. {
  635. case OpenMetaverse.GroupRoleUpdate.Create:
  636. m_groupData.AddGroupRole(GetRequestingAgentID(remoteClient), groupID, UUID.Random(), name, description, title, powers);
  637. break;
  638. case OpenMetaverse.GroupRoleUpdate.Delete:
  639. m_groupData.RemoveGroupRole(GetRequestingAgentID(remoteClient), groupID, roleID);
  640. break;
  641. case OpenMetaverse.GroupRoleUpdate.UpdateAll:
  642. case OpenMetaverse.GroupRoleUpdate.UpdateData:
  643. case OpenMetaverse.GroupRoleUpdate.UpdatePowers:
  644. if (m_debugEnabled)
  645. {
  646. GroupPowers gp = (GroupPowers)powers;
  647. m_log.DebugFormat("[GROUPS]: Role ({0}) updated with Powers ({1}) ({2})", name, powers.ToString(), gp.ToString());
  648. }
  649. m_groupData.UpdateGroupRole(GetRequestingAgentID(remoteClient), groupID, roleID, name, description, title, powers);
  650. break;
  651. case OpenMetaverse.GroupRoleUpdate.NoUpdate:
  652. default:
  653. // No Op
  654. break;
  655. }
  656. // TODO: This update really should send out updates for everyone in the role that just got changed.
  657. SendAgentGroupDataUpdate(remoteClient, GetRequestingAgentID(remoteClient));
  658. }
  659. public void GroupRoleChanges(IClientAPI remoteClient, UUID groupID, UUID roleID, UUID memberID, uint changes)
  660. {
  661. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  662. // Todo: Security check
  663. switch (changes)
  664. {
  665. case 0:
  666. // Add
  667. m_groupData.AddAgentToGroupRole(GetRequestingAgentID(remoteClient), memberID, groupID, roleID);
  668. break;
  669. case 1:
  670. // Remove
  671. m_groupData.RemoveAgentFromGroupRole(GetRequestingAgentID(remoteClient), memberID, groupID, roleID);
  672. break;
  673. default:
  674. m_log.ErrorFormat("[GROUPS]: {0} does not understand changes == {1}", System.Reflection.MethodBase.GetCurrentMethod().Name, changes);
  675. break;
  676. }
  677. // TODO: This update really should send out updates for everyone in the role that just got changed.
  678. SendAgentGroupDataUpdate(remoteClient, GetRequestingAgentID(remoteClient));
  679. }
  680. public void GroupNoticeRequest(IClientAPI remoteClient, UUID groupNoticeID)
  681. {
  682. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  683. GroupNoticeInfo data = m_groupData.GetGroupNotice(GetRequestingAgentID(remoteClient), groupNoticeID);
  684. if (data != null)
  685. {
  686. GroupRecord groupInfo = m_groupData.GetGroupRecord(GetRequestingAgentID(remoteClient), data.GroupID, null);
  687. GridInstantMessage msg = new GridInstantMessage();
  688. msg.imSessionID = UUID.Zero.Guid;
  689. msg.fromAgentID = data.GroupID.Guid;
  690. msg.toAgentID = GetRequestingAgentID(remoteClient).Guid;
  691. msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
  692. msg.fromAgentName = "Group Notice : " + groupInfo == null ? "Unknown" : groupInfo.GroupName;
  693. msg.message = data.noticeData.Subject + "|" + data.Message;
  694. msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.GroupNoticeRequested;
  695. msg.fromGroup = true;
  696. msg.offline = (byte)0;
  697. msg.ParentEstateID = 0;
  698. msg.Position = Vector3.Zero;
  699. msg.RegionID = UUID.Zero.Guid;
  700. msg.binaryBucket = data.BinaryBucket;
  701. OutgoingInstantMessage(msg, GetRequestingAgentID(remoteClient));
  702. }
  703. }
  704. public GridInstantMessage CreateGroupNoticeIM(UUID agentID, UUID groupNoticeID, byte dialog)
  705. {
  706. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  707. GridInstantMessage msg = new GridInstantMessage();
  708. msg.imSessionID = UUID.Zero.Guid;
  709. msg.toAgentID = agentID.Guid;
  710. msg.dialog = dialog;
  711. // msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.GroupNotice;
  712. msg.fromGroup = true;
  713. msg.offline = (byte)1; // Allow this message to be stored for offline use
  714. msg.ParentEstateID = 0;
  715. msg.Position = Vector3.Zero;
  716. msg.RegionID = UUID.Zero.Guid;
  717. GroupNoticeInfo info = m_groupData.GetGroupNotice(agentID, groupNoticeID);
  718. if (info != null)
  719. {
  720. msg.fromAgentID = info.GroupID.Guid;
  721. msg.timestamp = info.noticeData.Timestamp;
  722. msg.fromAgentName = info.noticeData.FromName;
  723. msg.message = info.noticeData.Subject + "|" + info.Message;
  724. msg.binaryBucket = info.BinaryBucket;
  725. }
  726. else
  727. {
  728. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: Group Notice {0} not found, composing empty message.", groupNoticeID);
  729. msg.fromAgentID = UUID.Zero.Guid;
  730. msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); ;
  731. msg.fromAgentName = string.Empty;
  732. msg.message = string.Empty;
  733. msg.binaryBucket = new byte[0];
  734. }
  735. return msg;
  736. }
  737. public void SendAgentGroupDataUpdate(IClientAPI remoteClient)
  738. {
  739. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  740. // Send agent information about his groups
  741. SendAgentGroupDataUpdate(remoteClient, GetRequestingAgentID(remoteClient));
  742. }
  743. public void JoinGroupRequest(IClientAPI remoteClient, UUID groupID)
  744. {
  745. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  746. // Should check to see if OpenEnrollment, or if there's an outstanding invitation
  747. m_groupData.AddAgentToGroup(GetRequestingAgentID(remoteClient), GetRequestingAgentID(remoteClient), groupID, UUID.Zero);
  748. remoteClient.SendJoinGroupReply(groupID, true);
  749. // Should this send updates to everyone in the group?
  750. SendAgentGroupDataUpdate(remoteClient, GetRequestingAgentID(remoteClient));
  751. }
  752. public void LeaveGroupRequest(IClientAPI remoteClient, UUID groupID)
  753. {
  754. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  755. m_groupData.RemoveAgentFromGroup(GetRequestingAgentID(remoteClient), GetRequestingAgentID(remoteClient), groupID);
  756. remoteClient.SendLeaveGroupReply(groupID, true);
  757. remoteClient.SendAgentDropGroup(groupID);
  758. // SL sends out notifcations to the group messaging session that the person has left
  759. // Should this also update everyone who is in the group?
  760. SendAgentGroupDataUpdate(remoteClient, GetRequestingAgentID(remoteClient));
  761. }
  762. public void EjectGroupMemberRequest(IClientAPI remoteClient, UUID groupID, UUID ejecteeID)
  763. {
  764. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  765. // Todo: Security check?
  766. m_groupData.RemoveAgentFromGroup(GetRequestingAgentID(remoteClient), ejecteeID, groupID);
  767. remoteClient.SendEjectGroupMemberReply(GetRequestingAgentID(remoteClient), groupID, true);
  768. GroupRecord groupInfo = m_groupData.GetGroupRecord(GetRequestingAgentID(remoteClient), groupID, null);
  769. UserAccount account = m_sceneList[0].UserAccountService.GetUserAccount(remoteClient.Scene.RegionInfo.ScopeID, ejecteeID);
  770. if ((groupInfo == null) || (account == null))
  771. {
  772. return;
  773. }
  774. // Send Message to Ejectee
  775. GridInstantMessage msg = new GridInstantMessage();
  776. msg.imSessionID = UUID.Zero.Guid;
  777. msg.fromAgentID = GetRequestingAgentID(remoteClient).Guid;
  778. // msg.fromAgentID = info.GroupID;
  779. msg.toAgentID = ejecteeID.Guid;
  780. //msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
  781. msg.timestamp = 0;
  782. msg.fromAgentName = remoteClient.Name;
  783. msg.message = string.Format("You have been ejected from '{1}' by {0}.", remoteClient.Name, groupInfo.GroupName);
  784. msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.MessageFromAgent;
  785. msg.fromGroup = false;
  786. msg.offline = (byte)0;
  787. msg.ParentEstateID = 0;
  788. msg.Position = Vector3.Zero;
  789. msg.RegionID = remoteClient.Scene.RegionInfo.RegionID.Guid;
  790. msg.binaryBucket = new byte[0];
  791. OutgoingInstantMessage(msg, ejecteeID);
  792. // Message to ejector
  793. // Interop, received special 210 code for ejecting a group member
  794. // this only works within the comms servers domain, and won't work hypergrid
  795. // TODO:FIXME: Use a presense server of some kind to find out where the
  796. // client actually is, and try contacting that region directly to notify them,
  797. // or provide the notification via xmlrpc update queue
  798. msg = new GridInstantMessage();
  799. msg.imSessionID = UUID.Zero.Guid;
  800. msg.fromAgentID = GetRequestingAgentID(remoteClient).Guid;
  801. msg.toAgentID = GetRequestingAgentID(remoteClient).Guid;
  802. msg.timestamp = 0;
  803. msg.fromAgentName = remoteClient.Name;
  804. if (account != null)
  805. {
  806. msg.message = string.Format("{2} has been ejected from '{1}' by {0}.", remoteClient.Name, groupInfo.GroupName, account.FirstName + " " + account.LastName);
  807. }
  808. else
  809. {
  810. msg.message = string.Format("{2} has been ejected from '{1}' by {0}.", remoteClient.Name, groupInfo.GroupName, "Unknown member");
  811. }
  812. msg.dialog = (byte)210; //interop
  813. msg.fromGroup = false;
  814. msg.offline = (byte)0;
  815. msg.ParentEstateID = 0;
  816. msg.Position = Vector3.Zero;
  817. msg.RegionID = remoteClient.Scene.RegionInfo.RegionID.Guid;
  818. msg.binaryBucket = new byte[0];
  819. OutgoingInstantMessage(msg, GetRequestingAgentID(remoteClient));
  820. // SL sends out messages to everyone in the group
  821. // Who all should receive updates and what should they be updated with?
  822. UpdateAllClientsWithGroupInfo(ejecteeID);
  823. }
  824. public void InviteGroupRequest(IClientAPI remoteClient, UUID groupID, UUID invitedAgentID, UUID roleID)
  825. {
  826. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  827. // Todo: Security check, probably also want to send some kind of notification
  828. UUID InviteID = UUID.Random();
  829. m_groupData.AddAgentToGroupInvite(GetRequestingAgentID(remoteClient), InviteID, groupID, roleID, invitedAgentID);
  830. // Check to see if the invite went through, if it did not then it's possible
  831. // the remoteClient did not validate or did not have permission to invite.
  832. GroupInviteInfo inviteInfo = m_groupData.GetAgentToGroupInvite(GetRequestingAgentID(remoteClient), InviteID);
  833. if (inviteInfo != null)
  834. {
  835. if (m_msgTransferModule != null)
  836. {
  837. Guid inviteUUID = InviteID.Guid;
  838. GridInstantMessage msg = new GridInstantMessage();
  839. msg.imSessionID = inviteUUID;
  840. // msg.fromAgentID = GetRequestingAgentID(remoteClient).Guid;
  841. msg.fromAgentID = groupID.Guid;
  842. msg.toAgentID = invitedAgentID.Guid;
  843. //msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
  844. msg.timestamp = 0;
  845. msg.fromAgentName = remoteClient.Name;
  846. msg.message = string.Format("{0} has invited you to join a group. There is no cost to join this group.", remoteClient.Name);
  847. msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.GroupInvitation;
  848. msg.fromGroup = true;
  849. msg.offline = (byte)0;
  850. msg.ParentEstateID = 0;
  851. msg.Position = Vector3.Zero;
  852. msg.RegionID = remoteClient.Scene.RegionInfo.RegionID.Guid;
  853. msg.binaryBucket = new byte[20];
  854. OutgoingInstantMessage(msg, invitedAgentID);
  855. }
  856. }
  857. }
  858. #endregion
  859. #region Client/Update Tools
  860. /// <summary>
  861. /// Try to find an active IClientAPI reference for agentID giving preference to root connections
  862. /// </summary>
  863. private IClientAPI GetActiveClient(UUID agentID)
  864. {
  865. IClientAPI child = null;
  866. // Try root avatar first
  867. foreach (Scene scene in m_sceneList)
  868. {
  869. if (scene.Entities.ContainsKey(agentID) &&
  870. scene.Entities[agentID] is ScenePresence)
  871. {
  872. ScenePresence user = (ScenePresence)scene.Entities[agentID];
  873. if (!user.IsChildAgent)
  874. {
  875. return user.ControllingClient;
  876. }
  877. else
  878. {
  879. child = user.ControllingClient;
  880. }
  881. }
  882. }
  883. // If we didn't find a root, then just return whichever child we found, or null if none
  884. return child;
  885. }
  886. /// <summary>
  887. /// Send 'remoteClient' the group membership 'data' for agent 'dataForAgentID'.
  888. /// </summary>
  889. private void SendGroupMembershipInfoViaCaps(IClientAPI remoteClient, UUID dataForAgentID, GroupMembershipData[] data)
  890. {
  891. if (m_debugEnabled) m_log.InfoFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  892. OSDArray AgentData = new OSDArray(1);
  893. OSDMap AgentDataMap = new OSDMap(1);
  894. AgentDataMap.Add("AgentID", OSD.FromUUID(dataForAgentID));
  895. AgentData.Add(AgentDataMap);
  896. OSDArray GroupData = new OSDArray(data.Length);
  897. OSDArray NewGroupData = new OSDArray(data.Length);
  898. foreach (GroupMembershipData membership in data)
  899. {
  900. if (GetRequestingAgentID(remoteClient) != dataForAgentID)
  901. {
  902. if (!membership.ListInProfile)
  903. {
  904. // If we're sending group info to remoteclient about another agent,
  905. // filter out groups the other agent doesn't want to share.
  906. continue;
  907. }
  908. }
  909. OSDMap GroupDataMap = new OSDMap(6);
  910. OSDMap NewGroupDataMap = new OSDMap(1);
  911. GroupDataMap.Add("GroupID", OSD.FromUUID(membership.GroupID));
  912. GroupDataMap.Add("GroupPowers", OSD.FromULong(membership.GroupPowers));
  913. GroupDataMap.Add("AcceptNotices", OSD.FromBoolean(membership.AcceptNotices));
  914. GroupDataMap.Add("GroupInsigniaID", OSD.FromUUID(membership.GroupPicture));
  915. GroupDataMap.Add("Contribution", OSD.FromInteger(membership.Contribution));
  916. GroupDataMap.Add("GroupName", OSD.FromString(membership.GroupName));
  917. NewGroupDataMap.Add("ListInProfile", OSD.FromBoolean(membership.ListInProfile));
  918. GroupData.Add(GroupDataMap);
  919. NewGroupData.Add(NewGroupDataMap);
  920. }
  921. OSDMap llDataStruct = new OSDMap(3);
  922. llDataStruct.Add("AgentData", AgentData);
  923. llDataStruct.Add("GroupData", GroupData);
  924. llDataStruct.Add("NewGroupData", NewGroupData);
  925. if (m_debugEnabled)
  926. {
  927. m_log.InfoFormat("[GROUPS]: {0}", OSDParser.SerializeJsonString(llDataStruct));
  928. }
  929. IEventQueue queue = remoteClient.Scene.RequestModuleInterface<IEventQueue>();
  930. if (queue != null)
  931. {
  932. queue.Enqueue(queue.BuildEvent("AgentGroupDataUpdate", llDataStruct), GetRequestingAgentID(remoteClient));
  933. }
  934. }
  935. private void SendScenePresenceUpdate(UUID AgentID, string Title)
  936. {
  937. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: Updating scene title for {0} with title: {1}", AgentID, Title);
  938. ScenePresence presence = null;
  939. foreach (Scene scene in m_sceneList)
  940. {
  941. presence = scene.GetScenePresence(AgentID);
  942. if (presence != null)
  943. {
  944. if (presence.Grouptitle != Title)
  945. {
  946. presence.Grouptitle = Title;
  947. if (! presence.IsChildAgent)
  948. presence.SendAvatarDataToAllAgents();
  949. }
  950. }
  951. }
  952. }
  953. /// <summary>
  954. /// Send updates to all clients who might be interested in groups data for dataForClientID
  955. /// </summary>
  956. private void UpdateAllClientsWithGroupInfo(UUID dataForClientID)
  957. {
  958. if (m_debugEnabled) m_log.InfoFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  959. // TODO: Probably isn't nessesary to update every client in every scene.
  960. // Need to examine client updates and do only what's nessesary.
  961. lock (m_sceneList)
  962. {
  963. foreach (Scene scene in m_sceneList)
  964. {
  965. scene.ForEachClient(delegate(IClientAPI client) { SendAgentGroupDataUpdate(client, dataForClientID); });
  966. }
  967. }
  968. }
  969. /// <summary>
  970. /// Update remoteClient with group information about dataForAgentID
  971. /// </summary>
  972. private void SendAgentGroupDataUpdate(IClientAPI remoteClient, UUID dataForAgentID)
  973. {
  974. if (m_debugEnabled) m_log.InfoFormat("[GROUPS]: {0} called for {1}", System.Reflection.MethodBase.GetCurrentMethod().Name, remoteClient.Name);
  975. // TODO: All the client update functions need to be reexamined because most do too much and send too much stuff
  976. OnAgentDataUpdateRequest(remoteClient, dataForAgentID, UUID.Zero);
  977. // Need to send a group membership update to the client
  978. // UDP version doesn't seem to behave nicely. But we're going to send it out here
  979. // with an empty group membership to hopefully remove groups being displayed due
  980. // to the core Groups Stub
  981. remoteClient.SendGroupMembership(new GroupMembershipData[0]);
  982. GroupMembershipData[] membershipArray = GetProfileListedGroupMemberships(remoteClient, dataForAgentID);
  983. SendGroupMembershipInfoViaCaps(remoteClient, dataForAgentID, membershipArray);
  984. remoteClient.SendAvatarGroupsReply(dataForAgentID, membershipArray);
  985. }
  986. /// <summary>
  987. /// Get a list of groups memberships for the agent that are marked "ListInProfile"
  988. /// (unless that agent has a godLike aspect, in which case get all groups)
  989. /// </summary>
  990. /// <param name="dataForAgentID"></param>
  991. /// <returns></returns>
  992. private GroupMembershipData[] GetProfileListedGroupMemberships(IClientAPI requestingClient, UUID dataForAgentID)
  993. {
  994. List<GroupMembershipData> membershipData = m_groupData.GetAgentGroupMemberships(requestingClient.AgentId, dataForAgentID);
  995. GroupMembershipData[] membershipArray;
  996. // cScene and property accessor 'isGod' are in support of the opertions to bypass 'hidden' group attributes for
  997. // those with a GodLike aspect.
  998. Scene cScene = (Scene)requestingClient.Scene;
  999. bool isGod = cScene.Permissions.IsGod(requestingClient.AgentId);
  1000. if (isGod)
  1001. {
  1002. membershipArray = membershipData.ToArray();
  1003. }
  1004. else
  1005. {
  1006. if (requestingClient.AgentId != dataForAgentID)
  1007. {
  1008. Predicate<GroupMembershipData> showInProfile = delegate(GroupMembershipData membership)
  1009. {
  1010. return membership.ListInProfile;
  1011. };
  1012. membershipArray = membershipData.FindAll(showInProfile).ToArray();
  1013. }
  1014. else
  1015. {
  1016. membershipArray = membershipData.ToArray();
  1017. }
  1018. }
  1019. if (m_debugEnabled)
  1020. {
  1021. m_log.InfoFormat("[GROUPS]: Get group membership information for {0} requested by {1}", dataForAgentID, requestingClient.AgentId);
  1022. foreach (GroupMembershipData membership in membershipArray)
  1023. {
  1024. m_log.InfoFormat("[GROUPS]: {0} :: {1} - {2} - {3}", dataForAgentID, membership.GroupName, membership.GroupTitle, membership.GroupPowers);
  1025. }
  1026. }
  1027. return membershipArray;
  1028. }
  1029. private void SendAgentDataUpdate(IClientAPI remoteClient, UUID dataForAgentID, UUID activeGroupID, string activeGroupName, ulong activeGroupPowers, string activeGroupTitle)
  1030. {
  1031. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  1032. // TODO: All the client update functions need to be reexamined because most do too much and send too much stuff
  1033. UserAccount account = m_sceneList[0].UserAccountService.GetUserAccount(remoteClient.Scene.RegionInfo.ScopeID, dataForAgentID);
  1034. string firstname, lastname;
  1035. if (account != null)
  1036. {
  1037. firstname = account.FirstName;
  1038. lastname = account.LastName;
  1039. }
  1040. else
  1041. {
  1042. firstname = "Unknown";
  1043. lastname = "Unknown";
  1044. }
  1045. remoteClient.SendAgentDataUpdate(dataForAgentID, activeGroupID, firstname,
  1046. lastname, activeGroupPowers, activeGroupName,
  1047. activeGroupTitle);
  1048. }
  1049. #endregion
  1050. #region IM Backed Processes
  1051. private void OutgoingInstantMessage(GridInstantMessage msg, UUID msgTo)
  1052. {
  1053. if (m_debugEnabled) m_log.InfoFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  1054. IClientAPI localClient = GetActiveClient(msgTo);
  1055. if (localClient != null)
  1056. {
  1057. if (m_debugEnabled) m_log.InfoFormat("[GROUPS]: MsgTo ({0}) is local, delivering directly", localClient.Name);
  1058. localClient.SendInstantMessage(msg);
  1059. }
  1060. else if (m_msgTransferModule != null)
  1061. {
  1062. if (m_debugEnabled) m_log.InfoFormat("[GROUPS]: MsgTo ({0}) is not local, delivering via TransferModule", msgTo);
  1063. m_msgTransferModule.SendInstantMessage(msg, delegate(bool success) { if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: Message Sent: {0}", success?"Succeeded":"Failed"); });
  1064. }
  1065. }
  1066. public void NotifyChange(UUID groupID)
  1067. {
  1068. // Notify all group members of a chnge in group roles and/or
  1069. // permissions
  1070. //
  1071. }
  1072. #endregion
  1073. private UUID GetRequestingAgentID(IClientAPI client)
  1074. {
  1075. UUID requestingAgentID = UUID.Zero;
  1076. if (client != null)
  1077. {
  1078. requestingAgentID = client.AgentId;
  1079. }
  1080. return requestingAgentID;
  1081. }
  1082. }
  1083. public class GroupNoticeInfo
  1084. {
  1085. public GroupNoticeData noticeData = new GroupNoticeData();
  1086. public UUID GroupID = UUID.Zero;
  1087. public string Message = string.Empty;
  1088. public byte[] BinaryBucket = new byte[0];
  1089. }
  1090. }