diff options
Merge branch 'master' into bulletsim
Conflicts:
OpenSim/Region/Framework/Scenes/SceneManager.cs
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Attachments')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs | 20 | ||||
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs | 200 |
2 files changed, 210 insertions, 10 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index 1e09610..97a1be6 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs | |||
@@ -101,7 +101,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
101 | /// <param name="silent"></param> | 101 | /// <param name="silent"></param> |
102 | public void AttachObject(IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, bool silent) | 102 | public void AttachObject(IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, bool silent) |
103 | { | 103 | { |
104 | m_log.Debug("[ATTACHMENTS MODULE]: Invoking AttachObject"); | 104 | // m_log.Debug("[ATTACHMENTS MODULE]: Invoking AttachObject"); |
105 | 105 | ||
106 | try | 106 | try |
107 | { | 107 | { |
@@ -226,9 +226,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
226 | public UUID RezSingleAttachmentFromInventory( | 226 | public UUID RezSingleAttachmentFromInventory( |
227 | IClientAPI remoteClient, UUID itemID, uint AttachmentPt, bool updateInventoryStatus) | 227 | IClientAPI remoteClient, UUID itemID, uint AttachmentPt, bool updateInventoryStatus) |
228 | { | 228 | { |
229 | m_log.DebugFormat( | 229 | // m_log.DebugFormat( |
230 | "[ATTACHMENTS MODULE]: Rezzing attachment to point {0} from item {1} for {2}", | 230 | // "[ATTACHMENTS MODULE]: Rezzing attachment to point {0} from item {1} for {2}", |
231 | (AttachmentPoint)AttachmentPt, itemID, remoteClient.Name); | 231 | // (AttachmentPoint)AttachmentPt, itemID, remoteClient.Name); |
232 | 232 | ||
233 | // TODO: this short circuits multiple attachments functionality in LL viewer 2.1+ and should | 233 | // TODO: this short circuits multiple attachments functionality in LL viewer 2.1+ and should |
234 | // be removed when that functionality is implemented in opensim | 234 | // be removed when that functionality is implemented in opensim |
@@ -261,7 +261,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
261 | false, false, remoteClient.AgentId, true); | 261 | false, false, remoteClient.AgentId, true); |
262 | 262 | ||
263 | // m_log.DebugFormat( | 263 | // m_log.DebugFormat( |
264 | // "[ATTACHMENTS MODULE]: Retrieved single object {0} for attachment to {1} on point {2}", | 264 | // "[ATTACHMENTS MODULE]: Retrieved single object {0} for attachment to {1} on point {2}", |
265 | // objatt.Name, remoteClient.Name, AttachmentPt); | 265 | // objatt.Name, remoteClient.Name, AttachmentPt); |
266 | 266 | ||
267 | if (objatt != null) | 267 | if (objatt != null) |
@@ -466,7 +466,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
466 | { | 466 | { |
467 | m_scene.EventManager.TriggerOnAttach(group.LocalId, itemID, UUID.Zero); | 467 | m_scene.EventManager.TriggerOnAttach(group.LocalId, itemID, UUID.Zero); |
468 | group.DetachToInventoryPrep(); | 468 | group.DetachToInventoryPrep(); |
469 | m_log.Debug("[ATTACHMENTS MODULE]: Saving attachpoint: " + ((uint)group.GetAttachmentPoint()).ToString()); | 469 | // m_log.Debug("[ATTACHMENTS MODULE]: Saving attachpoint: " + ((uint)group.GetAttachmentPoint()).ToString()); |
470 | 470 | ||
471 | // If an item contains scripts, it's always changed. | 471 | // If an item contains scripts, it's always changed. |
472 | // This ensures script state is saved on detach | 472 | // This ensures script state is saved on detach |
@@ -501,10 +501,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
501 | /// <summary> | 501 | /// <summary> |
502 | /// Update the attachment asset for the new sog details if they have changed. | 502 | /// Update the attachment asset for the new sog details if they have changed. |
503 | /// </summary> | 503 | /// </summary> |
504 | /// | 504 | /// <remarks> |
505 | /// This is essential for preserving attachment attributes such as permission. Unlike normal scene objects, | 505 | /// This is essential for preserving attachment attributes such as permission. Unlike normal scene objects, |
506 | /// these details are not stored on the region. | 506 | /// these details are not stored on the region. |
507 | /// | 507 | /// </remarks> |
508 | /// <param name="remoteClient"></param> | 508 | /// <param name="remoteClient"></param> |
509 | /// <param name="grp"></param> | 509 | /// <param name="grp"></param> |
510 | /// <param name="itemID"></param> | 510 | /// <param name="itemID"></param> |
@@ -566,8 +566,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments | |||
566 | /// <param name="silent"></param> | 566 | /// <param name="silent"></param> |
567 | protected void AttachToAgent(ScenePresence avatar, SceneObjectGroup so, uint attachmentpoint, Vector3 attachOffset, bool silent) | 567 | protected void AttachToAgent(ScenePresence avatar, SceneObjectGroup so, uint attachmentpoint, Vector3 attachOffset, bool silent) |
568 | { | 568 | { |
569 | m_log.DebugFormat("[ATTACHMENTS MODULE]: Adding attachment {0} to avatar {1} in pt {2} pos {3} {4}", Name, avatar.Name, | 569 | // m_log.DebugFormat("[ATTACHMENTS MODULE]: Adding attachment {0} to avatar {1} in pt {2} pos {3} {4}", |
570 | attachmentpoint, attachOffset, so.RootPart.AttachedPos); | 570 | // so.Name, avatar.Name, attachmentpoint, attachOffset, so.RootPart.AttachedPos); |
571 | 571 | ||
572 | so.DetachFromBackup(); | 572 | so.DetachFromBackup(); |
573 | 573 | ||
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs new file mode 100644 index 0000000..5bac4c6 --- /dev/null +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs | |||
@@ -0,0 +1,200 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Text; | ||
32 | using System.Threading; | ||
33 | using System.Timers; | ||
34 | using Timer=System.Timers.Timer; | ||
35 | using Nini.Config; | ||
36 | using NUnit.Framework; | ||
37 | using OpenMetaverse; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Framework.Communications; | ||
40 | using OpenSim.Region.CoreModules.Avatar.Attachments; | ||
41 | using OpenSim.Region.CoreModules.Framework.InventoryAccess; | ||
42 | using OpenSim.Region.CoreModules.World.Serialiser; | ||
43 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; | ||
44 | using OpenSim.Region.Framework.Scenes; | ||
45 | using OpenSim.Region.Framework.Interfaces; | ||
46 | using OpenSim.Tests.Common; | ||
47 | using OpenSim.Tests.Common.Mock; | ||
48 | |||
49 | namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests | ||
50 | { | ||
51 | /// <summary> | ||
52 | /// Attachment tests | ||
53 | /// </summary> | ||
54 | [TestFixture] | ||
55 | public class AttachmentsModuleTests | ||
56 | { | ||
57 | public Scene scene; | ||
58 | public UUID agent1; | ||
59 | public static Random random; | ||
60 | public AgentCircuitData acd1; | ||
61 | public SceneObjectGroup sog1, sog2; | ||
62 | |||
63 | [SetUp] | ||
64 | public void Init() | ||
65 | { | ||
66 | // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread. | ||
67 | Util.FireAndForgetMethod = FireAndForgetMethod.None; | ||
68 | |||
69 | IConfigSource config = new IniConfigSource(); | ||
70 | config.AddConfig("Modules"); | ||
71 | config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule"); | ||
72 | |||
73 | scene = SceneHelpers.SetupScene(); | ||
74 | SceneHelpers.SetupSceneModules(scene, config, new AttachmentsModule(), new BasicInventoryAccessModule()); | ||
75 | |||
76 | agent1 = UUID.Random(); | ||
77 | random = new Random(); | ||
78 | sog1 = NewSOG(UUID.Random(), scene, agent1); | ||
79 | sog2 = NewSOG(UUID.Random(), scene, agent1); | ||
80 | } | ||
81 | |||
82 | [TearDown] | ||
83 | public void TearDown() | ||
84 | { | ||
85 | // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple | ||
86 | // threads. Possibly, later tests should be rewritten not to worry about such things. | ||
87 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; | ||
88 | } | ||
89 | |||
90 | [Test] | ||
91 | public void TestAddAttachments() | ||
92 | { | ||
93 | TestHelpers.InMethod(); | ||
94 | |||
95 | ScenePresence presence = SceneHelpers.AddScenePresence(scene, agent1); | ||
96 | presence.AddAttachment(sog1); | ||
97 | presence.AddAttachment(sog2); | ||
98 | |||
99 | Assert.That(presence.HasAttachments(), Is.True); | ||
100 | Assert.That(presence.ValidateAttachments(), Is.True); | ||
101 | } | ||
102 | |||
103 | [Test] | ||
104 | public void TestRemoveAttachments() | ||
105 | { | ||
106 | TestHelpers.InMethod(); | ||
107 | |||
108 | ScenePresence presence = SceneHelpers.AddScenePresence(scene, agent1); | ||
109 | presence.AddAttachment(sog1); | ||
110 | presence.AddAttachment(sog2); | ||
111 | presence.RemoveAttachment(sog1); | ||
112 | presence.RemoveAttachment(sog2); | ||
113 | Assert.That(presence.HasAttachments(), Is.False); | ||
114 | } | ||
115 | |||
116 | [Test] | ||
117 | public void TestRezAttachmentsOnAvatarEntrance() | ||
118 | { | ||
119 | TestHelpers.InMethod(); | ||
120 | // log4net.Config.XmlConfigurator.Configure(); | ||
121 | |||
122 | UUID userId = TestHelpers.ParseTail(0x1); | ||
123 | UUID attItemId = TestHelpers.ParseTail(0x2); | ||
124 | UUID attAssetId = TestHelpers.ParseTail(0x3); | ||
125 | string attName = "att"; | ||
126 | |||
127 | UserAccountHelpers.CreateUserWithInventory(scene, userId); | ||
128 | InventoryItemBase attItem | ||
129 | = UserInventoryHelpers.CreateInventoryItem( | ||
130 | scene, attName, attItemId, attAssetId, userId, InventoryType.Object); | ||
131 | |||
132 | AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId); | ||
133 | acd.Appearance = new AvatarAppearance(); | ||
134 | acd.Appearance.SetAttachment((int)AttachmentPoint.Chest, attItem.ID, attItem.AssetID); | ||
135 | ScenePresence presence = SceneHelpers.AddScenePresence(scene, acd); | ||
136 | |||
137 | Assert.That(presence.HasAttachments(), Is.True); | ||
138 | List<SceneObjectGroup> attachments = presence.Attachments; | ||
139 | |||
140 | Assert.That(attachments.Count, Is.EqualTo(1)); | ||
141 | Assert.That(attachments[0].Name, Is.EqualTo(attName)); | ||
142 | } | ||
143 | |||
144 | // I'm commenting this test because scene setup NEEDS InventoryService to | ||
145 | // be non-null | ||
146 | //[Test] | ||
147 | // public void T032_CrossAttachments() | ||
148 | // { | ||
149 | // TestHelpers.InMethod(); | ||
150 | // | ||
151 | // ScenePresence presence = scene.GetScenePresence(agent1); | ||
152 | // ScenePresence presence2 = scene2.GetScenePresence(agent1); | ||
153 | // presence2.AddAttachment(sog1); | ||
154 | // presence2.AddAttachment(sog2); | ||
155 | // | ||
156 | // ISharedRegionModule serialiser = new SerialiserModule(); | ||
157 | // SceneHelpers.SetupSceneModules(scene, new IniConfigSource(), serialiser); | ||
158 | // SceneHelpers.SetupSceneModules(scene2, new IniConfigSource(), serialiser); | ||
159 | // | ||
160 | // Assert.That(presence.HasAttachments(), Is.False, "Presence has attachments before cross"); | ||
161 | // | ||
162 | // //Assert.That(presence2.CrossAttachmentsIntoNewRegion(region1, true), Is.True, "Cross was not successful"); | ||
163 | // Assert.That(presence2.HasAttachments(), Is.False, "Presence2 objects were not deleted"); | ||
164 | // Assert.That(presence.HasAttachments(), Is.True, "Presence has not received new objects"); | ||
165 | // } | ||
166 | |||
167 | private SceneObjectGroup NewSOG(UUID uuid, Scene scene, UUID agent) | ||
168 | { | ||
169 | SceneObjectPart sop = new SceneObjectPart(); | ||
170 | sop.Name = RandomName(); | ||
171 | sop.Description = RandomName(); | ||
172 | sop.Text = RandomName(); | ||
173 | sop.SitName = RandomName(); | ||
174 | sop.TouchName = RandomName(); | ||
175 | sop.UUID = uuid; | ||
176 | sop.Shape = PrimitiveBaseShape.Default; | ||
177 | sop.Shape.State = 1; | ||
178 | sop.OwnerID = agent; | ||
179 | |||
180 | SceneObjectGroup sog = new SceneObjectGroup(sop); | ||
181 | sog.SetScene(scene); | ||
182 | |||
183 | return sog; | ||
184 | } | ||
185 | |||
186 | private static string RandomName() | ||
187 | { | ||
188 | StringBuilder name = new StringBuilder(); | ||
189 | int size = random.Next(5,12); | ||
190 | char ch; | ||
191 | for (int i = 0; i < size; i++) | ||
192 | { | ||
193 | ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ; | ||
194 | name.Append(ch); | ||
195 | } | ||
196 | |||
197 | return name.ToString(); | ||
198 | } | ||
199 | } | ||
200 | } \ No newline at end of file | ||