1
0

GroupsServiceRemoteConnectorModule.cs 16 KB

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