OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
LoadRegionsPlugin.cs
Go to the documentation of this file.
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 
28 using System;
29 using System.Collections.Generic;
30 using System.Reflection;
31 using System.Threading;
32 using log4net;
33 using OpenMetaverse;
34 using OpenSim.Framework;
35 using OpenSim.Region.CoreModules.Agent.AssetTransaction;
36 using OpenSim.Region.CoreModules.Avatar.InstantMessage;
37 using OpenSim.Region.CoreModules.Scripting.DynamicTexture;
38 using OpenSim.Region.CoreModules.Scripting.LoadImageURL;
39 using OpenSim.Region.CoreModules.Scripting.XMLRPC;
40 using OpenSim.Services.Interfaces;
41 using Mono.Addins;
42 
43 namespace OpenSim.ApplicationPlugins.LoadRegions
44 {
45  [Extension(Path="/OpenSim/Startup", Id="LoadRegions", NodeName="Plugin")]
47  {
48  private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49 
51  private NewRegionCreated m_newRegionCreatedHandler;
52 
53  #region IApplicationPlugin Members
54 
55  // TODO: required by IPlugin, but likely not at all right
56  private string m_name = "LoadRegionsPlugin";
57  private string m_version = "0.0";
58 
59  public string Version
60  {
61  get { return m_version; }
62  }
63 
64  public string Name
65  {
66  get { return m_name; }
67  }
68 
70 
71  public void Initialise()
72  {
73  m_log.Error("[LOAD REGIONS PLUGIN]: " + Name + " cannot be default-initialized!");
74  throw new PluginNotInitialisedException(Name);
75  }
76 
77  public void Initialise(OpenSimBase openSim)
78  {
79  m_openSim = openSim;
80  m_openSim.ApplicationRegistry.RegisterInterface<IRegionCreator>(this);
81  }
82 
83  public void PostInitialise()
84  {
85  //m_log.Info("[LOADREGIONS]: Load Regions addin being initialised");
86 
87  IRegionLoader regionLoader;
88  if (m_openSim.ConfigSource.Source.Configs["Startup"].GetString("region_info_source", "filesystem") == "filesystem")
89  {
90  m_log.Info("[LOAD REGIONS PLUGIN]: Loading region configurations from filesystem");
91  regionLoader = new RegionLoaderFileSystem();
92  }
93  else
94  {
95  m_log.Info("[LOAD REGIONS PLUGIN]: Loading region configurations from web");
96  regionLoader = new RegionLoaderWebServer();
97  }
98 
99  regionLoader.SetIniConfigSource(m_openSim.ConfigSource.Source);
100  RegionInfo[] regionsToLoad = regionLoader.LoadRegions();
101 
102  m_log.Info("[LOAD REGIONS PLUGIN]: Loading specific shared modules...");
103  //m_log.Info("[LOAD REGIONS PLUGIN]: DynamicTextureModule...");
104  //m_openSim.ModuleLoader.LoadDefaultSharedModule(new DynamicTextureModule());
105  //m_log.Info("[LOAD REGIONS PLUGIN]: LoadImageURLModule...");
106  //m_openSim.ModuleLoader.LoadDefaultSharedModule(new LoadImageURLModule());
107  //m_log.Info("[LOAD REGIONS PLUGIN]: XMLRPCModule...");
108  //m_openSim.ModuleLoader.LoadDefaultSharedModule(new XMLRPCModule());
109 // m_log.Info("[LOADREGIONSPLUGIN]: AssetTransactionModule...");
110 // m_openSim.ModuleLoader.LoadDefaultSharedModule(new AssetTransactionModule());
111  m_log.Info("[LOAD REGIONS PLUGIN]: Done.");
112 
113  if (!CheckRegionsForSanity(regionsToLoad))
114  {
115  m_log.Error("[LOAD REGIONS PLUGIN]: Halting startup due to conflicts in region configurations");
116  Environment.Exit(1);
117  }
118 
119  List<IScene> createdScenes = new List<IScene>();
120 
121  for (int i = 0; i < regionsToLoad.Length; i++)
122  {
123  IScene scene;
124  m_log.Debug("[LOAD REGIONS PLUGIN]: Creating Region: " + regionsToLoad[i].RegionName + " (ThreadID: " +
125  Thread.CurrentThread.ManagedThreadId.ToString() +
126  ")");
127 
128  bool changed = m_openSim.PopulateRegionEstateInfo(regionsToLoad[i]);
129 
130  m_openSim.CreateRegion(regionsToLoad[i], true, out scene);
131  createdScenes.Add(scene);
132 
133  if (changed)
134  m_openSim.EstateDataService.StoreEstateSettings(regionsToLoad[i].EstateSettings);
135  }
136 
137  foreach (IScene scene in createdScenes)
138  {
139  scene.Start();
140 
141  m_newRegionCreatedHandler = OnNewRegionCreated;
142  if (m_newRegionCreatedHandler != null)
143  {
144  m_newRegionCreatedHandler(scene);
145  }
146  }
147  }
148 
149  public void Dispose()
150  {
151  }
152 
153  #endregion
154 
160  private bool CheckRegionsForSanity(RegionInfo[] regions)
161  {
162  if (regions.Length == 0)
163  return true;
164 
165  foreach (RegionInfo region in regions)
166  {
167  if (region.RegionID == UUID.Zero)
168  {
169  m_log.ErrorFormat(
170  "[LOAD REGIONS PLUGIN]: Region {0} has invalid UUID {1}",
171  region.RegionName, region.RegionID);
172  return false;
173  }
174  }
175 
176  for (int i = 0; i < regions.Length - 1; i++)
177  {
178  for (int j = i + 1; j < regions.Length; j++)
179  {
180  if (regions[i].RegionID == regions[j].RegionID)
181  {
182  m_log.ErrorFormat(
183  "[LOAD REGIONS PLUGIN]: Regions {0} and {1} have the same UUID {2}",
184  regions[i].RegionName, regions[j].RegionName, regions[i].RegionID);
185  return false;
186  }
187  else if (
188  regions[i].RegionLocX == regions[j].RegionLocX && regions[i].RegionLocY == regions[j].RegionLocY)
189  {
190  m_log.ErrorFormat(
191  "[LOAD REGIONS PLUGIN]: Regions {0} and {1} have the same grid location ({2}, {3})",
192  regions[i].RegionName, regions[j].RegionName, regions[i].RegionLocX, regions[i].RegionLocY);
193  return false;
194  }
195  else if (regions[i].InternalEndPoint.Port == regions[j].InternalEndPoint.Port)
196  {
197  m_log.ErrorFormat(
198  "[LOAD REGIONS PLUGIN]: Regions {0} and {1} have the same internal IP port {2}",
199  regions[i].RegionName, regions[j].RegionName, regions[i].InternalEndPoint.Port);
200  return false;
201  }
202  }
203  }
204 
205  return true;
206  }
207  }
208 }
delegate void NewRegionCreated(IScene scene)
OpenSimulator Application Plugin framework interface
void Initialise()
Default-initialises the plugin
void PostInitialise()
Called when the application loading is completed
void Initialise(OpenSimBase openSim)
Initialize the Plugin
Exception thrown if Initialise has been called, but failed.
Definition: IPlugin.cs:35
Common OpenSimulator simulator code
Definition: OpenSimBase.cs:58