Beispiel #1
0
        public ISceneEntity RezSingleAttachmentFromInventory(
            IClientAPI remoteClient, UUID itemID, int AttachmentPt)
        {
            m_log.DebugFormat(
                "[ATTACHMENTS MODULE]: Rezzing attachment to point {0} from item {1} for {2}",
                (AttachmentPoint)AttachmentPt, itemID, remoteClient.Name);
            IInventoryAccessModule invAccess = m_scene.RequestModuleInterface <IInventoryAccessModule>();

            if (invAccess != null)
            {
                SceneObjectGroup objatt = invAccess.CreateObjectFromInventory(remoteClient,
                                                                              itemID);

                if (objatt != null)
                {
                    #region Set up object for attachment status

                    InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
                    item = m_scene.InventoryService.GetItem(item);

                    objatt.RootPart.Flags       |= PrimFlags.Phantom;
                    objatt.RootPart.IsAttachment = true;
                    objatt.SetFromItemID(itemID);

                    // Since renaming the item in the inventory does not affect the name stored
                    // in the serialization, transfer the correct name from the inventory to the
                    // object itself before we rez.
                    objatt.RootPart.Name        = item.Name;
                    objatt.RootPart.Description = item.Description;

                    List <SceneObjectPart> partList = new List <SceneObjectPart>(objatt.ChildrenList);

                    objatt.SetGroup(remoteClient.ActiveGroupId, remoteClient);
                    if (objatt.RootPart.OwnerID != item.Owner)
                    {
                        //Need to kill the for sale here
                        objatt.RootPart.ObjectSaleType = 0;
                        objatt.RootPart.SalePrice      = 10;

                        if (m_scene.Permissions.PropagatePermissions())
                        {
                            if ((item.CurrentPermissions & 8) != 0)
                            {
                                foreach (SceneObjectPart part in partList)
                                {
                                    part.EveryoneMask  = item.EveryOnePermissions;
                                    part.NextOwnerMask = item.NextPermissions;
                                    part.GroupMask     = 0; // DO NOT propagate here
                                }
                            }

                            objatt.ApplyNextOwnerPermissions();
                        }
                    }

                    foreach (SceneObjectPart part in partList)
                    {
                        if (part.OwnerID != item.Owner)
                        {
                            part.LastOwnerID = part.OwnerID;
                            part.OwnerID     = item.Owner;
                            part.Inventory.ChangeInventoryOwner(item.Owner);
                        }
                    }
                    objatt.RootPart.TrimPermissions();
                    objatt.RootPart.IsAttachment = true;
                    objatt.IsDeleted             = false;

                    //NOTE: we MUST do this manually, otherwise it will never be added!
                    //We also have to reset the IDs!
                    //Note: root first, as we have to set the parentID right!
                    m_scene.SceneGraph.PrepPrimForAdditionToScene(objatt);
                    m_scene.Entities.Add(objatt);

                    #endregion

                    //                m_log.DebugFormat(
                    //                    "[ATTACHMENTS MODULE]: Retrieved single object {0} for attachment to {1} on point {2}",
                    //                    objatt.Name, remoteClient.Name, AttachmentPt);

                    FindAttachmentPoint(remoteClient, objatt.LocalId, objatt, AttachmentPt, item);
                }
                else
                {
                    m_log.WarnFormat(
                        "[ATTACHMENTS MODULE]: Could not retrieve item {0} for attaching to avatar {1} at point {2}",
                        itemID, remoteClient.Name, AttachmentPt);
                }

                return(objatt);
            }

            return(null);
        }
