ScenePresenceTeleportTests.cs 31 KB

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