ScenePresenceAgentTests.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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 System.Text;
  31. using System.Threading;
  32. using System.Timers;
  33. using Timer = System.Timers.Timer;
  34. using Nini.Config;
  35. using NUnit.Framework;
  36. using OpenMetaverse;
  37. using OpenSim.Framework;
  38. using OpenSim.Framework.Communications;
  39. using OpenSim.Region.Framework.Scenes;
  40. using OpenSim.Region.Framework.Interfaces;
  41. using OpenSim.Region.ClientStack.Linden;
  42. using OpenSim.Region.CoreModules.Framework.EntityTransfer;
  43. using OpenSim.Region.CoreModules.World.Serialiser;
  44. using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
  45. using OpenSim.Tests.Common;
  46. using OpenSim.Tests.Common.Mock;
  47. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  48. namespace OpenSim.Region.Framework.Scenes.Tests
  49. {
  50. /// <summary>
  51. /// Scene presence tests
  52. /// </summary>
  53. [TestFixture]
  54. public class ScenePresenceAgentTests : OpenSimTestCase
  55. {
  56. // public Scene scene, scene2, scene3;
  57. // public UUID agent1, agent2, agent3;
  58. // public static Random random;
  59. // public ulong region1, region2, region3;
  60. // public AgentCircuitData acd1;
  61. // public TestClient testclient;
  62. // [TestFixtureSetUp]
  63. // public void Init()
  64. // {
  65. //// TestHelpers.InMethod();
  66. ////
  67. //// SceneHelpers sh = new SceneHelpers();
  68. ////
  69. //// scene = sh.SetupScene("Neighbour x", UUID.Random(), 1000, 1000);
  70. //// scene2 = sh.SetupScene("Neighbour x+1", UUID.Random(), 1001, 1000);
  71. //// scene3 = sh.SetupScene("Neighbour x-1", UUID.Random(), 999, 1000);
  72. ////
  73. //// ISharedRegionModule interregionComms = new LocalSimulationConnectorModule();
  74. //// interregionComms.Initialise(new IniConfigSource());
  75. //// interregionComms.PostInitialise();
  76. //// SceneHelpers.SetupSceneModules(scene, new IniConfigSource(), interregionComms);
  77. //// SceneHelpers.SetupSceneModules(scene2, new IniConfigSource(), interregionComms);
  78. //// SceneHelpers.SetupSceneModules(scene3, new IniConfigSource(), interregionComms);
  79. //
  80. //// agent1 = UUID.Random();
  81. //// agent2 = UUID.Random();
  82. //// agent3 = UUID.Random();
  83. //
  84. //// region1 = scene.RegionInfo.RegionHandle;
  85. //// region2 = scene2.RegionInfo.RegionHandle;
  86. //// region3 = scene3.RegionInfo.RegionHandle;
  87. // }
  88. [Test]
  89. public void TestCreateRootScenePresence()
  90. {
  91. TestHelpers.InMethod();
  92. // TestHelpers.EnableLogging();
  93. UUID spUuid = TestHelpers.ParseTail(0x1);
  94. TestScene scene = new SceneHelpers().SetupScene();
  95. SceneHelpers.AddScenePresence(scene, spUuid);
  96. Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(spUuid), Is.Not.Null);
  97. Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1));
  98. ScenePresence sp = scene.GetScenePresence(spUuid);
  99. Assert.That(sp, Is.Not.Null);
  100. Assert.That(sp.IsChildAgent, Is.False);
  101. Assert.That(sp.UUID, Is.EqualTo(spUuid));
  102. Assert.That(scene.GetScenePresences().Count, Is.EqualTo(1));
  103. }
  104. [Test]
  105. public void TestCreateDuplicateRootScenePresence()
  106. {
  107. TestHelpers.InMethod();
  108. // TestHelpers.EnableLogging();
  109. UUID spUuid = TestHelpers.ParseTail(0x1);
  110. // The etm is only invoked by this test to check whether an agent is still in transit if there is a dupe
  111. EntityTransferModule etm = new EntityTransferModule();
  112. IConfigSource config = new IniConfigSource();
  113. IConfig modulesConfig = config.AddConfig("Modules");
  114. modulesConfig.Set("EntityTransferModule", etm.Name);
  115. IConfig entityTransferConfig = config.AddConfig("EntityTransfer");
  116. // In order to run a single threaded regression test we do not want the entity transfer module waiting
  117. // for a callback from the destination scene before removing its avatar data.
  118. entityTransferConfig.Set("wait_for_callback", false);
  119. TestScene scene = new SceneHelpers().SetupScene();
  120. SceneHelpers.SetupSceneModules(scene, config, etm);
  121. SceneHelpers.AddScenePresence(scene, spUuid);
  122. SceneHelpers.AddScenePresence(scene, spUuid);
  123. Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(spUuid), Is.Not.Null);
  124. Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1));
  125. ScenePresence sp = scene.GetScenePresence(spUuid);
  126. Assert.That(sp, Is.Not.Null);
  127. Assert.That(sp.IsChildAgent, Is.False);
  128. Assert.That(sp.UUID, Is.EqualTo(spUuid));
  129. }
  130. [Test]
  131. public void TestCloseAgent()
  132. {
  133. TestHelpers.InMethod();
  134. // TestHelpers.EnableLogging();
  135. TestScene scene = new SceneHelpers().SetupScene();
  136. ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
  137. scene.IncomingCloseAgent(sp.UUID, false);
  138. Assert.That(scene.GetScenePresence(sp.UUID), Is.Null);
  139. Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(sp.UUID), Is.Null);
  140. Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(0));
  141. // TestHelpers.DisableLogging();
  142. }
  143. [Test]
  144. public void TestCreateChildScenePresence()
  145. {
  146. TestHelpers.InMethod();
  147. // log4net.Config.XmlConfigurator.Configure();
  148. LocalSimulationConnectorModule lsc = new LocalSimulationConnectorModule();
  149. IConfigSource configSource = new IniConfigSource();
  150. IConfig config = configSource.AddConfig("Modules");
  151. config.Set("SimulationServices", "LocalSimulationConnectorModule");
  152. SceneHelpers sceneHelpers = new SceneHelpers();
  153. TestScene scene = sceneHelpers.SetupScene();
  154. SceneHelpers.SetupSceneModules(scene, configSource, lsc);
  155. UUID agentId = TestHelpers.ParseTail(0x01);
  156. AgentCircuitData acd = SceneHelpers.GenerateAgentData(agentId);
  157. acd.child = true;
  158. GridRegion region = scene.GridService.GetRegionByName(UUID.Zero, scene.RegionInfo.RegionName);
  159. string reason;
  160. // *** This is the first stage, when a neighbouring region is told that a viewer is about to try and
  161. // establish a child scene presence. We pass in the circuit code that the client has to connect with ***
  162. // XXX: ViaLogin may not be correct here.
  163. scene.SimulationService.CreateAgent(region, acd, (uint)TeleportFlags.ViaLogin, out reason);
  164. Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(agentId), Is.Not.Null);
  165. Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1));
  166. // There's no scene presence yet since only an agent circuit has been established.
  167. Assert.That(scene.GetScenePresence(agentId), Is.Null);
  168. // *** This is the second stage, where the client established a child agent/scene presence using the
  169. // circuit code given to the scene in stage 1 ***
  170. TestClient client = new TestClient(acd, scene);
  171. scene.AddNewClient(client, PresenceType.User);
  172. Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(agentId), Is.Not.Null);
  173. Assert.That(scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1));
  174. ScenePresence sp = scene.GetScenePresence(agentId);
  175. Assert.That(sp, Is.Not.Null);
  176. Assert.That(sp.UUID, Is.EqualTo(agentId));
  177. Assert.That(sp.IsChildAgent, Is.True);
  178. }
  179. /// <summary>
  180. /// Test that if a root agent logs into a region, a child agent is also established in the neighbouring region
  181. /// </summary>
  182. /// <remarks>
  183. /// Please note that unlike the other tests here, this doesn't rely on anything set up in the instance fields.
  184. /// INCOMPLETE
  185. /// </remarks>
  186. [Test]
  187. public void TestChildAgentEstablishedInNeighbour()
  188. {
  189. TestHelpers.InMethod();
  190. // log4net.Config.XmlConfigurator.Configure();
  191. // UUID agent1Id = UUID.Parse("00000000-0000-0000-0000-000000000001");
  192. TestScene myScene1 = new SceneHelpers().SetupScene("Neighbour y", UUID.Random(), 1000, 1000);
  193. TestScene myScene2 = new SceneHelpers().SetupScene("Neighbour y + 1", UUID.Random(), 1001, 1000);
  194. IConfigSource configSource = new IniConfigSource();
  195. IConfig config = configSource.AddConfig("Startup");
  196. config.Set("serverside_object_permissions", true);
  197. config.Set("EventQueue", true);
  198. EntityTransferModule etm = new EntityTransferModule();
  199. EventQueueGetModule eqgm1 = new EventQueueGetModule();
  200. SceneHelpers.SetupSceneModules(myScene1, configSource, etm, eqgm1);
  201. EventQueueGetModule eqgm2 = new EventQueueGetModule();
  202. SceneHelpers.SetupSceneModules(myScene2, configSource, etm, eqgm2);
  203. // SceneHelpers.AddScenePresence(myScene1, agent1Id);
  204. // ScenePresence childPresence = myScene2.GetScenePresence(agent1);
  205. //
  206. // // TODO: Need to do a fair amount of work to allow synchronous establishment of child agents
  207. // Assert.That(childPresence, Is.Not.Null);
  208. // Assert.That(childPresence.IsChildAgent, Is.True);
  209. }
  210. // /// <summary>
  211. // /// Test adding a root agent to a scene. Doesn't yet actually complete crossing the agent into the scene.
  212. // /// </summary>
  213. // [Test]
  214. // public void T010_TestAddRootAgent()
  215. // {
  216. // TestHelpers.InMethod();
  217. //
  218. // string firstName = "testfirstname";
  219. //
  220. // AgentCircuitData agent = new AgentCircuitData();
  221. // agent.AgentID = agent1;
  222. // agent.firstname = firstName;
  223. // agent.lastname = "testlastname";
  224. // agent.SessionID = UUID.Random();
  225. // agent.SecureSessionID = UUID.Random();
  226. // agent.circuitcode = 123;
  227. // agent.BaseFolder = UUID.Zero;
  228. // agent.InventoryFolder = UUID.Zero;
  229. // agent.startpos = Vector3.Zero;
  230. // agent.CapsPath = GetRandomCapsObjectPath();
  231. // agent.ChildrenCapSeeds = new Dictionary<ulong, string>();
  232. // agent.child = true;
  233. //
  234. // scene.PresenceService.LoginAgent(agent.AgentID.ToString(), agent.SessionID, agent.SecureSessionID);
  235. //
  236. // string reason;
  237. // scene.NewUserConnection(agent, (uint)TeleportFlags.ViaLogin, out reason);
  238. // testclient = new TestClient(agent, scene);
  239. // scene.AddNewClient(testclient);
  240. //
  241. // ScenePresence presence = scene.GetScenePresence(agent1);
  242. //
  243. // Assert.That(presence, Is.Not.Null, "presence is null");
  244. // Assert.That(presence.Firstname, Is.EqualTo(firstName), "First name not same");
  245. // acd1 = agent;
  246. // }
  247. //
  248. // /// <summary>
  249. // /// Test removing an uncrossed root agent from a scene.
  250. // /// </summary>
  251. // [Test]
  252. // public void T011_TestRemoveRootAgent()
  253. // {
  254. // TestHelpers.InMethod();
  255. //
  256. // scene.RemoveClient(agent1);
  257. //
  258. // ScenePresence presence = scene.GetScenePresence(agent1);
  259. //
  260. // Assert.That(presence, Is.Null, "presence is not null");
  261. // }
  262. }
  263. }