PageRenderTime 49ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/Aurora/Services/DataService/Connectors/Local/LocalGroupsServiceConnector.cs

https://bitbucket.org/VirtualReality/software-testing
C# | 1904 lines | 1577 code | 272 blank | 55 comment | 335 complexity | 700a47c6487cad0c640600bd97ec9fd7 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * Copyright (c) Contributors, http://aurora-sim.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 Aurora-Sim 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 Aurora.Framework;
  28. using Aurora.Framework.ClientInterfaces;
  29. using Aurora.Framework.ConsoleFramework;
  30. using Aurora.Framework.DatabaseInterfaces;
  31. using Aurora.Framework.Modules;
  32. using Aurora.Framework.PresenceInfo;
  33. using Aurora.Framework.Services;
  34. using Aurora.Framework.Utilities;
  35. using Nini.Config;
  36. using OpenMetaverse;
  37. using System;
  38. using System.Collections.Generic;
  39. using System.Linq;
  40. namespace Aurora.Services.DataService
  41. {
  42. public class LocalGroupsServiceConnector : ConnectorBase, IGroupsServiceConnector
  43. {
  44. #region Declares
  45. private IGenericData data;
  46. private List<UUID> agentsCanBypassGroupNoticePermsCheck = new List<UUID>();
  47. #endregion
  48. #region IAuroraDataPlugin members
  49. public void Initialize(IGenericData GenericData, IConfigSource source, IRegistryCore simBase,
  50. string defaultConnectionString)
  51. {
  52. data = GenericData;
  53. if (source.Configs[Name] != null)
  54. {
  55. defaultConnectionString = source.Configs[Name].GetString("ConnectionString", defaultConnectionString);
  56. }
  57. if (source.Configs["Groups"] != null)
  58. {
  59. agentsCanBypassGroupNoticePermsCheck =
  60. Util.ConvertToList(source.Configs["Groups"].GetString("AgentsCanBypassGroupNoticePermsCheck", ""))
  61. .ConvertAll(x => new UUID(x));
  62. }
  63. if (data != null)
  64. data.ConnectToDatabase(defaultConnectionString, "Groups",
  65. source.Configs["AuroraConnectors"].GetBoolean("ValidateTables", true));
  66. Framework.Utilities.DataManager.RegisterPlugin(Name + "Local", this);
  67. if (source.Configs["AuroraConnectors"].GetString("GroupsConnector", "LocalConnector") == "LocalConnector")
  68. {
  69. Framework.Utilities.DataManager.RegisterPlugin(this);
  70. }
  71. Init(simBase, Name);
  72. }
  73. public string Name
  74. {
  75. get { return "IGroupsServiceConnector"; }
  76. }
  77. #endregion
  78. #region IGroupsServiceConnector Members
  79. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  80. public void CreateGroup(UUID groupID, string name, string charter, bool showInList, UUID insigniaID,
  81. int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish,
  82. UUID founderID, UUID OwnerRoleID)
  83. {
  84. object remoteValue = DoRemote(groupID, name, charter, showInList, insigniaID, membershipFee, openEnrollment,
  85. allowPublish, maturePublish, founderID, OwnerRoleID);
  86. if (remoteValue != null || m_doRemoteOnly)
  87. return;
  88. // Would this be cleaner as (GroupPowers)ulong.MaxValue;
  89. ulong OwnerPowers = (ulong) (GroupPowers.Accountable
  90. | GroupPowers.AllowEditLand
  91. | GroupPowers.AllowFly
  92. | GroupPowers.AllowLandmark
  93. | GroupPowers.AllowRez
  94. | GroupPowers.AllowSetHome
  95. | GroupPowers.AllowVoiceChat
  96. | GroupPowers.AssignMember
  97. | GroupPowers.AssignMemberLimited
  98. | GroupPowers.ChangeActions
  99. | GroupPowers.ChangeIdentity
  100. | GroupPowers.ChangeMedia
  101. | GroupPowers.ChangeOptions
  102. | GroupPowers.CreateRole
  103. | GroupPowers.DeedObject
  104. | GroupPowers.DeleteRole
  105. | GroupPowers.Eject
  106. | GroupPowers.FindPlaces
  107. | GroupPowers.Invite
  108. | GroupPowers.JoinChat
  109. | GroupPowers.LandChangeIdentity
  110. | GroupPowers.LandDeed
  111. | GroupPowers.LandDivideJoin
  112. | GroupPowers.LandEdit
  113. | GroupPowers.LandEjectAndFreeze
  114. | GroupPowers.LandGardening
  115. | GroupPowers.LandManageAllowed
  116. | GroupPowers.LandManageBanned
  117. | GroupPowers.LandManagePasses
  118. | GroupPowers.LandOptions
  119. | GroupPowers.LandRelease
  120. | GroupPowers.LandSetSale
  121. | GroupPowers.ModerateChat
  122. | GroupPowers.ObjectManipulate
  123. | GroupPowers.ObjectSetForSale
  124. | GroupPowers.ReceiveNotices
  125. | GroupPowers.RemoveMember
  126. | GroupPowers.ReturnGroupOwned
  127. | GroupPowers.ReturnGroupSet
  128. | GroupPowers.ReturnNonGroup
  129. | GroupPowers.RoleProperties
  130. | GroupPowers.SendNotices
  131. | GroupPowers.SetLandingPoint
  132. | GroupPowers.StartProposal
  133. | GroupPowers.VoteOnProposal);
  134. ulong EveryonePowers = (ulong) (GroupPowers.AllowSetHome |
  135. GroupPowers.Accountable |
  136. GroupPowers.JoinChat |
  137. GroupPowers.AllowVoiceChat |
  138. GroupPowers.ReceiveNotices |
  139. GroupPowers.StartProposal |
  140. GroupPowers.VoteOnProposal);
  141. Dictionary<string, object> row = new Dictionary<string, object>(11);
  142. row["GroupID"] = groupID;
  143. row["Name"] = name;
  144. row["Charter"] = charter ?? "";
  145. row["InsigniaID"] = insigniaID;
  146. row["FounderID"] = founderID;
  147. row["MembershipFee"] = membershipFee;
  148. row["OpenEnrollment"] = openEnrollment ? 1 : 0;
  149. row["ShowInList"] = showInList ? 1 : 0;
  150. row["AllowPublish"] = allowPublish ? 1 : 0;
  151. row["MaturePublish"] = maturePublish ? 1 : 0;
  152. row["OwnerRoleID"] = OwnerRoleID;
  153. data.Insert("osgroup", row);
  154. //Add everyone role to group
  155. AddRoleToGroup(founderID, groupID, UUID.Zero, "Everyone", "Everyone in the group is in the everyone role.",
  156. "Member of " + name, EveryonePowers);
  157. const ulong groupPowers = 296868139497678;
  158. UUID officersRole = UUID.Random();
  159. //Add officers role to group
  160. AddRoleToGroup(founderID, groupID, officersRole, "Officers",
  161. "The officers of the group, with more powers than regular members.", "Officer of " + name,
  162. groupPowers);
  163. //Add owner role to group
  164. AddRoleToGroup(founderID, groupID, OwnerRoleID, "Owners", "Owners of " + name, "Owner of " + name,
  165. OwnerPowers);
  166. //Add owner to the group as owner
  167. AddAgentToGroup(founderID, founderID, groupID, OwnerRoleID);
  168. AddAgentToRole(founderID, founderID, groupID, officersRole);
  169. SetAgentGroupSelectedRole(founderID, groupID, OwnerRoleID);
  170. SetAgentActiveGroup(founderID, groupID);
  171. }
  172. //[CanBeReflected(ThreatLevel = ThreatLevel.Full)]
  173. public void UpdateGroupFounder(UUID groupID, UUID newOwner, bool keepOldOwnerInGroup)
  174. {
  175. /*object remoteValue = DoRemote(groupID, newOwner, keepOldOwnerInGroup);
  176. if (remoteValue != null || m_doRemoteOnly)
  177. return;*/
  178. GroupRecord record = GetGroupRecord(UUID.Zero, groupID, "");
  179. bool newUserExists = GetAgentGroupMemberData(newOwner, groupID, newOwner) != null;
  180. Dictionary<string, object> values = new Dictionary<string, object>(1);
  181. values["FounderID"] = newOwner;
  182. QueryFilter filter = new QueryFilter();
  183. filter.andFilters["GroupID"] = groupID;
  184. data.Update("osgroup", values, null, filter, null, null);
  185. if (!newUserExists)
  186. AddAgentToGroup(newOwner, newOwner, groupID, record.OwnerRoleID);
  187. else
  188. AddAgentToRole(newOwner, newOwner, groupID, record.OwnerRoleID);
  189. if (!keepOldOwnerInGroup)
  190. RemoveAgentFromGroup(newOwner, record.FounderID, groupID);
  191. }
  192. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  193. public void UpdateGroup(UUID requestingAgentID, UUID groupID, string charter, int showInList, UUID insigniaID,
  194. int membershipFee, int openEnrollment, int allowPublish, int maturePublish)
  195. {
  196. object remoteValue = DoRemote(requestingAgentID, groupID, charter, showInList, insigniaID, membershipFee,
  197. openEnrollment, allowPublish, maturePublish);
  198. if (remoteValue != null || m_doRemoteOnly)
  199. return;
  200. if (CheckGroupPermissions(requestingAgentID, groupID,
  201. (ulong) (GroupPowers.ChangeOptions | GroupPowers.ChangeIdentity)))
  202. {
  203. Dictionary<string, object> values = new Dictionary<string, object>(6);
  204. values["Charter"] = charter;
  205. values["InsigniaID"] = insigniaID;
  206. values["MembershipFee"] = membershipFee;
  207. values["OpenEnrollment"] = openEnrollment;
  208. values["ShowInList"] = showInList;
  209. values["AllowPublish"] = allowPublish;
  210. values["MaturePublish"] = maturePublish;
  211. QueryFilter filter = new QueryFilter();
  212. filter.andFilters["GroupID"] = groupID;
  213. data.Update("osgroup", values, null, filter, null, null);
  214. }
  215. }
  216. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  217. public void AddGroupNotice(UUID requestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject,
  218. string message, UUID ItemID, int AssetType, string ItemName)
  219. {
  220. object remoteValue = DoRemote(requestingAgentID, groupID, noticeID, fromName, subject, message, ItemID,
  221. AssetType, ItemName);
  222. if (remoteValue != null || m_doRemoteOnly)
  223. return;
  224. if (CheckGroupPermissions(requestingAgentID, groupID, (ulong) GroupPowers.SendNotices))
  225. {
  226. Dictionary<string, object> row = new Dictionary<string, object>(10);
  227. row["GroupID"] = groupID;
  228. row["NoticeID"] = noticeID == UUID.Zero ? UUID.Random() : noticeID;
  229. row["Timestamp"] = ((uint) Util.UnixTimeSinceEpoch());
  230. row["FromName"] = fromName;
  231. row["Subject"] = subject;
  232. row["Message"] = message;
  233. row["HasAttachment"] = (ItemID != UUID.Zero) ? 1 : 0;
  234. row["ItemID"] = ItemID;
  235. row["AssetType"] = AssetType;
  236. row["ItemName"] = ItemName == null ? "" : ItemName;
  237. data.Insert("osgroupnotice", row);
  238. }
  239. }
  240. [CanBeReflected(ThreatLevel = ThreatLevel.High)]
  241. public bool EditGroupNotice(UUID requestingAgentID, UUID groupID, UUID noticeID, string subject, string message)
  242. {
  243. object remoteValue = DoRemote(requestingAgentID, groupID, noticeID, subject, message);
  244. if (remoteValue != null || m_doRemoteOnly)
  245. {
  246. return (bool) remoteValue;
  247. }
  248. if (!agentsCanBypassGroupNoticePermsCheck.Contains(requestingAgentID) &&
  249. !CheckGroupPermissions(requestingAgentID, groupID, (ulong) GroupPowers.SendNotices))
  250. {
  251. MainConsole.Instance.TraceFormat("Permission check failed when trying to edit group notice {0}.",
  252. noticeID);
  253. return false;
  254. }
  255. GroupNoticeInfo GNI = GetGroupNotice(requestingAgentID, noticeID);
  256. if (GNI == null)
  257. {
  258. MainConsole.Instance.TraceFormat("Could not find group notice {0}", noticeID);
  259. return false;
  260. }
  261. else if (GNI.GroupID != groupID)
  262. {
  263. MainConsole.Instance.TraceFormat("Group notice {0} group ID {1} does not match supplied group ID {2}",
  264. noticeID, GNI.GroupID, groupID);
  265. return false;
  266. }
  267. else if (subject.Trim() == string.Empty || message.Trim() == string.Empty)
  268. {
  269. MainConsole.Instance.TraceFormat("Could not edit group notice {0}, message or subject was empty",
  270. noticeID);
  271. return false;
  272. }
  273. QueryFilter filter = new QueryFilter();
  274. filter.andFilters["GroupID"] = groupID;
  275. filter.andFilters["NoticeID"] = noticeID;
  276. Dictionary<string, object> update = new Dictionary<string, object>(2);
  277. update["Subject"] = subject.Trim();
  278. update["Message"] = message.Trim();
  279. return data.Update("osgroupnotice", update, null, filter, null, null);
  280. }
  281. [CanBeReflected(ThreatLevel = ThreatLevel.High)]
  282. public bool RemoveGroupNotice(UUID requestingAgentID, UUID groupID, UUID noticeID)
  283. {
  284. object remoteValue = DoRemote(requestingAgentID, groupID, noticeID);
  285. if (remoteValue != null || m_doRemoteOnly)
  286. {
  287. return (bool) remoteValue;
  288. }
  289. if (!agentsCanBypassGroupNoticePermsCheck.Contains(requestingAgentID) &&
  290. !CheckGroupPermissions(requestingAgentID, groupID, (ulong) GroupPowers.SendNotices))
  291. {
  292. MainConsole.Instance.TraceFormat("Permission check failed when trying to edit group notice {0}.",
  293. noticeID);
  294. return false;
  295. }
  296. GroupNoticeInfo GNI = GetGroupNotice(requestingAgentID, noticeID);
  297. if (GNI == null)
  298. {
  299. MainConsole.Instance.TraceFormat("Could not find group notice {0}", noticeID);
  300. return false;
  301. }
  302. else if (GNI.GroupID != groupID)
  303. {
  304. MainConsole.Instance.TraceFormat("Group notice {0} group ID {1} does not match supplied group ID {2}",
  305. noticeID, GNI.GroupID, groupID);
  306. return false;
  307. }
  308. QueryFilter filter = new QueryFilter();
  309. filter.andFilters["GroupID"] = groupID;
  310. filter.andFilters["NoticeID"] = noticeID;
  311. return data.Delete("osgroupnotice", filter);
  312. }
  313. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  314. public string SetAgentActiveGroup(UUID AgentID, UUID GroupID)
  315. {
  316. object remoteValue = DoRemote(AgentID, GroupID);
  317. if (remoteValue != null || m_doRemoteOnly)
  318. return (string) remoteValue;
  319. QueryFilter filter = new QueryFilter();
  320. filter.andFilters["AgentID"] = AgentID;
  321. if (data.Query(new[] {"*"}, "osagent", filter, null, null, null).Count != 0)
  322. {
  323. Dictionary<string, object> values = new Dictionary<string, object>(1);
  324. values["ActiveGroupID"] = GroupID;
  325. data.Update("osagent", values, null, filter, null, null);
  326. }
  327. else
  328. {
  329. Dictionary<string, object> row = new Dictionary<string, object>(2);
  330. row["AgentID"] = AgentID;
  331. row["ActiveGroupID"] = GroupID;
  332. data.Insert("osagent", row);
  333. }
  334. GroupMembersData gdata = GetAgentGroupMemberData(AgentID, GroupID, AgentID);
  335. return gdata == null ? "" : gdata.Title;
  336. }
  337. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  338. public UUID GetAgentActiveGroup(UUID RequestingAgentID, UUID AgentID)
  339. {
  340. object remoteValue = DoRemote(RequestingAgentID, AgentID);
  341. if (remoteValue != null || m_doRemoteOnly)
  342. return (UUID) remoteValue; // note: this is bad, you can't cast a null object to a UUID
  343. QueryFilter filter = new QueryFilter();
  344. filter.andFilters["AgentID"] = AgentID;
  345. List<string> groups = data.Query(new string[1] {"ActiveGroupID"}, "osagent", filter, null, null, null);
  346. return (groups.Count != 0) ? UUID.Parse(groups[0]) : UUID.Zero;
  347. }
  348. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  349. public string SetAgentGroupSelectedRole(UUID AgentID, UUID GroupID, UUID RoleID)
  350. {
  351. object remoteValue = DoRemote(AgentID, GroupID, RoleID);
  352. if (remoteValue != null || m_doRemoteOnly)
  353. return (string) remoteValue;
  354. Dictionary<string, object> values = new Dictionary<string, object>(1);
  355. values["SelectedRoleID"] = RoleID;
  356. QueryFilter filter = new QueryFilter();
  357. filter.andFilters["AgentID"] = AgentID;
  358. filter.andFilters["GroupID"] = GroupID;
  359. data.Update("osgroupmembership", values, null, filter, null, null);
  360. GroupMembersData gdata = GetAgentGroupMemberData(AgentID, GroupID, AgentID);
  361. return gdata == null ? "" : gdata.Title;
  362. }
  363. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  364. public void AddAgentToGroup(UUID requestingAgentID, UUID AgentID, UUID GroupID, UUID RoleID)
  365. {
  366. object remoteValue = DoRemote(requestingAgentID, AgentID, GroupID, RoleID);
  367. if (remoteValue != null || m_doRemoteOnly)
  368. return;
  369. Dictionary<string, object> where = new Dictionary<string, object>(2);
  370. where["AgentID"] = AgentID;
  371. where["GroupID"] = GroupID;
  372. if (data.Query(new[] {"*"}, "osgroupmembership", new QueryFilter
  373. {
  374. andFilters = where
  375. }, null, null, null).Count != 0)
  376. {
  377. MainConsole.Instance.Error("[AGM]: Agent " + AgentID + " is already in " + GroupID);
  378. return;
  379. }
  380. Dictionary<string, object> row = new Dictionary<string, object>(6);
  381. row["GroupID"] = GroupID;
  382. row["AgentID"] = AgentID;
  383. row["SelectedRoleID"] = RoleID;
  384. row["Contribution"] = 0;
  385. row["ListInProfile"] = 1;
  386. row["AcceptNotices"] = 1;
  387. data.Insert("osgroupmembership", row);
  388. // Make sure they're in the Everyone role
  389. AddAgentToRole(requestingAgentID, AgentID, GroupID, UUID.Zero);
  390. // Make sure they're in specified role, if they were invited
  391. if (RoleID != UUID.Zero)
  392. AddAgentToRole(requestingAgentID, AgentID, GroupID, RoleID);
  393. //Set the role they were invited to as their selected role
  394. SetAgentGroupSelectedRole(AgentID, GroupID, RoleID);
  395. SetAgentActiveGroup(AgentID, GroupID);
  396. }
  397. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  398. public bool RemoveAgentFromGroup(UUID requestingAgentID, UUID AgentID, UUID GroupID)
  399. {
  400. //Allow kicking yourself
  401. object remoteValue = DoRemote(requestingAgentID, AgentID, GroupID);
  402. if (remoteValue != null || m_doRemoteOnly)
  403. return remoteValue != null && (bool) remoteValue;
  404. if ((CheckGroupPermissions(requestingAgentID, GroupID, (ulong) GroupPowers.RemoveMember)) ||
  405. (requestingAgentID == AgentID))
  406. {
  407. QueryFilter filter = new QueryFilter();
  408. filter.andFilters["AgentID"] = AgentID;
  409. filter.andFilters["ActiveGroupID"] = GroupID;
  410. Dictionary<string, object> values = new Dictionary<string, object>(1);
  411. values["ActiveGroupID"] = UUID.Zero;
  412. // 1. If group is agent's active group, change active group to uuidZero
  413. data.Update("osagent", values, null, filter, null, null);
  414. filter.andFilters.Remove("ActiveGroupID");
  415. filter.andFilters["GroupID"] = GroupID;
  416. // 2. Remove Agent from group (osgroupmembership)
  417. data.Delete("osgrouprolemembership", filter);
  418. // 3. Remove Agent from all of the groups roles (osgrouprolemembership)
  419. data.Delete("osgroupmembership", filter);
  420. return true;
  421. }
  422. return false;
  423. }
  424. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  425. public void AddRoleToGroup(UUID requestingAgentID, UUID GroupID, UUID RoleID, string NameOf, string Description,
  426. string Title, ulong Powers)
  427. {
  428. object remoteValue = DoRemote(requestingAgentID, GroupID, RoleID, NameOf, Description, Title, Powers);
  429. if (remoteValue != null || m_doRemoteOnly)
  430. return;
  431. if (CheckGroupPermissions(requestingAgentID, GroupID, (ulong) GroupPowers.CreateRole))
  432. {
  433. Dictionary<string, object> row = new Dictionary<string, object>(6);
  434. row["GroupID"] = GroupID;
  435. row["RoleID"] = RoleID;
  436. row["Name"] = NameOf;
  437. row["Description"] = Description != null ? Description : "";
  438. row["Title"] = Title;
  439. row["Powers"] = (long) Powers;
  440. data.Insert("osrole", row);
  441. }
  442. }
  443. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  444. public void UpdateRole(UUID requestingAgentID, UUID GroupID, UUID RoleID, string NameOf, string Desc,
  445. string Title, ulong Powers)
  446. {
  447. object remoteValue = DoRemote(requestingAgentID, GroupID, RoleID, NameOf, Desc, Title, Powers);
  448. if (remoteValue != null || m_doRemoteOnly)
  449. return;
  450. if (CheckGroupPermissions(requestingAgentID, GroupID, (ulong) GroupPowers.RoleProperties))
  451. {
  452. Dictionary<string, object> values = new Dictionary<string, object>();
  453. values["RoleID"] = RoleID;
  454. if (NameOf != null)
  455. {
  456. values["Name"] = NameOf;
  457. }
  458. if (Desc != null)
  459. values["Description"] = Desc;
  460. if (Title != null)
  461. {
  462. values["Title"] = Title;
  463. }
  464. values["Powers"] = Powers.ToString();
  465. QueryFilter filter = new QueryFilter();
  466. filter.andFilters["GroupID"] = GroupID;
  467. filter.andFilters["RoleID"] = RoleID;
  468. data.Update("osrole", values, null, filter, null, null);
  469. }
  470. }
  471. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  472. public void RemoveRoleFromGroup(UUID requestingAgentID, UUID RoleID, UUID GroupID)
  473. {
  474. object remoteValue = DoRemote(requestingAgentID, RoleID, GroupID);
  475. if (remoteValue != null || m_doRemoteOnly)
  476. return;
  477. if (CheckGroupPermissions(requestingAgentID, GroupID, (ulong) GroupPowers.DeleteRole))
  478. {
  479. Dictionary<string, object> values = new Dictionary<string, object>(1);
  480. values["SelectedRoleID"] = UUID.Zero;
  481. QueryFilter ufilter = new QueryFilter();
  482. ufilter.andFilters["GroupID"] = GroupID;
  483. ufilter.andFilters["SelectedRoleID"] = RoleID;
  484. QueryFilter dfilter = new QueryFilter();
  485. dfilter.andFilters["GroupID"] = GroupID;
  486. dfilter.andFilters["RoleID"] = RoleID;
  487. data.Delete("osgrouprolemembership", dfilter);
  488. data.Update("osgroupmembership", values, null, ufilter, null, null);
  489. data.Delete("osrole", dfilter);
  490. }
  491. }
  492. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  493. public void AddAgentToRole(UUID requestingAgentID, UUID AgentID, UUID GroupID, UUID RoleID)
  494. {
  495. object remoteValue = DoRemote(requestingAgentID, AgentID, GroupID, RoleID);
  496. if (remoteValue != null || m_doRemoteOnly)
  497. return;
  498. if (!CheckGroupPermissions(requestingAgentID, GroupID, (ulong) GroupPowers.AssignMember))
  499. {
  500. //This isn't an open and shut case, they could be setting the agent to their role, which would allow for AssignMemberLimited
  501. if (!CheckGroupPermissions(requestingAgentID, GroupID, (ulong) GroupPowers.AssignMemberLimited))
  502. {
  503. GroupProfileData profile = GetGroupProfile(requestingAgentID, GroupID);
  504. if (profile == null || !profile.OpenEnrollment || RoleID != UUID.Zero) //For open enrollment adding
  505. {
  506. MainConsole.Instance.Warn("[AGM]: User " + requestingAgentID + " attempted to add user " +
  507. AgentID +
  508. " to group " + GroupID + ", but did not have permissions to do so!");
  509. return;
  510. }
  511. }
  512. }
  513. QueryFilter filter = new QueryFilter();
  514. filter.andFilters["GroupID"] = GroupID;
  515. filter.andFilters["RoleID"] = RoleID;
  516. filter.andFilters["AgentID"] = AgentID;
  517. //Make sure they arn't already in this role
  518. if (
  519. uint.Parse(data.Query(new[] {"COUNT(AgentID)"}, "osgrouprolemembership", filter, null, null, null)[0]) ==
  520. 0)
  521. {
  522. Dictionary<string, object> row = new Dictionary<string, object>(3);
  523. row["GroupID"] = GroupID;
  524. row["RoleID"] = RoleID;
  525. row["AgentID"] = AgentID;
  526. data.Insert("osgrouprolemembership", row);
  527. }
  528. }
  529. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  530. public void RemoveAgentFromRole(UUID requestingAgentID, UUID AgentID, UUID GroupID, UUID RoleID)
  531. {
  532. object remoteValue = DoRemote(requestingAgentID, AgentID, GroupID, RoleID);
  533. if (remoteValue != null || m_doRemoteOnly)
  534. return;
  535. if (CheckGroupPermissions(requestingAgentID, GroupID, (ulong) GroupPowers.AssignMember))
  536. {
  537. Dictionary<string, object> values = new Dictionary<string, object>(1);
  538. values["SelectedRoleID"] = UUID.Zero;
  539. QueryFilter filter = new QueryFilter();
  540. filter.andFilters["AgentID"] = AgentID;
  541. filter.andFilters["GroupID"] = GroupID;
  542. filter.andFilters["SelectedRoleID"] = RoleID;
  543. data.Update("osgroupmembership", values, null, filter, null, null);
  544. filter.andFilters.Remove("SelectedRoleID");
  545. filter.andFilters["RoleID"] = RoleID;
  546. data.Delete("osgrouprolemembership", filter);
  547. }
  548. }
  549. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  550. public void SetAgentGroupInfo(UUID requestingAgentID, UUID AgentID, UUID GroupID, int AcceptNotices,
  551. int ListInProfile)
  552. {
  553. object remoteValue = DoRemote(requestingAgentID, AgentID, GroupID, AcceptNotices, ListInProfile);
  554. if (remoteValue != null || m_doRemoteOnly)
  555. return;
  556. if (!CheckGroupPermissions(requestingAgentID, GroupID, (ulong) GroupPowers.ChangeIdentity))
  557. {
  558. return;
  559. }
  560. Dictionary<string, object> values = new Dictionary<string, object>(3);
  561. values["AgentID"] = AgentID;
  562. values["AcceptNotices"] = AcceptNotices;
  563. values["ListInProfile"] = ListInProfile;
  564. QueryFilter filter = new QueryFilter();
  565. // these look the wrong way around ~ SignpostMarv
  566. filter.andFilters["GroupID"] = AgentID;
  567. filter.andFilters["AgentID"] = GroupID;
  568. data.Update("osgroupmembership", values, null, filter, null, null);
  569. }
  570. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  571. public void AddAgentGroupInvite(UUID requestingAgentID, UUID inviteID, UUID GroupID, UUID roleID, UUID AgentID,
  572. string FromAgentName)
  573. {
  574. object remoteValue = DoRemote(requestingAgentID, inviteID, GroupID, roleID, AgentID, FromAgentName);
  575. if (remoteValue != null || m_doRemoteOnly)
  576. return;
  577. if (CheckGroupPermissions(requestingAgentID, GroupID, (ulong) GroupPowers.Invite))
  578. {
  579. QueryFilter filter = new QueryFilter();
  580. filter.andFilters["AgentID"] = AgentID;
  581. filter.andFilters["GroupID"] = GroupID;
  582. data.Delete("osgroupinvite", filter);
  583. Dictionary<string, object> row = new Dictionary<string, object>(6);
  584. row["InviteID"] = inviteID;
  585. row["GroupID"] = GroupID;
  586. row["RoleID"] = roleID;
  587. row["AgentID"] = AgentID;
  588. row["TMStamp"] = Util.UnixTimeSinceEpoch();
  589. row["FromAgentName"] = FromAgentName;
  590. data.Insert("osgroupinvite", row);
  591. }
  592. }
  593. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  594. public void RemoveAgentInvite(UUID requestingAgentID, UUID inviteID)
  595. {
  596. object remoteValue = DoRemote(requestingAgentID, inviteID);
  597. if (remoteValue != null || m_doRemoteOnly)
  598. return;
  599. QueryFilter filter = new QueryFilter();
  600. filter.andFilters["InviteID"] = inviteID;
  601. data.Delete("osgroupinvite", filter);
  602. }
  603. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  604. public void AddGroupProposal(UUID agentID, GroupProposalInfo info)
  605. {
  606. object remoteValue = DoRemote(agentID, info);
  607. if (remoteValue != null || m_doRemoteOnly)
  608. return;
  609. if (CheckGroupPermissions(agentID, info.GroupID, (ulong) GroupPowers.StartProposal))
  610. GenericUtils.AddGeneric(info.GroupID, "Proposal", info.VoteID.ToString(), info.ToOSD(), data);
  611. }
  612. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  613. public List<GroupProposalInfo> GetActiveProposals(UUID agentID, UUID groupID)
  614. {
  615. object remoteValue = DoRemote(agentID, groupID);
  616. if (remoteValue != null || m_doRemoteOnly)
  617. return (List<GroupProposalInfo>) remoteValue;
  618. if (!CheckGroupPermissions(agentID, groupID, (ulong) GroupPowers.VoteOnProposal))
  619. return new List<GroupProposalInfo>();
  620. List<GroupProposalInfo> proposals = GenericUtils.GetGenerics<GroupProposalInfo>(groupID, "Proposal", data);
  621. proposals = (from p in proposals where p.Ending > DateTime.Now select p).ToList();
  622. foreach (GroupProposalInfo p in proposals)
  623. p.VoteCast = GetHasVoted(agentID, p);
  624. return proposals; //Return only ones that are still running
  625. }
  626. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  627. public List<GroupProposalInfo> GetInactiveProposals(UUID agentID, UUID groupID)
  628. {
  629. object remoteValue = DoRemote(agentID, groupID);
  630. if (remoteValue != null || m_doRemoteOnly)
  631. return (List<GroupProposalInfo>) remoteValue;
  632. if (!CheckGroupPermissions(agentID, groupID, (ulong) GroupPowers.VoteOnProposal))
  633. return new List<GroupProposalInfo>();
  634. List<GroupProposalInfo> proposals = GenericUtils.GetGenerics<GroupProposalInfo>(groupID, "Proposal", data);
  635. proposals = (from p in proposals where p.Ending < DateTime.Now select p).ToList();
  636. List<GroupProposalInfo> proposalsNeedingResults =
  637. (from p in proposals where !p.HasCalculatedResult select p).ToList();
  638. foreach (GroupProposalInfo p in proposalsNeedingResults)
  639. {
  640. List<OpenMetaverse.StructuredData.OSDMap> maps = GenericUtils.GetGenerics(p.GroupID, p.VoteID.ToString(),
  641. data);
  642. int yes = 0;
  643. int no = 0;
  644. foreach (OpenMetaverse.StructuredData.OSDMap vote in maps)
  645. {
  646. if (vote["Vote"].AsString().ToLower() == "yes")
  647. yes++;
  648. else if (vote["Vote"].AsString().ToLower() == "no")
  649. no++;
  650. }
  651. if (yes + no < p.Quorum)
  652. p.Result = false;
  653. /*if (yes > no)
  654. p.Result = true;
  655. else
  656. p.Result = false;*/
  657. p.HasCalculatedResult = true;
  658. GenericUtils.AddGeneric(p.GroupID, "Proposal", p.VoteID.ToString(), p.ToOSD(), data);
  659. }
  660. foreach (GroupProposalInfo p in proposals)
  661. p.VoteCast = GetHasVoted(agentID, p);
  662. return proposals; //Return only ones that are still running
  663. }
  664. private string GetHasVoted(UUID agentID, GroupProposalInfo p)
  665. {
  666. OpenMetaverse.StructuredData.OSDMap map = GenericUtils.GetGeneric(p.GroupID, p.VoteID.ToString(),
  667. agentID.ToString(), data);
  668. if (map != null)
  669. return map["Vote"];
  670. return "";
  671. }
  672. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  673. public void VoteOnActiveProposals(UUID agentID, UUID groupID, UUID proposalID, string vote)
  674. {
  675. object remoteValue = DoRemote(agentID, groupID, proposalID, vote);
  676. if (remoteValue != null || m_doRemoteOnly)
  677. return;
  678. if (!CheckGroupPermissions(agentID, groupID, (ulong) GroupPowers.VoteOnProposal))
  679. return;
  680. OpenMetaverse.StructuredData.OSDMap map = new OpenMetaverse.StructuredData.OSDMap();
  681. map["Vote"] = vote;
  682. GenericUtils.AddGeneric(groupID, proposalID.ToString(), agentID.ToString(), map, data);
  683. }
  684. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  685. public uint GetNumberOfGroupNotices(UUID requestingAgentID, UUID GroupID)
  686. {
  687. object remoteValue = DoRemote(requestingAgentID, GroupID);
  688. if (remoteValue != null || m_doRemoteOnly)
  689. return (uint) remoteValue; // note: this is bad, you can't cast a null object to a uint
  690. List<UUID> GroupIDs = new List<UUID> {GroupID};
  691. return GetNumberOfGroupNotices(requestingAgentID, GroupIDs);
  692. }
  693. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  694. public uint GetNumberOfGroupNotices(UUID requestingAgentID, List<UUID> GroupIDs)
  695. {
  696. object remoteValue = DoRemote(requestingAgentID, GroupIDs);
  697. if (remoteValue != null || m_doRemoteOnly)
  698. return (uint) remoteValue; // note: this is bad, you can't cast a null object to a uint
  699. bool had = GroupIDs.Count > 0;
  700. List<UUID> groupIDs = new List<UUID>();
  701. if (!agentsCanBypassGroupNoticePermsCheck.Contains(requestingAgentID))
  702. {
  703. #if (!ISWIN)
  704. foreach (UUID GroupID in GroupIDs)
  705. {
  706. if (CheckGroupPermissions(requestingAgentID, GroupID, (ulong)GroupPowers.ReceiveNotices))
  707. groupIDs.Add(GroupID);
  708. }
  709. #else
  710. groupIDs.AddRange(
  711. GroupIDs.Where(
  712. GroupID => CheckGroupPermissions(requestingAgentID, GroupID, (ulong) GroupPowers.ReceiveNotices)));
  713. #endif
  714. }
  715. else
  716. {
  717. groupIDs = GroupIDs;
  718. }
  719. if (had && groupIDs.Count == 0)
  720. {
  721. return 0;
  722. }
  723. QueryFilter filter = new QueryFilter();
  724. List<object> filterGroupIDs = new List<object>(groupIDs.Count);
  725. filterGroupIDs.AddRange(groupIDs.Cast<object>());
  726. if (filterGroupIDs.Count > 0)
  727. {
  728. filter.orMultiFilters["GroupID"] = filterGroupIDs;
  729. }
  730. return uint.Parse(data.Query(new[] {"COUNT(NoticeID)"}, "osgroupnotice", filter, null, null, null)[0]);
  731. }
  732. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  733. public uint GetNumberOfGroups(UUID requestingAgentID, Dictionary<string, bool> boolFields)
  734. {
  735. object remoteValue = DoRemote(requestingAgentID, boolFields);
  736. if (remoteValue != null || m_doRemoteOnly)
  737. return (uint) remoteValue; // note: this is bad, you can't cast a null object to a uint
  738. QueryFilter filter = new QueryFilter();
  739. string[] BoolFields = {"OpenEnrollment", "ShowInList", "AllowPublish", "MaturePublish"};
  740. foreach (string field in BoolFields)
  741. {
  742. if (boolFields.ContainsKey(field))
  743. {
  744. filter.andFilters[field] = boolFields[field] ? "1" : "0";
  745. }
  746. }
  747. return uint.Parse(data.Query(new[] {"COUNT(GroupID)"}, "osgroup", filter, null, null, null)[0]);
  748. }
  749. private static GroupRecord GroupRecordQueryResult2GroupRecord(List<String> result)
  750. {
  751. return new GroupRecord
  752. {
  753. GroupID = UUID.Parse(result[0]),
  754. GroupName = result[1],
  755. Charter = result[2],
  756. GroupPicture = UUID.Parse(result[3]),
  757. FounderID = UUID.Parse(result[4]),
  758. MembershipFee = int.Parse(result[5]),
  759. OpenEnrollment = int.Parse(result[6]) == 1,
  760. ShowInList = int.Parse(result[7]) == 1,
  761. AllowPublish = int.Parse(result[8]) == 1,
  762. MaturePublish = int.Parse(result[9]) == 1,
  763. OwnerRoleID = UUID.Parse(result[10])
  764. };
  765. }
  766. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  767. public GroupRecord GetGroupRecord(UUID requestingAgentID, UUID GroupID, string GroupName)
  768. {
  769. object remoteValue = DoRemote(requestingAgentID, GroupID, GroupName);
  770. if (remoteValue != null || m_doRemoteOnly)
  771. return (GroupRecord) remoteValue;
  772. QueryFilter filter = new QueryFilter();
  773. if (GroupID != UUID.Zero)
  774. {
  775. filter.andFilters["GroupID"] = GroupID;
  776. }
  777. if (!string.IsNullOrEmpty(GroupName))
  778. {
  779. filter.andFilters["Name"] = GroupName;
  780. }
  781. if (filter.Count == 0)
  782. {
  783. return null;
  784. }
  785. List<string> osgroupsData = data.Query(new[]
  786. {
  787. "GroupID",
  788. "Name",
  789. "Charter",
  790. "InsigniaID",
  791. "FounderID",
  792. "MembershipFee",
  793. "OpenEnrollment",
  794. "ShowInList",
  795. "AllowPublish",
  796. "MaturePublish",
  797. "OwnerRoleID"
  798. }, "osgroup", filter, null, null, null);
  799. return (osgroupsData.Count == 0) ? null : GroupRecordQueryResult2GroupRecord(osgroupsData);
  800. }
  801. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  802. public List<GroupRecord> GetGroupRecords(UUID requestingAgentID, uint start, uint count,
  803. Dictionary<string, bool> sort, Dictionary<string, bool> boolFields)
  804. {
  805. // List<string> filter = new List<string>();
  806. object remoteValue = DoRemote(requestingAgentID, start, count, boolFields);
  807. if (remoteValue != null || m_doRemoteOnly)
  808. return (List<GroupRecord>) remoteValue;
  809. string[] sortAndBool = {"OpenEnrollment", "MaturePublish"};
  810. string[] BoolFields = {"OpenEnrollment", "ShowInList", "AllowPublish", "MaturePublish"};
  811. foreach (string field in sortAndBool)
  812. {
  813. if (boolFields.ContainsKey(field) && sort.ContainsKey(field))
  814. {
  815. sort.Remove(field);
  816. }
  817. }
  818. QueryFilter filter = new QueryFilter();
  819. foreach (string field in BoolFields)
  820. {
  821. if (boolFields.ContainsKey(field))
  822. {
  823. filter.andFilters[field] = boolFields[field] ? "1" : "0";
  824. }
  825. }
  826. List<GroupRecord> Reply = new List<GroupRecord>();
  827. List<string> osgroupsData = data.Query(new[]
  828. {
  829. "GroupID",
  830. "Name",
  831. "Charter",
  832. "InsigniaID",
  833. "FounderID",
  834. "MembershipFee",
  835. "OpenEnrollment",
  836. "ShowInList",
  837. "AllowPublish",
  838. "MaturePublish",
  839. "OwnerRoleID"
  840. }, "osgroup", filter, sort, start, count);
  841. if (osgroupsData.Count < 11)
  842. {
  843. return Reply;
  844. }
  845. for (int i = 0; i < osgroupsData.Count; i += 11)
  846. {
  847. Reply.Add(GroupRecordQueryResult2GroupRecord(osgroupsData.GetRange(i, 11)));
  848. }
  849. return Reply;
  850. }
  851. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  852. public List<GroupRecord> GetGroupRecords(UUID requestingAgentID, List<UUID> GroupIDs)
  853. {
  854. object remoteValue = DoRemote(requestingAgentID, GroupIDs);
  855. if (remoteValue != null || m_doRemoteOnly)
  856. return (List<GroupRecord>) remoteValue;
  857. List<GroupRecord> Reply = new List<GroupRecord>(0);
  858. if (GroupIDs.Count <= 0)
  859. {
  860. return Reply;
  861. }
  862. QueryFilter filter = new QueryFilter();
  863. filter.orMultiFilters["GroupID"] = new List<object>();
  864. foreach (UUID groupID in GroupIDs)
  865. {
  866. filter.orMultiFilters["GroupID"].Add(groupID);
  867. }
  868. List<string> osgroupsData = data.Query(new[]
  869. {
  870. "GroupID",
  871. "Name",
  872. "Charter",
  873. "InsigniaID",
  874. "FounderID",
  875. "MembershipFee",
  876. "OpenEnrollment",
  877. "ShowInList",
  878. "AllowPublish",
  879. "MaturePublish",
  880. "OwnerRoleID"
  881. }, "osgroup", filter, null, null, null);
  882. if (osgroupsData.Count < 11)
  883. {
  884. return Reply;
  885. }
  886. for (int i = 0; i < osgroupsData.Count; i += 11)
  887. {
  888. Reply.Add(GroupRecordQueryResult2GroupRecord(osgroupsData.GetRange(i, 11)));
  889. }
  890. return Reply;
  891. }
  892. [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
  893. public GroupProfileData GetMemberGroupProfile(UUID requestingAgentID, UUID GroupID, UUID AgentID)
  894. {
  895. object remoteValue = DoRemote(requestingAgentID, GroupID, AgentID);
  896. if (remoteValue != null || m_doRemoteOnly)
  897. return (GroupProfileData) remoteValue;
  898. if (!CheckGroupPermissions(requestingAgentID, GroupID, (ulong) GroupPowers.MemberVisible))
  899. return new GroupProfileData();
  900. GroupProfileData GPD = new GroupProfileData();
  901. GroupRecord record = GetGroupRecord(requestingAgentID, GroupID, null);
  902. QueryFilter filter1 = new QueryFilter();
  903. filter1.andFilters["GroupID"] = A

Large files files are truncated, but you can click here to view the full file