1
0

ScenePresenceCrossingTests.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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.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.Region.OptionalModules.Avatar.XmlRpcGroups;
  42. using System.Threading;
  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 | AgentManager.ControlFlags.AGENT_CONTROL_FAST_AT);
  100. originalSp.HandleAgentUpdate(originalSp.ControllingClient, moveArgs);
  101. sceneA.Update(1);
  102. // Console.WriteLine("Second pos {0}", originalSp.AbsolutePosition);
  103. // FIXME: This is a sufficient number of updates to for the presence to reach the northern border.
  104. // But really we want to do this in a more robust way.
  105. for (int i = 0; i < 100; i++)
  106. {
  107. sceneA.Update(1);
  108. // Console.WriteLine("Pos {0}", originalSp.AbsolutePosition);
  109. }
  110. // Need to sort processing of EnableSimulator message on adding scene presences before we can test eqm
  111. // messages
  112. // Dictionary<UUID, List<TestEventQueueGetModule.Event>> eqmEvents = eqmA.Events;
  113. //
  114. // Assert.That(eqmEvents.Count, Is.EqualTo(1));
  115. // Assert.That(eqmEvents.ContainsKey(originalSp.UUID), Is.True);
  116. //
  117. // List<TestEventQueueGetModule.Event> spEqmEvents = eqmEvents[originalSp.UUID];
  118. //
  119. // Assert.That(spEqmEvents.Count, Is.EqualTo(1));
  120. // Assert.That(spEqmEvents[0].Name, Is.EqualTo("CrossRegion"));
  121. // sceneA should now only have a child agent
  122. ScenePresence spAfterCrossSceneA = sceneA.GetScenePresence(originalSp.UUID);
  123. Assert.That(spAfterCrossSceneA.IsChildAgent, Is.True);
  124. ScenePresence spAfterCrossSceneB = sceneB.GetScenePresence(originalSp.UUID);
  125. // Agent remains a child until the client triggers complete movement
  126. Assert.That(spAfterCrossSceneB.IsChildAgent, Is.True);
  127. TestClient sceneBTc = ((TestClient)spAfterCrossSceneB.ControllingClient);
  128. int agentMovementCompleteReceived = 0;
  129. sceneBTc.OnReceivedMoveAgentIntoRegion += (ri, pos, look) => agentMovementCompleteReceived++;
  130. sceneBTc.CompleteMovement();
  131. Assert.That(agentMovementCompleteReceived, Is.EqualTo(1));
  132. Assert.That(spAfterCrossSceneB.IsChildAgent, Is.False);
  133. }
  134. /// <summary>
  135. /// Test a cross attempt where the user can see into the neighbour but does not have permission to become
  136. /// root there.
  137. /// </summary>
  138. [Test]
  139. public void TestCrossOnSameSimulatorNoRootDestPerm()
  140. {
  141. TestHelpers.InMethod();
  142. // TestHelpers.EnableLogging();
  143. UUID userId = TestHelpers.ParseTail(0x1);
  144. EntityTransferModule etmA = new EntityTransferModule();
  145. EntityTransferModule etmB = new EntityTransferModule();
  146. LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
  147. IConfigSource config = new IniConfigSource();
  148. IConfig modulesConfig = config.AddConfig("Modules");
  149. modulesConfig.Set("EntityTransferModule", etmA.Name);
  150. modulesConfig.Set("SimulationServices", lscm.Name);
  151. SceneHelpers sh = new SceneHelpers();
  152. TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
  153. TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999);
  154. SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
  155. SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA);
  156. // We need to set up the permisions module on scene B so that our later use of agent limit to deny
  157. // QueryAccess won't succeed anyway because administrators are always allowed in and the default
  158. // IsAdministrator if no permissions module is present is true.
  159. SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), new DefaultPermissionsModule(), etmB);
  160. AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId);
  161. TestClient tc = new TestClient(acd, sceneA);
  162. List<TestClient> destinationTestClients = new List<TestClient>();
  163. EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients);
  164. // Make sure sceneB will not accept this avatar.
  165. sceneB.RegionInfo.EstateSettings.PublicAccess = false;
  166. ScenePresence originalSp = SceneHelpers.AddScenePresence(sceneA, tc, acd);
  167. originalSp.AbsolutePosition = new Vector3(128, 32, 10);
  168. AgentUpdateArgs moveArgs = new AgentUpdateArgs();
  169. //moveArgs.BodyRotation = Quaternion.CreateFromEulers(Vector3.Zero);
  170. moveArgs.BodyRotation = Quaternion.CreateFromEulers(new Vector3(0, 0, (float)-(Math.PI / 2)));
  171. moveArgs.ControlFlags = (uint)(AgentManager.ControlFlags.AGENT_CONTROL_AT_POS | AgentManager.ControlFlags.AGENT_CONTROL_FAST_AT);
  172. originalSp.HandleAgentUpdate(originalSp.ControllingClient, moveArgs);
  173. sceneA.Update(1);
  174. // Console.WriteLine("Second pos {0}", originalSp.AbsolutePosition);
  175. // FIXME: This is a sufficient number of updates to for the presence to reach the northern border.
  176. // But really we want to do this in a more robust way.
  177. for (int i = 0; i < 100; i++)
  178. {
  179. sceneA.Update(1);
  180. // Console.WriteLine("Pos {0}", originalSp.AbsolutePosition);
  181. }
  182. // sceneA agent should still be root
  183. ScenePresence spAfterCrossSceneA = sceneA.GetScenePresence(originalSp.UUID);
  184. Assert.That(spAfterCrossSceneA.IsChildAgent, Is.False);
  185. ScenePresence spAfterCrossSceneB = sceneB.GetScenePresence(originalSp.UUID);
  186. // sceneB agent should still be child
  187. Assert.That(spAfterCrossSceneB.IsChildAgent, Is.True);
  188. // sceneB should ignore unauthorized attempt to upgrade agent to root
  189. TestClient sceneBTc = ((TestClient)spAfterCrossSceneB.ControllingClient);
  190. int agentMovementCompleteReceived = 0;
  191. sceneBTc.OnReceivedMoveAgentIntoRegion += (ri, pos, look) => agentMovementCompleteReceived++;
  192. sceneBTc.CompleteMovement();
  193. Assert.That(agentMovementCompleteReceived, Is.EqualTo(0));
  194. Assert.That(spAfterCrossSceneB.IsChildAgent, Is.True);
  195. }
  196. }
  197. }