GroupsServiceRemoteConnectorModule.cs 16 KB

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