OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
ScenePresenceCrossingTests.cs
Go to the documentation of this file.
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 
28 using System;
29 using System.Collections.Generic;
30 using System.Reflection;
31 using Nini.Config;
32 using NUnit.Framework;
33 using OpenMetaverse;
34 using OpenSim.Framework;
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.Region.OptionalModules.Avatar.XmlRpcGroups;
43 using System.Threading;
44 
45 namespace OpenSim.Region.Framework.Scenes.Tests
46 {
47  [TestFixture]
49  {
50  [TestFixtureSetUp]
51  public void FixtureInit()
52  {
53  // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
54  Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
55  }
56 
57  [TestFixtureTearDown]
58  public void TearDown()
59  {
60  // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
61  // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
62  // tests really shouldn't).
63  Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
64  }
65 
66  [Test]
68  {
69  TestHelpers.InMethod();
70 // TestHelpers.EnableLogging();
71 
72  UUID userId = TestHelpers.ParseTail(0x1);
73 
74 // TestEventQueueGetModule eqmA = new TestEventQueueGetModule();
78 
79  IConfigSource config = new IniConfigSource();
80  IConfig modulesConfig = config.AddConfig("Modules");
81  modulesConfig.Set("EntityTransferModule", etmA.Name);
82  modulesConfig.Set("SimulationServices", lscm.Name);
83 // IConfig entityTransferConfig = config.AddConfig("EntityTransfer");
84 
85  // In order to run a single threaded regression test we do not want the entity transfer module waiting
86  // for a callback from the destination scene before removing its avatar data.
87 // entityTransferConfig.Set("wait_for_callback", false);
88 
89  SceneHelpers sh = new SceneHelpers();
90  TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
91  TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999);
92 
93  SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
94  SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA);
95 // SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA, eqmA);
96  SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), etmB);
97 
98  AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId);
99  TestClient tc = new TestClient(acd, sceneA);
100  List<TestClient> destinationTestClients = new List<TestClient>();
101  EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients);
102 
103  ScenePresence originalSp = SceneHelpers.AddScenePresence(sceneA, tc, acd);
104  originalSp.AbsolutePosition = new Vector3(128, 32, 10);
105 
106 // originalSp.Flying = true;
107 
108 // Console.WriteLine("First pos {0}", originalSp.AbsolutePosition);
109 
110 // eqmA.ClearEvents();
111 
112  AgentUpdateArgs moveArgs = new AgentUpdateArgs();
113  //moveArgs.BodyRotation = Quaternion.CreateFromEulers(Vector3.Zero);
114  moveArgs.BodyRotation = Quaternion.CreateFromEulers(new Vector3(0, 0, (float)-(Math.PI / 2)));
115  moveArgs.ControlFlags = (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS;
116  moveArgs.SessionID = acd.SessionID;
117 
118  originalSp.HandleAgentUpdate(originalSp.ControllingClient, moveArgs);
119 
120  sceneA.Update(1);
121 
122 // Console.WriteLine("Second pos {0}", originalSp.AbsolutePosition);
123 
124  // FIXME: This is a sufficient number of updates to for the presence to reach the northern border.
125  // But really we want to do this in a more robust way.
126  for (int i = 0; i < 100; i++)
127  {
128  sceneA.Update(1);
129 // Console.WriteLine("Pos {0}", originalSp.AbsolutePosition);
130  }
131 
132  // Need to sort processing of EnableSimulator message on adding scene presences before we can test eqm
133  // messages
134 // Dictionary<UUID, List<TestEventQueueGetModule.Event>> eqmEvents = eqmA.Events;
135 //
136 // Assert.That(eqmEvents.Count, Is.EqualTo(1));
137 // Assert.That(eqmEvents.ContainsKey(originalSp.UUID), Is.True);
138 //
139 // List<TestEventQueueGetModule.Event> spEqmEvents = eqmEvents[originalSp.UUID];
140 //
141 // Assert.That(spEqmEvents.Count, Is.EqualTo(1));
142 // Assert.That(spEqmEvents[0].Name, Is.EqualTo("CrossRegion"));
143 
144  // sceneA should now only have a child agent
145  ScenePresence spAfterCrossSceneA = sceneA.GetScenePresence(originalSp.UUID);
146  Assert.That(spAfterCrossSceneA.IsChildAgent, Is.True);
147 
148  ScenePresence spAfterCrossSceneB = sceneB.GetScenePresence(originalSp.UUID);
149 
150  // Agent remains a child until the client triggers complete movement
151  Assert.That(spAfterCrossSceneB.IsChildAgent, Is.True);
152 
153  TestClient sceneBTc = ((TestClient)spAfterCrossSceneB.ControllingClient);
154 
155  int agentMovementCompleteReceived = 0;
156  sceneBTc.OnReceivedMoveAgentIntoRegion += (ri, pos, look) => agentMovementCompleteReceived++;
157 
158  sceneBTc.CompleteMovement();
159 
160  Assert.That(agentMovementCompleteReceived, Is.EqualTo(1));
161  Assert.That(spAfterCrossSceneB.IsChildAgent, Is.False);
162  }
163 
168  [Test]
170  {
171  TestHelpers.InMethod();
172 // TestHelpers.EnableLogging();
173 
174  UUID userId = TestHelpers.ParseTail(0x1);
175 
179 
180  IConfigSource config = new IniConfigSource();
181  IConfig modulesConfig = config.AddConfig("Modules");
182  modulesConfig.Set("EntityTransferModule", etmA.Name);
183  modulesConfig.Set("SimulationServices", lscm.Name);
184 
185  SceneHelpers sh = new SceneHelpers();
186  TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000);
187  TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999);
188 
189  SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm);
190  SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA);
191 
192  // We need to set up the permisions module on scene B so that our later use of agent limit to deny
193  // QueryAccess won't succeed anyway because administrators are always allowed in and the default
194  // IsAdministrator if no permissions module is present is true.
195  SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), new DefaultPermissionsModule(), etmB);
196 
197  AgentCircuitData acd = SceneHelpers.GenerateAgentData(userId);
198  TestClient tc = new TestClient(acd, sceneA);
199  List<TestClient> destinationTestClients = new List<TestClient>();
200  EntityTransferHelpers.SetupInformClientOfNeighbourTriggersNeighbourClientCreate(tc, destinationTestClients);
201 
202  // Make sure sceneB will not accept this avatar.
203  sceneB.RegionInfo.EstateSettings.PublicAccess = false;
204 
205  ScenePresence originalSp = SceneHelpers.AddScenePresence(sceneA, tc, acd);
206  originalSp.AbsolutePosition = new Vector3(128, 32, 10);
207 
208  AgentUpdateArgs moveArgs = new AgentUpdateArgs();
209  //moveArgs.BodyRotation = Quaternion.CreateFromEulers(Vector3.Zero);
210  moveArgs.BodyRotation = Quaternion.CreateFromEulers(new Vector3(0, 0, (float)-(Math.PI / 2)));
211  moveArgs.ControlFlags = (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS;
212  moveArgs.SessionID = acd.SessionID;
213 
214  originalSp.HandleAgentUpdate(originalSp.ControllingClient, moveArgs);
215 
216  sceneA.Update(1);
217 
218 // Console.WriteLine("Second pos {0}", originalSp.AbsolutePosition);
219 
220  // FIXME: This is a sufficient number of updates to for the presence to reach the northern border.
221  // But really we want to do this in a more robust way.
222  for (int i = 0; i < 100; i++)
223  {
224  sceneA.Update(1);
225 // Console.WriteLine("Pos {0}", originalSp.AbsolutePosition);
226  }
227 
228  // sceneA agent should still be root
229  ScenePresence spAfterCrossSceneA = sceneA.GetScenePresence(originalSp.UUID);
230  Assert.That(spAfterCrossSceneA.IsChildAgent, Is.False);
231 
232  ScenePresence spAfterCrossSceneB = sceneB.GetScenePresence(originalSp.UUID);
233 
234  // sceneB agent should still be child
235  Assert.That(spAfterCrossSceneB.IsChildAgent, Is.True);
236 
237  // sceneB should ignore unauthorized attempt to upgrade agent to root
238  TestClient sceneBTc = ((TestClient)spAfterCrossSceneB.ControllingClient);
239 
240  int agentMovementCompleteReceived = 0;
241  sceneBTc.OnReceivedMoveAgentIntoRegion += (ri, pos, look) => agentMovementCompleteReceived++;
242 
243  sceneBTc.CompleteMovement();
244 
245  Assert.That(agentMovementCompleteReceived, Is.EqualTo(0));
246  Assert.That(spAfterCrossSceneB.IsChildAgent, Is.True);
247  }
248  }
249 }
Client provided parameters for avatar movement
Circuit data for an agent. Connection information shared between regions that accept UDP connections ...
void HandleAgentUpdate(IClientAPI remoteClient, AgentUpdateArgs agentData)
This is the event handler for client movement. If a client is moving, this event is triggering...
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60
void TestCrossOnSameSimulatorNoRootDestPerm()
Test a cross attempt where the user can see into the neighbour but does not have permission to become...