GroupsServiceLocalConnectorModule.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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.Region.Framework.Scenes;
  34. using OpenSim.Region.Framework.Interfaces;
  35. using OpenSim.Services.Interfaces;
  36. using OpenMetaverse;
  37. using Mono.Addins;
  38. using log4net;
  39. using Nini.Config;
  40. namespace OpenSim.Groups
  41. {
  42. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GroupsServiceLocalConnectorModule")]
  43. public class GroupsServiceLocalConnectorModule : ISharedRegionModule, IGroupsServicesConnector
  44. {
  45. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  46. private bool m_Enabled = false;
  47. private GroupsService m_GroupsService;
  48. private IUserManagement m_UserManagement;
  49. private List<Scene> m_Scenes;
  50. private ForeignImporter m_ForeignImporter;
  51. #region constructors
  52. public GroupsServiceLocalConnectorModule()
  53. {
  54. }
  55. public GroupsServiceLocalConnectorModule(IConfigSource config, IUserManagement uman)
  56. {
  57. Init(config);
  58. m_UserManagement = uman;
  59. m_ForeignImporter = new ForeignImporter(uman);
  60. }
  61. #endregion
  62. private void Init(IConfigSource config)
  63. {
  64. m_GroupsService = new GroupsService(config);
  65. m_Scenes = new List<Scene>();
  66. }
  67. #region ISharedRegionModule
  68. public void Initialise(IConfigSource config)
  69. {
  70. IConfig groupsConfig = config.Configs["Groups"];
  71. if (groupsConfig == null)
  72. return;
  73. if ((groupsConfig.GetBoolean("Enabled", false) == false)
  74. || (groupsConfig.GetString("ServicesConnectorModule", string.Empty) != Name))
  75. {
  76. return;
  77. }
  78. Init(config);
  79. m_Enabled = true;
  80. m_log.DebugFormat("[Groups]: Initializing {0}", this.Name);
  81. }
  82. public string Name
  83. {
  84. get { return "Groups Local Service Connector"; }
  85. }
  86. public Type ReplaceableInterface
  87. {
  88. get { return null; }
  89. }
  90. public void AddRegion(Scene scene)
  91. {
  92. if (!m_Enabled)
  93. return;
  94. m_log.DebugFormat("[Groups]: Registering {0} with {1}", this.Name, scene.RegionInfo.RegionName);
  95. scene.RegisterModuleInterface<IGroupsServicesConnector>(this);
  96. m_Scenes.Add(scene);
  97. }
  98. public void RemoveRegion(Scene scene)
  99. {
  100. if (!m_Enabled)
  101. return;
  102. scene.UnregisterModuleInterface<IGroupsServicesConnector>(this);
  103. m_Scenes.Remove(scene);
  104. }
  105. public void RegionLoaded(Scene scene)
  106. {
  107. if (!m_Enabled)
  108. return;
  109. if (m_UserManagement == null)
  110. {
  111. m_UserManagement = scene.RequestModuleInterface<IUserManagement>();
  112. m_ForeignImporter = new ForeignImporter(m_UserManagement);
  113. }
  114. }
  115. public void PostInitialise()
  116. {
  117. }
  118. public void Close()
  119. {
  120. }
  121. #endregion
  122. #region IGroupsServicesConnector
  123. public UUID CreateGroup(UUID RequestingAgentID, string name, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment,
  124. bool allowPublish, bool maturePublish, UUID founderID, out string reason)
  125. {
  126. m_log.DebugFormat("[Groups]: Creating group {0}", name);
  127. reason = string.Empty;
  128. return m_GroupsService.CreateGroup(RequestingAgentID.ToString(), name, charter, showInList, insigniaID,
  129. membershipFee, openEnrollment, allowPublish, maturePublish, founderID, out reason);
  130. }
  131. public bool UpdateGroup(string RequestingAgentID, UUID groupID, string charter, bool showInList, UUID insigniaID, int membershipFee,
  132. bool openEnrollment, bool allowPublish, bool maturePublish, out string reason)
  133. {
  134. reason = string.Empty;
  135. m_GroupsService.UpdateGroup(RequestingAgentID, groupID, charter, showInList, insigniaID, membershipFee, openEnrollment, allowPublish, maturePublish);
  136. return true;
  137. }
  138. public ExtendedGroupRecord GetGroupRecord(string RequestingAgentID, UUID GroupID, string GroupName)
  139. {
  140. if (!GroupID.IsZero())
  141. return m_GroupsService.GetGroupRecord(RequestingAgentID, GroupID);
  142. else if (GroupName != null)
  143. return m_GroupsService.GetGroupRecord(RequestingAgentID, GroupName);
  144. return null;
  145. }
  146. public List<DirGroupsReplyData> FindGroups(string RequestingAgentIDstr, string search)
  147. {
  148. return m_GroupsService.FindGroups(RequestingAgentIDstr, search);
  149. }
  150. public List<GroupMembersData> GetGroupMembers(string RequestingAgentID, UUID GroupID)
  151. {
  152. List<ExtendedGroupMembersData> _members = m_GroupsService.GetGroupMembers(RequestingAgentID, GroupID);
  153. if (_members != null && _members.Count > 0)
  154. {
  155. List<GroupMembersData> members = _members.ConvertAll<GroupMembersData>(new Converter<ExtendedGroupMembersData, GroupMembersData>(m_ForeignImporter.ConvertGroupMembersData));
  156. return members;
  157. }
  158. return new List<GroupMembersData>();
  159. }
  160. public bool AddGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers, out string reason)
  161. {
  162. return m_GroupsService.AddGroupRole(RequestingAgentID, groupID, roleID, name, description, title, powers, out reason);
  163. }
  164. public bool UpdateGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers)
  165. {
  166. return m_GroupsService.UpdateGroupRole(RequestingAgentID, groupID, roleID, name, description, title, powers);
  167. }
  168. public void RemoveGroupRole(string RequestingAgentID, UUID groupID, UUID roleID)
  169. {
  170. m_GroupsService.RemoveGroupRole(RequestingAgentID, groupID, roleID);
  171. }
  172. public List<GroupRolesData> GetGroupRoles(string RequestingAgentID, UUID GroupID)
  173. {
  174. return m_GroupsService.GetGroupRoles(RequestingAgentID, GroupID);
  175. }
  176. public List<GroupRoleMembersData> GetGroupRoleMembers(string RequestingAgentID, UUID GroupID)
  177. {
  178. List<ExtendedGroupRoleMembersData> _rm = m_GroupsService.GetGroupRoleMembers(RequestingAgentID, GroupID);
  179. if (_rm != null && _rm.Count > 0)
  180. {
  181. List<GroupRoleMembersData> rm = _rm.ConvertAll<GroupRoleMembersData>(new Converter<ExtendedGroupRoleMembersData, GroupRoleMembersData>(m_ForeignImporter.ConvertGroupRoleMembersData));
  182. return rm;
  183. }
  184. return new List<GroupRoleMembersData>();
  185. }
  186. public bool AddAgentToGroup(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID, string token, out string reason)
  187. {
  188. return m_GroupsService.AddAgentToGroup(RequestingAgentID, AgentID, GroupID, RoleID, token, out reason);
  189. }
  190. public void RemoveAgentFromGroup(string RequestingAgentID, string AgentID, UUID GroupID)
  191. {
  192. m_GroupsService.RemoveAgentFromGroup(RequestingAgentID, AgentID, GroupID);
  193. }
  194. public bool AddAgentToGroupInvite(string RequestingAgentID, UUID inviteID, UUID groupID, UUID roleID, string agentID)
  195. {
  196. return m_GroupsService.AddAgentToGroupInvite(RequestingAgentID, inviteID, groupID, roleID, agentID);
  197. }
  198. public GroupInviteInfo GetAgentToGroupInvite(string RequestingAgentID, UUID inviteID)
  199. {
  200. return m_GroupsService.GetAgentToGroupInvite(RequestingAgentID, inviteID);
  201. }
  202. public void RemoveAgentToGroupInvite(string RequestingAgentID, UUID inviteID)
  203. {
  204. m_GroupsService.RemoveAgentToGroupInvite(RequestingAgentID, inviteID);
  205. }
  206. public void AddAgentToGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
  207. {
  208. m_GroupsService.AddAgentToGroupRole(RequestingAgentID, AgentID, GroupID, RoleID);
  209. }
  210. public void RemoveAgentFromGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
  211. {
  212. m_GroupsService.RemoveAgentFromGroupRole(RequestingAgentID, AgentID, GroupID, RoleID);
  213. }
  214. public List<GroupRolesData> GetAgentGroupRoles(string RequestingAgentID, string AgentID, UUID GroupID)
  215. {
  216. return m_GroupsService.GetAgentGroupRoles(RequestingAgentID, AgentID, GroupID);
  217. }
  218. public void SetAgentActiveGroup(string RequestingAgentID, string AgentID, UUID GroupID)
  219. {
  220. m_GroupsService.SetAgentActiveGroup(RequestingAgentID, AgentID, GroupID);
  221. }
  222. public ExtendedGroupMembershipData GetAgentActiveMembership(string RequestingAgentID, string AgentID)
  223. {
  224. return m_GroupsService.GetAgentActiveMembership(RequestingAgentID, AgentID);
  225. }
  226. public void SetAgentActiveGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
  227. {
  228. m_GroupsService.SetAgentActiveGroupRole(RequestingAgentID, AgentID, GroupID, RoleID);
  229. }
  230. public void UpdateMembership(string RequestingAgentID, string AgentID, UUID GroupID, bool AcceptNotices, bool ListInProfile)
  231. {
  232. m_GroupsService.UpdateMembership(RequestingAgentID, AgentID, GroupID, AcceptNotices, ListInProfile);
  233. }
  234. public ExtendedGroupMembershipData GetAgentGroupMembership(string RequestingAgentID, string AgentID, UUID GroupID)
  235. {
  236. return m_GroupsService.GetAgentGroupMembership(RequestingAgentID, AgentID, GroupID);
  237. }
  238. public List<GroupMembershipData> GetAgentGroupMemberships(string RequestingAgentID, string AgentID)
  239. {
  240. return m_GroupsService.GetAgentGroupMemberships(RequestingAgentID, AgentID);
  241. }
  242. public bool AddGroupNotice(string RequestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject, string message,
  243. bool hasAttachment, byte attType, string attName, UUID attItemID, string attOwnerID)
  244. {
  245. return m_GroupsService.AddGroupNotice(RequestingAgentID, groupID, noticeID, fromName, subject, message,
  246. hasAttachment, attType, attName, attItemID, attOwnerID);
  247. }
  248. public GroupNoticeInfo GetGroupNotice(string RequestingAgentID, UUID noticeID)
  249. {
  250. GroupNoticeInfo notice = m_GroupsService.GetGroupNotice(RequestingAgentID, noticeID);
  251. //if (notice != null && notice.noticeData.HasAttachment && notice.noticeData.AttachmentOwnerID != null)
  252. //{
  253. // UUID userID = UUID.Zero;
  254. // string url = string.Empty, first = string.Empty, last = string.Empty, tmp = string.Empty;
  255. // Util.ParseUniversalUserIdentifier(notice.noticeData.AttachmentOwnerID, out userID, out url, out first, out last, out tmp);
  256. // if (url != string.Empty)
  257. // m_UserManagement.AddUser(userID, first, last, url);
  258. //}
  259. return notice;
  260. }
  261. public List<ExtendedGroupNoticeData> GetGroupNotices(string RequestingAgentID, UUID GroupID)
  262. {
  263. return m_GroupsService.GetGroupNotices(RequestingAgentID, GroupID);
  264. }
  265. #endregion
  266. }
  267. }