1
0

GroupsModule.cs 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715
  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();
  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.IsZero())
  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 = Array.Empty<byte>();
  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.IsZero() && !ownerID.IsZero())
  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.IsZero())
  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.IsZero())
  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. //50 offset gets us to start of attachment name.
  985. bucket = new byte[info.BinaryBucket.Length - 32];
  986. Array.Copy(info.BinaryBucket, 0,
  987. bucket, 0, 18);
  988. Array.Copy(info.BinaryBucket, 50,
  989. bucket, 18, info.BinaryBucket.Length - 50);
  990. }
  991. else
  992. {
  993. bucket = new byte[19];
  994. bucket[0] = 0; //No attachment
  995. bucket[1] = 0; //Attachment type
  996. info.GroupID.ToBytes(bucket, 2);
  997. bucket[18] = 0; //NUL terminate name
  998. }
  999. msg.binaryBucket = bucket;
  1000. }
  1001. else
  1002. {
  1003. if (m_debugEnabled)
  1004. m_log.DebugFormat("[GROUPS]: Group Notice {0} not found, composing empty message.", groupNoticeID);
  1005. msg.fromAgentID = UUID.Zero.Guid;
  1006. msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
  1007. msg.fromAgentName = string.Empty;
  1008. msg.message = string.Empty;
  1009. msg.binaryBucket = Array.Empty<byte>();
  1010. }
  1011. return msg;
  1012. }
  1013. public void JoinGroupRequest(IClientAPI remoteClient, UUID groupID)
  1014. {
  1015. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  1016. // Should check to see if OpenEnrollment, or if there's an outstanding invitation
  1017. m_groupData.AddAgentToGroup(GetRequestingAgentID(remoteClient), GetRequestingAgentID(remoteClient), groupID, UUID.Zero);
  1018. // check funds
  1019. // is there a money module present ?
  1020. GroupRecord groupRecord = m_groupData.GetGroupRecord(GetRequestingAgentID(remoteClient), groupID, null);
  1021. IMoneyModule money = remoteClient.Scene.RequestModuleInterface<IMoneyModule>();
  1022. if (money != null && groupRecord.MembershipFee > 0)
  1023. {
  1024. // do the transaction, that is if the agent has sufficient funds
  1025. if (!money.AmountCovered(GetRequestingAgentID(remoteClient), groupRecord.MembershipFee)) {
  1026. remoteClient.SendCreateGroupReply(UUID.Zero, false, "You have insufficient funds to join the group.");
  1027. return;
  1028. }
  1029. money.ApplyCharge(GetRequestingAgentID(remoteClient), groupRecord.MembershipFee, MoneyTransactionType.GroupJoin, groupRecord.GroupName);
  1030. }
  1031. remoteClient.SendJoinGroupReply(groupID, true);
  1032. SendAgentGroupDataUpdate(remoteClient, true);
  1033. }
  1034. public void LeaveGroupRequest(IClientAPI remoteClient, UUID groupID)
  1035. {
  1036. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  1037. m_groupData.RemoveAgentFromGroup(GetRequestingAgentID(remoteClient), GetRequestingAgentID(remoteClient), groupID);
  1038. remoteClient.SendLeaveGroupReply(groupID, true);
  1039. remoteClient.SendAgentDropGroup(groupID);
  1040. // SL sends out notifcations to the group messaging session that the person has left
  1041. // Should this also update everyone who is in the group?
  1042. SendAgentGroupDataUpdate(remoteClient, true);
  1043. }
  1044. public void EjectGroupMemberRequest(IClientAPI remoteClient, UUID groupID, UUID ejecteeID)
  1045. {
  1046. EjectGroupMember(remoteClient, GetRequestingAgentID(remoteClient), groupID, ejecteeID);
  1047. }
  1048. public void EjectGroupMember(IClientAPI remoteClient, UUID agentID, UUID groupID, UUID ejecteeID)
  1049. {
  1050. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  1051. // Todo: Security check?
  1052. m_groupData.RemoveAgentFromGroup(agentID, ejecteeID, groupID);
  1053. string agentName;
  1054. RegionInfo regionInfo;
  1055. // remoteClient provided or just agentID?
  1056. if (remoteClient != null)
  1057. {
  1058. agentName = remoteClient.Name;
  1059. regionInfo = remoteClient.Scene.RegionInfo;
  1060. remoteClient.SendEjectGroupMemberReply(agentID, groupID, true);
  1061. }
  1062. else
  1063. {
  1064. IClientAPI client = GetActiveClient(agentID);
  1065. if (client != null)
  1066. {
  1067. agentName = client.Name;
  1068. regionInfo = client.Scene.RegionInfo;
  1069. client.SendEjectGroupMemberReply(agentID, groupID, true);
  1070. }
  1071. else
  1072. {
  1073. regionInfo = m_sceneList[0].RegionInfo;
  1074. UserAccount acc = m_sceneList[0].UserAccountService.GetUserAccount(regionInfo.ScopeID, agentID);
  1075. if (acc != null)
  1076. {
  1077. agentName = acc.FirstName + " " + acc.LastName;
  1078. }
  1079. else
  1080. {
  1081. agentName = "Unknown member";
  1082. }
  1083. }
  1084. }
  1085. GroupRecord groupInfo = m_groupData.GetGroupRecord(agentID, groupID, null);
  1086. if (groupInfo == null)
  1087. return;
  1088. IClientAPI ejecteeClient = GetActiveRootClient(ejecteeID);
  1089. // Send Message to Ejectee
  1090. GridInstantMessage msg = new GridInstantMessage();
  1091. string ejecteeName = "Unknown member";
  1092. // if local send a normal message
  1093. if(ejecteeClient != null)
  1094. {
  1095. msg.imSessionID = UUID.Zero.Guid;
  1096. msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.MessageFromAgent;
  1097. // also execute and send update
  1098. ejecteeClient.SendAgentDropGroup(groupID);
  1099. SendAgentGroupDataUpdate(ejecteeClient,true);
  1100. ejecteeName = ejecteeClient.Name;
  1101. }
  1102. else // send
  1103. {
  1104. // Interop, received special 210 code for ejecting a group member
  1105. // this only works within the comms servers domain, and won't work hypergrid
  1106. // TODO:FIXME: Use a presence server of some kind to find out where the
  1107. // client actually is, and try contacting that region directly to notify them,
  1108. // or provide the notification via xmlrpc update queue
  1109. msg.imSessionID = groupInfo.GroupID.Guid;
  1110. msg.dialog = (byte)210; //interop
  1111. UserAccount account = m_sceneList[0].UserAccountService.GetUserAccount(regionInfo.ScopeID, ejecteeID);
  1112. if (account != null)
  1113. ejecteeName = account.FirstName + " " + account.LastName;
  1114. }
  1115. msg.fromAgentID = agentID.Guid;
  1116. // msg.fromAgentID = info.GroupID;
  1117. msg.toAgentID = ejecteeID.Guid;
  1118. //msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
  1119. msg.timestamp = 0;
  1120. msg.fromAgentName = agentName;
  1121. msg.message = string.Format("You have been ejected from '{1}' by {0}.", agentName, groupInfo.GroupName);
  1122. //
  1123. msg.fromGroup = false;
  1124. msg.offline = (byte)0;
  1125. msg.ParentEstateID = 0;
  1126. msg.Position = Vector3.Zero;
  1127. msg.RegionID = regionInfo.RegionID.Guid;
  1128. msg.binaryBucket = Array.Empty<byte>();
  1129. OutgoingInstantMessage(msg, ejecteeID);
  1130. // Message to ejector
  1131. msg = new GridInstantMessage();
  1132. msg.imSessionID = UUID.Zero.Guid;
  1133. msg.fromAgentID = agentID.Guid;
  1134. msg.toAgentID = agentID.Guid;
  1135. msg.timestamp = 0;
  1136. msg.fromAgentName = agentName;
  1137. msg.message = string.Format("{2} has been ejected from '{1}' by {0}.", agentName, groupInfo.GroupName, ejecteeName);
  1138. // msg.dialog = (byte)210; //interop
  1139. msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.MessageFromAgent;
  1140. msg.fromGroup = false;
  1141. msg.offline = (byte)0;
  1142. msg.ParentEstateID = 0;
  1143. msg.Position = Vector3.Zero;
  1144. msg.RegionID = regionInfo.RegionID.Guid;
  1145. msg.binaryBucket = Array.Empty<byte>();
  1146. OutgoingInstantMessage(msg, agentID);
  1147. }
  1148. public void InviteGroupRequest(IClientAPI remoteClient, UUID groupID, UUID invitedAgentID, UUID roleID)
  1149. {
  1150. InviteGroup(remoteClient, GetRequestingAgentID(remoteClient), groupID, invitedAgentID, roleID);
  1151. }
  1152. public void InviteGroup(IClientAPI remoteClient, UUID agentID, UUID groupID, UUID invitedAgentID, UUID roleID)
  1153. {
  1154. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  1155. string agentName;
  1156. RegionInfo regionInfo;
  1157. // remoteClient provided or just agentID?
  1158. if (remoteClient != null)
  1159. {
  1160. agentName = remoteClient.Name;
  1161. regionInfo = remoteClient.Scene.RegionInfo;
  1162. }
  1163. else
  1164. {
  1165. IClientAPI client = GetActiveClient(agentID);
  1166. if (client != null)
  1167. {
  1168. agentName = client.Name;
  1169. regionInfo = client.Scene.RegionInfo;
  1170. }
  1171. else
  1172. {
  1173. regionInfo = m_sceneList[0].RegionInfo;
  1174. UserAccount account = m_sceneList[0].UserAccountService.GetUserAccount(regionInfo.ScopeID, agentID);
  1175. if (account != null)
  1176. {
  1177. agentName = account.FirstName + " " + account.LastName;
  1178. }
  1179. else
  1180. {
  1181. agentName = "Unknown member";
  1182. }
  1183. }
  1184. }
  1185. // Todo: Security check, probably also want to send some kind of notification
  1186. UUID InviteID = UUID.Random();
  1187. m_groupData.AddAgentToGroupInvite(agentID, InviteID, groupID, roleID, invitedAgentID);
  1188. // Check to see if the invite went through, if it did not then it's possible
  1189. // the remoteClient did not validate or did not have permission to invite.
  1190. GroupInviteInfo inviteInfo = m_groupData.GetAgentToGroupInvite(agentID, InviteID);
  1191. if (inviteInfo != null)
  1192. {
  1193. if (m_msgTransferModule != null)
  1194. {
  1195. Guid inviteUUID = InviteID.Guid;
  1196. GridInstantMessage msg = new GridInstantMessage();
  1197. msg.imSessionID = inviteUUID;
  1198. // msg.fromAgentID = agentID.Guid;
  1199. msg.fromAgentID = groupID.Guid;
  1200. msg.toAgentID = invitedAgentID.Guid;
  1201. //msg.timestamp = (uint)Util.UnixTimeSinceEpoch();
  1202. msg.timestamp = 0;
  1203. msg.fromAgentName = agentName;
  1204. msg.message = string.Format("{0} has invited you to join a group. There is no cost to join this group.", agentName);
  1205. msg.dialog = (byte)OpenMetaverse.InstantMessageDialog.GroupInvitation;
  1206. msg.fromGroup = true;
  1207. msg.offline = (byte)0;
  1208. msg.ParentEstateID = 0;
  1209. msg.Position = Vector3.Zero;
  1210. msg.RegionID = regionInfo.RegionID.Guid;
  1211. msg.binaryBucket = new byte[20];
  1212. OutgoingInstantMessage(msg, invitedAgentID);
  1213. }
  1214. }
  1215. }
  1216. public List<DirGroupsReplyData> FindGroups(IClientAPI remoteClient, string query)
  1217. {
  1218. return m_groupData.FindGroups(GetRequestingAgentID(remoteClient), query);
  1219. }
  1220. #endregion
  1221. #region Client/Update Tools
  1222. private IClientAPI GetActiveRootClient(UUID agentID)
  1223. {
  1224. foreach (Scene scene in m_sceneList)
  1225. {
  1226. ScenePresence sp = scene.GetScenePresence(agentID);
  1227. if (sp != null && !sp.IsChildAgent && !sp.IsDeleted)
  1228. {
  1229. return sp.ControllingClient;
  1230. }
  1231. }
  1232. return null;
  1233. }
  1234. /// <summary>
  1235. /// Try to find an active IClientAPI reference for agentID giving preference to root connections
  1236. /// </summary>
  1237. private IClientAPI GetActiveClient(UUID agentID)
  1238. {
  1239. IClientAPI child = null;
  1240. // Try root avatar first
  1241. foreach (Scene scene in m_sceneList)
  1242. {
  1243. ScenePresence sp = scene.GetScenePresence(agentID);
  1244. if (sp != null && !sp.IsDeleted)
  1245. {
  1246. if (!sp.IsChildAgent)
  1247. {
  1248. return sp.ControllingClient;
  1249. }
  1250. else
  1251. {
  1252. child = sp.ControllingClient;
  1253. }
  1254. }
  1255. }
  1256. // If we didn't find a root, then just return whichever child we found, or null if none
  1257. return child;
  1258. }
  1259. private void SendScenePresenceUpdate(UUID AgentID, string Title)
  1260. {
  1261. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: Updating scene title for {0} with title: {1}", AgentID, Title);
  1262. ScenePresence presence = null;
  1263. foreach (Scene scene in m_sceneList)
  1264. {
  1265. presence = scene.GetScenePresence(AgentID);
  1266. if (presence != null)
  1267. {
  1268. if (presence.Grouptitle != Title)
  1269. {
  1270. presence.Grouptitle = Title;
  1271. if (! presence.IsChildAgent)
  1272. presence.SendAvatarDataToAllAgents();
  1273. }
  1274. }
  1275. }
  1276. }
  1277. public void SendAgentGroupDataUpdate(IClientAPI remoteClient)
  1278. {
  1279. SendAgentGroupDataUpdate(remoteClient, true);
  1280. }
  1281. /// <summary>
  1282. /// Tell remoteClient about its agent groups, and optionally send title to others
  1283. /// </summary>
  1284. private void SendAgentGroupDataUpdate(IClientAPI remoteClient, bool tellOthers)
  1285. {
  1286. if (m_debugEnabled) m_log.InfoFormat("[GROUPS]: {0} called for {1}", System.Reflection.MethodBase.GetCurrentMethod().Name, remoteClient.Name);
  1287. // NPCs currently don't have a CAPs structure or event queues. There is a strong argument for conveying this information
  1288. // to them anyway since it makes writing server-side bots a lot easier, but for now we don't do anything.
  1289. if (remoteClient.SceneAgent.PresenceType == PresenceType.Npc)
  1290. return;
  1291. // TODO: All the client update functions need to be reexamined because most do too much and send too much stuff
  1292. UUID agentID = GetRequestingAgentID(remoteClient);
  1293. SendDataUpdate(remoteClient, tellOthers);
  1294. GroupMembershipData[] membershipArray = GetProfileListedGroupMemberships(remoteClient, agentID);
  1295. remoteClient.UpdateGroupMembership(membershipArray);
  1296. remoteClient.SendAgentGroupDataUpdate(agentID, membershipArray);
  1297. }
  1298. /// <summary>
  1299. /// Get a list of groups memberships for the agent that are marked "ListInProfile"
  1300. /// (unless that agent has a godLike aspect, in which case get all groups)
  1301. /// </summary>
  1302. /// <param name="dataForAgentID"></param>
  1303. /// <returns></returns>
  1304. private GroupMembershipData[] GetProfileListedGroupMemberships(IClientAPI requestingClient, UUID dataForAgentID)
  1305. {
  1306. List<GroupMembershipData> membershipData = m_groupData.GetAgentGroupMemberships(requestingClient.AgentId, dataForAgentID);
  1307. GroupMembershipData[] membershipArray;
  1308. // cScene and property accessor 'isGod' are in support of the opertions to bypass 'hidden' group attributes for
  1309. // those with a GodLike aspect.
  1310. Scene cScene = (Scene)requestingClient.Scene;
  1311. bool isGod = cScene.Permissions.IsGod(requestingClient.AgentId);
  1312. if (isGod)
  1313. {
  1314. membershipArray = membershipData.ToArray();
  1315. }
  1316. else
  1317. {
  1318. if (requestingClient.AgentId != dataForAgentID)
  1319. {
  1320. Predicate<GroupMembershipData> showInProfile = delegate(GroupMembershipData membership)
  1321. {
  1322. return membership.ListInProfile;
  1323. };
  1324. membershipArray = membershipData.FindAll(showInProfile).ToArray();
  1325. }
  1326. else
  1327. {
  1328. membershipArray = membershipData.ToArray();
  1329. }
  1330. }
  1331. if (m_debugEnabled)
  1332. {
  1333. m_log.InfoFormat("[GROUPS]: Get group membership information for {0} requested by {1}", dataForAgentID, requestingClient.AgentId);
  1334. foreach (GroupMembershipData membership in membershipArray)
  1335. {
  1336. m_log.InfoFormat("[GROUPS]: {0} :: {1} - {2} - {3}", dataForAgentID, membership.GroupName, membership.GroupTitle, membership.GroupPowers);
  1337. }
  1338. }
  1339. return membershipArray;
  1340. }
  1341. //tell remoteClient about its agent group info, and optionally send title to others
  1342. private void SendDataUpdate(IClientAPI remoteClient, bool tellOthers)
  1343. {
  1344. if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  1345. UUID activeGroupID = UUID.Zero;
  1346. string activeGroupTitle = string.Empty;
  1347. string activeGroupName = string.Empty;
  1348. ulong activeGroupPowers = (ulong)GroupPowers.None;
  1349. UUID agentID = GetRequestingAgentID(remoteClient);
  1350. GroupMembershipData membership = m_groupData.GetAgentActiveMembership(agentID, agentID);
  1351. if (membership != null)
  1352. {
  1353. activeGroupID = membership.GroupID;
  1354. activeGroupTitle = membership.GroupTitle;
  1355. activeGroupPowers = membership.GroupPowers;
  1356. activeGroupName = membership.GroupName;
  1357. }
  1358. UserAccount account = m_sceneList[0].UserAccountService.GetUserAccount(remoteClient.Scene.RegionInfo.ScopeID, agentID);
  1359. string firstname, lastname;
  1360. if (account != null)
  1361. {
  1362. firstname = account.FirstName;
  1363. lastname = account.LastName;
  1364. }
  1365. else
  1366. {
  1367. firstname = "Unknown";
  1368. lastname = "Unknown";
  1369. }
  1370. remoteClient.SendAgentDataUpdate(agentID, activeGroupID, firstname,
  1371. lastname, activeGroupPowers, activeGroupName,
  1372. activeGroupTitle);
  1373. if (tellOthers)
  1374. SendScenePresenceUpdate(agentID, activeGroupTitle);
  1375. ScenePresence sp = (ScenePresence)remoteClient.SceneAgent;
  1376. if (sp != null)
  1377. sp.Grouptitle = activeGroupTitle;
  1378. }
  1379. #endregion
  1380. #region IM Backed Processes
  1381. private void OutgoingInstantMessage(GridInstantMessage msg, UUID msgTo)
  1382. {
  1383. if (m_debugEnabled) m_log.InfoFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name);
  1384. IClientAPI localClient = GetActiveRootClient(msgTo);
  1385. if (localClient != null)
  1386. {
  1387. if (m_debugEnabled) m_log.InfoFormat("[GROUPS]: MsgTo ({0}) is local, delivering directly", localClient.Name);
  1388. localClient.SendInstantMessage(msg);
  1389. }
  1390. else if (m_msgTransferModule != null)
  1391. {
  1392. if (m_debugEnabled) m_log.InfoFormat("[GROUPS]: MsgTo ({0}) is not local, delivering via TransferModule", msgTo);
  1393. m_msgTransferModule.SendInstantMessage(msg, delegate(bool success) { if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: Message Sent: {0}", success?"Succeeded":"Failed"); });
  1394. }
  1395. }
  1396. public void NotifyChange(UUID groupID)
  1397. {
  1398. // Notify all group members of a chnge in group roles and/or
  1399. // permissions
  1400. //
  1401. }
  1402. #endregion
  1403. private UUID GetRequestingAgentID(IClientAPI client)
  1404. {
  1405. return client is null ? UUID.Zero : client.AgentId;
  1406. }
  1407. }
  1408. public class GroupNoticeInfo
  1409. {
  1410. public GroupNoticeData noticeData = new GroupNoticeData();
  1411. public UUID GroupID = UUID.Zero;
  1412. public string Message = string.Empty;
  1413. public byte[] BinaryBucket = new byte[0];
  1414. }
  1415. }