RegionApplicationBase.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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.Collections.Generic;
  28. using System.Net;
  29. using System.Reflection;
  30. using libsecondlife;
  31. using log4net;
  32. using Nini.Config;
  33. using OpenSim.Framework;
  34. using OpenSim.Framework.Communications;
  35. using OpenSim.Framework.Communications.Cache;
  36. using OpenSim.Framework.Servers;
  37. using OpenSim.Region.Environment;
  38. using OpenSim.Region.Environment.Scenes;
  39. using OpenSim.Region.Physics.Manager;
  40. namespace OpenSim.Region.ClientStack
  41. {
  42. public abstract class RegionApplicationBase : BaseOpenSimServer
  43. {
  44. private static readonly ILog m_log
  45. = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  46. protected AssetCache m_assetCache;
  47. protected Dictionary<EndPoint, uint> m_clientCircuits = new Dictionary<EndPoint, uint>();
  48. protected NetworkServersInfo m_networkServersInfo;
  49. protected BaseHttpServer m_httpServer;
  50. protected uint m_httpServerPort;
  51. protected CommunicationsManager m_commsManager;
  52. public CommunicationsManager CommunicationsManager {
  53. get { return m_commsManager; }
  54. }
  55. protected SceneManager m_sceneManager = new SceneManager();
  56. protected StorageManager m_storageManager;
  57. protected string m_storageConnectionString;
  58. protected ClientStackManager m_clientStackManager;
  59. // An attribute to indicate whether prim inventories should be persisted.
  60. // Probably will be temporary until this stops being experimental.
  61. protected bool m_storagePersistPrimInventories;
  62. public SceneManager SceneManager
  63. {
  64. get { return m_sceneManager; }
  65. }
  66. public override void Startup()
  67. {
  68. base.Startup();
  69. m_storageManager = CreateStorageManager(m_storageConnectionString);
  70. m_clientStackManager = CreateClientStackManager();
  71. Initialize();
  72. m_httpServer = new BaseHttpServer(m_httpServerPort);
  73. m_log.Info("[REGION]: Starting HTTP server");
  74. m_httpServer.Start();
  75. }
  76. protected abstract void Initialize();
  77. // protected void StartConsole()
  78. // {
  79. // m_console = CreateConsole();
  80. // MainConsole.Instance = m_console;
  81. // }
  82. // protected abstract ConsoleBase CreateConsole();
  83. protected abstract PhysicsScene GetPhysicsScene();
  84. protected abstract StorageManager CreateStorageManager(string connectionstring);
  85. protected abstract ClientStackManager CreateClientStackManager();
  86. protected PhysicsScene GetPhysicsScene(string engine, string meshEngine, IConfigSource config)
  87. {
  88. PhysicsPluginManager physicsPluginManager;
  89. physicsPluginManager = new PhysicsPluginManager();
  90. physicsPluginManager.LoadPlugins();
  91. return physicsPluginManager.GetPhysicsScene(engine, meshEngine, config);
  92. }
  93. protected Scene SetupScene(RegionInfo regionInfo, out IClientNetworkServer clientServer)
  94. {
  95. return SetupScene(regionInfo, 0, out clientServer);
  96. }
  97. protected Scene SetupScene(RegionInfo regionInfo, int proxyOffset, out IClientNetworkServer clientServer)
  98. {
  99. AgentCircuitManager circuitManager = new AgentCircuitManager();
  100. IPAddress listenIP = regionInfo.InternalEndPoint.Address;
  101. //if (!IPAddress.TryParse(regionInfo.InternalEndPoint, out listenIP))
  102. // listenIP = IPAddress.Parse("0.0.0.0");
  103. uint port = (uint) regionInfo.InternalEndPoint.Port;
  104. clientServer = m_clientStackManager.CreateServer(listenIP, ref port, proxyOffset, regionInfo.m_allow_alternate_ports, m_assetCache, circuitManager);
  105. regionInfo.InternalEndPoint.Port = (int)port;
  106. Scene scene = CreateScene(regionInfo, m_storageManager, circuitManager);
  107. clientServer.AddScene(scene);
  108. scene.LoadWorldMap();
  109. scene.PhysicsScene = GetPhysicsScene();
  110. scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised());
  111. scene.PhysicsScene.SetWaterLevel((float)regionInfo.RegionSettings.WaterHeight);
  112. //Master Avatar Setup
  113. UserProfileData masterAvatar;
  114. if (scene.RegionInfo.MasterAvatarAssignedUUID != LLUUID.Zero)
  115. {
  116. masterAvatar = m_commsManager.UserService.SetupMasterUser(scene.RegionInfo.MasterAvatarAssignedUUID);
  117. }
  118. else
  119. {
  120. masterAvatar =
  121. m_commsManager.UserService.SetupMasterUser(scene.RegionInfo.MasterAvatarFirstName,
  122. scene.RegionInfo.MasterAvatarLastName,
  123. scene.RegionInfo.MasterAvatarSandboxPassword);
  124. }
  125. if (masterAvatar != null)
  126. {
  127. m_log.Info("[PARCEL]: Found master avatar [" + masterAvatar.ID.ToString() + "]");
  128. scene.RegionInfo.MasterAvatarAssignedUUID = masterAvatar.ID;
  129. }
  130. else
  131. {
  132. m_log.Info("[PARCEL]: No master avatar found, using null.");
  133. scene.RegionInfo.MasterAvatarAssignedUUID = LLUUID.Zero;
  134. }
  135. scene.LoadPrimsFromStorage(regionInfo.originRegionID);
  136. scene.StartTimer();
  137. return scene;
  138. }
  139. protected abstract Scene CreateScene(RegionInfo regionInfo, StorageManager storageManager,
  140. AgentCircuitManager circuitManager);
  141. }
  142. }