protected void ObjectSaleInfo(
            IClientAPI client, UUID sessionID, uint localID, byte saleType, int salePrice)
        {
            ISceneChildEntity part = m_scene.GetSceneObjectPart(localID);

            if (part == null || part.ParentEntity == null)
            {
                return;
            }

            if (part.ParentEntity.IsDeleted)
            {
                return;
            }

            if (part.OwnerID != client.AgentId && (!m_scene.Permissions.IsGod(client.AgentId)))
            {
                return;
            }

            part = part.ParentEntity.RootChild;

            part.ObjectSaleType = saleType;
            part.SalePrice      = salePrice;

            part.ParentEntity.HasGroupChanged = true;

            part.GetProperties(client);
        }
Exemple #2
0
        //private void CreateItemFromUpload(AssetBase asset, IClientAPI ourClient, UUID inventoryFolderID, uint nextPerms, uint wearableType)
        //{
        //    Manager.MyScene.CommsManager.AssetCache.AddAsset(asset);
        //    CachedUserInfo userInfo = Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails(
        //            ourClient.AgentId);

        //    if (userInfo != null)
        //    {
        //        InventoryItemBase item = new InventoryItemBase();
        //        item.Owner = ourClient.AgentId;
        //        item.Creator = ourClient.AgentId;
        //        item.ID = UUID.Random();
        //        item.AssetID = asset.FullID;
        //        item.Description = asset.Description;
        //        item.Name = asset.Name;
        //        item.AssetType = asset.Type;
        //        item.InvType = asset.Type;
        //        item.Folder = inventoryFolderID;
        //        item.BasePermissions = 0x7fffffff;
        //        item.CurrentPermissions = 0x7fffffff;
        //        item.EveryOnePermissions = 0;
        //        item.NextPermissions = nextPerms;
        //        item.Flags = wearableType;
        //        item.CreationDate = Util.UnixTimeSinceEpoch();

        //        userInfo.AddItem(item);
        //        ourClient.SendInventoryItemCreateUpdate(item);
        //    }
        //    else
        //    {
        //        MainConsole.Instance.ErrorFormat(
        //            "[ASSET TRANSACTIONS]: Could not find user {0} for inventory item creation",
        //            ourClient.AgentId);
        //    }
        //}

        public void RequestUpdateTaskInventoryItem(
            IClientAPI remoteClient, ISceneChildEntity part, UUID transactionID, TaskInventoryItem item)
        {
            if (XferUploaders.ContainsKey(transactionID))
            {
                AssetBase asset = XferUploaders[transactionID].GetAssetData();
                if (asset != null)
                {
                    MainConsole.Instance.DebugFormat(
                        "[ASSET TRANSACTIONS]: Updating task item {0} in {1} with asset in transaction {2}",
                        item.Name, part.Name, transactionID);

                    asset.Name        = item.Name;
                    asset.Description = item.Description;
                    asset.Type        = (sbyte)item.Type;
                    item.AssetID      = asset.ID;

                    IMonitorModule monitorModule = Manager.MyScene.RequestModuleInterface <IMonitorModule>();
                    if (monitorModule != null)
                    {
                        INetworkMonitor networkMonitor =
                            (INetworkMonitor)
                            monitorModule.GetMonitor(Manager.MyScene.RegionInfo.RegionID.ToString(),
                                                     MonitorModuleHelper.NetworkMonitor);
                        networkMonitor.AddPendingUploads(-1);
                    }

                    asset.ID     = Manager.MyScene.AssetService.Store(asset);
                    item.AssetID = asset.ID;

                    if (part.Inventory.UpdateInventoryItem(item))
                    {
                        if ((InventoryType)item.InvType == InventoryType.Notecard)
                        {
                            remoteClient.SendAgentAlertMessage("Notecard saved", false);
                        }
                        else if ((InventoryType)item.InvType == InventoryType.LSL)
                        {
                            remoteClient.SendAgentAlertMessage("Script saved", false);
                        }
                        else
                        {
                            remoteClient.SendAgentAlertMessage("Item saved", false);
                        }

                        part.GetProperties(remoteClient);
                    }
                }
            }
        }
        public bool BuyObject(IClientAPI remoteClient, UUID categoryID, uint localID, byte saleType, int salePrice)
        {
            ISceneChildEntity part = m_scene.GetSceneObjectPart(localID);

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

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

            ISceneEntity       group           = part.ParentEntity;
            ILLClientInventory inventoryModule = m_scene.RequestModuleInterface <ILLClientInventory>();

            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 (ISceneChildEntity child in group.ChildrenEntities())
                    {
                        child.Inventory.ChangeInventoryOwner(remoteClient.AgentId);
                        child.TriggerScriptChangedEvent(Changed.OWNER);
                        child.ApplyNextOwnerPermissions();
                    }
                }

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

                group.HasGroupChanged = true;
                part.GetProperties(remoteClient);
                part.TriggerScriptChangedEvent(Changed.OWNER);
                group.ResumeScripts();
                part.ScheduleUpdate(PrimUpdateFlags.ForcedFullUpdate);

                break;

            case 2:     // Sell a copy
                Vector3 inventoryStoredPosition = new Vector3
                                                      (((group.AbsolutePosition.X > m_scene.RegionInfo.RegionSizeX)
                              ? m_scene.RegionInfo.RegionSizeX - 1
                              : group.AbsolutePosition.X)
                                                      ,
                                                      (group.AbsolutePosition.X > m_scene.RegionInfo.RegionSizeY)
                             ? m_scene.RegionInfo.RegionSizeY - 1
                             : group.AbsolutePosition.X,
                                                      group.AbsolutePosition.Z);

                Vector3 originalPosition = group.AbsolutePosition;

                group.AbsolutePosition = inventoryStoredPosition;

                string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat((SceneObjectGroup)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 = new AssetBase(UUID.Random(), part.Name,
                                                AssetType.Object, group.OwnerID)
                {
                    Description = part.Description, Data = Utils.StringToBytes(sceneObjectXml)
                };
                asset.ID = m_scene.AssetService.Store(asset);

                InventoryItemBase item = new InventoryItemBase
                {
                    CreatorId   = part.CreatorID.ToString(),
                    CreatorData = part.CreatorData,
                    ID          = UUID.Random(),
                    Owner       = remoteClient.AgentId,
                    AssetID     = asset.ID,
                    Description = asset.Description,
                    Name        = asset.Name,
                    AssetType   = asset.Type,
                    InvType     = (int)InventoryType.Object,
                    Folder      = categoryID
                };


                uint nextPerms = (perms & 7) << 13;
                if ((nextPerms & (uint)PermissionMask.Copy) == 0)
                {
                    perms &= ~(uint)PermissionMask.Copy;
                }
                if ((nextPerms & (uint)PermissionMask.Transfer) == 0)
                {
                    perms &= ~(uint)PermissionMask.Transfer;
                }
                if ((nextPerms & (uint)PermissionMask.Modify) == 0)
                {
                    perms &= ~(uint)PermissionMask.Modify;
                }

                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.CurrentPermissions |= 16;     // Slam!
                item.CreationDate        = Util.UnixTimeSinceEpoch();

                if (inventoryModule != null)
                {
                    if (inventoryModule.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();

#if (!ISWIN)
                bool okToSell = true;
                foreach (UUID invId in invList)
                {
                    TaskInventoryItem item1 = part.Inventory.GetInventoryItem(invId);
                    if ((item1.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
                    {
                        okToSell = false;
                        break;
                    }
                }
#else
                bool okToSell = invList.Select(invID => part.Inventory.GetInventoryItem(invID)).All(item1 => (item1.CurrentPermissions & (uint)PermissionMask.Transfer) != 0);
#endif

                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)
                {
                    if (inventoryModule != null)
                    {
                        inventoryModule.MoveTaskInventoryItemsToUserInventory(remoteClient.AgentId, part.Name, part,
                                                                              invList);
                    }
                }
                break;
            }

            return(true);
        }
        //private void CreateItemFromUpload(AssetBase asset, IClientAPI ourClient, UUID inventoryFolderID, uint nextPerms, uint wearableType)
        //{
        //    Manager.MyScene.CommsManager.AssetCache.AddAsset(asset);
        //    CachedUserInfo userInfo = Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails(
        //            ourClient.AgentId);

        //    if (userInfo != null)
        //    {
        //        InventoryItemBase item = new InventoryItemBase();
        //        item.Owner = ourClient.AgentId;
        //        item.Creator = ourClient.AgentId;
        //        item.ID = UUID.Random();
        //        item.AssetID = asset.FullID;
        //        item.Description = asset.Description;
        //        item.Name = asset.Name;
        //        item.AssetType = asset.Type;
        //        item.InvType = asset.Type;
        //        item.Folder = inventoryFolderID;
        //        item.BasePermissions = 0x7fffffff;
        //        item.CurrentPermissions = 0x7fffffff;
        //        item.EveryOnePermissions = 0;
        //        item.NextPermissions = nextPerms;
        //        item.Flags = wearableType;
        //        item.CreationDate = Util.UnixTimeSinceEpoch();

        //        userInfo.AddItem(item);
        //        ourClient.SendInventoryItemCreateUpdate(item);
        //    }
        //    else
        //    {
        //        m_log.ErrorFormat(
        //            "[ASSET TRANSACTIONS]: Could not find user {0} for inventory item creation",
        //            ourClient.AgentId);
        //    }
        //}

        public void RequestUpdateTaskInventoryItem(
           IClientAPI remoteClient, ISceneChildEntity part, UUID transactionID, TaskInventoryItem item)
        {
            if (XferUploaders.ContainsKey(transactionID))
            {
                AssetBase asset = XferUploaders[transactionID].GetAssetData();
                if (asset != null)
                {
                    m_log.DebugFormat(
                        "[ASSET TRANSACTIONS]: Updating task item {0} in {1} with asset in transaction {2}",
                        item.Name, part.Name, transactionID);

                    asset.Name = item.Name;
                    asset.Description = item.Description;
                    asset.Type = (sbyte)item.Type;
                    item.AssetID = asset.ID;

                    IMonitorModule monitorModule = Manager.MyScene.RequestModuleInterface<IMonitorModule>();
                    if (monitorModule != null)
                    {
                        INetworkMonitor networkMonitor = (INetworkMonitor)monitorModule.GetMonitor(Manager.MyScene.RegionInfo.RegionID.ToString(), MonitorModuleHelper.NetworkMonitor);
                        networkMonitor.AddPendingUploads(-1);
                    }

                    asset.ID = Manager.MyScene.AssetService.Store(asset);
                    item.AssetID = asset.ID;

                    if (part.Inventory.UpdateInventoryItem(item))
                    {
                        if ((InventoryType)item.InvType == InventoryType.Notecard)
                            remoteClient.SendAgentAlertMessage("Notecard saved", false);
                        else if ((InventoryType)item.InvType == InventoryType.LSL)
                            remoteClient.SendAgentAlertMessage("Script saved", false);
                        else
                            remoteClient.SendAgentAlertMessage("Item saved", false);

                        part.GetProperties(remoteClient);
                    }
                }
            }
        }