MockGroupsServicesConnector.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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;
  29. using System.Collections.Generic;
  30. using System.Reflection;
  31. using log4net;
  32. using Mono.Addins;
  33. using Nini.Config;
  34. using OpenMetaverse;
  35. using OpenSim.Data;
  36. using OpenSim.Data.Null;
  37. using OpenSim.Framework;
  38. using OpenSim.Region.Framework.Interfaces;
  39. using OpenSim.Region.Framework.Scenes;
  40. using OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups;
  41. namespace OpenSim.Tests.Common
  42. {
  43. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
  44. public class MockGroupsServicesConnector : ISharedRegionModule, IGroupsServicesConnector
  45. {
  46. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  47. IXGroupData m_data = new NullXGroupData(null, null);
  48. public string Name
  49. {
  50. get { return "MockGroupsServicesConnector"; }
  51. }
  52. public Type ReplaceableInterface
  53. {
  54. get { return null; }
  55. }
  56. public void Initialise(IConfigSource config)
  57. {
  58. }
  59. public void Close()
  60. {
  61. }
  62. public void AddRegion(Scene scene)
  63. {
  64. m_log.DebugFormat("[MOCK GROUPS SERVICES CONNECTOR]: Adding to region {0}", scene.RegionInfo.RegionName);
  65. scene.RegisterModuleInterface<IGroupsServicesConnector>(this);
  66. }
  67. public void RemoveRegion(Scene scene)
  68. {
  69. }
  70. public void RegionLoaded(Scene scene)
  71. {
  72. }
  73. public void PostInitialise()
  74. {
  75. }
  76. public UUID CreateGroup(UUID requestingAgentID, string name, string charter, bool showInList, UUID insigniaID,
  77. int membershipFee, bool openEnrollment, bool allowPublish,
  78. bool maturePublish, UUID founderID)
  79. {
  80. XGroup group = new XGroup()
  81. {
  82. groupID = UUID.Random(),
  83. ownerRoleID = UUID.Random(),
  84. name = name,
  85. charter = charter,
  86. showInList = showInList,
  87. insigniaID = insigniaID,
  88. membershipFee = membershipFee,
  89. openEnrollment = openEnrollment,
  90. allowPublish = allowPublish,
  91. maturePublish = maturePublish,
  92. founderID = founderID,
  93. everyonePowers = (ulong)XmlRpcGroupsServicesConnectorModule.DefaultEveryonePowers,
  94. ownersPowers = (ulong)XmlRpcGroupsServicesConnectorModule.DefaultOwnerPowers
  95. };
  96. if (m_data.StoreGroup(group))
  97. {
  98. m_log.DebugFormat("[MOCK GROUPS SERVICES CONNECTOR]: Created group {0} {1}", group.name, group.groupID);
  99. return group.groupID;
  100. }
  101. else
  102. {
  103. m_log.ErrorFormat("[MOCK GROUPS SERVICES CONNECTOR]: Failed to create group {0}", name);
  104. return UUID.Zero;
  105. }
  106. }
  107. public void UpdateGroup(UUID requestingAgentID, UUID groupID, string charter, bool showInList,
  108. UUID insigniaID, int membershipFee, bool openEnrollment,
  109. bool allowPublish, bool maturePublish)
  110. {
  111. }
  112. public void AddGroupRole(UUID requestingAgentID, UUID groupID, UUID roleID, string name, string description,
  113. string title, ulong powers)
  114. {
  115. }
  116. public void RemoveGroupRole(UUID requestingAgentID, UUID groupID, UUID roleID)
  117. {
  118. }
  119. public void UpdateGroupRole(UUID requestingAgentID, UUID groupID, UUID roleID, string name, string description,
  120. string title, ulong powers)
  121. {
  122. }
  123. private XGroup GetXGroup(UUID groupID, string name)
  124. {
  125. XGroup group = m_data.GetGroup(groupID);
  126. if (group == null)
  127. m_log.DebugFormat("[MOCK GROUPS SERVICES CONNECTOR]: No group found with ID {0}", groupID);
  128. return group;
  129. }
  130. public GroupRecord GetGroupRecord(UUID requestingAgentID, UUID groupID, string groupName)
  131. {
  132. m_log.DebugFormat(
  133. "[MOCK GROUPS SERVICES CONNECTOR]: Processing GetGroupRecord() for groupID {0}, name {1}",
  134. groupID, groupName);
  135. XGroup xg = GetXGroup(groupID, groupName);
  136. if (xg == null)
  137. return null;
  138. GroupRecord gr = new GroupRecord()
  139. {
  140. GroupID = xg.groupID,
  141. GroupName = xg.name,
  142. AllowPublish = xg.allowPublish,
  143. MaturePublish = xg.maturePublish,
  144. Charter = xg.charter,
  145. FounderID = xg.founderID,
  146. // FIXME: group picture storage location unknown
  147. MembershipFee = xg.membershipFee,
  148. OpenEnrollment = xg.openEnrollment,
  149. OwnerRoleID = xg.ownerRoleID,
  150. ShowInList = xg.showInList
  151. };
  152. return gr;
  153. }
  154. public GroupProfileData GetMemberGroupProfile(UUID requestingAgentID, UUID GroupID, UUID AgentID)
  155. {
  156. return default(GroupProfileData);
  157. }
  158. public void SetAgentActiveGroup(UUID requestingAgentID, UUID AgentID, UUID GroupID)
  159. {
  160. }
  161. public void SetAgentActiveGroupRole(UUID requestingAgentID, UUID AgentID, UUID GroupID, UUID RoleID)
  162. {
  163. }
  164. public void SetAgentGroupInfo(UUID requestingAgentID, UUID agentID, UUID groupID, bool acceptNotices, bool listInProfile)
  165. {
  166. m_log.DebugFormat(
  167. "[MOCK GROUPS SERVICES CONNECTOR]: SetAgentGroupInfo, requestingAgentID {0}, agentID {1}, groupID {2}, acceptNotices {3}, listInProfile {4}",
  168. requestingAgentID, agentID, groupID, acceptNotices, listInProfile);
  169. XGroup group = GetXGroup(groupID, null);
  170. if (group == null)
  171. return;
  172. XGroupMember xgm = null;
  173. if (!group.members.TryGetValue(agentID, out xgm))
  174. return;
  175. xgm.acceptNotices = acceptNotices;
  176. xgm.listInProfile = listInProfile;
  177. m_data.StoreGroup(group);
  178. }
  179. public void AddAgentToGroupInvite(UUID requestingAgentID, UUID inviteID, UUID groupID, UUID roleID, UUID agentID)
  180. {
  181. }
  182. public GroupInviteInfo GetAgentToGroupInvite(UUID requestingAgentID, UUID inviteID)
  183. {
  184. return null;
  185. }
  186. public void RemoveAgentToGroupInvite(UUID requestingAgentID, UUID inviteID)
  187. {
  188. }
  189. public void AddAgentToGroup(UUID requestingAgentID, UUID agentID, UUID groupID, UUID roleID)
  190. {
  191. m_log.DebugFormat(
  192. "[MOCK GROUPS SERVICES CONNECTOR]: AddAgentToGroup, requestingAgentID {0}, agentID {1}, groupID {2}, roleID {3}",
  193. requestingAgentID, agentID, groupID, roleID);
  194. XGroup group = GetXGroup(groupID, null);
  195. if (group == null)
  196. return;
  197. XGroupMember groupMember = new XGroupMember()
  198. {
  199. agentID = agentID,
  200. groupID = groupID,
  201. roleID = roleID
  202. };
  203. group.members[agentID] = groupMember;
  204. m_data.StoreGroup(group);
  205. }
  206. public void RemoveAgentFromGroup(UUID requestingAgentID, UUID AgentID, UUID GroupID)
  207. {
  208. }
  209. public void AddAgentToGroupRole(UUID requestingAgentID, UUID AgentID, UUID GroupID, UUID RoleID)
  210. {
  211. }
  212. public void RemoveAgentFromGroupRole(UUID requestingAgentID, UUID AgentID, UUID GroupID, UUID RoleID)
  213. {
  214. }
  215. public List<DirGroupsReplyData> FindGroups(UUID requestingAgentID, string search)
  216. {
  217. return null;
  218. }
  219. public GroupMembershipData GetAgentGroupMembership(UUID requestingAgentID, UUID AgentID, UUID GroupID)
  220. {
  221. return null;
  222. }
  223. public GroupMembershipData GetAgentActiveMembership(UUID requestingAgentID, UUID AgentID)
  224. {
  225. return null;
  226. }
  227. public List<GroupMembershipData> GetAgentGroupMemberships(UUID requestingAgentID, UUID AgentID)
  228. {
  229. return new List<GroupMembershipData>();
  230. }
  231. public List<GroupRolesData> GetAgentGroupRoles(UUID requestingAgentID, UUID AgentID, UUID GroupID)
  232. {
  233. return null;
  234. }
  235. public List<GroupRolesData> GetGroupRoles(UUID requestingAgentID, UUID GroupID)
  236. {
  237. return null;
  238. }
  239. public List<GroupMembersData> GetGroupMembers(UUID requestingAgentID, UUID groupID)
  240. {
  241. m_log.DebugFormat(
  242. "[MOCK GROUPS SERVICES CONNECTOR]: GetGroupMembers, requestingAgentID {0}, groupID {1}",
  243. requestingAgentID, groupID);
  244. List<GroupMembersData> groupMembers = new List<GroupMembersData>();
  245. XGroup group = GetXGroup(groupID, null);
  246. if (group == null)
  247. return groupMembers;
  248. foreach (XGroupMember xgm in group.members.Values)
  249. {
  250. GroupMembersData gmd = new GroupMembersData();
  251. gmd.AgentID = xgm.agentID;
  252. gmd.IsOwner = group.founderID == gmd.AgentID;
  253. gmd.AcceptNotices = xgm.acceptNotices;
  254. gmd.ListInProfile = xgm.listInProfile;
  255. groupMembers.Add(gmd);
  256. }
  257. return groupMembers;
  258. }
  259. public List<GroupRoleMembersData> GetGroupRoleMembers(UUID requestingAgentID, UUID GroupID)
  260. {
  261. return null;
  262. }
  263. public List<GroupNoticeData> GetGroupNotices(UUID requestingAgentID, UUID groupID)
  264. {
  265. XGroup group = GetXGroup(groupID, null);
  266. if (group == null)
  267. return null;
  268. List<GroupNoticeData> notices = new List<GroupNoticeData>();
  269. foreach (XGroupNotice notice in group.notices.Values)
  270. {
  271. GroupNoticeData gnd = new GroupNoticeData()
  272. {
  273. NoticeID = notice.noticeID,
  274. Timestamp = notice.timestamp,
  275. FromName = notice.fromName,
  276. Subject = notice.subject,
  277. HasAttachment = notice.hasAttachment,
  278. AssetType = (byte)notice.assetType
  279. };
  280. notices.Add(gnd);
  281. }
  282. return notices;
  283. }
  284. public GroupNoticeInfo GetGroupNotice(UUID requestingAgentID, UUID noticeID)
  285. {
  286. m_log.DebugFormat(
  287. "[MOCK GROUPS SERVICES CONNECTOR]: GetGroupNotices, requestingAgentID {0}, noticeID {1}",
  288. requestingAgentID, noticeID);
  289. // Yes, not an efficient way to do it.
  290. Dictionary<UUID, XGroup> groups = m_data.GetGroups();
  291. foreach (XGroup group in groups.Values)
  292. {
  293. if (group.notices.ContainsKey(noticeID))
  294. {
  295. XGroupNotice n = group.notices[noticeID];
  296. GroupNoticeInfo gni = new GroupNoticeInfo();
  297. gni.GroupID = n.groupID;
  298. gni.Message = n.message;
  299. gni.BinaryBucket = n.binaryBucket;
  300. gni.noticeData.NoticeID = n.noticeID;
  301. gni.noticeData.Timestamp = n.timestamp;
  302. gni.noticeData.FromName = n.fromName;
  303. gni.noticeData.Subject = n.subject;
  304. gni.noticeData.HasAttachment = n.hasAttachment;
  305. gni.noticeData.AssetType = (byte)n.assetType;
  306. return gni;
  307. }
  308. }
  309. return null;
  310. }
  311. public void AddGroupNotice(UUID requestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject, string message, byte[] binaryBucket)
  312. {
  313. m_log.DebugFormat(
  314. "[MOCK GROUPS SERVICES CONNECTOR]: AddGroupNotice, requestingAgentID {0}, groupID {1}, noticeID {2}, fromName {3}, subject {4}, message {5}, binaryBucket.Length {6}",
  315. requestingAgentID, groupID, noticeID, fromName, subject, message, binaryBucket.Length);
  316. XGroup group = GetXGroup(groupID, null);
  317. if (group == null)
  318. return;
  319. XGroupNotice groupNotice = new XGroupNotice()
  320. {
  321. groupID = groupID,
  322. noticeID = noticeID,
  323. fromName = fromName,
  324. subject = subject,
  325. message = message,
  326. timestamp = (uint)Util.UnixTimeSinceEpoch(),
  327. hasAttachment = false,
  328. assetType = 0,
  329. binaryBucket = binaryBucket
  330. };
  331. group.notices[noticeID] = groupNotice;
  332. m_data.StoreGroup(group);
  333. }
  334. public void ResetAgentGroupChatSessions(UUID agentID)
  335. {
  336. }
  337. public bool hasAgentBeenInvitedToGroupChatSession(UUID agentID, UUID groupID)
  338. {
  339. return false;
  340. }
  341. public bool hasAgentDroppedGroupChatSession(UUID agentID, UUID groupID)
  342. {
  343. return false;
  344. }
  345. public void AgentDroppedFromGroupChatSession(UUID agentID, UUID groupID)
  346. {
  347. }
  348. public void AgentInvitedToGroupChatSession(UUID agentID, UUID groupID)
  349. {
  350. }
  351. }
  352. }