1
0

LoadRegionsPlugin.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 OpenSimulator 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;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using System.Threading;
  31. using log4net;
  32. using OpenMetaverse;
  33. using OpenSim.Framework;
  34. using OpenSim.Framework.RegionLoader.Filesystem;
  35. using OpenSim.Framework.RegionLoader.Web;
  36. using OpenSim.Region.CoreModules.Agent.AssetTransaction;
  37. using OpenSim.Region.CoreModules.Avatar.InstantMessage;
  38. using OpenSim.Region.CoreModules.Scripting.DynamicTexture;
  39. using OpenSim.Region.CoreModules.Scripting.LoadImageURL;
  40. using OpenSim.Region.CoreModules.Scripting.XMLRPC;
  41. using OpenSim.Services.Interfaces;
  42. namespace OpenSim.ApplicationPlugins.LoadRegions
  43. {
  44. public class LoadRegionsPlugin : IApplicationPlugin, IRegionCreator
  45. {
  46. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  47. public event NewRegionCreated OnNewRegionCreated;
  48. private NewRegionCreated m_newRegionCreatedHandler;
  49. #region IApplicationPlugin Members
  50. // TODO: required by IPlugin, but likely not at all right
  51. private string m_name = "LoadRegionsPlugin";
  52. private string m_version = "0.0";
  53. public string Version
  54. {
  55. get { return m_version; }
  56. }
  57. public string Name
  58. {
  59. get { return m_name; }
  60. }
  61. protected OpenSimBase m_openSim;
  62. public void Initialise()
  63. {
  64. m_log.Error("[LOAD REGIONS PLUGIN]: " + Name + " cannot be default-initialized!");
  65. throw new PluginNotInitialisedException(Name);
  66. }
  67. public void Initialise(OpenSimBase openSim)
  68. {
  69. m_openSim = openSim;
  70. m_openSim.ApplicationRegistry.RegisterInterface<IRegionCreator>(this);
  71. }
  72. public void PostInitialise()
  73. {
  74. //m_log.Info("[LOADREGIONS]: Load Regions addin being initialised");
  75. IRegionLoader regionLoader;
  76. if (m_openSim.ConfigSource.Source.Configs["Startup"].GetString("region_info_source", "filesystem") == "filesystem")
  77. {
  78. m_log.Info("[LOAD REGIONS PLUGIN]: Loading region configurations from filesystem");
  79. regionLoader = new RegionLoaderFileSystem();
  80. }
  81. else
  82. {
  83. m_log.Info("[LOAD REGIONS PLUGIN]: Loading region configurations from web");
  84. regionLoader = new RegionLoaderWebServer();
  85. }
  86. regionLoader.SetIniConfigSource(m_openSim.ConfigSource.Source);
  87. RegionInfo[] regionsToLoad = regionLoader.LoadRegions();
  88. m_log.Info("[LOAD REGIONS PLUGIN]: Loading specific shared modules...");
  89. //m_log.Info("[LOAD REGIONS PLUGIN]: DynamicTextureModule...");
  90. //m_openSim.ModuleLoader.LoadDefaultSharedModule(new DynamicTextureModule());
  91. //m_log.Info("[LOAD REGIONS PLUGIN]: LoadImageURLModule...");
  92. //m_openSim.ModuleLoader.LoadDefaultSharedModule(new LoadImageURLModule());
  93. //m_log.Info("[LOAD REGIONS PLUGIN]: XMLRPCModule...");
  94. //m_openSim.ModuleLoader.LoadDefaultSharedModule(new XMLRPCModule());
  95. // m_log.Info("[LOADREGIONSPLUGIN]: AssetTransactionModule...");
  96. // m_openSim.ModuleLoader.LoadDefaultSharedModule(new AssetTransactionModule());
  97. m_log.Info("[LOAD REGIONS PLUGIN]: Done.");
  98. if (!CheckRegionsForSanity(regionsToLoad))
  99. {
  100. m_log.Error("[LOAD REGIONS PLUGIN]: Halting startup due to conflicts in region configurations");
  101. Environment.Exit(1);
  102. }
  103. List<IScene> createdScenes = new List<IScene>();
  104. for (int i = 0; i < regionsToLoad.Length; i++)
  105. {
  106. IScene scene;
  107. m_log.Debug("[LOAD REGIONS PLUGIN]: Creating Region: " + regionsToLoad[i].RegionName + " (ThreadID: " +
  108. Thread.CurrentThread.ManagedThreadId.ToString() +
  109. ")");
  110. bool changed = m_openSim.PopulateRegionEstateInfo(regionsToLoad[i]);
  111. m_openSim.CreateRegion(regionsToLoad[i], true, out scene);
  112. createdScenes.Add(scene);
  113. if (changed)
  114. m_openSim.EstateDataService.StoreEstateSettings(regionsToLoad[i].EstateSettings);
  115. }
  116. foreach (IScene scene in createdScenes)
  117. {
  118. scene.Start();
  119. m_newRegionCreatedHandler = OnNewRegionCreated;
  120. if (m_newRegionCreatedHandler != null)
  121. {
  122. m_newRegionCreatedHandler(scene);
  123. }
  124. }
  125. }
  126. public void Dispose()
  127. {
  128. }
  129. #endregion
  130. /// <summary>
  131. /// Check that region configuration information makes sense.
  132. /// </summary>
  133. /// <param name="regions"></param>
  134. /// <returns>True if we're sane, false if we're insane</returns>
  135. private bool CheckRegionsForSanity(RegionInfo[] regions)
  136. {
  137. if (regions.Length == 0)
  138. return true;
  139. foreach (RegionInfo region in regions)
  140. {
  141. if (region.RegionID == UUID.Zero)
  142. {
  143. m_log.ErrorFormat(
  144. "[LOAD REGIONS PLUGIN]: Region {0} has invalid UUID {1}",
  145. region.RegionName, region.RegionID);
  146. return false;
  147. }
  148. }
  149. for (int i = 0; i < regions.Length - 1; i++)
  150. {
  151. for (int j = i + 1; j < regions.Length; j++)
  152. {
  153. if (regions[i].RegionID == regions[j].RegionID)
  154. {
  155. m_log.ErrorFormat(
  156. "[LOAD REGIONS PLUGIN]: Regions {0} and {1} have the same UUID {2}",
  157. regions[i].RegionName, regions[j].RegionName, regions[i].RegionID);
  158. return false;
  159. }
  160. else if (
  161. regions[i].RegionLocX == regions[j].RegionLocX && regions[i].RegionLocY == regions[j].RegionLocY)
  162. {
  163. m_log.ErrorFormat(
  164. "[LOAD REGIONS PLUGIN]: Regions {0} and {1} have the same grid location ({2}, {3})",
  165. regions[i].RegionName, regions[j].RegionName, regions[i].RegionLocX, regions[i].RegionLocY);
  166. return false;
  167. }
  168. else if (regions[i].InternalEndPoint.Port == regions[j].InternalEndPoint.Port)
  169. {
  170. m_log.ErrorFormat(
  171. "[LOAD REGIONS PLUGIN]: Regions {0} and {1} have the same internal IP port {2}",
  172. regions[i].RegionName, regions[j].RegionName, regions[i].InternalEndPoint.Port);
  173. return false;
  174. }
  175. }
  176. }
  177. return true;
  178. }
  179. }
  180. }