1
0

ScenePresenceTeleportTests.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  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.IO;
  30. using System.Net;
  31. using System.Text;
  32. using System.Threading;
  33. using Nini.Config;
  34. using NUnit.Framework;
  35. using OpenMetaverse;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Servers;
  38. using OpenSim.Region.Framework.Interfaces;
  39. using OpenSim.Region.CoreModules.Framework;
  40. using OpenSim.Region.CoreModules.Framework.EntityTransfer;
  41. using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
  42. using OpenSim.Region.CoreModules.World.Permissions;
  43. using OpenSim.Tests.Common;
  44. namespace OpenSim.Region.Framework.Scenes.Tests
  45. {
  46. /// <summary>
  47. /// Teleport tests in a standalone OpenSim
  48. /// </summary>
  49. [TestFixture]
  50. public class ScenePresenceTeleportTests : OpenSimTestCase
  51. {
  52. [TestFixtureSetUp]
  53. public void FixtureInit()
  54. {
  55. // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
  56. Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
  57. }
  58. [TestFixtureTearDown]
  59. public void TearDown()
  60. {
  61. // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
  62. // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
  63. // tests really shouldn't).
  64. Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
  65. }
  66. [Test]
  67. public void TestSameRegion()
  68. {
  69. TestHelpers.InMethod();
  70. // log4net.Config.XmlConfigurator.Configure();
  71. EntityTransferModule etm = new EntityTransferModule();
  72. IConfigSource config = new IniConfigSource();
  73. config.AddConfig("Modules");
  74. // Not strictly necessary since FriendsModule assumes it is the default (!)
  75. config.Configs["Modules"].Set("EntityTransferModule", etm.Name);
  76. TestScene scene = new SceneHelpers().SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
  77. SceneHelpers.SetupSceneModules(scene, config, etm);
  78. Vector3 teleportPosition = new Vector3(10, 11, 12);
  79. Vector3 teleportLookAt = new Vector3(20, 21, 22);
  80. ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
  81. sp.AbsolutePosition = new Vector3(30, 31, 32);
  82. scene.RequestTeleportLocation(
  83. sp.ControllingClient,
  84. scene.RegionInfo.RegionHandle,
  85. teleportPosition,
  86. teleportLookAt,
  87. (uint)TeleportFlags.ViaLocation);
  88. Assert.That(sp.AbsolutePosition, Is.EqualTo(teleportPosition));
  89. Assert.That(scene.GetRootAgentCount(), Is.EqualTo(1));
  90. Assert.That(scene.GetChildAgentCount(), Is.EqualTo(0));
  91. // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera
  92. // position instead).
  93. // Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt));
  94. }
  95. /*
  96. [Test]
  97. public void TestSameSimulatorIsolatedRegionsV1()
  98. {
  99. TestHelpers.InMethod();
  100. // TestHelpers.EnableLogging();
  101. UUID userId = TestHelpers.ParseTail(0x1);
  102. EntityTransferModule etmA = new EntityTransferModule();
  103. EntityTransferModule etmB = new EntityTransferModule();
  104. LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
  105. IConfigSource config = new IniConfigSource();
  106. IConfig modulesConfig = config.AddConfig("Modules");
  107. modulesConfig.Set("EntityTransferModule", etmA.Name);
  108. modulesConfig.Set("SimulationServices", lscm.Name);
  109. IConfig entityTransferConfig = config.AddConfig("EntityTransfer");
  110. // In order to run a single threaded regression test we do not want the entity transfer module waiting
  111. // for a callback from the destination scene before removing its avatar data.
  112. entityTransferConfig.Set("wait_for_callback", false);
  113. SceneHelpers sh = new SceneHelpers();
  114. TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
  115. TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1002, 1000);
  116. SceneHelpers.SetupSceneModules(sceneA, config, etmA);
  117. SceneHelpers.SetupSceneModules(sceneB, config, etmB);
  118. SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
  119. // FIXME: Hack - this is here temporarily to revert back to older entity transfer behaviour
  120. lscm.ServiceVersion = 0.1f;
  121. Vector3 teleportPosition = new Vector3(10, 11, 12);
  122. Vector3 teleportLookAt = new Vector3(20, 21, 22);
  123. ScenePresence sp = SceneHelpers.AddScenePresence(sceneA, userId);
  124. sp.AbsolutePosition = new Vector3(30, 31, 32);
  125. List<TestClient> destinationTestClients = new List<TestClient>();
  126. EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(
  127. (TestClient)sp.ControllingClient, destinationTestClients);
  128. sceneA.RequestTeleportLocation(
  129. sp.ControllingClient,
  130. sceneB.RegionInfo.RegionHandle,
  131. teleportPosition,
  132. teleportLookAt,
  133. (uint)TeleportFlags.ViaLocation);
  134. // SetupInformClientOfNeighbour() will have handled the callback into the target scene to setup the child
  135. // agent. This call will now complete the movement of the user into the destination and upgrade the agent
  136. // from child to root.
  137. destinationTestClients[0].CompleteMovement();
  138. Assert.That(sceneA.GetScenePresence(userId), Is.Null);
  139. ScenePresence sceneBSp = sceneB.GetScenePresence(userId);
  140. Assert.That(sceneBSp, Is.Not.Null);
  141. Assert.That(sceneBSp.Scene.RegionInfo.RegionName, Is.EqualTo(sceneB.RegionInfo.RegionName));
  142. Assert.That(sceneBSp.AbsolutePosition, Is.EqualTo(teleportPosition));
  143. Assert.That(sceneA.GetRootAgentCount(), Is.EqualTo(0));
  144. Assert.That(sceneA.GetChildAgentCount(), Is.EqualTo(0));
  145. Assert.That(sceneB.GetRootAgentCount(), Is.EqualTo(1));
  146. Assert.That(sceneB.GetChildAgentCount(), Is.EqualTo(0));
  147. // TODO: Add assertions to check correct circuit details in both scenes.
  148. // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera
  149. // position instead).
  150. // Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt));
  151. }
  152. */
  153. [Test]
  154. public void TestSameSimulatorIsolatedRegionsV2()
  155. {
  156. TestHelpers.InMethod();
  157. // TestHelpers.EnableLogging();
  158. UUID userId = TestHelpers.ParseTail(0x1);
  159. EntityTransferModule etmA = new EntityTransferModule();
  160. EntityTransferModule etmB = new EntityTransferModule();
  161. LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
  162. IConfigSource config = new IniConfigSource();
  163. IConfig modulesConfig = config.AddConfig("Modules");
  164. modulesConfig.Set("EntityTransferModule", etmA.Name);
  165. modulesConfig.Set("SimulationServices", lscm.Name);
  166. SceneHelpers sh = new SceneHelpers();
  167. TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
  168. TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1002, 1000);
  169. SceneHelpers.SetupSceneModules(sceneA, config, etmA);
  170. SceneHelpers.SetupSceneModules(sceneB, config, etmB);
  171. SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
  172. Vector3 teleportPosition = new Vector3(10, 11, 12);
  173. Vector3 teleportLookAt = new Vector3(20, 21, 22);
  174. ScenePresence sp = SceneHelpers.AddScenePresence(sceneA, userId);
  175. sp.AbsolutePosition = new Vector3(30, 31, 32);
  176. sceneA.Update(4);
  177. sceneB.Update(4);
  178. List<TestClient> destinationTestClients = new List<TestClient>();
  179. EntityTransferHelpers.SetupSendRegionTeleportTriggersDestinationClientCreateAndCompleteMovement(
  180. (TestClient)sp.ControllingClient, destinationTestClients);
  181. sceneA.RequestTeleportLocation(
  182. sp.ControllingClient,
  183. sceneB.RegionInfo.RegionHandle,
  184. teleportPosition,
  185. teleportLookAt,
  186. (uint)TeleportFlags.ViaLocation);
  187. // Assert.That(sceneA.GetScenePresence(userId), Is.Null);
  188. sceneA.Update(4);
  189. sceneB.Update(4);
  190. ScenePresence sceneBSp = sceneB.GetScenePresence(userId);
  191. Assert.That(sceneBSp, Is.Not.Null);
  192. Assert.That(sceneBSp.Scene.RegionInfo.RegionName, Is.EqualTo(sceneB.RegionInfo.RegionName));
  193. Assert.That(sceneBSp.AbsolutePosition.X, Is.EqualTo(teleportPosition.X));
  194. Assert.That(sceneBSp.AbsolutePosition.Y, Is.EqualTo(teleportPosition.Y));
  195. //Assert.That(sceneA.GetRootAgentCount(), Is.EqualTo(0));
  196. //Assert.That(sceneA.GetChildAgentCount(), Is.EqualTo(0));
  197. //Assert.That(sceneB.GetRootAgentCount(), Is.EqualTo(1));
  198. //Assert.That(sceneB.GetChildAgentCount(), Is.EqualTo(0));
  199. // TODO: Add assertions to check correct circuit details in both scenes.
  200. // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera
  201. // position instead).
  202. // Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt));
  203. }
  204. /// <summary>
  205. /// Test teleport procedures when the target simulator returns false when queried about access.
  206. /// </summary>
  207. [Test]
  208. public void TestSameSimulatorIsolatedRegions_DeniedOnQueryAccess()
  209. {
  210. TestHelpers.InMethod();
  211. // TestHelpers.EnableLogging();
  212. UUID userId = TestHelpers.ParseTail(0x1);
  213. Vector3 preTeleportPosition = new Vector3(30, 31, 32);
  214. EntityTransferModule etmA = new EntityTransferModule();
  215. EntityTransferModule etmB = new EntityTransferModule();
  216. LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
  217. IConfigSource config = new IniConfigSource();
  218. config.AddConfig("Modules");
  219. config.Configs["Modules"].Set("EntityTransferModule", etmA.Name);
  220. config.Configs["Modules"].Set("SimulationServices", lscm.Name);
  221. config.AddConfig("EntityTransfer");
  222. // In order to run a single threaded regression test we do not want the entity transfer module waiting
  223. // for a callback from the destination scene before removing its avatar data.
  224. config.Configs["EntityTransfer"].Set("wait_for_callback", false);
  225. config.AddConfig("Startup");
  226. config.Configs["Startup"].Set("serverside_object_permissions", true);
  227. SceneHelpers sh = new SceneHelpers();
  228. TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
  229. TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1002, 1000);
  230. SceneHelpers.SetupSceneModules(sceneA, config, etmA );
  231. // We need to set up the permisions module on scene B so that our later use of agent limit to deny
  232. // QueryAccess won't succeed anyway because administrators are always allowed in and the default
  233. // IsAdministrator if no permissions module is present is true.
  234. SceneHelpers.SetupSceneModules(sceneB, config, new object[] { new DefaultPermissionsModule(), etmB });
  235. // Shared scene modules
  236. SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
  237. Vector3 teleportPosition = new Vector3(10, 11, 12);
  238. Vector3 teleportLookAt = new Vector3(20, 21, 22);
  239. ScenePresence sp = SceneHelpers.AddScenePresence(sceneA, userId);
  240. sp.AbsolutePosition = preTeleportPosition;
  241. // Make sceneB return false on query access
  242. sceneB.RegionInfo.RegionSettings.AgentLimit = 0;
  243. sceneA.RequestTeleportLocation(
  244. sp.ControllingClient,
  245. sceneB.RegionInfo.RegionHandle,
  246. teleportPosition,
  247. teleportLookAt,
  248. (uint)TeleportFlags.ViaLocation);
  249. // ((TestClient)sp.ControllingClient).CompleteTeleportClientSide();
  250. Assert.That(sceneB.GetScenePresence(userId), Is.Null);
  251. ScenePresence sceneASp = sceneA.GetScenePresence(userId);
  252. Assert.That(sceneASp, Is.Not.Null);
  253. Assert.That(sceneASp.Scene.RegionInfo.RegionName, Is.EqualTo(sceneA.RegionInfo.RegionName));
  254. Assert.That(sceneASp.AbsolutePosition.X, Is.EqualTo(preTeleportPosition.X));
  255. Assert.That(sceneASp.AbsolutePosition.Y, Is.EqualTo(preTeleportPosition.Y));
  256. Assert.That(sceneA.GetRootAgentCount(), Is.EqualTo(1));
  257. Assert.That(sceneA.GetChildAgentCount(), Is.EqualTo(0));
  258. Assert.That(sceneB.GetRootAgentCount(), Is.EqualTo(0));
  259. Assert.That(sceneB.GetChildAgentCount(), Is.EqualTo(0));
  260. // TODO: Add assertions to check correct circuit details in both scenes.
  261. // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera
  262. // position instead).
  263. // Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt));
  264. // TestHelpers.DisableLogging();
  265. }
  266. /// <summary>
  267. /// Test teleport procedures when the target simulator create agent step is refused.
  268. /// </summary>
  269. [Test]
  270. public void TestSameSimulatorIsolatedRegions_DeniedOnCreateAgent()
  271. {
  272. TestHelpers.InMethod();
  273. // TestHelpers.EnableLogging();
  274. UUID userId = TestHelpers.ParseTail(0x1);
  275. Vector3 preTeleportPosition = new Vector3(30, 31, 32);
  276. EntityTransferModule etmA = new EntityTransferModule();
  277. EntityTransferModule etmB = new EntityTransferModule();
  278. LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
  279. IConfigSource config = new IniConfigSource();
  280. config.AddConfig("Modules");
  281. config.Configs["Modules"].Set("EntityTransferModule", etmA.Name);
  282. config.Configs["Modules"].Set("SimulationServices", lscm.Name);
  283. config.AddConfig("EntityTransfer");
  284. // In order to run a single threaded regression test we do not want the entity transfer module waiting
  285. // for a callback from the destination scene before removing its avatar data.
  286. config.Configs["EntityTransfer"].Set("wait_for_callback", false);
  287. SceneHelpers sh = new SceneHelpers();
  288. TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
  289. TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1002, 1000);
  290. SceneHelpers.SetupSceneModules(sceneA, config, etmA);
  291. SceneHelpers.SetupSceneModules(sceneB, config, etmB);
  292. // Shared scene modules
  293. SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
  294. Vector3 teleportPosition = new Vector3(10, 11, 12);
  295. Vector3 teleportLookAt = new Vector3(20, 21, 22);
  296. ScenePresence sp = SceneHelpers.AddScenePresence(sceneA, userId);
  297. sp.AbsolutePosition = preTeleportPosition;
  298. sceneA.Update(4);
  299. sceneB.Update(4);
  300. // Make sceneB refuse CreateAgent
  301. sceneB.LoginsEnabled = false;
  302. sceneA.RequestTeleportLocation(
  303. sp.ControllingClient,
  304. sceneB.RegionInfo.RegionHandle,
  305. teleportPosition,
  306. teleportLookAt,
  307. (uint)TeleportFlags.ViaLocation);
  308. // ((TestClient)sp.ControllingClient).CompleteTeleportClientSide();
  309. sceneA.Update(4);
  310. sceneB.Update(4);
  311. Assert.That(sceneB.GetScenePresence(userId), Is.Null);
  312. ScenePresence sceneASp = sceneA.GetScenePresence(userId);
  313. Assert.That(sceneASp, Is.Not.Null);
  314. Assert.That(sceneASp.Scene.RegionInfo.RegionName, Is.EqualTo(sceneA.RegionInfo.RegionName));
  315. Assert.That(sceneASp.AbsolutePosition.X, Is.EqualTo(preTeleportPosition.X));
  316. Assert.That(sceneASp.AbsolutePosition.Y, Is.EqualTo(preTeleportPosition.Y));
  317. Assert.That(sceneA.GetRootAgentCount(), Is.EqualTo(1));
  318. Assert.That(sceneA.GetChildAgentCount(), Is.EqualTo(0));
  319. Assert.That(sceneB.GetRootAgentCount(), Is.EqualTo(0));
  320. Assert.That(sceneB.GetChildAgentCount(), Is.EqualTo(0));
  321. // TODO: Add assertions to check correct circuit details in both scenes.
  322. // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera
  323. // position instead).
  324. // Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt));
  325. // TestHelpers.DisableLogging();
  326. }
  327. /// <summary>
  328. /// Test teleport when the destination region does not process (or does not receive) the connection attempt
  329. /// from the viewer.
  330. /// </summary>
  331. /// <remarks>
  332. /// This could be quite a common case where the source region can connect to a remove destination region
  333. /// (for CreateAgent) but the viewer cannot reach the destination region due to network issues.
  334. /// </remarks>
  335. [Test]
  336. public void TestSameSimulatorIsolatedRegions_DestinationDidNotProcessViewerConnection()
  337. {
  338. TestHelpers.InMethod();
  339. // TestHelpers.EnableLogging();
  340. UUID userId = TestHelpers.ParseTail(0x1);
  341. Vector3 preTeleportPosition = new Vector3(30, 31, 32);
  342. EntityTransferModule etmA = new EntityTransferModule();
  343. EntityTransferModule etmB = new EntityTransferModule();
  344. LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
  345. IConfigSource config = new IniConfigSource();
  346. config.AddConfig("Modules");
  347. config.Configs["Modules"].Set("EntityTransferModule", etmA.Name);
  348. config.Configs["Modules"].Set("SimulationServices", lscm.Name);
  349. config.AddConfig("EntityTransfer");
  350. // In order to run a single threaded regression test we do not want the entity transfer module waiting
  351. // for a callback from the destination scene before removing its avatar data.
  352. config.Configs["EntityTransfer"].Set("wait_for_callback", false);
  353. // config.AddConfig("Startup");
  354. // config.Configs["Startup"].Set("serverside_object_permissions", true);
  355. SceneHelpers sh = new SceneHelpers();
  356. TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
  357. TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1002, 1000);
  358. SceneHelpers.SetupSceneModules(sceneA, config, etmA );
  359. // We need to set up the permisions module on scene B so that our later use of agent limit to deny
  360. // QueryAccess won't succeed anyway because administrators are always allowed in and the default
  361. // IsAdministrator if no permissions module is present is true.
  362. SceneHelpers.SetupSceneModules(sceneB, config, new object[] { new DefaultPermissionsModule(), etmB });
  363. // Shared scene modules
  364. SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
  365. Vector3 teleportPosition = new Vector3(10, 11, 12);
  366. Vector3 teleportLookAt = new Vector3(20, 21, 22);
  367. ScenePresence sp = SceneHelpers.AddScenePresence(sceneA, userId);
  368. sp.AbsolutePosition = preTeleportPosition;
  369. sceneA.Update(4);
  370. sceneB.Update(4);
  371. sceneA.RequestTeleportLocation(
  372. sp.ControllingClient,
  373. sceneB.RegionInfo.RegionHandle,
  374. teleportPosition,
  375. teleportLookAt,
  376. (uint)TeleportFlags.ViaLocation);
  377. // FIXME: Not setting up InformClientOfNeighbour on the TestClient means that it does not initiate
  378. // communication with the destination region. But this is a very non-obvious way of doing it - really we
  379. // should be forced to expicitly set this up.
  380. sceneA.Update(4);
  381. sceneB.Update(4);
  382. Assert.That(sceneB.GetScenePresence(userId), Is.Null);
  383. ScenePresence sceneASp = sceneA.GetScenePresence(userId);
  384. Assert.That(sceneASp, Is.Not.Null);
  385. Assert.That(sceneASp.Scene.RegionInfo.RegionName, Is.EqualTo(sceneA.RegionInfo.RegionName));
  386. Assert.That(sceneASp.AbsolutePosition.X, Is.EqualTo(preTeleportPosition.X));
  387. Assert.That(sceneASp.AbsolutePosition.Y, Is.EqualTo(preTeleportPosition.Y));
  388. sceneA.SceneGraph.RecalculateStats();
  389. sceneB.SceneGraph.RecalculateStats();
  390. Assert.That(sceneA.GetRootAgentCount(), Is.EqualTo(1));
  391. Assert.That(sceneA.GetChildAgentCount(), Is.EqualTo(0));
  392. Assert.That(sceneB.GetRootAgentCount(), Is.EqualTo(0));
  393. Assert.That(sceneB.GetChildAgentCount(), Is.EqualTo(0));
  394. // TODO: Add assertions to check correct circuit details in both scenes.
  395. // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera
  396. // position instead).
  397. // Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt));
  398. // TestHelpers.DisableLogging();
  399. }
  400. /*
  401. [Test]
  402. public void TestSameSimulatorNeighbouringRegionsV1()
  403. {
  404. TestHelpers.InMethod();
  405. // TestHelpers.EnableLogging();
  406. UUID userId = TestHelpers.ParseTail(0x1);
  407. EntityTransferModule etmA = new EntityTransferModule();
  408. EntityTransferModule etmB = new EntityTransferModule();
  409. LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
  410. IConfigSource config = new IniConfigSource();
  411. IConfig modulesConfig = config.AddConfig("Modules");
  412. modulesConfig.Set("EntityTransferModule", etmA.Name);
  413. modulesConfig.Set("SimulationServices", lscm.Name);
  414. IConfig entityTransferConfig = config.AddConfig("EntityTransfer");
  415. // In order to run a single threaded regression test we do not want the entity transfer module waiting
  416. // for a callback from the destination scene before removing its avatar data.
  417. entityTransferConfig.Set("wait_for_callback", false);
  418. SceneHelpers sh = new SceneHelpers();
  419. TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
  420. TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1001, 1000);
  421. SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
  422. SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA);
  423. SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), etmB);
  424. // FIXME: Hack - this is here temporarily to revert back to older entity transfer behaviour
  425. lscm.ServiceVersion = 0.1f;
  426. Vector3 teleportPosition = new Vector3(10, 11, 12);
  427. Vector3 teleportLookAt = new Vector3(20, 21, 22);
  428. AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId);
  429. TestClient tc = new TestClient(acd, sceneA);
  430. List<TestClient> destinationTestClients = new List<TestClient>();
  431. EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients);
  432. ScenePresence beforeSceneASp = SceneHelpers.AddScenePresence(sceneA, tc, acd);
  433. beforeSceneASp.AbsolutePosition = new Vector3(30, 31, 32);
  434. Assert.That(beforeSceneASp, Is.Not.Null);
  435. Assert.That(beforeSceneASp.IsChildAgent, Is.False);
  436. ScenePresence beforeSceneBSp = sceneB.GetScenePresence(userId);
  437. Assert.That(beforeSceneBSp, Is.Not.Null);
  438. Assert.That(beforeSceneBSp.IsChildAgent, Is.True);
  439. // In this case, we will not receieve a second InformClientOfNeighbour since the viewer already knows
  440. // about the neighbour region it is teleporting to.
  441. sceneA.RequestTeleportLocation(
  442. beforeSceneASp.ControllingClient,
  443. sceneB.RegionInfo.RegionHandle,
  444. teleportPosition,
  445. teleportLookAt,
  446. (uint)TeleportFlags.ViaLocation);
  447. destinationTestClients[0].CompleteMovement();
  448. ScenePresence afterSceneASp = sceneA.GetScenePresence(userId);
  449. Assert.That(afterSceneASp, Is.Not.Null);
  450. Assert.That(afterSceneASp.IsChildAgent, Is.True);
  451. ScenePresence afterSceneBSp = sceneB.GetScenePresence(userId);
  452. Assert.That(afterSceneBSp, Is.Not.Null);
  453. Assert.That(afterSceneBSp.IsChildAgent, Is.False);
  454. Assert.That(afterSceneBSp.Scene.RegionInfo.RegionName, Is.EqualTo(sceneB.RegionInfo.RegionName));
  455. Assert.That(afterSceneBSp.AbsolutePosition, Is.EqualTo(teleportPosition));
  456. Assert.That(sceneA.GetRootAgentCount(), Is.EqualTo(0));
  457. Assert.That(sceneA.GetChildAgentCount(), Is.EqualTo(1));
  458. Assert.That(sceneB.GetRootAgentCount(), Is.EqualTo(1));
  459. Assert.That(sceneB.GetChildAgentCount(), Is.EqualTo(0));
  460. // TODO: Add assertions to check correct circuit details in both scenes.
  461. // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera
  462. // position instead).
  463. // Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt));
  464. // TestHelpers.DisableLogging();
  465. }
  466. */
  467. [Test]
  468. public void TestSameSimulatorNeighbouringRegionsV2()
  469. {
  470. TestHelpers.InMethod();
  471. // TestHelpers.EnableLogging();
  472. UUID userId = TestHelpers.ParseTail(0x1);
  473. EntityTransferModule etmA = new EntityTransferModule();
  474. EntityTransferModule etmB = new EntityTransferModule();
  475. LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
  476. IConfigSource config = new IniConfigSource();
  477. IConfig modulesConfig = config.AddConfig("Modules");
  478. modulesConfig.Set("EntityTransferModule", etmA.Name);
  479. modulesConfig.Set("SimulationServices", lscm.Name);
  480. SceneHelpers sh = new SceneHelpers();
  481. TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
  482. TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1001, 1000);
  483. SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
  484. SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA);
  485. SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), etmB);
  486. Vector3 teleportPosition = new Vector3(10, 11, 12);
  487. Vector3 teleportLookAt = new Vector3(20, 21, 22);
  488. AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId);
  489. TestClient tc = new TestClient(acd, sceneA);
  490. List<TestClient> destinationTestClients = new List<TestClient>();
  491. EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients);
  492. ScenePresence beforeSceneASp = SceneHelpers.AddScenePresence(sceneA, tc, acd);
  493. beforeSceneASp.AbsolutePosition = new Vector3(30, 31, 32);
  494. sceneA.Update(4);
  495. sceneB.Update(4);
  496. Assert.That(beforeSceneASp, Is.Not.Null);
  497. Assert.That(beforeSceneASp.IsChildAgent, Is.False);
  498. ScenePresence beforeSceneBSp = sceneB.GetScenePresence(userId);
  499. Assert.That(beforeSceneBSp, Is.Not.Null);
  500. Assert.That(beforeSceneBSp.IsChildAgent, Is.True);
  501. // Here, we need to make clientA's receipt of SendRegionTeleport trigger clientB's CompleteMovement(). This
  502. // is to operate the teleport V2 mechanism where the EntityTransferModule will first request the client to
  503. // CompleteMovement to the region and then call UpdateAgent to the destination region to confirm the receipt
  504. // Both these operations will occur on different threads and will wait for each other.
  505. // We have to do this via ThreadPool directly since FireAndForget has been switched to sync for the V1
  506. // test protocol, where we are trying to avoid unpredictable async operations in regression tests.
  507. tc.OnTestClientSendRegionTeleport
  508. += (regionHandle, simAccess, regionExternalEndPoint, locationID, flags, capsURL)
  509. => ThreadPool.UnsafeQueueUserWorkItem(o => destinationTestClients[0].CompleteMovement(), null);
  510. sceneA.RequestTeleportLocation(
  511. beforeSceneASp.ControllingClient,
  512. sceneB.RegionInfo.RegionHandle,
  513. teleportPosition,
  514. teleportLookAt,
  515. (uint)TeleportFlags.ViaLocation);
  516. sceneA.Update(4);
  517. sceneB.Update(4);
  518. ScenePresence afterSceneASp = sceneA.GetScenePresence(userId);
  519. Assert.That(afterSceneASp, Is.Not.Null);
  520. Assert.That(afterSceneASp.IsChildAgent, Is.True);
  521. ScenePresence afterSceneBSp = sceneB.GetScenePresence(userId);
  522. Assert.That(afterSceneBSp, Is.Not.Null);
  523. Assert.That(afterSceneBSp.IsChildAgent, Is.False);
  524. Assert.That(afterSceneBSp.Scene.RegionInfo.RegionName, Is.EqualTo(sceneB.RegionInfo.RegionName));
  525. Assert.That(afterSceneBSp.AbsolutePosition.X, Is.EqualTo(teleportPosition.X));
  526. Assert.That(afterSceneBSp.AbsolutePosition.Y, Is.EqualTo(teleportPosition.Y));
  527. Assert.That(sceneA.GetRootAgentCount(), Is.EqualTo(0));
  528. Assert.That(sceneA.GetChildAgentCount(), Is.EqualTo(1));
  529. Assert.That(sceneB.GetRootAgentCount(), Is.EqualTo(1));
  530. Assert.That(sceneB.GetChildAgentCount(), Is.EqualTo(0));
  531. // TODO: Add assertions to check correct circuit details in both scenes.
  532. // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera
  533. // position instead).
  534. // Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt));
  535. // TestHelpers.DisableLogging();
  536. }
  537. }
  538. }