public override void AssetTransferComplete()
            {
#if DEBUG
                m_Log.DebugFormat("Finished transfer {0} to {1}", m_SrcAgent, m_DestinationAgent);
#endif
                AssetType assetType = AssetType.Folder;
                UUID      givenID;
                string    givenName;
                if (m_InventoryTree != null)
                {
                    InventoryFolder folder;
                    if (!m_DstInventoryService.Folder.TryGetValue(m_DestinationAgent.ID, AssetType.RootFolder, out folder))
                    {
                        return;
                    }
                    var folderCreator = new List <TransferInventoryFolder>
                    {
                        m_InventoryTree
                    };
                    m_InventoryTree.ParentFolderID = folder.ID;
                    m_InventoryTree.Owner          = m_DestinationAgent;
                    m_InventoryTree.Version        = 1;
                    givenID   = m_InventoryTree.ID;
                    givenName = m_InventoryTree.Name;
                    List <UUID> noCopyItems = new List <UUID>();
                    while (folderCreator.Count != 0)
                    {
                        TransferInventoryFolder transferFolder = folderCreator[0];
                        m_DstInventoryService.Folder.Add(transferFolder);
                        foreach (InventoryItem item in transferFolder.Items)
                        {
                            if (!item.CheckPermissions(m_SrcAgent, UGI.Unknown, InventoryPermissionsMask.Copy))
                            {
                                noCopyItems.Add(item.ID);
                            }
                            item.SetNewID(UUID.Random);
                            item.LastOwner = item.Owner;
                            item.Owner     = m_DestinationAgent;
                            item.AdjustToNextOwner();
                            m_DstInventoryService.Item.Add(item);
                        }
                        foreach (TransferInventoryFolder childfolder in transferFolder.Folders)
                        {
                            childfolder.Owner          = m_DestinationAgent;
                            childfolder.ParentFolderID = transferFolder.ID;
                            childfolder.Version        = 1;
                            folderCreator.Add(childfolder);
                        }
                    }

                    if (noCopyItems.Count != 0)
                    {
                        m_SrcInventoryService.Item.Delete(m_SrcAgent.ID, noCopyItems);
                    }
                }
                else
                {
                    InventoryFolder folder;
                    if (!m_DstInventoryService.Folder.TryGetDefaultFolderOrFallback(m_DestinationAgent.ID, m_Item.AssetType, out folder))
                    {
#if DEBUG
                        m_Log.DebugFormat("Folder not found for {0} of {1}", m_Item.AssetType, m_DestinationAgent);
#endif
                        return;
                    }
                    UUID oldItemID  = m_Item.ID;
                    bool noCopyItem = !m_Item.CheckPermissions(m_SrcAgent, UGI.Unknown, InventoryPermissionsMask.Copy);
                    m_Item.SetNewID(UUID.Random);
                    assetType = m_Item.AssetType;
                    m_Item.AdjustToNextOwner();
                    m_Item.LastOwner      = m_Item.Owner;
                    m_Item.Owner          = m_DestinationAgent;
                    m_Item.ParentFolderID = folder.ID;
                    givenName             = m_Item.Name;
                    m_DstInventoryService.Item.Add(m_Item);
                    givenID = m_Item.ID;
                    if (noCopyItem)
                    {
                        m_SrcInventoryService.Item.Delete(m_SrcAgent.ID, oldItemID);
                    }
                }

                var binbuck = new byte[17];
                binbuck[0] = (byte)assetType;
                givenID.ToBytes(binbuck, 1);

                m_InventoryCreate?.Invoke(givenID);

                var im = new GridInstantMessage
                {
                    ToAgent      = m_DestinationAgent,
                    FromAgent    = m_SrcAgent,
                    Message      = givenName,
                    IMSessionID  = m_DstUserAgentService.RequiresInventoryIDAsIMSessionID ? givenID : m_TransactionID,
                    Dialog       = GridInstantMessageDialog.InventoryOffered,
                    BinaryBucket = binbuck,
                };
                m_IMService.Send(im);
            }
