aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tests/Common/Helpers/SceneHelpers.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Tests/Common/Helpers/SceneHelpers.cs')
-rw-r--r--OpenSim/Tests/Common/Helpers/SceneHelpers.cs510
1 files changed, 510 insertions, 0 deletions
diff --git a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs
new file mode 100644
index 0000000..ea433a6
--- /dev/null
+++ b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs
@@ -0,0 +1,510 @@
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
28using System;
29using System.Net;
30using System.Collections.Generic;
31using Nini.Config;
32using OpenMetaverse;
33using OpenSim.Framework;
34using OpenSim.Framework.Communications;
35using OpenSim.Framework.Console;
36using OpenSim.Framework.Servers;
37using OpenSim.Framework.Servers.HttpServer;
38using OpenSim.Region.Physics.Manager;
39using OpenSim.Region.Framework;
40using OpenSim.Region.Framework.Interfaces;
41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Region.CoreModules.Avatar.Gods;
43using OpenSim.Region.CoreModules.Asset;
44using OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset;
45using OpenSim.Region.CoreModules.ServiceConnectorsOut.Authentication;
46using OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory;
47using OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid;
48using OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts;
49using OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence;
50using OpenSim.Services.Interfaces;
51using OpenSim.Tests.Common.Mock;
52
53namespace OpenSim.Tests.Common
54{
55 /// <summary>
56 /// Helpers for setting up scenes.
57 /// </summary>
58 public class SceneHelpers
59 {
60 public static TestScene SetupScene()
61 {
62 return SetupScene(null);
63 }
64
65 /// <summary>
66 /// Set up a test scene
67 /// </summary>
68 /// <remarks>
69 /// Automatically starts service threads, as would the normal runtime.
70 /// </remarks>
71 /// <returns></returns>
72 public static TestScene SetupScene(CoreAssetCache cache)
73 {
74 return SetupScene("Unit test region", UUID.Random(), 1000, 1000, cache);
75 }
76
77 public static TestScene SetupScene(string name, UUID id, uint x, uint y)
78 {
79 return SetupScene(name, id, x, y, null);
80 }
81
82 /// <summary>
83 /// Set up a scene. If it's more then one scene, use the same CommunicationsManager to link regions
84 /// or a different, to get a brand new scene with new shared region modules.
85 /// </summary>
86 /// <param name="name">Name of the region</param>
87 /// <param name="id">ID of the region</param>
88 /// <param name="x">X co-ordinate of the region</param>
89 /// <param name="y">Y co-ordinate of the region</param>
90 /// <param name="cm">This should be the same if simulating two scenes within a standalone</param>
91 /// <returns></returns>
92 public static TestScene SetupScene(string name, UUID id, uint x, uint y, CoreAssetCache cache)
93 {
94 Console.WriteLine("Setting up test scene {0}", name);
95
96 // We must set up a console otherwise setup of some modules may fail
97 MainConsole.Instance = new MockConsole("TEST PROMPT");
98
99 RegionInfo regInfo = new RegionInfo(x, y, new IPEndPoint(IPAddress.Loopback, 9000), "127.0.0.1");
100 regInfo.RegionName = name;
101 regInfo.RegionID = id;
102
103 AgentCircuitManager acm = new AgentCircuitManager();
104 SceneCommunicationService scs = new SceneCommunicationService();
105
106 ISimulationDataService simDataService = OpenSim.Server.Base.ServerUtils.LoadPlugin<ISimulationDataService>("OpenSim.Tests.Common.dll", null);
107 IEstateDataService estateDataService = null;
108 IConfigSource configSource = new IniConfigSource();
109
110 TestScene testScene = new TestScene(
111 regInfo, acm, scs, simDataService, estateDataService, null, false, false, false, configSource, null);
112
113 IRegionModule godsModule = new GodsModule();
114 godsModule.Initialise(testScene, new IniConfigSource());
115 testScene.AddModule(godsModule.Name, godsModule);
116
117 LocalAssetServicesConnector assetService = StartAssetService(testScene, cache);
118 StartAuthenticationService(testScene);
119 LocalInventoryServicesConnector inventoryService = StartInventoryService(testScene);
120 StartGridService(testScene);
121 LocalUserAccountServicesConnector userAccountService = StartUserAccountService(testScene);
122 LocalPresenceServicesConnector presenceService = StartPresenceService(testScene);
123
124 inventoryService.PostInitialise();
125 assetService.PostInitialise();
126 userAccountService.PostInitialise();
127 presenceService.PostInitialise();
128
129 testScene.RegionInfo.EstateSettings.EstateOwner = UUID.Random();
130 testScene.SetModuleInterfaces();
131
132 testScene.LandChannel = new TestLandChannel(testScene);
133 testScene.LoadWorldMap();
134
135 PhysicsPluginManager physicsPluginManager = new PhysicsPluginManager();
136 physicsPluginManager.LoadPluginsFromAssembly("Physics/OpenSim.Region.Physics.BasicPhysicsPlugin.dll");
137 testScene.PhysicsScene
138 = physicsPluginManager.GetPhysicsScene("basicphysics", "ZeroMesher", new IniConfigSource(), "test");
139
140 testScene.RegionInfo.EstateSettings = new EstateSettings();
141 testScene.LoginsDisabled = false;
142
143 return testScene;
144 }
145
146 private static LocalAssetServicesConnector StartAssetService(Scene testScene, CoreAssetCache cache)
147 {
148 LocalAssetServicesConnector assetService = new LocalAssetServicesConnector();
149 IConfigSource config = new IniConfigSource();
150
151 config.AddConfig("Modules");
152 config.Configs["Modules"].Set("AssetServices", "LocalAssetServicesConnector");
153 config.AddConfig("AssetService");
154 config.Configs["AssetService"].Set("LocalServiceModule", "OpenSim.Services.AssetService.dll:AssetService");
155 config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
156
157 assetService.Initialise(config);
158 assetService.AddRegion(testScene);
159
160 if (cache != null)
161 {
162 IConfigSource cacheConfig = new IniConfigSource();
163 cacheConfig.AddConfig("Modules");
164 cacheConfig.Configs["Modules"].Set("AssetCaching", "CoreAssetCache");
165 cacheConfig.AddConfig("AssetCache");
166
167 cache.Initialise(cacheConfig);
168 cache.AddRegion(testScene);
169 cache.RegionLoaded(testScene);
170 testScene.AddRegionModule(cache.Name, cache);
171 }
172
173 assetService.RegionLoaded(testScene);
174 testScene.AddRegionModule(assetService.Name, assetService);
175
176 return assetService;
177 }
178
179 private static void StartAuthenticationService(Scene testScene)
180 {
181 ISharedRegionModule service = new LocalAuthenticationServicesConnector();
182 IConfigSource config = new IniConfigSource();
183
184 config.AddConfig("Modules");
185 config.AddConfig("AuthenticationService");
186 config.Configs["Modules"].Set("AuthenticationServices", "LocalAuthenticationServicesConnector");
187 config.Configs["AuthenticationService"].Set(
188 "LocalServiceModule", "OpenSim.Services.AuthenticationService.dll:PasswordAuthenticationService");
189 config.Configs["AuthenticationService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
190
191 service.Initialise(config);
192 service.AddRegion(testScene);
193 service.RegionLoaded(testScene);
194 testScene.AddRegionModule(service.Name, service);
195 //m_authenticationService = service;
196 }
197
198 private static LocalInventoryServicesConnector StartInventoryService(Scene testScene)
199 {
200 LocalInventoryServicesConnector inventoryService = new LocalInventoryServicesConnector();
201
202 IConfigSource config = new IniConfigSource();
203 config.AddConfig("Modules");
204 config.AddConfig("InventoryService");
205 config.Configs["Modules"].Set("InventoryServices", "LocalInventoryServicesConnector");
206 config.Configs["InventoryService"].Set("LocalServiceModule", "OpenSim.Services.InventoryService.dll:InventoryService");
207 config.Configs["InventoryService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
208
209 inventoryService.Initialise(config);
210 inventoryService.AddRegion(testScene);
211 inventoryService.RegionLoaded(testScene);
212 testScene.AddRegionModule(inventoryService.Name, inventoryService);
213
214 return inventoryService;
215 }
216
217 private static LocalGridServicesConnector StartGridService(Scene testScene)
218 {
219 IConfigSource config = new IniConfigSource();
220 config.AddConfig("Modules");
221 config.AddConfig("GridService");
222 config.Configs["Modules"].Set("GridServices", "LocalGridServicesConnector");
223 config.Configs["GridService"].Set("StorageProvider", "OpenSim.Data.Null.dll:NullRegionData");
224 config.Configs["GridService"].Set("LocalServiceModule", "OpenSim.Services.GridService.dll:GridService");
225
226 LocalGridServicesConnector gridService = new LocalGridServicesConnector();
227 gridService.Initialise(config);
228 gridService.AddRegion(testScene);
229 gridService.RegionLoaded(testScene);
230
231 return gridService;
232 }
233
234 /// <summary>
235 /// Start a user account service
236 /// </summary>
237 /// <param name="testScene"></param>
238 /// <returns></returns>
239 private static LocalUserAccountServicesConnector StartUserAccountService(Scene testScene)
240 {
241 IConfigSource config = new IniConfigSource();
242 config.AddConfig("Modules");
243 config.AddConfig("UserAccountService");
244 config.Configs["Modules"].Set("UserAccountServices", "LocalUserAccountServicesConnector");
245 config.Configs["UserAccountService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
246 config.Configs["UserAccountService"].Set(
247 "LocalServiceModule", "OpenSim.Services.UserAccountService.dll:UserAccountService");
248
249 LocalUserAccountServicesConnector userAccountService = new LocalUserAccountServicesConnector();
250 userAccountService.Initialise(config);
251
252 userAccountService.AddRegion(testScene);
253 userAccountService.RegionLoaded(testScene);
254 testScene.AddRegionModule(userAccountService.Name, userAccountService);
255
256 return userAccountService;
257 }
258
259 /// <summary>
260 /// Start a presence service
261 /// </summary>
262 /// <param name="testScene"></param>
263 private static LocalPresenceServicesConnector StartPresenceService(Scene testScene)
264 {
265 IConfigSource config = new IniConfigSource();
266 config.AddConfig("Modules");
267 config.AddConfig("PresenceService");
268 config.Configs["Modules"].Set("PresenceServices", "LocalPresenceServicesConnector");
269 config.Configs["PresenceService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
270 config.Configs["PresenceService"].Set(
271 "LocalServiceModule", "OpenSim.Services.PresenceService.dll:PresenceService");
272
273 LocalPresenceServicesConnector presenceService = new LocalPresenceServicesConnector();
274 presenceService.Initialise(config);
275
276 presenceService.AddRegion(testScene);
277 presenceService.RegionLoaded(testScene);
278 testScene.AddRegionModule(presenceService.Name, presenceService);
279
280 return presenceService;
281 }
282
283 /// <summary>
284 /// Setup modules for a scene using their default settings.
285 /// </summary>
286 /// <param name="scene"></param>
287 /// <param name="modules"></param>
288 public static void SetupSceneModules(Scene scene, params object[] modules)
289 {
290 SetupSceneModules(scene, new IniConfigSource(), modules);
291 }
292
293 /// <summary>
294 /// Setup modules for a scene.
295 /// </summary>
296 /// <param name="scene"></param>
297 /// <param name="config"></param>
298 /// <param name="modules"></param>
299 public static void SetupSceneModules(Scene scene, IConfigSource config, params object[] modules)
300 {
301 List<IRegionModuleBase> newModules = new List<IRegionModuleBase>();
302 foreach (object module in modules)
303 {
304 if (module is IRegionModule)
305 {
306 IRegionModule m = (IRegionModule)module;
307 m.Initialise(scene, config);
308 scene.AddModule(m.Name, m);
309 m.PostInitialise();
310 }
311 else if (module is IRegionModuleBase)
312 {
313 // for the new system, everything has to be initialised first,
314 // shared modules have to be post-initialised, then all get an AddRegion with the scene
315 IRegionModuleBase m = (IRegionModuleBase)module;
316 m.Initialise(config);
317 newModules.Add(m);
318 }
319 }
320
321 foreach (IRegionModuleBase module in newModules)
322 {
323 if (module is ISharedRegionModule) ((ISharedRegionModule)module).PostInitialise();
324 }
325
326 foreach (IRegionModuleBase module in newModules)
327 {
328 module.AddRegion(scene);
329 scene.AddRegionModule(module.Name, module);
330 }
331
332 // RegionLoaded is fired after all modules have been appropriately added to all scenes
333 foreach (IRegionModuleBase module in newModules)
334 module.RegionLoaded(scene);
335
336 scene.SetModuleInterfaces();
337 }
338
339 /// <summary>
340 /// Generate some standard agent connection data.
341 /// </summary>
342 /// <param name="agentId"></param>
343 /// <returns></returns>
344 public static AgentCircuitData GenerateAgentData(UUID agentId)
345 {
346 string firstName = "testfirstname";
347
348 AgentCircuitData agentData = new AgentCircuitData();
349 agentData.AgentID = agentId;
350 agentData.firstname = firstName;
351 agentData.lastname = "testlastname";
352 agentData.SessionID = UUID.Zero;
353 agentData.SecureSessionID = UUID.Zero;
354 agentData.circuitcode = 123;
355 agentData.BaseFolder = UUID.Zero;
356 agentData.InventoryFolder = UUID.Zero;
357 agentData.startpos = Vector3.Zero;
358 agentData.CapsPath = "http://wibble.com";
359 agentData.ServiceURLs = new Dictionary<string, object>();
360 agentData.Appearance = new AvatarAppearance();
361
362 return agentData;
363 }
364
365 /// <summary>
366 /// Add a root agent where the details of the agent connection (apart from the id) are unimportant for the test
367 /// </summary>
368 /// <param name="scene"></param>
369 /// <param name="agentId"></param>
370 /// <returns></returns>
371 public static ScenePresence AddScenePresence(Scene scene, UUID agentId)
372 {
373 return AddScenePresence(scene, GenerateAgentData(agentId));
374 }
375
376 /// <summary>
377 /// Add a root agent.
378 /// </summary>
379 /// <remarks>
380 /// This function
381 ///
382 /// 1) Tells the scene that an agent is coming. Normally, the login service (local if standalone, from the
383 /// userserver if grid) would give initial login data back to the client and separately tell the scene that the
384 /// agent was coming.
385 ///
386 /// 2) Connects the agent with the scene
387 ///
388 /// This function performs actions equivalent with notifying the scene that an agent is
389 /// coming and then actually connecting the agent to the scene. The one step missed out is the very first
390 /// </remarks>
391 /// <param name="scene"></param>
392 /// <param name="agentData"></param>
393 /// <returns></returns>
394 public static ScenePresence AddScenePresence(Scene scene, AgentCircuitData agentData)
395 {
396 string reason;
397
398 // We emulate the proper login sequence here by doing things in four stages
399
400 // Stage 0: log the presence
401 scene.PresenceService.LoginAgent(agentData.AgentID.ToString(), agentData.SessionID, agentData.SecureSessionID);
402
403 // Stage 1: simulate login by telling the scene to expect a new user connection
404 if (!scene.NewUserConnection(agentData, (uint)TeleportFlags.ViaLogin, out reason))
405 Console.WriteLine("NewUserConnection failed: " + reason);
406
407 // Stage 2: add the new client as a child agent to the scene
408 TestClient client = new TestClient(agentData, scene);
409 scene.AddNewClient(client, PresenceType.User);
410
411 // Stage 3: Complete the entrance into the region. This converts the child agent into a root agent.
412 ScenePresence scp = scene.GetScenePresence(agentData.AgentID);
413 scp.CompleteMovement(client, true);
414 //scp.MakeRootAgent(new Vector3(90, 90, 90), true);
415
416 return scp;
417 }
418
419 /// <summary>
420 /// Add a test object
421 /// </summary>
422 /// <param name="scene"></param>
423 /// <returns></returns>
424 public static SceneObjectPart AddSceneObject(Scene scene)
425 {
426 return AddSceneObject(scene, "Test Object");
427 }
428
429 /// <summary>
430 /// Add a test object
431 /// </summary>
432 /// <param name="scene"></param>
433 /// <param name="name"></param>
434 /// <returns></returns>
435 public static SceneObjectPart AddSceneObject(Scene scene, string name)
436 {
437 SceneObjectPart part = CreateSceneObjectPart(name, UUID.Random(), UUID.Zero);
438
439 //part.UpdatePrimFlags(false, false, true);
440 //part.ObjectFlags |= (uint)PrimFlags.Phantom;
441
442 scene.AddNewSceneObject(new SceneObjectGroup(part), false);
443
444 return part;
445 }
446
447 /// <summary>
448 /// Create a scene object part.
449 /// </summary>
450 /// <param name="name"></param>
451 /// <param name="id"></param>
452 /// <param name="ownerId"></param>
453 /// <returns></returns>
454 public static SceneObjectPart CreateSceneObjectPart(string name, UUID id, UUID ownerId)
455 {
456 return new SceneObjectPart(
457 ownerId, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
458 { Name = name, UUID = id, Scale = new Vector3(1, 1, 1) };
459 }
460
461 /// <summary>
462 /// Create a scene object but do not add it to the scene.
463 /// </summary>
464 /// <remarks>
465 /// UUID always starts at 00000000-0000-0000-0000-000000000001
466 /// </remarks>
467 /// <param name="parts">The number of parts that should be in the scene object</param>
468 /// <param name="ownerId"></param>
469 /// <returns></returns>
470 public static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId)
471 {
472 return CreateSceneObject(parts, ownerId, "", 0x1);
473 }
474
475 /// <summary>
476 /// Create a scene object but do not add it to the scene.
477 /// </summary>
478 /// <param name="parts">
479 /// The number of parts that should be in the scene object
480 /// </param>
481 /// <param name="ownerId"></param>
482 /// <param name="partNamePrefix">
483 /// The prefix to be given to part names. This will be suffixed with "Part<part no>"
484 /// (e.g. mynamePart0 for the root part)
485 /// </param>
486 /// <param name="uuidTail">
487 /// The hexadecimal last part of the UUID for parts created. A UUID of the form "00000000-0000-0000-0000-{0:XD12}"
488 /// will be given to the root part, and incremented for each part thereafter.
489 /// </param>
490 /// <returns></returns>
491 public static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId, string partNamePrefix, int uuidTail)
492 {
493 string rawSogId = string.Format("00000000-0000-0000-0000-{0:X12}", uuidTail);
494
495 SceneObjectGroup sog
496 = new SceneObjectGroup(
497 CreateSceneObjectPart(string.Format("{0}Part0", partNamePrefix), new UUID(rawSogId), ownerId));
498
499 if (parts > 1)
500 for (int i = 1; i < parts; i++)
501 sog.AddPart(
502 CreateSceneObjectPart(
503 string.Format("{0}Part{1}", partNamePrefix, i),
504 new UUID(string.Format("00000000-0000-0000-0000-{0:X12}", uuidTail + i)),
505 ownerId));
506
507 return sog;
508 }
509 }
510} \ No newline at end of file