aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar
diff options
context:
space:
mode:
authorMelanie2012-07-12 08:55:16 +0100
committerMelanie2012-07-12 08:55:16 +0100
commitd632fd7124e3962534fc34f9c7749615dbb62108 (patch)
tree84ece06822680bfd5b639d9c3fd046ecbb7a154e /OpenSim/Region/CoreModules/Avatar
parentMerge branch 'avination' into careminster (diff)
parentMany explanitory comments added to the link and delink code in (diff)
downloadopensim-SC-d632fd7124e3962534fc34f9c7749615dbb62108.zip
opensim-SC-d632fd7124e3962534fc34f9c7749615dbb62108.tar.gz
opensim-SC-d632fd7124e3962534fc34f9c7749615dbb62108.tar.bz2
opensim-SC-d632fd7124e3962534fc34f9c7749615dbb62108.tar.xz
Merge branch 'master' into careminster
Conflicts: OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs OpenSim/Region/Framework/Scenes/SceneObjectPart.cs OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs20
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs157
2 files changed, 155 insertions, 22 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
index 2bb60d5..394b90a 100644
--- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
@@ -237,7 +237,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
237 if (sp.PresenceType == PresenceType.Npc) 237 if (sp.PresenceType == PresenceType.Npc)
238 RezSingleAttachmentFromInventoryInternal(sp, UUID.Zero, attach.AssetID, p, null); 238 RezSingleAttachmentFromInventoryInternal(sp, UUID.Zero, attach.AssetID, p, null);
239 else 239 else
240 RezSingleAttachmentFromInventory(sp, attach.ItemID, p, true, d); 240 RezSingleAttachmentFromInventory(sp, attach.ItemID, p, d);
241 } 241 }
242 catch (Exception e) 242 catch (Exception e)
243 { 243 {
@@ -405,10 +405,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
405 405
406 public ISceneEntity RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt) 406 public ISceneEntity RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt)
407 { 407 {
408 return RezSingleAttachmentFromInventory(sp, itemID, AttachmentPt, true, null); 408 return RezSingleAttachmentFromInventory(sp, itemID, AttachmentPt, null);
409 } 409 }
410 410
411 public ISceneEntity RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt, bool updateInventoryStatus, XmlDocument doc) 411 public ISceneEntity RezSingleAttachmentFromInventory(IScenePresence sp, UUID itemID, uint AttachmentPt, XmlDocument doc)
412 { 412 {
413 if (!Enabled) 413 if (!Enabled)
414 return null; 414 return null;
@@ -596,6 +596,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
596 /// </remarks> 596 /// </remarks>
597 /// <param name="sp"></param> 597 /// <param name="sp"></param>
598 /// <param name="grp"></param> 598 /// <param name="grp"></param>
599 /// <param name="saveAllScripted"></param>
599 private void UpdateKnownItem(IScenePresence sp, SceneObjectGroup grp, bool saveAllScripted) 600 private void UpdateKnownItem(IScenePresence sp, SceneObjectGroup grp, bool saveAllScripted)
600 { 601 {
601 // Saving attachments for NPCs messes them up for the real owner! 602 // Saving attachments for NPCs messes them up for the real owner!
@@ -789,18 +790,23 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
789 null, assetID, Vector3.Zero, Vector3.Zero, UUID.Zero, (byte)1, true, 790 null, assetID, Vector3.Zero, Vector3.Zero, UUID.Zero, (byte)1, true,
790 false, false, sp.UUID, true); 791 false, false, sp.UUID, true);
791 792
792// m_log.DebugFormat(
793// "[ATTACHMENTS MODULE]: Retrieved single object {0} for attachment to {1} on point {2}",
794// objatt.Name, remoteClient.Name, AttachmentPt);
795
796 if (objatt != null) 793 if (objatt != null)
797 { 794 {
795// m_log.DebugFormat(
796// "[ATTACHMENTS MODULE]: Rezzed single object {0} for attachment to {1} on point {2} in {3}",
797// objatt.Name, sp.Name, attachmentPt, m_scene.Name);
798
798 // HasGroupChanged is being set from within RezObject. Ideally it would be set by the caller. 799 // HasGroupChanged is being set from within RezObject. Ideally it would be set by the caller.
799 objatt.HasGroupChanged = false; 800 objatt.HasGroupChanged = false;
800 bool tainted = false; 801 bool tainted = false;
801 if (attachmentPt != 0 && attachmentPt != objatt.AttachmentPoint) 802 if (attachmentPt != 0 && attachmentPt != objatt.AttachmentPoint)
802 tainted = true; 803 tainted = true;
803 804
805 // FIXME: Detect whether it's really likely for AttachObject to throw an exception in the normal
806 // course of events. If not, then it's probably not worth trying to recover the situation
807 // since this is more likely to trigger further exceptions and confuse later debugging. If
808 // exceptions can be thrown in expected error conditions (not NREs) then make this consistent
809 // since other normal error conditions will simply return false instead.
804 // This will throw if the attachment fails 810 // This will throw if the attachment fails
805 try 811 try
806 { 812 {
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs
index 8423d43..cd1e1c1 100644
--- a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs
@@ -31,6 +31,7 @@ using System.Reflection;
31using System.Text; 31using System.Text;
32using System.Threading; 32using System.Threading;
33using System.Timers; 33using System.Timers;
34using System.Xml;
34using Timer=System.Timers.Timer; 35using Timer=System.Timers.Timer;
35using Nini.Config; 36using Nini.Config;
36using NUnit.Framework; 37using NUnit.Framework;
@@ -41,10 +42,12 @@ using OpenSim.Region.CoreModules.Avatar.Attachments;
41using OpenSim.Region.CoreModules.Framework; 42using OpenSim.Region.CoreModules.Framework;
42using OpenSim.Region.CoreModules.Framework.EntityTransfer; 43using OpenSim.Region.CoreModules.Framework.EntityTransfer;
43using OpenSim.Region.CoreModules.Framework.InventoryAccess; 44using OpenSim.Region.CoreModules.Framework.InventoryAccess;
44using OpenSim.Region.CoreModules.World.Serialiser; 45using OpenSim.Region.CoreModules.Scripting.WorldComm;
45using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; 46using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
47using OpenSim.Region.CoreModules.World.Serialiser;
46using OpenSim.Region.Framework.Scenes; 48using OpenSim.Region.Framework.Scenes;
47using OpenSim.Region.Framework.Interfaces; 49using OpenSim.Region.Framework.Interfaces;
50using OpenSim.Region.ScriptEngine.XEngine;
48using OpenSim.Services.Interfaces; 51using OpenSim.Services.Interfaces;
49using OpenSim.Tests.Common; 52using OpenSim.Tests.Common;
50using OpenSim.Tests.Common.Mock; 53using OpenSim.Tests.Common.Mock;
@@ -57,6 +60,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
57 [TestFixture] 60 [TestFixture]
58 public class AttachmentsModuleTests : OpenSimTestCase 61 public class AttachmentsModuleTests : OpenSimTestCase
59 { 62 {
63 private AutoResetEvent m_chatEvent = new AutoResetEvent(false);
64 private OSChatMessage m_osChatMessageReceived;
65
60 [TestFixtureSetUp] 66 [TestFixtureSetUp]
61 public void FixtureInit() 67 public void FixtureInit()
62 { 68 {
@@ -72,16 +78,74 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
72 Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; 78 Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
73 } 79 }
74 80
75 private Scene CreateDefaultTestScene() 81 private void OnChatFromWorld(object sender, OSChatMessage oscm)
82 {
83// Console.WriteLine("Got chat [{0}]", oscm.Message);
84
85 m_osChatMessageReceived = oscm;
86 m_chatEvent.Set();
87 }
88
89 private Scene CreateTestScene()
90 {
91 IConfigSource config = new IniConfigSource();
92 List<object> modules = new List<object>();
93
94 AddCommonConfig(config, modules);
95
96 Scene scene
97 = new SceneHelpers().SetupScene(
98 "attachments-test-scene", TestHelpers.ParseTail(999), 1000, 1000, config);
99 SceneHelpers.SetupSceneModules(scene, config, modules.ToArray());
100
101 return scene;
102 }
103
104 private Scene CreateScriptingEnabledTestScene()
76 { 105 {
77 IConfigSource config = new IniConfigSource(); 106 IConfigSource config = new IniConfigSource();
107 List<object> modules = new List<object>();
108
109 AddCommonConfig(config, modules);
110 AddScriptingConfig(config, modules);
111
112 Scene scene
113 = new SceneHelpers().SetupScene(
114 "attachments-test-scene", TestHelpers.ParseTail(999), 1000, 1000, config);
115 SceneHelpers.SetupSceneModules(scene, config, modules.ToArray());
116
117 scene.StartScripts();
118
119 return scene;
120 }
121
122 private void AddCommonConfig(IConfigSource config, List<object> modules)
123 {
78 config.AddConfig("Modules"); 124 config.AddConfig("Modules");
79 config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule"); 125 config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule");
80 126
81 Scene scene = new SceneHelpers().SetupScene(); 127 modules.Add(new AttachmentsModule());
82 SceneHelpers.SetupSceneModules(scene, config, new AttachmentsModule(), new BasicInventoryAccessModule()); 128 modules.Add(new BasicInventoryAccessModule());
129 }
130
131 private void AddScriptingConfig(IConfigSource config, List<object> modules)
132 {
133 IConfig startupConfig = config.AddConfig("Startup");
134 startupConfig.Set("DefaultScriptEngine", "XEngine");
135
136 IConfig xEngineConfig = config.AddConfig("XEngine");
137 xEngineConfig.Set("Enabled", "true");
138 xEngineConfig.Set("StartDelay", "0");
83 139
84 return scene; 140 // These tests will not run with AppDomainLoading = true, at least on mono. For unknown reasons, the call
141 // to AssemblyResolver.OnAssemblyResolve fails.
142 xEngineConfig.Set("AppDomainLoading", "false");
143
144 modules.Add(new XEngine());
145
146 // Necessary to stop serialization complaining
147 // FIXME: Stop this being necessary if at all possible
148// modules.Add(new WorldCommModule());
85 } 149 }
86 150
87 /// <summary> 151 /// <summary>
@@ -116,7 +180,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
116 TestHelpers.InMethod(); 180 TestHelpers.InMethod();
117// TestHelpers.EnableLogging(); 181// TestHelpers.EnableLogging();
118 182
119 Scene scene = CreateDefaultTestScene(); 183 Scene scene = CreateTestScene();
120 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); 184 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
121 ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1); 185 ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1);
122 186
@@ -163,7 +227,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
163 TestHelpers.InMethod(); 227 TestHelpers.InMethod();
164// TestHelpers.EnableLogging(); 228// TestHelpers.EnableLogging();
165 229
166 Scene scene = CreateDefaultTestScene(); 230 Scene scene = CreateTestScene();
167 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); 231 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
168 ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1); 232 ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1);
169 233
@@ -185,12 +249,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
185 } 249 }
186 250
187 [Test] 251 [Test]
188 public void TestAddAttachmentFromInventory() 252 public void TestRezAttachmentFromInventory()
189 { 253 {
190 TestHelpers.InMethod(); 254 TestHelpers.InMethod();
191// log4net.Config.XmlConfigurator.Configure(); 255// log4net.Config.XmlConfigurator.Configure();
192 256
193 Scene scene = CreateDefaultTestScene(); 257 Scene scene = CreateTestScene();
194 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); 258 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
195 ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID); 259 ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID);
196 260
@@ -217,13 +281,38 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
217 Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1)); 281 Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
218 } 282 }
219 283
284 /// <summary>
285 /// Test specific conditions associated with rezzing a scripted attachment from inventory.
286 /// </summary>
287 [Test]
288 public void TestRezScriptedAttachmentFromInventory()
289 {
290 TestHelpers.InMethod();
291
292 Scene scene = CreateTestScene();
293 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
294 ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID);
295
296 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, sp.UUID, "att-name", 0x10);
297 TaskInventoryHelpers.AddScript(scene, so.RootPart);
298 InventoryItemBase userItem = UserInventoryHelpers.AddInventoryItem(scene, so, 0x100, 0x1000);
299
300 scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, userItem.ID, (uint)AttachmentPoint.Chest);
301
302 // TODO: Need to have a test that checks the script is actually started but this involves a lot more
303 // plumbing of the script engine and either pausing for events or more infrastructure to turn off various
304 // script engine delays/asychronicity that isn't helpful in an automated regression testing context.
305 SceneObjectGroup attSo = scene.GetSceneObjectGroup(so.Name);
306 Assert.That(attSo.ContainsScripts(), Is.True);
307 }
308
220 [Test] 309 [Test]
221 public void TestDetachAttachmentToGround() 310 public void TestDetachAttachmentToGround()
222 { 311 {
223 TestHelpers.InMethod(); 312 TestHelpers.InMethod();
224// log4net.Config.XmlConfigurator.Configure(); 313// log4net.Config.XmlConfigurator.Configure();
225 314
226 Scene scene = CreateDefaultTestScene(); 315 Scene scene = CreateTestScene();
227 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); 316 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
228 ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID); 317 ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID);
229 318
@@ -253,9 +342,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
253 public void TestDetachAttachmentToInventory() 342 public void TestDetachAttachmentToInventory()
254 { 343 {
255 TestHelpers.InMethod(); 344 TestHelpers.InMethod();
256// log4net.Config.XmlConfigurator.Configure();
257 345
258 Scene scene = CreateDefaultTestScene(); 346 Scene scene = CreateTestScene();
259 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); 347 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
260 ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID); 348 ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID);
261 349
@@ -278,6 +366,45 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
278 } 366 }
279 367
280 /// <summary> 368 /// <summary>
369 /// Test specific conditions associated with detaching a scripted attachment from inventory.
370 /// </summary>
371 [Test]
372 public void TestDetachScriptedAttachmentToInventory()
373 {
374 TestHelpers.InMethod();
375// TestHelpers.EnableLogging();
376
377 Scene scene = CreateScriptingEnabledTestScene();
378 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
379 ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1);
380
381 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, sp.UUID, "att-name", 0x10);
382 TaskInventoryHelpers.AddScript(scene, so.RootPart);
383 InventoryItemBase userItem = UserInventoryHelpers.AddInventoryItem(scene, so, 0x100, 0x1000);
384
385 // FIXME: Right now, we have to do a tricksy chat listen to make sure we know when the script is running.
386 // In the future, we need to be able to do this programatically more predicably.
387 scene.EventManager.OnChatFromWorld += OnChatFromWorld;
388
389 SceneObjectGroup soRezzed
390 = (SceneObjectGroup)scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, userItem.ID, (uint)AttachmentPoint.Chest);
391
392 // Wait for chat to signal rezzed script has been started.
393 m_chatEvent.WaitOne(60000);
394
395 scene.AttachmentsModule.DetachSingleAttachmentToInv(sp, soRezzed);
396
397 InventoryItemBase userItemUpdated = scene.InventoryService.GetItem(userItem);
398 AssetBase asset = scene.AssetService.Get(userItemUpdated.AssetID.ToString());
399
400 XmlDocument soXml = new XmlDocument();
401 soXml.LoadXml(Encoding.UTF8.GetString(asset.Data));
402
403 XmlNodeList scriptStateNodes = soXml.GetElementsByTagName("ScriptState");
404 Assert.That(scriptStateNodes.Count, Is.EqualTo(1));
405 }
406
407 /// <summary>
281 /// Test that attachments don't hang about in the scene when the agent is closed 408 /// Test that attachments don't hang about in the scene when the agent is closed
282 /// </summary> 409 /// </summary>
283 [Test] 410 [Test]
@@ -286,7 +413,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
286 TestHelpers.InMethod(); 413 TestHelpers.InMethod();
287// log4net.Config.XmlConfigurator.Configure(); 414// log4net.Config.XmlConfigurator.Configure();
288 415
289 Scene scene = CreateDefaultTestScene(); 416 Scene scene = CreateTestScene();
290 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); 417 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
291 InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20); 418 InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20);
292 419
@@ -309,7 +436,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
309 TestHelpers.InMethod(); 436 TestHelpers.InMethod();
310// log4net.Config.XmlConfigurator.Configure(); 437// log4net.Config.XmlConfigurator.Configure();
311 438
312 Scene scene = CreateDefaultTestScene(); 439 Scene scene = CreateTestScene();
313 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); 440 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
314 InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20); 441 InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20);
315 442
@@ -345,7 +472,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
345 { 472 {
346 TestHelpers.InMethod(); 473 TestHelpers.InMethod();
347 474
348 Scene scene = CreateDefaultTestScene(); 475 Scene scene = CreateTestScene();
349 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1); 476 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
350 InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20); 477 InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20);
351 478