SceneHelpers.cs 30 KB

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