Beispiel #2
0
        public ISceneEntity RezSingleAttachmentFromInventory(
            IClientAPI remoteClient, UUID itemID, UUID assetID, int AttachmentPt, bool updateUUIDs)
        {
            MainConsole.Instance.DebugFormat(
                "[ATTACHMENTS MODULE]: Rezzing attachment to point {0} from item {1} for {2}",
                (AttachmentPoint)AttachmentPt, itemID, remoteClient.Name);
            IInventoryAccessModule invAccess = m_scene.RequestModuleInterface <IInventoryAccessModule>();

            if (invAccess != null)
            {
                InventoryItemBase item   = null;
                ISceneEntity      objatt = assetID == UUID.Zero
                                          ? invAccess.CreateObjectFromInventory(remoteClient,
                                                                                itemID, out item)
                                          : invAccess.CreateObjectFromInventory(remoteClient, itemID, assetID, null);

                if (objatt != null)
                {
                    #region Set up object for attachment status

                    if (item != null)
                    {
                        assetID = item.AssetID;

                        // Since renaming the item in the inventory does not affect the name stored
                        // in the serialization, transfer the correct name from the inventory to the
                        // object itself before we rez.
                        objatt.RootChild.Name        = item.Name;
                        objatt.RootChild.Description = item.Description;
                    }

                    objatt.RootChild.Flags       |= PrimFlags.Phantom;
                    objatt.RootChild.IsAttachment = true;
                    objatt.SetFromItemID(itemID, assetID);

                    List <ISceneChildEntity> partList = new List <ISceneChildEntity>(objatt.ChildrenEntities());

                    foreach (ISceneChildEntity part in partList)
                    {
                        part.AttachedAvatar = remoteClient.AgentId;
                    }

                    objatt.SetGroup(remoteClient.ActiveGroupId, remoteClient.AgentId, false);
                    if (objatt.RootChild.OwnerID != remoteClient.AgentId)
                    {
                        //Need to kill the for sale here
                        objatt.RootChild.ObjectSaleType = 0;
                        objatt.RootChild.SalePrice      = 10;

                        if (m_scene.Permissions.PropagatePermissions())
                        {
                            if (item == null)
                            {
                                item = m_scene.InventoryService.GetItem(remoteClient.AgentId, itemID);
                            }
                            if (item == null)
                            {
                                return(null);
                            }
                            if ((item.CurrentPermissions & 8) != 0)
                            {
                                foreach (ISceneChildEntity part in partList)
                                {
                                    part.EveryoneMask  = item.EveryOnePermissions;
                                    part.NextOwnerMask = item.NextPermissions;
                                    part.GroupMask     = 0; // DO NOT propagate here
                                }
                            }

                            objatt.ApplyNextOwnerPermissions();
                        }
                    }

                    foreach (ISceneChildEntity part in partList)
                    {
                        if (part.OwnerID != remoteClient.AgentId)
                        {
                            part.LastOwnerID = part.OwnerID;
                            part.OwnerID     = remoteClient.AgentId;
                            part.Inventory.ChangeInventoryOwner(remoteClient.AgentId);
                        }
                    }
                    objatt.RootChild.TrimPermissions();
                    objatt.RootChild.IsAttachment = true;
                    objatt.IsDeleted = false;

                    //Update the ItemID with the new item
                    objatt.SetFromItemID(itemID, assetID);

                    //We also have to reset the IDs so that it doesn't have the same IDs as one inworld (possibly)!
                    ISceneEntity[] atts = GetAttachmentsForAvatar(remoteClient.AgentId);
                    foreach (var obj in atts)
                    {
                        if (obj.UUID == objatt.UUID)
                        {
                            updateUUIDs = false; //If the user is already wearing it, don't readd
                        }
                    }
                    bool forceUpdateOnNextDeattach = false;
                    try
                    {
                        bool foundDuplicate = false;
                        foreach (var obj in atts)
                        {
                            if (obj.RootChild.FromUserInventoryItemID == objatt.RootChild.FromUserInventoryItemID)
                            {
                                foundDuplicate = true;
                            }
                        }
                        IEntity e;
                        if (!m_scene.SceneGraph.TryGetEntity(objatt.UUID, out e)) //if (updateUUIDs)
                        {
                            foreach (var prim in objatt.ChildrenEntities())
                            {
                                prim.LocalId = 0;
                            }
                            bool success = m_scene.SceneGraph.RestorePrimToScene(objatt, false);
                            if (!success)
                            {
                                MainConsole.Instance.Error("[AttachmentModule]: Failed to add attachment " + objatt.Name +
                                                           " for user " + remoteClient.Name + "!");
                                return(null);
                            }
                        }
                        else
                        {
                            if (!foundDuplicate)
                            {
                                //If the user has information stored about this object, we need to force updating next time
                                if (m_scene.SceneGraph.AddPrimToScene(objatt))
                                {
                                    forceUpdateOnNextDeattach = true;
                                }
                            }
                            else
                            {
                                if (e as ISceneEntity != null)
                                {
                                    (e as ISceneEntity).ScheduleGroupUpdate(PrimUpdateFlags.ForcedFullUpdate);
                                }

                                return(e as ISceneEntity);  //It was already added
                            }
                        }
                    }
                    catch
                    {
                    }

                    //If we updated the attachment, we need to save the change
                    IScenePresence presence = m_scene.GetScenePresence(remoteClient.AgentId);
                    if (presence != null)
                    {
                        FindAttachmentPoint(remoteClient, objatt.LocalId, objatt, AttachmentPt, assetID,
                                            forceUpdateOnNextDeattach, false);
                    }
                    else
                    {
                        objatt = null; //Presence left, kill the attachment
                    }
                    #endregion
                }
                else
                {
                    MainConsole.Instance.WarnFormat(
                        "[ATTACHMENTS MODULE]: Could not retrieve item {0} for attaching to avatar {1} at point {2}",
                        itemID, remoteClient.Name, AttachmentPt);
                }

                return(objatt);
            }

            return(null);
        }
