RegionApplicationBase.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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.ClientStack.LindenUDP;
  38. using OpenSim.Region.Environment;
  39. using OpenSim.Region.Environment.Scenes;
  40. using OpenSim.Region.Physics.Manager;
  41. namespace OpenSim.Region.ClientStack
  42. {
  43. public abstract class RegionApplicationBase : BaseOpenSimServer
  44. {
  45. private static readonly ILog m_log
  46. = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  47. protected AssetCache m_assetCache;
  48. protected Dictionary<EndPoint, uint> m_clientCircuits = new Dictionary<EndPoint, uint>();
  49. protected NetworkServersInfo m_networkServersInfo;
  50. protected BaseHttpServer m_httpServer;
  51. protected uint m_httpServerPort;
  52. protected CommunicationsManager m_commsManager;
  53. public CommunicationsManager CommunicationsManager {
  54. get { return m_commsManager; }
  55. }
  56. protected SceneManager m_sceneManager = new SceneManager();
  57. protected StorageManager m_storageManager;
  58. protected string m_storageConnectionString;
  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 virtual void StartUp()
  67. {
  68. LLClientView.TerrainManager = new TerrainManager(new SecondLife());
  69. m_storageManager = CreateStorageManager(m_storageConnectionString);
  70. Initialize();
  71. m_httpServer = new BaseHttpServer(m_httpServerPort);
  72. m_log.Info("[REGION]: Starting HTTP server");
  73. m_httpServer.Start();
  74. }
  75. protected abstract void Initialize();
  76. // protected void StartConsole()
  77. // {
  78. // m_console = CreateConsole();
  79. // MainConsole.Instance = m_console;
  80. // }
  81. // protected abstract ConsoleBase CreateConsole();
  82. protected abstract PhysicsScene GetPhysicsScene();
  83. protected abstract StorageManager CreateStorageManager(string connectionstring);
  84. protected PhysicsScene GetPhysicsScene(string engine, string meshEngine, IConfigSource config)
  85. {
  86. PhysicsPluginManager physicsPluginManager;
  87. physicsPluginManager = new PhysicsPluginManager();
  88. physicsPluginManager.LoadPlugins();
  89. return physicsPluginManager.GetPhysicsScene(engine, meshEngine, config);
  90. }
  91. protected Scene SetupScene(RegionInfo regionInfo, out IClientNetworkServer clientServer)
  92. {
  93. return SetupScene(regionInfo, 0, out clientServer);
  94. }
  95. protected Scene SetupScene(RegionInfo regionInfo, int proxyOffset, out IClientNetworkServer clientServer)
  96. {
  97. AgentCircuitManager circuitManager = new AgentCircuitManager();
  98. IPAddress listenIP = regionInfo.InternalEndPoint.Address;
  99. //if (!IPAddress.TryParse(regionInfo.InternalEndPoint, out listenIP))
  100. // listenIP = IPAddress.Parse("0.0.0.0");
  101. uint port = (uint) regionInfo.InternalEndPoint.Port;
  102. clientServer = new LLUDPServer(listenIP, ref port, proxyOffset, regionInfo.m_allow_alternate_ports, m_assetCache, circuitManager);
  103. regionInfo.InternalEndPoint.Port = (int)port;
  104. Scene scene = CreateScene(regionInfo, m_storageManager, circuitManager);
  105. clientServer.AddScene(scene);
  106. scene.LoadWorldMap();
  107. scene.PhysicsScene = GetPhysicsScene();
  108. scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised());
  109. scene.PhysicsScene.SetWaterLevel(regionInfo.EstateSettings.waterHeight);
  110. //Master Avatar Setup
  111. UserProfileData masterAvatar;
  112. if (scene.RegionInfo.MasterAvatarAssignedUUID != LLUUID.Zero)
  113. {
  114. masterAvatar = m_commsManager.UserService.SetupMasterUser(scene.RegionInfo.MasterAvatarAssignedUUID);
  115. }
  116. else
  117. {
  118. masterAvatar =
  119. m_commsManager.UserService.SetupMasterUser(scene.RegionInfo.MasterAvatarFirstName,
  120. scene.RegionInfo.MasterAvatarLastName,
  121. scene.RegionInfo.MasterAvatarSandboxPassword);
  122. }
  123. if (masterAvatar != null)
  124. {
  125. m_log.Info("[PARCEL]: Found master avatar [" + masterAvatar.ID.ToString() + "]");
  126. scene.RegionInfo.MasterAvatarAssignedUUID = masterAvatar.ID;
  127. }
  128. else
  129. {
  130. m_log.Info("[PARCEL]: No master avatar found, using null.");
  131. scene.RegionInfo.MasterAvatarAssignedUUID = LLUUID.Zero;
  132. }
  133. scene.LoadPrimsFromStorage(regionInfo.originRegionID);
  134. scene.StartTimer();
  135. return scene;
  136. }
  137. protected abstract Scene CreateScene(RegionInfo regionInfo, StorageManager storageManager,
  138. AgentCircuitManager circuitManager);
  139. }
  140. }