From 460946ad62b682c7a942751f192ca9e96b662f0e Mon Sep 17 00:00:00 2001 From: Dan Lake Date: Mon, 3 Oct 2011 16:44:32 -0700 Subject: [PATCH] Removed redundant code in AttachmentsModule and simplified interfaces which converted back and forth between ScenePresence and IClientAPI. More to be done still. --- .../Avatar/Attachments/AttachmentsModule.cs | 156 ++++++++---------- .../Tests/AttachmentsModuleTests.cs | 10 +- .../Interfaces/IAttachmentsModule.cs | 35 +--- OpenSim/Region/Framework/Scenes/Scene.cs | 2 +- .../World/NPC/Tests/NPCModuleTests.cs | 6 +- .../Shared/Api/Implementation/LSL_Api.cs | 3 +- 6 files changed, 82 insertions(+), 130 deletions(-) diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index 48695a4585..78b9afcd8f 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs @@ -152,7 +152,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments if (sp.PresenceType == PresenceType.Npc) RezSingleAttachmentFromInventoryInternal(sp, UUID.Zero, attach.AssetID, p); else - RezSingleAttachmentFromInventory(sp.ControllingClient, attach.ItemID, p); + RezSingleAttachmentFromInventory(sp, attach.ItemID, p); } catch (Exception e) { @@ -204,7 +204,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments /// /// /// - public void AttachObject(IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, bool silent) + private void AttachObject(IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, bool silent) { // m_log.DebugFormat( // "[ATTACHMENTS MODULE]: Attaching object local id {0} to {1} point {2} from ground (silent = {3})", @@ -258,25 +258,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments m_log.ErrorFormat("[ATTACHMENTS MODULE]: exception upon Attach Object {0}{1}", e.Message, e.StackTrace); } } - - public bool AttachObject(IClientAPI remoteClient, SceneObjectGroup group, uint AttachmentPt, bool silent) - { - if (!Enabled) - return false; - - ScenePresence sp = m_scene.GetScenePresence(remoteClient.AgentId); - - if (sp == null) - { - m_log.ErrorFormat( - "[ATTACHMENTS MODULE]: Could not find presence for client {0} {1}", remoteClient.Name, remoteClient.AgentId); - return false; - } - - return AttachObject(sp, group, AttachmentPt, silent); - } - private bool AttachObject(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent) + public bool AttachObject(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent) { lock (sp.AttachmentsSyncLock) { @@ -356,29 +339,31 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments } return true; + } + + private void RezMultipleAttachmentsFromInventory(IClientAPI remoteClient, List> rezlist) + { + if (!Enabled) + return; + + ScenePresence sp; + if (m_scene.TryGetScenePresence(remoteClient.AgentId, out sp)) + RezMultipleAttachmentsFromInventory(sp, rezlist); + else + m_log.ErrorFormat( + "[ATTACHMENTS MODULE]: Could not find presence for client {0} {1} in RezMultipleAttachmentsFromInventory()", + remoteClient.Name, remoteClient.AgentId); + return; } - public void RezMultipleAttachmentsFromInventory( - IClientAPI remoteClient, - List> rezlist) + public void RezMultipleAttachmentsFromInventory(IScenePresence sp, List> rezlist) { if (!Enabled) - return; - - ScenePresence sp = m_scene.GetScenePresence(remoteClient.AgentId); - - if (sp == null) - { - m_log.ErrorFormat( - "[ATTACHMENTS MODULE]: Could not find presence for client {0} {1} in RezMultipleAttachmentsFromInventory()", - remoteClient.Name, remoteClient.AgentId); - return; - } - + return; + +// m_log.DebugFormat("[ATTACHMENTS MODULE]: Rezzing multiple attachments from inventory for {0}", sp.Name); lock (sp.AttachmentsSyncLock) { -// m_log.DebugFormat("[ATTACHMENTS MODULE]: Rezzing multiple attachments from inventory for {0}", sp.Name); - foreach (KeyValuePair rez in rezlist) { RezSingleAttachmentFromInventory(sp, rez.Key, rez.Value); @@ -386,7 +371,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments } } - public ISceneEntity RezSingleAttachmentFromInventory(IClientAPI remoteClient, UUID itemID, uint AttachmentPt) + private ISceneEntity RezSingleAttachmentFromInventory(IClientAPI remoteClient, UUID itemID, uint AttachmentPt) { if (!Enabled) return null; @@ -408,7 +393,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments return RezSingleAttachmentFromInventory(sp, itemID, AttachmentPt); } - public ISceneEntity RezSingleAttachmentFromInventory(ScenePresence sp, UUID itemID, uint AttachmentPt) + public ISceneEntity RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt) { if (!Enabled) return null; @@ -593,23 +578,33 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments DetachSingleAttachmentToInv(itemID, presence); } } + } + + private void DetachSingleAttachmentToGround(uint soLocalId, IClientAPI remoteClient) + { + if (!Enabled) + return; + + ScenePresence sp; + if (m_scene.TryGetScenePresence(remoteClient.AgentId, out sp)) + DetachSingleAttachmentToGround(sp, soLocalId); } - public void DetachSingleAttachmentToGround(uint soLocalId, IClientAPI remoteClient) + public void DetachSingleAttachmentToGround(IScenePresence sp, uint soLocalId) { if (!Enabled) return; // m_log.DebugFormat( // "[ATTACHMENTS MODULE]: DetachSingleAttachmentToGround() for {0}, object {1}", -// remoteClient.Name, soLocalId); +// sp.UUID, soLocalId); SceneObjectGroup so = m_scene.GetGroupByPrim(soLocalId); if (so == null) return; - if (so.AttachedAvatar != remoteClient.AgentId) + if (so.AttachedAvatar != sp.UUID) return; UUID inventoryID = so.GetFromItemID(); @@ -618,57 +613,40 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments // "[ATTACHMENTS MODULE]: In DetachSingleAttachmentToGround(), object is {0} {1}, associated item is {2}", // so.Name, so.LocalId, inventoryID); - ScenePresence presence; - if (m_scene.TryGetScenePresence(remoteClient.AgentId, out presence)) + lock (sp.AttachmentsSyncLock) { - lock (presence.AttachmentsSyncLock) - { - if (!m_scene.Permissions.CanRezObject( - so.PrimCount, remoteClient.AgentId, presence.AbsolutePosition)) - return; + if (!m_scene.Permissions.CanRezObject( + so.PrimCount, sp.UUID, sp.AbsolutePosition)) + return; + + bool changed = sp.Appearance.DetachAttachment(inventoryID); + if (changed && m_scene.AvatarFactory != null) + m_scene.AvatarFactory.QueueAppearanceSave(sp.UUID); + + sp.RemoveAttachment(so); + + SceneObjectPart rootPart = so.RootPart; + rootPart.FromItemID = UUID.Zero; + so.AbsolutePosition = sp.AbsolutePosition; + so.AttachedAvatar = UUID.Zero; + rootPart.SetParentLocalId(0); + so.ClearPartAttachmentData(); + rootPart.ApplyPhysics(rootPart.GetEffectiveObjectFlags(), rootPart.VolumeDetectActive, m_scene.m_physicalPrim); + so.HasGroupChanged = true; + rootPart.Rezzed = DateTime.Now; + rootPart.RemFlag(PrimFlags.TemporaryOnRez); + so.AttachToBackup(); + m_scene.EventManager.TriggerParcelPrimCountTainted(); + rootPart.ScheduleFullUpdate(); + rootPart.ClearUndoState(); - bool changed = presence.Appearance.DetachAttachment(inventoryID); - if (changed && m_scene.AvatarFactory != null) - m_scene.AvatarFactory.QueueAppearanceSave(remoteClient.AgentId); - - presence.RemoveAttachment(so); - DetachSceneObjectToGround(so, presence); - - List uuids = new List(); - uuids.Add(inventoryID); - m_scene.InventoryService.DeleteItems(remoteClient.AgentId, uuids); - remoteClient.SendRemoveInventoryItem(inventoryID); - } - - m_scene.EventManager.TriggerOnAttach(so.LocalId, so.UUID, UUID.Zero); + List uuids = new List(); + uuids.Add(inventoryID); + m_scene.InventoryService.DeleteItems(sp.UUID, uuids); + sp.ControllingClient.SendRemoveInventoryItem(inventoryID); } - } - /// - /// Detach the given scene object to the ground. - /// - /// - /// The caller has to take care of all the other work in updating avatar appearance, inventory, etc. - /// - /// The scene object to detach. - /// The scene presence from which the scene object is being detached. - private void DetachSceneObjectToGround(SceneObjectGroup so, ScenePresence sp) - { - SceneObjectPart rootPart = so.RootPart; - - rootPart.FromItemID = UUID.Zero; - so.AbsolutePosition = sp.AbsolutePosition; - so.AttachedAvatar = UUID.Zero; - rootPart.SetParentLocalId(0); - so.ClearPartAttachmentData(); - rootPart.ApplyPhysics(rootPart.GetEffectiveObjectFlags(), rootPart.VolumeDetectActive, m_scene.m_physicalPrim); - so.HasGroupChanged = true; - rootPart.Rezzed = DateTime.Now; - rootPart.RemFlag(PrimFlags.TemporaryOnRez); - so.AttachToBackup(); - m_scene.EventManager.TriggerParcelPrimCountTainted(); - rootPart.ScheduleFullUpdate(); - rootPart.ClearUndoState(); + m_scene.EventManager.TriggerOnAttach(so.LocalId, so.UUID, UUID.Zero); } // What makes this method odd and unique is it tries to detach using an UUID.... Yay for standards. diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs index ff3358f4fe..832c6eba7c 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs @@ -106,7 +106,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, attName).ParentGroup; - m_attMod.AttachObject(m_presence.ControllingClient, so, (uint)AttachmentPoint.Chest, false); + m_attMod.AttachObject(m_presence, so, (uint)AttachmentPoint.Chest, false); // Check status on scene presence Assert.That(m_presence.HasAttachments(), Is.True); @@ -140,7 +140,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests scene, attName, attItemId, attAssetId, m_presence.UUID, InventoryType.Object); m_attMod.RezSingleAttachmentFromInventory( - m_presence.ControllingClient, attItemId, (uint)AttachmentPoint.Chest); + m_presence, attItemId, (uint)AttachmentPoint.Chest); // Check scene presence status Assert.That(m_presence.HasAttachments(), Is.True); @@ -174,8 +174,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests scene, attName, attItemId, attAssetId, m_presence.UUID, InventoryType.Object); ISceneEntity so = m_attMod.RezSingleAttachmentFromInventory( - m_presence.ControllingClient, attItemId, (uint)AttachmentPoint.Chest); - m_attMod.DetachSingleAttachmentToGround(so.LocalId, m_presence.ControllingClient); + m_presence, attItemId, (uint)AttachmentPoint.Chest); + m_attMod.DetachSingleAttachmentToGround(m_presence, so.LocalId); // Check scene presence status Assert.That(m_presence.HasAttachments(), Is.False); @@ -208,7 +208,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests scene, attName, attItemId, attAssetId, m_presence.UUID, InventoryType.Object); m_attMod.RezSingleAttachmentFromInventory( - m_presence.ControllingClient, attItemId, (uint)AttachmentPoint.Chest); + m_presence, attItemId, (uint)AttachmentPoint.Chest); m_attMod.DetachSingleAttachmentToInv(attItemId, m_presence.ControllingClient); // Check status on scene presence diff --git a/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs b/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs index 8d3366c062..1a0423f33d 100644 --- a/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs @@ -57,17 +57,6 @@ namespace OpenSim.Region.Framework.Interfaces /// void DeleteAttachmentsFromScene(IScenePresence sp, bool silent); - /// - /// Attach an object to an avatar from the world. - /// - /// - /// - /// - /// - /// - void AttachObject( - IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, bool silent); - /// /// Attach an object to an avatar /// @@ -76,17 +65,7 @@ namespace OpenSim.Region.Framework.Interfaces /// /// /// true if the object was successfully attached, false otherwise - bool AttachObject( - IClientAPI remoteClient, SceneObjectGroup grp, uint AttachmentPt, bool silent); - - /// - /// Rez an attachment from user inventory and change inventory status to match. - /// - /// - /// - /// - /// The scene object that was attached. Null if the scene object could not be found - ISceneEntity RezSingleAttachmentFromInventory(IClientAPI remoteClient, UUID itemID, uint AttachmentPt); + bool AttachObject(IScenePresence sp, SceneObjectGroup grp, uint AttachmentPt, bool silent); /// /// Rez an attachment from user inventory and change inventory status to match. @@ -95,17 +74,15 @@ namespace OpenSim.Region.Framework.Interfaces /// /// /// The scene object that was attached. Null if the scene object could not be found - ISceneEntity RezSingleAttachmentFromInventory(ScenePresence sp, UUID itemID, uint AttachmentPt); + ISceneEntity RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt); /// /// Rez multiple attachments from a user's inventory /// - /// + /// /// /// - void RezMultipleAttachmentsFromInventory( - IClientAPI remoteClient, - List> rezlist); + void RezMultipleAttachmentsFromInventory(IScenePresence sp,List> rezlist); /// /// Detach an object from the avatar. @@ -121,9 +98,9 @@ namespace OpenSim.Region.Framework.Interfaces /// /// Detach the given item to the ground. /// + /// /// - /// - void DetachSingleAttachmentToGround(uint objectLocalID, IClientAPI remoteClient); + void DetachSingleAttachmentToGround(IScenePresence sp, uint objectLocalID); /// /// Detach the given item so that it remains in the user's inventory. diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index eadec09df3..0e5a7d25d2 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -2451,7 +2451,7 @@ namespace OpenSim.Region.Framework.Scenes RootPrim.RemFlag(PrimFlags.TemporaryOnRez); if (AttachmentsModule != null) - AttachmentsModule.AttachObject(sp.ControllingClient, grp, 0, false); + AttachmentsModule.AttachObject(sp, grp, 0, false); } else { diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs index 1a0d0c742d..49c06bcfcd 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs @@ -132,11 +132,9 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests UUID attAssetId = TestHelpers.ParseTail(0x3); string attName = "att"; - UserInventoryHelpers.CreateInventoryItem( - scene, attName, attItemId, attAssetId, sp.UUID, InventoryType.Object); + UserInventoryHelpers.CreateInventoryItem(scene, attName, attItemId, attAssetId, sp.UUID, InventoryType.Object); - am.RezSingleAttachmentFromInventory( - sp.ControllingClient, attItemId, (uint)AttachmentPoint.Chest); + am.RezSingleAttachmentFromInventory(sp, attItemId, (uint)AttachmentPoint.Chest); INPCModule npcModule = scene.RequestModuleInterface(); UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), scene, sp.Appearance); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 9a26f4b79a..4b2fb511bd 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -2966,8 +2966,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; if (attachmentsModule != null) - attachmentsModule.AttachObject(presence.ControllingClient, - grp, (uint)attachment, false); + attachmentsModule.AttachObject(presence, grp, (uint)attachment, false); } }