clockwerk-opensim-stable – Blame information for rev 1

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