protected SceneObjectGroup RezSingleAttachmentFromInventoryInternal(
            IClientAPI remoteClient, UUID itemID, uint AttachmentPt)
        {
            IInventoryAccessModule invAccess = m_scene.RequestModuleInterface <IInventoryAccessModule>();

            if (invAccess != null)
            {
                SceneObjectGroup objatt = invAccess.RezObject(remoteClient,
                                                              itemID, Vector3.Zero, Vector3.Zero, UUID.Zero, (byte)1, true,
                                                              false, false, remoteClient.AgentId, true);

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

                if (objatt != null)
                {
                    bool tainted = false;
                    if (AttachmentPt != 0 && AttachmentPt != objatt.GetAttachmentPoint())
                    {
                        tainted = true;
                    }

                    // This will throw if the attachment fails
                    try
                    {
                        AttachObject(remoteClient, objatt, AttachmentPt, false);
                    }
                    catch
                    {
                        // Make sure the object doesn't stick around and bail
                        m_scene.DeleteSceneObject(objatt, false);
                        return(null);
                    }

                    if (tainted)
                    {
                        objatt.HasGroupChanged = true;
                    }

                    // Fire after attach, so we don't get messy perms dialogs
                    // 4 == AttachedRez
                    objatt.CreateScriptInstances(0, true, m_scene.DefaultScriptEngine, 4);
                    objatt.ResumeScripts();

                    // Do this last so that event listeners have access to all the effects of the attachment
                    m_scene.EventManager.TriggerOnAttach(objatt.LocalId, itemID, remoteClient.AgentId);
                }
                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);
        }
        private SceneObjectGroup RezSingleAttachmentFromInventoryInternal(
            IScenePresence sp, UUID itemID, UUID assetID, uint attachmentPt)
        {
            IInventoryAccessModule invAccess = m_scene.RequestModuleInterface <IInventoryAccessModule>();

            if (invAccess != null)
            {
                lock (sp.AttachmentsSyncLock)
                {
                    SceneObjectGroup objatt;

                    if (itemID != UUID.Zero)
                    {
                        objatt = invAccess.RezObject(sp.ControllingClient,
                                                     itemID, Vector3.Zero, Vector3.Zero, UUID.Zero, (byte)1, true,
                                                     false, false, sp.UUID, true);
                    }
                    else
                    {
                        objatt = invAccess.RezObject(sp.ControllingClient,
                                                     null, assetID, Vector3.Zero, Vector3.Zero, UUID.Zero, (byte)1, true,
                                                     false, false, sp.UUID, true);
                    }

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

                    if (objatt != null)
                    {
                        // HasGroupChanged is being set from within RezObject.  Ideally it would be set by the caller.
                        objatt.HasGroupChanged = false;
                        bool tainted = false;
                        if (attachmentPt != 0 && attachmentPt != objatt.AttachmentPoint)
                        {
                            tainted = true;
                        }

                        // This will throw if the attachment fails
                        try
                        {
                            AttachObject(sp, objatt, attachmentPt, false);
                        }
                        catch (Exception e)
                        {
                            m_log.ErrorFormat(
                                "[ATTACHMENTS MODULE]: Failed to attach {0} {1} for {2}, exception {3}{4}",
                                objatt.Name, objatt.UUID, sp.Name, e.Message, e.StackTrace);

                            // Make sure the object doesn't stick around and bail
                            sp.RemoveAttachment(objatt);
                            m_scene.DeleteSceneObject(objatt, false);
                            return(null);
                        }

                        if (tainted)
                        {
                            objatt.HasGroupChanged = true;
                        }

                        // Fire after attach, so we don't get messy perms dialogs
                        // 4 == AttachedRez
                        objatt.CreateScriptInstances(0, true, m_scene.DefaultScriptEngine, 4);
                        objatt.ResumeScripts();

                        // Do this last so that event listeners have access to all the effects of the attachment
                        m_scene.EventManager.TriggerOnAttach(objatt.LocalId, itemID, sp.UUID);

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

            return(null);
        }
Esempio n. 3
0
        private SceneObjectGroup RezSingleAttachmentFromInventoryInternal(
            IScenePresence sp, UUID itemID, UUID assetID, uint attachmentPt)
        {
            if (m_invAccessModule == null)
            {
                return(null);
            }

            lock (sp.AttachmentsSyncLock)
            {
                SceneObjectGroup objatt;

                if (itemID != UUID.Zero)
                {
                    objatt = m_invAccessModule.RezObject(sp.ControllingClient,
                                                         itemID, Vector3.Zero, Vector3.Zero, UUID.Zero, (byte)1, true,
                                                         false, false, sp.UUID, true);
                }
                else
                {
                    objatt = m_invAccessModule.RezObject(sp.ControllingClient,
                                                         null, assetID, Vector3.Zero, Vector3.Zero, UUID.Zero, (byte)1, true,
                                                         false, false, sp.UUID, true);
                }

                if (objatt != null)
                {
//                    m_log.DebugFormat(
//                        "[ATTACHMENTS MODULE]: Rezzed single object {0} for attachment to {1} on point {2} in {3}",
//                        objatt.Name, sp.Name, attachmentPt, m_scene.Name);

                    // HasGroupChanged is being set from within RezObject.  Ideally it would be set by the caller.
                    objatt.HasGroupChanged = false;
                    bool tainted = false;
                    if (attachmentPt != 0 && attachmentPt != objatt.AttachmentPoint)
                    {
                        tainted = true;
                    }

                    // FIXME: Detect whether it's really likely for AttachObject to throw an exception in the normal
                    // course of events.  If not, then it's probably not worth trying to recover the situation
                    // since this is more likely to trigger further exceptions and confuse later debugging.  If
                    // exceptions can be thrown in expected error conditions (not NREs) then make this consistent
                    // since other normal error conditions will simply return false instead.
                    // This will throw if the attachment fails
                    try
                    {
                        AttachObjectInternal(sp, objatt, attachmentPt, false, false);
                    }
                    catch (Exception e)
                    {
                        m_log.ErrorFormat(
                            "[ATTACHMENTS MODULE]: Failed to attach {0} {1} for {2}, exception {3}{4}",
                            objatt.Name, objatt.UUID, sp.Name, e.Message, e.StackTrace);

                        // Make sure the object doesn't stick around and bail
                        sp.RemoveAttachment(objatt);
                        m_scene.DeleteSceneObject(objatt, false);
                        return(null);
                    }

                    if (tainted)
                    {
                        objatt.HasGroupChanged = true;
                    }

                    // Fire after attach, so we don't get messy perms dialogs
                    // 4 == AttachedRez
                    objatt.CreateScriptInstances(0, true, m_scene.DefaultScriptEngine, 4);
                    objatt.ResumeScripts();

                    // Do this last so that event listeners have access to all the effects of the attachment
                    m_scene.EventManager.TriggerOnAttach(objatt.LocalId, itemID, sp.UUID);

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

            return(null);
        }