private void UpdateUserInventoryWithAttachment(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool temp) { // Remove any previous attachments List <SceneObjectGroup> attachments = sp.GetAttachments(attachmentPt); // At the moment we can only deal with a single attachment if (attachments.Count != 0) { if (attachments[0].FromItemID != UUID.Zero) { DetachSingleAttachmentToInvInternal(sp, attachments[0]); } // Error logging commented because UUID.Zero now means temp attachment // else // m_log.WarnFormat( // "[ATTACHMENTS MODULE]: When detaching existing attachment {0} {1} at point {2} to make way for {3} {4} for {5}, couldn't find the associated item ID to adjust inventory attachment record!", // attachments[0].Name, attachments[0].LocalId, attachmentPt, group.Name, group.LocalId, sp.Name); } // Add the new attachment to inventory if we don't already have it. if (!temp) { UUID newAttachmentItemID = group.FromItemID; if (newAttachmentItemID == UUID.Zero) { newAttachmentItemID = AddSceneObjectAsNewAttachmentInInv(sp, group).ID; } ShowAttachInUserInventory(sp, attachmentPt, newAttachmentItemID, group); } }
public void CopyAttachments(IScenePresence sp, AgentData ad) { lock (sp.AttachmentsSyncLock) { // Attachment objects List <SceneObjectGroup> attachments = sp.GetAttachments(); if (attachments.Count > 0) { ad.AttachmentObjects = new List <ISceneObject>(); ad.AttachmentObjectStates = new List <string>(); // IScriptModule se = m_scene.RequestModuleInterface<IScriptModule>(); sp.InTransitScriptStates.Clear(); foreach (SceneObjectGroup sog in attachments) { // We need to make a copy and pass that copy // because of transfers withn the same sim ISceneObject clone = sog.CloneForNewScene(); // Attachment module assumes that GroupPosition holds the offsets...! ((SceneObjectGroup)clone).RootPart.GroupPosition = sog.RootPart.AttachedPos; ((SceneObjectGroup)clone).IsAttachment = false; ad.AttachmentObjects.Add(clone); string state = sog.GetStateSnapshot(); ad.AttachmentObjectStates.Add(state); sp.InTransitScriptStates.Add(state); // Let's remove the scripts of the original object here sog.RemoveScriptInstances(true); } } } }
public ISceneEntity RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt) { if (!Enabled) { return(null); } // m_log.DebugFormat( // "[ATTACHMENTS MODULE]: RezSingleAttachmentFromInventory to point {0} from item {1} for {2}", // (AttachmentPoint)AttachmentPt, itemID, sp.Name); // TODO: this short circuits multiple attachments functionality in LL viewer 2.1+ and should // be removed when that functionality is implemented in opensim AttachmentPt &= 0x7f; // Viewer 2/3 sometimes asks to re-wear items that are already worn (and show up in it's inventory as such). // This often happens during login - not sure the exact reason. // For now, we will ignore the request. Unfortunately, this means that we need to dig through all the // ScenePresence attachments. We can't use the data in AvatarAppearance because that's present at login // before anything has actually been attached. bool alreadyOn = false; List <SceneObjectGroup> existingAttachments = sp.GetAttachments(); foreach (SceneObjectGroup so in existingAttachments) { if (so.GetFromItemID() == itemID) { alreadyOn = true; break; } } // if (sp.Appearance.GetAttachmentForItem(itemID) != null) if (alreadyOn) { // m_log.WarnFormat( // "[ATTACHMENTS MODULE]: Ignoring request by {0} to wear item {1} at {2} since it is already worn", // sp.Name, itemID, AttachmentPt); return(null); } SceneObjectGroup att = RezSingleAttachmentFromInventoryInternal(sp, itemID, UUID.Zero, AttachmentPt); if (att == null) { DetachSingleAttachmentToInv(sp, itemID); } return(att); }
public void SaveChangedAttachments(IScenePresence sp, bool saveAllScripted) { // m_log.DebugFormat("[ATTACHMENTS MODULE]: Saving changed attachments for {0}", sp.Name); if (!Enabled) { return; } foreach (SceneObjectGroup grp in sp.GetAttachments()) { grp.IsAttachment = false; grp.AbsolutePosition = grp.RootPart.AttachedPos; UpdateKnownItem(sp, grp, saveAllScripted); grp.IsAttachment = true; } }
public void DeleteAttachmentsFromScene(IScenePresence sp, bool silent) { // m_log.DebugFormat( // "[ATTACHMENTS MODULE]: Deleting attachments from scene {0} for {1}, silent = {2}", // m_scene.RegionInfo.RegionName, sp.Name, silent); if (!Enabled) { return; } foreach (SceneObjectGroup sop in sp.GetAttachments()) { sop.Scene.DeleteSceneObject(sop, silent); } sp.ClearAttachments(); }
public void DeRezAttachments(IScenePresence sp) { if (!Enabled) { return; } // m_log.DebugFormat("[ATTACHMENTS MODULE]: Saving changed attachments for {0}", sp.Name); lock (sp.AttachmentsSyncLock) { foreach (SceneObjectGroup so in sp.GetAttachments()) { UpdateDetachedObject(sp, so); } sp.ClearAttachments(); } }
public bool AttachObject(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent) { lock (sp.AttachmentsSyncLock) { // m_log.DebugFormat( // "[ATTACHMENTS MODULE]: Attaching object {0} {1} to {2} point {3} from ground (silent = {4})", // group.Name, group.LocalId, sp.Name, attachmentPt, silent); if (sp.GetAttachments(attachmentPt).Contains(group)) { // m_log.WarnFormat( // "[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since it's already attached", // group.Name, group.LocalId, sp.Name, AttachmentPt); return(false); } Vector3 attachPos = group.AbsolutePosition; // TODO: this short circuits multiple attachments functionality in LL viewer 2.1+ and should // be removed when that functionality is implemented in opensim attachmentPt &= 0x7f; // If the attachment point isn't the same as the one previously used // set it's offset position = 0 so that it appears on the attachment point // and not in a weird location somewhere unknown. if (attachmentPt != 0 && attachmentPt != group.AttachmentPoint) { attachPos = Vector3.Zero; } // AttachmentPt 0 means the client chose to 'wear' the attachment. if (attachmentPt == 0) { // Check object for stored attachment point attachmentPt = group.AttachmentPoint; } // if we still didn't find a suitable attachment point....... if (attachmentPt == 0) { // Stick it on left hand with Zero Offset from the attachment point. attachmentPt = (uint)AttachmentPoint.LeftHand; attachPos = Vector3.Zero; } group.AttachmentPoint = attachmentPt; group.AbsolutePosition = attachPos; // We also don't want to do any of the inventory operations for an NPC. if (sp.PresenceType != PresenceType.Npc) { // Remove any previous attachments List <SceneObjectGroup> attachments = sp.GetAttachments(attachmentPt); // At the moment we can only deal with a single attachment if (attachments.Count != 0) { UUID oldAttachmentItemID = attachments[0].GetFromItemID(); if (oldAttachmentItemID != UUID.Zero) { DetachSingleAttachmentToInvInternal(sp, oldAttachmentItemID); } else { m_log.WarnFormat( "[ATTACHMENTS MODULE]: When detaching existing attachment {0} {1} at point {2} to make way for {3} {4} for {5}, couldn't find the associated item ID to adjust inventory attachment record!", attachments[0].Name, attachments[0].LocalId, attachmentPt, group.Name, group.LocalId, sp.Name); } } // Add the new attachment to inventory if we don't already have it. UUID newAttachmentItemID = group.GetFromItemID(); if (newAttachmentItemID == UUID.Zero) { newAttachmentItemID = AddSceneObjectAsNewAttachmentInInv(sp, group).ID; } ShowAttachInUserInventory(sp, attachmentPt, newAttachmentItemID, group); } AttachToAgent(sp, group, attachmentPt, attachPos, silent); } return(true); }
public SceneObjectGroup RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt) { if (!Enabled) return null; // m_log.DebugFormat( // "[ATTACHMENTS MODULE]: RezSingleAttachmentFromInventory to point {0} from item {1} for {2}", // (AttachmentPoint)AttachmentPt, itemID, sp.Name); // TODO: this short circuits multiple attachments functionality in LL viewer 2.1+ and should // be removed when that functionality is implemented in opensim AttachmentPt &= 0x7f; // Viewer 2/3 sometimes asks to re-wear items that are already worn (and show up in it's inventory as such). // This often happens during login - not sure the exact reason. // For now, we will ignore the request. Unfortunately, this means that we need to dig through all the // ScenePresence attachments. We can't use the data in AvatarAppearance because that's present at login // before anything has actually been attached. bool alreadyOn = false; List<SceneObjectGroup> existingAttachments = sp.GetAttachments(); foreach (SceneObjectGroup so in existingAttachments) { if (so.FromItemID == itemID) { alreadyOn = true; break; } } // if (sp.Appearance.GetAttachmentForItem(itemID) != null) if (alreadyOn) { // m_log.WarnFormat( // "[ATTACHMENTS MODULE]: Ignoring request by {0} to wear item {1} at {2} since it is already worn", // sp.Name, itemID, AttachmentPt); return null; } return RezSingleAttachmentFromInventoryInternal(sp, itemID, UUID.Zero, AttachmentPt); }
public void DeRezAttachments(IScenePresence sp, bool saveChanged, bool saveAllScripted) { if (!Enabled) return; // m_log.DebugFormat("[ATTACHMENTS MODULE]: Saving changed attachments for {0}", sp.Name); lock (sp.AttachmentsSyncLock) { foreach (SceneObjectGroup grp in sp.GetAttachments()) { grp.Scene.DeleteSceneObject(grp, false); if (saveChanged || saveAllScripted) { grp.IsAttachment = false; grp.AbsolutePosition = grp.RootPart.AttachedPos; UpdateKnownItem(sp, grp, saveAllScripted); } } sp.ClearAttachments(); } }
public void DeleteAttachmentsFromScene(IScenePresence sp, bool silent) { if (!Enabled) return; if (DebugLevel > 0) m_log.DebugFormat( "[ATTACHMENTS MODULE]: Deleting attachments from scene {0} for {1}, silent = {2}", m_scene.RegionInfo.RegionName, sp.Name, silent); foreach (SceneObjectGroup sop in sp.GetAttachments()) { sop.Scene.DeleteSceneObject(sop, silent); } sp.ClearAttachments(); }
public void RezAttachments(IScenePresence sp) { if (!Enabled) return; if (null == sp.Appearance) { m_log.WarnFormat("[ATTACHMENTS MODULE]: Appearance has not been initialized for agent {0}", sp.UUID); return; } if (sp.GetAttachments().Count > 0) { if (DebugLevel > 0) m_log.DebugFormat( "[ATTACHMENTS MODULE]: Not doing simulator-side attachment rez for {0} in {1} as their viewer has already rezzed attachments", m_scene.Name, sp.Name); return; } if (DebugLevel > 0) m_log.DebugFormat("[ATTACHMENTS MODULE]: Rezzing any attachments for {0} from simulator-side", sp.Name); List<AvatarAttachment> attachments = sp.Appearance.GetAttachments(); foreach (AvatarAttachment attach in attachments) { uint attachmentPt = (uint)attach.AttachPoint; // m_log.DebugFormat( // "[ATTACHMENTS MODULE]: Doing initial rez of attachment with itemID {0}, assetID {1}, point {2} for {3} in {4}", // attach.ItemID, attach.AssetID, p, sp.Name, m_scene.RegionInfo.RegionName); // For some reason assetIDs are being written as Zero's in the DB -- need to track tat down // But they're not used anyway, the item is being looked up for now, so let's proceed. //if (UUID.Zero == assetID) //{ // m_log.DebugFormat("[ATTACHMENT]: Cannot rez attachment in point {0} with itemID {1}", p, itemID); // continue; //} try { // If we're an NPC then skip all the item checks and manipulations since we don't have an // inventory right now. RezSingleAttachmentFromInventoryInternal( sp, sp.PresenceType == PresenceType.Npc ? UUID.Zero : attach.ItemID, attach.AssetID, attachmentPt, true); } catch (Exception e) { UUID agentId = (sp.ControllingClient == null) ? default(UUID) : sp.ControllingClient.AgentId; m_log.ErrorFormat("[ATTACHMENTS MODULE]: Unable to rez attachment with itemID {0}, assetID {1}, point {2} for {3}: {4}\n{5}", attach.ItemID, attach.AssetID, attachmentPt, agentId, e.Message, e.StackTrace); } } }
public void RezAttachments(IScenePresence sp) { if (!Enabled) return; if (null == sp.Appearance) { m_log.WarnFormat("[ATTACHMENTS MODULE]: Appearance has not been initialized for agent {0}", sp.UUID); return; } if (sp.GetAttachments().Count > 0) { if (DebugLevel > 0) m_log.DebugFormat( "[ATTACHMENTS MODULE]: Not doing simulator-side attachment rez for {0} in {1} as their viewer has already rezzed attachments", m_scene.Name, sp.Name); return; } if (DebugLevel > 0) m_log.DebugFormat("[ATTACHMENTS MODULE]: Rezzing any attachments for {0} from simulator-side", sp.Name); XmlDocument doc = new XmlDocument(); string stateData = String.Empty; IAttachmentsService attServ = m_scene.RequestModuleInterface<IAttachmentsService>(); if (attServ != null) { m_log.DebugFormat("[ATTACHMENT]: Loading attachment data from attachment service"); stateData = attServ.Get(sp.UUID.ToString()); if (stateData != String.Empty) { try { doc.LoadXml(stateData); } catch { } } } Dictionary<UUID, string> itemData = new Dictionary<UUID, string>(); XmlNodeList nodes = doc.GetElementsByTagName("Attachment"); if (nodes.Count > 0) { foreach (XmlNode n in nodes) { XmlElement elem = (XmlElement)n; string itemID = elem.GetAttribute("ItemID"); string xml = elem.InnerXml; itemData[new UUID(itemID)] = xml; } } List<AvatarAttachment> attachments = sp.Appearance.GetAttachments(); // Let's get all items at once, so they get cached UUID[] items = new UUID[attachments.Count]; int i = 0; foreach (AvatarAttachment attach in attachments) items[i++] = attach.ItemID; m_scene.InventoryService.GetMultipleItems(sp.UUID, items); foreach (AvatarAttachment attach in attachments) { uint attachmentPt = (uint)attach.AttachPoint; // m_log.DebugFormat( // "[ATTACHMENTS MODULE]: Doing initial rez of attachment with itemID {0}, assetID {1}, point {2} for {3} in {4}", // attach.ItemID, attach.AssetID, p, sp.Name, m_scene.RegionInfo.RegionName); // For some reason assetIDs are being written as Zero's in the DB -- need to track tat down // But they're not used anyway, the item is being looked up for now, so let's proceed. //if (UUID.Zero == assetID) //{ // m_log.DebugFormat("[ATTACHMENT]: Cannot rez attachment in point {0} with itemID {1}", p, itemID); // continue; //} try { string xmlData; XmlDocument d = null; UUID asset; if (itemData.TryGetValue(attach.ItemID, out xmlData)) { d = new XmlDocument(); d.LoadXml(xmlData); m_log.InfoFormat("[ATTACHMENT]: Found saved state for item {0}, loading it", attach.ItemID); } // If we're an NPC then skip all the item checks and manipulations since we don't have an // inventory right now. RezSingleAttachmentFromInventoryInternal( sp, sp.PresenceType == PresenceType.Npc ? UUID.Zero : attach.ItemID, attach.AssetID, attachmentPt, true, d); } catch (Exception e) { UUID agentId = (sp.ControllingClient == null) ? default(UUID) : sp.ControllingClient.AgentId; m_log.ErrorFormat("[ATTACHMENTS MODULE]: Unable to rez attachment with itemID {0}, assetID {1}, point {2} for {3}: {4}\n{5}", attach.ItemID, attach.AssetID, attachmentPt, agentId, e.Message, e.StackTrace); } } }
public bool AttachObject(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent) { lock (sp.AttachmentsSyncLock) { // m_log.DebugFormat( // "[ATTACHMENTS MODULE]: Attaching object {0} {1} to {2} point {3} from ground (silent = {4})", // group.Name, group.LocalId, sp.Name, attachmentPt, silent); if (sp.GetAttachments(attachmentPt).Contains(group)) { // m_log.WarnFormat( // "[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since it's already attached", // group.Name, group.LocalId, sp.Name, AttachmentPt); return false; } Vector3 attachPos = group.AbsolutePosition; // TODO: this short circuits multiple attachments functionality in LL viewer 2.1+ and should // be removed when that functionality is implemented in opensim attachmentPt &= 0x7f; // If the attachment point isn't the same as the one previously used // set it's offset position = 0 so that it appears on the attachment point // and not in a weird location somewhere unknown. if (attachmentPt != 0 && attachmentPt != group.AttachmentPoint) { attachPos = Vector3.Zero; } // AttachmentPt 0 means the client chose to 'wear' the attachment. if (attachmentPt == 0) { // Check object for stored attachment point attachmentPt = group.AttachmentPoint; } // if we still didn't find a suitable attachment point....... if (attachmentPt == 0) { // Stick it on left hand with Zero Offset from the attachment point. attachmentPt = (uint)AttachmentPoint.LeftHand; attachPos = Vector3.Zero; } group.AttachmentPoint = attachmentPt; group.AbsolutePosition = attachPos; // We also don't want to do any of the inventory operations for an NPC. if (sp.PresenceType != PresenceType.Npc) { // Remove any previous attachments List<SceneObjectGroup> attachments = sp.GetAttachments(attachmentPt); // At the moment we can only deal with a single attachment if (attachments.Count != 0) { UUID oldAttachmentItemID = attachments[0].GetFromItemID(); if (oldAttachmentItemID != UUID.Zero) DetachSingleAttachmentToInvInternal(sp, oldAttachmentItemID); else m_log.WarnFormat( "[ATTACHMENTS MODULE]: When detaching existing attachment {0} {1} at point {2} to make way for {3} {4} for {5}, couldn't find the associated item ID to adjust inventory attachment record!", attachments[0].Name, attachments[0].LocalId, attachmentPt, group.Name, group.LocalId, sp.Name); } // Add the new attachment to inventory if we don't already have it. UUID newAttachmentItemID = group.GetFromItemID(); if (newAttachmentItemID == UUID.Zero) newAttachmentItemID = AddSceneObjectAsNewAttachmentInInv(sp, group).ID; ShowAttachInUserInventory(sp, attachmentPt, newAttachmentItemID, group); } AttachToAgent(sp, group, attachmentPt, attachPos, silent); } return true; }
public void SaveChangedAttachments(IScenePresence sp) { // m_log.DebugFormat("[ATTACHMENTS MODULE]: Saving changed attachments for {0}", sp.Name); if (!Enabled) return; foreach (SceneObjectGroup grp in sp.GetAttachments()) { // if (grp.HasGroupChanged) // Resizer scripts? // { grp.IsAttachment = false; grp.AbsolutePosition = grp.RootPart.AttachedPos; UpdateKnownItem(sp, grp); grp.IsAttachment = true; // } } }
private bool AttachObjectInternal(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent, bool temp) { lock (sp.AttachmentsSyncLock) { // m_log.DebugFormat( // "[ATTACHMENTS MODULE]: Attaching object {0} {1} to {2} point {3} from ground (silent = {4})", // group.Name, group.LocalId, sp.Name, attachmentPt, silent); if (group.GetSittingAvatarsCount() != 0) { // m_log.WarnFormat( // "[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since {4} avatars are still sitting on it", // group.Name, group.LocalId, sp.Name, attachmentPt, group.GetSittingAvatarsCount()); return(false); } if (sp.GetAttachments(attachmentPt).Contains(group)) { // m_log.WarnFormat( // "[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since it's already attached", // group.Name, group.LocalId, sp.Name, AttachmentPt); return(false); } Vector3 attachPos = group.AbsolutePosition; // TODO: this short circuits multiple attachments functionality in LL viewer 2.1+ and should // be removed when that functionality is implemented in opensim attachmentPt &= 0x7f; // If the attachment point isn't the same as the one previously used // set it's offset position = 0 so that it appears on the attachment point // and not in a weird location somewhere unknown. if (attachmentPt != 0 && attachmentPt != group.AttachmentPoint) { attachPos = Vector3.Zero; } // AttachmentPt 0 means the client chose to 'wear' the attachment. if (attachmentPt == 0) { // Check object for stored attachment point attachmentPt = group.AttachmentPoint; } // if we still didn't find a suitable attachment point....... if (attachmentPt == 0) { // Stick it on left hand with Zero Offset from the attachment point. attachmentPt = (uint)AttachmentPoint.LeftHand; attachPos = Vector3.Zero; } group.AttachmentPoint = attachmentPt; group.AbsolutePosition = attachPos; if (sp.PresenceType != PresenceType.Npc) { UpdateUserInventoryWithAttachment(sp, group, attachmentPt, temp); } AttachToAgent(sp, group, attachmentPt, attachPos, silent); } return(true); }
public void DeRezAttachments(IScenePresence sp) { if (!Enabled) return; // m_log.DebugFormat("[ATTACHMENTS MODULE]: Saving changed attachments for {0}", sp.Name); lock (sp.AttachmentsSyncLock) { foreach (SceneObjectGroup so in sp.GetAttachments()) { UpdateDetachedObject(sp, so); } sp.ClearAttachments(); } }
public void CopyAttachments(IScenePresence sp, AgentData ad) { lock (sp.AttachmentsSyncLock) { // Attachment objects List<SceneObjectGroup> attachments = sp.GetAttachments(); if (attachments.Count > 0) { ad.AttachmentObjects = new List<ISceneObject>(); ad.AttachmentObjectStates = new List<string>(); // IScriptModule se = m_scene.RequestModuleInterface<IScriptModule>(); sp.InTransitScriptStates.Clear(); foreach (SceneObjectGroup sog in attachments) { // We need to make a copy and pass that copy // because of transfers withn the same sim ISceneObject clone = sog.CloneForNewScene(); // Attachment module assumes that GroupPosition holds the offsets...! ((SceneObjectGroup)clone).RootPart.GroupPosition = sog.RootPart.AttachedPos; ((SceneObjectGroup)clone).IsAttachment = false; ad.AttachmentObjects.Add(clone); string state = sog.GetStateSnapshot(); ad.AttachmentObjectStates.Add(state); sp.InTransitScriptStates.Add(state); // Scripts of the originals will be removed when the Agent is successfully removed. // sog.RemoveScriptInstances(true); } } } }
private bool AttachObjectInternal(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent, bool temp) { lock (sp.AttachmentsSyncLock) { // m_log.DebugFormat( // "[ATTACHMENTS MODULE]: Attaching object {0} {1} to {2} point {3} from ground (silent = {4})", // group.Name, group.LocalId, sp.Name, attachmentPt, silent); if (group.GetSittingAvatarsCount() != 0) { // m_log.WarnFormat( // "[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since {4} avatars are still sitting on it", // group.Name, group.LocalId, sp.Name, attachmentPt, group.GetSittingAvatarsCount()); return false; } if (sp.GetAttachments(attachmentPt).Contains(group)) { // m_log.WarnFormat( // "[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since it's already attached", // group.Name, group.LocalId, sp.Name, AttachmentPt); return false; } Vector3 attachPos = group.AbsolutePosition; // TODO: this short circuits multiple attachments functionality in LL viewer 2.1+ and should // be removed when that functionality is implemented in opensim attachmentPt &= 0x7f; // If the attachment point isn't the same as the one previously used // set it's offset position = 0 so that it appears on the attachment point // and not in a weird location somewhere unknown. if (attachmentPt != 0 && attachmentPt != group.AttachmentPoint) { attachPos = Vector3.Zero; } // AttachmentPt 0 means the client chose to 'wear' the attachment. if (attachmentPt == 0) { // Check object for stored attachment point attachmentPt = group.AttachmentPoint; } // if we still didn't find a suitable attachment point....... if (attachmentPt == 0) { // Stick it on left hand with Zero Offset from the attachment point. attachmentPt = (uint)AttachmentPoint.LeftHand; attachPos = Vector3.Zero; } group.AttachmentPoint = attachmentPt; group.AbsolutePosition = attachPos; if (sp.PresenceType != PresenceType.Npc) UpdateUserInventoryWithAttachment(sp, group, attachmentPt, temp); AttachToAgent(sp, group, attachmentPt, attachPos, silent); } return true; }
public void DeRezAttachments(IScenePresence sp) { if (!Enabled) return; if (DebugLevel > 0) m_log.DebugFormat("[ATTACHMENTS MODULE]: Saving changed attachments for {0}", sp.Name); List<SceneObjectGroup> attachments = sp.GetAttachments(); if (attachments.Count <= 0) return; Dictionary<SceneObjectGroup, string> scriptStates = new Dictionary<SceneObjectGroup, string>(); foreach (SceneObjectGroup so in attachments) { // Scripts MUST be snapshotted before the object is // removed from the scene because doing otherwise will // clobber the run flag // This must be done outside the sp.AttachmentSyncLock so that there is no risk of a deadlock from // scripts performing attachment operations at the same time. Getting object states stops the scripts. scriptStates[so] = PrepareScriptInstanceForSave(so, false); } lock (sp.AttachmentsSyncLock) { foreach (SceneObjectGroup so in attachments) UpdateDetachedObject(sp, so, scriptStates[so]); sp.ClearAttachments(); } }
private void UpdateUserInventoryWithAttachment(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool temp) { // Remove any previous attachments List<SceneObjectGroup> attachments = sp.GetAttachments(attachmentPt); // At the moment we can only deal with a single attachment if (attachments.Count != 0) { if (attachments[0].FromItemID != UUID.Zero) DetachSingleAttachmentToInvInternal(sp, attachments[0]); // Error logging commented because UUID.Zero now means temp attachment // else // m_log.WarnFormat( // "[ATTACHMENTS MODULE]: When detaching existing attachment {0} {1} at point {2} to make way for {3} {4} for {5}, couldn't find the associated item ID to adjust inventory attachment record!", // attachments[0].Name, attachments[0].LocalId, attachmentPt, group.Name, group.LocalId, sp.Name); } // Add the new attachment to inventory if we don't already have it. if (!temp) { UUID newAttachmentItemID = group.FromItemID; if (newAttachmentItemID == UUID.Zero) newAttachmentItemID = AddSceneObjectAsNewAttachmentInInv(sp, group).ID; ShowAttachInUserInventory(sp, attachmentPt, newAttachmentItemID, group); } }
/// <summary> /// Internal method which actually does all the work for attaching an object. /// </summary> /// <returns>The object attached.</returns> /// <param name='sp'></param> /// <param name='group'>The object to attach.</param> /// <param name='attachmentPt'></param> /// <param name='silent'></param> /// <param name='addToInventory'>If true then add object to user inventory.</param> /// <param name='resumeScripts'>If true then scripts are resumed on the attached object.</param> /// <param name='append'>Append to attachment point rather than replace.</param> private bool AttachObjectInternal( IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent, bool addToInventory, bool resumeScripts, bool append) { if (group.GetSittingAvatarsCount() != 0) { if (DebugLevel > 0) m_log.WarnFormat( "[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since {4} avatars are still sitting on it", group.Name, group.LocalId, sp.Name, attachmentPt, group.GetSittingAvatarsCount()); return false; } Vector3 attachPos = group.AbsolutePosition; // If the attachment point isn't the same as the one previously used // set it's offset position = 0 so that it appears on the attachment point // and not in a weird location somewhere unknown. if (attachmentPt != (uint)AttachmentPoint.Default && attachmentPt != group.AttachmentPoint) { attachPos = Vector3.Zero; } // if the attachment point is the same as previous, make sure we get the saved // position info. if (attachmentPt != 0 && attachmentPt == group.RootPart.Shape.LastAttachPoint) { attachPos = group.RootPart.AttachedPos; } // AttachmentPt 0 means the client chose to 'wear' the attachment. if (attachmentPt == (uint)AttachmentPoint.Default) { // Check object for stored attachment point attachmentPt = group.AttachmentPoint; } // if we didn't find an attach point, look for where it was last attached if (attachmentPt == 0) { attachmentPt = (uint)group.RootPart.Shape.LastAttachPoint; attachPos = group.RootPart.AttachedPos; group.HasGroupChanged = true; } // if we still didn't find a suitable attachment point....... if (attachmentPt == 0) { // Stick it on left hand with Zero Offset from the attachment point. attachmentPt = (uint)AttachmentPoint.LeftHand; attachPos = Vector3.Zero; } group.AttachmentPoint = attachmentPt; group.AbsolutePosition = attachPos; List<SceneObjectGroup> attachments = sp.GetAttachments(attachmentPt); if (attachments.Contains(group)) { if (DebugLevel > 0) m_log.WarnFormat( "[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since it's already attached", group.Name, group.LocalId, sp.Name, attachmentPt); return false; } // If we already have 5, remove the oldest until only 4 are left. Skip over temp ones while (attachments.Count >= 5) { if (attachments[0].FromItemID != UUID.Zero) DetachSingleAttachmentToInv(sp, attachments[0]); attachments.RemoveAt(0); } // If we're not appending, remove the rest as well if (attachments.Count != 0 && !append) { foreach (SceneObjectGroup g in attachments) { if (g.FromItemID != UUID.Zero) DetachSingleAttachmentToInv(sp, g); } } lock (sp.AttachmentsSyncLock) { if (addToInventory && sp.PresenceType != PresenceType.Npc) UpdateUserInventoryWithAttachment(sp, group, attachmentPt, append); AttachToAgent(sp, group, attachmentPt, attachPos, silent); if (resumeScripts) { // Fire after attach, so we don't get messy perms dialogs // 4 == AttachedRez group.CreateScriptInstances(0, true, m_scene.DefaultScriptEngine, 4); group.ResumeScripts(); } // Do this last so that event listeners have access to all the effects of the attachment m_scene.EventManager.TriggerOnAttach(group.LocalId, group.FromItemID, sp.UUID); } return true; }
private SceneObjectGroup RezSingleAttachmentFromInventoryInternal( IScenePresence sp, UUID itemID, UUID assetID, uint attachmentPt) { if (m_invAccessModule == null) return null; 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.WarnFormat( "[ATTACHMENTS MODULE]: Could not retrieve item {0} for attaching to avatar {1} at point {2}", itemID, sp.Name, attachmentPt); return null; } // Remove any previous attachments List<SceneObjectGroup> attachments = sp.GetAttachments(attachmentPt); // At the moment we can only deal with a single attachment if (attachments.Count != 0) DetachSingleAttachmentToInv(sp, attachments[0]); lock (sp.AttachmentsSyncLock) { // 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; } }