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