GroupsServiceHGConnectorModule.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Linq;
  30. using System.Reflection;
  31. using System.Text;
  32. using OpenSim.Framework;
  33. using OpenSim.Framework.Monitoring;
  34. using OpenSim.Framework.Servers;
  35. using OpenSim.Region.Framework.Scenes;
  36. using OpenSim.Region.Framework.Interfaces;
  37. using OpenSim.Services.Interfaces;
  38. using OpenMetaverse;
  39. using Mono.Addins;
  40. using log4net;
  41. using Nini.Config;
  42. namespace OpenSim.Groups
  43. {
  44. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GroupsServiceHGConnectorModule")]
  45. public class GroupsServiceHGConnectorModule : ISharedRegionModule, IGroupsServicesConnector
  46. {
  47. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  48. private bool m_Enabled = false;
  49. private IGroupsServicesConnector m_LocalGroupsConnector;
  50. private string m_LocalGroupsServiceLocation;
  51. private IUserManagement m_UserManagement;
  52. private IOfflineIMService m_OfflineIM;
  53. private IMessageTransferModule m_Messaging;
  54. private List<Scene> m_Scenes;
  55. private ForeignImporter m_ForeignImporter;
  56. private string m_ServiceLocation;
  57. private IConfigSource m_Config;
  58. private Dictionary<string, GroupsServiceHGConnector> m_NetworkConnectors = new Dictionary<string, GroupsServiceHGConnector>();
  59. private RemoteConnectorCacheWrapper m_CacheWrapper; // for caching info of external group services
  60. #region ISharedRegionModule
  61. public void Initialise(IConfigSource config)
  62. {
  63. IConfig groupsConfig = config.Configs["Groups"];
  64. if (groupsConfig == null)
  65. return;
  66. if ((groupsConfig.GetBoolean("Enabled", false) == false)
  67. || (groupsConfig.GetString("ServicesConnectorModule", string.Empty) != Name))
  68. {
  69. return;
  70. }
  71. m_Config = config;
  72. m_ServiceLocation = groupsConfig.GetString("LocalService", "local"); // local or remote
  73. m_LocalGroupsServiceLocation = groupsConfig.GetString("GroupsExternalURI", "http://127.0.0.1");
  74. m_Scenes = new List<Scene>();
  75. m_Enabled = true;
  76. m_log.DebugFormat("[Groups]: Initializing {0} with LocalService {1}", this.Name, m_ServiceLocation);
  77. }
  78. public string Name
  79. {
  80. get { return "Groups HG Service Connector"; }
  81. }
  82. public Type ReplaceableInterface
  83. {
  84. get { return null; }
  85. }
  86. public void AddRegion(Scene scene)
  87. {
  88. if (!m_Enabled)
  89. return;
  90. m_log.DebugFormat("[Groups]: Registering {0} with {1}", this.Name, scene.RegionInfo.RegionName);
  91. scene.RegisterModuleInterface<IGroupsServicesConnector>(this);
  92. m_Scenes.Add(scene);
  93. scene.EventManager.OnNewClient += OnNewClient;
  94. }
  95. public void RemoveRegion(Scene scene)
  96. {
  97. if (!m_Enabled)
  98. return;
  99. scene.UnregisterModuleInterface<IGroupsServicesConnector>(this);
  100. m_Scenes.Remove(scene);
  101. }
  102. public void RegionLoaded(Scene scene)
  103. {
  104. if (!m_Enabled)
  105. return;
  106. if (m_UserManagement == null)
  107. {
  108. m_UserManagement = scene.RequestModuleInterface<IUserManagement>();
  109. m_OfflineIM = scene.RequestModuleInterface<IOfflineIMService>();
  110. m_Messaging = scene.RequestModuleInterface<IMessageTransferModule>();
  111. m_ForeignImporter = new ForeignImporter(m_UserManagement);
  112. if (m_ServiceLocation.Equals("local"))
  113. {
  114. m_LocalGroupsConnector = new GroupsServiceLocalConnectorModule(m_Config, m_UserManagement);
  115. // Also, if local, create the endpoint for the HGGroupsService
  116. new HGGroupsServiceRobustConnector(m_Config, MainServer.Instance, string.Empty,
  117. scene.RequestModuleInterface<IOfflineIMService>(), scene.RequestModuleInterface<IUserAccountService>());
  118. }
  119. else
  120. m_LocalGroupsConnector = new GroupsServiceRemoteConnectorModule(m_Config, m_UserManagement);
  121. m_CacheWrapper = new RemoteConnectorCacheWrapper(m_UserManagement);
  122. }
  123. }
  124. public void PostInitialise()
  125. {
  126. }
  127. public void Close()
  128. {
  129. }
  130. #endregion
  131. private void OnNewClient(IClientAPI client)
  132. {
  133. client.OnCompleteMovementToRegion += OnCompleteMovementToRegion;
  134. }
  135. void OnCompleteMovementToRegion(IClientAPI client, bool arg2)
  136. {
  137. if (client.SceneAgent is ScenePresence sp)
  138. {
  139. if (sp.PresenceType != PresenceType.Npc)
  140. {
  141. AgentCircuitData aCircuit = sp.Scene.AuthenticateHandler.GetAgentCircuitData(client.AgentId);
  142. if (aCircuit != null && (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0 &&
  143. m_OfflineIM != null && m_Messaging != null)
  144. {
  145. List<GridInstantMessage> ims = m_OfflineIM.GetMessages(aCircuit.AgentID);
  146. if (ims != null && ims.Count > 0)
  147. foreach (GridInstantMessage im in ims)
  148. m_Messaging.SendInstantMessage(im, delegate(bool success) { });
  149. }
  150. }
  151. }
  152. }
  153. #region IGroupsServicesConnector
  154. public UUID CreateGroup(UUID RequestingAgentID, string name, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment,
  155. bool allowPublish, bool maturePublish, UUID founderID, out string reason)
  156. {
  157. reason = string.Empty;
  158. if (m_UserManagement.IsLocalGridUser(RequestingAgentID))
  159. return m_LocalGroupsConnector.CreateGroup(RequestingAgentID, name, charter, showInList, insigniaID,
  160. membershipFee, openEnrollment, allowPublish, maturePublish, founderID, out reason);
  161. else
  162. {
  163. reason = "Only local grid users are allowed to create a new group";
  164. return UUID.Zero;
  165. }
  166. }
  167. public bool UpdateGroup(string RequestingAgentID, UUID groupID, string charter, bool showInList, UUID insigniaID, int membershipFee,
  168. bool openEnrollment, bool allowPublish, bool maturePublish, out string reason)
  169. {
  170. reason = string.Empty;
  171. string url = string.Empty;
  172. string name = string.Empty;
  173. if (IsLocal(groupID, out url, out name))
  174. return m_LocalGroupsConnector.UpdateGroup(AgentUUI(RequestingAgentID), groupID, charter, showInList, insigniaID, membershipFee,
  175. openEnrollment, allowPublish, maturePublish, out reason);
  176. else
  177. {
  178. reason = "Changes to remote group not allowed. Please go to the group's original world.";
  179. return false;
  180. }
  181. }
  182. public ExtendedGroupRecord GetGroupRecord(string RequestingAgentID, UUID GroupID, string GroupName)
  183. {
  184. string url = string.Empty;
  185. string name = string.Empty;
  186. if (IsLocal(GroupID, out url, out name))
  187. return m_LocalGroupsConnector.GetGroupRecord(AgentUUI(RequestingAgentID), GroupID, GroupName);
  188. else if (url != string.Empty)
  189. {
  190. ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(RequestingAgentID, RequestingAgentID, GroupID);
  191. string accessToken = string.Empty;
  192. if (membership != null)
  193. accessToken = membership.AccessToken;
  194. else
  195. return null;
  196. GroupsServiceHGConnector c = GetConnector(url);
  197. if (c != null)
  198. {
  199. ExtendedGroupRecord grec = m_CacheWrapper.GetGroupRecord(RequestingAgentID, GroupID, GroupName, delegate
  200. {
  201. return c.GetGroupRecord(AgentUUIForOutside(RequestingAgentID), GroupID, GroupName, accessToken);
  202. });
  203. if (grec != null)
  204. ImportForeigner(grec.FounderUUI);
  205. return grec;
  206. }
  207. }
  208. return null;
  209. }
  210. public List<DirGroupsReplyData> FindGroups(string RequestingAgentIDstr, string search)
  211. {
  212. return m_LocalGroupsConnector.FindGroups(RequestingAgentIDstr, search);
  213. }
  214. public List<GroupMembersData> GetGroupMembers(string RequestingAgentID, UUID GroupID)
  215. {
  216. string url = string.Empty, gname = string.Empty;
  217. if (IsLocal(GroupID, out url, out gname))
  218. {
  219. string agentID = AgentUUI(RequestingAgentID);
  220. return m_LocalGroupsConnector.GetGroupMembers(agentID, GroupID);
  221. }
  222. else if (!string.IsNullOrEmpty(url))
  223. {
  224. ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(RequestingAgentID, RequestingAgentID, GroupID);
  225. string accessToken = string.Empty;
  226. if (membership != null)
  227. accessToken = membership.AccessToken;
  228. else
  229. return null;
  230. GroupsServiceHGConnector c = GetConnector(url);
  231. if (c != null)
  232. {
  233. return m_CacheWrapper.GetGroupMembers(RequestingAgentID, GroupID, delegate
  234. {
  235. return c.GetGroupMembers(AgentUUIForOutside(RequestingAgentID), GroupID, accessToken);
  236. });
  237. }
  238. }
  239. return new List<GroupMembersData>();
  240. }
  241. public bool AddGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers, out string reason)
  242. {
  243. reason = string.Empty;
  244. string url = string.Empty, gname = string.Empty;
  245. if (IsLocal(groupID, out url, out gname))
  246. return m_LocalGroupsConnector.AddGroupRole(AgentUUI(RequestingAgentID), groupID, roleID, name, description, title, powers, out reason);
  247. else
  248. {
  249. reason = "Operation not allowed outside this group's origin world.";
  250. return false;
  251. }
  252. }
  253. public bool UpdateGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers)
  254. {
  255. string url = string.Empty, gname = string.Empty;
  256. if (IsLocal(groupID, out url, out gname))
  257. return m_LocalGroupsConnector.UpdateGroupRole(AgentUUI(RequestingAgentID), groupID, roleID, name, description, title, powers);
  258. else
  259. {
  260. return false;
  261. }
  262. }
  263. public void RemoveGroupRole(string RequestingAgentID, UUID groupID, UUID roleID)
  264. {
  265. string url = string.Empty, gname = string.Empty;
  266. if (IsLocal(groupID, out url, out gname))
  267. m_LocalGroupsConnector.RemoveGroupRole(AgentUUI(RequestingAgentID), groupID, roleID);
  268. else
  269. {
  270. return;
  271. }
  272. }
  273. public List<GroupRolesData> GetGroupRoles(string RequestingAgentID, UUID groupID)
  274. {
  275. string url = string.Empty, gname = string.Empty;
  276. if (IsLocal(groupID, out url, out gname))
  277. return m_LocalGroupsConnector.GetGroupRoles(AgentUUI(RequestingAgentID), groupID);
  278. else if (!string.IsNullOrEmpty(url))
  279. {
  280. ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(RequestingAgentID, RequestingAgentID, groupID);
  281. string accessToken = string.Empty;
  282. if (membership != null)
  283. accessToken = membership.AccessToken;
  284. else
  285. return null;
  286. GroupsServiceHGConnector c = GetConnector(url);
  287. if (c != null)
  288. {
  289. return m_CacheWrapper.GetGroupRoles(RequestingAgentID, groupID, delegate
  290. {
  291. return c.GetGroupRoles(AgentUUIForOutside(RequestingAgentID), groupID, accessToken);
  292. });
  293. }
  294. }
  295. return new List<GroupRolesData>();
  296. }
  297. public List<GroupRoleMembersData> GetGroupRoleMembers(string RequestingAgentID, UUID groupID)
  298. {
  299. string url = string.Empty, gname = string.Empty;
  300. if (IsLocal(groupID, out url, out gname))
  301. return m_LocalGroupsConnector.GetGroupRoleMembers(AgentUUI(RequestingAgentID), groupID);
  302. else if (!string.IsNullOrEmpty(url))
  303. {
  304. ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(RequestingAgentID, RequestingAgentID, groupID);
  305. string accessToken = string.Empty;
  306. if (membership != null)
  307. accessToken = membership.AccessToken;
  308. else
  309. return null;
  310. GroupsServiceHGConnector c = GetConnector(url);
  311. if (c != null)
  312. {
  313. return m_CacheWrapper.GetGroupRoleMembers(RequestingAgentID, groupID, delegate
  314. {
  315. return c.GetGroupRoleMembers(AgentUUIForOutside(RequestingAgentID), groupID, accessToken);
  316. });
  317. }
  318. }
  319. return new List<GroupRoleMembersData>();
  320. }
  321. public bool AddAgentToGroup(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID, string token, out string reason)
  322. {
  323. string url = string.Empty;
  324. string name = string.Empty;
  325. reason = string.Empty;
  326. UUID uid = new UUID(AgentID);
  327. if (IsLocal(GroupID, out url, out name))
  328. {
  329. if (m_UserManagement.IsLocalGridUser(uid)) // local user
  330. {
  331. // normal case: local group, local user
  332. return m_LocalGroupsConnector.AddAgentToGroup(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID, token, out reason);
  333. }
  334. else // local group, foreign user
  335. {
  336. // the user is accepting the invitation, or joining, where the group resides
  337. token = UUID.Random().ToString();
  338. bool success = m_LocalGroupsConnector.AddAgentToGroup(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID, token, out reason);
  339. if (success)
  340. {
  341. // Here we always return true. The user has been added to the local group,
  342. // independent of whether the remote operation succeeds or not
  343. url = m_UserManagement.GetUserServerURL(uid, "GroupsServerURI");
  344. if (url.Length == 0)
  345. {
  346. reason = "You don't have an accessible groups server in your home world. You membership to this group in only within this grid.";
  347. return true;
  348. }
  349. GroupsServiceHGConnector c = GetConnector(url);
  350. if (c != null)
  351. c.CreateProxy(AgentUUI(RequestingAgentID), AgentID, token, GroupID, m_LocalGroupsServiceLocation, name, out reason);
  352. return true;
  353. }
  354. return false;
  355. }
  356. }
  357. else if (m_UserManagement.IsLocalGridUser(uid)) // local user
  358. {
  359. // foreign group, local user. She's been added already by the HG service.
  360. // Let's just check
  361. if (m_LocalGroupsConnector.GetAgentGroupMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID) != null)
  362. return true;
  363. }
  364. reason = "Operation not allowed outside this group's origin world";
  365. return false;
  366. }
  367. public void RemoveAgentFromGroup(string RequestingAgentID, string AgentID, UUID GroupID)
  368. {
  369. string url = string.Empty, name = string.Empty;
  370. if (!IsLocal(GroupID, out url, out name) && url != string.Empty)
  371. {
  372. ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID);
  373. if (membership != null)
  374. {
  375. GroupsServiceHGConnector c = GetConnector(url);
  376. if (c != null)
  377. c.RemoveAgentFromGroup(AgentUUIForOutside(AgentID), GroupID, membership.AccessToken);
  378. }
  379. }
  380. // remove from local service
  381. m_LocalGroupsConnector.RemoveAgentFromGroup(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID);
  382. }
  383. public bool AddAgentToGroupInvite(string RequestingAgentID, UUID inviteID, UUID groupID, UUID roleID, string agentID)
  384. {
  385. string url = string.Empty, gname = string.Empty;
  386. if (IsLocal(groupID, out url, out gname))
  387. return m_LocalGroupsConnector.AddAgentToGroupInvite(AgentUUI(RequestingAgentID), inviteID, groupID, roleID, AgentUUI(agentID));
  388. else
  389. return false;
  390. }
  391. public GroupInviteInfo GetAgentToGroupInvite(string RequestingAgentID, UUID inviteID)
  392. {
  393. return m_LocalGroupsConnector.GetAgentToGroupInvite(AgentUUI(RequestingAgentID), inviteID);
  394. }
  395. public void RemoveAgentToGroupInvite(string RequestingAgentID, UUID inviteID)
  396. {
  397. m_LocalGroupsConnector.RemoveAgentToGroupInvite(AgentUUI(RequestingAgentID), inviteID);
  398. }
  399. public void AddAgentToGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
  400. {
  401. string url = string.Empty, gname = string.Empty;
  402. if (IsLocal(GroupID, out url, out gname))
  403. m_LocalGroupsConnector.AddAgentToGroupRole(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID);
  404. }
  405. public void RemoveAgentFromGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
  406. {
  407. string url = string.Empty, gname = string.Empty;
  408. if (IsLocal(GroupID, out url, out gname))
  409. m_LocalGroupsConnector.RemoveAgentFromGroupRole(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID);
  410. }
  411. public List<GroupRolesData> GetAgentGroupRoles(string RequestingAgentID, string AgentID, UUID GroupID)
  412. {
  413. string url = string.Empty, gname = string.Empty;
  414. if (IsLocal(GroupID, out url, out gname))
  415. return m_LocalGroupsConnector.GetAgentGroupRoles(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID);
  416. else
  417. return new List<GroupRolesData>();
  418. }
  419. public void SetAgentActiveGroup(string RequestingAgentID, string AgentID, UUID GroupID)
  420. {
  421. string url = string.Empty, gname = string.Empty;
  422. if (IsLocal(GroupID, out url, out gname))
  423. m_LocalGroupsConnector.SetAgentActiveGroup(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID);
  424. }
  425. public ExtendedGroupMembershipData GetAgentActiveMembership(string RequestingAgentID, string AgentID)
  426. {
  427. return m_LocalGroupsConnector.GetAgentActiveMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID));
  428. }
  429. public void SetAgentActiveGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
  430. {
  431. string url = string.Empty, gname = string.Empty;
  432. if (IsLocal(GroupID, out url, out gname))
  433. m_LocalGroupsConnector.SetAgentActiveGroupRole(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID);
  434. }
  435. public void UpdateMembership(string RequestingAgentID, string AgentID, UUID GroupID, bool AcceptNotices, bool ListInProfile)
  436. {
  437. m_LocalGroupsConnector.UpdateMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, AcceptNotices, ListInProfile);
  438. }
  439. public ExtendedGroupMembershipData GetAgentGroupMembership(string RequestingAgentID, string AgentID, UUID GroupID)
  440. {
  441. string url = string.Empty, gname = string.Empty;
  442. if (IsLocal(GroupID, out url, out gname))
  443. return m_LocalGroupsConnector.GetAgentGroupMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID);
  444. else
  445. return null;
  446. }
  447. public List<GroupMembershipData> GetAgentGroupMemberships(string RequestingAgentID, string AgentID)
  448. {
  449. return m_LocalGroupsConnector.GetAgentGroupMemberships(AgentUUI(RequestingAgentID), AgentUUI(AgentID));
  450. }
  451. public bool AddGroupNotice(string RequestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject, string message,
  452. bool hasAttachment, byte attType, string attName, UUID attItemID, string attOwnerID)
  453. {
  454. string url = string.Empty, gname = string.Empty;
  455. if (IsLocal(groupID, out url, out gname))
  456. {
  457. if (m_LocalGroupsConnector.AddGroupNotice(AgentUUI(RequestingAgentID), groupID, noticeID, fromName, subject, message,
  458. hasAttachment, attType, attName, attItemID, AgentUUI(attOwnerID)))
  459. {
  460. // then send the notice to every grid for which there are members in this group
  461. List<GroupMembersData> members = m_LocalGroupsConnector.GetGroupMembers(AgentUUI(RequestingAgentID), groupID);
  462. List<string> urls = new List<string>();
  463. foreach (GroupMembersData m in members)
  464. {
  465. if (!m_UserManagement.IsLocalGridUser(m.AgentID))
  466. {
  467. string gURL = m_UserManagement.GetUserServerURL(m.AgentID, "GroupsServerURI");
  468. if (!urls.Contains(gURL))
  469. urls.Add(gURL);
  470. }
  471. }
  472. // so we have the list of urls to send the notice to
  473. // this may take a long time...
  474. WorkManager.RunInThread(delegate
  475. {
  476. foreach (string u in urls)
  477. {
  478. GroupsServiceHGConnector c = GetConnector(u);
  479. if (c != null)
  480. {
  481. c.AddNotice(AgentUUIForOutside(RequestingAgentID), groupID, noticeID, fromName, subject, message,
  482. hasAttachment, attType, attName, attItemID, AgentUUIForOutside(attOwnerID));
  483. }
  484. }
  485. }, null, string.Format("AddGroupNotice (agent {0}, group {1})", RequestingAgentID, groupID));
  486. return true;
  487. }
  488. return false;
  489. }
  490. else
  491. return false;
  492. }
  493. public GroupNoticeInfo GetGroupNotice(string RequestingAgentID, UUID noticeID)
  494. {
  495. GroupNoticeInfo notice = m_LocalGroupsConnector.GetGroupNotice(AgentUUI(RequestingAgentID), noticeID);
  496. if (notice != null && notice.noticeData.HasAttachment && notice.noticeData.AttachmentOwnerID != null)
  497. ImportForeigner(notice.noticeData.AttachmentOwnerID);
  498. return notice;
  499. }
  500. public List<ExtendedGroupNoticeData> GetGroupNotices(string RequestingAgentID, UUID GroupID)
  501. {
  502. return m_LocalGroupsConnector.GetGroupNotices(AgentUUI(RequestingAgentID), GroupID);
  503. }
  504. #endregion
  505. #region hypergrid groups
  506. private string AgentUUI(string AgentIDStr)
  507. {
  508. UUID AgentID = UUID.Zero;
  509. if (!UUID.TryParse(AgentIDStr, out AgentID) || AgentID.IsZero())
  510. return UUID.Zero.ToString();
  511. if (m_UserManagement.IsLocalGridUser(AgentID))
  512. return AgentID.ToString();
  513. AgentCircuitData agent = null;
  514. foreach (Scene scene in m_Scenes)
  515. {
  516. agent = scene.AuthenticateHandler.GetAgentCircuitData(AgentID);
  517. if (agent != null)
  518. break;
  519. }
  520. if (agent != null)
  521. return Util.ProduceUserUniversalIdentifier(agent);
  522. // we don't know anything about this foreign user
  523. // try asking the user management module, which may know more
  524. return m_UserManagement.GetUserUUI(AgentID);
  525. }
  526. private string AgentUUIForOutside(string AgentIDStr)
  527. {
  528. UUID AgentID = UUID.Zero;
  529. if (!UUID.TryParse(AgentIDStr, out AgentID) || AgentID.IsZero())
  530. return UUID.ZeroString;
  531. AgentCircuitData agent = null;
  532. foreach (Scene scene in m_Scenes)
  533. {
  534. agent = scene.AuthenticateHandler.GetAgentCircuitData(AgentID);
  535. if (agent != null)
  536. break;
  537. }
  538. if (agent == null) // oops
  539. return AgentID.ToString();
  540. return Util.ProduceUserUniversalIdentifier(agent);
  541. }
  542. private UUID ImportForeigner(string uID)
  543. {
  544. UUID userID = UUID.Zero;
  545. string url = string.Empty, first = string.Empty, last = string.Empty, tmp = string.Empty;
  546. if (Util.ParseUniversalUserIdentifier(uID, out userID, out url, out first, out last, out tmp))
  547. m_UserManagement.AddUser(userID, first, last, url);
  548. return userID;
  549. }
  550. private bool IsLocal(UUID groupID, out string serviceLocation, out string name)
  551. {
  552. serviceLocation = string.Empty;
  553. name = string.Empty;
  554. if (groupID.Equals(UUID.Zero))
  555. return true;
  556. ExtendedGroupRecord group = m_LocalGroupsConnector.GetGroupRecord(UUID.Zero.ToString(), groupID, string.Empty);
  557. if (group == null)
  558. {
  559. //m_log.DebugFormat("[XXX]: IsLocal? group {0} not found -- no.", groupID);
  560. return false;
  561. }
  562. serviceLocation = group.ServiceLocation;
  563. name = group.GroupName;
  564. bool isLocal = (group.ServiceLocation.Length == 0);
  565. //m_log.DebugFormat("[XXX]: IsLocal? {0}", isLocal);
  566. return isLocal;
  567. }
  568. private GroupsServiceHGConnector GetConnector(string url)
  569. {
  570. lock (m_NetworkConnectors)
  571. {
  572. if (m_NetworkConnectors.ContainsKey(url))
  573. return m_NetworkConnectors[url];
  574. GroupsServiceHGConnector c = new GroupsServiceHGConnector(url);
  575. m_NetworkConnectors[url] = c;
  576. }
  577. return m_NetworkConnectors[url];
  578. }
  579. #endregion
  580. }
  581. }