SceneHelpers.cs 29 KB

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