OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
SceneHelpers.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.Net;
30 using System.Collections.Generic;
31 using Nini.Config;
32 using OpenMetaverse;
33 using OpenSim.Data.Null;
34 using OpenSim.Framework;
35 
36 using OpenSim.Framework.Console;
37 using OpenSim.Framework.Servers;
38 using OpenSim.Framework.Servers.HttpServer;
39 using OpenSim.Region.PhysicsModules.SharedBase;
40 using OpenSim.Region.Framework;
41 using OpenSim.Region.Framework.Interfaces;
42 using OpenSim.Region.Framework.Scenes;
43 using OpenSim.Region.CoreModules.Avatar.Gods;
44 using OpenSim.Region.CoreModules.Asset;
45 using OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset;
46 using OpenSim.Region.CoreModules.ServiceConnectorsOut.Authentication;
47 using OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory;
48 using OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid;
49 using OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts;
50 using OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence;
51 using OpenSim.Region.PhysicsModule.BasicPhysics;
52 using OpenSim.Services.Interfaces;
54 
55 namespace OpenSim.Tests.Common
56 {
60  public class SceneHelpers
61  {
65  public SceneManager SceneManager { get; private set; }
66 
67  public ISimulationDataService SimDataService { get; private set; }
68 
69  private AgentCircuitManager m_acm = new AgentCircuitManager();
70  private IEstateDataService m_estateDataService = null;
71 
72  private LocalAssetServicesConnector m_assetService;
73  private LocalAuthenticationServicesConnector m_authenticationService;
74  private LocalInventoryServicesConnector m_inventoryService;
75  private LocalGridServicesConnector m_gridService;
76  private LocalUserAccountServicesConnector m_userAccountService;
77  private LocalPresenceServicesConnector m_presenceService;
78 
79  private CoreAssetCache m_cache;
80 
81  private PhysicsScene m_physicsScene;
82 
83  public SceneHelpers() : this(null) {}
84 
86  {
87  SceneManager = new SceneManager();
88 
89  m_assetService = StartAssetService(cache);
90  m_authenticationService = StartAuthenticationService();
91  m_inventoryService = StartInventoryService();
92  m_gridService = StartGridService();
93  m_userAccountService = StartUserAccountService();
94  m_presenceService = StartPresenceService();
95 
96  m_inventoryService.PostInitialise();
97  m_assetService.PostInitialise();
98  m_userAccountService.PostInitialise();
99  m_presenceService.PostInitialise();
100 
101  m_cache = cache;
102 
103  m_physicsScene = StartPhysicsScene();
104 
105  SimDataService
106  = OpenSim.Server.Base.ServerUtils.LoadPlugin<ISimulationDataService>("OpenSim.Tests.Common.dll", null);
107  }
108 
117  {
118  return SetupScene("Unit test region", UUID.Random(), 1000, 1000);
119  }
120 
121  public TestScene SetupScene(string name, UUID id, uint x, uint y)
122  {
123  return SetupScene(name, id, x, y, new IniConfigSource());
124  }
125 
126  public TestScene SetupScene(string name, UUID id, uint x, uint y, IConfigSource configSource)
127  {
128  return SetupScene(name, id, x, y, Constants.RegionSize, Constants.RegionSize, configSource);
129  }
130 
143  string name, UUID id, uint x, uint y, uint sizeX, uint sizeY, IConfigSource configSource)
144  {
145  Console.WriteLine("Setting up test scene {0}", name);
146 
147  // We must set up a console otherwise setup of some modules may fail
148  MainConsole.Instance = new MockConsole();
149 
150  RegionInfo regInfo = new RegionInfo(x, y, new IPEndPoint(IPAddress.Loopback, 9000), "127.0.0.1");
151  regInfo.RegionName = name;
152  regInfo.RegionID = id;
153  regInfo.RegionSizeX = sizeX;
154  regInfo.RegionSizeY = sizeY;
155 
156  TestScene testScene = new TestScene(
157  regInfo, m_acm, SimDataService, m_estateDataService, configSource, null);
158 
159  INonSharedRegionModule godsModule = new GodsModule();
160  godsModule.Initialise(new IniConfigSource());
161  godsModule.AddRegion(testScene);
162 
163  // Add scene to physics
164  ((INonSharedRegionModule)m_physicsScene).AddRegion(testScene);
165  ((INonSharedRegionModule)m_physicsScene).RegionLoaded(testScene);
166 
167  // Add scene to services
168  m_assetService.AddRegion(testScene);
169 
170  if (m_cache != null)
171  {
172  m_cache.AddRegion(testScene);
173  m_cache.RegionLoaded(testScene);
174  testScene.AddRegionModule(m_cache.Name, m_cache);
175  }
176 
177  m_assetService.RegionLoaded(testScene);
178  testScene.AddRegionModule(m_assetService.Name, m_assetService);
179 
180  m_authenticationService.AddRegion(testScene);
181  m_authenticationService.RegionLoaded(testScene);
182  testScene.AddRegionModule(m_authenticationService.Name, m_authenticationService);
183 
184  m_inventoryService.AddRegion(testScene);
185  m_inventoryService.RegionLoaded(testScene);
186  testScene.AddRegionModule(m_inventoryService.Name, m_inventoryService);
187 
188  m_gridService.AddRegion(testScene);
189  m_gridService.RegionLoaded(testScene);
190  testScene.AddRegionModule(m_gridService.Name, m_gridService);
191 
192  m_userAccountService.AddRegion(testScene);
193  m_userAccountService.RegionLoaded(testScene);
194  testScene.AddRegionModule(m_userAccountService.Name, m_userAccountService);
195 
196  m_presenceService.AddRegion(testScene);
197  m_presenceService.RegionLoaded(testScene);
198  testScene.AddRegionModule(m_presenceService.Name, m_presenceService);
199 
200  testScene.RegionInfo.EstateSettings.EstateOwner = UUID.Random();
201  testScene.SetModuleInterfaces();
202 
203  testScene.LandChannel = new TestLandChannel(testScene);
204  testScene.LoadWorldMap();
205 
206  testScene.RegionInfo.EstateSettings = new EstateSettings();
207  testScene.LoginsEnabled = true;
208  testScene.RegisterRegionWithGrid();
209 
210  SceneManager.Add(testScene);
211 
212  return testScene;
213  }
214 
215  private static LocalAssetServicesConnector StartAssetService(CoreAssetCache cache)
216  {
217  IConfigSource config = new IniConfigSource();
218  config.AddConfig("Modules");
219  config.Configs["Modules"].Set("AssetServices", "LocalAssetServicesConnector");
220  config.AddConfig("AssetService");
221  config.Configs["AssetService"].Set("LocalServiceModule", "OpenSim.Services.AssetService.dll:AssetService");
222  config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
223 
225  assetService.Initialise(config);
226 
227  if (cache != null)
228  {
229  IConfigSource cacheConfig = new IniConfigSource();
230  cacheConfig.AddConfig("Modules");
231  cacheConfig.Configs["Modules"].Set("AssetCaching", "CoreAssetCache");
232  cacheConfig.AddConfig("AssetCache");
233 
234  cache.Initialise(cacheConfig);
235  }
236 
237  return assetService;
238  }
239 
240  private static LocalAuthenticationServicesConnector StartAuthenticationService()
241  {
242  IConfigSource config = new IniConfigSource();
243  config.AddConfig("Modules");
244  config.AddConfig("AuthenticationService");
245  config.Configs["Modules"].Set("AuthenticationServices", "LocalAuthenticationServicesConnector");
246  config.Configs["AuthenticationService"].Set(
247  "LocalServiceModule", "OpenSim.Services.AuthenticationService.dll:PasswordAuthenticationService");
248  config.Configs["AuthenticationService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
249 
251  service.Initialise(config);
252 
253  return service;
254  }
255 
256  private static LocalInventoryServicesConnector StartInventoryService()
257  {
258  IConfigSource config = new IniConfigSource();
259  config.AddConfig("Modules");
260  config.AddConfig("InventoryService");
261  config.Configs["Modules"].Set("InventoryServices", "LocalInventoryServicesConnector");
262  config.Configs["InventoryService"].Set("LocalServiceModule", "OpenSim.Services.InventoryService.dll:XInventoryService");
263  config.Configs["InventoryService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
264 
266  inventoryService.Initialise(config);
267 
268  return inventoryService;
269  }
270 
271  private static LocalGridServicesConnector StartGridService()
272  {
273  IConfigSource config = new IniConfigSource();
274  config.AddConfig("Modules");
275  config.AddConfig("GridService");
276  config.Configs["Modules"].Set("GridServices", "LocalGridServicesConnector");
277  config.Configs["GridService"].Set("StorageProvider", "OpenSim.Data.Null.dll:NullRegionData");
278  config.Configs["GridService"].Set("LocalServiceModule", "OpenSim.Services.GridService.dll:GridService");
279  config.Configs["GridService"].Set("ConnectionString", "!static");
280 
282  gridService.Initialise(config);
283 
284  return gridService;
285  }
286 
292  private static LocalUserAccountServicesConnector StartUserAccountService()
293  {
294  IConfigSource config = new IniConfigSource();
295  config.AddConfig("Modules");
296  config.AddConfig("UserAccountService");
297  config.Configs["Modules"].Set("UserAccountServices", "LocalUserAccountServicesConnector");
298  config.Configs["UserAccountService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
299  config.Configs["UserAccountService"].Set(
300  "LocalServiceModule", "OpenSim.Services.UserAccountService.dll:UserAccountService");
301 
303  userAccountService.Initialise(config);
304 
305  return userAccountService;
306  }
307 
312  private static LocalPresenceServicesConnector StartPresenceService()
313  {
314  // Unfortunately, some services share data via statics, so we need to null every time to stop interference
315  // between tests.
316  // This is a massive non-obvious pita.
317  NullPresenceData.Instance = null;
318 
319  IConfigSource config = new IniConfigSource();
320  config.AddConfig("Modules");
321  config.AddConfig("PresenceService");
322  config.Configs["Modules"].Set("PresenceServices", "LocalPresenceServicesConnector");
323  config.Configs["PresenceService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
324  config.Configs["PresenceService"].Set(
325  "LocalServiceModule", "OpenSim.Services.PresenceService.dll:PresenceService");
326 
328  presenceService.Initialise(config);
329 
330  return presenceService;
331  }
332 
333  private static PhysicsScene StartPhysicsScene()
334  {
335  IConfigSource config = new IniConfigSource();
336  config.AddConfig("Startup");
337  config.Configs["Startup"].Set("physics", "basicphysics");
338 
339  PhysicsScene pScene = new BasicScene();
341  mod.Initialise(config);
342 
343  return pScene;
344  }
345 
351  public static void SetupSceneModules(Scene scene, params object[] modules)
352  {
353  SetupSceneModules(scene, new IniConfigSource(), modules);
354  }
355 
365  public static void SetupSceneModules(Scene scene, IConfigSource config, params object[] modules)
366  {
367  SetupSceneModules(new Scene[] { scene }, config, modules);
368  }
369 
375  public static void SetupSceneModules(Scene[] scenes, params object[] modules)
376  {
377  SetupSceneModules(scenes, new IniConfigSource(), modules);
378  }
379 
393  public static void SetupSceneModules(Scene[] scenes, IConfigSource config, params object[] modules)
394  {
395  List<IRegionModuleBase> newModules = new List<IRegionModuleBase>();
396  foreach (object module in modules)
397  {
399 // Console.WriteLine("MODULE {0}", m.Name);
400  m.Initialise(config);
401  newModules.Add(m);
402  }
403 
404  foreach (IRegionModuleBase module in newModules)
405  {
406  if (module is ISharedRegionModule) ((ISharedRegionModule)module).PostInitialise();
407  }
408 
409  foreach (IRegionModuleBase module in newModules)
410  {
411  foreach (Scene scene in scenes)
412  {
413  module.AddRegion(scene);
414  scene.AddRegionModule(module.Name, module);
415  }
416  }
417 
418  // RegionLoaded is fired after all modules have been appropriately added to all scenes
419  foreach (IRegionModuleBase module in newModules)
420  foreach (Scene scene in scenes)
421  module.RegionLoaded(scene);
422 
423  foreach (Scene scene in scenes) { scene.SetModuleInterfaces(); }
424  }
425 
431  public static AgentCircuitData GenerateAgentData(UUID agentId)
432  {
433  AgentCircuitData acd = GenerateCommonAgentData();
434 
435  acd.AgentID = agentId;
436  acd.firstname = "testfirstname";
437  acd.lastname = "testlastname";
438  acd.ServiceURLs = new Dictionary<string, object>();
439 
440  return acd;
441  }
442 
449  {
450  AgentCircuitData acd = GenerateCommonAgentData();
451 
452  acd.AgentID = ua.PrincipalID;
453  acd.firstname = ua.FirstName;
454  acd.lastname = ua.LastName;
455  acd.ServiceURLs = ua.ServiceURLs;
456 
457  return acd;
458  }
459 
460  private static AgentCircuitData GenerateCommonAgentData()
461  {
463 
464  // XXX: Sessions must be unique, otherwise one presence can overwrite another in NullPresenceData.
465  acd.SessionID = UUID.Random();
466  acd.SecureSessionID = UUID.Random();
467 
468  acd.circuitcode = 123;
469  acd.BaseFolder = UUID.Zero;
470  acd.InventoryFolder = UUID.Zero;
471  acd.startpos = Vector3.Zero;
472  acd.CapsPath = "http://wibble.com";
473  acd.Appearance = new AvatarAppearance();
474 
475  return acd;
476  }
477 
488  public static ScenePresence AddScenePresence(Scene scene, UUID agentId)
489  {
490  return AddScenePresence(scene, GenerateAgentData(agentId));
491  }
492 
500  {
501  return AddScenePresence(scene, GenerateAgentData(ua));
502  }
503 
522  public static ScenePresence AddScenePresence(Scene scene, AgentCircuitData agentData)
523  {
524  return AddScenePresence(scene, new TestClient(agentData, scene), agentData);
525  }
526 
546  Scene scene, IClientAPI client, AgentCircuitData agentData)
547  {
548  // We emulate the proper login sequence here by doing things in four stages
549 
550  // Stage 0: login
551  // We need to punch through to the underlying service because scene will not, correctly, let us call it
552  // through it's reference to the LPSC
554  lpsc.m_PresenceService.LoginAgent(agentData.AgentID.ToString(), agentData.SessionID, agentData.SecureSessionID);
555 
556  // Stages 1 & 2
557  ScenePresence sp = IntroduceClientToScene(scene, client, agentData, TeleportFlags.ViaLogin);
558 
559  // Stage 3: Complete the entrance into the region. This converts the child agent into a root agent.
560  sp.CompleteMovement(sp.ControllingClient, true);
561 
562  return sp;
563  }
564 
573  private static ScenePresence IntroduceClientToScene(
574  Scene scene, IClientAPI client, AgentCircuitData agentData, TeleportFlags tf)
575  {
576  string reason;
577 
578  // Stage 1: tell the scene to expect a new user connection
579  if (!scene.NewUserConnection(agentData, (uint)tf, null, out reason))
580  Console.WriteLine("NewUserConnection failed: " + reason);
581 
582  // Stage 2: add the new client as a child agent to the scene
583  scene.AddNewAgent(client, PresenceType.User);
584 
585  return scene.GetScenePresence(client.AgentId);
586  }
587 
588  public static ScenePresence AddChildScenePresence(Scene scene, UUID agentId)
589  {
590  return AddChildScenePresence(scene, GenerateAgentData(agentId));
591  }
592 
594  {
595  acd.child = true;
596 
597  // XXX: ViaLogin may not be correct for child agents
598  TestClient client = new TestClient(acd, scene);
599  return IntroduceClientToScene(scene, client, acd, TeleportFlags.ViaLogin);
600  }
601 
607  public static SceneObjectGroup AddSceneObject(Scene scene)
608  {
609  return AddSceneObject(scene, "Test Object", UUID.Random());
610  }
611 
619  public static SceneObjectGroup AddSceneObject(Scene scene, string name, UUID ownerId)
620  {
621  SceneObjectGroup so = new SceneObjectGroup(CreateSceneObjectPart(name, UUID.Random(), ownerId));
622 
623  //part.UpdatePrimFlags(false, false, true);
624  //part.ObjectFlags |= (uint)PrimFlags.Phantom;
625 
626  scene.AddNewSceneObject(so, true);
627 
628  return so;
629  }
630 
648  public static SceneObjectGroup AddSceneObject(Scene scene, int parts, UUID ownerId, string partNamePrefix, int uuidTail)
649  {
650  SceneObjectGroup so = CreateSceneObject(parts, ownerId, partNamePrefix, uuidTail);
651 
652  scene.AddNewSceneObject(so, false);
653 
654  return so;
655  }
656 
664  public static SceneObjectPart CreateSceneObjectPart(string name, UUID id, UUID ownerId)
665  {
666  return new SceneObjectPart(
667  ownerId, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
668  { Name = name, UUID = id, Scale = new Vector3(1, 1, 1) };
669  }
670 
682  public static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId)
683  {
684  return CreateSceneObject(parts, ownerId, 0x1);
685  }
686 
697  public static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId, int uuidTail)
698  {
699  return CreateSceneObject(parts, ownerId, "", uuidTail);
700  }
701 
718  public static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId, string partNamePrefix, int uuidTail)
719  {
720  string rawSogId = string.Format("00000000-0000-0000-0000-{0:X12}", uuidTail);
721 
722  SceneObjectGroup sog
723  = new SceneObjectGroup(
724  CreateSceneObjectPart(string.Format("{0}Part1", partNamePrefix), new UUID(rawSogId), ownerId));
725 
726  if (parts > 1)
727  for (int i = 2; i <= parts; i++)
728  sog.AddPart(
729  CreateSceneObjectPart(
730  string.Format("{0}Part{1}", partNamePrefix, i),
731  new UUID(string.Format("00000000-0000-0000-0000-{0:X12}", uuidTail + i - 1)),
732  ownerId));
733 
734  return sog;
735  }
736  }
737 }
static void SetupSceneModules(Scene[] scenes, params object[] modules)
Setup modules for a scene using their default settings.
static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId)
Create a scene object but do not add it to the scene.
static SceneObjectGroup AddSceneObject(Scene scene, int parts, UUID ownerId, string partNamePrefix, int uuidTail)
Add a test object
static void SetupSceneModules(Scene scene, params object[] modules)
Setup modules for a scene using their default settings.
OpenSim.Framework.Constants.TeleportFlags TeleportFlags
static ScenePresence AddScenePresence(Scene scene, IClientAPI client, AgentCircuitData agentData)
Add a root agent.
TestScene SetupScene(string name, UUID id, uint x, uint y)
OpenSim.Framework.RegionInfo RegionInfo
static void SetupSceneModules(Scene scene, IConfigSource config, params object[] modules)
Setup modules for a scene.
Contains the Avatar's Appearance and methods to manipulate the appearance.
TestScene SetupScene(string name, UUID id, uint x, uint y, IConfigSource configSource)
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId, string partNamePrefix, int uuidTail)
Create a scene object but do not add it to the scene.
OpenSim.Services.Interfaces.GridRegion GridRegion
Definition: SceneHelpers.cs:53
TestScene SetupScene(string name, UUID id, uint x, uint y, uint sizeX, uint sizeY, IConfigSource configSource)
Set up a scene.
static SceneObjectPart CreateSceneObjectPart(string name, UUID id, UUID ownerId)
Create a scene object part.
bool LoginAgent(string userID, UUID sessionID, UUID secureSessionID)
Store session information.
static SceneObjectGroup AddSceneObject(Scene scene, string name, UUID ownerId)
Add a test object
static ScenePresence AddChildScenePresence(Scene scene, AgentCircuitData acd)
SceneHelpers(CoreAssetCache cache)
Definition: SceneHelpers.cs:85
static SceneObjectGroup AddSceneObject(Scene scene)
Add a test object
Circuit data for an agent. Connection information shared between regions that accept UDP connections ...
Manager for adding, closing and restarting scenes.
Definition: SceneManager.cs:44
static AgentCircuitData GenerateAgentData(UUID agentId)
Generate some standard agent connection data.
bool NewUserConnection(AgentCircuitData agent, uint teleportFlags, GridRegion source, out string reason)
Do the work necessary to initiate a new user connection for a particular scene.
Definition: Scene.cs:3949
static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId, int uuidTail)
Create a scene object but do not add it to the scene.
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60
IPresenceService PresenceService
Definition: Scene.cs:722
This is a Fake console that's used when setting up the Scene in Unit Tests Don't use this except for ...
Definition: MockConsole.cs:41
This is an incomplete extremely basic physics implementation
TestScene SetupScene()
Set up a test scene
static ScenePresence AddScenePresence(Scene scene, AgentCircuitData agentData)
Add a root agent.
IPresenceService m_PresenceService
Underlying presence service. Do not use directly.
static ScenePresence AddScenePresence(Scene scene, UserAccount ua)
Add a root agent.
Land channel for test purposes
UUID AgentID
Avatar Unique Agent Identifier
static ScenePresence AddScenePresence(Scene scene, UUID agentId)
Add a root agent where the details of the agent connection (apart from the id) are unimportant for th...
static void SetupSceneModules(Scene[] scenes, IConfigSource config, params object[] modules)
Setup modules for scenes.
static AgentCircuitData GenerateAgentData(UserAccount ua)
Generate some standard agent connection data.
static ScenePresence AddChildScenePresence(Scene scene, UUID agentId)