ScenePresenceCrossingTests.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 Nini.Config;
  31. using NUnit.Framework;
  32. using OpenMetaverse;
  33. using OpenSim.Framework;
  34. using OpenSim.Framework.Communications;
  35. using OpenSim.Framework.Servers;
  36. using OpenSim.Region.Framework.Interfaces;
  37. using OpenSim.Region.CoreModules.Framework;
  38. using OpenSim.Region.CoreModules.Framework.EntityTransfer;
  39. using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
  40. using OpenSim.Region.CoreModules.World.Permissions;
  41. using OpenSim.Tests.Common;
  42. using OpenSim.Tests.Common.Mock;
  43. namespace OpenSim.Region.Framework.Scenes.Tests
  44. {
  45. [TestFixture]
  46. public class ScenePresenceCrossingTests : OpenSimTestCase
  47. {
  48. [TestFixtureSetUp]
  49. public void FixtureInit()
  50. {
  51. // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
  52. Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
  53. }
  54. [TestFixtureTearDown]
  55. public void TearDown()
  56. {
  57. // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
  58. // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
  59. // tests really shouldn't).
  60. Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
  61. }
  62. [Test]
  63. public void TestCrossOnSameSimulator()
  64. {
  65. TestHelpers.InMethod();
  66. // TestHelpers.EnableLogging();
  67. UUID userId = TestHelpers.ParseTail(0x1);
  68. // TestEventQueueGetModule eqmA = new TestEventQueueGetModule();
  69. EntityTransferModule etmA = new EntityTransferModule();
  70. EntityTransferModule etmB = new EntityTransferModule();
  71. LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
  72. IConfigSource config = new IniConfigSource();
  73. IConfig modulesConfig = config.AddConfig("Modules");
  74. modulesConfig.Set("EntityTransferModule", etmA.Name);
  75. modulesConfig.Set("SimulationServices", lscm.Name);
  76. // IConfig entityTransferConfig = config.AddConfig("EntityTransfer");
  77. // In order to run a single threaded regression test we do not want the entity transfer module waiting
  78. // for a callback from the destination scene before removing its avatar data.
  79. // entityTransferConfig.Set("wait_for_callback", false);
  80. SceneHelpers sh = new SceneHelpers();
  81. TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
  82. TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999);
  83. SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
  84. SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA);
  85. // SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA, eqmA);
  86. SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), etmB);
  87. AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId);
  88. TestClient tc = new TestClient(acd, sceneA);
  89. List<TestClient> destinationTestClients = new List<TestClient>();
  90. EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients);
  91. ScenePresence originalSp = SceneHelpers.AddScenePresence(sceneA, tc, acd);
  92. originalSp.AbsolutePosition = new Vector3(128, 32, 10);
  93. // originalSp.Flying = true;
  94. // Console.WriteLine("First pos {0}", originalSp.AbsolutePosition);
  95. // eqmA.ClearEvents();
  96. AgentUpdateArgs moveArgs = new AgentUpdateArgs();
  97. //moveArgs.BodyRotation = Quaternion.CreateFromEulers(Vector3.Zero);
  98. moveArgs.BodyRotation = Quaternion.CreateFromEulers(new Vector3(0, 0, (float)-(Math.PI / 2)));
  99. moveArgs.ControlFlags = (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS;
  100. moveArgs.SessionID = acd.SessionID;
  101. originalSp.HandleAgentUpdate(originalSp.ControllingClient, moveArgs);
  102. sceneA.Update(1);
  103. // Console.WriteLine("Second pos {0}", originalSp.AbsolutePosition);
  104. // FIXME: This is a sufficient number of updates to for the presence to reach the northern border.
  105. // But really we want to do this in a more robust way.
  106. for (int i = 0; i < 100; i++)
  107. {
  108. sceneA.Update(1);
  109. // Console.WriteLine("Pos {0}", originalSp.AbsolutePosition);
  110. }
  111. // Need to sort processing of EnableSimulator message on adding scene presences before we can test eqm
  112. // messages
  113. // Dictionary<UUID, List<TestEventQueueGetModule.Event>> eqmEvents = eqmA.Events;
  114. //
  115. // Assert.That(eqmEvents.Count, Is.EqualTo(1));
  116. // Assert.That(eqmEvents.ContainsKey(originalSp.UUID), Is.True);
  117. //
  118. // List<TestEventQueueGetModule.Event> spEqmEvents = eqmEvents[originalSp.UUID];
  119. //
  120. // Assert.That(spEqmEvents.Count, Is.EqualTo(1));
  121. // Assert.That(spEqmEvents[0].Name, Is.EqualTo("CrossRegion"));
  122. // sceneA should now only have a child agent
  123. ScenePresence spAfterCrossSceneA = sceneA.GetScenePresence(originalSp.UUID);
  124. Assert.That(spAfterCrossSceneA.IsChildAgent, Is.True);
  125. ScenePresence spAfterCrossSceneB = sceneB.GetScenePresence(originalSp.UUID);
  126. // Agent remains a child until the client triggers complete movement
  127. Assert.That(spAfterCrossSceneB.IsChildAgent, Is.True);
  128. TestClient sceneBTc = ((TestClient)spAfterCrossSceneB.ControllingClient);
  129. int agentMovementCompleteReceived = 0;
  130. sceneBTc.OnReceivedMoveAgentIntoRegion += (ri, pos, look) => agentMovementCompleteReceived++;
  131. sceneBTc.CompleteMovement();
  132. Assert.That(agentMovementCompleteReceived, Is.EqualTo(1));
  133. Assert.That(spAfterCrossSceneB.IsChildAgent, Is.False);
  134. }
  135. /// <summary>
  136. /// Test a cross attempt where the user can see into the neighbour but does not have permission to become
  137. /// root there.
  138. /// </summary>
  139. [Test]
  140. public void TestCrossOnSameSimulatorNoRootDestPerm()
  141. {
  142. TestHelpers.InMethod();
  143. // TestHelpers.EnableLogging();
  144. UUID userId = TestHelpers.ParseTail(0x1);
  145. EntityTransferModule etmA = new EntityTransferModule();
  146. EntityTransferModule etmB = new EntityTransferModule();
  147. LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
  148. IConfigSource config = new IniConfigSource();
  149. IConfig modulesConfig = config.AddConfig("Modules");
  150. modulesConfig.Set("EntityTransferModule", etmA.Name);
  151. modulesConfig.Set("SimulationServices", lscm.Name);
  152. SceneHelpers sh = new SceneHelpers();
  153. TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
  154. TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999);
  155. SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
  156. SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA);
  157. // We need to set up the permisions module on scene B so that our later use of agent limit to deny
  158. // QueryAccess won't succeed anyway because administrators are always allowed in and the default
  159. // IsAdministrator if no permissions module is present is true.
  160. SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), new PermissionsModule(), etmB);
  161. AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId);
  162. TestClient tc = new TestClient(acd, sceneA);
  163. List<TestClient> destinationTestClients = new List<TestClient>();
  164. EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients);
  165. // Make sure sceneB will not accept this avatar.
  166. sceneB.RegionInfo.EstateSettings.PublicAccess = false;
  167. ScenePresence originalSp = SceneHelpers.AddScenePresence(sceneA, tc, acd);
  168. originalSp.AbsolutePosition = new Vector3(128, 32, 10);
  169. AgentUpdateArgs moveArgs = new AgentUpdateArgs();
  170. //moveArgs.BodyRotation = Quaternion.CreateFromEulers(Vector3.Zero);
  171. moveArgs.BodyRotation = Quaternion.CreateFromEulers(new Vector3(0, 0, (float)-(Math.PI / 2)));
  172. moveArgs.ControlFlags = (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS;
  173. moveArgs.SessionID = acd.SessionID;
  174. originalSp.HandleAgentUpdate(originalSp.ControllingClient, moveArgs);
  175. sceneA.Update(1);
  176. // Console.WriteLine("Second pos {0}", originalSp.AbsolutePosition);
  177. // FIXME: This is a sufficient number of updates to for the presence to reach the northern border.
  178. // But really we want to do this in a more robust way.
  179. for (int i = 0; i < 100; i++)
  180. {
  181. sceneA.Update(1);
  182. // Console.WriteLine("Pos {0}", originalSp.AbsolutePosition);
  183. }
  184. // sceneA agent should still be root
  185. ScenePresence spAfterCrossSceneA = sceneA.GetScenePresence(originalSp.UUID);
  186. Assert.That(spAfterCrossSceneA.IsChildAgent, Is.False);
  187. ScenePresence spAfterCrossSceneB = sceneB.GetScenePresence(originalSp.UUID);
  188. // sceneB agent should also still be root
  189. Assert.That(spAfterCrossSceneB.IsChildAgent, Is.True);
  190. // sceneB should ignore unauthorized attempt to upgrade agent to root
  191. TestClient sceneBTc = ((TestClient)spAfterCrossSceneB.ControllingClient);
  192. int agentMovementCompleteReceived = 0;
  193. sceneBTc.OnReceivedMoveAgentIntoRegion += (ri, pos, look) => agentMovementCompleteReceived++;
  194. sceneBTc.CompleteMovement();
  195. Assert.That(agentMovementCompleteReceived, Is.EqualTo(0));
  196. Assert.That(spAfterCrossSceneB.IsChildAgent, Is.True);
  197. }
  198. }
  199. }