Fix bug where attachments were remaining on the avatar after being dropped.

If the inventory service is configured not to allow deletion then these will not disappear from inventory
remove-scene-viewer
Justin Clark-Casey (justincc) 2011-08-30 22:06:24 +01:00
parent 17dab7245f
commit e7a515bab0
3 changed files with 25 additions and 8 deletions

View File

@ -383,9 +383,11 @@ namespace OpenSim.Framework
// DEBUG OFF // DEBUG OFF
/// <summary> /// <summary>
/// Get a list of the attachments, note that there may be /// Get a list of the attachments.
/// duplicate attachpoints
/// </summary> /// </summary>
/// <remarks>
/// There may be duplicate attachpoints
/// </remarks>
public List<AvatarAttachment> GetAttachments() public List<AvatarAttachment> GetAttachments()
{ {
List<AvatarAttachment> alist = new List<AvatarAttachment>(); List<AvatarAttachment> alist = new List<AvatarAttachment>();
@ -487,6 +489,7 @@ namespace OpenSim.Framework
// And remove the list if there are no more attachments here // And remove the list if there are no more attachments here
if (m_attachments[kvp.Key].Count == 0) if (m_attachments[kvp.Key].Count == 0)
m_attachments.Remove(kvp.Key); m_attachments.Remove(kvp.Key);
return true; return true;
} }
} }

View File

@ -451,6 +451,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
public void DetachSingleAttachmentToGround(UUID sceneObjectID, IClientAPI remoteClient) public void DetachSingleAttachmentToGround(UUID sceneObjectID, IClientAPI remoteClient)
{ {
// m_log.DebugFormat(
// "[ATTACHMENTS MODULE]: DetachSingleAttachmentToGround() for {0}, object {1}",
// remoteClient.Name, sceneObjectID);
SceneObjectGroup so = m_scene.GetSceneObjectGroup(sceneObjectID); SceneObjectGroup so = m_scene.GetSceneObjectGroup(sceneObjectID);
if (so == null) if (so == null)
@ -461,6 +465,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
UUID inventoryID = so.GetFromItemID(); UUID inventoryID = so.GetFromItemID();
// m_log.DebugFormat(
// "[ATTACHMENTS MODULE]: In DetachSingleAttachmentToGround(), object is {0} {1}, associated item is {2}",
// so.Name, so.LocalId, inventoryID);
ScenePresence presence; ScenePresence presence;
if (m_scene.TryGetScenePresence(remoteClient.AgentId, out presence)) if (m_scene.TryGetScenePresence(remoteClient.AgentId, out presence))
{ {
@ -468,7 +476,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
so.PrimCount, remoteClient.AgentId, presence.AbsolutePosition)) so.PrimCount, remoteClient.AgentId, presence.AbsolutePosition))
return; return;
bool changed = presence.Appearance.DetachAttachment(sceneObjectID); bool changed = presence.Appearance.DetachAttachment(inventoryID);
if (changed && m_scene.AvatarFactory != null) if (changed && m_scene.AvatarFactory != null)
m_scene.AvatarFactory.QueueAppearanceSave(remoteClient.AgentId); m_scene.AvatarFactory.QueueAppearanceSave(remoteClient.AgentId);
@ -485,7 +493,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
} }
/// <summary> /// <summary>
/// Detach the given scene objet to the ground. /// Detach the given scene object to the ground.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// The caller has to take care of all the other work in updating avatar appearance, inventory, etc. /// The caller has to take care of all the other work in updating avatar appearance, inventory, etc.

View File

@ -138,7 +138,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
m_attMod.RezSingleAttachmentFromInventory( m_attMod.RezSingleAttachmentFromInventory(
m_presence.ControllingClient, attItemId, (uint)AttachmentPoint.Chest); m_presence.ControllingClient, attItemId, (uint)AttachmentPoint.Chest);
// Check status on scene presence // Check scene presence status
Assert.That(m_presence.HasAttachments(), Is.True); Assert.That(m_presence.HasAttachments(), Is.True);
List<SceneObjectGroup> attachments = m_presence.Attachments; List<SceneObjectGroup> attachments = m_presence.Attachments;
Assert.That(attachments.Count, Is.EqualTo(1)); Assert.That(attachments.Count, Is.EqualTo(1));
@ -149,12 +149,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
Assert.That(attSo.UsesPhysics, Is.False); Assert.That(attSo.UsesPhysics, Is.False);
Assert.That(attSo.IsTemporary, Is.False); Assert.That(attSo.IsTemporary, Is.False);
// Check item status // Check appearance status
Assert.That(m_presence.Appearance.GetAttachpoint(attItemId), Is.EqualTo((int)AttachmentPoint.Chest)); Assert.That(m_presence.Appearance.GetAttachpoint(attItemId), Is.EqualTo((int)AttachmentPoint.Chest));
} }
[Test] [Test]
public void TestDetachAttachmentToScene() public void TestDetachAttachmentToGround()
{ {
TestHelpers.InMethod(); TestHelpers.InMethod();
// log4net.Config.XmlConfigurator.Configure(); // log4net.Config.XmlConfigurator.Configure();
@ -168,15 +168,21 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
UserInventoryHelpers.CreateInventoryItem( UserInventoryHelpers.CreateInventoryItem(
scene, attName, attItemId, attAssetId, m_presence.UUID, InventoryType.Object); scene, attName, attItemId, attAssetId, m_presence.UUID, InventoryType.Object);
// Check item status
Assert.That(scene.InventoryService.GetItem(new InventoryItemBase(attItemId)), Is.Not.Null);
UUID attSoId = m_attMod.RezSingleAttachmentFromInventory( UUID attSoId = m_attMod.RezSingleAttachmentFromInventory(
m_presence.ControllingClient, attItemId, (uint)AttachmentPoint.Chest); m_presence.ControllingClient, attItemId, (uint)AttachmentPoint.Chest);
m_attMod.DetachSingleAttachmentToGround(attSoId, m_presence.ControllingClient); m_attMod.DetachSingleAttachmentToGround(attSoId, m_presence.ControllingClient);
// Check status on scene presence // Check scene presence status
Assert.That(m_presence.HasAttachments(), Is.False); Assert.That(m_presence.HasAttachments(), Is.False);
List<SceneObjectGroup> attachments = m_presence.Attachments; List<SceneObjectGroup> attachments = m_presence.Attachments;
Assert.That(attachments.Count, Is.EqualTo(0)); Assert.That(attachments.Count, Is.EqualTo(0));
// Check appearance status
Assert.That(m_presence.Appearance.GetAttachments().Count, Is.EqualTo(0));
// Check item status // Check item status
Assert.That(scene.InventoryService.GetItem(new InventoryItemBase(attItemId)), Is.Null); Assert.That(scene.InventoryService.GetItem(new InventoryItemBase(attItemId)), Is.Null);