1
0

GroupsServiceRemoteConnectorModule.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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.Threading;
  32. using System.Text;
  33. using OpenSim.Framework;
  34. using OpenSim.Region.Framework.Scenes;
  35. using OpenSim.Region.Framework.Interfaces;
  36. using OpenSim.Server.Base;
  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 = "GroupsServiceRemoteConnectorModule")]
  44. public class GroupsServiceRemoteConnectorModule : ISharedRegionModule, IGroupsServicesConnector
  45. {
  46. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  47. private bool m_Enabled = false;
  48. private GroupsServiceRemoteConnector m_GroupsService;
  49. private IUserManagement m_UserManagement;
  50. private List<Scene> m_Scenes;
  51. private RemoteConnectorCacheWrapper m_CacheWrapper;
  52. #region constructors
  53. public GroupsServiceRemoteConnectorModule()
  54. {
  55. }
  56. public GroupsServiceRemoteConnectorModule(IConfigSource config, IUserManagement uman)
  57. {
  58. Init(config);
  59. m_UserManagement = uman;
  60. m_CacheWrapper = new RemoteConnectorCacheWrapper(m_UserManagement);
  61. }
  62. #endregion
  63. private void Init(IConfigSource config)
  64. {
  65. IConfig groupsConfig = config.Configs["Groups"];
  66. string url = groupsConfig.GetString("GroupsServerURI", string.Empty);
  67. if (!Uri.IsWellFormedUriString(url, UriKind.Absolute))
  68. throw new Exception(string.Format("[Groups.RemoteConnector]: Malformed groups server URL {0}. Fix it or disable the Groups feature.", url));
  69. m_GroupsService = new GroupsServiceRemoteConnector(url);
  70. m_Scenes = new List<Scene>();
  71. }
  72. #region ISharedRegionModule
  73. public void Initialise(IConfigSource config)
  74. {
  75. IConfig groupsConfig = config.Configs["Groups"];
  76. if (groupsConfig == null)
  77. return;
  78. if ((groupsConfig.GetBoolean("Enabled", false) == false)
  79. || (groupsConfig.GetString("ServicesConnectorModule", string.Empty) != Name))
  80. {
  81. return;
  82. }
  83. Init(config);
  84. m_Enabled = true;
  85. m_log.DebugFormat("[Groups.RemoteConnector]: Initializing {0}", this.Name);
  86. }
  87. public string Name
  88. {
  89. get { return "Groups Remote Service Connector"; }
  90. }
  91. public Type ReplaceableInterface
  92. {
  93. get { return null; }
  94. }
  95. public void AddRegion(Scene scene)
  96. {
  97. if (!m_Enabled)
  98. return;
  99. m_log.DebugFormat("[Groups.RemoteConnector]: Registering {0} with {1}", this.Name, scene.RegionInfo.RegionName);
  100. scene.RegisterModuleInterface<IGroupsServicesConnector>(this);
  101. m_Scenes.Add(scene);
  102. }
  103. public void RemoveRegion(Scene scene)
  104. {
  105. if (!m_Enabled)
  106. return;
  107. scene.UnregisterModuleInterface<IGroupsServicesConnector>(this);
  108. m_Scenes.Remove(scene);
  109. }
  110. public void RegionLoaded(Scene scene)
  111. {
  112. if (!m_Enabled)
  113. return;
  114. if (m_UserManagement == null)
  115. {
  116. m_UserManagement = scene.RequestModuleInterface<IUserManagement>();
  117. m_CacheWrapper = new RemoteConnectorCacheWrapper(m_UserManagement);
  118. }
  119. }
  120. public void PostInitialise()
  121. {
  122. }
  123. public void Close()
  124. {
  125. }
  126. #endregion
  127. #region IGroupsServicesConnector
  128. public UUID CreateGroup(UUID RequestingAgentID, string name, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment,
  129. bool allowPublish, bool maturePublish, UUID founderID, out string reason)
  130. {
  131. m_log.DebugFormat("[Groups.RemoteConnector]: Creating group {0}", name);
  132. string r = string.Empty;
  133. UUID groupID = m_CacheWrapper.CreateGroup(RequestingAgentID, delegate
  134. {
  135. return m_GroupsService.CreateGroup(RequestingAgentID.ToString(), name, charter, showInList, insigniaID,
  136. membershipFee, openEnrollment, allowPublish, maturePublish, founderID, out r);
  137. });
  138. reason = r;
  139. return groupID;
  140. }
  141. public bool UpdateGroup(string RequestingAgentID, UUID groupID, string charter, bool showInList, UUID insigniaID, int membershipFee,
  142. bool openEnrollment, bool allowPublish, bool maturePublish, out string reason)
  143. {
  144. string r = string.Empty;
  145. bool success = m_CacheWrapper.UpdateGroup(groupID, delegate
  146. {
  147. return m_GroupsService.UpdateGroup(RequestingAgentID, groupID, charter, showInList, insigniaID, membershipFee, openEnrollment, allowPublish, maturePublish);
  148. });
  149. reason = r;
  150. return success;
  151. }
  152. public ExtendedGroupRecord GetGroupRecord(string RequestingAgentID, UUID GroupID, string GroupName)
  153. {
  154. if (GroupID == UUID.Zero && (GroupName == null || GroupName != null && GroupName == string.Empty))
  155. return null;
  156. return m_CacheWrapper.GetGroupRecord(RequestingAgentID,GroupID,GroupName, delegate
  157. {
  158. return m_GroupsService.GetGroupRecord(RequestingAgentID, GroupID, GroupName);
  159. });
  160. }
  161. public List<DirGroupsReplyData> FindGroups(string RequestingAgentID, string search)
  162. {
  163. // TODO!
  164. return m_GroupsService.FindGroups(RequestingAgentID, search);
  165. }
  166. public bool AddAgentToGroup(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID, string token, out string reason)
  167. {
  168. string agentFullID = AgentID;
  169. m_log.DebugFormat("[Groups.RemoteConnector]: Add agent {0} to group {1}", agentFullID, GroupID);
  170. string r = string.Empty;
  171. bool success = m_CacheWrapper.AddAgentToGroup(RequestingAgentID, AgentID, GroupID, delegate
  172. {
  173. return m_GroupsService.AddAgentToGroup(RequestingAgentID, agentFullID, GroupID, RoleID, token, out r);
  174. });
  175. reason = r;
  176. return success;
  177. }
  178. public void RemoveAgentFromGroup(string RequestingAgentID, string AgentID, UUID GroupID)
  179. {
  180. m_CacheWrapper.RemoveAgentFromGroup(RequestingAgentID, AgentID, GroupID, delegate
  181. {
  182. m_GroupsService.RemoveAgentFromGroup(RequestingAgentID, AgentID, GroupID);
  183. });
  184. }
  185. public void SetAgentActiveGroup(string RequestingAgentID, string AgentID, UUID GroupID)
  186. {
  187. m_CacheWrapper.SetAgentActiveGroup(AgentID, delegate
  188. {
  189. return m_GroupsService.SetAgentActiveGroup(RequestingAgentID, AgentID, GroupID);
  190. });
  191. }
  192. public ExtendedGroupMembershipData GetAgentActiveMembership(string RequestingAgentID, string AgentID)
  193. {
  194. return m_CacheWrapper.GetAgentActiveMembership(AgentID, delegate
  195. {
  196. return m_GroupsService.GetMembership(RequestingAgentID, AgentID, UUID.Zero);
  197. });
  198. }
  199. public ExtendedGroupMembershipData GetAgentGroupMembership(string RequestingAgentID, string AgentID, UUID GroupID)
  200. {
  201. return m_CacheWrapper.GetAgentGroupMembership(AgentID, GroupID, delegate
  202. {
  203. return m_GroupsService.GetMembership(RequestingAgentID, AgentID, GroupID);
  204. });
  205. }
  206. public List<GroupMembershipData> GetAgentGroupMemberships(string RequestingAgentID, string AgentID)
  207. {
  208. return m_CacheWrapper.GetAgentGroupMemberships(AgentID, delegate
  209. {
  210. return m_GroupsService.GetMemberships(RequestingAgentID, AgentID);
  211. });
  212. }
  213. public List<GroupMembersData> GetGroupMembers(string RequestingAgentID, UUID GroupID)
  214. {
  215. return m_CacheWrapper.GetGroupMembers(RequestingAgentID, GroupID, delegate
  216. {
  217. return m_GroupsService.GetGroupMembers(RequestingAgentID, GroupID);
  218. });
  219. }
  220. public bool AddGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers, out string reason)
  221. {
  222. string r = string.Empty;
  223. bool success = m_CacheWrapper.AddGroupRole(groupID, roleID, description, name, powers, title, delegate
  224. {
  225. return m_GroupsService.AddGroupRole(RequestingAgentID, groupID, roleID, name, description, title, powers, out r);
  226. });
  227. reason = r;
  228. return success;
  229. }
  230. public bool UpdateGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers)
  231. {
  232. return m_CacheWrapper.UpdateGroupRole(groupID, roleID, name, description, title, powers, delegate
  233. {
  234. return m_GroupsService.UpdateGroupRole(RequestingAgentID, groupID, roleID, name, description, title, powers);
  235. });
  236. }
  237. public void RemoveGroupRole(string RequestingAgentID, UUID groupID, UUID roleID)
  238. {
  239. m_CacheWrapper.RemoveGroupRole(RequestingAgentID, groupID, roleID, delegate
  240. {
  241. m_GroupsService.RemoveGroupRole(RequestingAgentID, groupID, roleID);
  242. });
  243. }
  244. public List<GroupRolesData> GetGroupRoles(string RequestingAgentID, UUID GroupID)
  245. {
  246. return m_CacheWrapper.GetGroupRoles(RequestingAgentID, GroupID, delegate
  247. {
  248. return m_GroupsService.GetGroupRoles(RequestingAgentID, GroupID);
  249. });
  250. }
  251. public List<GroupRoleMembersData> GetGroupRoleMembers(string RequestingAgentID, UUID GroupID)
  252. {
  253. return m_CacheWrapper.GetGroupRoleMembers(RequestingAgentID, GroupID, delegate
  254. {
  255. return m_GroupsService.GetGroupRoleMembers(RequestingAgentID, GroupID);
  256. });
  257. }
  258. public void AddAgentToGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
  259. {
  260. m_CacheWrapper.AddAgentToGroupRole(RequestingAgentID, AgentID, GroupID, RoleID, delegate
  261. {
  262. return m_GroupsService.AddAgentToGroupRole(RequestingAgentID, AgentID, GroupID, RoleID);
  263. });
  264. }
  265. public void RemoveAgentFromGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
  266. {
  267. m_CacheWrapper.RemoveAgentFromGroupRole(RequestingAgentID, AgentID, GroupID, RoleID, delegate
  268. {
  269. return m_GroupsService.RemoveAgentFromGroupRole(RequestingAgentID, AgentID, GroupID, RoleID);
  270. });
  271. }
  272. public List<GroupRolesData> GetAgentGroupRoles(string RequestingAgentID, string AgentID, UUID GroupID)
  273. {
  274. return m_CacheWrapper.GetAgentGroupRoles(RequestingAgentID, AgentID, GroupID, delegate
  275. {
  276. return m_GroupsService.GetAgentGroupRoles(RequestingAgentID, AgentID, GroupID); ;
  277. });
  278. }
  279. public void SetAgentActiveGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
  280. {
  281. m_CacheWrapper.SetAgentActiveGroupRole(AgentID, GroupID, delegate
  282. {
  283. m_GroupsService.SetAgentActiveGroupRole(RequestingAgentID, AgentID, GroupID, RoleID);
  284. });
  285. }
  286. public void UpdateMembership(string RequestingAgentID, string AgentID, UUID GroupID, bool AcceptNotices, bool ListInProfile)
  287. {
  288. m_CacheWrapper.UpdateMembership(AgentID, GroupID, AcceptNotices, ListInProfile, delegate
  289. {
  290. m_GroupsService.UpdateMembership(RequestingAgentID, AgentID, GroupID, AcceptNotices, ListInProfile);
  291. });
  292. }
  293. public bool AddAgentToGroupInvite(string RequestingAgentID, UUID inviteID, UUID groupID, UUID roleID, string agentID)
  294. {
  295. return m_GroupsService.AddAgentToGroupInvite(RequestingAgentID, inviteID, groupID, roleID, agentID);
  296. }
  297. public GroupInviteInfo GetAgentToGroupInvite(string RequestingAgentID, UUID inviteID)
  298. {
  299. return m_GroupsService.GetAgentToGroupInvite(RequestingAgentID, inviteID);
  300. }
  301. public void RemoveAgentToGroupInvite(string RequestingAgentID, UUID inviteID)
  302. {
  303. m_GroupsService.RemoveAgentToGroupInvite(RequestingAgentID, inviteID);
  304. }
  305. public bool AddGroupNotice(string RequestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject, string message,
  306. bool hasAttachment, byte attType, string attName, UUID attItemID, string attOwnerID)
  307. {
  308. GroupNoticeInfo notice = new GroupNoticeInfo();
  309. notice.GroupID = groupID;
  310. notice.Message = message;
  311. notice.noticeData = new ExtendedGroupNoticeData();
  312. notice.noticeData.AttachmentItemID = attItemID;
  313. notice.noticeData.AttachmentName = attName;
  314. notice.noticeData.AttachmentOwnerID = attOwnerID.ToString();
  315. notice.noticeData.AttachmentType = attType;
  316. notice.noticeData.FromName = fromName;
  317. notice.noticeData.HasAttachment = hasAttachment;
  318. notice.noticeData.NoticeID = noticeID;
  319. notice.noticeData.Subject = subject;
  320. notice.noticeData.Timestamp = (uint)Util.UnixTimeSinceEpoch();
  321. return m_CacheWrapper.AddGroupNotice(groupID, noticeID, notice, delegate
  322. {
  323. return m_GroupsService.AddGroupNotice(RequestingAgentID, groupID, noticeID, fromName, subject, message,
  324. hasAttachment, attType, attName, attItemID, attOwnerID);
  325. });
  326. }
  327. public GroupNoticeInfo GetGroupNotice(string RequestingAgentID, UUID noticeID)
  328. {
  329. return m_CacheWrapper.GetGroupNotice(noticeID, delegate
  330. {
  331. return m_GroupsService.GetGroupNotice(RequestingAgentID, noticeID);
  332. });
  333. }
  334. public List<ExtendedGroupNoticeData> GetGroupNotices(string RequestingAgentID, UUID GroupID)
  335. {
  336. return m_CacheWrapper.GetGroupNotices(GroupID, delegate
  337. {
  338. return m_GroupsService.GetGroupNotices(RequestingAgentID, GroupID);
  339. });
  340. }
  341. #endregion
  342. }
  343. }