aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs100
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs48
2 files changed, 141 insertions, 7 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
index c274a5b..928d43f 100644
--- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
@@ -46,7 +46,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
46 { 46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48 48
49 protected Scene m_scene = null; 49 private Scene m_scene = null;
50 private IDialogModule m_dialogModule;
50 51
51 public string Name { get { return "Attachments Module"; } } 52 public string Name { get { return "Attachments Module"; } }
52 public Type ReplaceableInterface { get { return null; } } 53 public Type ReplaceableInterface { get { return null; } }
@@ -56,6 +57,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
56 public void AddRegion(Scene scene) 57 public void AddRegion(Scene scene)
57 { 58 {
58 m_scene = scene; 59 m_scene = scene;
60 m_dialogModule = m_scene.RequestModuleInterface<IDialogModule>();
59 m_scene.RegisterModuleInterface<IAttachmentsModule>(this); 61 m_scene.RegisterModuleInterface<IAttachmentsModule>(this);
60 m_scene.EventManager.OnNewClient += SubscribeToClientEvents; 62 m_scene.EventManager.OnNewClient += SubscribeToClientEvents;
61 // TODO: Should probably be subscribing to CloseClient too, but this doesn't yet give us IClientAPI 63 // TODO: Should probably be subscribing to CloseClient too, but this doesn't yet give us IClientAPI
@@ -228,7 +230,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
228 230
229 itemID = group.GetFromItemID(); 231 itemID = group.GetFromItemID();
230 if (itemID == UUID.Zero) 232 if (itemID == UUID.Zero)
231 m_scene.attachObjectAssetStore(sp.ControllingClient, group, sp.UUID, out itemID); 233 itemID = AddSceneObjectAsAttachment(sp.ControllingClient, group).ID;
232 234
233 ShowAttachInUserInventory(sp, AttachmentPt, itemID, group); 235 ShowAttachInUserInventory(sp, AttachmentPt, itemID, group);
234 236
@@ -563,7 +565,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
563 // the client/server crashes rather than logging out normally, the attachment's scripts will resume 565 // the client/server crashes rather than logging out normally, the attachment's scripts will resume
564 // without state on relog. Arguably, this is what we want anyway. 566 // without state on relog. Arguably, this is what we want anyway.
565 string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp, false); 567 string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp, false);
566 568
567 InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId); 569 InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
568 item = m_scene.InventoryService.GetItem(item); 570 item = m_scene.InventoryService.GetItem(item);
569 571
@@ -656,5 +658,97 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
656 // it get cleaned up 658 // it get cleaned up
657 so.RootPart.RemFlag(PrimFlags.TemporaryOnRez); 659 so.RootPart.RemFlag(PrimFlags.TemporaryOnRez);
658 } 660 }
661
662 /// <summary>
663 /// Add a scene object that was previously free in the scene as an attachment to an avatar.
664 /// </summary>
665 /// <param name="remoteClient"></param>
666 /// <param name="grp"></param>
667 /// <returns>The user inventory item created that holds the attachment.</returns>
668 private InventoryItemBase AddSceneObjectAsAttachment(IClientAPI remoteClient, SceneObjectGroup grp)
669 {
670// m_log.DebugFormat("[SCENE]: Called AddSceneObjectAsAttachment for object {0} {1} for {2} {3} {4}", grp.Name, grp.LocalId, remoteClient.Name, remoteClient.AgentId, AgentId);
671
672 Vector3 inventoryStoredPosition = new Vector3
673 (((grp.AbsolutePosition.X > (int)Constants.RegionSize)
674 ? Constants.RegionSize - 6
675 : grp.AbsolutePosition.X)
676 ,
677 (grp.AbsolutePosition.Y > (int)Constants.RegionSize)
678 ? Constants.RegionSize - 6
679 : grp.AbsolutePosition.Y,
680 grp.AbsolutePosition.Z);
681
682 Vector3 originalPosition = grp.AbsolutePosition;
683
684 grp.AbsolutePosition = inventoryStoredPosition;
685
686 // If we're being called from a script, then trying to serialize that same script's state will not complete
687 // in any reasonable time period. Therefore, we'll avoid it. The worst that can happen is that if
688 // the client/server crashes rather than logging out normally, the attachment's scripts will resume
689 // without state on relog. Arguably, this is what we want anyway.
690 string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp, false);
691
692 grp.AbsolutePosition = originalPosition;
693
694 AssetBase asset = m_scene.CreateAsset(
695 grp.GetPartName(grp.LocalId),
696 grp.GetPartDescription(grp.LocalId),
697 (sbyte)AssetType.Object,
698 Utils.StringToBytes(sceneObjectXml),
699 remoteClient.AgentId);
700
701 m_scene.AssetService.Store(asset);
702
703 InventoryItemBase item = new InventoryItemBase();
704 item.CreatorId = grp.RootPart.CreatorID.ToString();
705 item.CreatorData = grp.RootPart.CreatorData;
706 item.Owner = remoteClient.AgentId;
707 item.ID = UUID.Random();
708 item.AssetID = asset.FullID;
709 item.Description = asset.Description;
710 item.Name = asset.Name;
711 item.AssetType = asset.Type;
712 item.InvType = (int)InventoryType.Object;
713
714 InventoryFolderBase folder = m_scene.InventoryService.GetFolderForType(remoteClient.AgentId, AssetType.Object);
715 if (folder != null)
716 item.Folder = folder.ID;
717 else // oopsies
718 item.Folder = UUID.Zero;
719
720 if ((remoteClient.AgentId != grp.RootPart.OwnerID) && m_scene.Permissions.PropagatePermissions())
721 {
722 item.BasePermissions = grp.RootPart.NextOwnerMask;
723 item.CurrentPermissions = grp.RootPart.NextOwnerMask;
724 item.NextPermissions = grp.RootPart.NextOwnerMask;
725 item.EveryOnePermissions = grp.RootPart.EveryoneMask & grp.RootPart.NextOwnerMask;
726 item.GroupPermissions = grp.RootPart.GroupMask & grp.RootPart.NextOwnerMask;
727 }
728 else
729 {
730 item.BasePermissions = grp.RootPart.BaseMask;
731 item.CurrentPermissions = grp.RootPart.OwnerMask;
732 item.NextPermissions = grp.RootPart.NextOwnerMask;
733 item.EveryOnePermissions = grp.RootPart.EveryoneMask;
734 item.GroupPermissions = grp.RootPart.GroupMask;
735 }
736 item.CreationDate = Util.UnixTimeSinceEpoch();
737
738 // sets itemID so client can show item as 'attached' in inventory
739 grp.SetFromItemID(item.ID);
740
741 if (m_scene.AddInventoryItem(item))
742 {
743 remoteClient.SendInventoryItemCreateUpdate(item, 0);
744 }
745 else
746 {
747 if (m_dialogModule != null)
748 m_dialogModule.SendAlertToUser(remoteClient, "Operation failed");
749 }
750
751 return item;
752 }
659 } 753 }
660} 754}
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs
index 6695a9d..859f6ff 100644
--- a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs
@@ -81,7 +81,38 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
81 } 81 }
82 82
83 [Test] 83 [Test]
84 public void TestAddAttachment() 84 public void TestAddAttachmentFromGround()
85 {
86 TestHelpers.InMethod();
87// log4net.Config.XmlConfigurator.Configure();
88
89 UUID userId = TestHelpers.ParseTail(0x1);
90 string attName = "att";
91
92 UserAccountHelpers.CreateUserWithInventory(scene, userId);
93 ScenePresence presence = SceneHelpers.AddScenePresence(scene, userId);
94 SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, attName).ParentGroup;
95
96 m_attMod.AttachObject(presence.ControllingClient, so, (uint)AttachmentPoint.Chest, false);
97
98 // Check status on scene presence
99 Assert.That(presence.HasAttachments(), Is.True);
100 List<SceneObjectGroup> attachments = presence.Attachments;
101 Assert.That(attachments.Count, Is.EqualTo(1));
102 SceneObjectGroup attSo = attachments[0];
103 Assert.That(attSo.Name, Is.EqualTo(attName));
104 Assert.That(attSo.GetAttachmentPoint(), Is.EqualTo((byte)AttachmentPoint.Chest));
105 Assert.That(attSo.IsAttachment);
106 Assert.That(attSo.UsesPhysics, Is.False);
107 Assert.That(attSo.IsTemporary, Is.False);
108
109 // Check item status
110 Assert.That(presence.Appearance.GetAttachpoint(
111 attSo.GetFromItemID()), Is.EqualTo((int)AttachmentPoint.Chest));
112 }
113
114 [Test]
115 public void TestAddAttachmentFromInventory()
85 { 116 {
86 TestHelpers.InMethod(); 117 TestHelpers.InMethod();
87// log4net.Config.XmlConfigurator.Configure(); 118// log4net.Config.XmlConfigurator.Configure();
@@ -104,8 +135,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
104 Assert.That(presence.HasAttachments(), Is.True); 135 Assert.That(presence.HasAttachments(), Is.True);
105 List<SceneObjectGroup> attachments = presence.Attachments; 136 List<SceneObjectGroup> attachments = presence.Attachments;
106 Assert.That(attachments.Count, Is.EqualTo(1)); 137 Assert.That(attachments.Count, Is.EqualTo(1));
107 Assert.That(attachments[0].Name, Is.EqualTo(attName)); 138 SceneObjectGroup attSo = attachments[0];
108 Assert.That(attachments[0].GetAttachmentPoint(), Is.EqualTo((byte)AttachmentPoint.Chest)); 139 Assert.That(attSo.Name, Is.EqualTo(attName));
140 Assert.That(attSo.GetAttachmentPoint(), Is.EqualTo((byte)AttachmentPoint.Chest));
141 Assert.That(attSo.IsAttachment);
142 Assert.That(attSo.UsesPhysics, Is.False);
143 Assert.That(attSo.IsTemporary, Is.False);
109 144
110 // Check item status 145 // Check item status
111 Assert.That(presence.Appearance.GetAttachpoint(attItemId), Is.EqualTo((int)AttachmentPoint.Chest)); 146 Assert.That(presence.Appearance.GetAttachpoint(attItemId), Is.EqualTo((int)AttachmentPoint.Chest));
@@ -166,7 +201,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
166 List<SceneObjectGroup> attachments = presence.Attachments; 201 List<SceneObjectGroup> attachments = presence.Attachments;
167 202
168 Assert.That(attachments.Count, Is.EqualTo(1)); 203 Assert.That(attachments.Count, Is.EqualTo(1));
169 Assert.That(attachments[0].Name, Is.EqualTo(attName)); 204 SceneObjectGroup attSo = attachments[0];
205 Assert.That(attSo.Name, Is.EqualTo(attName));
206 Assert.That(attSo.GetAttachmentPoint(), Is.EqualTo((byte)AttachmentPoint.Chest));
207 Assert.That(attSo.IsAttachment);
208 Assert.That(attSo.UsesPhysics, Is.False);
209 Assert.That(attSo.IsTemporary, Is.False);
170 } 210 }
171 211
172 // I'm commenting this test because scene setup NEEDS InventoryService to 212 // I'm commenting this test because scene setup NEEDS InventoryService to