GroupsServiceHGConnectorModule.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  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.Servers;
  34. using OpenSim.Region.Framework.Scenes;
  35. using OpenSim.Region.Framework.Interfaces;
  36. using OpenSim.Services.Interfaces;
  37. using OpenMetaverse;
  38. using Mono.Addins;
  39. using log4net;
  40. using Nini.Config;
  41. namespace OpenSim.Groups
  42. {
  43. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GroupsServiceHGConnectorModule")]
  44. public class GroupsServiceHGConnectorModule : ISharedRegionModule, IGroupsServicesConnector
  45. {
  46. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  47. private bool m_Enabled = false;
  48. private IGroupsServicesConnector m_LocalGroupsConnector;
  49. private string m_LocalGroupsServiceLocation;
  50. private IUserManagement m_UserManagement;
  51. private IOfflineIMService m_OfflineIM;
  52. private IMessageTransferModule m_Messaging;
  53. private List<Scene> m_Scenes;
  54. private ForeignImporter m_ForeignImporter;
  55. private string m_ServiceLocation;
  56. private IConfigSource m_Config;
  57. private Dictionary<string, GroupsServiceHGConnector> m_NetworkConnectors = new Dictionary<string, GroupsServiceHGConnector>();
  58. private RemoteConnectorCacheWrapper m_CacheWrapper; // for caching info of external group services
  59. #region ISharedRegionModule
  60. public void Initialise(IConfigSource config)
  61. {
  62. IConfig groupsConfig = config.Configs["Groups"];
  63. if (groupsConfig == null)
  64. return;
  65. if ((groupsConfig.GetBoolean("Enabled", false) == false)
  66. || (groupsConfig.GetString("ServicesConnectorModule", string.Empty) != Name))
  67. {
  68. return;
  69. }
  70. m_Config = config;
  71. m_ServiceLocation = groupsConfig.GetString("LocalService", "local"); // local or remote
  72. m_LocalGroupsServiceLocation = groupsConfig.GetString("GroupsExternalURI", "http://127.0.0.1");
  73. m_Scenes = new List<Scene>();
  74. m_Enabled = true;
  75. m_log.DebugFormat("[Groups]: Initializing {0} with LocalService {1}", this.Name, m_ServiceLocation);
  76. }
  77. public string Name
  78. {
  79. get { return "Groups HG Service Connector"; }
  80. }
  81. public Type ReplaceableInterface
  82. {
  83. get { return null; }
  84. }
  85. public void AddRegion(Scene scene)
  86. {
  87. if (!m_Enabled)
  88. return;
  89. m_log.DebugFormat("[Groups]: Registering {0} with {1}", this.Name, scene.RegionInfo.RegionName);
  90. scene.RegisterModuleInterface<IGroupsServicesConnector>(this);
  91. m_Scenes.Add(scene);
  92. scene.EventManager.OnNewClient += OnNewClient;
  93. }
  94. public void RemoveRegion(Scene scene)
  95. {
  96. if (!m_Enabled)
  97. return;
  98. scene.UnregisterModuleInterface<IGroupsServicesConnector>(this);
  99. m_Scenes.Remove(scene);
  100. }
  101. public void RegionLoaded(Scene scene)
  102. {
  103. if (!m_Enabled)
  104. return;
  105. if (m_UserManagement == null)
  106. {
  107. m_UserManagement = scene.RequestModuleInterface<IUserManagement>();
  108. m_OfflineIM = scene.RequestModuleInterface<IOfflineIMService>();
  109. m_Messaging = scene.RequestModuleInterface<IMessageTransferModule>();
  110. m_ForeignImporter = new ForeignImporter(m_UserManagement);
  111. if (m_ServiceLocation.Equals("local"))
  112. {
  113. m_LocalGroupsConnector = new GroupsServiceLocalConnectorModule(m_Config, m_UserManagement);
  114. // Also, if local, create the endpoint for the HGGroupsService
  115. new HGGroupsServiceRobustConnector(m_Config, MainServer.Instance, string.Empty,
  116. scene.RequestModuleInterface<IOfflineIMService>(), scene.RequestModuleInterface<IUserAccountService>());
  117. }
  118. else
  119. m_LocalGroupsConnector = new GroupsServiceRemoteConnectorModule(m_Config, m_UserManagement);
  120. m_CacheWrapper = new RemoteConnectorCacheWrapper(m_UserManagement);
  121. }
  122. }
  123. public void PostInitialise()
  124. {
  125. }
  126. public void Close()
  127. {
  128. }
  129. #endregion
  130. private void OnNewClient(IClientAPI client)
  131. {
  132. client.OnCompleteMovementToRegion += OnCompleteMovementToRegion;
  133. }
  134. void OnCompleteMovementToRegion(IClientAPI client, bool arg2)
  135. {
  136. object sp = null;
  137. if (client.Scene.TryGetScenePresence(client.AgentId, out sp))
  138. {
  139. if (sp is ScenePresence && ((ScenePresence)sp).PresenceType != PresenceType.Npc)
  140. {
  141. AgentCircuitData aCircuit = ((ScenePresence)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 RequestingAgentID, string search)
  211. {
  212. return m_LocalGroupsConnector.FindGroups(AgentUUI(RequestingAgentID), 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 == string.Empty)
  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. Util.RunThreadNoTimeout(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. }, "AddGroupNotice", null);
  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. try
  510. {
  511. AgentID = new UUID(AgentIDStr);
  512. }
  513. catch (FormatException)
  514. {
  515. return AgentID.ToString();
  516. }
  517. if (m_UserManagement.IsLocalGridUser(AgentID))
  518. return AgentID.ToString();
  519. AgentCircuitData agent = null;
  520. foreach (Scene scene in m_Scenes)
  521. {
  522. agent = scene.AuthenticateHandler.GetAgentCircuitData(AgentID);
  523. if (agent != null)
  524. break;
  525. }
  526. if (agent != null)
  527. return Util.ProduceUserUniversalIdentifier(agent);
  528. // we don't know anything about this foreign user
  529. // try asking the user management module, which may know more
  530. return m_UserManagement.GetUserUUI(AgentID);
  531. }
  532. private string AgentUUIForOutside(string AgentIDStr)
  533. {
  534. UUID AgentID = UUID.Zero;
  535. try
  536. {
  537. AgentID = new UUID(AgentIDStr);
  538. }
  539. catch (FormatException)
  540. {
  541. return AgentID.ToString();
  542. }
  543. AgentCircuitData agent = null;
  544. foreach (Scene scene in m_Scenes)
  545. {
  546. agent = scene.AuthenticateHandler.GetAgentCircuitData(AgentID);
  547. if (agent != null)
  548. break;
  549. }
  550. if (agent == null) // oops
  551. return AgentID.ToString();
  552. return Util.ProduceUserUniversalIdentifier(agent);
  553. }
  554. private UUID ImportForeigner(string uID)
  555. {
  556. UUID userID = UUID.Zero;
  557. string url = string.Empty, first = string.Empty, last = string.Empty, tmp = string.Empty;
  558. if (Util.ParseUniversalUserIdentifier(uID, out userID, out url, out first, out last, out tmp))
  559. m_UserManagement.AddUser(userID, first, last, url);
  560. return userID;
  561. }
  562. private bool IsLocal(UUID groupID, out string serviceLocation, out string name)
  563. {
  564. serviceLocation = string.Empty;
  565. name = string.Empty;
  566. if (groupID.Equals(UUID.Zero))
  567. return true;
  568. ExtendedGroupRecord group = m_LocalGroupsConnector.GetGroupRecord(UUID.Zero.ToString(), groupID, string.Empty);
  569. if (group == null)
  570. {
  571. //m_log.DebugFormat("[XXX]: IsLocal? group {0} not found -- no.", groupID);
  572. return false;
  573. }
  574. serviceLocation = group.ServiceLocation;
  575. name = group.GroupName;
  576. bool isLocal = (group.ServiceLocation == string.Empty);
  577. //m_log.DebugFormat("[XXX]: IsLocal? {0}", isLocal);
  578. return isLocal;
  579. }
  580. private GroupsServiceHGConnector GetConnector(string url)
  581. {
  582. lock (m_NetworkConnectors)
  583. {
  584. if (m_NetworkConnectors.ContainsKey(url))
  585. return m_NetworkConnectors[url];
  586. GroupsServiceHGConnector c = new GroupsServiceHGConnector(url);
  587. m_NetworkConnectors[url] = c;
  588. }
  589. return m_NetworkConnectors[url];
  590. }
  591. #endregion
  592. }
  593. }