1
0

GroupsServiceLocalConnectorModule.cs 13 KB

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