From 9a01fddd1cefea0508b6b1616771e6ef8eabef87 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 30 Mar 2017 17:39:21 +0100 Subject: [PATCH] add CanSellObject() permitions check functions --- .../CoreModules/World/Land/LandObject.cs | 3 +- .../World/Objects/BuySell/BuySellModule.cs | 21 ++-- .../World/Permissions/PermissionsModule.cs | 87 +++++++++++++- .../Framework/Scenes/Scene.Permissions.cs | 106 +++++++++--------- 4 files changed, 151 insertions(+), 66 deletions(-) diff --git a/OpenSim/Region/CoreModules/World/Land/LandObject.cs b/OpenSim/Region/CoreModules/World/Land/LandObject.cs index 9d84e664dd..2b5cb31eeb 100644 --- a/OpenSim/Region/CoreModules/World/Land/LandObject.cs +++ b/OpenSim/Region/CoreModules/World/Land/LandObject.cs @@ -1649,8 +1649,7 @@ namespace OpenSim.Region.CoreModules.World.Land { foreach (SceneObjectGroup obj in primsOverMe) { - if (obj.OwnerID == previousOwner && obj.GroupID == UUID.Zero && - (obj.EffectiveOwnerPerms & (uint)(OpenSim.Framework.PermissionMask.Transfer)) != 0) + if(m_scene.Permissions.CanSellObject(previousOwner,obj, (byte)SaleType.Original)) m_BuySellModule.BuyObject(sp.ControllingClient, UUID.Zero, obj.LocalId, 1, 0); } } diff --git a/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs b/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs index 142c8b7119..90d65c7101 100644 --- a/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs +++ b/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs @@ -89,28 +89,23 @@ namespace OpenSim.Region.CoreModules.World.Objects.BuySell if (part == null) return; - if (part.ParentGroup.IsDeleted) + SceneObjectGroup sog = part.ParentGroup; + if (sog == null || sog.IsDeleted) return; - if (part.OwnerID != part.GroupID && part.OwnerID != client.AgentId && (!m_scene.Permissions.IsGod(client.AgentId))) - return; - - if (part.OwnerID == part.GroupID) // Group owned + // Does the user have the power to put the object on sale? + if (!m_scene.Permissions.CanSellObject(client, sog, saleType)) { - // Does the user have the power to put the object on sale? - if (!m_scene.Permissions.CanSellGroupObject(client.AgentId, part.GroupID)) - { - client.SendAgentAlertMessage("You don't have permission to set group-owned objects on sale", false); - return; - } + client.SendAgentAlertMessage("You don't have permission to set object on sale", false); + return; } - part = part.ParentGroup.RootPart; + part = sog.RootPart; part.ObjectSaleType = saleType; part.SalePrice = salePrice; - part.ParentGroup.HasGroupChanged = true; + sog.HasGroupChanged = true; part.SendPropertiesToClient(client); } diff --git a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs index 279b966b73..7f2b29a1ea 100644 --- a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs +++ b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs @@ -300,6 +300,8 @@ namespace OpenSim.Region.CoreModules.World.Permissions scenePermissions.OnDelinkObject += CanDelinkObject; scenePermissions.OnDeedObject += CanDeedObject; scenePermissions.OnSellGroupObject += CanSellGroupObject; + scenePermissions.OnSellObjectByUserID += CanSellObjectByUserID; + scenePermissions.OnSellObject += CanSellObject; scenePermissions.OnCreateObjectInventory += CanCreateObjectInventory; scenePermissions.OnEditObjectInventory += CanEditObjectInventory; @@ -393,7 +395,10 @@ namespace OpenSim.Region.CoreModules.World.Permissions scenePermissions.OnLinkObject -= CanLinkObject; scenePermissions.OnDelinkObject -= CanDelinkObject; scenePermissions.OnDeedObject -= CanDeedObject; + scenePermissions.OnSellGroupObject -= CanSellGroupObject; + scenePermissions.OnSellObjectByUserID -= CanSellObjectByUserID; + scenePermissions.OnSellObject -= CanSellObject; scenePermissions.OnCreateObjectInventory -= CanCreateObjectInventory; scenePermissions.OnEditObjectInventory -= CanEditObjectInventory; @@ -1826,6 +1831,86 @@ namespace OpenSim.Region.CoreModules.World.Permissions return IsGroupMember(groupID, userID, (ulong)GroupPowers.ObjectSetForSale); } + private bool CanSellObjectByUserID(SceneObjectGroup sog, UUID userID, byte saleType) + { + DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name); + if (m_bypassPermissions) return m_bypassPermissionsValue; + + if (sog == null || sog.IsDeleted || userID == UUID.Zero) + return false; + + // sell is not a attachment op + if(sog.IsAttachment) + return false; + + if(IsAdministrator(userID)) + return true; + + uint sogEffectiveOwnerPerms = sog.EffectiveOwnerPerms; + if((sogEffectiveOwnerPerms & (uint)PermissionMask.Transfer) == 0) + return false; + + if(saleType == (byte)SaleType.Copy && + (sogEffectiveOwnerPerms & (uint)PermissionMask.Copy) == 0) + return false; + + UUID sogOwnerID = sog.OwnerID; + + if(sogOwnerID == userID) + return true; + + // else only group owned can be sold by members with powers + UUID sogGroupID = sog.GroupID; + if(sog.OwnerID != sogGroupID || sogGroupID == UUID.Zero) + return false; + + return IsGroupMember(sogGroupID, userID, (ulong)GroupPowers.ObjectSetForSale); + } + + private bool CanSellObject(SceneObjectGroup sog, ScenePresence sp, byte saleType) + { + DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name); + if (m_bypassPermissions) return m_bypassPermissionsValue; + + if (sog == null || sog.IsDeleted || sp == null || sp.IsDeleted) + return false; + + // sell is not a attachment op + if(sog.IsAttachment) + return false; + + if(sp.IsGod) + return true; + + uint sogEffectiveOwnerPerms = sog.EffectiveOwnerPerms; + if((sogEffectiveOwnerPerms & (uint)PermissionMask.Transfer) == 0) + return false; + + if(saleType == (byte)SaleType.Copy && + (sogEffectiveOwnerPerms & (uint)PermissionMask.Copy) == 0) + return false; + + UUID userID = sp.UUID; + UUID sogOwnerID = sog.OwnerID; + + if(sogOwnerID == userID) + return true; + + // else only group owned can be sold by members with powers + UUID sogGroupID = sog.GroupID; + if(sog.OwnerID != sogGroupID || sogGroupID == UUID.Zero) + return false; + + ulong powers = 0; + if(!GroupMemberPowers(sogGroupID, sp, ref powers)) + return false; + + if((powers & (ulong)GroupPowers.ObjectSetForSale) == 0) + return false; + + return true; + } + private bool CanTakeObject(SceneObjectGroup sog, ScenePresence sp) { // ignore locked, viewers shell ask for confirmation @@ -1835,7 +1920,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions if (sog == null || sog.IsDeleted || sp == null || sp.IsDeleted) return false; - // take is not a attachment op + // take is not a attachment op if(sog.IsAttachment) return false; diff --git a/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs b/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs index 6d3b82f55a..7d69a9b663 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Permissions.cs @@ -47,6 +47,8 @@ namespace OpenSim.Region.Framework.Scenes public delegate bool TransferObjectHandler(UUID objectID, UUID recipient); public delegate bool TakeObjectHandler(SceneObjectGroup sog, ScenePresence sp); public delegate bool SellGroupObjectHandler(UUID userID, UUID groupID); + public delegate bool SellObjectHandlerByUserID(SceneObjectGroup sog, UUID userID, byte saleType); + public delegate bool SellObjectHandler(SceneObjectGroup sog, ScenePresence sp, byte saleType); public delegate bool TakeCopyObjectHandler(SceneObjectGroup sog, ScenePresence sp); public delegate bool DuplicateObjectHandler(SceneObjectGroup sog, ScenePresence sp); public delegate bool EditObjectByIDsHandler(UUID objectID, UUID editorID); @@ -121,7 +123,11 @@ namespace OpenSim.Region.Framework.Scenes public event DeleteObjectHandler OnDeleteObject; public event TransferObjectHandler OnTransferObject; public event TakeObjectHandler OnTakeObject; + public event SellGroupObjectHandler OnSellGroupObject; + public event SellObjectHandlerByUserID OnSellObjectByUserID; + public event SellObjectHandler OnSellObject; + public event TakeCopyObjectHandler OnTakeCopyObject; public event DuplicateObjectHandler OnDuplicateObject; public event EditObjectByIDsHandler OnEditObjectByIDs; @@ -281,14 +287,11 @@ namespace OpenSim.Region.Framework.Scenes } } } - return result; } public bool CanDeleteObject(SceneObjectGroup sog, IClientAPI client) { - bool result = true; - DeleteObjectHandler handler = OnDeleteObject; if (handler != null) { @@ -301,20 +304,15 @@ namespace OpenSim.Region.Framework.Scenes foreach (DeleteObjectHandler h in list) { if (h(sog, sp) == false) - { - result = false; - break; - } + return false; } } - return result; + return true; } public bool CanTransferObject(UUID objectID, UUID recipient) { - bool result = true; - TransferObjectHandler handler = OnTransferObject; if (handler != null) { @@ -322,14 +320,10 @@ namespace OpenSim.Region.Framework.Scenes foreach (TransferObjectHandler h in list) { if (h(objectID, recipient) == false) - { - result = false; - break; - } + return false; } } - - return result; + return true; } #endregion @@ -337,8 +331,6 @@ namespace OpenSim.Region.Framework.Scenes #region TAKE OBJECT public bool CanTakeObject(SceneObjectGroup sog, ScenePresence sp) { - bool result = true; - TakeObjectHandler handler = OnTakeObject; if (handler != null) { @@ -349,18 +341,13 @@ namespace OpenSim.Region.Framework.Scenes foreach (TakeObjectHandler h in list) { if (h(sog, sp) == false) - { - result = false; - break; - } + return false; } } - // m_log.DebugFormat( // "[SCENE PERMISSIONS]: CanTakeObject() fired for object {0}, taker {1}, result {2}", // objectID, AvatarTakingUUID, result); - - return result; + return true; } #endregion @@ -368,8 +355,6 @@ namespace OpenSim.Region.Framework.Scenes #region SELL GROUP OBJECT public bool CanSellGroupObject(UUID userID, UUID groupID) { - bool result = true; - SellGroupObjectHandler handler = OnSellGroupObject; if (handler != null) { @@ -377,18 +362,52 @@ namespace OpenSim.Region.Framework.Scenes foreach (SellGroupObjectHandler h in list) { if (h(userID, groupID) == false) - { - result = false; - break; - } + return false; } } - //m_log.DebugFormat( // "[SCENE PERMISSIONS]: CanSellGroupObject() fired for user {0}, group {1}, result {2}", // userID, groupID, result); + return true; + } - return result; + #endregion + + #region SELL OBJECT + public bool CanSellObject(IClientAPI client, SceneObjectGroup sog, byte saleType) + { + SellObjectHandler handler = OnSellObject; + if (handler != null) + { + if(sog == null || client == null || client.SceneAgent == null) + return false; + + ScenePresence sp = client.SceneAgent as ScenePresence; + Delegate[] list = handler.GetInvocationList(); + foreach (SellObjectHandler h in list) + { + if (h(sog, sp, saleType) == false) + return false; + } + } + return true; + } + + public bool CanSellObject(UUID userID, SceneObjectGroup sog, byte saleType) + { + SellObjectHandlerByUserID handler = OnSellObjectByUserID; + if (handler != null) + { + if(sog == null) + return false; + Delegate[] list = handler.GetInvocationList(); + foreach (SellObjectHandlerByUserID h in list) + { + if (h(sog, userID, saleType) == false) + return false; + } + } + return true; } #endregion @@ -397,8 +416,6 @@ namespace OpenSim.Region.Framework.Scenes #region TAKE COPY OBJECT public bool CanTakeCopyObject(SceneObjectGroup sog, ScenePresence sp) { - bool result = true; - TakeCopyObjectHandler handler = OnTakeCopyObject; if (handler != null) { @@ -408,18 +425,13 @@ namespace OpenSim.Region.Framework.Scenes foreach (TakeCopyObjectHandler h in list) { if (h(sog, sp) == false) - { - result = false; - break; - } + return false; } } - // m_log.DebugFormat( // "[SCENE PERMISSIONS]: CanTakeCopyObject() fired for object {0}, user {1}, result {2}", // objectID, userID, result); - - return result; + return true; } #endregion @@ -558,8 +570,6 @@ namespace OpenSim.Region.Framework.Scenes #region RETURN OBJECT public bool CanReturnObjects(ILandObject land, IClientAPI client, List objects) { - bool result = true; - ReturnObjectsHandler handler = OnReturnObjects; if (handler != null) { @@ -574,18 +584,14 @@ namespace OpenSim.Region.Framework.Scenes foreach (ReturnObjectsHandler h in list) { if (h(land, sp, objects) == false) - { - result = false; - break; - } + return false; } } - // m_log.DebugFormat( // "[SCENE PERMISSIONS]: CanReturnObjects() fired for user {0} for {1} objects on {2}, result {3}", // user, objects.Count, land.LandData.Name, result); - return result; + return true; } #endregion