1
0

SceneSetupHelpers.cs 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 OpenSim 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.Net;
  28. using Nini.Config;
  29. using OpenMetaverse;
  30. using OpenSim.Framework;
  31. using OpenSim.Framework.Communications;
  32. using OpenSim.Framework.Communications.Cache;
  33. using OpenSim.Framework.Servers;
  34. using OpenSim.Region.Physics.Manager;
  35. using OpenSim.Region.Framework;
  36. using OpenSim.Region.Framework.Interfaces;
  37. using OpenSim.Region.Framework.Scenes;
  38. using OpenSim.Region.CoreModules.Agent.Capabilities;
  39. using OpenSim.Tests.Common.Mock;
  40. namespace OpenSim.Tests.Common.Setup
  41. {
  42. /// <summary>
  43. /// Helpers for setting up scenes.
  44. /// </summary>
  45. public class SceneSetupHelpers
  46. {
  47. /// <summary>
  48. /// Set up a test scene
  49. /// </summary>
  50. /// <returns></returns>
  51. public static TestScene SetupScene()
  52. {
  53. return SetupScene("Unit test region", UUID.Random(), 1000, 1000, new TestCommunicationsManager());
  54. }
  55. /// <summary>
  56. /// Set up a test scene
  57. /// </summary>
  58. /// <param name="name">Name of the region</param>
  59. /// <param name="id">ID of the region</param>
  60. /// <param name="x">X co-ordinate of the region</param>
  61. /// <param name="y">Y co-ordinate of the region</param>
  62. /// <param name="cm">This should be the same if simulating two scenes within a standalone</param>
  63. /// <returns></returns>
  64. public static TestScene SetupScene(string name, UUID id, uint x, uint y, CommunicationsManager cm)
  65. {
  66. RegionInfo regInfo = new RegionInfo(x, y, new IPEndPoint(IPAddress.Loopback, 9000), "127.0.0.1");
  67. regInfo.RegionName = name;
  68. regInfo.RegionID = id;
  69. AgentCircuitManager acm = new AgentCircuitManager();
  70. SceneCommunicationService scs = new SceneCommunicationService(cm);
  71. StorageManager sm = new StorageManager("OpenSim.Data.Null.dll", "", "");
  72. IConfigSource configSource = new IniConfigSource();
  73. TestScene testScene = new TestScene(
  74. regInfo, acm, cm, scs, sm, null, false, false, false, configSource, null);
  75. IRegionModule capsModule = new CapabilitiesModule();
  76. capsModule.Initialise(testScene, new IniConfigSource());
  77. testScene.AddModule(capsModule.Name, capsModule);
  78. testScene.SetModuleInterfaces();
  79. testScene.LandChannel = new TestLandChannel();
  80. testScene.LoadWorldMap();
  81. PhysicsPluginManager physicsPluginManager = new PhysicsPluginManager();
  82. physicsPluginManager.LoadPluginsFromAssembly("Physics/OpenSim.Region.Physics.BasicPhysicsPlugin.dll");
  83. testScene.PhysicsScene
  84. = physicsPluginManager.GetPhysicsScene("basicphysics", "ZeroMesher", configSource, "test");
  85. return testScene;
  86. }
  87. /// <summary>
  88. /// Setup modules for a scene using their default settings.
  89. /// </summary>
  90. /// <param name="scene"></param>
  91. /// <param name="modules"></param>
  92. public static void SetupSceneModules(Scene scene, params IRegionModule[] modules)
  93. {
  94. SetupSceneModules(scene, null, modules);
  95. }
  96. /// <summary>
  97. /// Setup modules for a scene.
  98. /// </summary>
  99. /// <param name="scene"></param>
  100. /// <param name="config"></param>
  101. /// <param name="modules"></param>
  102. public static void SetupSceneModules(Scene scene, IConfigSource config, params IRegionModule[] modules)
  103. {
  104. foreach (IRegionModule module in modules)
  105. {
  106. module.Initialise(scene, config);
  107. scene.AddModule(module.Name, module);
  108. }
  109. scene.SetModuleInterfaces();
  110. }
  111. /// <summary>
  112. /// Generate some standard agent connection data.
  113. /// </summary>
  114. /// <param name="agentId"></param>
  115. /// <returns></returns>
  116. public static AgentCircuitData GenerateAgentData(UUID agentId)
  117. {
  118. string firstName = "testfirstname";
  119. AgentCircuitData agentData = new AgentCircuitData();
  120. agentData.AgentID = agentId;
  121. agentData.firstname = firstName;
  122. agentData.lastname = "testlastname";
  123. agentData.SessionID = UUID.Zero;
  124. agentData.SecureSessionID = UUID.Zero;
  125. agentData.circuitcode = 123;
  126. agentData.BaseFolder = UUID.Zero;
  127. agentData.InventoryFolder = UUID.Zero;
  128. agentData.startpos = Vector3.Zero;
  129. agentData.CapsPath = "http://wibble.com";
  130. return agentData;
  131. }
  132. /// <summary>
  133. /// Add a root agent where the details of the agent connection (apart from the id) are unimportant for the test
  134. /// </summary>
  135. /// <param name="scene"></param>
  136. /// <param name="agentId"></param>
  137. /// <returns></returns>
  138. public static TestClient AddRootAgent(Scene scene, UUID agentId)
  139. {
  140. return AddRootAgent(scene, GenerateAgentData(agentId));
  141. }
  142. /// <summary>
  143. /// Add a root agent.
  144. /// </summary>
  145. ///
  146. /// This function
  147. ///
  148. /// 1) Tells the scene that an agent is coming. Normally, the login service (local if standalone, from the
  149. /// userserver if grid) would give initial login data back to the client and separately tell the scene that the
  150. /// agent was coming.
  151. ///
  152. /// 2) Connects the agent with the scene
  153. ///
  154. /// This function performs actions equivalent with notifying the scene that an agent is
  155. /// coming and then actually connecting the agent to the scene. The one step missed out is the very first
  156. ///
  157. /// <param name="scene"></param>
  158. /// <param name="agentData"></param>
  159. /// <returns></returns>
  160. public static TestClient AddRootAgent(Scene scene, AgentCircuitData agentData)
  161. {
  162. // We emulate the proper login sequence here by doing things in three stages
  163. // Stage 1: simulate login by telling the scene to expect a new user connection
  164. scene.NewUserConnection(agentData);
  165. // Stage 2: add the new client as a child agent to the scene
  166. TestClient client = new TestClient(agentData, scene);
  167. scene.AddNewClient(client);
  168. // Stage 3: Invoke agent crossing, which converts the child agent into a root agent (with appearance,
  169. // inventory, etc.)
  170. //scene.AgentCrossing(agentData.AgentID, new Vector3(90, 90, 90), false); OBSOLETE
  171. ScenePresence scp = scene.GetScenePresence(agentData.AgentID);
  172. scp.MakeRootAgent(new Vector3(90,90,90), true);
  173. return client;
  174. }
  175. /// <summary>
  176. /// Add a test object
  177. /// </summary>
  178. /// <param name="scene"></param>
  179. /// <returns></returns>
  180. public static SceneObjectPart AddSceneObject(Scene scene)
  181. {
  182. return AddSceneObject(scene, "Test Object");
  183. }
  184. /// <summary>
  185. /// Add a test object
  186. /// </summary>
  187. /// <param name="scene"></param>
  188. /// <param name="name"></param>
  189. /// <returns></returns>
  190. public static SceneObjectPart AddSceneObject(Scene scene, string name)
  191. {
  192. SceneObjectPart part
  193. = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero);
  194. part.Name = name;
  195. //part.UpdatePrimFlags(false, false, true);
  196. //part.ObjectFlags |= (uint)PrimFlags.Phantom;
  197. scene.AddNewSceneObject(new SceneObjectGroup(part), false);
  198. return part;
  199. }
  200. /// <summary>
  201. /// Delete a scene object asynchronously
  202. /// </summary>
  203. /// <param name="scene"></param>
  204. /// <param name="part"></param>
  205. /// <param name="action"></param>
  206. /// <param name="destinationId"></param>
  207. /// <param name="client"></param>
  208. public static void DeleteSceneObjectAsync(
  209. TestScene scene, SceneObjectPart part, DeRezAction action, UUID destinationId, IClientAPI client)
  210. {
  211. // Turn off the timer on the async sog deleter - we'll crank it by hand within a unit test
  212. AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
  213. sogd.Enabled = false;
  214. scene.DeRezObject(client, part.LocalId, UUID.Zero, action, destinationId);
  215. sogd.InventoryDeQueueAndDelete();
  216. }
  217. }
  218. }