AttachmentsModuleTests.cs 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  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. using System;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using System.Text;
  31. using System.Threading;
  32. using System.Timers;
  33. using System.Xml;
  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.Servers;
  40. using OpenSim.Framework.Servers.HttpServer;
  41. using OpenSim.Region.CoreModules.Avatar.Attachments;
  42. using OpenSim.Region.CoreModules.Framework;
  43. using OpenSim.Region.CoreModules.Framework.EntityTransfer;
  44. using OpenSim.Region.CoreModules.Framework.InventoryAccess;
  45. using OpenSim.Region.CoreModules.Scripting.WorldComm;
  46. using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
  47. using OpenSim.Region.CoreModules.World.Serialiser;
  48. using OpenSim.Region.Framework.Scenes;
  49. using OpenSim.Region.Framework.Interfaces;
  50. using OpenSim.Region.ScriptEngine.Interfaces;
  51. using OpenSim.Region.ScriptEngine.XEngine;
  52. using OpenSim.Services.Interfaces;
  53. using OpenSim.Tests.Common;
  54. namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
  55. {
  56. /*
  57. /// <summary>
  58. /// Attachment tests
  59. /// </summary>
  60. [TestFixture]
  61. public class AttachmentsModuleTests : OpenSimTestCase
  62. {
  63. private AutoResetEvent m_chatEvent = new AutoResetEvent(false);
  64. // private OSChatMessage m_osChatMessageReceived;
  65. // Used to test whether the operations have fired the attach event. Must be reset after each test.
  66. private int m_numberOfAttachEventsFired;
  67. [TestFixtureSetUp]
  68. public void FixtureInit()
  69. {
  70. // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
  71. Util.FireAndForgetMethod = FireAndForgetMethod.None;
  72. }
  73. [TestFixtureTearDown]
  74. public void TearDown()
  75. {
  76. // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
  77. // threads. Possibly, later tests should be rewritten not to worry about such things.
  78. Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
  79. }
  80. private void OnChatFromWorld(object sender, OSChatMessage oscm)
  81. {
  82. // Console.WriteLine("Got chat [{0}]", oscm.Message);
  83. // m_osChatMessageReceived = oscm;
  84. m_chatEvent.Set();
  85. }
  86. private Scene CreateTestScene()
  87. {
  88. IConfigSource config = new IniConfigSource();
  89. List<object> modules = new List<object>();
  90. AddCommonConfig(config, modules);
  91. Scene scene
  92. = new SceneHelpers().SetupScene(
  93. "attachments-test-scene", TestHelpers.ParseTail(999), 1000, 1000, config);
  94. SceneHelpers.SetupSceneModules(scene, config, modules.ToArray());
  95. scene.EventManager.OnAttach += (localID, itemID, avatarID) => m_numberOfAttachEventsFired++;
  96. return scene;
  97. }
  98. private Scene CreateScriptingEnabledTestScene()
  99. {
  100. IConfigSource config = new IniConfigSource();
  101. List<object> modules = new List<object>();
  102. AddCommonConfig(config, modules);
  103. AddScriptingConfig(config, modules);
  104. Scene scene
  105. = new SceneHelpers().SetupScene(
  106. "attachments-test-scene", TestHelpers.ParseTail(999), 1000, 1000, config);
  107. SceneHelpers.SetupSceneModules(scene, config, modules.ToArray());
  108. scene.StartScripts();
  109. return scene;
  110. }
  111. private void AddCommonConfig(IConfigSource config, List<object> modules)
  112. {
  113. config.AddConfig("Modules");
  114. config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule");
  115. AttachmentsModule attMod = new AttachmentsModule();
  116. attMod.DebugLevel = 1;
  117. modules.Add(attMod);
  118. modules.Add(new BasicInventoryAccessModule());
  119. }
  120. private void AddScriptingConfig(IConfigSource config, List<object> modules)
  121. {
  122. IConfig startupConfig = config.AddConfig("Startup");
  123. startupConfig.Set("DefaultScriptEngine", "XEngine");
  124. IConfig xEngineConfig = config.AddConfig("XEngine");
  125. xEngineConfig.Set("Enabled", "true");
  126. xEngineConfig.Set("StartDelay", "0");
  127. // These tests will not run with AppDomainLoading = true, at least on mono. For unknown reasons, the call
  128. // to AssemblyResolver.OnAssemblyResolve fails.
  129. xEngineConfig.Set("AppDomainLoading", "false");
  130. modules.Add(new XEngine());
  131. // Necessary to stop serialization complaining
  132. // FIXME: Stop this being necessary if at all possible
  133. // modules.Add(new WorldCommModule());
  134. }
  135. /// <summary>
  136. /// Creates an attachment item in the given user's inventory. Does not attach.
  137. /// </summary>
  138. /// <remarks>
  139. /// A user with the given ID and an inventory must already exist.
  140. /// </remarks>
  141. /// <returns>
  142. /// The attachment item.
  143. /// </returns>
  144. /// <param name='scene'></param>
  145. /// <param name='userId'></param>
  146. /// <param name='attName'></param>
  147. /// <param name='rawItemId'></param>
  148. /// <param name='rawAssetId'></param>
  149. private InventoryItemBase CreateAttachmentItem(
  150. Scene scene, UUID userId, string attName, int rawItemId, int rawAssetId)
  151. {
  152. return UserInventoryHelpers.CreateInventoryItem(
  153. scene,
  154. attName,
  155. TestHelpers.ParseTail(rawItemId),
  156. TestHelpers.ParseTail(rawAssetId),
  157. userId,
  158. InventoryType.Object);
  159. }
  160. [Test]
  161. public void TestAddAttachmentFromGround()
  162. {
  163. TestHelpers.InMethod();
  164. // TestHelpers.EnableLogging();
  165. m_numberOfAttachEventsFired = 0;
  166. Scene scene = CreateTestScene();
  167. UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
  168. ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1);
  169. string attName = "att";
  170. SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, attName, sp.UUID);
  171. Assert.That(so.Backup, Is.True);
  172. m_numberOfAttachEventsFired = 0;
  173. scene.AttachmentsModule.AttachObject(sp, so, (uint)AttachmentPoint.Chest, false, true, false);
  174. // Check status on scene presence
  175. Assert.That(sp.HasAttachments(), Is.True);
  176. List<SceneObjectGroup> attachments = sp.GetAttachments();
  177. Assert.That(attachments.Count, Is.EqualTo(1));
  178. SceneObjectGroup attSo = attachments[0];
  179. Assert.That(attSo.Name, Is.EqualTo(attName));
  180. Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest));
  181. Assert.That(attSo.IsAttachment);
  182. Assert.That(attSo.UsesPhysics, Is.False);
  183. Assert.That(attSo.IsTemporary, Is.False);
  184. Assert.That(attSo.Backup, Is.False);
  185. // Check item status
  186. // Assert.That(
  187. // sp.Appearance.GetAttachpoint(attSo.FromItemID),
  188. // Is.EqualTo((int)AttachmentPoint.Chest));
  189. InventoryItemBase attachmentItem = scene.InventoryService.GetItem(sp.UUID, attSo.FromItemID);
  190. Assert.That(attachmentItem, Is.Not.Null);
  191. Assert.That(attachmentItem.Name, Is.EqualTo(attName));
  192. InventoryFolderBase targetFolder = scene.InventoryService.GetFolderForType(sp.UUID, FolderType.Object);
  193. Assert.That(attachmentItem.Folder, Is.EqualTo(targetFolder.ID));
  194. Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
  195. // Check events
  196. Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(1));
  197. }
  198. [Test]
  199. public void TestWearAttachmentFromGround()
  200. {
  201. TestHelpers.InMethod();
  202. // TestHelpers.EnableLogging();
  203. Scene scene = CreateTestScene();
  204. UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
  205. ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1);
  206. SceneObjectGroup so2 = SceneHelpers.AddSceneObject(scene, "att2", sp.UUID);
  207. {
  208. SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, "att1", sp.UUID);
  209. m_numberOfAttachEventsFired = 0;
  210. scene.AttachmentsModule.AttachObject(sp, so, (uint)AttachmentPoint.Default, false, true, false);
  211. // Check status on scene presence
  212. Assert.That(sp.HasAttachments(), Is.True);
  213. List<SceneObjectGroup> attachments = sp.GetAttachments();
  214. Assert.That(attachments.Count, Is.EqualTo(1));
  215. SceneObjectGroup attSo = attachments[0];
  216. Assert.That(attSo.Name, Is.EqualTo(so.Name));
  217. Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.LeftHand));
  218. Assert.That(attSo.IsAttachment);
  219. Assert.That(attSo.UsesPhysics, Is.False);
  220. Assert.That(attSo.IsTemporary, Is.False);
  221. // Check item status
  222. // Assert.That(
  223. // sp.Appearance.GetAttachpoint(attSo.FromItemID),
  224. // Is.EqualTo((int)AttachmentPoint.LeftHand));
  225. InventoryItemBase attachmentItem = scene.InventoryService.GetItem(sp.UUID, attSo.FromItemID);
  226. Assert.That(attachmentItem, Is.Not.Null);
  227. Assert.That(attachmentItem.Name, Is.EqualTo(so.Name));
  228. InventoryFolderBase targetFolder = scene.InventoryService.GetFolderForType(sp.UUID, FolderType.Object);
  229. Assert.That(attachmentItem.Folder, Is.EqualTo(targetFolder.ID));
  230. Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(2));
  231. // Check events
  232. Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(1));
  233. }
  234. // Test wearing a different attachment from the ground.
  235. {
  236. scene.AttachmentsModule.AttachObject(sp, so2, (uint)AttachmentPoint.Default, false, true, false);
  237. // Check status on scene presence
  238. Assert.That(sp.HasAttachments(), Is.True);
  239. List<SceneObjectGroup> attachments = sp.GetAttachments();
  240. Assert.That(attachments.Count, Is.EqualTo(1));
  241. SceneObjectGroup attSo = attachments[0];
  242. Assert.That(attSo.Name, Is.EqualTo(so2.Name));
  243. Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.LeftHand));
  244. Assert.That(attSo.IsAttachment);
  245. Assert.That(attSo.UsesPhysics, Is.False);
  246. Assert.That(attSo.IsTemporary, Is.False);
  247. // Check item status
  248. // Assert.That(
  249. // sp.Appearance.GetAttachpoint(attSo.FromItemID),
  250. // Is.EqualTo((int)AttachmentPoint.LeftHand));
  251. InventoryItemBase attachmentItem = scene.InventoryService.GetItem(sp.UUID, attSo.FromItemID);
  252. Assert.That(attachmentItem, Is.Not.Null);
  253. Assert.That(attachmentItem.Name, Is.EqualTo(so2.Name));
  254. InventoryFolderBase targetFolder = scene.InventoryService.GetFolderForType(sp.UUID, FolderType.Object);
  255. Assert.That(attachmentItem.Folder, Is.EqualTo(targetFolder.ID));
  256. Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
  257. // Check events
  258. Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(3));
  259. }
  260. // Test rewearing an already worn attachment from ground. Nothing should happen.
  261. {
  262. scene.AttachmentsModule.AttachObject(sp, so2, (uint)AttachmentPoint.Default, false, true, false);
  263. // Check status on scene presence
  264. Assert.That(sp.HasAttachments(), Is.True);
  265. List<SceneObjectGroup> attachments = sp.GetAttachments();
  266. Assert.That(attachments.Count, Is.EqualTo(1));
  267. SceneObjectGroup attSo = attachments[0];
  268. Assert.That(attSo.Name, Is.EqualTo(so2.Name));
  269. Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.LeftHand));
  270. Assert.That(attSo.IsAttachment);
  271. Assert.That(attSo.UsesPhysics, Is.False);
  272. Assert.That(attSo.IsTemporary, Is.False);
  273. // Check item status
  274. // Assert.That(
  275. // sp.Appearance.GetAttachpoint(attSo.FromItemID),
  276. // Is.EqualTo((int)AttachmentPoint.LeftHand));
  277. InventoryItemBase attachmentItem = scene.InventoryService.GetItem(sp.UUID, attSo.FromItemID);
  278. Assert.That(attachmentItem, Is.Not.Null);
  279. Assert.That(attachmentItem.Name, Is.EqualTo(so2.Name));
  280. InventoryFolderBase targetFolder = scene.InventoryService.GetFolderForType(sp.UUID, FolderType.Object);
  281. Assert.That(attachmentItem.Folder, Is.EqualTo(targetFolder.ID));
  282. Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
  283. // Check events
  284. Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(3));
  285. }
  286. }
  287. /// <summary>
  288. /// Test that we do not attempt to attach an in-world object that someone else is sitting on.
  289. /// </summary>
  290. [Test]
  291. public void TestAddSatOnAttachmentFromGround()
  292. {
  293. TestHelpers.InMethod();
  294. // TestHelpers.EnableLogging();
  295. m_numberOfAttachEventsFired = 0;
  296. Scene scene = CreateTestScene();
  297. UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
  298. ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1);
  299. string attName = "att";
  300. SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, attName, sp.UUID);
  301. UserAccount ua2 = UserAccountHelpers.CreateUserWithInventory(scene, 0x2);
  302. ScenePresence sp2 = SceneHelpers.AddScenePresence(scene, ua2);
  303. // Put avatar within 10m of the prim so that sit doesn't fail.
  304. sp2.AbsolutePosition = new Vector3(0, 0, 0);
  305. sp2.HandleAgentRequestSit(sp2.ControllingClient, sp2.UUID, so.UUID, Vector3.Zero);
  306. scene.AttachmentsModule.AttachObject(sp, so, (uint)AttachmentPoint.Chest, false, true, false);
  307. Assert.That(sp.HasAttachments(), Is.False);
  308. Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
  309. // Check events
  310. Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(0));
  311. }
  312. [Test]
  313. public void TestRezAttachmentFromInventory()
  314. {
  315. TestHelpers.InMethod();
  316. // TestHelpers.EnableLogging();
  317. Scene scene = CreateTestScene();
  318. UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
  319. ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID);
  320. InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20);
  321. {
  322. scene.AttachmentsModule.RezSingleAttachmentFromInventory(
  323. sp, attItem.ID, (uint)AttachmentPoint.Chest);
  324. // Check scene presence status
  325. Assert.That(sp.HasAttachments(), Is.True);
  326. List<SceneObjectGroup> attachments = sp.GetAttachments();
  327. Assert.That(attachments.Count, Is.EqualTo(1));
  328. SceneObjectGroup attSo = attachments[0];
  329. Assert.That(attSo.Name, Is.EqualTo(attItem.Name));
  330. Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest));
  331. Assert.That(attSo.IsAttachment);
  332. Assert.That(attSo.UsesPhysics, Is.False);
  333. Assert.That(attSo.IsTemporary, Is.False);
  334. Assert.IsFalse(attSo.Backup);
  335. // Check appearance status
  336. // Assert.That(sp.Appearance.GetAttachments().Count, Is.EqualTo(1));
  337. // Assert.That(sp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest));
  338. Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
  339. // Check events
  340. Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(1));
  341. }
  342. // Test attaching an already attached attachment
  343. {
  344. scene.AttachmentsModule.RezSingleAttachmentFromInventory(
  345. sp, attItem.ID, (uint)AttachmentPoint.Chest);
  346. // Check scene presence status
  347. Assert.That(sp.HasAttachments(), Is.True);
  348. List<SceneObjectGroup> attachments = sp.GetAttachments();
  349. Assert.That(attachments.Count, Is.EqualTo(1));
  350. SceneObjectGroup attSo = attachments[0];
  351. Assert.That(attSo.Name, Is.EqualTo(attItem.Name));
  352. Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest));
  353. Assert.That(attSo.IsAttachment);
  354. Assert.That(attSo.UsesPhysics, Is.False);
  355. Assert.That(attSo.IsTemporary, Is.False);
  356. // Check appearance status
  357. // Assert.That(sp.Appearance.GetAttachments().Count, Is.EqualTo(1));
  358. // Assert.That(sp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest));
  359. Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
  360. // Check events
  361. Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(1));
  362. }
  363. }
  364. /// <summary>
  365. /// Test wearing an attachment from inventory, as opposed to explicit choosing the rez point
  366. /// </summary>
  367. [Test]
  368. public void TestWearAttachmentFromInventory()
  369. {
  370. TestHelpers.InMethod();
  371. // TestHelpers.EnableLogging();
  372. Scene scene = CreateTestScene();
  373. UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
  374. ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID);
  375. InventoryItemBase attItem1 = CreateAttachmentItem(scene, ua1.PrincipalID, "att1", 0x10, 0x20);
  376. InventoryItemBase attItem2 = CreateAttachmentItem(scene, ua1.PrincipalID, "att2", 0x11, 0x21);
  377. {
  378. m_numberOfAttachEventsFired = 0;
  379. scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, attItem1.ID, (uint)AttachmentPoint.Default);
  380. // default attachment point is currently the left hand.
  381. Assert.That(sp.HasAttachments(), Is.True);
  382. List<SceneObjectGroup> attachments = sp.GetAttachments();
  383. Assert.That(attachments.Count, Is.EqualTo(1));
  384. SceneObjectGroup attSo = attachments[0];
  385. Assert.That(attSo.Name, Is.EqualTo(attItem1.Name));
  386. Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.LeftHand));
  387. Assert.That(attSo.IsAttachment);
  388. // Check appearance status
  389. // Assert.That(sp.Appearance.GetAttachments().Count, Is.EqualTo(1));
  390. // Assert.That(sp.Appearance.GetAttachpoint(attItem1.ID), Is.EqualTo((int)AttachmentPoint.LeftHand));
  391. Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
  392. // Check events
  393. Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(1));
  394. }
  395. // Test wearing a second attachment at the same position
  396. // Until multiple attachments at one point is implemented, this will remove the first attachment
  397. // This test relies on both attachments having the same default attachment point (in this case LeftHand
  398. // since none other has been set).
  399. {
  400. scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, attItem2.ID, (uint)AttachmentPoint.Default);
  401. // default attachment point is currently the left hand.
  402. Assert.That(sp.HasAttachments(), Is.True);
  403. List<SceneObjectGroup> attachments = sp.GetAttachments();
  404. Assert.That(attachments.Count, Is.EqualTo(1));
  405. SceneObjectGroup attSo = attachments[0];
  406. Assert.That(attSo.Name, Is.EqualTo(attItem2.Name));
  407. Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.LeftHand));
  408. Assert.That(attSo.IsAttachment);
  409. // Check appearance status
  410. // Assert.That(sp.Appearance.GetAttachments().Count, Is.EqualTo(1));
  411. // Assert.That(sp.Appearance.GetAttachpoint(attItem2.ID), Is.EqualTo((int)AttachmentPoint.LeftHand));
  412. Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
  413. // Check events
  414. Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(3));
  415. }
  416. // Test wearing an already attached attachment
  417. {
  418. scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, attItem2.ID, (uint)AttachmentPoint.Default);
  419. // default attachment point is currently the left hand.
  420. Assert.That(sp.HasAttachments(), Is.True);
  421. List<SceneObjectGroup> attachments = sp.GetAttachments();
  422. Assert.That(attachments.Count, Is.EqualTo(1));
  423. SceneObjectGroup attSo = attachments[0];
  424. Assert.That(attSo.Name, Is.EqualTo(attItem2.Name));
  425. Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.LeftHand));
  426. Assert.That(attSo.IsAttachment);
  427. // Check appearance status
  428. // Assert.That(sp.Appearance.GetAttachments().Count, Is.EqualTo(1));
  429. // Assert.That(sp.Appearance.GetAttachpoint(attItem2.ID), Is.EqualTo((int)AttachmentPoint.LeftHand));
  430. Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
  431. // Check events
  432. Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(3));
  433. }
  434. }
  435. /// <summary>
  436. /// Test specific conditions associated with rezzing a scripted attachment from inventory.
  437. /// </summary>
  438. [Test]
  439. public void TestRezScriptedAttachmentFromInventory()
  440. {
  441. TestHelpers.InMethod();
  442. Scene scene = CreateScriptingEnabledTestScene();
  443. UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
  444. ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1);
  445. SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, sp.UUID, "att-name", 0x10);
  446. TaskInventoryItem scriptItem
  447. = TaskInventoryHelpers.AddScript(
  448. scene.AssetService,
  449. so.RootPart,
  450. "scriptItem",
  451. "default { attach(key id) { if (id != NULL_KEY) { llSay(0, \"Hello World\"); } } }");
  452. InventoryItemBase userItem = UserInventoryHelpers.AddInventoryItem(scene, so, 0x100, 0x1000);
  453. // FIXME: Right now, we have to do a tricksy chat listen to make sure we know when the script is running.
  454. // In the future, we need to be able to do this programatically more predicably.
  455. scene.EventManager.OnChatFromWorld += OnChatFromWorld;
  456. m_chatEvent.Reset();
  457. scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, userItem.ID, (uint)AttachmentPoint.Chest);
  458. m_chatEvent.WaitOne(60000);
  459. // TODO: Need to have a test that checks the script is actually started but this involves a lot more
  460. // plumbing of the script engine and either pausing for events or more infrastructure to turn off various
  461. // script engine delays/asychronicity that isn't helpful in an automated regression testing context.
  462. SceneObjectGroup attSo = scene.GetSceneObjectGroup(so.Name);
  463. Assert.That(attSo.ContainsScripts(), Is.True);
  464. TaskInventoryItem reRezzedScriptItem = attSo.RootPart.Inventory.GetInventoryItem(scriptItem.Name);
  465. IScriptModule xengine = scene.RequestModuleInterface<IScriptModule>();
  466. Assert.That(xengine.GetScriptState(reRezzedScriptItem.ItemID), Is.True);
  467. }
  468. [Test]
  469. public void TestDetachAttachmentToGround()
  470. {
  471. TestHelpers.InMethod();
  472. // log4net.Config.XmlConfigurator.Configure();
  473. Scene scene = CreateTestScene();
  474. UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
  475. ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID);
  476. InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20);
  477. ISceneEntity so
  478. = scene.AttachmentsModule.RezSingleAttachmentFromInventory(
  479. sp, attItem.ID, (uint)AttachmentPoint.Chest);
  480. m_numberOfAttachEventsFired = 0;
  481. scene.AttachmentsModule.DetachSingleAttachmentToGround(sp, so.LocalId);
  482. // Check scene presence status
  483. Assert.That(sp.HasAttachments(), Is.False);
  484. List<SceneObjectGroup> attachments = sp.GetAttachments();
  485. Assert.That(attachments.Count, Is.EqualTo(0));
  486. // Check appearance status
  487. // Assert.That(sp.Appearance.GetAttachments().Count, Is.EqualTo(0));
  488. // Check item status
  489. Assert.That(scene.InventoryService.GetItem(sp.UUID, attItem.ID), Is.Null);
  490. // Check object in scene
  491. SceneObjectGroup soInScene = scene.GetSceneObjectGroup("att");
  492. Assert.That(soInScene, Is.Not.Null);
  493. Assert.IsTrue(soInScene.Backup);
  494. // Check events
  495. Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(1));
  496. }
  497. [Test]
  498. public void TestDetachAttachmentToInventory()
  499. {
  500. TestHelpers.InMethod();
  501. Scene scene = CreateTestScene();
  502. UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
  503. ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1.PrincipalID);
  504. InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20);
  505. SceneObjectGroup so
  506. = (SceneObjectGroup)scene.AttachmentsModule.RezSingleAttachmentFromInventory(
  507. sp, attItem.ID, (uint)AttachmentPoint.Chest);
  508. m_numberOfAttachEventsFired = 0;
  509. scene.AttachmentsModule.DetachSingleAttachmentToInv(sp, so);
  510. // Check status on scene presence
  511. Assert.That(sp.HasAttachments(), Is.False);
  512. List<SceneObjectGroup> attachments = sp.GetAttachments();
  513. Assert.That(attachments.Count, Is.EqualTo(0));
  514. // Check item status
  515. // Assert.That(sp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo(0));
  516. Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(0));
  517. // Check events
  518. Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(1));
  519. }
  520. /// <summary>
  521. /// Test specific conditions associated with detaching a scripted attachment from inventory.
  522. /// </summary>
  523. [Test]
  524. public void TestDetachScriptedAttachmentToInventory()
  525. {
  526. TestHelpers.InMethod();
  527. // TestHelpers.EnableLogging();
  528. Scene scene = CreateScriptingEnabledTestScene();
  529. UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
  530. ScenePresence sp = SceneHelpers.AddScenePresence(scene, ua1);
  531. SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, sp.UUID, "att-name", 0x10);
  532. TaskInventoryItem scriptTaskItem
  533. = TaskInventoryHelpers.AddScript(
  534. scene.AssetService,
  535. so.RootPart,
  536. "scriptItem",
  537. "default { attach(key id) { if (id != NULL_KEY) { llSay(0, \"Hello World\"); } } }");
  538. InventoryItemBase userItem = UserInventoryHelpers.AddInventoryItem(scene, so, 0x100, 0x1000);
  539. // FIXME: Right now, we have to do a tricksy chat listen to make sure we know when the script is running.
  540. // In the future, we need to be able to do this programatically more predicably.
  541. scene.EventManager.OnChatFromWorld += OnChatFromWorld;
  542. m_chatEvent.Reset();
  543. SceneObjectGroup rezzedSo
  544. = (SceneObjectGroup)(scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, userItem.ID, (uint)AttachmentPoint.Chest));
  545. // Wait for chat to signal rezzed script has been started.
  546. m_chatEvent.WaitOne(60000);
  547. scene.AttachmentsModule.DetachSingleAttachmentToInv(sp, rezzedSo);
  548. InventoryItemBase userItemUpdated = scene.InventoryService.GetItem(userItem.Owner, userItem.ID);
  549. AssetBase asset = scene.AssetService.Get(userItemUpdated.AssetID.ToString());
  550. // TODO: It would probably be better here to check script state via the saving and retrieval of state
  551. // information at a higher level, rather than having to inspect the serialization.
  552. XmlDocument soXml = new XmlDocument();
  553. soXml.LoadXml(Encoding.UTF8.GetString(asset.Data));
  554. XmlNodeList scriptStateNodes = soXml.GetElementsByTagName("ScriptState");
  555. Assert.That(scriptStateNodes.Count, Is.EqualTo(1));
  556. // Re-rez the attachment to check script running state
  557. SceneObjectGroup reRezzedSo = (SceneObjectGroup)(scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, userItem.ID, (uint)AttachmentPoint.Chest));
  558. // Wait for chat to signal rezzed script has been started.
  559. m_chatEvent.WaitOne(60000);
  560. TaskInventoryItem reRezzedScriptItem = reRezzedSo.RootPart.Inventory.GetInventoryItem(scriptTaskItem.Name);
  561. IScriptModule xengine = scene.RequestModuleInterface<IScriptModule>();
  562. Assert.That(xengine.GetScriptState(reRezzedScriptItem.ItemID), Is.True);
  563. // Console.WriteLine(soXml.OuterXml);
  564. }
  565. /// <summary>
  566. /// Test that attachments don't hang about in the scene when the agent is closed
  567. /// </summary>
  568. [Test]
  569. public void TestRemoveAttachmentsOnAvatarExit()
  570. {
  571. TestHelpers.InMethod();
  572. // log4net.Config.XmlConfigurator.Configure();
  573. Scene scene = CreateTestScene();
  574. UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
  575. InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20);
  576. AgentCircuitData acd = SceneHelpers.GenerateAgentData(ua1.PrincipalID);
  577. acd.Appearance = new AvatarAppearance();
  578. acd.Appearance.SetAttachment((int)AttachmentPoint.Chest, attItem.ID, attItem.AssetID);
  579. ScenePresence presence = SceneHelpers.AddScenePresence(scene, acd);
  580. UUID rezzedAttID = presence.GetAttachments()[0].UUID;
  581. m_numberOfAttachEventsFired = 0;
  582. scene.CloseAgent(presence.UUID, false);
  583. // Check that we can't retrieve this attachment from the scene.
  584. Assert.That(scene.GetSceneObjectGroup(rezzedAttID), Is.Null);
  585. // Check events
  586. Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(0));
  587. }
  588. [Test]
  589. public void TestRezAttachmentsOnAvatarEntrance()
  590. {
  591. TestHelpers.InMethod();
  592. // TestHelpers.EnableLogging();
  593. Scene scene = CreateTestScene();
  594. UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
  595. InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20);
  596. AgentCircuitData acd = SceneHelpers.GenerateAgentData(ua1.PrincipalID);
  597. acd.Appearance = new AvatarAppearance();
  598. acd.Appearance.SetAttachment((int)AttachmentPoint.Chest, attItem.ID, attItem.AssetID);
  599. m_numberOfAttachEventsFired = 0;
  600. ScenePresence presence = SceneHelpers.AddScenePresence(scene, acd);
  601. Assert.That(presence.HasAttachments(), Is.True);
  602. List<SceneObjectGroup> attachments = presence.GetAttachments();
  603. Assert.That(attachments.Count, Is.EqualTo(1));
  604. SceneObjectGroup attSo = attachments[0];
  605. Assert.That(attSo.Name, Is.EqualTo(attItem.Name));
  606. Assert.That(attSo.AttachmentPoint, Is.EqualTo((byte)AttachmentPoint.Chest));
  607. Assert.That(attSo.IsAttachment);
  608. Assert.That(attSo.UsesPhysics, Is.False);
  609. Assert.That(attSo.IsTemporary, Is.False);
  610. Assert.IsFalse(attSo.Backup);
  611. // Check appearance status
  612. List<AvatarAttachment> retreivedAttachments = presence.Appearance.GetAttachments();
  613. Assert.That(retreivedAttachments.Count, Is.EqualTo(1));
  614. Assert.That(retreivedAttachments[0].AttachPoint, Is.EqualTo((int)AttachmentPoint.Chest));
  615. Assert.That(retreivedAttachments[0].ItemID, Is.EqualTo(attItem.ID));
  616. Assert.That(retreivedAttachments[0].AssetID, Is.EqualTo(attItem.AssetID));
  617. Assert.That(presence.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest));
  618. Assert.That(scene.GetSceneObjectGroups().Count, Is.EqualTo(1));
  619. // Check events. We expect OnAttach to fire on login.
  620. Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(1));
  621. }
  622. [Test]
  623. public void TestUpdateAttachmentPosition()
  624. {
  625. TestHelpers.InMethod();
  626. Scene scene = CreateTestScene();
  627. UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
  628. InventoryItemBase attItem = CreateAttachmentItem(scene, ua1.PrincipalID, "att", 0x10, 0x20);
  629. AgentCircuitData acd = SceneHelpers.GenerateAgentData(ua1.PrincipalID);
  630. acd.Appearance = new AvatarAppearance();
  631. acd.Appearance.SetAttachment((int)AttachmentPoint.Chest, attItem.ID, attItem.AssetID);
  632. ScenePresence sp = SceneHelpers.AddScenePresence(scene, acd);
  633. SceneObjectGroup attSo = sp.GetAttachments()[0];
  634. Vector3 newPosition = new Vector3(1, 2, 4);
  635. m_numberOfAttachEventsFired = 0;
  636. scene.SceneGraph.UpdatePrimGroupPosition(attSo.LocalId, newPosition, sp.ControllingClient);
  637. Assert.That(attSo.AbsolutePosition, Is.EqualTo(sp.AbsolutePosition));
  638. Assert.That(attSo.RootPart.AttachedPos, Is.EqualTo(newPosition));
  639. // Check events
  640. Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(0));
  641. }
  642. [Test]
  643. public void TestSameSimulatorNeighbouringRegionsTeleportV1()
  644. {
  645. TestHelpers.InMethod();
  646. // TestHelpers.EnableLogging();
  647. BaseHttpServer httpServer = new BaseHttpServer(99999);
  648. MainServer.AddHttpServer(httpServer);
  649. MainServer.Instance = httpServer;
  650. AttachmentsModule attModA = new AttachmentsModule();
  651. AttachmentsModule attModB = new AttachmentsModule();
  652. EntityTransferModule etmA = new EntityTransferModule();
  653. EntityTransferModule etmB = new EntityTransferModule();
  654. LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
  655. IConfigSource config = new IniConfigSource();
  656. IConfig modulesConfig = config.AddConfig("Modules");
  657. modulesConfig.Set("EntityTransferModule", etmA.Name);
  658. modulesConfig.Set("SimulationServices", lscm.Name);
  659. IConfig entityTransferConfig = config.AddConfig("EntityTransfer");
  660. // In order to run a single threaded regression test we do not want the entity transfer module waiting
  661. // for a callback from the destination scene before removing its avatar data.
  662. entityTransferConfig.Set("wait_for_callback", false);
  663. modulesConfig.Set("InventoryAccessModule", "BasicInventoryAccessModule");
  664. SceneHelpers sh = new SceneHelpers();
  665. TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
  666. TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1001, 1000);
  667. SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
  668. SceneHelpers.SetupSceneModules(
  669. sceneA, config, new CapabilitiesModule(), etmA, attModA, new BasicInventoryAccessModule());
  670. SceneHelpers.SetupSceneModules(
  671. sceneB, config, new CapabilitiesModule(), etmB, attModB, new BasicInventoryAccessModule());
  672. // FIXME: Hack - this is here temporarily to revert back to older entity transfer behaviour
  673. //lscm.ServiceVersion = 0.1f;
  674. UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(sceneA, 0x1);
  675. AgentCircuitData acd = SceneHelpers.GenerateAgentData(ua1.PrincipalID);
  676. TestClient tc = new TestClient(acd, sceneA);
  677. List<TestClient> destinationTestClients = new List<TestClient>();
  678. EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients);
  679. ScenePresence beforeTeleportSp = SceneHelpers.AddScenePresence(sceneA, tc, acd);
  680. beforeTeleportSp.AbsolutePosition = new Vector3(30, 31, 32);
  681. InventoryItemBase attItem = CreateAttachmentItem(sceneA, ua1.PrincipalID, "att", 0x10, 0x20);
  682. sceneA.AttachmentsModule.RezSingleAttachmentFromInventory(
  683. beforeTeleportSp, attItem.ID, (uint)AttachmentPoint.Chest);
  684. Vector3 teleportPosition = new Vector3(10, 11, 12);
  685. Vector3 teleportLookAt = new Vector3(20, 21, 22);
  686. m_numberOfAttachEventsFired = 0;
  687. sceneA.RequestTeleportLocation(
  688. beforeTeleportSp.ControllingClient,
  689. sceneB.RegionInfo.RegionHandle,
  690. teleportPosition,
  691. teleportLookAt,
  692. (uint)TeleportFlags.ViaLocation);
  693. destinationTestClients[0].CompleteMovement();
  694. // Check attachments have made it into sceneB
  695. ScenePresence afterTeleportSceneBSp = sceneB.GetScenePresence(ua1.PrincipalID);
  696. // This is appearance data, as opposed to actually rezzed attachments
  697. List<AvatarAttachment> sceneBAttachments = afterTeleportSceneBSp.Appearance.GetAttachments();
  698. Assert.That(sceneBAttachments.Count, Is.EqualTo(1));
  699. Assert.That(sceneBAttachments[0].AttachPoint, Is.EqualTo((int)AttachmentPoint.Chest));
  700. Assert.That(sceneBAttachments[0].ItemID, Is.EqualTo(attItem.ID));
  701. Assert.That(sceneBAttachments[0].AssetID, Is.EqualTo(attItem.AssetID));
  702. Assert.That(afterTeleportSceneBSp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest));
  703. // This is the actual attachment
  704. List<SceneObjectGroup> actualSceneBAttachments = afterTeleportSceneBSp.GetAttachments();
  705. Assert.That(actualSceneBAttachments.Count, Is.EqualTo(1));
  706. SceneObjectGroup actualSceneBAtt = actualSceneBAttachments[0];
  707. Assert.That(actualSceneBAtt.Name, Is.EqualTo(attItem.Name));
  708. Assert.That(actualSceneBAtt.AttachmentPoint, Is.EqualTo((uint)AttachmentPoint.Chest));
  709. Assert.IsFalse(actualSceneBAtt.Backup);
  710. Assert.That(sceneB.GetSceneObjectGroups().Count, Is.EqualTo(1));
  711. // Check attachments have been removed from sceneA
  712. ScenePresence afterTeleportSceneASp = sceneA.GetScenePresence(ua1.PrincipalID);
  713. // Since this is appearance data, it is still present on the child avatar!
  714. List<AvatarAttachment> sceneAAttachments = afterTeleportSceneASp.Appearance.GetAttachments();
  715. Assert.That(sceneAAttachments.Count, Is.EqualTo(1));
  716. Assert.That(afterTeleportSceneASp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest));
  717. // This is the actual attachment, which should no longer exist
  718. List<SceneObjectGroup> actualSceneAAttachments = afterTeleportSceneASp.GetAttachments();
  719. Assert.That(actualSceneAAttachments.Count, Is.EqualTo(0));
  720. Assert.That(sceneA.GetSceneObjectGroups().Count, Is.EqualTo(0));
  721. // Check events
  722. Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(0));
  723. }
  724. [Test]
  725. public void TestSameSimulatorNeighbouringRegionsTeleportV2()
  726. {
  727. TestHelpers.InMethod();
  728. // TestHelpers.EnableLogging();
  729. BaseHttpServer httpServer = new BaseHttpServer(99999);
  730. MainServer.AddHttpServer(httpServer);
  731. MainServer.Instance = httpServer;
  732. AttachmentsModule attModA = new AttachmentsModule();
  733. AttachmentsModule attModB = new AttachmentsModule();
  734. EntityTransferModule etmA = new EntityTransferModule();
  735. EntityTransferModule etmB = new EntityTransferModule();
  736. LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
  737. IConfigSource config = new IniConfigSource();
  738. IConfig modulesConfig = config.AddConfig("Modules");
  739. modulesConfig.Set("EntityTransferModule", etmA.Name);
  740. modulesConfig.Set("SimulationServices", lscm.Name);
  741. modulesConfig.Set("InventoryAccessModule", "BasicInventoryAccessModule");
  742. SceneHelpers sh = new SceneHelpers();
  743. TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
  744. TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1001, 1000);
  745. SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
  746. SceneHelpers.SetupSceneModules(
  747. sceneA, config, new CapabilitiesModule(), etmA, attModA, new BasicInventoryAccessModule());
  748. SceneHelpers.SetupSceneModules(
  749. sceneB, config, new CapabilitiesModule(), etmB, attModB, new BasicInventoryAccessModule());
  750. UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(sceneA, 0x1);
  751. AgentCircuitData acd = SceneHelpers.GenerateAgentData(ua1.PrincipalID);
  752. TestClient tc = new TestClient(acd, sceneA);
  753. List<TestClient> destinationTestClients = new List<TestClient>();
  754. EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients);
  755. ScenePresence beforeTeleportSp = SceneHelpers.AddScenePresence(sceneA, tc, acd);
  756. beforeTeleportSp.AbsolutePosition = new Vector3(30, 31, 32);
  757. Assert.That(destinationTestClients.Count, Is.EqualTo(1));
  758. Assert.That(destinationTestClients[0], Is.Not.Null);
  759. InventoryItemBase attItem = CreateAttachmentItem(sceneA, ua1.PrincipalID, "att", 0x10, 0x20);
  760. sceneA.AttachmentsModule.RezSingleAttachmentFromInventory(
  761. beforeTeleportSp, attItem.ID, (uint)AttachmentPoint.Chest);
  762. Vector3 teleportPosition = new Vector3(10, 11, 12);
  763. Vector3 teleportLookAt = new Vector3(20, 21, 22);
  764. // Here, we need to make clientA's receipt of SendRegionTeleport trigger clientB's CompleteMovement(). This
  765. // is to operate the teleport V2 mechanism where the EntityTransferModule will first request the client to
  766. // CompleteMovement to the region and then call UpdateAgent to the destination region to confirm the receipt
  767. // Both these operations will occur on different threads and will wait for each other.
  768. // We have to do this via ThreadPool directly since FireAndForget has been switched to sync for the V1
  769. // test protocol, where we are trying to avoid unpredictable async operations in regression tests.
  770. tc.OnTestClientSendRegionTeleport
  771. += (regionHandle, simAccess, regionExternalEndPoint, locationID, flags, capsURL)
  772. => ThreadPool.UnsafeQueueUserWorkItem(o => destinationTestClients[0].CompleteMovement(), null);
  773. m_numberOfAttachEventsFired = 0;
  774. sceneA.RequestTeleportLocation(
  775. beforeTeleportSp.ControllingClient,
  776. sceneB.RegionInfo.RegionHandle,
  777. teleportPosition,
  778. teleportLookAt,
  779. (uint)TeleportFlags.ViaLocation);
  780. // Check attachments have made it into sceneB
  781. ScenePresence afterTeleportSceneBSp = sceneB.GetScenePresence(ua1.PrincipalID);
  782. // This is appearance data, as opposed to actually rezzed attachments
  783. List<AvatarAttachment> sceneBAttachments = afterTeleportSceneBSp.Appearance.GetAttachments();
  784. Assert.That(sceneBAttachments.Count, Is.EqualTo(1));
  785. Assert.That(sceneBAttachments[0].AttachPoint, Is.EqualTo((int)AttachmentPoint.Chest));
  786. Assert.That(sceneBAttachments[0].ItemID, Is.EqualTo(attItem.ID));
  787. Assert.That(sceneBAttachments[0].AssetID, Is.EqualTo(attItem.AssetID));
  788. Assert.That(afterTeleportSceneBSp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest));
  789. // This is the actual attachment
  790. List<SceneObjectGroup> actualSceneBAttachments = afterTeleportSceneBSp.GetAttachments();
  791. Assert.That(actualSceneBAttachments.Count, Is.EqualTo(1));
  792. SceneObjectGroup actualSceneBAtt = actualSceneBAttachments[0];
  793. Assert.That(actualSceneBAtt.Name, Is.EqualTo(attItem.Name));
  794. Assert.That(actualSceneBAtt.AttachmentPoint, Is.EqualTo((uint)AttachmentPoint.Chest));
  795. Assert.IsFalse(actualSceneBAtt.Backup);
  796. Assert.That(sceneB.GetSceneObjectGroups().Count, Is.EqualTo(1));
  797. // Check attachments have been removed from sceneA
  798. ScenePresence afterTeleportSceneASp = sceneA.GetScenePresence(ua1.PrincipalID);
  799. // Since this is appearance data, it is still present on the child avatar!
  800. List<AvatarAttachment> sceneAAttachments = afterTeleportSceneASp.Appearance.GetAttachments();
  801. Assert.That(sceneAAttachments.Count, Is.EqualTo(1));
  802. Assert.That(afterTeleportSceneASp.Appearance.GetAttachpoint(attItem.ID), Is.EqualTo((int)AttachmentPoint.Chest));
  803. // This is the actual attachment, which should no longer exist
  804. List<SceneObjectGroup> actualSceneAAttachments = afterTeleportSceneASp.GetAttachments();
  805. Assert.That(actualSceneAAttachments.Count, Is.EqualTo(0));
  806. Assert.That(sceneA.GetSceneObjectGroups().Count, Is.EqualTo(0));
  807. // Check events
  808. Assert.That(m_numberOfAttachEventsFired, Is.EqualTo(0));
  809. }
  810. }
  811. */
  812. }