/// <summary>
        /// Add relevant permissions for an object to the item.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="so"></param>
        /// <param name="objsForEffectivePermissions"></param>
        /// <param name="remoteClient"></param>
        /// <returns></returns>
        protected InventoryItemBase AddPermissions(
            InventoryItemBase item, SceneObjectGroup so, List <SceneObjectGroup> objsForEffectivePermissions,
            IClientAPI remoteClient)
        {
            uint effectivePerms           = (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify | PermissionMask.Move | PermissionMask.Export) | 7;
            uint allObjectsNextOwnerPerms = 0x7fffffff;
            uint allObjectsEveryOnePerms  = 0x7fffffff;
            uint allObjectsGroupPerms     = 0x7fffffff;

            foreach (SceneObjectGroup grp in objsForEffectivePermissions)
            {
                effectivePerms           &= grp.GetEffectivePermissions();
                allObjectsNextOwnerPerms &= grp.RootPart.NextOwnerMask;
                allObjectsEveryOnePerms  &= grp.RootPart.EveryoneMask;
                allObjectsGroupPerms     &= grp.RootPart.GroupMask;
            }
            effectivePerms |= (uint)PermissionMask.Move;

            //PermissionsUtil.LogPermissions(item.Name, "Before AddPermissions", item.BasePermissions, item.CurrentPermissions, item.NextPermissions);

            if (remoteClient != null && (remoteClient.AgentId != so.RootPart.OwnerID) && m_Scene.Permissions.PropagatePermissions())
            {
                uint perms = effectivePerms;
                PermissionsUtil.ApplyFoldedPermissions(effectivePerms, ref perms);

                item.BasePermissions     = perms & allObjectsNextOwnerPerms;
                item.CurrentPermissions  = item.BasePermissions;
                item.NextPermissions     = perms & allObjectsNextOwnerPerms;
                item.EveryOnePermissions = allObjectsEveryOnePerms & allObjectsNextOwnerPerms;
                item.GroupPermissions    = allObjectsGroupPerms & allObjectsNextOwnerPerms;

                // apply next owner perms on rez
                item.CurrentPermissions |= SceneObjectGroup.SLAM;
            }
            else
            {
                item.BasePermissions     = effectivePerms;
                item.CurrentPermissions  = effectivePerms;
                item.NextPermissions     = allObjectsNextOwnerPerms & effectivePerms;
                item.EveryOnePermissions = allObjectsEveryOnePerms & effectivePerms;
                item.GroupPermissions    = allObjectsGroupPerms & effectivePerms;

                item.CurrentPermissions &=
                    ((uint)PermissionMask.Copy |
                     (uint)PermissionMask.Transfer |
                     (uint)PermissionMask.Modify |
                     (uint)PermissionMask.Move |
                     (uint)PermissionMask.Export |
                     7);     // Preserve folded permissions
            }

            //PermissionsUtil.LogPermissions(item.Name, "After AddPermissions", item.BasePermissions, item.CurrentPermissions, item.NextPermissions);

            return(item);
        }
        /// <summary>
        /// Apply next owner permissions.
        /// </summary>
        private void ApplyNextOwnerPermissions(InventoryItemBase item)
        {
            if (item.InvType == (int)InventoryType.Object)
            {
                uint perms = item.CurrentPermissions;
                PermissionsUtil.ApplyFoldedPermissions(item.CurrentPermissions, ref perms);
                item.CurrentPermissions = perms;
            }

            item.CurrentPermissions  &= item.NextPermissions;
            item.BasePermissions     &= item.NextPermissions;
            item.EveryOnePermissions &= item.NextPermissions;
        }