Beispiel #3
0
        public ISceneEntity RezSingleAttachmentFromInventory(
            IClientAPI remoteClient, UUID itemID, int AttachmentPt)
        {
            MainConsole.Instance.DebugFormat(
                "[ATTACHMENTS MODULE]: Rezzing attachment to point {0} from item {1} for {2}",
                (AttachmentPoint)AttachmentPt, itemID, remoteClient.Name);
            IInventoryAccessModule invAccess = m_scene.RequestModuleInterface <IInventoryAccessModule>();

            if (invAccess != null)
            {
                SceneObjectGroup objatt = invAccess.CreateObjectFromInventory(remoteClient,
                                                                              itemID);

                if (objatt != null)
                {
                    #region Set up object for attachment status

                    InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
                    item = m_scene.InventoryService.GetItem(item);
                    if (item == null)
                    {
                        return(null);
                    }

                    objatt.RootPart.Flags       |= PrimFlags.Phantom;
                    objatt.RootPart.IsAttachment = true;
                    objatt.SetFromItemID(itemID, item.AssetID);

                    // Since renaming the item in the inventory does not affect the name stored
                    // in the serialization, transfer the correct name from the inventory to the
                    // object itself before we rez.
                    objatt.RootPart.Name        = item.Name;
                    objatt.RootPart.Description = item.Description;

                    List <SceneObjectPart> partList = new List <SceneObjectPart>(objatt.ChildrenList);

                    foreach (SceneObjectPart part in partList)
                    {
                        part.AttachedAvatar = remoteClient.AgentId;
                    }

                    objatt.SetGroup(remoteClient.ActiveGroupId, remoteClient.AgentId);
                    if (objatt.RootPart.OwnerID != item.Owner)
                    {
                        //Need to kill the for sale here
                        objatt.RootPart.ObjectSaleType = 0;
                        objatt.RootPart.SalePrice      = 10;

                        if (m_scene.Permissions.PropagatePermissions())
                        {
                            if ((item.CurrentPermissions & 8) != 0)
                            {
                                foreach (SceneObjectPart part in partList)
                                {
                                    part.EveryoneMask  = item.EveryOnePermissions;
                                    part.NextOwnerMask = item.NextPermissions;
                                    part.GroupMask     = 0; // DO NOT propagate here
                                }
                            }

                            objatt.ApplyNextOwnerPermissions();
                        }
                    }

                    foreach (SceneObjectPart part in partList)
                    {
                        if (part.OwnerID != item.Owner)
                        {
                            part.LastOwnerID = part.OwnerID;
                            part.OwnerID     = item.Owner;
                            part.Inventory.ChangeInventoryOwner(item.Owner);
                        }
                    }
                    objatt.RootPart.TrimPermissions();
                    objatt.RootPart.IsAttachment = true;
                    objatt.IsDeleted             = false;

                    //Update the ItemID with the new item
                    objatt.SetFromItemID(itemID, item.AssetID);

                    //DO NOT SEND THIS KILL ENTITY
                    // If we send this, when someone copies an inworld object, then wears it, the inworld objects disapepars
                    // If a bug is caused by this, we need to figure out some other workaround.
                    //SendKillEntity(objatt.RootChild);
                    //We also have to reset the IDs so that it doesn't have the same IDs as one inworld (possibly)!
                    m_scene.SceneGraph.PrepPrimForAdditionToScene(objatt);
                    m_scene.Entities.Add(objatt);

                    //If we updated the attachment, we need to save the change
                    IScenePresence presence = m_scene.GetScenePresence(remoteClient.AgentId);
                    if (presence != null)
                    {
                        IAvatarAppearanceModule appearance = presence.RequestModuleInterface <IAvatarAppearanceModule>();
                        AvatarAttachments       attPlugin  = presence.RequestModuleInterface <AvatarAttachments>();
                        bool save = appearance.Appearance.CheckWhetherAttachmentChanged(AttachmentPt, item.ID, item.AssetID);
                        attPlugin.AddAttachment(objatt);
                        appearance.Appearance.SetAttachments(attPlugin.Get());
                        if (save)
                        {
                            AvatarFactory.QueueAppearanceSave(remoteClient.AgentId);
                        }

                        MainConsole.Instance.InfoFormat(
                            "[ATTACHMENTS MODULE]: Retrieved single object {0} for attachment to {1} on point {2} localID {3}",
                            objatt.Name, remoteClient.Name, AttachmentPt, objatt.LocalId);

                        FindAttachmentPoint(remoteClient, objatt.LocalId, objatt, AttachmentPt, item);
                    }
                    else
                    {
                        objatt = null;//Presence left, kill the attachment
                    }
                    #endregion
                }
                else
                {
                    MainConsole.Instance.WarnFormat(
                        "[ATTACHMENTS MODULE]: Could not retrieve item {0} for attaching to avatar {1} at point {2}",
                        itemID, remoteClient.Name, AttachmentPt);
                }

                return(objatt);
            }

            return(null);
        }