/Aurora/Services/DataService/Connectors/Local/LocalGroupsServiceConnector.cs
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
- /*
- * Copyright (c) Contributors, http://aurora-sim.org/
- * See CONTRIBUTORS.TXT for a full list of copyright holders.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the Aurora-Sim Project nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
- using Aurora.Framework;
- using Aurora.Framework.ClientInterfaces;
- using Aurora.Framework.ConsoleFramework;
- using Aurora.Framework.DatabaseInterfaces;
- using Aurora.Framework.Modules;
- using Aurora.Framework.PresenceInfo;
- using Aurora.Framework.Services;
- using Aurora.Framework.Utilities;
- using Nini.Config;
- using OpenMetaverse;
- using System;
- using System.Collections.Generic;
- using System.Linq;
-
- namespace Aurora.Services.DataService
- {
- public class LocalGroupsServiceConnector : ConnectorBase, IGroupsServiceConnector
- {
- #region Declares
-
- private IGenericData data;
- private List<UUID> agentsCanBypassGroupNoticePermsCheck = new List<UUID>();
-
- #endregion
-
- #region IAuroraDataPlugin members
-
- public void Initialize(IGenericData GenericData, IConfigSource source, IRegistryCore simBase,
- string defaultConnectionString)
- {
- data = GenericData;
-
- if (source.Configs[Name] != null)
- {
- defaultConnectionString = source.Configs[Name].GetString("ConnectionString", defaultConnectionString);
- }
- if (source.Configs["Groups"] != null)
- {
- agentsCanBypassGroupNoticePermsCheck =
- Util.ConvertToList(source.Configs["Groups"].GetString("AgentsCanBypassGroupNoticePermsCheck", ""))
- .ConvertAll(x => new UUID(x));
- }
-
- if (data != null)
- data.ConnectToDatabase(defaultConnectionString, "Groups",
- source.Configs["AuroraConnectors"].GetBoolean("ValidateTables", true));
-
- Framework.Utilities.DataManager.RegisterPlugin(Name + "Local", this);
-
- if (source.Configs["AuroraConnectors"].GetString("GroupsConnector", "LocalConnector") == "LocalConnector")
- {
- Framework.Utilities.DataManager.RegisterPlugin(this);
- }
- Init(simBase, Name);
- }
-
- public string Name
- {
- get { return "IGroupsServiceConnector"; }
- }
-
- #endregion
-
- #region IGroupsServiceConnector Members
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public void CreateGroup(UUID groupID, string name, string charter, bool showInList, UUID insigniaID,
- int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish,
- UUID founderID, UUID OwnerRoleID)
- {
- object remoteValue = DoRemote(groupID, name, charter, showInList, insigniaID, membershipFee, openEnrollment,
- allowPublish, maturePublish, founderID, OwnerRoleID);
- if (remoteValue != null || m_doRemoteOnly)
- return;
-
- // Would this be cleaner as (GroupPowers)ulong.MaxValue;
- ulong OwnerPowers = (ulong) (GroupPowers.Accountable
- | GroupPowers.AllowEditLand
- | GroupPowers.AllowFly
- | GroupPowers.AllowLandmark
- | GroupPowers.AllowRez
- | GroupPowers.AllowSetHome
- | GroupPowers.AllowVoiceChat
- | GroupPowers.AssignMember
- | GroupPowers.AssignMemberLimited
- | GroupPowers.ChangeActions
- | GroupPowers.ChangeIdentity
- | GroupPowers.ChangeMedia
- | GroupPowers.ChangeOptions
- | GroupPowers.CreateRole
- | GroupPowers.DeedObject
- | GroupPowers.DeleteRole
- | GroupPowers.Eject
- | GroupPowers.FindPlaces
- | GroupPowers.Invite
- | GroupPowers.JoinChat
- | GroupPowers.LandChangeIdentity
- | GroupPowers.LandDeed
- | GroupPowers.LandDivideJoin
- | GroupPowers.LandEdit
- | GroupPowers.LandEjectAndFreeze
- | GroupPowers.LandGardening
- | GroupPowers.LandManageAllowed
- | GroupPowers.LandManageBanned
- | GroupPowers.LandManagePasses
- | GroupPowers.LandOptions
- | GroupPowers.LandRelease
- | GroupPowers.LandSetSale
- | GroupPowers.ModerateChat
- | GroupPowers.ObjectManipulate
- | GroupPowers.ObjectSetForSale
- | GroupPowers.ReceiveNotices
- | GroupPowers.RemoveMember
- | GroupPowers.ReturnGroupOwned
- | GroupPowers.ReturnGroupSet
- | GroupPowers.ReturnNonGroup
- | GroupPowers.RoleProperties
- | GroupPowers.SendNotices
- | GroupPowers.SetLandingPoint
- | GroupPowers.StartProposal
- | GroupPowers.VoteOnProposal);
-
- ulong EveryonePowers = (ulong) (GroupPowers.AllowSetHome |
- GroupPowers.Accountable |
- GroupPowers.JoinChat |
- GroupPowers.AllowVoiceChat |
- GroupPowers.ReceiveNotices |
- GroupPowers.StartProposal |
- GroupPowers.VoteOnProposal);
-
- Dictionary<string, object> row = new Dictionary<string, object>(11);
- row["GroupID"] = groupID;
- row["Name"] = name;
- row["Charter"] = charter ?? "";
- row["InsigniaID"] = insigniaID;
- row["FounderID"] = founderID;
- row["MembershipFee"] = membershipFee;
- row["OpenEnrollment"] = openEnrollment ? 1 : 0;
- row["ShowInList"] = showInList ? 1 : 0;
- row["AllowPublish"] = allowPublish ? 1 : 0;
- row["MaturePublish"] = maturePublish ? 1 : 0;
- row["OwnerRoleID"] = OwnerRoleID;
-
- data.Insert("osgroup", row);
-
- //Add everyone role to group
- AddRoleToGroup(founderID, groupID, UUID.Zero, "Everyone", "Everyone in the group is in the everyone role.",
- "Member of " + name, EveryonePowers);
-
- const ulong groupPowers = 296868139497678;
-
- UUID officersRole = UUID.Random();
- //Add officers role to group
- AddRoleToGroup(founderID, groupID, officersRole, "Officers",
- "The officers of the group, with more powers than regular members.", "Officer of " + name,
- groupPowers);
-
- //Add owner role to group
- AddRoleToGroup(founderID, groupID, OwnerRoleID, "Owners", "Owners of " + name, "Owner of " + name,
- OwnerPowers);
-
- //Add owner to the group as owner
- AddAgentToGroup(founderID, founderID, groupID, OwnerRoleID);
- AddAgentToRole(founderID, founderID, groupID, officersRole);
-
- SetAgentGroupSelectedRole(founderID, groupID, OwnerRoleID);
-
- SetAgentActiveGroup(founderID, groupID);
- }
-
- //[CanBeReflected(ThreatLevel = ThreatLevel.Full)]
- public void UpdateGroupFounder(UUID groupID, UUID newOwner, bool keepOldOwnerInGroup)
- {
- /*object remoteValue = DoRemote(groupID, newOwner, keepOldOwnerInGroup);
- if (remoteValue != null || m_doRemoteOnly)
- return;*/
-
- GroupRecord record = GetGroupRecord(UUID.Zero, groupID, "");
- bool newUserExists = GetAgentGroupMemberData(newOwner, groupID, newOwner) != null;
-
- Dictionary<string, object> values = new Dictionary<string, object>(1);
- values["FounderID"] = newOwner;
- QueryFilter filter = new QueryFilter();
- filter.andFilters["GroupID"] = groupID;
-
- data.Update("osgroup", values, null, filter, null, null);
-
- if (!newUserExists)
- AddAgentToGroup(newOwner, newOwner, groupID, record.OwnerRoleID);
- else
- AddAgentToRole(newOwner, newOwner, groupID, record.OwnerRoleID);
-
- if (!keepOldOwnerInGroup)
- RemoveAgentFromGroup(newOwner, record.FounderID, groupID);
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public void UpdateGroup(UUID requestingAgentID, UUID groupID, string charter, int showInList, UUID insigniaID,
- int membershipFee, int openEnrollment, int allowPublish, int maturePublish)
- {
- object remoteValue = DoRemote(requestingAgentID, groupID, charter, showInList, insigniaID, membershipFee,
- openEnrollment, allowPublish, maturePublish);
- if (remoteValue != null || m_doRemoteOnly)
- return;
-
- if (CheckGroupPermissions(requestingAgentID, groupID,
- (ulong) (GroupPowers.ChangeOptions | GroupPowers.ChangeIdentity)))
- {
- Dictionary<string, object> values = new Dictionary<string, object>(6);
- values["Charter"] = charter;
- values["InsigniaID"] = insigniaID;
- values["MembershipFee"] = membershipFee;
- values["OpenEnrollment"] = openEnrollment;
- values["ShowInList"] = showInList;
- values["AllowPublish"] = allowPublish;
- values["MaturePublish"] = maturePublish;
-
- QueryFilter filter = new QueryFilter();
- filter.andFilters["GroupID"] = groupID;
-
- data.Update("osgroup", values, null, filter, null, null);
- }
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public void AddGroupNotice(UUID requestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject,
- string message, UUID ItemID, int AssetType, string ItemName)
- {
- object remoteValue = DoRemote(requestingAgentID, groupID, noticeID, fromName, subject, message, ItemID,
- AssetType, ItemName);
- if (remoteValue != null || m_doRemoteOnly)
- return;
-
- if (CheckGroupPermissions(requestingAgentID, groupID, (ulong) GroupPowers.SendNotices))
- {
- Dictionary<string, object> row = new Dictionary<string, object>(10);
- row["GroupID"] = groupID;
- row["NoticeID"] = noticeID == UUID.Zero ? UUID.Random() : noticeID;
- row["Timestamp"] = ((uint) Util.UnixTimeSinceEpoch());
- row["FromName"] = fromName;
- row["Subject"] = subject;
- row["Message"] = message;
- row["HasAttachment"] = (ItemID != UUID.Zero) ? 1 : 0;
- row["ItemID"] = ItemID;
- row["AssetType"] = AssetType;
- row["ItemName"] = ItemName == null ? "" : ItemName;
-
- data.Insert("osgroupnotice", row);
- }
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.High)]
- public bool EditGroupNotice(UUID requestingAgentID, UUID groupID, UUID noticeID, string subject, string message)
- {
- object remoteValue = DoRemote(requestingAgentID, groupID, noticeID, subject, message);
- if (remoteValue != null || m_doRemoteOnly)
- {
- return (bool) remoteValue;
- }
-
- if (!agentsCanBypassGroupNoticePermsCheck.Contains(requestingAgentID) &&
- !CheckGroupPermissions(requestingAgentID, groupID, (ulong) GroupPowers.SendNotices))
- {
- MainConsole.Instance.TraceFormat("Permission check failed when trying to edit group notice {0}.",
- noticeID);
- return false;
- }
-
- GroupNoticeInfo GNI = GetGroupNotice(requestingAgentID, noticeID);
- if (GNI == null)
- {
- MainConsole.Instance.TraceFormat("Could not find group notice {0}", noticeID);
- return false;
- }
- else if (GNI.GroupID != groupID)
- {
- MainConsole.Instance.TraceFormat("Group notice {0} group ID {1} does not match supplied group ID {2}",
- noticeID, GNI.GroupID, groupID);
- return false;
- }
- else if (subject.Trim() == string.Empty || message.Trim() == string.Empty)
- {
- MainConsole.Instance.TraceFormat("Could not edit group notice {0}, message or subject was empty",
- noticeID);
- return false;
- }
-
- QueryFilter filter = new QueryFilter();
- filter.andFilters["GroupID"] = groupID;
- filter.andFilters["NoticeID"] = noticeID;
-
- Dictionary<string, object> update = new Dictionary<string, object>(2);
- update["Subject"] = subject.Trim();
- update["Message"] = message.Trim();
-
- return data.Update("osgroupnotice", update, null, filter, null, null);
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.High)]
- public bool RemoveGroupNotice(UUID requestingAgentID, UUID groupID, UUID noticeID)
- {
- object remoteValue = DoRemote(requestingAgentID, groupID, noticeID);
- if (remoteValue != null || m_doRemoteOnly)
- {
- return (bool) remoteValue;
- }
-
- if (!agentsCanBypassGroupNoticePermsCheck.Contains(requestingAgentID) &&
- !CheckGroupPermissions(requestingAgentID, groupID, (ulong) GroupPowers.SendNotices))
- {
- MainConsole.Instance.TraceFormat("Permission check failed when trying to edit group notice {0}.",
- noticeID);
- return false;
- }
-
- GroupNoticeInfo GNI = GetGroupNotice(requestingAgentID, noticeID);
- if (GNI == null)
- {
- MainConsole.Instance.TraceFormat("Could not find group notice {0}", noticeID);
- return false;
- }
- else if (GNI.GroupID != groupID)
- {
- MainConsole.Instance.TraceFormat("Group notice {0} group ID {1} does not match supplied group ID {2}",
- noticeID, GNI.GroupID, groupID);
- return false;
- }
-
- QueryFilter filter = new QueryFilter();
- filter.andFilters["GroupID"] = groupID;
- filter.andFilters["NoticeID"] = noticeID;
-
- return data.Delete("osgroupnotice", filter);
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public string SetAgentActiveGroup(UUID AgentID, UUID GroupID)
- {
- object remoteValue = DoRemote(AgentID, GroupID);
- if (remoteValue != null || m_doRemoteOnly)
- return (string) remoteValue;
-
- QueryFilter filter = new QueryFilter();
- filter.andFilters["AgentID"] = AgentID;
- if (data.Query(new[] {"*"}, "osagent", filter, null, null, null).Count != 0)
- {
- Dictionary<string, object> values = new Dictionary<string, object>(1);
- values["ActiveGroupID"] = GroupID;
-
- data.Update("osagent", values, null, filter, null, null);
- }
- else
- {
- Dictionary<string, object> row = new Dictionary<string, object>(2);
- row["AgentID"] = AgentID;
- row["ActiveGroupID"] = GroupID;
- data.Insert("osagent", row);
- }
- GroupMembersData gdata = GetAgentGroupMemberData(AgentID, GroupID, AgentID);
- return gdata == null ? "" : gdata.Title;
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public UUID GetAgentActiveGroup(UUID RequestingAgentID, UUID AgentID)
- {
- object remoteValue = DoRemote(RequestingAgentID, AgentID);
- if (remoteValue != null || m_doRemoteOnly)
- return (UUID) remoteValue; // note: this is bad, you can't cast a null object to a UUID
-
- QueryFilter filter = new QueryFilter();
- filter.andFilters["AgentID"] = AgentID;
- List<string> groups = data.Query(new string[1] {"ActiveGroupID"}, "osagent", filter, null, null, null);
-
- return (groups.Count != 0) ? UUID.Parse(groups[0]) : UUID.Zero;
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public string SetAgentGroupSelectedRole(UUID AgentID, UUID GroupID, UUID RoleID)
- {
- object remoteValue = DoRemote(AgentID, GroupID, RoleID);
- if (remoteValue != null || m_doRemoteOnly)
- return (string) remoteValue;
-
- Dictionary<string, object> values = new Dictionary<string, object>(1);
- values["SelectedRoleID"] = RoleID;
-
- QueryFilter filter = new QueryFilter();
- filter.andFilters["AgentID"] = AgentID;
- filter.andFilters["GroupID"] = GroupID;
-
- data.Update("osgroupmembership", values, null, filter, null, null);
-
- GroupMembersData gdata = GetAgentGroupMemberData(AgentID, GroupID, AgentID);
- return gdata == null ? "" : gdata.Title;
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public void AddAgentToGroup(UUID requestingAgentID, UUID AgentID, UUID GroupID, UUID RoleID)
- {
- object remoteValue = DoRemote(requestingAgentID, AgentID, GroupID, RoleID);
- if (remoteValue != null || m_doRemoteOnly)
- return;
-
- Dictionary<string, object> where = new Dictionary<string, object>(2);
- where["AgentID"] = AgentID;
- where["GroupID"] = GroupID;
-
- if (data.Query(new[] {"*"}, "osgroupmembership", new QueryFilter
- {
- andFilters = where
- }, null, null, null).Count != 0)
- {
- MainConsole.Instance.Error("[AGM]: Agent " + AgentID + " is already in " + GroupID);
- return;
- }
- Dictionary<string, object> row = new Dictionary<string, object>(6);
- row["GroupID"] = GroupID;
- row["AgentID"] = AgentID;
- row["SelectedRoleID"] = RoleID;
- row["Contribution"] = 0;
- row["ListInProfile"] = 1;
- row["AcceptNotices"] = 1;
- data.Insert("osgroupmembership", row);
-
- // Make sure they're in the Everyone role
- AddAgentToRole(requestingAgentID, AgentID, GroupID, UUID.Zero);
- // Make sure they're in specified role, if they were invited
- if (RoleID != UUID.Zero)
- AddAgentToRole(requestingAgentID, AgentID, GroupID, RoleID);
- //Set the role they were invited to as their selected role
- SetAgentGroupSelectedRole(AgentID, GroupID, RoleID);
- SetAgentActiveGroup(AgentID, GroupID);
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public bool RemoveAgentFromGroup(UUID requestingAgentID, UUID AgentID, UUID GroupID)
- {
- //Allow kicking yourself
- object remoteValue = DoRemote(requestingAgentID, AgentID, GroupID);
- if (remoteValue != null || m_doRemoteOnly)
- return remoteValue != null && (bool) remoteValue;
-
- if ((CheckGroupPermissions(requestingAgentID, GroupID, (ulong) GroupPowers.RemoveMember)) ||
- (requestingAgentID == AgentID))
- {
- QueryFilter filter = new QueryFilter();
- filter.andFilters["AgentID"] = AgentID;
- filter.andFilters["ActiveGroupID"] = GroupID;
-
- Dictionary<string, object> values = new Dictionary<string, object>(1);
- values["ActiveGroupID"] = UUID.Zero;
-
- // 1. If group is agent's active group, change active group to uuidZero
- data.Update("osagent", values, null, filter, null, null);
-
- filter.andFilters.Remove("ActiveGroupID");
- filter.andFilters["GroupID"] = GroupID;
-
- // 2. Remove Agent from group (osgroupmembership)
- data.Delete("osgrouprolemembership", filter);
-
- // 3. Remove Agent from all of the groups roles (osgrouprolemembership)
- data.Delete("osgroupmembership", filter);
-
- return true;
- }
- return false;
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public void AddRoleToGroup(UUID requestingAgentID, UUID GroupID, UUID RoleID, string NameOf, string Description,
- string Title, ulong Powers)
- {
- object remoteValue = DoRemote(requestingAgentID, GroupID, RoleID, NameOf, Description, Title, Powers);
- if (remoteValue != null || m_doRemoteOnly)
- return;
-
- if (CheckGroupPermissions(requestingAgentID, GroupID, (ulong) GroupPowers.CreateRole))
- {
- Dictionary<string, object> row = new Dictionary<string, object>(6);
- row["GroupID"] = GroupID;
- row["RoleID"] = RoleID;
- row["Name"] = NameOf;
- row["Description"] = Description != null ? Description : "";
- row["Title"] = Title;
- row["Powers"] = (long) Powers;
- data.Insert("osrole", row);
- }
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public void UpdateRole(UUID requestingAgentID, UUID GroupID, UUID RoleID, string NameOf, string Desc,
- string Title, ulong Powers)
- {
- object remoteValue = DoRemote(requestingAgentID, GroupID, RoleID, NameOf, Desc, Title, Powers);
- if (remoteValue != null || m_doRemoteOnly)
- return;
-
- if (CheckGroupPermissions(requestingAgentID, GroupID, (ulong) GroupPowers.RoleProperties))
- {
- Dictionary<string, object> values = new Dictionary<string, object>();
- values["RoleID"] = RoleID;
- if (NameOf != null)
- {
- values["Name"] = NameOf;
- }
- if (Desc != null)
- values["Description"] = Desc;
-
- if (Title != null)
- {
- values["Title"] = Title;
- }
- values["Powers"] = Powers.ToString();
-
- QueryFilter filter = new QueryFilter();
- filter.andFilters["GroupID"] = GroupID;
- filter.andFilters["RoleID"] = RoleID;
-
- data.Update("osrole", values, null, filter, null, null);
- }
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public void RemoveRoleFromGroup(UUID requestingAgentID, UUID RoleID, UUID GroupID)
- {
- object remoteValue = DoRemote(requestingAgentID, RoleID, GroupID);
- if (remoteValue != null || m_doRemoteOnly)
- return;
-
- if (CheckGroupPermissions(requestingAgentID, GroupID, (ulong) GroupPowers.DeleteRole))
- {
- Dictionary<string, object> values = new Dictionary<string, object>(1);
- values["SelectedRoleID"] = UUID.Zero;
-
- QueryFilter ufilter = new QueryFilter();
- ufilter.andFilters["GroupID"] = GroupID;
- ufilter.andFilters["SelectedRoleID"] = RoleID;
-
- QueryFilter dfilter = new QueryFilter();
- dfilter.andFilters["GroupID"] = GroupID;
- dfilter.andFilters["RoleID"] = RoleID;
-
- data.Delete("osgrouprolemembership", dfilter);
- data.Update("osgroupmembership", values, null, ufilter, null, null);
- data.Delete("osrole", dfilter);
- }
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public void AddAgentToRole(UUID requestingAgentID, UUID AgentID, UUID GroupID, UUID RoleID)
- {
- object remoteValue = DoRemote(requestingAgentID, AgentID, GroupID, RoleID);
- if (remoteValue != null || m_doRemoteOnly)
- return;
-
- if (!CheckGroupPermissions(requestingAgentID, GroupID, (ulong) GroupPowers.AssignMember))
- {
- //This isn't an open and shut case, they could be setting the agent to their role, which would allow for AssignMemberLimited
- if (!CheckGroupPermissions(requestingAgentID, GroupID, (ulong) GroupPowers.AssignMemberLimited))
- {
- GroupProfileData profile = GetGroupProfile(requestingAgentID, GroupID);
- if (profile == null || !profile.OpenEnrollment || RoleID != UUID.Zero) //For open enrollment adding
- {
- MainConsole.Instance.Warn("[AGM]: User " + requestingAgentID + " attempted to add user " +
- AgentID +
- " to group " + GroupID + ", but did not have permissions to do so!");
- return;
- }
- }
- }
-
- QueryFilter filter = new QueryFilter();
- filter.andFilters["GroupID"] = GroupID;
- filter.andFilters["RoleID"] = RoleID;
- filter.andFilters["AgentID"] = AgentID;
- //Make sure they arn't already in this role
- if (
- uint.Parse(data.Query(new[] {"COUNT(AgentID)"}, "osgrouprolemembership", filter, null, null, null)[0]) ==
- 0)
- {
- Dictionary<string, object> row = new Dictionary<string, object>(3);
- row["GroupID"] = GroupID;
- row["RoleID"] = RoleID;
- row["AgentID"] = AgentID;
- data.Insert("osgrouprolemembership", row);
- }
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public void RemoveAgentFromRole(UUID requestingAgentID, UUID AgentID, UUID GroupID, UUID RoleID)
- {
- object remoteValue = DoRemote(requestingAgentID, AgentID, GroupID, RoleID);
- if (remoteValue != null || m_doRemoteOnly)
- return;
-
- if (CheckGroupPermissions(requestingAgentID, GroupID, (ulong) GroupPowers.AssignMember))
- {
- Dictionary<string, object> values = new Dictionary<string, object>(1);
- values["SelectedRoleID"] = UUID.Zero;
-
- QueryFilter filter = new QueryFilter();
- filter.andFilters["AgentID"] = AgentID;
- filter.andFilters["GroupID"] = GroupID;
- filter.andFilters["SelectedRoleID"] = RoleID;
-
- data.Update("osgroupmembership", values, null, filter, null, null);
-
- filter.andFilters.Remove("SelectedRoleID");
- filter.andFilters["RoleID"] = RoleID;
- data.Delete("osgrouprolemembership", filter);
- }
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public void SetAgentGroupInfo(UUID requestingAgentID, UUID AgentID, UUID GroupID, int AcceptNotices,
- int ListInProfile)
- {
- object remoteValue = DoRemote(requestingAgentID, AgentID, GroupID, AcceptNotices, ListInProfile);
- if (remoteValue != null || m_doRemoteOnly)
- return;
-
- if (!CheckGroupPermissions(requestingAgentID, GroupID, (ulong) GroupPowers.ChangeIdentity))
- {
- return;
- }
-
- Dictionary<string, object> values = new Dictionary<string, object>(3);
- values["AgentID"] = AgentID;
- values["AcceptNotices"] = AcceptNotices;
- values["ListInProfile"] = ListInProfile;
-
- QueryFilter filter = new QueryFilter();
- // these look the wrong way around ~ SignpostMarv
- filter.andFilters["GroupID"] = AgentID;
- filter.andFilters["AgentID"] = GroupID;
-
- data.Update("osgroupmembership", values, null, filter, null, null);
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public void AddAgentGroupInvite(UUID requestingAgentID, UUID inviteID, UUID GroupID, UUID roleID, UUID AgentID,
- string FromAgentName)
- {
- object remoteValue = DoRemote(requestingAgentID, inviteID, GroupID, roleID, AgentID, FromAgentName);
- if (remoteValue != null || m_doRemoteOnly)
- return;
-
- if (CheckGroupPermissions(requestingAgentID, GroupID, (ulong) GroupPowers.Invite))
- {
- QueryFilter filter = new QueryFilter();
- filter.andFilters["AgentID"] = AgentID;
- filter.andFilters["GroupID"] = GroupID;
- data.Delete("osgroupinvite", filter);
-
- Dictionary<string, object> row = new Dictionary<string, object>(6);
- row["InviteID"] = inviteID;
- row["GroupID"] = GroupID;
- row["RoleID"] = roleID;
- row["AgentID"] = AgentID;
- row["TMStamp"] = Util.UnixTimeSinceEpoch();
- row["FromAgentName"] = FromAgentName;
- data.Insert("osgroupinvite", row);
- }
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public void RemoveAgentInvite(UUID requestingAgentID, UUID inviteID)
- {
- object remoteValue = DoRemote(requestingAgentID, inviteID);
- if (remoteValue != null || m_doRemoteOnly)
- return;
-
- QueryFilter filter = new QueryFilter();
- filter.andFilters["InviteID"] = inviteID;
- data.Delete("osgroupinvite", filter);
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public void AddGroupProposal(UUID agentID, GroupProposalInfo info)
- {
- object remoteValue = DoRemote(agentID, info);
- if (remoteValue != null || m_doRemoteOnly)
- return;
-
- if (CheckGroupPermissions(agentID, info.GroupID, (ulong) GroupPowers.StartProposal))
- GenericUtils.AddGeneric(info.GroupID, "Proposal", info.VoteID.ToString(), info.ToOSD(), data);
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public List<GroupProposalInfo> GetActiveProposals(UUID agentID, UUID groupID)
- {
- object remoteValue = DoRemote(agentID, groupID);
- if (remoteValue != null || m_doRemoteOnly)
- return (List<GroupProposalInfo>) remoteValue;
-
- if (!CheckGroupPermissions(agentID, groupID, (ulong) GroupPowers.VoteOnProposal))
- return new List<GroupProposalInfo>();
-
- List<GroupProposalInfo> proposals = GenericUtils.GetGenerics<GroupProposalInfo>(groupID, "Proposal", data);
- proposals = (from p in proposals where p.Ending > DateTime.Now select p).ToList();
- foreach (GroupProposalInfo p in proposals)
- p.VoteCast = GetHasVoted(agentID, p);
-
- return proposals; //Return only ones that are still running
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public List<GroupProposalInfo> GetInactiveProposals(UUID agentID, UUID groupID)
- {
- object remoteValue = DoRemote(agentID, groupID);
- if (remoteValue != null || m_doRemoteOnly)
- return (List<GroupProposalInfo>) remoteValue;
-
- if (!CheckGroupPermissions(agentID, groupID, (ulong) GroupPowers.VoteOnProposal))
- return new List<GroupProposalInfo>();
-
- List<GroupProposalInfo> proposals = GenericUtils.GetGenerics<GroupProposalInfo>(groupID, "Proposal", data);
- proposals = (from p in proposals where p.Ending < DateTime.Now select p).ToList();
- List<GroupProposalInfo> proposalsNeedingResults =
- (from p in proposals where !p.HasCalculatedResult select p).ToList();
- foreach (GroupProposalInfo p in proposalsNeedingResults)
- {
- List<OpenMetaverse.StructuredData.OSDMap> maps = GenericUtils.GetGenerics(p.GroupID, p.VoteID.ToString(),
- data);
- int yes = 0;
- int no = 0;
- foreach (OpenMetaverse.StructuredData.OSDMap vote in maps)
- {
- if (vote["Vote"].AsString().ToLower() == "yes")
- yes++;
- else if (vote["Vote"].AsString().ToLower() == "no")
- no++;
- }
- if (yes + no < p.Quorum)
- p.Result = false;
- /*if (yes > no)
- p.Result = true;
- else
- p.Result = false;*/
- p.HasCalculatedResult = true;
- GenericUtils.AddGeneric(p.GroupID, "Proposal", p.VoteID.ToString(), p.ToOSD(), data);
- }
- foreach (GroupProposalInfo p in proposals)
- p.VoteCast = GetHasVoted(agentID, p);
-
- return proposals; //Return only ones that are still running
- }
-
- private string GetHasVoted(UUID agentID, GroupProposalInfo p)
- {
- OpenMetaverse.StructuredData.OSDMap map = GenericUtils.GetGeneric(p.GroupID, p.VoteID.ToString(),
- agentID.ToString(), data);
- if (map != null)
- return map["Vote"];
- return "";
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public void VoteOnActiveProposals(UUID agentID, UUID groupID, UUID proposalID, string vote)
- {
- object remoteValue = DoRemote(agentID, groupID, proposalID, vote);
- if (remoteValue != null || m_doRemoteOnly)
- return;
-
- if (!CheckGroupPermissions(agentID, groupID, (ulong) GroupPowers.VoteOnProposal))
- return;
-
- OpenMetaverse.StructuredData.OSDMap map = new OpenMetaverse.StructuredData.OSDMap();
- map["Vote"] = vote;
- GenericUtils.AddGeneric(groupID, proposalID.ToString(), agentID.ToString(), map, data);
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public uint GetNumberOfGroupNotices(UUID requestingAgentID, UUID GroupID)
- {
- object remoteValue = DoRemote(requestingAgentID, GroupID);
- if (remoteValue != null || m_doRemoteOnly)
- return (uint) remoteValue; // note: this is bad, you can't cast a null object to a uint
-
- List<UUID> GroupIDs = new List<UUID> {GroupID};
- return GetNumberOfGroupNotices(requestingAgentID, GroupIDs);
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public uint GetNumberOfGroupNotices(UUID requestingAgentID, List<UUID> GroupIDs)
- {
- object remoteValue = DoRemote(requestingAgentID, GroupIDs);
- if (remoteValue != null || m_doRemoteOnly)
- return (uint) remoteValue; // note: this is bad, you can't cast a null object to a uint
-
- bool had = GroupIDs.Count > 0;
-
- List<UUID> groupIDs = new List<UUID>();
- if (!agentsCanBypassGroupNoticePermsCheck.Contains(requestingAgentID))
- {
- #if (!ISWIN)
- foreach (UUID GroupID in GroupIDs)
- {
- if (CheckGroupPermissions(requestingAgentID, GroupID, (ulong)GroupPowers.ReceiveNotices))
- groupIDs.Add(GroupID);
- }
- #else
- groupIDs.AddRange(
- GroupIDs.Where(
- GroupID => CheckGroupPermissions(requestingAgentID, GroupID, (ulong) GroupPowers.ReceiveNotices)));
- #endif
- }
- else
- {
- groupIDs = GroupIDs;
- }
-
- if (had && groupIDs.Count == 0)
- {
- return 0;
- }
-
- QueryFilter filter = new QueryFilter();
- List<object> filterGroupIDs = new List<object>(groupIDs.Count);
- filterGroupIDs.AddRange(groupIDs.Cast<object>());
- if (filterGroupIDs.Count > 0)
- {
- filter.orMultiFilters["GroupID"] = filterGroupIDs;
- }
-
- return uint.Parse(data.Query(new[] {"COUNT(NoticeID)"}, "osgroupnotice", filter, null, null, null)[0]);
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public uint GetNumberOfGroups(UUID requestingAgentID, Dictionary<string, bool> boolFields)
- {
- object remoteValue = DoRemote(requestingAgentID, boolFields);
- if (remoteValue != null || m_doRemoteOnly)
- return (uint) remoteValue; // note: this is bad, you can't cast a null object to a uint
-
- QueryFilter filter = new QueryFilter();
-
- string[] BoolFields = {"OpenEnrollment", "ShowInList", "AllowPublish", "MaturePublish"};
- foreach (string field in BoolFields)
- {
- if (boolFields.ContainsKey(field))
- {
- filter.andFilters[field] = boolFields[field] ? "1" : "0";
- }
- }
-
- return uint.Parse(data.Query(new[] {"COUNT(GroupID)"}, "osgroup", filter, null, null, null)[0]);
- }
-
- private static GroupRecord GroupRecordQueryResult2GroupRecord(List<String> result)
- {
- return new GroupRecord
- {
- GroupID = UUID.Parse(result[0]),
- GroupName = result[1],
- Charter = result[2],
- GroupPicture = UUID.Parse(result[3]),
- FounderID = UUID.Parse(result[4]),
- MembershipFee = int.Parse(result[5]),
- OpenEnrollment = int.Parse(result[6]) == 1,
- ShowInList = int.Parse(result[7]) == 1,
- AllowPublish = int.Parse(result[8]) == 1,
- MaturePublish = int.Parse(result[9]) == 1,
- OwnerRoleID = UUID.Parse(result[10])
- };
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public GroupRecord GetGroupRecord(UUID requestingAgentID, UUID GroupID, string GroupName)
- {
- object remoteValue = DoRemote(requestingAgentID, GroupID, GroupName);
- if (remoteValue != null || m_doRemoteOnly)
- return (GroupRecord) remoteValue;
-
- QueryFilter filter = new QueryFilter();
-
- if (GroupID != UUID.Zero)
- {
- filter.andFilters["GroupID"] = GroupID;
- }
- if (!string.IsNullOrEmpty(GroupName))
- {
- filter.andFilters["Name"] = GroupName;
- }
- if (filter.Count == 0)
- {
- return null;
- }
- List<string> osgroupsData = data.Query(new[]
- {
- "GroupID",
- "Name",
- "Charter",
- "InsigniaID",
- "FounderID",
- "MembershipFee",
- "OpenEnrollment",
- "ShowInList",
- "AllowPublish",
- "MaturePublish",
- "OwnerRoleID"
- }, "osgroup", filter, null, null, null);
- return (osgroupsData.Count == 0) ? null : GroupRecordQueryResult2GroupRecord(osgroupsData);
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public List<GroupRecord> GetGroupRecords(UUID requestingAgentID, uint start, uint count,
- Dictionary<string, bool> sort, Dictionary<string, bool> boolFields)
- {
- // List<string> filter = new List<string>();
-
- object remoteValue = DoRemote(requestingAgentID, start, count, boolFields);
- if (remoteValue != null || m_doRemoteOnly)
- return (List<GroupRecord>) remoteValue;
-
- string[] sortAndBool = {"OpenEnrollment", "MaturePublish"};
- string[] BoolFields = {"OpenEnrollment", "ShowInList", "AllowPublish", "MaturePublish"};
-
- foreach (string field in sortAndBool)
- {
- if (boolFields.ContainsKey(field) && sort.ContainsKey(field))
- {
- sort.Remove(field);
- }
- }
-
- QueryFilter filter = new QueryFilter();
-
- foreach (string field in BoolFields)
- {
- if (boolFields.ContainsKey(field))
- {
- filter.andFilters[field] = boolFields[field] ? "1" : "0";
- }
- }
-
- List<GroupRecord> Reply = new List<GroupRecord>();
-
- List<string> osgroupsData = data.Query(new[]
- {
- "GroupID",
- "Name",
- "Charter",
- "InsigniaID",
- "FounderID",
- "MembershipFee",
- "OpenEnrollment",
- "ShowInList",
- "AllowPublish",
- "MaturePublish",
- "OwnerRoleID"
- }, "osgroup", filter, sort, start, count);
-
- if (osgroupsData.Count < 11)
- {
- return Reply;
- }
- for (int i = 0; i < osgroupsData.Count; i += 11)
- {
- Reply.Add(GroupRecordQueryResult2GroupRecord(osgroupsData.GetRange(i, 11)));
- }
- return Reply;
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public List<GroupRecord> GetGroupRecords(UUID requestingAgentID, List<UUID> GroupIDs)
- {
- object remoteValue = DoRemote(requestingAgentID, GroupIDs);
- if (remoteValue != null || m_doRemoteOnly)
- return (List<GroupRecord>) remoteValue;
-
- List<GroupRecord> Reply = new List<GroupRecord>(0);
- if (GroupIDs.Count <= 0)
- {
- return Reply;
- }
-
- QueryFilter filter = new QueryFilter();
- filter.orMultiFilters["GroupID"] = new List<object>();
- foreach (UUID groupID in GroupIDs)
- {
- filter.orMultiFilters["GroupID"].Add(groupID);
- }
-
- List<string> osgroupsData = data.Query(new[]
- {
- "GroupID",
- "Name",
- "Charter",
- "InsigniaID",
- "FounderID",
- "MembershipFee",
- "OpenEnrollment",
- "ShowInList",
- "AllowPublish",
- "MaturePublish",
- "OwnerRoleID"
- }, "osgroup", filter, null, null, null);
-
- if (osgroupsData.Count < 11)
- {
- return Reply;
- }
- for (int i = 0; i < osgroupsData.Count; i += 11)
- {
- Reply.Add(GroupRecordQueryResult2GroupRecord(osgroupsData.GetRange(i, 11)));
- }
- return Reply;
- }
-
- [CanBeReflected(ThreatLevel = ThreatLevel.Low)]
- public GroupProfileData GetMemberGroupProfile(UUID requestingAgentID, UUID GroupID, UUID AgentID)
- {
- object remoteValue = DoRemote(requestingAgentID, GroupID, AgentID);
- if (remoteValue != null || m_doRemoteOnly)
- return (GroupProfileData) remoteValue;
-
- if (!CheckGroupPermissions(requestingAgentID, GroupID, (ulong) GroupPowers.MemberVisible))
- return new GroupProfileData();
-
- GroupProfileData GPD = new GroupProfileData();
- GroupRecord record = GetGroupRecord(requestingAgentID, GroupID, null);
-
- QueryFilter filter1 = new QueryFilter();
- filter1.andFilters["GroupID"] = A…
Large files files are truncated, but you can click here to view the full file