示例#3
0
        public bool BuyObject(IClientAPI remoteClient, UUID categoryID, uint localID, byte saleType, int salePrice)
        {
            SceneObjectPart part = m_scene.GetSceneObjectPart(localID);

            if (part == null)
            {
                return(false);
            }

            SceneObjectGroup group = part.ParentGroup;

            switch (saleType)
            {
            case 1: // Sell as original (in-place sale)
                uint effectivePerms = group.GetEffectivePermissions();

                if ((effectivePerms & (uint)PermissionMask.Transfer) == 0)
                {
                    if (m_dialogModule != null)
                    {
                        m_dialogModule.SendAlertToUser(remoteClient, "This item doesn't appear to be for sale");
                    }
                    return(false);
                }

                group.SetOwnerId(remoteClient.AgentId);
                group.SetRootPartOwner(part, remoteClient.AgentId, remoteClient.ActiveGroupId);

                if (m_scene.Permissions.PropagatePermissions())
                {
                    foreach (SceneObjectPart child in group.Parts)
                    {
                        child.Inventory.ChangeInventoryOwner(remoteClient.AgentId);
                        child.TriggerScriptChangedEvent(Changed.OWNER);
                        child.ApplyNextOwnerPermissions();
                    }
                }

                part.ObjectSaleType = 0;
                part.SalePrice      = 10;

                group.HasGroupChanged = true;
                part.SendPropertiesToClient(remoteClient);
                part.TriggerScriptChangedEvent(Changed.OWNER);
                group.ResumeScripts();
                part.ScheduleFullUpdate();

                break;

            case 2: // Sell a copy
                Vector3 inventoryStoredPosition = new Vector3(
                    Math.Min(group.AbsolutePosition.X, m_scene.RegionInfo.RegionSizeX - 6),
                    Math.Min(group.AbsolutePosition.Y, m_scene.RegionInfo.RegionSizeY - 6),
                    group.AbsolutePosition.Z);

                Vector3 originalPosition = group.AbsolutePosition;

                group.AbsolutePosition = inventoryStoredPosition;

                string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(group);
                group.AbsolutePosition = originalPosition;

                uint perms = group.GetEffectivePermissions();

                if ((perms & (uint)PermissionMask.Transfer) == 0)
                {
                    if (m_dialogModule != null)
                    {
                        m_dialogModule.SendAlertToUser(remoteClient, "This item doesn't appear to be for sale");
                    }
                    return(false);
                }

                AssetBase asset = m_scene.CreateAsset(
                    group.GetPartName(localID),
                    group.GetPartDescription(localID),
                    (sbyte)AssetType.Object,
                    Utils.StringToBytes(sceneObjectXml),
                    group.OwnerID);
                m_scene.AssetService.Store(asset);

                InventoryItemBase item = new InventoryItemBase();
                item.CreatorId   = part.CreatorID.ToString();
                item.CreatorData = part.CreatorData;

                item.ID          = UUID.Random();
                item.Owner       = remoteClient.AgentId;
                item.AssetID     = asset.FullID;
                item.Description = asset.Description;
                item.Name        = asset.Name;
                item.AssetType   = asset.Type;
                item.InvType     = (int)InventoryType.Object;
                item.Folder      = categoryID;

                PermissionsUtil.ApplyFoldedPermissions(perms, ref perms);

                item.BasePermissions     = perms & part.NextOwnerMask;
                item.CurrentPermissions  = perms & part.NextOwnerMask;
                item.NextPermissions     = part.NextOwnerMask;
                item.EveryOnePermissions = part.EveryoneMask &
                                           part.NextOwnerMask;
                item.GroupPermissions = part.GroupMask &
                                        part.NextOwnerMask;
                item.Flags       |= (uint)InventoryItemFlags.ObjectSlamPerm;
                item.CreationDate = Util.UnixTimeSinceEpoch();

                if (m_scene.AddInventoryItem(item))
                {
                    remoteClient.SendInventoryItemCreateUpdate(item, 0);
                }
                else
                {
                    if (m_dialogModule != null)
                    {
                        m_dialogModule.SendAlertToUser(remoteClient, "Cannot buy now. Your inventory is unavailable");
                    }
                    return(false);
                }
                break;

            case 3: // Sell contents
                List <UUID> invList = part.Inventory.GetInventoryList();

                bool okToSell = true;

                foreach (UUID invID in invList)
                {
                    TaskInventoryItem item1 = part.Inventory.GetInventoryItem(invID);
                    if ((item1.CurrentPermissions &
                         (uint)PermissionMask.Transfer) == 0)
                    {
                        okToSell = false;
                        break;
                    }
                }

                if (!okToSell)
                {
                    if (m_dialogModule != null)
                    {
                        m_dialogModule.SendAlertToUser(
                            remoteClient, "This item's inventory doesn't appear to be for sale");
                    }
                    return(false);
                }

                if (invList.Count > 0)
                {
                    m_scene.MoveTaskInventoryItems(remoteClient.AgentId, part.Name, part, invList);
                }
                break;
            }

            return(true);
        }
        /// <summary>
        /// Add relevant permissions for an object to the item.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="so"></param>
        /// <param name="objsForEffectivePermissions"></param>
        /// <param name="remoteClient"></param>
        /// <returns></returns>
        protected InventoryItemBase AddPermissions(
            InventoryItemBase item, SceneObjectGroup so, List <SceneObjectGroup> objsForEffectivePermissions,
            IClientAPI remoteClient)
        {
            uint effectivePerms           = (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify | PermissionMask.Move | PermissionMask.Export) | 7;
            uint allObjectsNextOwnerPerms = 0x7fffffff;
            uint allObjectsEveryOnePerms  = 0x7fffffff;
            uint allObjectsGroupPerms     = 0x7fffffff;

            foreach (SceneObjectGroup grp in objsForEffectivePermissions)
            {
                effectivePerms           &= grp.GetEffectivePermissions();
                allObjectsNextOwnerPerms &= grp.RootPart.NextOwnerMask;
                allObjectsEveryOnePerms  &= grp.RootPart.EveryoneMask;
                allObjectsGroupPerms     &= grp.RootPart.GroupMask;
            }
            effectivePerms |= (uint)PermissionMask.Move;

            //PermissionsUtil.LogPermissions(item.Name, "Before AddPermissions", item.BasePermissions, item.CurrentPermissions, item.NextPermissions);

            if (remoteClient != null && (remoteClient.AgentId != so.RootPart.OwnerID) && m_Scene.Permissions.PropagatePermissions())
            {
                // Changing ownership, so apply the "Next Owner" permissions to all of the
                // inventory item's permissions.

                uint perms = effectivePerms;
                PermissionsUtil.ApplyFoldedPermissions(effectivePerms, ref perms);

                item.BasePermissions     = perms & allObjectsNextOwnerPerms;
                item.CurrentPermissions  = item.BasePermissions;
                item.NextPermissions     = perms & allObjectsNextOwnerPerms;
                item.EveryOnePermissions = allObjectsEveryOnePerms & allObjectsNextOwnerPerms;
                item.GroupPermissions    = allObjectsGroupPerms & allObjectsNextOwnerPerms;

                // apply next owner perms on rez
                item.CurrentPermissions |= SceneObjectGroup.SLAM;
            }
            else
            {
                // Not changing ownership.
                // In this case we apply the permissions in the object's items ONLY to the inventory
                // item's "Next Owner" permissions, but NOT to its "Current", "Base", etc. permissions.
                // E.g., if the object contains a No-Transfer item then the item's "Next Owner"
                // permissions are also No-Transfer.
                PermissionsUtil.ApplyFoldedPermissions(effectivePerms, ref allObjectsNextOwnerPerms);

                item.BasePermissions     = effectivePerms;
                item.CurrentPermissions  = effectivePerms;
                item.NextPermissions     = allObjectsNextOwnerPerms & effectivePerms;
                item.EveryOnePermissions = allObjectsEveryOnePerms & effectivePerms;
                item.GroupPermissions    = allObjectsGroupPerms & effectivePerms;

                item.CurrentPermissions &=
                    ((uint)PermissionMask.Copy |
                     (uint)PermissionMask.Transfer |
                     (uint)PermissionMask.Modify |
                     (uint)PermissionMask.Move |
                     (uint)PermissionMask.Export |
                     7);     // Preserve folded permissions
            }

            //PermissionsUtil.LogPermissions(item.Name, "After AddPermissions", item.BasePermissions, item.CurrentPermissions, item.NextPermissions);

            return(item);
        }