RegionApplicationBase.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. */
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Net;
  31. using libsecondlife;
  32. using OpenSim.Framework;
  33. using OpenSim.Framework.Communications;
  34. using OpenSim.Framework.Communications.Cache;
  35. using OpenSim.Framework.Console;
  36. using OpenSim.Framework.Servers;
  37. using OpenSim.Region.Environment;
  38. using OpenSim.Region.Environment.Scenes;
  39. using OpenSim.Region.Physics.Manager;
  40. using OpenSim.Region.Communications.VoiceChat;
  41. namespace OpenSim.Region.ClientStack
  42. {
  43. public abstract class RegionApplicationBase
  44. {
  45. protected AssetCache m_assetCache;
  46. protected Dictionary<EndPoint, uint> m_clientCircuits = new Dictionary<EndPoint, uint>();
  47. protected DateTime m_startuptime;
  48. protected NetworkServersInfo m_networkServersInfo;
  49. protected BaseHttpServer m_httpServer;
  50. protected uint m_httpServerPort;
  51. protected LogBase m_log;
  52. protected CommunicationsManager m_commsManager;
  53. protected SceneManager m_sceneManager = new SceneManager();
  54. protected StorageManager m_storageManager;
  55. protected string m_storageConnectionString;
  56. protected VoiceChatServer m_voiceChatServer;
  57. public SceneManager SceneManager
  58. {
  59. get { return m_sceneManager; }
  60. }
  61. public RegionApplicationBase()
  62. {
  63. m_startuptime = DateTime.Now;
  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.Status("REGION", "Starting HTTP server");
  72. m_httpServer.Start();
  73. }
  74. protected abstract void Initialize();
  75. protected void StartLog()
  76. {
  77. m_log = CreateLog();
  78. MainLog.Instance = m_log;
  79. }
  80. protected abstract LogBase CreateLog();
  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. AgentCircuitManager circuitManager = new AgentCircuitManager();
  93. udpServer = new UDPServer((uint) regionInfo.InternalEndPoint.Port, m_assetCache, m_log, circuitManager);
  94. Scene scene = CreateScene(regionInfo, m_storageManager, circuitManager);
  95. m_voiceChatServer = new VoiceChatServer(scene);
  96. udpServer.LocalScene = scene;
  97. scene.LoadWorldMap();
  98. scene.RegisterRegionWithGrid();
  99. scene.PhysicsScene = GetPhysicsScene();
  100. scene.PhysicsScene.SetTerrain(scene.Terrain.GetHeights1D());
  101. //Master Avatar Setup
  102. UserProfileData masterAvatar;
  103. if (scene.RegionInfo.MasterAvatarAssignedUUID != LLUUID.Zero)
  104. {
  105. masterAvatar = m_commsManager.UserService.SetupMasterUser(scene.RegionInfo.MasterAvatarAssignedUUID);
  106. }
  107. else
  108. {
  109. masterAvatar =
  110. m_commsManager.UserService.SetupMasterUser(scene.RegionInfo.MasterAvatarFirstName,
  111. scene.RegionInfo.MasterAvatarLastName,
  112. scene.RegionInfo.MasterAvatarSandboxPassword);
  113. }
  114. if (masterAvatar != null)
  115. {
  116. m_log.Verbose("PARCEL", "Found master avatar [" + masterAvatar.UUID.ToString() + "]");
  117. scene.RegionInfo.MasterAvatarAssignedUUID = masterAvatar.UUID;
  118. }
  119. else
  120. {
  121. m_log.Verbose("PARCEL", "No master avatar found, using null.");
  122. scene.RegionInfo.MasterAvatarAssignedUUID = LLUUID.Zero;
  123. }
  124. scene.LoadPrimsFromStorage(m_permissions);
  125. scene.loadAllLandObjectsFromStorage();
  126. scene.performParcelPrimCountUpdate();
  127. scene.StartTimer();
  128. return scene;
  129. }
  130. protected abstract Scene CreateScene(RegionInfo regionInfo, StorageManager storageManager,
  131. AgentCircuitManager circuitManager);
  132. }
  133. }