GroupsServiceHGConnectorModule.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  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. object sp = null;
  138. if (client.Scene.TryGetScenePresence(client.AgentId, out sp))
  139. {
  140. if (sp is ScenePresence && ((ScenePresence)sp).PresenceType != PresenceType.Npc)
  141. {
  142. AgentCircuitData aCircuit = ((ScenePresence)sp).Scene.AuthenticateHandler.GetAgentCircuitData(client.AgentId);
  143. if (aCircuit != null && (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0 &&
  144. m_OfflineIM != null && m_Messaging != null)
  145. {
  146. List<GridInstantMessage> ims = m_OfflineIM.GetMessages(aCircuit.AgentID);
  147. if (ims != null && ims.Count > 0)
  148. foreach (GridInstantMessage im in ims)
  149. m_Messaging.SendInstantMessage(im, delegate(bool success) { });
  150. }
  151. }
  152. }
  153. }
  154. #region IGroupsServicesConnector
  155. public UUID CreateGroup(UUID RequestingAgentID, string name, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment,
  156. bool allowPublish, bool maturePublish, UUID founderID, out string reason)
  157. {
  158. reason = string.Empty;
  159. if (m_UserManagement.IsLocalGridUser(RequestingAgentID))
  160. return m_LocalGroupsConnector.CreateGroup(RequestingAgentID, name, charter, showInList, insigniaID,
  161. membershipFee, openEnrollment, allowPublish, maturePublish, founderID, out reason);
  162. else
  163. {
  164. reason = "Only local grid users are allowed to create a new group";
  165. return UUID.Zero;
  166. }
  167. }
  168. public bool UpdateGroup(string RequestingAgentID, UUID groupID, string charter, bool showInList, UUID insigniaID, int membershipFee,
  169. bool openEnrollment, bool allowPublish, bool maturePublish, out string reason)
  170. {
  171. reason = string.Empty;
  172. string url = string.Empty;
  173. string name = string.Empty;
  174. if (IsLocal(groupID, out url, out name))
  175. return m_LocalGroupsConnector.UpdateGroup(AgentUUI(RequestingAgentID), groupID, charter, showInList, insigniaID, membershipFee,
  176. openEnrollment, allowPublish, maturePublish, out reason);
  177. else
  178. {
  179. reason = "Changes to remote group not allowed. Please go to the group's original world.";
  180. return false;
  181. }
  182. }
  183. public ExtendedGroupRecord GetGroupRecord(string RequestingAgentID, UUID GroupID, string GroupName)
  184. {
  185. string url = string.Empty;
  186. string name = string.Empty;
  187. if (IsLocal(GroupID, out url, out name))
  188. return m_LocalGroupsConnector.GetGroupRecord(AgentUUI(RequestingAgentID), GroupID, GroupName);
  189. else if (url != string.Empty)
  190. {
  191. ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(RequestingAgentID, RequestingAgentID, GroupID);
  192. string accessToken = string.Empty;
  193. if (membership != null)
  194. accessToken = membership.AccessToken;
  195. else
  196. return null;
  197. GroupsServiceHGConnector c = GetConnector(url);
  198. if (c != null)
  199. {
  200. ExtendedGroupRecord grec = m_CacheWrapper.GetGroupRecord(RequestingAgentID, GroupID, GroupName, delegate
  201. {
  202. return c.GetGroupRecord(AgentUUIForOutside(RequestingAgentID), GroupID, GroupName, accessToken);
  203. });
  204. if (grec != null)
  205. ImportForeigner(grec.FounderUUI);
  206. return grec;
  207. }
  208. }
  209. return null;
  210. }
  211. public List<DirGroupsReplyData> FindGroups(string RequestingAgentIDstr, string search)
  212. {
  213. return m_LocalGroupsConnector.FindGroups(RequestingAgentIDstr, search);
  214. }
  215. public List<GroupMembersData> GetGroupMembers(string RequestingAgentID, UUID GroupID)
  216. {
  217. string url = string.Empty, gname = string.Empty;
  218. if (IsLocal(GroupID, out url, out gname))
  219. {
  220. string agentID = AgentUUI(RequestingAgentID);
  221. return m_LocalGroupsConnector.GetGroupMembers(agentID, GroupID);
  222. }
  223. else if (!string.IsNullOrEmpty(url))
  224. {
  225. ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(RequestingAgentID, RequestingAgentID, GroupID);
  226. string accessToken = string.Empty;
  227. if (membership != null)
  228. accessToken = membership.AccessToken;
  229. else
  230. return null;
  231. GroupsServiceHGConnector c = GetConnector(url);
  232. if (c != null)
  233. {
  234. return m_CacheWrapper.GetGroupMembers(RequestingAgentID, GroupID, delegate
  235. {
  236. return c.GetGroupMembers(AgentUUIForOutside(RequestingAgentID), GroupID, accessToken);
  237. });
  238. }
  239. }
  240. return new List<GroupMembersData>();
  241. }
  242. public bool AddGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers, out string reason)
  243. {
  244. reason = string.Empty;
  245. string url = string.Empty, gname = string.Empty;
  246. if (IsLocal(groupID, out url, out gname))
  247. return m_LocalGroupsConnector.AddGroupRole(AgentUUI(RequestingAgentID), groupID, roleID, name, description, title, powers, out reason);
  248. else
  249. {
  250. reason = "Operation not allowed outside this group's origin world.";
  251. return false;
  252. }
  253. }
  254. public bool UpdateGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers)
  255. {
  256. string url = string.Empty, gname = string.Empty;
  257. if (IsLocal(groupID, out url, out gname))
  258. return m_LocalGroupsConnector.UpdateGroupRole(AgentUUI(RequestingAgentID), groupID, roleID, name, description, title, powers);
  259. else
  260. {
  261. return false;
  262. }
  263. }
  264. public void RemoveGroupRole(string RequestingAgentID, UUID groupID, UUID roleID)
  265. {
  266. string url = string.Empty, gname = string.Empty;
  267. if (IsLocal(groupID, out url, out gname))
  268. m_LocalGroupsConnector.RemoveGroupRole(AgentUUI(RequestingAgentID), groupID, roleID);
  269. else
  270. {
  271. return;
  272. }
  273. }
  274. public List<GroupRolesData> GetGroupRoles(string RequestingAgentID, UUID groupID)
  275. {
  276. string url = string.Empty, gname = string.Empty;
  277. if (IsLocal(groupID, out url, out gname))
  278. return m_LocalGroupsConnector.GetGroupRoles(AgentUUI(RequestingAgentID), groupID);
  279. else if (!string.IsNullOrEmpty(url))
  280. {
  281. ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(RequestingAgentID, RequestingAgentID, groupID);
  282. string accessToken = string.Empty;
  283. if (membership != null)
  284. accessToken = membership.AccessToken;
  285. else
  286. return null;
  287. GroupsServiceHGConnector c = GetConnector(url);
  288. if (c != null)
  289. {
  290. return m_CacheWrapper.GetGroupRoles(RequestingAgentID, groupID, delegate
  291. {
  292. return c.GetGroupRoles(AgentUUIForOutside(RequestingAgentID), groupID, accessToken);
  293. });
  294. }
  295. }
  296. return new List<GroupRolesData>();
  297. }
  298. public List<GroupRoleMembersData> GetGroupRoleMembers(string RequestingAgentID, UUID groupID)
  299. {
  300. string url = string.Empty, gname = string.Empty;
  301. if (IsLocal(groupID, out url, out gname))
  302. return m_LocalGroupsConnector.GetGroupRoleMembers(AgentUUI(RequestingAgentID), groupID);
  303. else if (!string.IsNullOrEmpty(url))
  304. {
  305. ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(RequestingAgentID, RequestingAgentID, groupID);
  306. string accessToken = string.Empty;
  307. if (membership != null)
  308. accessToken = membership.AccessToken;
  309. else
  310. return null;
  311. GroupsServiceHGConnector c = GetConnector(url);
  312. if (c != null)
  313. {
  314. return m_CacheWrapper.GetGroupRoleMembers(RequestingAgentID, groupID, delegate
  315. {
  316. return c.GetGroupRoleMembers(AgentUUIForOutside(RequestingAgentID), groupID, accessToken);
  317. });
  318. }
  319. }
  320. return new List<GroupRoleMembersData>();
  321. }
  322. public bool AddAgentToGroup(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID, string token, out string reason)
  323. {
  324. string url = string.Empty;
  325. string name = string.Empty;
  326. reason = string.Empty;
  327. UUID uid = new UUID(AgentID);
  328. if (IsLocal(GroupID, out url, out name))
  329. {
  330. if (m_UserManagement.IsLocalGridUser(uid)) // local user
  331. {
  332. // normal case: local group, local user
  333. return m_LocalGroupsConnector.AddAgentToGroup(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID, token, out reason);
  334. }
  335. else // local group, foreign user
  336. {
  337. // the user is accepting the invitation, or joining, where the group resides
  338. token = UUID.Random().ToString();
  339. bool success = m_LocalGroupsConnector.AddAgentToGroup(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID, token, out reason);
  340. if (success)
  341. {
  342. // Here we always return true. The user has been added to the local group,
  343. // independent of whether the remote operation succeeds or not
  344. url = m_UserManagement.GetUserServerURL(uid, "GroupsServerURI");
  345. if (url == string.Empty)
  346. {
  347. reason = "You don't have an accessible groups server in your home world. You membership to this group in only within this grid.";
  348. return true;
  349. }
  350. GroupsServiceHGConnector c = GetConnector(url);
  351. if (c != null)
  352. c.CreateProxy(AgentUUI(RequestingAgentID), AgentID, token, GroupID, m_LocalGroupsServiceLocation, name, out reason);
  353. return true;
  354. }
  355. return false;
  356. }
  357. }
  358. else if (m_UserManagement.IsLocalGridUser(uid)) // local user
  359. {
  360. // foreign group, local user. She's been added already by the HG service.
  361. // Let's just check
  362. if (m_LocalGroupsConnector.GetAgentGroupMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID) != null)
  363. return true;
  364. }
  365. reason = "Operation not allowed outside this group's origin world";
  366. return false;
  367. }
  368. public void RemoveAgentFromGroup(string RequestingAgentID, string AgentID, UUID GroupID)
  369. {
  370. string url = string.Empty, name = string.Empty;
  371. if (!IsLocal(GroupID, out url, out name) && url != string.Empty)
  372. {
  373. ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID);
  374. if (membership != null)
  375. {
  376. GroupsServiceHGConnector c = GetConnector(url);
  377. if (c != null)
  378. c.RemoveAgentFromGroup(AgentUUIForOutside(AgentID), GroupID, membership.AccessToken);
  379. }
  380. }
  381. // remove from local service
  382. m_LocalGroupsConnector.RemoveAgentFromGroup(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID);
  383. }
  384. public bool AddAgentToGroupInvite(string RequestingAgentID, UUID inviteID, UUID groupID, UUID roleID, string agentID)
  385. {
  386. string url = string.Empty, gname = string.Empty;
  387. if (IsLocal(groupID, out url, out gname))
  388. return m_LocalGroupsConnector.AddAgentToGroupInvite(AgentUUI(RequestingAgentID), inviteID, groupID, roleID, AgentUUI(agentID));
  389. else
  390. return false;
  391. }
  392. public GroupInviteInfo GetAgentToGroupInvite(string RequestingAgentID, UUID inviteID)
  393. {
  394. return m_LocalGroupsConnector.GetAgentToGroupInvite(AgentUUI(RequestingAgentID), inviteID); ;
  395. }
  396. public void RemoveAgentToGroupInvite(string RequestingAgentID, UUID inviteID)
  397. {
  398. m_LocalGroupsConnector.RemoveAgentToGroupInvite(AgentUUI(RequestingAgentID), inviteID);
  399. }
  400. public void AddAgentToGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
  401. {
  402. string url = string.Empty, gname = string.Empty;
  403. if (IsLocal(GroupID, out url, out gname))
  404. m_LocalGroupsConnector.AddAgentToGroupRole(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID);
  405. }
  406. public void RemoveAgentFromGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
  407. {
  408. string url = string.Empty, gname = string.Empty;
  409. if (IsLocal(GroupID, out url, out gname))
  410. m_LocalGroupsConnector.RemoveAgentFromGroupRole(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID);
  411. }
  412. public List<GroupRolesData> GetAgentGroupRoles(string RequestingAgentID, string AgentID, UUID GroupID)
  413. {
  414. string url = string.Empty, gname = string.Empty;
  415. if (IsLocal(GroupID, out url, out gname))
  416. return m_LocalGroupsConnector.GetAgentGroupRoles(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID);
  417. else
  418. return new List<GroupRolesData>();
  419. }
  420. public void SetAgentActiveGroup(string RequestingAgentID, string AgentID, UUID GroupID)
  421. {
  422. string url = string.Empty, gname = string.Empty;
  423. if (IsLocal(GroupID, out url, out gname))
  424. m_LocalGroupsConnector.SetAgentActiveGroup(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID);
  425. }
  426. public ExtendedGroupMembershipData GetAgentActiveMembership(string RequestingAgentID, string AgentID)
  427. {
  428. return m_LocalGroupsConnector.GetAgentActiveMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID));
  429. }
  430. public void SetAgentActiveGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
  431. {
  432. string url = string.Empty, gname = string.Empty;
  433. if (IsLocal(GroupID, out url, out gname))
  434. m_LocalGroupsConnector.SetAgentActiveGroupRole(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID);
  435. }
  436. public void UpdateMembership(string RequestingAgentID, string AgentID, UUID GroupID, bool AcceptNotices, bool ListInProfile)
  437. {
  438. m_LocalGroupsConnector.UpdateMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, AcceptNotices, ListInProfile);
  439. }
  440. public ExtendedGroupMembershipData GetAgentGroupMembership(string RequestingAgentID, string AgentID, UUID GroupID)
  441. {
  442. string url = string.Empty, gname = string.Empty;
  443. if (IsLocal(GroupID, out url, out gname))
  444. return m_LocalGroupsConnector.GetAgentGroupMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID);
  445. else
  446. return null;
  447. }
  448. public List<GroupMembershipData> GetAgentGroupMemberships(string RequestingAgentID, string AgentID)
  449. {
  450. return m_LocalGroupsConnector.GetAgentGroupMemberships(AgentUUI(RequestingAgentID), AgentUUI(AgentID));
  451. }
  452. public bool AddGroupNotice(string RequestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject, string message,
  453. bool hasAttachment, byte attType, string attName, UUID attItemID, string attOwnerID)
  454. {
  455. string url = string.Empty, gname = string.Empty;
  456. if (IsLocal(groupID, out url, out gname))
  457. {
  458. if (m_LocalGroupsConnector.AddGroupNotice(AgentUUI(RequestingAgentID), groupID, noticeID, fromName, subject, message,
  459. hasAttachment, attType, attName, attItemID, AgentUUI(attOwnerID)))
  460. {
  461. // then send the notice to every grid for which there are members in this group
  462. List<GroupMembersData> members = m_LocalGroupsConnector.GetGroupMembers(AgentUUI(RequestingAgentID), groupID);
  463. List<string> urls = new List<string>();
  464. foreach (GroupMembersData m in members)
  465. {
  466. if (!m_UserManagement.IsLocalGridUser(m.AgentID))
  467. {
  468. string gURL = m_UserManagement.GetUserServerURL(m.AgentID, "GroupsServerURI");
  469. if (!urls.Contains(gURL))
  470. urls.Add(gURL);
  471. }
  472. }
  473. // so we have the list of urls to send the notice to
  474. // this may take a long time...
  475. WorkManager.RunInThread(delegate
  476. {
  477. foreach (string u in urls)
  478. {
  479. GroupsServiceHGConnector c = GetConnector(u);
  480. if (c != null)
  481. {
  482. c.AddNotice(AgentUUIForOutside(RequestingAgentID), groupID, noticeID, fromName, subject, message,
  483. hasAttachment, attType, attName, attItemID, AgentUUIForOutside(attOwnerID));
  484. }
  485. }
  486. }, null, string.Format("AddGroupNotice (agent {0}, group {1})", RequestingAgentID, groupID));
  487. return true;
  488. }
  489. return false;
  490. }
  491. else
  492. return false;
  493. }
  494. public GroupNoticeInfo GetGroupNotice(string RequestingAgentID, UUID noticeID)
  495. {
  496. GroupNoticeInfo notice = m_LocalGroupsConnector.GetGroupNotice(AgentUUI(RequestingAgentID), noticeID);
  497. if (notice != null && notice.noticeData.HasAttachment && notice.noticeData.AttachmentOwnerID != null)
  498. ImportForeigner(notice.noticeData.AttachmentOwnerID);
  499. return notice;
  500. }
  501. public List<ExtendedGroupNoticeData> GetGroupNotices(string RequestingAgentID, UUID GroupID)
  502. {
  503. return m_LocalGroupsConnector.GetGroupNotices(AgentUUI(RequestingAgentID), GroupID);
  504. }
  505. #endregion
  506. #region hypergrid groups
  507. private string AgentUUI(string AgentIDStr)
  508. {
  509. UUID AgentID = UUID.Zero;
  510. if (!UUID.TryParse(AgentIDStr, out AgentID) || AgentID == UUID.Zero)
  511. return UUID.Zero.ToString();
  512. if (m_UserManagement.IsLocalGridUser(AgentID))
  513. return AgentID.ToString();
  514. AgentCircuitData agent = null;
  515. foreach (Scene scene in m_Scenes)
  516. {
  517. agent = scene.AuthenticateHandler.GetAgentCircuitData(AgentID);
  518. if (agent != null)
  519. break;
  520. }
  521. if (agent != null)
  522. return Util.ProduceUserUniversalIdentifier(agent);
  523. // we don't know anything about this foreign user
  524. // try asking the user management module, which may know more
  525. return m_UserManagement.GetUserUUI(AgentID);
  526. }
  527. private string AgentUUIForOutside(string AgentIDStr)
  528. {
  529. UUID AgentID = UUID.Zero;
  530. if (!UUID.TryParse(AgentIDStr, out AgentID) || AgentID == UUID.Zero)
  531. return UUID.Zero.ToString();
  532. AgentCircuitData agent = null;
  533. foreach (Scene scene in m_Scenes)
  534. {
  535. agent = scene.AuthenticateHandler.GetAgentCircuitData(AgentID);
  536. if (agent != null)
  537. break;
  538. }
  539. if (agent == null) // oops
  540. return AgentID.ToString();
  541. return Util.ProduceUserUniversalIdentifier(agent);
  542. }
  543. private UUID ImportForeigner(string uID)
  544. {
  545. UUID userID = UUID.Zero;
  546. string url = string.Empty, first = string.Empty, last = string.Empty, tmp = string.Empty;
  547. if (Util.ParseUniversalUserIdentifier(uID, out userID, out url, out first, out last, out tmp))
  548. m_UserManagement.AddUser(userID, first, last, url);
  549. return userID;
  550. }
  551. private bool IsLocal(UUID groupID, out string serviceLocation, out string name)
  552. {
  553. serviceLocation = string.Empty;
  554. name = string.Empty;
  555. if (groupID.Equals(UUID.Zero))
  556. return true;
  557. ExtendedGroupRecord group = m_LocalGroupsConnector.GetGroupRecord(UUID.Zero.ToString(), groupID, string.Empty);
  558. if (group == null)
  559. {
  560. //m_log.DebugFormat("[XXX]: IsLocal? group {0} not found -- no.", groupID);
  561. return false;
  562. }
  563. serviceLocation = group.ServiceLocation;
  564. name = group.GroupName;
  565. bool isLocal = (group.ServiceLocation == string.Empty);
  566. //m_log.DebugFormat("[XXX]: IsLocal? {0}", isLocal);
  567. return isLocal;
  568. }
  569. private GroupsServiceHGConnector GetConnector(string url)
  570. {
  571. lock (m_NetworkConnectors)
  572. {
  573. if (m_NetworkConnectors.ContainsKey(url))
  574. return m_NetworkConnectors[url];
  575. GroupsServiceHGConnector c = new GroupsServiceHGConnector(url);
  576. m_NetworkConnectors[url] = c;
  577. }
  578. return m_NetworkConnectors[url];
  579. }
  580. #endregion
  581. }
  582. }