PageRenderTime 47ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

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

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