ScenePresenceTeleportTests.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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.Reflection;
  29. using Nini.Config;
  30. using NUnit.Framework;
  31. using OpenMetaverse;
  32. using OpenSim.Framework;
  33. using OpenSim.Framework.Communications;
  34. using OpenSim.Framework.Servers;
  35. using OpenSim.Region.Framework.Interfaces;
  36. using OpenSim.Region.CoreModules.Framework;
  37. using OpenSim.Region.CoreModules.Framework.EntityTransfer;
  38. using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
  39. using OpenSim.Region.CoreModules.World.Permissions;
  40. using OpenSim.Tests.Common;
  41. using OpenSim.Tests.Common.Mock;
  42. using System.IO;
  43. using System.Text;
  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
  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 TestSameRegionTeleport()
  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. [Test]
  96. public void TestSameSimulatorSeparatedRegionsTeleport()
  97. {
  98. TestHelpers.InMethod();
  99. // log4net.Config.XmlConfigurator.Configure();
  100. UUID userId = TestHelpers.ParseTail(0x1);
  101. EntityTransferModule etmA = new EntityTransferModule();
  102. EntityTransferModule etmB = new EntityTransferModule();
  103. LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
  104. IConfigSource config = new IniConfigSource();
  105. IConfig modulesConfig = config.AddConfig("Modules");
  106. modulesConfig.Set("EntityTransferModule", etmA.Name);
  107. modulesConfig.Set("SimulationServices", lscm.Name);
  108. IConfig entityTransferConfig = config.AddConfig("EntityTransfer");
  109. // In order to run a single threaded regression test we do not want the entity transfer module waiting
  110. // for a callback from the destination scene before removing its avatar data.
  111. entityTransferConfig.Set("wait_for_callback", false);
  112. SceneHelpers sh = new SceneHelpers();
  113. TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
  114. TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1002, 1000);
  115. SceneHelpers.SetupSceneModules(sceneA, config, etmA);
  116. SceneHelpers.SetupSceneModules(sceneB, config, etmB);
  117. SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
  118. Vector3 teleportPosition = new Vector3(10, 11, 12);
  119. Vector3 teleportLookAt = new Vector3(20, 21, 22);
  120. ScenePresence sp = SceneHelpers.AddScenePresence(sceneA, userId, sh.SceneManager);
  121. sp.AbsolutePosition = new Vector3(30, 31, 32);
  122. // XXX: A very nasty hack to tell the client about the destination scene without having to crank the whole
  123. // UDP stack (?)
  124. // ((TestClient)sp.ControllingClient).TeleportTargetScene = sceneB;
  125. sceneA.RequestTeleportLocation(
  126. sp.ControllingClient,
  127. sceneB.RegionInfo.RegionHandle,
  128. teleportPosition,
  129. teleportLookAt,
  130. (uint)TeleportFlags.ViaLocation);
  131. ((TestClient)sp.ControllingClient).CompleteTeleportClientSide();
  132. Assert.That(sceneA.GetScenePresence(userId), Is.Null);
  133. ScenePresence sceneBSp = sceneB.GetScenePresence(userId);
  134. Assert.That(sceneBSp, Is.Not.Null);
  135. Assert.That(sceneBSp.Scene.RegionInfo.RegionName, Is.EqualTo(sceneB.RegionInfo.RegionName));
  136. Assert.That(sceneBSp.AbsolutePosition, Is.EqualTo(teleportPosition));
  137. Assert.That(sceneA.GetRootAgentCount(), Is.EqualTo(0));
  138. Assert.That(sceneA.GetChildAgentCount(), Is.EqualTo(0));
  139. Assert.That(sceneB.GetRootAgentCount(), Is.EqualTo(1));
  140. Assert.That(sceneB.GetChildAgentCount(), Is.EqualTo(0));
  141. // TODO: Add assertions to check correct circuit details in both scenes.
  142. // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera
  143. // position instead).
  144. // Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt));
  145. }
  146. /// <summary>
  147. /// Test teleport procedures when the target simulator returns false when queried about access.
  148. /// </summary>
  149. [Test]
  150. public void TestSameSimulatorSeparatedRegionsQueryAccessFails()
  151. {
  152. TestHelpers.InMethod();
  153. // TestHelpers.EnableLogging();
  154. UUID userId = TestHelpers.ParseTail(0x1);
  155. Vector3 preTeleportPosition = new Vector3(30, 31, 32);
  156. EntityTransferModule etmA = new EntityTransferModule();
  157. EntityTransferModule etmB = new EntityTransferModule();
  158. LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
  159. IConfigSource config = new IniConfigSource();
  160. config.AddConfig("Modules");
  161. config.Configs["Modules"].Set("EntityTransferModule", etmA.Name);
  162. config.Configs["Modules"].Set("SimulationServices", lscm.Name);
  163. config.AddConfig("EntityTransfer");
  164. // In order to run a single threaded regression test we do not want the entity transfer module waiting
  165. // for a callback from the destination scene before removing its avatar data.
  166. config.Configs["EntityTransfer"].Set("wait_for_callback", false);
  167. config.AddConfig("Startup");
  168. config.Configs["Startup"].Set("serverside_object_permissions", true);
  169. SceneHelpers sh = new SceneHelpers();
  170. TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
  171. TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1002, 1000);
  172. SceneHelpers.SetupSceneModules(sceneA, config, etmA );
  173. // We need to set up the permisions module on scene B so that our later use of agent limit to deny
  174. // QueryAccess won't succeed anyway because administrators are always allowed in and the default
  175. // IsAdministrator if no permissions module is present is true.
  176. SceneHelpers.SetupSceneModules(sceneB, config, new object[] { new PermissionsModule(), etmB });
  177. // Shared scene modules
  178. SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
  179. Vector3 teleportPosition = new Vector3(10, 11, 12);
  180. Vector3 teleportLookAt = new Vector3(20, 21, 22);
  181. ScenePresence sp = SceneHelpers.AddScenePresence(sceneA, userId, sh.SceneManager);
  182. sp.AbsolutePosition = preTeleportPosition;
  183. // Make sceneB return false on query access
  184. sceneB.RegionInfo.RegionSettings.AgentLimit = 0;
  185. sceneA.RequestTeleportLocation(
  186. sp.ControllingClient,
  187. sceneB.RegionInfo.RegionHandle,
  188. teleportPosition,
  189. teleportLookAt,
  190. (uint)TeleportFlags.ViaLocation);
  191. // ((TestClient)sp.ControllingClient).CompleteTeleportClientSide();
  192. Assert.That(sceneB.GetScenePresence(userId), Is.Null);
  193. ScenePresence sceneASp = sceneA.GetScenePresence(userId);
  194. Assert.That(sceneASp, Is.Not.Null);
  195. Assert.That(sceneASp.Scene.RegionInfo.RegionName, Is.EqualTo(sceneA.RegionInfo.RegionName));
  196. Assert.That(sceneASp.AbsolutePosition, Is.EqualTo(preTeleportPosition));
  197. Assert.That(sceneA.GetRootAgentCount(), Is.EqualTo(1));
  198. Assert.That(sceneA.GetChildAgentCount(), Is.EqualTo(0));
  199. Assert.That(sceneB.GetRootAgentCount(), Is.EqualTo(0));
  200. Assert.That(sceneB.GetChildAgentCount(), Is.EqualTo(0));
  201. // TODO: Add assertions to check correct circuit details in both scenes.
  202. // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera
  203. // position instead).
  204. // Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt));
  205. // TestHelpers.DisableLogging();
  206. }
  207. /// <summary>
  208. /// Test teleport procedures when the target simulator create agent step is refused.
  209. /// </summary>
  210. [Test]
  211. public void TestSameSimulatorSeparatedRegionsCreateAgentFails()
  212. {
  213. TestHelpers.InMethod();
  214. // TestHelpers.EnableLogging();
  215. UUID userId = TestHelpers.ParseTail(0x1);
  216. Vector3 preTeleportPosition = new Vector3(30, 31, 32);
  217. EntityTransferModule etmA = new EntityTransferModule();
  218. EntityTransferModule etmB = new EntityTransferModule();
  219. LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
  220. IConfigSource config = new IniConfigSource();
  221. config.AddConfig("Modules");
  222. config.Configs["Modules"].Set("EntityTransferModule", etmA.Name);
  223. config.Configs["Modules"].Set("SimulationServices", lscm.Name);
  224. config.AddConfig("EntityTransfer");
  225. // In order to run a single threaded regression test we do not want the entity transfer module waiting
  226. // for a callback from the destination scene before removing its avatar data.
  227. config.Configs["EntityTransfer"].Set("wait_for_callback", false);
  228. SceneHelpers sh = new SceneHelpers();
  229. TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
  230. TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1002, 1000);
  231. SceneHelpers.SetupSceneModules(sceneA, config, etmA);
  232. SceneHelpers.SetupSceneModules(sceneB, config, etmB);
  233. // Shared scene modules
  234. SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
  235. Vector3 teleportPosition = new Vector3(10, 11, 12);
  236. Vector3 teleportLookAt = new Vector3(20, 21, 22);
  237. ScenePresence sp = SceneHelpers.AddScenePresence(sceneA, userId, sh.SceneManager);
  238. sp.AbsolutePosition = preTeleportPosition;
  239. // Make sceneB refuse CreateAgent
  240. sceneB.LoginsEnabled = false;
  241. sceneA.RequestTeleportLocation(
  242. sp.ControllingClient,
  243. sceneB.RegionInfo.RegionHandle,
  244. teleportPosition,
  245. teleportLookAt,
  246. (uint)TeleportFlags.ViaLocation);
  247. // ((TestClient)sp.ControllingClient).CompleteTeleportClientSide();
  248. Assert.That(sceneB.GetScenePresence(userId), Is.Null);
  249. ScenePresence sceneASp = sceneA.GetScenePresence(userId);
  250. Assert.That(sceneASp, Is.Not.Null);
  251. Assert.That(sceneASp.Scene.RegionInfo.RegionName, Is.EqualTo(sceneA.RegionInfo.RegionName));
  252. Assert.That(sceneASp.AbsolutePosition, Is.EqualTo(preTeleportPosition));
  253. Assert.That(sceneA.GetRootAgentCount(), Is.EqualTo(1));
  254. Assert.That(sceneA.GetChildAgentCount(), Is.EqualTo(0));
  255. Assert.That(sceneB.GetRootAgentCount(), Is.EqualTo(0));
  256. Assert.That(sceneB.GetChildAgentCount(), Is.EqualTo(0));
  257. // TODO: Add assertions to check correct circuit details in both scenes.
  258. // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera
  259. // position instead).
  260. // Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt));
  261. // TestHelpers.DisableLogging();
  262. }
  263. [Test]
  264. public void TestSameSimulatorNeighbouringRegionsTeleport()
  265. {
  266. TestHelpers.InMethod();
  267. // TestHelpers.EnableLogging();
  268. UUID userId = TestHelpers.ParseTail(0x1);
  269. EntityTransferModule etmA = new EntityTransferModule();
  270. EntityTransferModule etmB = new EntityTransferModule();
  271. LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
  272. IConfigSource config = new IniConfigSource();
  273. IConfig modulesConfig = config.AddConfig("Modules");
  274. modulesConfig.Set("EntityTransferModule", etmA.Name);
  275. modulesConfig.Set("SimulationServices", lscm.Name);
  276. IConfig entityTransferConfig = 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. entityTransferConfig.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), 1001, 1000);
  283. SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
  284. SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA);
  285. SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), etmB);
  286. Vector3 teleportPosition = new Vector3(10, 11, 12);
  287. Vector3 teleportLookAt = new Vector3(20, 21, 22);
  288. ScenePresence originalSp = SceneHelpers.AddScenePresence(sceneA, userId, sh.SceneManager);
  289. originalSp.AbsolutePosition = new Vector3(30, 31, 32);
  290. ScenePresence beforeSceneASp = sceneA.GetScenePresence(userId);
  291. Assert.That(beforeSceneASp, Is.Not.Null);
  292. Assert.That(beforeSceneASp.IsChildAgent, Is.False);
  293. ScenePresence beforeSceneBSp = sceneB.GetScenePresence(userId);
  294. Assert.That(beforeSceneBSp, Is.Not.Null);
  295. Assert.That(beforeSceneBSp.IsChildAgent, Is.True);
  296. // XXX: A very nasty hack to tell the client about the destination scene without having to crank the whole
  297. // UDP stack (?)
  298. // ((TestClient)beforeSceneASp.ControllingClient).TeleportTargetScene = sceneB;
  299. sceneA.RequestTeleportLocation(
  300. beforeSceneASp.ControllingClient,
  301. sceneB.RegionInfo.RegionHandle,
  302. teleportPosition,
  303. teleportLookAt,
  304. (uint)TeleportFlags.ViaLocation);
  305. ((TestClient)beforeSceneASp.ControllingClient).CompleteTeleportClientSide();
  306. ScenePresence afterSceneASp = sceneA.GetScenePresence(userId);
  307. Assert.That(afterSceneASp, Is.Not.Null);
  308. Assert.That(afterSceneASp.IsChildAgent, Is.True);
  309. ScenePresence afterSceneBSp = sceneB.GetScenePresence(userId);
  310. Assert.That(afterSceneBSp, Is.Not.Null);
  311. Assert.That(afterSceneBSp.IsChildAgent, Is.False);
  312. Assert.That(afterSceneBSp.Scene.RegionInfo.RegionName, Is.EqualTo(sceneB.RegionInfo.RegionName));
  313. Assert.That(afterSceneBSp.AbsolutePosition, Is.EqualTo(teleportPosition));
  314. Assert.That(sceneA.GetRootAgentCount(), Is.EqualTo(0));
  315. Assert.That(sceneA.GetChildAgentCount(), Is.EqualTo(1));
  316. Assert.That(sceneB.GetRootAgentCount(), Is.EqualTo(1));
  317. Assert.That(sceneB.GetChildAgentCount(), Is.EqualTo(0));
  318. // TODO: Add assertions to check correct circuit details in both scenes.
  319. // Lookat is sent to the client only - sp.Lookat does not yield the same thing (calculation from camera
  320. // position instead).
  321. // Assert.That(sp.Lookat, Is.EqualTo(teleportLookAt));
  322. // TestHelpers.DisableLogging();
  323. }
  324. }
  325. }