1
0

SceneHelpers.cs 30 KB

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