Exemplo n.º 1
0
        private void CopyItemsToFolder(CachedUserInfo inventoryOwner, UUID folderId, IList<SceneObjectGroup> items,
            IClientAPI remoteClient, bool stopScripts)
        {
            SerializationFlags serFlags = stopScripts ? SerializationFlags.StopScripts : SerializationFlags.None;

            if (items.Count == 0)
            {
                throw new ArgumentOutOfRangeException("CopyItemsToFolder() Given 0 items to copy");
            }

            //if there is only one item, this will be the basis for it
            //if this a coalesced object, this will be the basis for the name etc
            InventoryItemBase newInvItem = new InventoryItemBase();
            newInvItem.CreatorId = items[0].RootPart.CreatorID.ToString();
            newInvItem.ID = UUID.Random();
            newInvItem.InvType = (int)InventoryType.Object;
            newInvItem.Folder = folderId;
            newInvItem.Owner = inventoryOwner.UserProfile.ID;

            if (items.Count == 1)
            {
                ItemPermissionBlock newPerms = items[0].GetNewItemPermissions(inventoryOwner.UserProfile.ID);
                newPerms.ApplyToOther(newInvItem);

                byte[] objAsset = this.DoSerializeSingleGroup(items[0], serFlags);
                
                //single item, store as single item asset
                AssetBase itemAsset = CreateAsset(
                    items[0].GetPartName(items[0].RootPart.LocalId),
                    items[0].GetPartDescription(items[0].RootPart.LocalId),
                    (sbyte)AssetType.Object,
                    objAsset);

                //exception storing asset will get thrown up and prevent the object from
                //vanishing from the scene
                try
                {
                    CommsManager.AssetCache.AddAsset(itemAsset, AssetRequestInfo.InternalRequest());
                }
                catch (AssetServerException)
                {
                    if (remoteClient != null) remoteClient.SendAgentAlertMessage("Unable to create asset. Please try again later.", false);
                    throw;
                }
                
                //store inventory object
                newInvItem.CreationDate = Util.UnixTimeSinceEpoch();
                newInvItem.Description = itemAsset.Description;
                newInvItem.Name = itemAsset.Name;
                newInvItem.AssetType = itemAsset.Type;
                newInvItem.AssetID = itemAsset.FullID;

                inventoryOwner.AddItem(newInvItem);

                this.InformClientOfInvChange(remoteClient, newInvItem);
            }
            else if (items.Count > 1)
            {
                //we have a coalesced object, this must be serialized differently and flags set

                //retrieve a set of the next permissions for each item
                List<ItemPermissionBlock> itemPermissions = new List<ItemPermissionBlock>();
                foreach (SceneObjectGroup item in items)
                {
                    ItemPermissionBlock permsBlock = item.GetNewItemPermissions(inventoryOwner.UserProfile.ID);
                    itemPermissions.Add(permsBlock);
                }

                //serialize coalesced
                byte[] objAsset = this.DoSerializeCoalesced(items, itemPermissions, serFlags);

                //grab the first item to set the name etc
                SceneObjectGroup modelItem = items[0];

                //multiple items, store as multi item asset
                AssetBase itemAsset = CreateAsset(
                    modelItem.GetPartName(modelItem.RootPart.LocalId),
                    modelItem.GetPartDescription(modelItem.RootPart.LocalId),
                    (sbyte)AssetType.Object,
                    objAsset);

                //exception storing asset will get thrown up and prevent the object from
                //vanishing from the scene
                try
                {
                    CommsManager.AssetCache.AddAsset(itemAsset, AssetRequestInfo.InternalRequest());
                }
                catch (AssetServerException)
                {
                    if (remoteClient != null) remoteClient.SendAgentAlertMessage("Unable to create asset. Please try again later.", false);
                    throw;
                }

                //calculate minimum permissions for the coalesced object
                ItemPermissionBlock.CalculateCoalescedPermissions(itemPermissions).ApplyToOther(newInvItem);

                //misc
                newInvItem.CreationDate = Util.UnixTimeSinceEpoch();
                newInvItem.Description = itemAsset.Description;
                newInvItem.Name = itemAsset.Name;
                newInvItem.AssetType = itemAsset.Type;
                newInvItem.AssetID = itemAsset.FullID;

                //mark as coalesced
                newInvItem.Flags |= (uint)InventoryItemBase.Flag.OBJECT_HAS_MULTIPLE_ITEMS;

                //store inventory object
                inventoryOwner.AddItem(newInvItem);

                this.InformClientOfInvChange(remoteClient, newInvItem);
            }
        }