SceneHelpers.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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. Vector3 regionExtent = new Vector3( regInfo.RegionSizeX, regInfo.RegionSizeY, regInfo.RegionSizeZ);
  161. testScene.PhysicsScene
  162. = physicsPluginManager.GetPhysicsScene("basicphysics", "ZeroMesher", new IniConfigSource(), "test", regionExtent);
  163. testScene.RegionInfo.EstateSettings = new EstateSettings();
  164. testScene.LoginsEnabled = true;
  165. testScene.RegisterRegionWithGrid();
  166. SceneManager.Add(testScene);
  167. return testScene;
  168. }
  169. private static LocalAssetServicesConnector StartAssetService(CoreAssetCache cache)
  170. {
  171. IConfigSource config = new IniConfigSource();
  172. config.AddConfig("Modules");
  173. config.Configs["Modules"].Set("AssetServices", "LocalAssetServicesConnector");
  174. config.AddConfig("AssetService");
  175. config.Configs["AssetService"].Set("LocalServiceModule", "OpenSim.Services.AssetService.dll:AssetService");
  176. config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
  177. LocalAssetServicesConnector assetService = new LocalAssetServicesConnector();
  178. assetService.Initialise(config);
  179. if (cache != null)
  180. {
  181. IConfigSource cacheConfig = new IniConfigSource();
  182. cacheConfig.AddConfig("Modules");
  183. cacheConfig.Configs["Modules"].Set("AssetCaching", "CoreAssetCache");
  184. cacheConfig.AddConfig("AssetCache");
  185. cache.Initialise(cacheConfig);
  186. }
  187. return assetService;
  188. }
  189. private static LocalAuthenticationServicesConnector StartAuthenticationService()
  190. {
  191. IConfigSource config = new IniConfigSource();
  192. config.AddConfig("Modules");
  193. config.AddConfig("AuthenticationService");
  194. config.Configs["Modules"].Set("AuthenticationServices", "LocalAuthenticationServicesConnector");
  195. config.Configs["AuthenticationService"].Set(
  196. "LocalServiceModule", "OpenSim.Services.AuthenticationService.dll:PasswordAuthenticationService");
  197. config.Configs["AuthenticationService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
  198. LocalAuthenticationServicesConnector service = new LocalAuthenticationServicesConnector();
  199. service.Initialise(config);
  200. return service;
  201. }
  202. private static LocalInventoryServicesConnector StartInventoryService()
  203. {
  204. IConfigSource config = new IniConfigSource();
  205. config.AddConfig("Modules");
  206. config.AddConfig("InventoryService");
  207. config.Configs["Modules"].Set("InventoryServices", "LocalInventoryServicesConnector");
  208. config.Configs["InventoryService"].Set("LocalServiceModule", "OpenSim.Services.InventoryService.dll:XInventoryService");
  209. config.Configs["InventoryService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
  210. LocalInventoryServicesConnector inventoryService = new LocalInventoryServicesConnector();
  211. inventoryService.Initialise(config);
  212. return inventoryService;
  213. }
  214. private static LocalGridServicesConnector StartGridService()
  215. {
  216. IConfigSource config = new IniConfigSource();
  217. config.AddConfig("Modules");
  218. config.AddConfig("GridService");
  219. config.Configs["Modules"].Set("GridServices", "LocalGridServicesConnector");
  220. config.Configs["GridService"].Set("StorageProvider", "OpenSim.Data.Null.dll:NullRegionData");
  221. config.Configs["GridService"].Set("LocalServiceModule", "OpenSim.Services.GridService.dll:GridService");
  222. config.Configs["GridService"].Set("ConnectionString", "!static");
  223. LocalGridServicesConnector gridService = new LocalGridServicesConnector();
  224. gridService.Initialise(config);
  225. return gridService;
  226. }
  227. /// <summary>
  228. /// Start a user account service
  229. /// </summary>
  230. /// <param name="testScene"></param>
  231. /// <returns></returns>
  232. private static LocalUserAccountServicesConnector StartUserAccountService()
  233. {
  234. IConfigSource config = new IniConfigSource();
  235. config.AddConfig("Modules");
  236. config.AddConfig("UserAccountService");
  237. config.Configs["Modules"].Set("UserAccountServices", "LocalUserAccountServicesConnector");
  238. config.Configs["UserAccountService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
  239. config.Configs["UserAccountService"].Set(
  240. "LocalServiceModule", "OpenSim.Services.UserAccountService.dll:UserAccountService");
  241. LocalUserAccountServicesConnector userAccountService = new LocalUserAccountServicesConnector();
  242. userAccountService.Initialise(config);
  243. return userAccountService;
  244. }
  245. /// <summary>
  246. /// Start a presence service
  247. /// </summary>
  248. /// <param name="testScene"></param>
  249. private static LocalPresenceServicesConnector StartPresenceService()
  250. {
  251. IConfigSource config = new IniConfigSource();
  252. config.AddConfig("Modules");
  253. config.AddConfig("PresenceService");
  254. config.Configs["Modules"].Set("PresenceServices", "LocalPresenceServicesConnector");
  255. config.Configs["PresenceService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
  256. config.Configs["PresenceService"].Set(
  257. "LocalServiceModule", "OpenSim.Services.PresenceService.dll:PresenceService");
  258. LocalPresenceServicesConnector presenceService = new LocalPresenceServicesConnector();
  259. presenceService.Initialise(config);
  260. return presenceService;
  261. }
  262. /// <summary>
  263. /// Setup modules for a scene using their default settings.
  264. /// </summary>
  265. /// <param name="scene"></param>
  266. /// <param name="modules"></param>
  267. public static void SetupSceneModules(Scene scene, params object[] modules)
  268. {
  269. SetupSceneModules(scene, new IniConfigSource(), modules);
  270. }
  271. /// <summary>
  272. /// Setup modules for a scene.
  273. /// </summary>
  274. /// <remarks>
  275. /// If called directly, then all the modules must be shared modules.
  276. /// </remarks>
  277. /// <param name="scenes"></param>
  278. /// <param name="config"></param>
  279. /// <param name="modules"></param>
  280. public static void SetupSceneModules(Scene scene, IConfigSource config, params object[] modules)
  281. {
  282. SetupSceneModules(new Scene[] { scene }, config, modules);
  283. }
  284. /// <summary>
  285. /// Setup modules for a scene using their default settings.
  286. /// </summary>
  287. /// <param name="scenes"></param>
  288. /// <param name="modules"></param>
  289. public static void SetupSceneModules(Scene[] scenes, params object[] modules)
  290. {
  291. SetupSceneModules(scenes, new IniConfigSource(), modules);
  292. }
  293. /// <summary>
  294. /// Setup modules for scenes.
  295. /// </summary>
  296. /// <remarks>
  297. /// If called directly, then all the modules must be shared modules.
  298. ///
  299. /// We are emulating here the normal calls made to setup region modules
  300. /// (Initialise(), PostInitialise(), AddRegion, RegionLoaded()).
  301. /// TODO: Need to reuse normal runtime module code.
  302. /// </remarks>
  303. /// <param name="scenes"></param>
  304. /// <param name="config"></param>
  305. /// <param name="modules"></param>
  306. public static void SetupSceneModules(Scene[] scenes, IConfigSource config, params object[] modules)
  307. {
  308. List<IRegionModuleBase> newModules = new List<IRegionModuleBase>();
  309. foreach (object module in modules)
  310. {
  311. IRegionModuleBase m = (IRegionModuleBase)module;
  312. // Console.WriteLine("MODULE {0}", m.Name);
  313. m.Initialise(config);
  314. newModules.Add(m);
  315. }
  316. foreach (IRegionModuleBase module in newModules)
  317. {
  318. if (module is ISharedRegionModule) ((ISharedRegionModule)module).PostInitialise();
  319. }
  320. foreach (IRegionModuleBase module in newModules)
  321. {
  322. foreach (Scene scene in scenes)
  323. {
  324. module.AddRegion(scene);
  325. scene.AddRegionModule(module.Name, module);
  326. }
  327. }
  328. // RegionLoaded is fired after all modules have been appropriately added to all scenes
  329. foreach (IRegionModuleBase module in newModules)
  330. foreach (Scene scene in scenes)
  331. module.RegionLoaded(scene);
  332. foreach (Scene scene in scenes) { scene.SetModuleInterfaces(); }
  333. }
  334. /// <summary>
  335. /// Generate some standard agent connection data.
  336. /// </summary>
  337. /// <param name="agentId"></param>
  338. /// <returns></returns>
  339. public static AgentCircuitData GenerateAgentData(UUID agentId)
  340. {
  341. AgentCircuitData acd = GenerateCommonAgentData();
  342. acd.AgentID = agentId;
  343. acd.firstname = "testfirstname";
  344. acd.lastname = "testlastname";
  345. acd.ServiceURLs = new Dictionary<string, object>();
  346. return acd;
  347. }
  348. /// <summary>
  349. /// Generate some standard agent connection data.
  350. /// </summary>
  351. /// <param name="agentId"></param>
  352. /// <returns></returns>
  353. public static AgentCircuitData GenerateAgentData(UserAccount ua)
  354. {
  355. AgentCircuitData acd = GenerateCommonAgentData();
  356. acd.AgentID = ua.PrincipalID;
  357. acd.firstname = ua.FirstName;
  358. acd.lastname = ua.LastName;
  359. acd.ServiceURLs = ua.ServiceURLs;
  360. return acd;
  361. }
  362. private static AgentCircuitData GenerateCommonAgentData()
  363. {
  364. AgentCircuitData acd = new AgentCircuitData();
  365. // XXX: Sessions must be unique, otherwise one presence can overwrite another in NullPresenceData.
  366. acd.SessionID = UUID.Random();
  367. acd.SecureSessionID = UUID.Random();
  368. acd.circuitcode = 123;
  369. acd.BaseFolder = UUID.Zero;
  370. acd.InventoryFolder = UUID.Zero;
  371. acd.startpos = Vector3.Zero;
  372. acd.CapsPath = "http://wibble.com";
  373. acd.Appearance = new AvatarAppearance();
  374. return acd;
  375. }
  376. /// <summary>
  377. /// Add a root agent where the details of the agent connection (apart from the id) are unimportant for the test
  378. /// </summary>
  379. /// <remarks>
  380. /// XXX: Use the version of this method that takes the UserAccount structure wherever possible - this will
  381. /// make the agent circuit data (e.g. first, lastname) consistent with the user account data.
  382. /// </remarks>
  383. /// <param name="scene"></param>
  384. /// <param name="agentId"></param>
  385. /// <returns></returns>
  386. public static ScenePresence AddScenePresence(Scene scene, UUID agentId)
  387. {
  388. return AddScenePresence(scene, GenerateAgentData(agentId));
  389. }
  390. /// <summary>
  391. /// Add a root agent.
  392. /// </summary>
  393. /// <param name="scene"></param>
  394. /// <param name="ua"></param>
  395. /// <returns></returns>
  396. public static ScenePresence AddScenePresence(Scene scene, UserAccount ua)
  397. {
  398. return AddScenePresence(scene, GenerateAgentData(ua));
  399. }
  400. /// <summary>
  401. /// Add a root agent.
  402. /// </summary>
  403. /// <remarks>
  404. /// This function
  405. ///
  406. /// 1) Tells the scene that an agent is coming. Normally, the login service (local if standalone, from the
  407. /// userserver if grid) would give initial login data back to the client and separately tell the scene that the
  408. /// agent was coming.
  409. ///
  410. /// 2) Connects the agent with the scene
  411. ///
  412. /// This function performs actions equivalent with notifying the scene that an agent is
  413. /// coming and then actually connecting the agent to the scene. The one step missed out is the very first
  414. /// </remarks>
  415. /// <param name="scene"></param>
  416. /// <param name="agentData"></param>
  417. /// <returns></returns>
  418. public static ScenePresence AddScenePresence(Scene scene, AgentCircuitData agentData)
  419. {
  420. return AddScenePresence(scene, new TestClient(agentData, scene), agentData);
  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(
  441. Scene scene, IClientAPI client, AgentCircuitData agentData)
  442. {
  443. // We emulate the proper login sequence here by doing things in four stages
  444. // Stage 0: login
  445. // We need to punch through to the underlying service because scene will not, correctly, let us call it
  446. // through it's reference to the LPSC
  447. LocalPresenceServicesConnector lpsc = (LocalPresenceServicesConnector)scene.PresenceService;
  448. lpsc.m_PresenceService.LoginAgent(agentData.AgentID.ToString(), agentData.SessionID, agentData.SecureSessionID);
  449. // Stages 1 & 2
  450. ScenePresence sp = IntroduceClientToScene(scene, client, agentData, TeleportFlags.ViaLogin);
  451. // Stage 3: Complete the entrance into the region. This converts the child agent into a root agent.
  452. sp.CompleteMovement(sp.ControllingClient, true);
  453. return sp;
  454. }
  455. /// <summary>
  456. /// Introduce an agent into the scene by adding a new client.
  457. /// </summary>
  458. /// <returns>The scene presence added</returns>
  459. /// <param name='scene'></param>
  460. /// <param name='testClient'></param>
  461. /// <param name='agentData'></param>
  462. /// <param name='tf'></param>
  463. private static ScenePresence IntroduceClientToScene(
  464. Scene scene, IClientAPI client, AgentCircuitData agentData, TeleportFlags tf)
  465. {
  466. string reason;
  467. // Stage 1: tell the scene to expect a new user connection
  468. if (!scene.NewUserConnection(agentData, (uint)tf, out reason))
  469. Console.WriteLine("NewUserConnection failed: " + reason);
  470. // Stage 2: add the new client as a child agent to the scene
  471. scene.AddNewAgent(client, PresenceType.User);
  472. return scene.GetScenePresence(client.AgentId);
  473. }
  474. public static ScenePresence AddChildScenePresence(Scene scene, UUID agentId)
  475. {
  476. AgentCircuitData acd = GenerateAgentData(agentId);
  477. acd.child = true;
  478. // XXX: ViaLogin may not be correct for child agents
  479. TestClient client = new TestClient(acd, scene);
  480. return IntroduceClientToScene(scene, client, acd, TeleportFlags.ViaLogin);
  481. }
  482. /// <summary>
  483. /// Add a test object
  484. /// </summary>
  485. /// <param name="scene"></param>
  486. /// <returns></returns>
  487. public static SceneObjectGroup AddSceneObject(Scene scene)
  488. {
  489. return AddSceneObject(scene, "Test Object", UUID.Zero);
  490. }
  491. /// <summary>
  492. /// Add a test object
  493. /// </summary>
  494. /// <param name="scene"></param>
  495. /// <param name="name"></param>
  496. /// <param name="ownerId"></param>
  497. /// <returns></returns>
  498. public static SceneObjectGroup AddSceneObject(Scene scene, string name, UUID ownerId)
  499. {
  500. SceneObjectGroup so = new SceneObjectGroup(CreateSceneObjectPart(name, UUID.Random(), ownerId));
  501. //part.UpdatePrimFlags(false, false, true);
  502. //part.ObjectFlags |= (uint)PrimFlags.Phantom;
  503. scene.AddNewSceneObject(so, false);
  504. return so;
  505. }
  506. /// <summary>
  507. /// Create a scene object part.
  508. /// </summary>
  509. /// <param name="name"></param>
  510. /// <param name="id"></param>
  511. /// <param name="ownerId"></param>
  512. /// <returns></returns>
  513. public static SceneObjectPart CreateSceneObjectPart(string name, UUID id, UUID ownerId)
  514. {
  515. return new SceneObjectPart(
  516. ownerId, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
  517. { Name = name, UUID = id, Scale = new Vector3(1, 1, 1) };
  518. }
  519. /// <summary>
  520. /// Create a scene object but do not add it to the scene.
  521. /// </summary>
  522. /// <remarks>
  523. /// UUID always starts at 00000000-0000-0000-0000-000000000001. For some purposes, (e.g. serializing direct
  524. /// to another object's inventory) we do not need a scene unique ID. So it would be better to add the
  525. /// UUID when we actually add an object to a scene rather than on creation.
  526. /// </remarks>
  527. /// <param name="parts">The number of parts that should be in the scene object</param>
  528. /// <param name="ownerId"></param>
  529. /// <returns></returns>
  530. public static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId)
  531. {
  532. return CreateSceneObject(parts, ownerId, 0x1);
  533. }
  534. /// <summary>
  535. /// Create a scene object but do not add it to the scene.
  536. /// </summary>
  537. /// <param name="parts">The number of parts that should be in the scene object</param>
  538. /// <param name="ownerId"></param>
  539. /// <param name="uuidTail">
  540. /// The hexadecimal last part of the UUID for parts created. A UUID of the form "00000000-0000-0000-0000-{0:XD12}"
  541. /// will be given to the root part, and incremented for each part thereafter.
  542. /// </param>
  543. /// <returns></returns>
  544. public static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId, int uuidTail)
  545. {
  546. return CreateSceneObject(parts, ownerId, "", uuidTail);
  547. }
  548. /// <summary>
  549. /// Create a scene object but do not add it to the scene.
  550. /// </summary>
  551. /// <param name="parts">
  552. /// The number of parts that should be in the scene object
  553. /// </param>
  554. /// <param name="ownerId"></param>
  555. /// <param name="partNamePrefix">
  556. /// The prefix to be given to part names. This will be suffixed with "Part<part no>"
  557. /// (e.g. mynamePart1 for the root part)
  558. /// </param>
  559. /// <param name="uuidTail">
  560. /// The hexadecimal last part of the UUID for parts created. A UUID of the form "00000000-0000-0000-0000-{0:XD12}"
  561. /// will be given to the root part, and incremented for each part thereafter.
  562. /// </param>
  563. /// <returns></returns>
  564. public static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId, string partNamePrefix, int uuidTail)
  565. {
  566. string rawSogId = string.Format("00000000-0000-0000-0000-{0:X12}", uuidTail);
  567. SceneObjectGroup sog
  568. = new SceneObjectGroup(
  569. CreateSceneObjectPart(string.Format("{0}Part1", partNamePrefix), new UUID(rawSogId), ownerId));
  570. if (parts > 1)
  571. for (int i = 2; i <= parts; i++)
  572. sog.AddPart(
  573. CreateSceneObjectPart(
  574. string.Format("{0}Part{1}", partNamePrefix, i),
  575. new UUID(string.Format("00000000-0000-0000-0000-{0:X12}", uuidTail + i - 1)),
  576. ownerId));
  577. return sog;
  578. }
  579. }
  580. }