GroupsModule.cs 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722
  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.Region.Framework.Interfaces;
  38. using OpenSim.Region.Framework.Scenes;
  39. using OpenSim.Services.Interfaces;
  40. using System.Text;
  41. using PermissionMask = OpenSim.Framework.PermissionMask;
  42. namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
  43. {
  44. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GroupsModule")]
  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;
  75. private IGroupsMessagingModule m_groupsMessagingModule;
  76. private IGroupsServicesConnector m_groupData;
  77. // Configuration settings
  78. private bool m_groupsEnabled = false;
  79. private bool m_groupNoticesEnabled = true;
  80. private bool m_debugEnabled = false;
  81. private int m_levelGroupCreate = 0;
  82. #region Region Module interfaceBase Members
  83. public void Initialise(IConfigSource config)
  84. {
  85. IConfig groupsConfig = config.Configs["Groups"];
  86. if (groupsConfig == null)
  87. {
  88. // Do not run this module by default.
  89. return;
  90. }
  91. else
  92. {
  93. m_groupsEnabled = groupsConfig.GetBoolean("Enabled", false);
  94. if (!m_groupsEnabled)
  95. return;
  96. if (groupsConfig.GetString("Module", "Default") != Name)
  97. {
  98. m_groupsEnabled = false;
  99. return;
  100. }
  101. m_log.InfoFormat("[xmlGROUPS]: Initializing {0}", this.Name);
  102. m_groupNoticesEnabled = groupsConfig.GetBoolean("NoticesEnabled", true);
  103. m_debugEnabled = groupsConfig.GetBoolean("DebugEnabled", false);
  104. m_levelGroupCreate = groupsConfig.GetInt("LevelGroupCreate", 0);
  105. }
  106. }
  107. public void AddRegion(Scene scene)
  108. {
  109. if (m_groupsEnabled)
  110. {
  111. scene.RegisterModuleInterface<IGroupsModule>(this);
  112. scene.AddCommand(
  113. "Debug",
  114. this,
  115. "debug groups verbose",
  116. "debug groups verbose <true|false>",
  117. "This setting turns on very verbose groups debugging",
  118. HandleDebugGroupsVerbose);
  119. }
  120. }
  121. private void HandleDebugGroupsVerbose(object modules, string[] args)
  122. {
  123. if (args.Length < 4)
  124. {
  125. MainConsole.Instance.Output("Usage: debug groups verbose <true|false>");
  126. return;
  127. }
  128. bool verbose = false;
  129. if (!bool.TryParse(args[3], out verbose))
  130. {
  131. MainConsole.Instance.Output("Usage: debug groups verbose <true|false>");
  132. return;
  133. }
  134. m_debugEnabled = verbose;
  135. MainConsole.Instance.Output("{0} verbose logging set to {1}", Name, m_debugEnabled);
  136. }
  137. public void RegionLoaded(Scene scene)
  138. {
  139. if (!m_groupsEnabled)
  140. return;
  141. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  142. if (m_groupData == null)
  143. {
  144. m_groupData = scene.RequestModuleInterface<IGroupsServicesConnector>();
  145. // No Groups Service Connector, then nothing works...
  146. if (m_groupData == null)
  147. {
  148. m_groupsEnabled = false;
  149. m_log.Error("[GROUPS]: Could not get IGroupsServicesConnector");
  150. Close();
  151. return;
  152. }
  153. }
  154. if (m_msgTransferModule == null)
  155. {
  156. m_msgTransferModule = scene.RequestModuleInterface<IMessageTransferModule>();
  157. // No message transfer module, no notices, group invites, rejects, ejects, etc
  158. if (m_msgTransferModule == null)
  159. {
  160. m_groupsEnabled = false;
  161. m_log.Warn("[GROUPS]: Could not get IMessageTransferModule");
  162. }
  163. }
  164. if (m_groupsMessagingModule == null)
  165. {
  166. m_groupsMessagingModule = scene.RequestModuleInterface<IGroupsMessagingModule>();
  167. // No message transfer module, no notices, group invites, rejects, ejects, etc
  168. if (m_groupsMessagingModule == null)
  169. m_log.Warn("[GROUPS]: Could not get IGroupsMessagingModule");
  170. }
  171. lock (m_sceneList)
  172. {
  173. m_sceneList.Add(scene);
  174. }
  175. scene.EventManager.OnNewClient += OnNewClient;
  176. scene.EventManager.OnMakeRootAgent += OnMakeRoot;
  177. scene.EventManager.OnMakeChildAgent += OnMakeChild;
  178. scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage;
  179. scene.EventManager.OnClientClosed += OnClientClosed;
  180. }
  181. public void RemoveRegion(Scene scene)
  182. {
  183. if (!m_groupsEnabled)
  184. return;
  185. if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  186. scene.EventManager.OnNewClient -= OnNewClient;
  187. scene.EventManager.OnMakeRootAgent -= OnMakeRoot;
  188. scene.EventManager.OnMakeChildAgent -= OnMakeChild;
  189. scene.EventManager.OnIncomingInstantMessage -= OnGridInstantMessage;
  190. scene.EventManager.OnClientClosed -= OnClientClosed;
  191. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  192. lock (m_sceneList)
  193. {
  194. m_sceneList.Remove(scene);
  195. }
  196. }
  197. public void Close()
  198. {
  199. if (!m_groupsEnabled)
  200. return;
  201. if (m_debugEnabled) m_log.Debug("[GROUPS]: Shutting down Groups module.");
  202. }
  203. public Type ReplaceableInterface
  204. {
  205. get { return null; }
  206. }
  207. public string Name
  208. {
  209. get { return "GroupsModule"; }
  210. }
  211. #endregion
  212. #region ISharedRegionModule Members
  213. public void PostInitialise()
  214. {
  215. // NoOp
  216. }
  217. #endregion
  218. #region EventHandlers
  219. private void OnMakeRoot(ScenePresence sp)
  220. {
  221. if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  222. sp.ControllingClient.OnUUIDGroupNameRequest += HandleUUIDGroupNameRequest;
  223. // Used for Notices and Group Invites/Accept/Reject
  224. sp.ControllingClient.OnInstantMessage += OnInstantMessage;
  225. // comented out because some viewers no longer suport it
  226. // sp.ControllingClient.AddGenericPacketHandler("avatargroupsrequest", AvatarGroupsRequest);
  227. // Send out group data update for compatibility.
  228. // There might be some problem with the thread we're generating this on but not
  229. // doing the update at this time causes problems (Mantis #7920 and #7915)
  230. // TODO: move sending this update to a later time in the rootification of the client.
  231. if(!sp.m_haveGroupInformation)
  232. SendAgentGroupDataUpdate(sp.ControllingClient, false);
  233. }
  234. private void OnMakeChild(ScenePresence sp)
  235. {
  236. if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  237. sp.ControllingClient.OnUUIDGroupNameRequest -= HandleUUIDGroupNameRequest;
  238. sp.ControllingClient.OnInstantMessage -= OnInstantMessage;
  239. }
  240. private void OnNewClient(IClientAPI client)
  241. {
  242. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  243. client.OnAgentDataUpdateRequest += OnAgentDataUpdateRequest;
  244. client.OnRequestAvatarProperties += OnRequestAvatarProperties;
  245. }
  246. /* this should be the right message to ask for other avatars groups
  247. private void AvatarGroupsRequest(Object sender, string method, List<String> args)
  248. {
  249. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  250. if (!(sender is IClientAPI))
  251. return;
  252. IClientAPI remoteClient = (IClientAPI)sender;
  253. UUID avatarID;
  254. UUID.TryParse(args[0], out avatarID);
  255. if (avatarID != UUID.Zero)
  256. {
  257. GroupMembershipData[] avatarGroups = GetProfileListedGroupMemberships(remoteClient, avatarID);
  258. remoteClient.SendAvatarGroupsReply(avatarID, avatarGroups);
  259. }
  260. }
  261. */
  262. // this should not be used to send groups memberships, but some viewers do expect it
  263. // it does send unnecessary memberships, when viewers just want other properties information
  264. private void OnRequestAvatarProperties(IClientAPI remoteClient, UUID avatarID)
  265. {
  266. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  267. GroupMembershipData[] avatarGroups = GetProfileListedGroupMemberships(remoteClient, avatarID);
  268. remoteClient.SendAvatarGroupsReply(avatarID, avatarGroups);
  269. }
  270. private void OnClientClosed(UUID AgentId, Scene scene)
  271. {
  272. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  273. if (scene == null)
  274. return;
  275. ScenePresence sp = scene.GetScenePresence(AgentId);
  276. IClientAPI client = sp.ControllingClient;
  277. if (client != null)
  278. {
  279. client.OnAgentDataUpdateRequest -= OnAgentDataUpdateRequest;
  280. client.OnRequestAvatarProperties -= OnRequestAvatarProperties;
  281. // make child possible not called?
  282. client.OnUUIDGroupNameRequest -= HandleUUIDGroupNameRequest;
  283. client.OnInstantMessage -= OnInstantMessage;
  284. }
  285. /*
  286. lock (m_ActiveClients)
  287. {
  288. if (m_ActiveClients.ContainsKey(AgentId))
  289. {
  290. IClientAPI client = m_ActiveClients[AgentId];
  291. client.OnUUIDGroupNameRequest -= HandleUUIDGroupNameRequest;
  292. client.OnAgentDataUpdateRequest -= OnAgentDataUpdateRequest;
  293. client.OnDirFindQuery -= OnDirFindQuery;
  294. client.OnInstantMessage -= OnInstantMessage;
  295. m_ActiveClients.Remove(AgentId);
  296. }
  297. else
  298. {
  299. if (m_debugEnabled) m_log.WarnFormat("[GROUPS]: Client closed that wasn't registered here.");
  300. }
  301. }
  302. */
  303. }
  304. private void OnAgentDataUpdateRequest(IClientAPI remoteClient, UUID dataForAgentID, UUID sessionID)
  305. {
  306. // this a private message for own agent only
  307. if (dataForAgentID != GetRequestingAgentID(remoteClient))
  308. return;
  309. SendAgentGroupDataUpdate(remoteClient, false);
  310. // its a info request not a change, so nothing is sent to others
  311. // they do get the group title with the avatar object update on arrivel to a region
  312. }
  313. private void HandleUUIDGroupNameRequest(UUID GroupID, IClientAPI remoteClient)
  314. {
  315. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  316. string GroupName;
  317. GroupRecord group = m_groupData.GetGroupRecord(GetRequestingAgentID(remoteClient), GroupID, null);
  318. if (group != null)
  319. {
  320. GroupName = group.GroupName;
  321. }
  322. else
  323. {
  324. GroupName = "Unknown";
  325. }
  326. remoteClient.SendGroupNameReply(GroupID, GroupName);
  327. }
  328. private void OnInstantMessage(IClientAPI remoteClient, GridInstantMessage im)
  329. {
  330. if (m_debugEnabled)
  331. m_log.DebugFormat("[xmlGROUPS]: OnInstantMessage called for {0}, message type {1}",
  332. remoteClient.Name, (InstantMessageDialog)im.dialog);
  333. if (remoteClient == null || !remoteClient.IsActive || remoteClient.AgentId == UUID.Zero)
  334. return;
  335. Scene scene = (Scene)remoteClient.Scene;
  336. if(scene == null)
  337. return;
  338. UUID remoteAgentID = remoteClient.AgentId;
  339. // Group invitations
  340. if ((im.dialog == (byte)InstantMessageDialog.GroupInvitationAccept) || (im.dialog == (byte)InstantMessageDialog.GroupInvitationDecline))
  341. {
  342. UUID inviteID = new UUID(im.imSessionID);
  343. GroupInviteInfo inviteInfo = m_groupData.GetAgentToGroupInvite(GetRequestingAgentID(remoteClient), inviteID);
  344. if (inviteInfo == null)
  345. {
  346. if (m_debugEnabled)
  347. m_log.WarnFormat("[xmlGROUPS]: Received an Invite IM for an invite that does not exist {0}.", inviteID);
  348. return;
  349. }
  350. if (m_debugEnabled)
  351. m_log.DebugFormat("[xmlGROUPS]: Invite is for Agent {0} to Group {1}.", inviteInfo.AgentID, inviteInfo.GroupID);
  352. UUID fromAgentID = new UUID(im.fromAgentID);
  353. if ((inviteInfo != null) && (fromAgentID == inviteInfo.AgentID))
  354. {
  355. // Accept
  356. if (im.dialog == (byte)InstantMessageDialog.GroupInvitationAccept)
  357. {
  358. if (m_debugEnabled)
  359. m_log.DebugFormat("[xmlGROUPS]: Received an accept invite notice.");
  360. // and the sessionid is the role
  361. m_groupData.AddAgentToGroup(remoteAgentID, inviteInfo.AgentID, inviteInfo.GroupID, inviteInfo.RoleID);
  362. GridInstantMessage msg = new GridInstantMessage();
  363. msg.imSessionID = UUID.Zero.Guid;
  364. msg.fromAgentID = UUID.Zero.Guid;
  365. msg.toAgentID = inviteInfo.AgentID.Guid;
  366. msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
  367. msg.fromAgentName = "Groups";
  368. msg.message = string.Format("You have been added to the group.");
  369. msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.MessageBox;
  370. msg.fromGroup = false;
  371. msg.offline = (byte)0;
  372. msg.ParentEstateID = 0;
  373. msg.Position = Vector3.Zero;
  374. msg.RegionID = UUID.Zero.Guid;
  375. msg.binaryBucket = new byte[0];
  376. OutgoingInstantMessage(msg, inviteInfo.AgentID);
  377. IClientAPI inviteeClient = GetActiveRootClient(inviteInfo.AgentID);
  378. if(inviteeClient !=null)
  379. {
  380. SendAgentGroupDataUpdate(inviteeClient,true);
  381. }
  382. m_groupData.RemoveAgentToGroupInvite(GetRequestingAgentID(remoteClient), inviteID);
  383. }
  384. // Reject
  385. if (im.dialog == (byte)InstantMessageDialog.GroupInvitationDecline)
  386. {
  387. if (m_debugEnabled)
  388. m_log.DebugFormat("[xmlGROUPS]: Received a reject invite notice.");
  389. m_groupData.RemoveAgentToGroupInvite(remoteAgentID, inviteID);
  390. }
  391. }
  392. return;
  393. }
  394. // Group notices
  395. if ((im.dialog == (byte)InstantMessageDialog.GroupNotice))
  396. {
  397. if (!m_groupNoticesEnabled)
  398. return;
  399. UUID GroupID = new UUID(im.toAgentID);
  400. GroupMembershipData grpMemberData = m_groupData.GetAgentGroupMembership(remoteAgentID, remoteAgentID, GroupID);
  401. if (grpMemberData == null)
  402. {
  403. remoteClient.SendAgentAlertMessage("Group membership not found", false);
  404. return;
  405. }
  406. if ((grpMemberData.GroupPowers & (ulong)GroupPowers.SendNotices) == 0)
  407. {
  408. remoteClient.SendAgentAlertMessage("No permission to send notice to group", false);
  409. return;
  410. }
  411. int index = im.message.IndexOf('|');
  412. if(index < 0)
  413. return;
  414. string Subject = im.message.Substring(0, index);
  415. string Message = im.message.Substring(index + 1);
  416. InventoryItemBase item = null;
  417. bool hasAttachment = false;
  418. UUID itemID = UUID.Zero;
  419. UUID ownerID = UUID.Zero;
  420. byte[] bucket;
  421. if (im.binaryBucket.Length >= 1 && im.binaryBucket[0] > 0)
  422. {
  423. try
  424. {
  425. string binBucket = Utils.BytesToString(im.binaryBucket);
  426. binBucket = binBucket.Substring(15); // remove extra LLSD pre header
  427. OSDMap binBucketMAP = (OSDMap)OSDParser.DeserializeLLSDXml(binBucket);
  428. itemID = binBucketMAP["item_id"].AsUUID();
  429. ownerID = binBucketMAP["owner_id"].AsUUID();
  430. }
  431. catch
  432. {
  433. m_log.DebugFormat("[xmlGROUPS]: failed to decode group notice bucket");
  434. return;
  435. }
  436. if(itemID != UUID.Zero && ownerID != UUID.Zero)
  437. {
  438. item = scene.InventoryService.GetItem(ownerID, itemID);
  439. if (item != null)
  440. {
  441. if((item.CurrentPermissions & (uint)(PermissionMask.Transfer | PermissionMask.Copy)) !=
  442. (uint)(PermissionMask.Transfer | PermissionMask.Copy))
  443. {
  444. remoteClient.SendAgentAlertMessage("Item must be have Copy and Transfer rights to attach to group notice", false);
  445. return;
  446. }
  447. hasAttachment = true;
  448. }
  449. }
  450. }
  451. if (hasAttachment)
  452. {
  453. //Bucket contains information about attachment.
  454. //
  455. //Byte offset and description of bucket data:
  456. //0: 1 byte indicating if attachment is present
  457. //1: 1 byte indicating the type of attachment
  458. //2: 16 bytes - Group UUID
  459. //18: 16 bytes - UUID of the attachment owner
  460. //34: 16 bytes - UUID of the attachment
  461. //50: variable - Name of the attachment
  462. //??: NUL byte to terminate the attachment name
  463. byte[] name = Encoding.UTF8.GetBytes(item.Name);
  464. bucket = new byte[51 + name.Length];//2 bytes, 3 UUIDs, and name and null
  465. bucket[0] = 1; //Has attachment flag
  466. bucket[1] = (byte)item.AssetType; //Type of Attachment
  467. GroupID.ToBytes(bucket, 2);
  468. ownerID.ToBytes(bucket, 18);
  469. itemID.ToBytes(bucket, 34);
  470. name.CopyTo(bucket, 50);
  471. }
  472. else
  473. {
  474. bucket = new byte[19];
  475. bucket[0] = 0; //Has attachment flag
  476. bucket[1] = 0; //Type of attachment
  477. GroupID.ToBytes(bucket, 2);
  478. bucket[18] = 0; //NUL terminate name of attachment
  479. }
  480. UUID NoticeID = UUID.Random();
  481. m_groupData.AddGroupNotice(remoteAgentID, GroupID, NoticeID, im.fromAgentName, Subject, Message, bucket);
  482. OnNewGroupNotice?.Invoke(GroupID, NoticeID);
  483. if (m_debugEnabled)
  484. {
  485. foreach (GroupMembersData member in m_groupData.GetGroupMembers(GetRequestingAgentID(remoteClient), GroupID))
  486. {
  487. if (m_debugEnabled)
  488. {
  489. UserAccount targetUser = m_sceneList[0].UserAccountService.GetUserAccount(
  490. remoteClient.Scene.RegionInfo.ScopeID, member.AgentID);
  491. if (targetUser != null)
  492. {
  493. m_log.DebugFormat(
  494. "[xmlGROUPS]: Prepping group notice {0} for agent: {1} who Accepts Notices ({2})",
  495. NoticeID, targetUser.FirstName + " " + targetUser.LastName, member.AcceptNotices);
  496. }
  497. else
  498. {
  499. m_log.DebugFormat(
  500. "[xmlGROUPS]: Prepping group notice {0} for agent: {1} who Accepts Notices ({2})",
  501. NoticeID, member.AgentID, member.AcceptNotices);
  502. }
  503. }
  504. }
  505. }
  506. if (m_groupsMessagingModule != null)
  507. {
  508. GridInstantMessage msg
  509. = CreateGroupNoticeIM(UUID.Zero, NoticeID, (byte)InstantMessageDialog.GroupNotice);
  510. m_groupsMessagingModule.SendMessageToGroup(
  511. msg, GroupID, remoteAgentID, gmd => gmd.AcceptNotices);
  512. }
  513. }
  514. else if (im.dialog == (byte)InstantMessageDialog.GroupNoticeInventoryAccepted)
  515. {
  516. if (!m_groupNoticesEnabled)
  517. return;
  518. UUID noticeID = new UUID(im.imSessionID);
  519. if (m_debugEnabled)
  520. m_log.DebugFormat("[xmlGROUPS]: Accepted notice {0} for {1}", noticeID, remoteClient.AgentId);
  521. if (noticeID == UUID.Zero)
  522. return;
  523. UUID folderID = UUID.Zero;
  524. try
  525. {
  526. if (im.binaryBucket != null && im.binaryBucket.Length >= 16)
  527. folderID = new UUID(im.binaryBucket, 0);
  528. }
  529. catch
  530. {
  531. m_log.DebugFormat("[xmlGROUPS]: GroupNoticeInventoryAccepted failed to decode target folder");
  532. return;
  533. }
  534. GroupNoticeInfo notice = m_groupData.GetGroupNotice(remoteAgentID, noticeID);
  535. if (notice == null)
  536. {
  537. if (m_debugEnabled)
  538. m_log.DebugFormat(
  539. "[GROUPS]: Could not find notice {0} for {1} on GroupNoticeInventoryAccepted.",
  540. noticeID, remoteClient.AgentId);
  541. return;
  542. }
  543. UUID giver = UUID.Zero;
  544. UUID attachmentUUID = UUID.Zero;
  545. try
  546. {
  547. giver = new UUID(notice.BinaryBucket, 18);
  548. attachmentUUID = new UUID(notice.BinaryBucket, 34);
  549. }
  550. catch
  551. {
  552. m_log.DebugFormat("[xmlGROUPS]: GroupNoticeInventoryAccepted failed to giver or attachment ID");
  553. return;
  554. }
  555. if (m_debugEnabled)
  556. m_log.DebugFormat("[xmlGroups]: Giving inventory from {0} to {1}", giver, remoteAgentID);
  557. string message = "Could not find group notice attached item";
  558. InventoryItemBase itemCopy = scene.InventoryService.GetItem(giver, attachmentUUID);
  559. if (itemCopy != null)
  560. {
  561. itemCopy = scene.GiveInventoryItem(remoteAgentID, giver, attachmentUUID, folderID, out message);
  562. }
  563. if (itemCopy == null)
  564. {
  565. remoteClient.SendAgentAlertMessage(message, false);
  566. return;
  567. }
  568. remoteClient.SendInventoryItemCreateUpdate(itemCopy, 0);
  569. }
  570. else if (im.dialog == (byte)InstantMessageDialog.GroupNoticeInventoryDeclined)
  571. {
  572. if (!m_groupNoticesEnabled)
  573. return;
  574. UUID noticeID = new UUID(im.imSessionID);
  575. if (m_debugEnabled)
  576. m_log.DebugFormat("[xmlGROUPS]: Accepted notice {0} for {1}", noticeID, remoteAgentID);
  577. if (noticeID == UUID.Zero)
  578. return;
  579. GroupNoticeInfo notice = m_groupData.GetGroupNotice(remoteAgentID, noticeID);
  580. if (notice == null)
  581. {
  582. if (m_debugEnabled)
  583. m_log.DebugFormat(
  584. "[GROUPS]: Could not find notice {0} for {1} on GroupNoticeInventoryAccepted.",
  585. noticeID, remoteClient.AgentId);
  586. return;
  587. }
  588. UUID giver = UUID.Zero;
  589. UUID attachmentUUID = UUID.Zero;
  590. try
  591. {
  592. giver = new UUID(notice.BinaryBucket, 18);
  593. attachmentUUID = new UUID(notice.BinaryBucket, 34);
  594. }
  595. catch
  596. {
  597. m_log.DebugFormat("[xmlGROUPS]: GroupNoticeInventoryAccepted failed to giver or attachment ID");
  598. return;
  599. }
  600. if (m_debugEnabled)
  601. m_log.DebugFormat("[xmlGroups]: Deny inventory from {0} to {1}", giver, remoteAgentID);
  602. string message = String.Empty;
  603. // check if we already have it
  604. InventoryItemBase itemCopy = scene.InventoryService.GetItem(remoteAgentID, attachmentUUID);
  605. if (itemCopy == null)
  606. return;
  607. InventoryFolderBase trash = scene.InventoryService.GetFolderForType(remoteAgentID, FolderType.Trash);
  608. if (trash == null)
  609. {
  610. m_log.DebugFormat("[xmlGROUPS]: failed to find trash folder for {0} ", remoteAgentID);
  611. return;
  612. }
  613. if (itemCopy.Folder == trash.ID || remoteAgentID == giver)
  614. return;
  615. itemCopy.Folder = trash.ID;
  616. scene.InventoryService.MoveItems(itemCopy.Owner, new List<InventoryItemBase>() { itemCopy });
  617. if (itemCopy == null)
  618. {
  619. remoteClient.SendAgentAlertMessage(message, false);
  620. return;
  621. }
  622. remoteClient.SendInventoryItemCreateUpdate(itemCopy, 0);
  623. }
  624. // Interop, received special 210 code for ejecting a group member
  625. // this only works within the comms servers domain, and won't work hypergrid
  626. // TODO:FIXME: Use a presence server of some kind to find out where the
  627. // client actually is, and try contacting that region directly to notify them,
  628. // or provide the notification via xmlrpc update queue
  629. else if ((im.dialog == 210))
  630. {
  631. // This is sent from the region that the ejectee was ejected from
  632. // if it's being delivered here, then the ejectee is here
  633. // so we need to send local updates to the agent.
  634. UUID ejecteeID = new UUID(im.toAgentID);
  635. im.imSessionID = UUID.Zero.Guid;
  636. im.dialog = (byte)InstantMessageDialog.MessageFromAgent;
  637. OutgoingInstantMessage(im, ejecteeID);
  638. IClientAPI ejectee = GetActiveRootClient(ejecteeID);
  639. if (ejectee != null)
  640. {
  641. UUID groupID = new UUID(im.imSessionID);
  642. ejectee.SendAgentDropGroup(groupID);
  643. SendAgentGroupDataUpdate(ejectee,true);
  644. }
  645. }
  646. }
  647. private void OnGridInstantMessage(GridInstantMessage msg)
  648. {
  649. if (m_debugEnabled)
  650. m_log.InfoFormat("[xmlGROUPS]: OnGridInstantMessage called");
  651. // Trigger the above event handler
  652. OnInstantMessage(null, msg);
  653. // If a message from a group arrives here, it may need to be forwarded to a local client
  654. if (msg.fromGroup == true)
  655. {
  656. switch (msg.dialog)
  657. {
  658. case (byte)InstantMessageDialog.GroupInvitation:
  659. case (byte)InstantMessageDialog.GroupNotice:
  660. UUID toAgentID = new UUID(msg.toAgentID);
  661. IClientAPI localClient = GetActiveRootClient(toAgentID);
  662. if (localClient != null)
  663. {
  664. localClient.SendInstantMessage(msg);
  665. }
  666. break;
  667. }
  668. }
  669. }
  670. #endregion
  671. #region IGroupsModule Members
  672. public event NewGroupNotice OnNewGroupNotice;
  673. public GroupRecord GetGroupRecord(UUID GroupID)
  674. {
  675. return m_groupData.GetGroupRecord(UUID.Zero, GroupID, null);
  676. }
  677. public GroupRecord GetGroupRecord(string name)
  678. {
  679. return m_groupData.GetGroupRecord(UUID.Zero, UUID.Zero, name);
  680. }
  681. public void ActivateGroup(IClientAPI remoteClient, UUID groupID)
  682. {
  683. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  684. UUID agentID = GetRequestingAgentID(remoteClient);
  685. m_groupData.SetAgentActiveGroup(agentID, agentID, groupID);
  686. // llClientView does this
  687. SendAgentGroupDataUpdate(remoteClient, true);
  688. }
  689. /// <summary>
  690. /// Get the Role Titles for an Agent, for a specific group
  691. /// </summary>
  692. public List<GroupTitlesData> GroupTitlesRequest(IClientAPI remoteClient, UUID groupID)
  693. {
  694. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  695. List<GroupRolesData> agentRoles = m_groupData.GetAgentGroupRoles(GetRequestingAgentID(remoteClient), GetRequestingAgentID(remoteClient), groupID);
  696. GroupMembershipData agentMembership = m_groupData.GetAgentGroupMembership(GetRequestingAgentID(remoteClient), GetRequestingAgentID(remoteClient), groupID);
  697. List<GroupTitlesData> titles = new List<GroupTitlesData>();
  698. foreach (GroupRolesData role in agentRoles)
  699. {
  700. GroupTitlesData title = new GroupTitlesData();
  701. title.Name = role.Name;
  702. if (agentMembership != null)
  703. {
  704. title.Selected = agentMembership.ActiveRole == role.RoleID;
  705. }
  706. title.UUID = role.RoleID;
  707. titles.Add(title);
  708. }
  709. return titles;
  710. }
  711. public List<GroupMembersData> GroupMembersRequest(IClientAPI remoteClient, UUID groupID)
  712. {
  713. if (m_debugEnabled)
  714. m_log.DebugFormat(
  715. "[GROUPS]: GroupMembersRequest called for {0} from client {1}", groupID, remoteClient.Name);
  716. List<GroupMembersData> data = m_groupData.GetGroupMembers(GetRequestingAgentID(remoteClient), groupID);
  717. if (m_debugEnabled)
  718. {
  719. foreach (GroupMembersData member in data)
  720. {
  721. m_log.DebugFormat("[GROUPS]: Member({0}) - IsOwner({1})", member.AgentID, member.IsOwner);
  722. }
  723. }
  724. return data;
  725. }
  726. public ulong GetFullGroupPowers(UUID agentID, UUID groupID)
  727. {
  728. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  729. List<GroupRolesData> data = m_groupData.GetGroupRoles(agentID, groupID);
  730. if (data == null || data.Count == 0)
  731. return 0;
  732. ulong powers = 0;
  733. for (int i = 0; i < data.Count; ++i)
  734. {
  735. powers |= data[i].Powers;
  736. }
  737. return powers;
  738. }
  739. public List<GroupRolesData> GroupRoleDataRequest(UUID agentID, UUID groupID)
  740. {
  741. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  742. List<GroupRolesData> data = m_groupData.GetGroupRoles(agentID, groupID);
  743. return data;
  744. }
  745. public List<GroupRolesData> GroupRoleDataRequest(IClientAPI remoteClient, UUID groupID)
  746. {
  747. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  748. List<GroupRolesData> data = m_groupData.GetGroupRoles(GetRequestingAgentID(remoteClient), groupID);
  749. return data;
  750. }
  751. public List<GroupRoleMembersData> GroupRoleMembersRequest(IClientAPI remoteClient, UUID groupID)
  752. {
  753. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  754. List<GroupRoleMembersData> data = m_groupData.GetGroupRoleMembers(GetRequestingAgentID(remoteClient), groupID);
  755. if (m_debugEnabled)
  756. {
  757. foreach (GroupRoleMembersData member in data)
  758. {
  759. m_log.DebugFormat("[GROUPS]: Member({0}) - Role({1})", member.MemberID, member.RoleID);
  760. }
  761. }
  762. return data;
  763. }
  764. public GroupProfileData GroupProfileRequest(IClientAPI remoteClient, UUID groupID)
  765. {
  766. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  767. GroupProfileData profile = new GroupProfileData();
  768. GroupRecord groupInfo = m_groupData.GetGroupRecord(GetRequestingAgentID(remoteClient), groupID, null);
  769. if (groupInfo != null)
  770. {
  771. profile.AllowPublish = groupInfo.AllowPublish;
  772. profile.Charter = groupInfo.Charter;
  773. profile.FounderID = groupInfo.FounderID;
  774. profile.GroupID = groupID;
  775. profile.GroupMembershipCount = m_groupData.GetGroupMembers(GetRequestingAgentID(remoteClient), groupID).Count;
  776. profile.GroupRolesCount = m_groupData.GetGroupRoles(GetRequestingAgentID(remoteClient), groupID).Count;
  777. profile.InsigniaID = groupInfo.GroupPicture;
  778. profile.MaturePublish = groupInfo.MaturePublish;
  779. profile.MembershipFee = groupInfo.MembershipFee;
  780. profile.Money = 0; // TODO: Get this from the currency server?
  781. profile.Name = groupInfo.GroupName;
  782. profile.OpenEnrollment = groupInfo.OpenEnrollment;
  783. profile.OwnerRole = groupInfo.OwnerRoleID;
  784. profile.ShowInList = groupInfo.ShowInList;
  785. }
  786. GroupMembershipData memberInfo = m_groupData.GetAgentGroupMembership(GetRequestingAgentID(remoteClient), GetRequestingAgentID(remoteClient), groupID);
  787. if (memberInfo != null)
  788. {
  789. profile.MemberTitle = memberInfo.GroupTitle;
  790. profile.PowersMask = memberInfo.GroupPowers;
  791. }
  792. /*
  793. this should save xmlrpc calls, but seems to return wrong GroupMembershipCount and GroupRolesCount
  794. UUID agent = GetRequestingAgentID(remoteClient);
  795. GroupProfileData profile = m_groupData.GetMemberGroupProfile(agent, groupID, agent);
  796. */
  797. return profile;
  798. }
  799. public GroupMembershipData[] GetMembershipData(UUID agentID)
  800. {
  801. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  802. return m_groupData.GetAgentGroupMemberships(UUID.Zero, agentID).ToArray();
  803. }
  804. public GroupMembershipData GetMembershipData(UUID groupID, UUID agentID)
  805. {
  806. if (m_debugEnabled)
  807. m_log.DebugFormat(
  808. "[GROUPS]: {0} called with groupID={1}, agentID={2}",
  809. System.Reflection.MethodBase.GetCurrentMethod().Name, groupID, agentID);
  810. return m_groupData.GetAgentGroupMembership(UUID.Zero, agentID, groupID);
  811. }
  812. public GroupMembershipData GetActiveMembershipData(UUID agentID)
  813. {
  814. return m_groupData.GetAgentActiveMembership(agentID, agentID);
  815. }
  816. public void UpdateGroupInfo(IClientAPI remoteClient, UUID groupID, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish)
  817. {
  818. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  819. // Note: Permissions checking for modification rights is handled by the Groups Server/Service
  820. m_groupData.UpdateGroup(GetRequestingAgentID(remoteClient), groupID, charter, showInList, insigniaID, membershipFee, openEnrollment, allowPublish, maturePublish);
  821. }
  822. public void SetGroupAcceptNotices(IClientAPI remoteClient, UUID groupID, bool acceptNotices, bool listInProfile)
  823. {
  824. // Note: Permissions checking for modification rights is handled by the Groups Server/Service
  825. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  826. m_groupData.SetAgentGroupInfo(GetRequestingAgentID(remoteClient), GetRequestingAgentID(remoteClient), groupID, acceptNotices, listInProfile);
  827. }
  828. public UUID CreateGroup(IClientAPI remoteClient, string name, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish)
  829. {
  830. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  831. GroupRecord groupRecord = m_groupData.GetGroupRecord(GetRequestingAgentID(remoteClient), UUID.Zero, name);
  832. if (groupRecord != null)
  833. {
  834. remoteClient.SendCreateGroupReply(UUID.Zero, false, "A group with the same name already exists.");
  835. return UUID.Zero;
  836. }
  837. // check user level
  838. ScenePresence avatar = null;
  839. Scene scene = (Scene)remoteClient.Scene;
  840. scene.TryGetScenePresence(remoteClient.AgentId, out avatar);
  841. if (avatar != null)
  842. {
  843. if (avatar.GodController.UserLevel < m_levelGroupCreate)
  844. {
  845. remoteClient.SendCreateGroupReply(UUID.Zero, false, "You have insufficient permissions to create a group.");
  846. return UUID.Zero;
  847. }
  848. }
  849. // check funds
  850. // is there a money module present ?
  851. IMoneyModule money = scene.RequestModuleInterface<IMoneyModule>();
  852. if (money != null && money.GroupCreationCharge > 0)
  853. {
  854. // do the transaction, that is if the agent has sufficient funds
  855. if (!money.AmountCovered(remoteClient.AgentId, money.GroupCreationCharge)) {
  856. remoteClient.SendCreateGroupReply(UUID.Zero, false, "You have insufficient funds to create a group.");
  857. return UUID.Zero;
  858. }
  859. money.ApplyCharge(GetRequestingAgentID(remoteClient), money.GroupCreationCharge, MoneyTransactionType.GroupCreate, name);
  860. }
  861. UUID groupID = m_groupData.CreateGroup(GetRequestingAgentID(remoteClient), name, charter, showInList, insigniaID, membershipFee, openEnrollment, allowPublish, maturePublish, GetRequestingAgentID(remoteClient));
  862. remoteClient.SendCreateGroupReply(groupID, true, "Group created successfully");
  863. // Update the founder with new group information.
  864. SendAgentGroupDataUpdate(remoteClient, true);
  865. return groupID;
  866. }
  867. public GroupNoticeData[] GroupNoticesListRequest(IClientAPI remoteClient, UUID groupID)
  868. {
  869. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  870. // ToDo: check if agent is a member of group and is allowed to see notices?
  871. return m_groupData.GetGroupNotices(GetRequestingAgentID(remoteClient), groupID).ToArray();
  872. }
  873. /// <summary>
  874. /// Get the title of the agent's current role.
  875. /// </summary>
  876. public string GetGroupTitle(UUID avatarID)
  877. {
  878. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  879. GroupMembershipData membership = m_groupData.GetAgentActiveMembership(UUID.Zero, avatarID);
  880. if (membership != null)
  881. {
  882. return membership.GroupTitle;
  883. }
  884. return string.Empty;
  885. }
  886. /// <summary>
  887. /// Change the current Active Group Role for Agent
  888. /// </summary>
  889. public void GroupTitleUpdate(IClientAPI remoteClient, UUID groupID, UUID titleRoleID)
  890. {
  891. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  892. m_groupData.SetAgentActiveGroupRole(GetRequestingAgentID(remoteClient), GetRequestingAgentID(remoteClient), groupID, titleRoleID);
  893. // TODO: Not sure what all is needed here, but if the active group role change is for the group
  894. // the client currently has set active, then we need to do a scene presence update too
  895. // if (m_groupData.GetAgentActiveMembership(GetRequestingAgentID(remoteClient)).GroupID == GroupID)
  896. SendDataUpdate(remoteClient, true);
  897. }
  898. public void GroupRoleUpdate(IClientAPI remoteClient, UUID groupID, UUID roleID, string name, string description, string title, ulong powers, byte updateType)
  899. {
  900. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  901. // Security Checks are handled in the Groups Service.
  902. switch ((OpenMetaverse.GroupRoleUpdate)updateType)
  903. {
  904. case OpenMetaverse.GroupRoleUpdate.Create:
  905. m_groupData.AddGroupRole(GetRequestingAgentID(remoteClient), groupID, UUID.Random(), name, description, title, powers);
  906. break;
  907. case OpenMetaverse.GroupRoleUpdate.Delete:
  908. m_groupData.RemoveGroupRole(GetRequestingAgentID(remoteClient), groupID, roleID);
  909. break;
  910. case OpenMetaverse.GroupRoleUpdate.UpdateAll:
  911. case OpenMetaverse.GroupRoleUpdate.UpdateData:
  912. case OpenMetaverse.GroupRoleUpdate.UpdatePowers:
  913. if (m_debugEnabled)
  914. {
  915. GroupPowers gp = (GroupPowers)powers;
  916. m_log.DebugFormat("[GROUPS]: Role ({0}) updated with Powers ({1}) ({2})", name, powers.ToString(), gp.ToString());
  917. }
  918. m_groupData.UpdateGroupRole(GetRequestingAgentID(remoteClient), groupID, roleID, name, description, title, powers);
  919. break;
  920. case OpenMetaverse.GroupRoleUpdate.NoUpdate:
  921. default:
  922. // No Op
  923. break;
  924. }
  925. // TODO: This update really should send out updates for everyone in the role that just got changed.
  926. SendAgentGroupDataUpdate(remoteClient, false);
  927. }
  928. public void GroupRoleChanges(IClientAPI remoteClient, UUID groupID, UUID roleID, UUID memberID, uint changes)
  929. {
  930. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  931. // Todo: Security check
  932. switch (changes)
  933. {
  934. case 0:
  935. // Add
  936. m_groupData.AddAgentToGroupRole(GetRequestingAgentID(remoteClient), memberID, groupID, roleID);
  937. break;
  938. case 1:
  939. // Remove
  940. m_groupData.RemoveAgentFromGroupRole(GetRequestingAgentID(remoteClient), memberID, groupID, roleID);
  941. break;
  942. default:
  943. m_log.ErrorFormat("[GROUPS]: {0} does not understand changes == {1}", System.Reflection.MethodBase.GetCurrentMethod().Name, changes);
  944. break;
  945. }
  946. // TODO: This update really should send out updates for everyone in the role that just got changed.
  947. SendAgentGroupDataUpdate(remoteClient, false);
  948. }
  949. public void GroupNoticeRequest(IClientAPI remoteClient, UUID groupNoticeID)
  950. {
  951. if (m_debugEnabled)
  952. m_log.DebugFormat("[xmlGROUPS]: GroupNoticeRequest {0}", groupNoticeID);
  953. GroupNoticeInfo info = m_groupData.GetGroupNotice(remoteClient.AgentId, groupNoticeID);
  954. if(info == null)
  955. return;
  956. GridInstantMessage msg = CreateGroupNoticeIM(remoteClient.AgentId, groupNoticeID, (byte)InstantMessageDialog.GroupNoticeRequested, info);
  957. OutgoingInstantMessage(msg, GetRequestingAgentID(remoteClient));
  958. }
  959. public GridInstantMessage CreateGroupNoticeIM(UUID agentID, UUID groupNoticeID, byte dialog)
  960. {
  961. GroupNoticeInfo info = m_groupData.GetGroupNotice(agentID, groupNoticeID);
  962. return CreateGroupNoticeIM(agentID, groupNoticeID, dialog, info);
  963. }
  964. private GridInstantMessage CreateGroupNoticeIM(UUID agentID, UUID groupNoticeID, byte dialog, GroupNoticeInfo info)
  965. {
  966. GridInstantMessage msg = new GridInstantMessage();
  967. byte[] bucket;
  968. msg.imSessionID = groupNoticeID.Guid;
  969. msg.toAgentID = agentID.Guid;
  970. msg.dialog = dialog;
  971. msg.fromGroup = true;
  972. msg.offline = (byte)1; // Allow this message to be stored for offline use
  973. msg.ParentEstateID = 0;
  974. msg.Position = Vector3.Zero;
  975. msg.RegionID = UUID.Zero.Guid;
  976. if (info != null)
  977. {
  978. msg.fromAgentID = info.GroupID.Guid;
  979. msg.timestamp = info.noticeData.Timestamp;
  980. msg.fromAgentName = info.noticeData.FromName;
  981. msg.message = info.noticeData.Subject + "|" + info.Message;
  982. if (info.BinaryBucket[0] > 0)
  983. {
  984. //32 is due to not needing space for two of the UUIDs.
  985. //(Don't need UUID of attachment or its owner in IM)
  986. //50 offset gets us to start of attachment name.
  987. bucket = new byte[info.BinaryBucket.Length - 32];
  988. Array.Copy(info.BinaryBucket, 0,
  989. bucket, 0, 18);
  990. Array.Copy(info.BinaryBucket, 50,
  991. bucket, 18, info.BinaryBucket.Length - 50);
  992. }
  993. else
  994. {
  995. bucket = new byte[19];
  996. bucket[0] = 0; //No attachment
  997. bucket[1] = 0; //Attachment type
  998. bucket[18] = 0; //NUL terminate name
  999. }
  1000. msg.binaryBucket = bucket;
  1001. }
  1002. else
  1003. {
  1004. if (m_debugEnabled)
  1005. m_log.DebugFormat("[GROUPS]: Group Notice {0} not found, composing empty message.", groupNoticeID);
  1006. msg.fromAgentID = UUID.Zero.Guid;
  1007. msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
  1008. msg.fromAgentName = string.Empty;
  1009. msg.message = string.Empty;
  1010. msg.binaryBucket = new byte[0];
  1011. }
  1012. return msg;
  1013. }
  1014. public void JoinGroupRequest(IClientAPI remoteClient, UUID groupID)
  1015. {
  1016. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  1017. // Should check to see if OpenEnrollment, or if there's an outstanding invitation
  1018. m_groupData.AddAgentToGroup(GetRequestingAgentID(remoteClient), GetRequestingAgentID(remoteClient), groupID, UUID.Zero);
  1019. // check funds
  1020. // is there a money module present ?
  1021. GroupRecord groupRecord = m_groupData.GetGroupRecord(GetRequestingAgentID(remoteClient), groupID, null);
  1022. IMoneyModule money = remoteClient.Scene.RequestModuleInterface<IMoneyModule>();
  1023. if (money != null && groupRecord.MembershipFee > 0)
  1024. {
  1025. // do the transaction, that is if the agent has sufficient funds
  1026. if (!money.AmountCovered(GetRequestingAgentID(remoteClient), groupRecord.MembershipFee)) {
  1027. remoteClient.SendCreateGroupReply(UUID.Zero, false, "You have insufficient funds to join the group.");
  1028. return;
  1029. }
  1030. money.ApplyCharge(GetRequestingAgentID(remoteClient), groupRecord.MembershipFee, MoneyTransactionType.GroupJoin, groupRecord.GroupName);
  1031. }
  1032. remoteClient.SendJoinGroupReply(groupID, true);
  1033. SendAgentGroupDataUpdate(remoteClient, true);
  1034. }
  1035. public void LeaveGroupRequest(IClientAPI remoteClient, UUID groupID)
  1036. {
  1037. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  1038. m_groupData.RemoveAgentFromGroup(GetRequestingAgentID(remoteClient), GetRequestingAgentID(remoteClient), groupID);
  1039. remoteClient.SendLeaveGroupReply(groupID, true);
  1040. remoteClient.SendAgentDropGroup(groupID);
  1041. // SL sends out notifcations to the group messaging session that the person has left
  1042. // Should this also update everyone who is in the group?
  1043. SendAgentGroupDataUpdate(remoteClient, true);
  1044. }
  1045. public void EjectGroupMemberRequest(IClientAPI remoteClient, UUID groupID, UUID ejecteeID)
  1046. {
  1047. EjectGroupMember(remoteClient, GetRequestingAgentID(remoteClient), groupID, ejecteeID);
  1048. }
  1049. public void EjectGroupMember(IClientAPI remoteClient, UUID agentID, UUID groupID, UUID ejecteeID)
  1050. {
  1051. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  1052. // Todo: Security check?
  1053. m_groupData.RemoveAgentFromGroup(agentID, ejecteeID, groupID);
  1054. string agentName;
  1055. RegionInfo regionInfo;
  1056. // remoteClient provided or just agentID?
  1057. if (remoteClient != null)
  1058. {
  1059. agentName = remoteClient.Name;
  1060. regionInfo = remoteClient.Scene.RegionInfo;
  1061. remoteClient.SendEjectGroupMemberReply(agentID, groupID, true);
  1062. }
  1063. else
  1064. {
  1065. IClientAPI client = GetActiveClient(agentID);
  1066. if (client != null)
  1067. {
  1068. agentName = client.Name;
  1069. regionInfo = client.Scene.RegionInfo;
  1070. client.SendEjectGroupMemberReply(agentID, groupID, true);
  1071. }
  1072. else
  1073. {
  1074. regionInfo = m_sceneList[0].RegionInfo;
  1075. UserAccount acc = m_sceneList[0].UserAccountService.GetUserAccount(regionInfo.ScopeID, agentID);
  1076. if (acc != null)
  1077. {
  1078. agentName = acc.FirstName + " " + acc.LastName;
  1079. }
  1080. else
  1081. {
  1082. agentName = "Unknown member";
  1083. }
  1084. }
  1085. }
  1086. GroupRecord groupInfo = m_groupData.GetGroupRecord(agentID, groupID, null);
  1087. if (groupInfo == null)
  1088. return;
  1089. IClientAPI ejecteeClient = GetActiveRootClient(ejecteeID);
  1090. // Send Message to Ejectee
  1091. GridInstantMessage msg = new GridInstantMessage();
  1092. string ejecteeName = "Unknown member";
  1093. // if local send a normal message
  1094. if(ejecteeClient != null)
  1095. {
  1096. msg.imSessionID = UUID.Zero.Guid;
  1097. msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.MessageFromAgent;
  1098. // also execute and send update
  1099. ejecteeClient.SendAgentDropGroup(groupID);
  1100. SendAgentGroupDataUpdate(ejecteeClient,true);
  1101. ejecteeName = ejecteeClient.Name;
  1102. }
  1103. else // send
  1104. {
  1105. // Interop, received special 210 code for ejecting a group member
  1106. // this only works within the comms servers domain, and won't work hypergrid
  1107. // TODO:FIXME: Use a presence server of some kind to find out where the
  1108. // client actually is, and try contacting that region directly to notify them,
  1109. // or provide the notification via xmlrpc update queue
  1110. msg.imSessionID = groupInfo.GroupID.Guid;
  1111. msg.dialog = (byte)210; //interop
  1112. UserAccount account = m_sceneList[0].UserAccountService.GetUserAccount(regionInfo.ScopeID, ejecteeID);
  1113. if (account != null)
  1114. ejecteeName = account.FirstName + " " + account.LastName;
  1115. }
  1116. msg.fromAgentID = agentID.Guid;
  1117. // msg.fromAgentID = info.GroupID;
  1118. msg.toAgentID = ejecteeID.Guid;
  1119. //msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
  1120. msg.timestamp = 0;
  1121. msg.fromAgentName = agentName;
  1122. msg.message = string.Format("You have been ejected from '{1}' by {0}.", agentName, groupInfo.GroupName);
  1123. //
  1124. msg.fromGroup = false;
  1125. msg.offline = (byte)0;
  1126. msg.ParentEstateID = 0;
  1127. msg.Position = Vector3.Zero;
  1128. msg.RegionID = regionInfo.RegionID.Guid;
  1129. msg.binaryBucket = new byte[0];
  1130. OutgoingInstantMessage(msg, ejecteeID);
  1131. // Message to ejector
  1132. msg = new GridInstantMessage();
  1133. msg.imSessionID = UUID.Zero.Guid;
  1134. msg.fromAgentID = agentID.Guid;
  1135. msg.toAgentID = agentID.Guid;
  1136. msg.timestamp = 0;
  1137. msg.fromAgentName = agentName;
  1138. msg.message = string.Format("{2} has been ejected from '{1}' by {0}.", agentName, groupInfo.GroupName, ejecteeName);
  1139. // msg.dialog = (byte)210; //interop
  1140. msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.MessageFromAgent;
  1141. msg.fromGroup = false;
  1142. msg.offline = (byte)0;
  1143. msg.ParentEstateID = 0;
  1144. msg.Position = Vector3.Zero;
  1145. msg.RegionID = regionInfo.RegionID.Guid;
  1146. msg.binaryBucket = new byte[0];
  1147. OutgoingInstantMessage(msg, agentID);
  1148. }
  1149. public void InviteGroupRequest(IClientAPI remoteClient, UUID groupID, UUID invitedAgentID, UUID roleID)
  1150. {
  1151. InviteGroup(remoteClient, GetRequestingAgentID(remoteClient), groupID, invitedAgentID, roleID);
  1152. }
  1153. public void InviteGroup(IClientAPI remoteClient, UUID agentID, UUID groupID, UUID invitedAgentID, UUID roleID)
  1154. {
  1155. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  1156. string agentName;
  1157. RegionInfo regionInfo;
  1158. // remoteClient provided or just agentID?
  1159. if (remoteClient != null)
  1160. {
  1161. agentName = remoteClient.Name;
  1162. regionInfo = remoteClient.Scene.RegionInfo;
  1163. }
  1164. else
  1165. {
  1166. IClientAPI client = GetActiveClient(agentID);
  1167. if (client != null)
  1168. {
  1169. agentName = client.Name;
  1170. regionInfo = client.Scene.RegionInfo;
  1171. }
  1172. else
  1173. {
  1174. regionInfo = m_sceneList[0].RegionInfo;
  1175. UserAccount account = m_sceneList[0].UserAccountService.GetUserAccount(regionInfo.ScopeID, agentID);
  1176. if (account != null)
  1177. {
  1178. agentName = account.FirstName + " " + account.LastName;
  1179. }
  1180. else
  1181. {
  1182. agentName = "Unknown member";
  1183. }
  1184. }
  1185. }
  1186. // Todo: Security check, probably also want to send some kind of notification
  1187. UUID InviteID = UUID.Random();
  1188. m_groupData.AddAgentToGroupInvite(agentID, InviteID, groupID, roleID, invitedAgentID);
  1189. // Check to see if the invite went through, if it did not then it's possible
  1190. // the remoteClient did not validate or did not have permission to invite.
  1191. GroupInviteInfo inviteInfo = m_groupData.GetAgentToGroupInvite(agentID, InviteID);
  1192. if (inviteInfo != null)
  1193. {
  1194. if (m_msgTransferModule != null)
  1195. {
  1196. Guid inviteUUID = InviteID.Guid;
  1197. GridInstantMessage msg = new GridInstantMessage();
  1198. msg.imSessionID = inviteUUID;
  1199. // msg.fromAgentID = agentID.Guid;
  1200. msg.fromAgentID = groupID.Guid;
  1201. msg.toAgentID = invitedAgentID.Guid;
  1202. //msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
  1203. msg.timestamp = 0;
  1204. msg.fromAgentName = agentName;
  1205. msg.message = string.Format("{0} has invited you to join a group. There is no cost to join this group.", agentName);
  1206. msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.GroupInvitation;
  1207. msg.fromGroup = true;
  1208. msg.offline = (byte)0;
  1209. msg.ParentEstateID = 0;
  1210. msg.Position = Vector3.Zero;
  1211. msg.RegionID = regionInfo.RegionID.Guid;
  1212. msg.binaryBucket = new byte[20];
  1213. OutgoingInstantMessage(msg, invitedAgentID);
  1214. }
  1215. }
  1216. }
  1217. public List<DirGroupsReplyData> FindGroups(IClientAPI remoteClient, string query)
  1218. {
  1219. return m_groupData.FindGroups(GetRequestingAgentID(remoteClient), query);
  1220. }
  1221. #endregion
  1222. #region Client/Update Tools
  1223. private IClientAPI GetActiveRootClient(UUID agentID)
  1224. {
  1225. foreach (Scene scene in m_sceneList)
  1226. {
  1227. ScenePresence sp = scene.GetScenePresence(agentID);
  1228. if (sp != null && !sp.IsChildAgent && !sp.IsDeleted)
  1229. {
  1230. return sp.ControllingClient;
  1231. }
  1232. }
  1233. return null;
  1234. }
  1235. /// <summary>
  1236. /// Try to find an active IClientAPI reference for agentID giving preference to root connections
  1237. /// </summary>
  1238. private IClientAPI GetActiveClient(UUID agentID)
  1239. {
  1240. IClientAPI child = null;
  1241. // Try root avatar first
  1242. foreach (Scene scene in m_sceneList)
  1243. {
  1244. ScenePresence sp = scene.GetScenePresence(agentID);
  1245. if (sp != null && !sp.IsDeleted)
  1246. {
  1247. if (!sp.IsChildAgent)
  1248. {
  1249. return sp.ControllingClient;
  1250. }
  1251. else
  1252. {
  1253. child = sp.ControllingClient;
  1254. }
  1255. }
  1256. }
  1257. // If we didn't find a root, then just return whichever child we found, or null if none
  1258. return child;
  1259. }
  1260. private void SendScenePresenceUpdate(UUID AgentID, string Title)
  1261. {
  1262. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: Updating scene title for {0} with title: {1}", AgentID, Title);
  1263. ScenePresence presence = null;
  1264. foreach (Scene scene in m_sceneList)
  1265. {
  1266. presence = scene.GetScenePresence(AgentID);
  1267. if (presence != null)
  1268. {
  1269. if (presence.Grouptitle != Title)
  1270. {
  1271. presence.Grouptitle = Title;
  1272. if (! presence.IsChildAgent)
  1273. presence.SendAvatarDataToAllAgents();
  1274. }
  1275. }
  1276. }
  1277. }
  1278. public void SendAgentGroupDataUpdate(IClientAPI remoteClient)
  1279. {
  1280. SendAgentGroupDataUpdate(remoteClient, true);
  1281. }
  1282. /// <summary>
  1283. /// Tell remoteClient about its agent groups, and optionally send title to others
  1284. /// </summary>
  1285. private void SendAgentGroupDataUpdate(IClientAPI remoteClient, bool tellOthers)
  1286. {
  1287. if (m_debugEnabled) m_log.InfoFormat("[GROUPS]: {0} called for {1}", System.Reflection.MethodBase.GetCurrentMethod().Name, remoteClient.Name);
  1288. // NPCs currently don't have a CAPs structure or event queues. There is a strong argument for conveying this information
  1289. // to them anyway since it makes writing server-side bots a lot easier, but for now we don't do anything.
  1290. if (remoteClient.SceneAgent.PresenceType == PresenceType.Npc)
  1291. return;
  1292. // TODO: All the client update functions need to be reexamined because most do too much and send too much stuff
  1293. UUID agentID = GetRequestingAgentID(remoteClient);
  1294. SendDataUpdate(remoteClient, tellOthers);
  1295. GroupMembershipData[] membershipArray = GetProfileListedGroupMemberships(remoteClient, agentID);
  1296. remoteClient.UpdateGroupMembership(membershipArray);
  1297. remoteClient.SendAgentGroupDataUpdate(agentID, membershipArray);
  1298. }
  1299. /// <summary>
  1300. /// Get a list of groups memberships for the agent that are marked "ListInProfile"
  1301. /// (unless that agent has a godLike aspect, in which case get all groups)
  1302. /// </summary>
  1303. /// <param name="dataForAgentID"></param>
  1304. /// <returns></returns>
  1305. private GroupMembershipData[] GetProfileListedGroupMemberships(IClientAPI requestingClient, UUID dataForAgentID)
  1306. {
  1307. List<GroupMembershipData> membershipData = m_groupData.GetAgentGroupMemberships(requestingClient.AgentId, dataForAgentID);
  1308. GroupMembershipData[] membershipArray;
  1309. // cScene and property accessor 'isGod' are in support of the opertions to bypass 'hidden' group attributes for
  1310. // those with a GodLike aspect.
  1311. Scene cScene = (Scene)requestingClient.Scene;
  1312. bool isGod = cScene.Permissions.IsGod(requestingClient.AgentId);
  1313. if (isGod)
  1314. {
  1315. membershipArray = membershipData.ToArray();
  1316. }
  1317. else
  1318. {
  1319. if (requestingClient.AgentId != dataForAgentID)
  1320. {
  1321. Predicate<GroupMembershipData> showInProfile = delegate(GroupMembershipData membership)
  1322. {
  1323. return membership.ListInProfile;
  1324. };
  1325. membershipArray = membershipData.FindAll(showInProfile).ToArray();
  1326. }
  1327. else
  1328. {
  1329. membershipArray = membershipData.ToArray();
  1330. }
  1331. }
  1332. if (m_debugEnabled)
  1333. {
  1334. m_log.InfoFormat("[GROUPS]: Get group membership information for {0} requested by {1}", dataForAgentID, requestingClient.AgentId);
  1335. foreach (GroupMembershipData membership in membershipArray)
  1336. {
  1337. m_log.InfoFormat("[GROUPS]: {0} :: {1} - {2} - {3}", dataForAgentID, membership.GroupName, membership.GroupTitle, membership.GroupPowers);
  1338. }
  1339. }
  1340. return membershipArray;
  1341. }
  1342. //tell remoteClient about its agent group info, and optionally send title to others
  1343. private void SendDataUpdate(IClientAPI remoteClient, bool tellOthers)
  1344. {
  1345. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  1346. UUID activeGroupID = UUID.Zero;
  1347. string activeGroupTitle = string.Empty;
  1348. string activeGroupName = string.Empty;
  1349. ulong activeGroupPowers = (ulong)GroupPowers.None;
  1350. UUID agentID = GetRequestingAgentID(remoteClient);
  1351. GroupMembershipData membership = m_groupData.GetAgentActiveMembership(agentID, agentID);
  1352. if (membership != null)
  1353. {
  1354. activeGroupID = membership.GroupID;
  1355. activeGroupTitle = membership.GroupTitle;
  1356. activeGroupPowers = membership.GroupPowers;
  1357. activeGroupName = membership.GroupName;
  1358. }
  1359. UserAccount account = m_sceneList[0].UserAccountService.GetUserAccount(remoteClient.Scene.RegionInfo.ScopeID, agentID);
  1360. string firstname, lastname;
  1361. if (account != null)
  1362. {
  1363. firstname = account.FirstName;
  1364. lastname = account.LastName;
  1365. }
  1366. else
  1367. {
  1368. firstname = "Unknown";
  1369. lastname = "Unknown";
  1370. }
  1371. remoteClient.SendAgentDataUpdate(agentID, activeGroupID, firstname,
  1372. lastname, activeGroupPowers, activeGroupName,
  1373. activeGroupTitle);
  1374. if (tellOthers)
  1375. SendScenePresenceUpdate(agentID, activeGroupTitle);
  1376. ScenePresence sp = (ScenePresence)remoteClient.SceneAgent;
  1377. if (sp != null)
  1378. sp.Grouptitle = activeGroupTitle;
  1379. }
  1380. #endregion
  1381. #region IM Backed Processes
  1382. private void OutgoingInstantMessage(GridInstantMessage msg, UUID msgTo)
  1383. {
  1384. if (m_debugEnabled) m_log.InfoFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  1385. IClientAPI localClient = GetActiveRootClient(msgTo);
  1386. if (localClient != null)
  1387. {
  1388. if (m_debugEnabled) m_log.InfoFormat("[GROUPS]: MsgTo ({0}) is local, delivering directly", localClient.Name);
  1389. localClient.SendInstantMessage(msg);
  1390. }
  1391. else if (m_msgTransferModule != null)
  1392. {
  1393. if (m_debugEnabled) m_log.InfoFormat("[GROUPS]: MsgTo ({0}) is not local, delivering via TransferModule", msgTo);
  1394. m_msgTransferModule.SendInstantMessage(msg, delegate(bool success) { if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: Message Sent: {0}", success?"Succeeded":"Failed"); });
  1395. }
  1396. }
  1397. public void NotifyChange(UUID groupID)
  1398. {
  1399. // Notify all group members of a chnge in group roles and/or
  1400. // permissions
  1401. //
  1402. }
  1403. #endregion
  1404. private UUID GetRequestingAgentID(IClientAPI client)
  1405. {
  1406. UUID requestingAgentID = UUID.Zero;
  1407. if (client != null)
  1408. {
  1409. requestingAgentID = client.AgentId;
  1410. }
  1411. return requestingAgentID;
  1412. }
  1413. }
  1414. public class GroupNoticeInfo
  1415. {
  1416. public GroupNoticeData noticeData = new GroupNoticeData();
  1417. public UUID GroupID = UUID.Zero;
  1418. public string Message = string.Empty;
  1419. public byte[] BinaryBucket = new byte[0];
  1420. }
  1421. }