RegionApplicationBase.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 OpenSim.Framework;
  33. using OpenSim.Framework.Communications;
  34. using OpenSim.Framework.Communications.Cache;
  35. using OpenSim.Framework.Servers;
  36. using OpenSim.Region.Environment;
  37. using OpenSim.Region.Environment.Scenes;
  38. using OpenSim.Region.Physics.Manager;
  39. //using OpenSim.Framework.Console;
  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. // An attribute to indicate whether prim inventories should be persisted.
  59. // Probably will be temporary until this stops being experimental.
  60. protected bool m_storagePersistPrimInventories;
  61. public SceneManager SceneManager
  62. {
  63. get { return m_sceneManager; }
  64. }
  65. public virtual void StartUp()
  66. {
  67. ClientView.TerrainManager = new TerrainManager(new SecondLife());
  68. m_storageManager = CreateStorageManager(m_storageConnectionString);
  69. Initialize();
  70. m_httpServer = new BaseHttpServer(m_httpServerPort);
  71. m_log.Info("[REGION]: Starting HTTP server");
  72. m_httpServer.Start();
  73. }
  74. protected abstract void Initialize();
  75. // protected void StartConsole()
  76. // {
  77. // m_console = CreateConsole();
  78. // MainConsole.Instance = m_console;
  79. // }
  80. // protected abstract ConsoleBase CreateConsole();
  81. protected abstract PhysicsScene GetPhysicsScene();
  82. protected abstract StorageManager CreateStorageManager(string connectionstring);
  83. protected PhysicsScene GetPhysicsScene(string engine, string meshEngine)
  84. {
  85. PhysicsPluginManager physicsPluginManager;
  86. physicsPluginManager = new PhysicsPluginManager();
  87. physicsPluginManager.LoadPlugins();
  88. return physicsPluginManager.GetPhysicsScene(engine, meshEngine);
  89. }
  90. protected Scene SetupScene(RegionInfo regionInfo, out UDPServer udpServer, bool m_permissions)
  91. {
  92. return SetupScene(regionInfo, 0, out udpServer, m_permissions);
  93. }
  94. protected Scene SetupScene(RegionInfo regionInfo, int proxyOffset, out UDPServer udpServer, bool m_permissions)
  95. {
  96. AgentCircuitManager circuitManager = new AgentCircuitManager();
  97. IPAddress listenIP = regionInfo.InternalEndPoint.Address;
  98. //if (!IPAddress.TryParse(regionInfo.InternalEndPoint, out listenIP))
  99. // listenIP = IPAddress.Parse("0.0.0.0");
  100. uint port = (uint) regionInfo.InternalEndPoint.Port;
  101. udpServer = new UDPServer(listenIP, ref port, proxyOffset, regionInfo.m_allow_alternate_ports, m_assetCache, circuitManager);
  102. regionInfo.InternalEndPoint.Port = (int)port;
  103. Scene scene = CreateScene(regionInfo, m_storageManager, circuitManager);
  104. udpServer.LocalScene = scene;
  105. scene.LoadWorldMap();
  106. //moved to opensimMain as these have to happen after modules are initialised
  107. // scene.CreateTerrainTexture(true);
  108. // scene.RegisterRegionWithGrid();
  109. scene.PhysicsScene = GetPhysicsScene();
  110. scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised());
  111. scene.PhysicsScene.SetWaterLevel(regionInfo.EstateSettings.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(m_permissions, regionInfo.originRegionID);
  136. scene.StartTimer();
  137. return scene;
  138. }
  139. protected abstract Scene CreateScene(RegionInfo regionInfo, StorageManager storageManager,
  140. AgentCircuitManager circuitManager);
  141. }
  142. }