Esempio n. 2
0
        public void HandleObjectBuyWorkItem(object o)
        {
            var    req = (ObjectBuy)o;
            IAgent agent;

            if (!Agents.TryGetValue(req.AgentID, out agent))
            {
                return;
            }

            foreach (ObjectBuy.Data data in req.ObjectData)
            {
                ObjectPart part;
                if (!Primitives.TryGetValue(data.ObjectLocalID, out part))
                {
                    agent.SendAlertMessage(this.GetLanguageString(agent.CurrentCulture, "UnableToBuyDueNotFoundObject", "Unable to buy. The object was not found."), ID);
                }
                else
                {
                    Object.ObjectGroup grp = part.ObjectGroup;
                    if (grp.SalePrice != data.SalePrice || grp.SaleType != data.SaleType)
                    {
                        agent.SendAlertMessage(this.GetLanguageString(agent.CurrentCulture, "BuyingCurrentlyNotPossibleDueInvalidRequest", "Buying currently not possible since the viewer request is invalid. You might have to relog."), ID);
                    }
                    else if (grp.SalePrice != 0 && agent.EconomyService == null)
                    {
                        agent.SendAlertMessage(this.GetLanguageString(agent.CurrentCulture, "BuyingForAnyOtherPriceThanZeroIsNotPossible", "Buying for any other price than zero is not possible without economy system."), ID);
                    }
                    else
                    {
                        var       assetids        = new List <UUID>();
                        var       items           = new List <InventoryItem>();
                        bool      foundNoTransfer = false;
                        AssetData newAsset;
                        switch (grp.SaleType)
                        {
                        case InventoryItem.SaleInfoData.SaleType.NoSale:
                        default:
                            continue;

                        case InventoryItem.SaleInfoData.SaleType.Original:
                        case InventoryItem.SaleInfoData.SaleType.Copy:
                            UUID assetID;
                            if (grp.Owner == agent.Owner)
                            {
                                assetID = grp.OriginalAssetID;
                                if (assetID == UUID.Zero)
                                {
                                    newAsset    = grp.Asset(XmlSerializationOptions.WriteXml2 | XmlSerializationOptions.WriteOwnerInfo);
                                    assetID     = UUID.Random;
                                    newAsset.ID = assetID;
                                    AssetService.Store(newAsset);
                                    assetID             = newAsset.ID;
                                    grp.OriginalAssetID = assetID;
                                }
                            }
                            else
                            {
                                assetID = grp.NextOwnerAssetID;
                                if (assetID == UUID.Zero)
                                {
                                    newAsset    = grp.Asset(UGUI.Unknown, XmlSerializationOptions.WriteXml2 | XmlSerializationOptions.AdjustForNextOwner);
                                    assetID     = UUID.Random;
                                    newAsset.ID = assetID;
                                    AssetService.Store(newAsset);
                                    assetID = newAsset.ID;
                                    grp.NextOwnerAssetID = assetID;
                                }
                            }
                            assetids.Add(assetID);

                            if (grp.SaleType == InventoryItem.SaleInfoData.SaleType.Original)
                            {
                                Remove(grp);
                            }

                            bool foundNoCopy = false;
                            foreach (ObjectPart checkpart in grp.Values)
                            {
                                if (!checkpart.CheckPermissions(checkpart.Owner, checkpart.Group, InventoryPermissionsMask.Transfer))
                                {
                                    agent.SendAlertMessage(this.GetLanguageString(agent.CurrentCulture, "UnableToSellNoTransferItem", "Unable to sell no transfer item."), ID);
                                    foundNoTransfer = true;
                                    break;
                                }
                                if (grp.SaleType == InventoryItem.SaleInfoData.SaleType.Copy &&
                                    !checkpart.CheckPermissions(checkpart.Owner, checkpart.Group, InventoryPermissionsMask.Copy))
                                {
                                    agent.SendAlertMessage(this.GetLanguageString(agent.CurrentCulture, "UnableToSellNoCopyItemAsACopy", "Unable to sell no copy item as a copy."), ID);
                                    foundNoCopy = true;
                                    break;
                                }
                                foreach (ObjectPartInventoryItem item in checkpart.Inventory.Values)
                                {
                                    if (item.CheckPermissions(item.Owner, item.Group, InventoryPermissionsMask.Transfer))
                                    {
                                        agent.SendAlertMessage(this.GetLanguageString(agent.CurrentCulture, "UnableToSellNoTransferItem", "Unable to sell no transfer item."), ID);
                                        foundNoTransfer = true;
                                        break;
                                    }
                                }
                            }
                            if (foundNoTransfer || foundNoCopy)
                            {
                                continue;
                            }
                            var objectItem = new InventoryItem
                            {
                                Name          = grp.Name,
                                Description   = grp.Description,
                                LastOwner     = grp.Owner,
                                Owner         = agent.Owner,
                                AssetID       = assetID,
                                AssetType     = AssetType.Object,
                                InventoryType = InventoryType.Object
                            };
                            objectItem.Permissions.Base      = grp.RootPart.BaseMask;
                            objectItem.Permissions.EveryOne  = grp.RootPart.EveryoneMask;
                            objectItem.Permissions.Group     = InventoryPermissionsMask.None;
                            objectItem.Permissions.NextOwner = grp.RootPart.NextOwnerMask;
                            objectItem.Permissions.Current   = objectItem.Permissions.Base;
                            if (!agent.Owner.EqualsGrid(grp.Owner))
                            {
                                objectItem.AdjustToNextOwner();
                            }
                            items.Add(objectItem);
                            break;

                        case InventoryItem.SaleInfoData.SaleType.Content:
                            foreach (ObjectPartInventoryItem item in part.Inventory.Values)
                            {
                                if (!item.CheckPermissions(item.Owner, item.Group, InventoryPermissionsMask.Transfer))
                                {
                                    agent.SendAlertMessage(this.GetLanguageString(agent.CurrentCulture, "UnableToSellNoTransferItem", "Unable to sell no transfer item."), ID);
                                    foundNoTransfer = true;
                                    break;
                                }
                            }

                            if (foundNoTransfer)
                            {
                                continue;
                            }

                            foreach (ObjectPartInventoryItem item in part.Inventory.Values)
                            {
                                assetID = item.NextOwnerAssetID;
                                if (assetID == UUID.Zero && !item.Owner.EqualsGrid(agent.Owner))
                                {
                                    /* create next owner asset id */
                                    item.NextOwnerAssetID = AssetService.GenerateNextOwnerAsset(assetID);
                                }
                                var newItem = new InventoryItem(item);
                                if (!item.Owner.EqualsGrid(agent.Owner))
                                {
                                    newItem.AssetID = item.NextOwnerAssetID;
                                    newItem.AdjustToNextOwner();
                                }
                                assetids.Add(newItem.AssetID);

                                items.Add(newItem);
                                if (!item.CheckPermissions(item.Owner, item.Group, InventoryPermissionsMask.Copy))
                                {
                                    part.Inventory.Remove(item.ID);
                                }
                            }
                            break;
                        }

                        if (grp.SalePrice == 0)
                        {
                            new ObjectBuyTransferItem(
                                agent,
                                this,
                                assetids,
                                items,
                                grp.SaleType == InventoryItem.SaleInfoData.SaleType.Content ? part.Name : string.Empty,
                                part.ID).QueueWorkItem();
                        }
                        else if (agent.EconomyService != null)
                        {
                            IActiveTransaction transaction;
                            try
                            {
                                transaction = agent.EconomyService.BeginTransferTransaction(agent.Owner, part.Owner,
                                                                                            grp.SaleType == InventoryItem.SaleInfoData.SaleType.Content ?
                                                                                            (BaseTransaction) new ObjectInventorySaleTransaction(
                                                                                                GridPosition,
                                                                                                ID,
                                                                                                Name)
                                {
                                    ObjectID   = grp.ID,
                                    ObjectName = grp.Name
                                } :
                                                                                            new ObjectSaleTransaction(
                                                                                                GridPosition,
                                                                                                ID,
                                                                                                Name)
                                {
                                    ObjectID   = grp.ID,
                                    ObjectName = grp.Name
                                },
                                                                                            grp.SalePrice);
                            }
                            catch (InsufficientFundsException)
                            {
                                agent.SendAlertMessage(this.GetLanguageString(agent.CurrentCulture, "UnableToBuyInsufficientFunds", "Unable to buy. Insufficient funds."), ID);
                                continue;
                            }
                            catch (Exception e)
                            {
                                m_Log.Error("Exception at object selling", e);
                                agent.SendAlertMessage(e.Message, ID);
                                continue;
                            }

                            new ObjectBuyTransferItem(
                                agent,
                                this,
                                assetids,
                                items,
                                grp.SaleType == InventoryItem.SaleInfoData.SaleType.Content ? part.Name : string.Empty,
                                part.ID,
                                transaction).QueueWorkItem();
                        }
                        else
                        {
                            agent.SendAlertMessage(this.GetLanguageString(agent.CurrentCulture, "UnableToBuyNoEconomyConfigured", "Unable to buy. No economy configured."), ID);
                        }
                    }
                }
            }
        }