SceneHelpers.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  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.Net;
  29. using System.Collections.Generic;
  30. using Nini.Config;
  31. using OpenMetaverse;
  32. using OpenSim.Framework;
  33. using OpenSim.Framework.Communications;
  34. using OpenSim.Framework.Console;
  35. using OpenSim.Framework.Servers;
  36. using OpenSim.Framework.Servers.HttpServer;
  37. using OpenSim.Region.Physics.Manager;
  38. using OpenSim.Region.Framework;
  39. using OpenSim.Region.Framework.Interfaces;
  40. using OpenSim.Region.Framework.Scenes;
  41. using OpenSim.Region.CoreModules.Avatar.Gods;
  42. using OpenSim.Region.CoreModules.Asset;
  43. using OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset;
  44. using OpenSim.Region.CoreModules.ServiceConnectorsOut.Authentication;
  45. using OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory;
  46. using OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid;
  47. using OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts;
  48. using OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence;
  49. using OpenSim.Services.Interfaces;
  50. using OpenSim.Tests.Common.Mock;
  51. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  52. namespace OpenSim.Tests.Common
  53. {
  54. /// <summary>
  55. /// Helpers for setting up scenes.
  56. /// </summary>
  57. public class SceneHelpers
  58. {
  59. /// <summary>
  60. /// We need a scene manager so that test clients can retrieve a scene when performing teleport tests.
  61. /// </summary>
  62. public SceneManager SceneManager { get; private set; }
  63. private AgentCircuitManager m_acm = new AgentCircuitManager();
  64. private ISimulationDataService m_simDataService
  65. = OpenSim.Server.Base.ServerUtils.LoadPlugin<ISimulationDataService>("OpenSim.Tests.Common.dll", null);
  66. private IEstateDataService m_estateDataService = null;
  67. private LocalAssetServicesConnector m_assetService;
  68. private LocalAuthenticationServicesConnector m_authenticationService;
  69. private LocalInventoryServicesConnector m_inventoryService;
  70. private LocalGridServicesConnector m_gridService;
  71. private LocalUserAccountServicesConnector m_userAccountService;
  72. private LocalPresenceServicesConnector m_presenceService;
  73. private CoreAssetCache m_cache;
  74. public SceneHelpers() : this(null) {}
  75. public SceneHelpers(CoreAssetCache cache)
  76. {
  77. SceneManager = new SceneManager();
  78. m_assetService = StartAssetService(cache);
  79. m_authenticationService = StartAuthenticationService();
  80. m_inventoryService = StartInventoryService();
  81. m_gridService = StartGridService();
  82. m_userAccountService = StartUserAccountService();
  83. m_presenceService = StartPresenceService();
  84. m_inventoryService.PostInitialise();
  85. m_assetService.PostInitialise();
  86. m_userAccountService.PostInitialise();
  87. m_presenceService.PostInitialise();
  88. m_cache = cache;
  89. }
  90. /// <summary>
  91. /// Set up a test scene
  92. /// </summary>
  93. /// <remarks>
  94. /// Automatically starts services, as would the normal runtime.
  95. /// </remarks>
  96. /// <returns></returns>
  97. public TestScene SetupScene()
  98. {
  99. return SetupScene("Unit test region", UUID.Random(), 1000, 1000);
  100. }
  101. public TestScene SetupScene(string name, UUID id, uint x, uint y)
  102. {
  103. return SetupScene(name, id, x, y, new IniConfigSource());
  104. }
  105. /// <summary>
  106. /// Set up a scene.
  107. /// </summary>
  108. /// <param name="name">Name of the region</param>
  109. /// <param name="id">ID of the region</param>
  110. /// <param name="x">X co-ordinate of the region</param>
  111. /// <param name="y">Y co-ordinate of the region</param>
  112. /// <param name="configSource"></param>
  113. /// <returns></returns>
  114. public TestScene SetupScene(
  115. string name, UUID id, uint x, uint y, IConfigSource configSource)
  116. {
  117. Console.WriteLine("Setting up test scene {0}", name);
  118. // We must set up a console otherwise setup of some modules may fail
  119. MainConsole.Instance = new MockConsole();
  120. RegionInfo regInfo = new RegionInfo(x, y, new IPEndPoint(IPAddress.Loopback, 9000), "127.0.0.1");
  121. regInfo.RegionName = name;
  122. regInfo.RegionID = id;
  123. SceneCommunicationService scs = new SceneCommunicationService();
  124. TestScene testScene = new TestScene(
  125. regInfo, m_acm, scs, m_simDataService, m_estateDataService, configSource, null);
  126. INonSharedRegionModule godsModule = new GodsModule();
  127. godsModule.Initialise(new IniConfigSource());
  128. godsModule.AddRegion(testScene);
  129. // Add scene to services
  130. m_assetService.AddRegion(testScene);
  131. if (m_cache != null)
  132. {
  133. m_cache.AddRegion(testScene);
  134. m_cache.RegionLoaded(testScene);
  135. testScene.AddRegionModule(m_cache.Name, m_cache);
  136. }
  137. m_assetService.RegionLoaded(testScene);
  138. testScene.AddRegionModule(m_assetService.Name, m_assetService);
  139. m_authenticationService.AddRegion(testScene);
  140. m_authenticationService.RegionLoaded(testScene);
  141. testScene.AddRegionModule(m_authenticationService.Name, m_authenticationService);
  142. m_inventoryService.AddRegion(testScene);
  143. m_inventoryService.RegionLoaded(testScene);
  144. testScene.AddRegionModule(m_inventoryService.Name, m_inventoryService);
  145. m_gridService.AddRegion(testScene);
  146. m_gridService.RegionLoaded(testScene);
  147. testScene.AddRegionModule(m_gridService.Name, m_gridService);
  148. m_userAccountService.AddRegion(testScene);
  149. m_userAccountService.RegionLoaded(testScene);
  150. testScene.AddRegionModule(m_userAccountService.Name, m_userAccountService);
  151. m_presenceService.AddRegion(testScene);
  152. m_presenceService.RegionLoaded(testScene);
  153. testScene.AddRegionModule(m_presenceService.Name, m_presenceService);
  154. testScene.RegionInfo.EstateSettings.EstateOwner = UUID.Random();
  155. testScene.SetModuleInterfaces();
  156. testScene.LandChannel = new TestLandChannel(testScene);
  157. testScene.LoadWorldMap();
  158. PhysicsPluginManager physicsPluginManager = new PhysicsPluginManager();
  159. physicsPluginManager.LoadPluginsFromAssembly("Physics/OpenSim.Region.Physics.BasicPhysicsPlugin.dll");
  160. testScene.PhysicsScene
  161. = physicsPluginManager.GetPhysicsScene("basicphysics", "ZeroMesher", new IniConfigSource(), "test");
  162. testScene.RegionInfo.EstateSettings = new EstateSettings();
  163. testScene.LoginsEnabled = true;
  164. testScene.RegisterRegionWithGrid();
  165. SceneManager.Add(testScene);
  166. return testScene;
  167. }
  168. private static LocalAssetServicesConnector StartAssetService(CoreAssetCache cache)
  169. {
  170. IConfigSource config = new IniConfigSource();
  171. config.AddConfig("Modules");
  172. config.Configs["Modules"].Set("AssetServices", "LocalAssetServicesConnector");
  173. config.AddConfig("AssetService");
  174. config.Configs["AssetService"].Set("LocalServiceModule", "OpenSim.Services.AssetService.dll:AssetService");
  175. config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
  176. LocalAssetServicesConnector assetService = new LocalAssetServicesConnector();
  177. assetService.Initialise(config);
  178. if (cache != null)
  179. {
  180. IConfigSource cacheConfig = new IniConfigSource();
  181. cacheConfig.AddConfig("Modules");
  182. cacheConfig.Configs["Modules"].Set("AssetCaching", "CoreAssetCache");
  183. cacheConfig.AddConfig("AssetCache");
  184. cache.Initialise(cacheConfig);
  185. }
  186. return assetService;
  187. }
  188. private static LocalAuthenticationServicesConnector StartAuthenticationService()
  189. {
  190. IConfigSource config = new IniConfigSource();
  191. config.AddConfig("Modules");
  192. config.AddConfig("AuthenticationService");
  193. config.Configs["Modules"].Set("AuthenticationServices", "LocalAuthenticationServicesConnector");
  194. config.Configs["AuthenticationService"].Set(
  195. "LocalServiceModule", "OpenSim.Services.AuthenticationService.dll:PasswordAuthenticationService");
  196. config.Configs["AuthenticationService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
  197. LocalAuthenticationServicesConnector service = new LocalAuthenticationServicesConnector();
  198. service.Initialise(config);
  199. return service;
  200. }
  201. private static LocalInventoryServicesConnector StartInventoryService()
  202. {
  203. IConfigSource config = new IniConfigSource();
  204. config.AddConfig("Modules");
  205. config.AddConfig("InventoryService");
  206. config.Configs["Modules"].Set("InventoryServices", "LocalInventoryServicesConnector");
  207. config.Configs["InventoryService"].Set("LocalServiceModule", "OpenSim.Services.InventoryService.dll:XInventoryService");
  208. config.Configs["InventoryService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
  209. LocalInventoryServicesConnector inventoryService = new LocalInventoryServicesConnector();
  210. inventoryService.Initialise(config);
  211. return inventoryService;
  212. }
  213. private static LocalGridServicesConnector StartGridService()
  214. {
  215. IConfigSource config = new IniConfigSource();
  216. config.AddConfig("Modules");
  217. config.AddConfig("GridService");
  218. config.Configs["Modules"].Set("GridServices", "LocalGridServicesConnector");
  219. config.Configs["GridService"].Set("StorageProvider", "OpenSim.Data.Null.dll:NullRegionData");
  220. config.Configs["GridService"].Set("LocalServiceModule", "OpenSim.Services.GridService.dll:GridService");
  221. config.Configs["GridService"].Set("ConnectionString", "!static");
  222. LocalGridServicesConnector gridService = new LocalGridServicesConnector();
  223. gridService.Initialise(config);
  224. return gridService;
  225. }
  226. /// <summary>
  227. /// Start a user account service
  228. /// </summary>
  229. /// <param name="testScene"></param>
  230. /// <returns></returns>
  231. private static LocalUserAccountServicesConnector StartUserAccountService()
  232. {
  233. IConfigSource config = new IniConfigSource();
  234. config.AddConfig("Modules");
  235. config.AddConfig("UserAccountService");
  236. config.Configs["Modules"].Set("UserAccountServices", "LocalUserAccountServicesConnector");
  237. config.Configs["UserAccountService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
  238. config.Configs["UserAccountService"].Set(
  239. "LocalServiceModule", "OpenSim.Services.UserAccountService.dll:UserAccountService");
  240. LocalUserAccountServicesConnector userAccountService = new LocalUserAccountServicesConnector();
  241. userAccountService.Initialise(config);
  242. return userAccountService;
  243. }
  244. /// <summary>
  245. /// Start a presence service
  246. /// </summary>
  247. /// <param name="testScene"></param>
  248. private static LocalPresenceServicesConnector StartPresenceService()
  249. {
  250. IConfigSource config = new IniConfigSource();
  251. config.AddConfig("Modules");
  252. config.AddConfig("PresenceService");
  253. config.Configs["Modules"].Set("PresenceServices", "LocalPresenceServicesConnector");
  254. config.Configs["PresenceService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
  255. config.Configs["PresenceService"].Set(
  256. "LocalServiceModule", "OpenSim.Services.PresenceService.dll:PresenceService");
  257. LocalPresenceServicesConnector presenceService = new LocalPresenceServicesConnector();
  258. presenceService.Initialise(config);
  259. return presenceService;
  260. }
  261. /// <summary>
  262. /// Setup modules for a scene using their default settings.
  263. /// </summary>
  264. /// <param name="scene"></param>
  265. /// <param name="modules"></param>
  266. public static void SetupSceneModules(Scene scene, params object[] modules)
  267. {
  268. SetupSceneModules(scene, new IniConfigSource(), modules);
  269. }
  270. /// <summary>
  271. /// Setup modules for a scene.
  272. /// </summary>
  273. /// <remarks>
  274. /// If called directly, then all the modules must be shared modules.
  275. /// </remarks>
  276. /// <param name="scenes"></param>
  277. /// <param name="config"></param>
  278. /// <param name="modules"></param>
  279. public static void SetupSceneModules(Scene scene, IConfigSource config, params object[] modules)
  280. {
  281. SetupSceneModules(new Scene[] { scene }, config, modules);
  282. }
  283. /// <summary>
  284. /// Setup modules for a scene using their default settings.
  285. /// </summary>
  286. /// <param name="scenes"></param>
  287. /// <param name="modules"></param>
  288. public static void SetupSceneModules(Scene[] scenes, params object[] modules)
  289. {
  290. SetupSceneModules(scenes, new IniConfigSource(), modules);
  291. }
  292. /// <summary>
  293. /// Setup modules for scenes.
  294. /// </summary>
  295. /// <remarks>
  296. /// If called directly, then all the modules must be shared modules.
  297. ///
  298. /// We are emulating here the normal calls made to setup region modules
  299. /// (Initialise(), PostInitialise(), AddRegion, RegionLoaded()).
  300. /// TODO: Need to reuse normal runtime module code.
  301. /// </remarks>
  302. /// <param name="scenes"></param>
  303. /// <param name="config"></param>
  304. /// <param name="modules"></param>
  305. public static void SetupSceneModules(Scene[] scenes, IConfigSource config, params object[] modules)
  306. {
  307. List<IRegionModuleBase> newModules = new List<IRegionModuleBase>();
  308. foreach (object module in modules)
  309. {
  310. IRegionModuleBase m = (IRegionModuleBase)module;
  311. // Console.WriteLine("MODULE {0}", m.Name);
  312. m.Initialise(config);
  313. newModules.Add(m);
  314. }
  315. foreach (IRegionModuleBase module in newModules)
  316. {
  317. if (module is ISharedRegionModule) ((ISharedRegionModule)module).PostInitialise();
  318. }
  319. foreach (IRegionModuleBase module in newModules)
  320. {
  321. foreach (Scene scene in scenes)
  322. {
  323. module.AddRegion(scene);
  324. scene.AddRegionModule(module.Name, module);
  325. }
  326. }
  327. // RegionLoaded is fired after all modules have been appropriately added to all scenes
  328. foreach (IRegionModuleBase module in newModules)
  329. foreach (Scene scene in scenes)
  330. module.RegionLoaded(scene);
  331. foreach (Scene scene in scenes) { scene.SetModuleInterfaces(); }
  332. }
  333. /// <summary>
  334. /// Generate some standard agent connection data.
  335. /// </summary>
  336. /// <param name="agentId"></param>
  337. /// <returns></returns>
  338. public static AgentCircuitData GenerateAgentData(UUID agentId)
  339. {
  340. AgentCircuitData acd = GenerateCommonAgentData();
  341. acd.AgentID = agentId;
  342. acd.firstname = "testfirstname";
  343. acd.lastname = "testlastname";
  344. acd.ServiceURLs = new Dictionary<string, object>();
  345. return acd;
  346. }
  347. /// <summary>
  348. /// Generate some standard agent connection data.
  349. /// </summary>
  350. /// <param name="agentId"></param>
  351. /// <returns></returns>
  352. public static AgentCircuitData GenerateAgentData(UserAccount ua)
  353. {
  354. AgentCircuitData acd = GenerateCommonAgentData();
  355. acd.AgentID = ua.PrincipalID;
  356. acd.firstname = ua.FirstName;
  357. acd.lastname = ua.LastName;
  358. acd.ServiceURLs = ua.ServiceURLs;
  359. return acd;
  360. }
  361. private static AgentCircuitData GenerateCommonAgentData()
  362. {
  363. AgentCircuitData acd = new AgentCircuitData();
  364. // XXX: Sessions must be unique, otherwise one presence can overwrite another in NullPresenceData.
  365. acd.SessionID = UUID.Random();
  366. acd.SecureSessionID = UUID.Random();
  367. acd.circuitcode = 123;
  368. acd.BaseFolder = UUID.Zero;
  369. acd.InventoryFolder = UUID.Zero;
  370. acd.startpos = Vector3.Zero;
  371. acd.CapsPath = "http://wibble.com";
  372. acd.Appearance = new AvatarAppearance();
  373. return acd;
  374. }
  375. /// <summary>
  376. /// Add a root agent where the details of the agent connection (apart from the id) are unimportant for the test
  377. /// </summary>
  378. /// <remarks>
  379. /// XXX: Use the version of this method that takes the UserAccount structure wherever possible - this will
  380. /// make the agent circuit data (e.g. first, lastname) consistent with the user account data.
  381. /// </remarks>
  382. /// <param name="scene"></param>
  383. /// <param name="agentId"></param>
  384. /// <returns></returns>
  385. public static ScenePresence AddScenePresence(Scene scene, UUID agentId)
  386. {
  387. return AddScenePresence(scene, GenerateAgentData(agentId));
  388. }
  389. /// <summary>
  390. /// Add a root agent.
  391. /// </summary>
  392. /// <param name="scene"></param>
  393. /// <param name="ua"></param>
  394. /// <returns></returns>
  395. public static ScenePresence AddScenePresence(Scene scene, UserAccount ua)
  396. {
  397. return AddScenePresence(scene, GenerateAgentData(ua));
  398. }
  399. /// <summary>
  400. /// Add a root agent.
  401. /// </summary>
  402. /// <remarks>
  403. /// This function
  404. ///
  405. /// 1) Tells the scene that an agent is coming. Normally, the login service (local if standalone, from the
  406. /// userserver if grid) would give initial login data back to the client and separately tell the scene that the
  407. /// agent was coming.
  408. ///
  409. /// 2) Connects the agent with the scene
  410. ///
  411. /// This function performs actions equivalent with notifying the scene that an agent is
  412. /// coming and then actually connecting the agent to the scene. The one step missed out is the very first
  413. /// </remarks>
  414. /// <param name="scene"></param>
  415. /// <param name="agentData"></param>
  416. /// <returns></returns>
  417. public static ScenePresence AddScenePresence(Scene scene, AgentCircuitData agentData)
  418. {
  419. return AddScenePresence(scene, new TestClient(agentData, scene), agentData);
  420. }
  421. /// <summary>
  422. /// Add a root agent.
  423. /// </summary>
  424. /// <remarks>
  425. /// This function
  426. ///
  427. /// 1) Tells the scene that an agent is coming. Normally, the login service (local if standalone, from the
  428. /// userserver if grid) would give initial login data back to the client and separately tell the scene that the
  429. /// agent was coming.
  430. ///
  431. /// 2) Connects the agent with the scene
  432. ///
  433. /// This function performs actions equivalent with notifying the scene that an agent is
  434. /// coming and then actually connecting the agent to the scene. The one step missed out is the very first
  435. /// </remarks>
  436. /// <param name="scene"></param>
  437. /// <param name="agentData"></param>
  438. /// <returns></returns>
  439. public static ScenePresence AddScenePresence(
  440. Scene scene, IClientAPI client, AgentCircuitData agentData)
  441. {
  442. // We emulate the proper login sequence here by doing things in four stages
  443. // Stage 0: login
  444. // We need to punch through to the underlying service because scene will not, correctly, let us call it
  445. // through it's reference to the LPSC
  446. LocalPresenceServicesConnector lpsc = (LocalPresenceServicesConnector)scene.PresenceService;
  447. lpsc.m_PresenceService.LoginAgent(agentData.AgentID.ToString(), agentData.SessionID, agentData.SecureSessionID);
  448. // Stages 1 & 2
  449. ScenePresence sp = IntroduceClientToScene(scene, client, agentData, TeleportFlags.ViaLogin);
  450. // Stage 3: Complete the entrance into the region. This converts the child agent into a root agent.
  451. sp.CompleteMovement(sp.ControllingClient, true);
  452. return sp;
  453. }
  454. /// <summary>
  455. /// Introduce an agent into the scene by adding a new client.
  456. /// </summary>
  457. /// <returns>The scene presence added</returns>
  458. /// <param name='scene'></param>
  459. /// <param name='testClient'></param>
  460. /// <param name='agentData'></param>
  461. /// <param name='tf'></param>
  462. private static ScenePresence IntroduceClientToScene(
  463. Scene scene, IClientAPI client, AgentCircuitData agentData, TeleportFlags tf)
  464. {
  465. string reason;
  466. // Stage 1: tell the scene to expect a new user connection
  467. if (!scene.NewUserConnection(agentData, (uint)tf, out reason))
  468. Console.WriteLine("NewUserConnection failed: " + reason);
  469. // Stage 2: add the new client as a child agent to the scene
  470. scene.AddNewClient(client, PresenceType.User);
  471. return scene.GetScenePresence(client.AgentId);
  472. }
  473. public static ScenePresence AddChildScenePresence(Scene scene, UUID agentId)
  474. {
  475. AgentCircuitData acd = GenerateAgentData(agentId);
  476. acd.child = true;
  477. // XXX: ViaLogin may not be correct for child agents
  478. TestClient client = new TestClient(acd, scene);
  479. return IntroduceClientToScene(scene, client, acd, TeleportFlags.ViaLogin);
  480. }
  481. /// <summary>
  482. /// Add a test object
  483. /// </summary>
  484. /// <param name="scene"></param>
  485. /// <returns></returns>
  486. public static SceneObjectGroup AddSceneObject(Scene scene)
  487. {
  488. return AddSceneObject(scene, "Test Object", UUID.Zero);
  489. }
  490. /// <summary>
  491. /// Add a test object
  492. /// </summary>
  493. /// <param name="scene"></param>
  494. /// <param name="name"></param>
  495. /// <param name="ownerId"></param>
  496. /// <returns></returns>
  497. public static SceneObjectGroup AddSceneObject(Scene scene, string name, UUID ownerId)
  498. {
  499. SceneObjectGroup so = new SceneObjectGroup(CreateSceneObjectPart(name, UUID.Random(), ownerId));
  500. //part.UpdatePrimFlags(false, false, true);
  501. //part.ObjectFlags |= (uint)PrimFlags.Phantom;
  502. scene.AddNewSceneObject(so, false);
  503. return so;
  504. }
  505. /// <summary>
  506. /// Create a scene object part.
  507. /// </summary>
  508. /// <param name="name"></param>
  509. /// <param name="id"></param>
  510. /// <param name="ownerId"></param>
  511. /// <returns></returns>
  512. public static SceneObjectPart CreateSceneObjectPart(string name, UUID id, UUID ownerId)
  513. {
  514. return new SceneObjectPart(
  515. ownerId, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
  516. { Name = name, UUID = id, Scale = new Vector3(1, 1, 1) };
  517. }
  518. /// <summary>
  519. /// Create a scene object but do not add it to the scene.
  520. /// </summary>
  521. /// <remarks>
  522. /// UUID always starts at 00000000-0000-0000-0000-000000000001. For some purposes, (e.g. serializing direct
  523. /// to another object's inventory) we do not need a scene unique ID. So it would be better to add the
  524. /// UUID when we actually add an object to a scene rather than on creation.
  525. /// </remarks>
  526. /// <param name="parts">The number of parts that should be in the scene object</param>
  527. /// <param name="ownerId"></param>
  528. /// <returns></returns>
  529. public static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId)
  530. {
  531. return CreateSceneObject(parts, ownerId, 0x1);
  532. }
  533. /// <summary>
  534. /// Create a scene object but do not add it to the scene.
  535. /// </summary>
  536. /// <param name="parts">The number of parts that should be in the scene object</param>
  537. /// <param name="ownerId"></param>
  538. /// <param name="uuidTail">
  539. /// The hexadecimal last part of the UUID for parts created. A UUID of the form "00000000-0000-0000-0000-{0:XD12}"
  540. /// will be given to the root part, and incremented for each part thereafter.
  541. /// </param>
  542. /// <returns></returns>
  543. public static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId, int uuidTail)
  544. {
  545. return CreateSceneObject(parts, ownerId, "", uuidTail);
  546. }
  547. /// <summary>
  548. /// Create a scene object but do not add it to the scene.
  549. /// </summary>
  550. /// <param name="parts">
  551. /// The number of parts that should be in the scene object
  552. /// </param>
  553. /// <param name="ownerId"></param>
  554. /// <param name="partNamePrefix">
  555. /// The prefix to be given to part names. This will be suffixed with "Part<part no>"
  556. /// (e.g. mynamePart1 for the root part)
  557. /// </param>
  558. /// <param name="uuidTail">
  559. /// The hexadecimal last part of the UUID for parts created. A UUID of the form "00000000-0000-0000-0000-{0:XD12}"
  560. /// will be given to the root part, and incremented for each part thereafter.
  561. /// </param>
  562. /// <returns></returns>
  563. public static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId, string partNamePrefix, int uuidTail)
  564. {
  565. string rawSogId = string.Format("00000000-0000-0000-0000-{0:X12}", uuidTail);
  566. SceneObjectGroup sog
  567. = new SceneObjectGroup(
  568. CreateSceneObjectPart(string.Format("{0}Part1", partNamePrefix), new UUID(rawSogId), ownerId));
  569. if (parts > 1)
  570. for (int i = 2; i <= parts; i++)
  571. sog.AddPart(
  572. CreateSceneObjectPart(
  573. string.Format("{0}Part{1}", partNamePrefix, i),
  574. new UUID(string.Format("00000000-0000-0000-0000-{0:X12}", uuidTail + i - 1)),
  575. ownerId));
  576. return sog;
  577. }
  578. }
  579. }