From 8880aea728af2ccb95ea2400c7d180aa4dc98112 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 13 Sep 2011 22:13:58 +0100 Subject: Stop attempts to rewear already worn items from removing and reattaching. Viewer 2/3 will sometimes attempt to rewear attachments, even though they have already been attached during the main login process. This change ignores those attempts. This stops script failures during login, as the rewearing was racing with the script startup code. It might also help with attachments being abnormally put into deleted state. Hopefully resolves some more of http://opensimulator.org/mantis/view.php?id=5644 --- .../Avatar/Attachments/AttachmentsModule.cs | 119 +++++++++++++-------- OpenSim/Region/Framework/Scenes/SceneGraph.cs | 4 +- .../Framework/Scenes/SceneObjectGroup.Inventory.cs | 13 +++ .../Framework/Scenes/SceneObjectPartInventory.cs | 5 + 4 files changed, 97 insertions(+), 44 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index c817559..1e9a001 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs @@ -147,18 +147,22 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments foreach (SceneObjectGroup grp in sp.GetAttachments()) { - if (grp.HasGroupChanged) // Resizer scripts? - { +// if (grp.HasGroupChanged) // Resizer scripts? +// { grp.IsAttachment = false; grp.AbsolutePosition = grp.RootPart.AttachedPos; UpdateKnownItem(sp.ControllingClient, grp, grp.GetFromItemID(), grp.OwnerID); 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); + foreach (SceneObjectGroup sop in sp.GetAttachments()) { sop.Scene.DeleteSceneObject(sop, silent); @@ -214,7 +218,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments m_scene.EventManager.TriggerOnAttach(objectLocalID, part.ParentGroup.GetFromItemID(), remoteClient.AgentId); // Save avatar attachment information - m_log.Info( + m_log.Debug( "[ATTACHMENTS MODULE]: Saving avatar attachment. AgentID: " + remoteClient.AgentId + ", AttachmentPoint: " + AttachmentPt); @@ -339,6 +343,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments lock (sp.AttachmentsSyncLock) { +// m_log.DebugFormat("[ATTACHMENTS MODULE]: Rezzing multiple attachments from inventory for {0}", sp.Name); + foreach (RezMultipleAttachmentsFromInvPacket.ObjectDataBlock obj in objects) { RezSingleAttachmentFromInventory(sp, obj.ItemID, obj.AttachmentPt); @@ -349,7 +355,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments public ISceneEntity RezSingleAttachmentFromInventory(IClientAPI remoteClient, UUID itemID, uint AttachmentPt) { // m_log.DebugFormat( -// "[ATTACHMENTS MODULE]: Rezzing attachment to point {0} from item {1} for {2}", +// "[ATTACHMENTS MODULE]: Rezzing attachment to point {0} from item {1} for {2}", // (AttachmentPoint)AttachmentPt, itemID, remoteClient.Name); ScenePresence sp = m_scene.GetScenePresence(remoteClient.AgentId); @@ -375,6 +381,32 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments // 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 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) @@ -467,8 +499,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments IScenePresence sp, uint AttachmentPt, UUID itemID, SceneObjectGroup att) { // m_log.DebugFormat( -// "[USER INVENTORY]: Updating attachment {0} for {1} at {2} using item ID {3}", -// att.Name, remoteClient.Name, AttachmentPt, itemID); +// "[USER INVENTORY]: Updating attachment {0} for {1} at {2} using item ID {3}", +// att.Name, sp.Name, AttachmentPt, itemID); if (UUID.Zero == itemID) { @@ -524,7 +556,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments { // m_log.DebugFormat( // "[ATTACHMENTS MODULE]: DetachSingleAttachmentToGround() for {0}, object {1}", -// remoteClient.Name, sceneObjectID); +// remoteClient.Name, soLocalId); SceneObjectGroup so = m_scene.GetGroupByPrim(soLocalId); @@ -677,45 +709,45 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments { if (grp != null) { - if (!grp.HasGroupChanged) + if (grp.HasGroupChanged || grp.ContainsScripts()) { m_log.DebugFormat( - "[ATTACHMENTS MODULE]: Don't need to update asset for unchanged attachment {0}, attachpoint {1}", + "[ATTACHMENTS MODULE]: Updating asset for attachment {0}, attachpoint {1}", grp.UUID, grp.AttachmentPoint); - return; - } + string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp); - m_log.DebugFormat( - "[ATTACHMENTS MODULE]: Updating asset for attachment {0}, attachpoint {1}", - grp.UUID, grp.AttachmentPoint); + InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId); + item = m_scene.InventoryService.GetItem(item); - string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp); - - InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId); - item = m_scene.InventoryService.GetItem(item); - - if (item != null) + if (item != null) + { + AssetBase asset = m_scene.CreateAsset( + grp.GetPartName(grp.LocalId), + grp.GetPartDescription(grp.LocalId), + (sbyte)AssetType.Object, + Utils.StringToBytes(sceneObjectXml), + remoteClient.AgentId); + m_scene.AssetService.Store(asset); + + item.AssetID = asset.FullID; + item.Description = asset.Description; + item.Name = asset.Name; + item.AssetType = asset.Type; + item.InvType = (int)InventoryType.Object; + + m_scene.InventoryService.UpdateItem(item); + + // this gets called when the agent logs off! + if (remoteClient != null) + remoteClient.SendInventoryItemCreateUpdate(item, 0); + } + } + else { - AssetBase asset = m_scene.CreateAsset( - grp.GetPartName(grp.LocalId), - grp.GetPartDescription(grp.LocalId), - (sbyte)AssetType.Object, - Utils.StringToBytes(sceneObjectXml), - remoteClient.AgentId); - m_scene.AssetService.Store(asset); - - item.AssetID = asset.FullID; - item.Description = asset.Description; - item.Name = asset.Name; - item.AssetType = asset.Type; - item.InvType = (int)InventoryType.Object; - - m_scene.InventoryService.UpdateItem(item); - - // this gets called when the agent logs off! - if (remoteClient != null) - remoteClient.SendInventoryItemCreateUpdate(item, 0); + m_log.DebugFormat( + "[ATTACHMENTS MODULE]: Don't need to update asset for unchanged attachment {0}, attachpoint {1}", + grp.UUID, grp.AttachmentPoint); } } } @@ -735,7 +767,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments private void AttachToAgent( IScenePresence avatar, SceneObjectGroup so, uint attachmentpoint, Vector3 attachOffset, bool silent) { -// m_log.DebugFormat("[ATTACHMENTS MODULE]: Adding attachment {0} to avatar {1} in pt {2} pos {3} {4}", +// m_log.DebugFormat( +// "[ATTACHMENTS MODULE]: Adding attachment {0} to avatar {1} in pt {2} pos {3} {4}", // so.Name, avatar.Name, attachmentpoint, attachOffset, so.RootPart.AttachedPos); so.DetachFromBackup(); @@ -788,7 +821,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments /// The user inventory item created that holds the attachment. private InventoryItemBase AddSceneObjectAsNewAttachmentInInv(IClientAPI remoteClient, SceneObjectGroup grp) { -// m_log.DebugFormat("[SCENE]: Called AddSceneObjectAsAttachment for object {0} {1} for {2} {3} {4}", grp.Name, grp.LocalId, remoteClient.Name, remoteClient.AgentId, AgentId); +// m_log.DebugFormat( +// "[ATTACHMENTS MODULE]: Called AddSceneObjectAsAttachment for object {0} {1} for {2}", +// grp.Name, grp.LocalId, remoteClient.Name); Vector3 inventoryStoredPosition = new Vector3 (((grp.AbsolutePosition.X > (int)Constants.RegionSize) diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs index f03cf7b..36c5c52 100644 --- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs +++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs @@ -652,7 +652,7 @@ namespace OpenSim.Region.Framework.Scenes if (!Entities.Remove(agentID)) { m_log.WarnFormat( - "[SCENEGRAPH]: Tried to remove non-existent scene presence with agent ID {0} from scene Entities list", + "[SCENE GRAPH]: Tried to remove non-existent scene presence with agent ID {0} from scene Entities list", agentID); } @@ -675,7 +675,7 @@ namespace OpenSim.Region.Framework.Scenes } else { - m_log.WarnFormat("[SCENEGRAPH]: Tried to remove non-existent scene presence with agent ID {0} from scene ScenePresences list", agentID); + m_log.WarnFormat("[SCENE GRAPH]: Tried to remove non-existent scene presence with agent ID {0} from scene ScenePresences list", agentID); } } } diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs index 4bca3d0..905ecc9 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs @@ -389,5 +389,18 @@ namespace OpenSim.Region.Framework.Scenes for (int i = 0; i < parts.Length; i++) parts[i].Inventory.ResumeScripts(); } + + /// + /// Returns true if any part in the scene object contains scripts, false otherwise. + /// + /// + public bool ContainsScripts() + { + foreach (SceneObjectPart part in Parts) + if (part.Inventory.ContainsScripts()) + return true; + + return false; + } } } diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs index e40e57d..57adda7 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs @@ -1035,10 +1035,15 @@ namespace OpenSim.Region.Framework.Scenes item.BasePermissions = perms; } } + m_inventorySerial++; HasInventoryChanged = true; } + /// + /// Returns true if this part inventory contains any scripts. False otherwise. + /// + /// public bool ContainsScripts() { lock (m_items) -- cgit v1.1