diff options
author | Justin Clarke Casey | 2008-06-01 01:01:16 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2008-06-01 01:01:16 +0000 |
commit | 8e1d3386561f263646c10c875aa00af4b3c9f815 (patch) | |
tree | 3fc89893ecdd75b0be7283dd0b4a2b9376b59964 /OpenSim/Region/Application/OpenSimMain.cs | |
parent | * Updates permission module so that GenericCommunicationPermission returns tr... (diff) | |
download | opensim-SC_OLD-8e1d3386561f263646c10c875aa00af4b3c9f815.zip opensim-SC_OLD-8e1d3386561f263646c10c875aa00af4b3c9f815.tar.gz opensim-SC_OLD-8e1d3386561f263646c10c875aa00af4b3c9f815.tar.bz2 opensim-SC_OLD-8e1d3386561f263646c10c875aa00af4b3c9f815.tar.xz |
* Refactor: Split opensim background server into a separate class
Diffstat (limited to 'OpenSim/Region/Application/OpenSimMain.cs')
-rw-r--r-- | OpenSim/Region/Application/OpenSimMain.cs | 729 |
1 files changed, 0 insertions, 729 deletions
diff --git a/OpenSim/Region/Application/OpenSimMain.cs b/OpenSim/Region/Application/OpenSimMain.cs deleted file mode 100644 index 03dbf78..0000000 --- a/OpenSim/Region/Application/OpenSimMain.cs +++ /dev/null | |||
@@ -1,729 +0,0 @@ | |||
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.IO; | ||
31 | using System.Net; | ||
32 | using System.Reflection; | ||
33 | using System.Text; | ||
34 | using System.Threading; | ||
35 | using libsecondlife; | ||
36 | using log4net; | ||
37 | using Mono.Addins; | ||
38 | using Nini.Config; | ||
39 | using OpenSim.Framework; | ||
40 | using OpenSim.Framework.Communications.Cache; | ||
41 | using OpenSim.Framework.Servers; | ||
42 | using OpenSim.Framework.Statistics; | ||
43 | using OpenSim.Region.ClientStack; | ||
44 | using OpenSim.Region.Communications.Local; | ||
45 | using OpenSim.Region.Communications.OGS1; | ||
46 | using OpenSim.Region.Environment; | ||
47 | using OpenSim.Region.Environment.Interfaces; | ||
48 | using OpenSim.Region.Environment.Scenes; | ||
49 | using OpenSim.Region.Physics.Manager; | ||
50 | |||
51 | namespace OpenSim | ||
52 | { | ||
53 | public class OpenSimMain : RegionApplicationBase | ||
54 | { | ||
55 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
56 | |||
57 | protected string proxyUrl; | ||
58 | protected int proxyOffset = 0; | ||
59 | |||
60 | /// <summary> | ||
61 | /// The file used to load and save prim backup xml if none has been specified | ||
62 | /// </summary> | ||
63 | protected const string DEFAULT_PRIM_BACKUP_FILENAME = "prim-backup.xml"; | ||
64 | |||
65 | /// <summary> | ||
66 | /// The file use to load and save an opensim archive if none has been specified | ||
67 | /// </summary> | ||
68 | protected const string DEFAULT_OAR_BACKUP_FILENAME = "scene.oar.tar"; | ||
69 | |||
70 | public string m_physicsEngine; | ||
71 | public string m_meshEngineName; | ||
72 | public string m_scriptEngine; | ||
73 | public bool m_sandbox; | ||
74 | public bool user_accounts; | ||
75 | public bool m_gridLocalAsset; | ||
76 | public bool m_see_into_region_from_neighbor; | ||
77 | |||
78 | protected LocalLoginService m_loginService; | ||
79 | |||
80 | protected string m_storageDll; | ||
81 | |||
82 | protected List<IClientNetworkServer> m_clientServers = new List<IClientNetworkServer>(); | ||
83 | protected List<RegionInfo> m_regionData = new List<RegionInfo>(); | ||
84 | |||
85 | protected bool m_physicalPrim; | ||
86 | |||
87 | protected bool m_standaloneAuthenticate = false; | ||
88 | protected string m_standaloneWelcomeMessage = null; | ||
89 | protected string m_standaloneInventoryPlugin; | ||
90 | protected string m_standaloneAssetPlugin; | ||
91 | protected string m_standaloneUserPlugin; | ||
92 | |||
93 | private string m_standaloneInventorySource; | ||
94 | private string m_standaloneAssetSource; | ||
95 | private string m_standaloneUserSource; | ||
96 | |||
97 | protected string m_assetStorage = "local"; | ||
98 | |||
99 | public ConsoleCommand CreateAccount = null; | ||
100 | protected bool m_dumpAssetsToFile; | ||
101 | |||
102 | protected List<IApplicationPlugin> m_plugins = new List<IApplicationPlugin>(); | ||
103 | |||
104 | protected IConfigSource m_finalConfig = null; | ||
105 | |||
106 | protected IniConfigSource m_config; | ||
107 | |||
108 | public IniConfigSource ConfigSource | ||
109 | { | ||
110 | get { return m_config; } | ||
111 | set { m_config = value; } | ||
112 | } | ||
113 | |||
114 | public List<IClientNetworkServer> ClientServers | ||
115 | { | ||
116 | get { return m_clientServers; } | ||
117 | } | ||
118 | |||
119 | public List<RegionInfo> RegionData | ||
120 | { | ||
121 | get { return m_regionData; } | ||
122 | } | ||
123 | |||
124 | public new BaseHttpServer HttpServer | ||
125 | { | ||
126 | get { return m_httpServer; } | ||
127 | } | ||
128 | |||
129 | public new uint HttpServerPort | ||
130 | { | ||
131 | get { return m_httpServerPort; } | ||
132 | } | ||
133 | |||
134 | protected ModuleLoader m_moduleLoader; | ||
135 | |||
136 | public ModuleLoader ModuleLoader | ||
137 | { | ||
138 | get { return m_moduleLoader; } | ||
139 | set { m_moduleLoader = value; } | ||
140 | } | ||
141 | |||
142 | public OpenSimMain(IConfigSource configSource) | ||
143 | : base() | ||
144 | { | ||
145 | IConfig startupConfig = configSource.Configs["Startup"]; | ||
146 | |||
147 | // The Mono addin manager (in Mono.Addins.dll version 0.2.0.0) occasionally seems to corrupt its addin cache | ||
148 | // Hence, as a temporary solution we'll remove it before each startup | ||
149 | if (Directory.Exists("addin-db-000")) | ||
150 | Directory.Delete("addin-db-000", true); | ||
151 | |||
152 | if (Directory.Exists("addin-db-001")) | ||
153 | Directory.Delete("addin-db-001", true); | ||
154 | |||
155 | // This blocks the scanning warnings from outputing to the console. | ||
156 | TextWriter oldOutput = Console.Out; | ||
157 | Console.SetOut(new StreamWriter(Stream.Null)); | ||
158 | |||
159 | AddinManager.Initialize("."); | ||
160 | AddinManager.Registry.Update(null); | ||
161 | |||
162 | // Returns the console.writelines back to the console's stream | ||
163 | Console.SetOut(oldOutput); | ||
164 | |||
165 | Application.iniFilePath = startupConfig.GetString("inifile", "OpenSim.ini"); | ||
166 | |||
167 | m_config = new IniConfigSource(); | ||
168 | //check for .INI file (either default or name passed in command line) | ||
169 | if (File.Exists(Application.iniFilePath)) | ||
170 | { | ||
171 | m_config.Merge(new IniConfigSource(Application.iniFilePath)); | ||
172 | m_config.Merge(configSource); | ||
173 | } | ||
174 | else | ||
175 | { | ||
176 | Application.iniFilePath = Path.Combine(Util.configDir(), Application.iniFilePath); | ||
177 | if (File.Exists(Application.iniFilePath)) | ||
178 | { | ||
179 | m_config.Merge(new IniConfigSource(Application.iniFilePath)); | ||
180 | m_config.Merge(configSource); | ||
181 | } | ||
182 | else | ||
183 | { | ||
184 | // no default config files, so set default values, and save it | ||
185 | m_config.Merge(DefaultConfig()); | ||
186 | m_config.Merge(configSource); | ||
187 | m_config.Save(Application.iniFilePath); | ||
188 | } | ||
189 | } | ||
190 | |||
191 | ReadConfigSettings(); | ||
192 | } | ||
193 | |||
194 | public static IConfigSource DefaultConfig() | ||
195 | { | ||
196 | IConfigSource DefaultConfig = new IniConfigSource(); | ||
197 | if (DefaultConfig.Configs["Startup"] == null) | ||
198 | DefaultConfig.AddConfig("Startup"); | ||
199 | IConfig config = DefaultConfig.Configs["Startup"]; | ||
200 | if (config != null) | ||
201 | { | ||
202 | config.Set("gridmode", false); | ||
203 | config.Set("physics", "basicphysics"); | ||
204 | config.Set("physical_prim", true); | ||
205 | config.Set("see_into_this_sim_from_neighbor", true); | ||
206 | config.Set("serverside_object_permissions", false); | ||
207 | config.Set("storage_plugin", "OpenSim.Data.SQLite.dll"); | ||
208 | config.Set("storage_connection_string", "URI=file:OpenSim.db,version=3"); | ||
209 | config.Set("storage_prim_inventories", true); | ||
210 | config.Set("startup_console_commands_file", String.Empty); | ||
211 | config.Set("shutdown_console_commands_file", String.Empty); | ||
212 | config.Set("script_engine", "OpenSim.Region.ScriptEngine.DotNetEngine.dll"); | ||
213 | config.Set("asset_database", "sqlite"); | ||
214 | } | ||
215 | |||
216 | if (DefaultConfig.Configs["StandAlone"] == null) | ||
217 | DefaultConfig.AddConfig("StandAlone"); | ||
218 | |||
219 | config = DefaultConfig.Configs["StandAlone"]; | ||
220 | if (config != null) | ||
221 | { | ||
222 | config.Set("accounts_authenticate", false); | ||
223 | config.Set("welcome_message", "Welcome to OpenSimulator"); | ||
224 | config.Set("inventory_plugin", "OpenSim.Data.SQLite.dll"); | ||
225 | config.Set("inventory_source", ""); | ||
226 | config.Set("userDatabase_plugin", "OpenSim.Data.SQLite.dll"); | ||
227 | config.Set("user_source", ""); | ||
228 | config.Set("asset_plugin", "OpenSim.Data.SQLite.dll"); | ||
229 | config.Set("asset_source", ""); | ||
230 | config.Set("dump_assets_to_file", false); | ||
231 | } | ||
232 | |||
233 | if (DefaultConfig.Configs["Network"] == null) | ||
234 | DefaultConfig.AddConfig("Network"); | ||
235 | config = DefaultConfig.Configs["Network"]; | ||
236 | if (config != null) | ||
237 | { | ||
238 | config.Set("default_location_x", 1000); | ||
239 | config.Set("default_location_y", 1000); | ||
240 | config.Set("http_listener_port", NetworkServersInfo.DefaultHttpListenerPort); | ||
241 | config.Set("remoting_listener_port", NetworkServersInfo.RemotingListenerPort); | ||
242 | config.Set("grid_server_url", "http://127.0.0.1:" + GridConfig.DefaultHttpPort.ToString()); | ||
243 | config.Set("grid_send_key", "null"); | ||
244 | config.Set("grid_recv_key", "null"); | ||
245 | config.Set("user_server_url", "http://127.0.0.1:" + UserConfig.DefaultHttpPort.ToString()); | ||
246 | config.Set("user_send_key", "null"); | ||
247 | config.Set("user_recv_key", "null"); | ||
248 | config.Set("asset_server_url", "http://127.0.0.1:" + AssetConfig.DefaultHttpPort.ToString()); | ||
249 | config.Set("inventory_server_url", "http://127.0.0.1:" + InventoryConfig.DefaultHttpPort.ToString()); | ||
250 | } | ||
251 | |||
252 | if (DefaultConfig.Configs["RemoteAdmin"] == null) | ||
253 | DefaultConfig.AddConfig("RemoteAdmin"); | ||
254 | config = DefaultConfig.Configs["RemoteAdmin"]; | ||
255 | if (config != null) | ||
256 | { | ||
257 | config.Set("enabled", "false"); | ||
258 | } | ||
259 | |||
260 | if (DefaultConfig.Configs["Voice"] == null) | ||
261 | DefaultConfig.AddConfig("Voice"); | ||
262 | config = DefaultConfig.Configs["Voice"]; | ||
263 | if (config != null) | ||
264 | { | ||
265 | config.Set("enabled", "false"); | ||
266 | } | ||
267 | return DefaultConfig; | ||
268 | |||
269 | } | ||
270 | |||
271 | protected virtual void ReadConfigSettings() | ||
272 | { | ||
273 | m_networkServersInfo = new NetworkServersInfo(); | ||
274 | |||
275 | IConfig startupConfig = m_config.Configs["Startup"]; | ||
276 | |||
277 | if (startupConfig != null) | ||
278 | { | ||
279 | m_sandbox = !startupConfig.GetBoolean("gridmode", false); | ||
280 | m_physicsEngine = startupConfig.GetString("physics", "basicphysics"); | ||
281 | m_meshEngineName = startupConfig.GetString("meshing", "ZeroMesher"); | ||
282 | |||
283 | m_physicalPrim = startupConfig.GetBoolean("physical_prim", true); | ||
284 | |||
285 | m_see_into_region_from_neighbor = startupConfig.GetBoolean("see_into_this_sim_from_neighbor", true); | ||
286 | |||
287 | m_storageDll = startupConfig.GetString("storage_plugin", "OpenSim.Data.SQLite.dll"); | ||
288 | if (m_storageDll == "OpenSim.DataStore.MonoSqlite.dll") | ||
289 | { | ||
290 | m_storageDll = "OpenSim.Data.SQLite.dll"; | ||
291 | Console.WriteLine("WARNING: OpenSim.DataStore.MonoSqlite.dll is deprecated. Set storage_plugin to OpenSim.Data.SQLite.dll."); | ||
292 | Thread.Sleep(3000); | ||
293 | } | ||
294 | m_storageConnectionString | ||
295 | = startupConfig.GetString("storage_connection_string", "URI=file:OpenSim.db,version=3"); | ||
296 | m_storagePersistPrimInventories | ||
297 | = startupConfig.GetBoolean("storage_prim_inventories", true); | ||
298 | |||
299 | m_scriptEngine = startupConfig.GetString("script_engine", "OpenSim.Region.ScriptEngine.DotNetEngine.dll"); | ||
300 | m_assetStorage = startupConfig.GetString("asset_database", "local"); | ||
301 | } | ||
302 | |||
303 | IConfig standaloneConfig = m_config.Configs["StandAlone"]; | ||
304 | if (standaloneConfig != null) | ||
305 | { | ||
306 | m_standaloneAuthenticate = standaloneConfig.GetBoolean("accounts_authenticate", false); | ||
307 | m_standaloneWelcomeMessage = standaloneConfig.GetString("welcome_message", "Welcome to OpenSim"); | ||
308 | m_standaloneInventoryPlugin = | ||
309 | standaloneConfig.GetString("inventory_plugin", "OpenSim.Data.SQLite.dll"); | ||
310 | m_standaloneInventorySource = | ||
311 | standaloneConfig.GetString("inventory_source",""); | ||
312 | m_standaloneUserPlugin = | ||
313 | standaloneConfig.GetString("userDatabase_plugin", "OpenSim.Data.SQLite.dll"); | ||
314 | m_standaloneUserSource = | ||
315 | standaloneConfig.GetString("user_source",""); | ||
316 | m_standaloneAssetPlugin = | ||
317 | standaloneConfig.GetString("asset_plugin", "OpenSim.Data.SQLite.dll"); | ||
318 | m_standaloneAssetSource = | ||
319 | standaloneConfig.GetString("asset_source",""); | ||
320 | |||
321 | m_dumpAssetsToFile = standaloneConfig.GetBoolean("dump_assets_to_file", false); | ||
322 | } | ||
323 | |||
324 | |||
325 | m_networkServersInfo.loadFromConfiguration(m_config); | ||
326 | |||
327 | } | ||
328 | |||
329 | private ManualResetEvent WorldHasComeToAnEnd = new ManualResetEvent(false); | ||
330 | |||
331 | /// <summary> | ||
332 | /// Performs initialisation of the scene, such as loading configuration from disk. | ||
333 | /// </summary> | ||
334 | public override void StartUp() | ||
335 | { | ||
336 | // | ||
337 | // Called from app startup (OpenSim.Application) | ||
338 | // | ||
339 | m_log.Info("===================================================================="); | ||
340 | m_log.Info("========================= STARTING OPENSIM ========================="); | ||
341 | m_log.Info("===================================================================="); | ||
342 | m_log.InfoFormat("[OPENSIM MAIN]: Running in background {0} mode", m_sandbox ? "sandbox" : "grid"); | ||
343 | |||
344 | InternalStartUp(); | ||
345 | |||
346 | // We are done with startup | ||
347 | m_log.InfoFormat("[OPENSIM MAIN]: Startup complete, serving {0} region{1}", | ||
348 | m_clientServers.Count.ToString(), m_clientServers.Count > 1 ? "s" : ""); | ||
349 | |||
350 | WorldHasComeToAnEnd.WaitOne(); | ||
351 | m_log.Info("[OPENSIM MAIN]: Shutdown complete, goodbye."); | ||
352 | |||
353 | Environment.Exit(0); | ||
354 | } | ||
355 | |||
356 | /// <summary> | ||
357 | /// Performs initialisation of the scene, such as loading configuration from disk. | ||
358 | /// </summary> | ||
359 | protected void InternalStartUp() | ||
360 | { | ||
361 | m_log.Info("[STARTUP]: Version " + m_version + "\n"); | ||
362 | |||
363 | m_stats = StatsManager.StartCollectingSimExtraStats(); | ||
364 | |||
365 | // Do baseclass startup sequence: OpenSim.Region.ClientStack.RegionApplicationBase.StartUp | ||
366 | // TerrainManager, StorageManager, HTTP Server | ||
367 | // This base will call abstract Initialize | ||
368 | base.StartUp(); | ||
369 | |||
370 | // StandAlone mode? m_sandbox is determined by !startupConfig.GetBoolean("gridmode", false) | ||
371 | if (m_sandbox) | ||
372 | { | ||
373 | LocalInventoryService inventoryService = new LocalInventoryService(); | ||
374 | inventoryService.AddPlugin(m_standaloneInventoryPlugin, m_standaloneInventorySource); | ||
375 | |||
376 | LocalUserServices userService = | ||
377 | new LocalUserServices(m_networkServersInfo, m_networkServersInfo.DefaultHomeLocX, | ||
378 | m_networkServersInfo.DefaultHomeLocY, inventoryService); | ||
379 | userService.AddPlugin(m_standaloneUserPlugin, m_standaloneUserSource); | ||
380 | |||
381 | LocalBackEndServices backendService = new LocalBackEndServices(); | ||
382 | |||
383 | CommunicationsLocal localComms = | ||
384 | new CommunicationsLocal(m_networkServersInfo, m_httpServer, m_assetCache, userService, | ||
385 | inventoryService, backendService, backendService, m_dumpAssetsToFile); | ||
386 | m_commsManager = localComms; | ||
387 | |||
388 | m_loginService = | ||
389 | new LocalLoginService(userService, m_standaloneWelcomeMessage, localComms, m_networkServersInfo, | ||
390 | m_standaloneAuthenticate); | ||
391 | m_loginService.OnLoginToRegion += backendService.AddNewSession; | ||
392 | |||
393 | // set up XMLRPC handler for client's initial login request message | ||
394 | m_httpServer.AddXmlRPCHandler("login_to_simulator", m_loginService.XmlRpcLoginMethod); | ||
395 | |||
396 | // provides the web form login | ||
397 | m_httpServer.AddHTTPHandler("login", m_loginService.ProcessHTMLLogin); | ||
398 | |||
399 | // Provides the LLSD login | ||
400 | m_httpServer.SetLLSDHandler(m_loginService.LLSDLoginMethod); | ||
401 | |||
402 | CreateAccount = localComms.doCreate; | ||
403 | } | ||
404 | else | ||
405 | { | ||
406 | // We are in grid mode | ||
407 | m_commsManager = new CommunicationsOGS1(m_networkServersInfo, m_httpServer, m_assetCache); | ||
408 | m_httpServer.AddStreamHandler(new SimStatusHandler()); | ||
409 | } | ||
410 | |||
411 | proxyUrl = ConfigSource.Configs["Network"].GetString("proxy_url", ""); | ||
412 | proxyOffset = Int32.Parse(ConfigSource.Configs["Network"].GetString("proxy_offset", "0")); | ||
413 | |||
414 | // Create a ModuleLoader instance | ||
415 | m_moduleLoader = new ModuleLoader(m_config); | ||
416 | |||
417 | ExtensionNodeList nodes = AddinManager.GetExtensionNodes("/OpenSim/Startup"); | ||
418 | foreach (TypeExtensionNode node in nodes) | ||
419 | { | ||
420 | m_log.InfoFormat("[PLUGINS]: Loading OpenSim application plugin {0}", node.Path); | ||
421 | IApplicationPlugin plugin = (IApplicationPlugin)node.CreateInstance(); | ||
422 | plugin.Initialise(this); | ||
423 | m_plugins.Add(plugin); | ||
424 | } | ||
425 | } | ||
426 | |||
427 | protected override void Initialize() | ||
428 | { | ||
429 | // | ||
430 | // Called from base.StartUp() | ||
431 | // | ||
432 | |||
433 | m_httpServerPort = m_networkServersInfo.HttpListenerPort; | ||
434 | |||
435 | IAssetServer assetServer; | ||
436 | if (m_assetStorage == "grid") | ||
437 | { | ||
438 | assetServer = new GridAssetClient(m_networkServersInfo.AssetURL); | ||
439 | } | ||
440 | else | ||
441 | { | ||
442 | SQLAssetServer sqlAssetServer = new SQLAssetServer(m_standaloneAssetPlugin, m_standaloneAssetSource); | ||
443 | sqlAssetServer.LoadDefaultAssets(); | ||
444 | assetServer = sqlAssetServer; | ||
445 | } | ||
446 | |||
447 | m_assetCache = new AssetCache(assetServer); | ||
448 | |||
449 | m_sceneManager.OnRestartSim += handleRestartRegion; | ||
450 | } | ||
451 | |||
452 | public LLUUID CreateUser(string tempfirstname, string templastname, string tempPasswd, uint regX, uint regY) | ||
453 | { | ||
454 | return m_commsManager.AddUser(tempfirstname,templastname,tempPasswd,regX,regY); | ||
455 | } | ||
456 | |||
457 | /// <summary> | ||
458 | /// Execute the region creation process. This includes setting up scene infrastructure. | ||
459 | /// </summary> | ||
460 | /// <param name="regionInfo"></param> | ||
461 | /// <param name="portadd_flag"></param> | ||
462 | /// <returns></returns> | ||
463 | public IClientNetworkServer CreateRegion(RegionInfo regionInfo, bool portadd_flag) | ||
464 | { | ||
465 | return CreateRegion(regionInfo, portadd_flag, false); | ||
466 | } | ||
467 | |||
468 | /// <summary> | ||
469 | /// Execute the region creation process. This includes setting up scene infrastructure. | ||
470 | /// </summary> | ||
471 | /// <param name="regionInfo"></param> | ||
472 | /// <param name="portadd_flag"></param> | ||
473 | /// <returns></returns> | ||
474 | public IClientNetworkServer CreateRegion(RegionInfo regionInfo) | ||
475 | { | ||
476 | return CreateRegion(regionInfo, false, true); | ||
477 | } | ||
478 | |||
479 | /// <summary> | ||
480 | /// Execute the region creation process. This includes setting up scene infrastructure. | ||
481 | /// </summary> | ||
482 | /// <param name="regionInfo"></param> | ||
483 | /// <param name="portadd_flag"></param> | ||
484 | /// <param name="do_post_init"></param> | ||
485 | /// <returns></returns> | ||
486 | public IClientNetworkServer CreateRegion(RegionInfo regionInfo, bool portadd_flag, bool do_post_init) | ||
487 | { | ||
488 | int port = regionInfo.InternalEndPoint.Port; | ||
489 | |||
490 | // set initial RegionID to originRegionID in RegionInfo. (it needs for loding prims) | ||
491 | regionInfo.originRegionID = regionInfo.RegionID; | ||
492 | |||
493 | // set initial ServerURI | ||
494 | regionInfo.ServerURI = "http://" + regionInfo.ExternalHostName | ||
495 | + ":" + regionInfo.InternalEndPoint.Port.ToString(); | ||
496 | |||
497 | regionInfo.HttpPort = m_httpServerPort; | ||
498 | |||
499 | if ((proxyUrl.Length > 0) && (portadd_flag)) | ||
500 | { | ||
501 | // set proxy url to RegionInfo | ||
502 | regionInfo.proxyUrl = proxyUrl; | ||
503 | Util.XmlRpcCommand(proxyUrl, "AddPort", port, port + proxyOffset, regionInfo.ExternalHostName); | ||
504 | } | ||
505 | |||
506 | IClientNetworkServer clientServer; | ||
507 | Scene scene = SetupScene(regionInfo, proxyOffset, out clientServer); | ||
508 | |||
509 | m_log.Info("[MODULES]: Loading Region's modules"); | ||
510 | |||
511 | List<IRegionModule> modules = m_moduleLoader.PickupModules(scene, "."); | ||
512 | // This needs to be ahead of the script engine load, so the | ||
513 | // script module can pick up events exposed by a module | ||
514 | m_moduleLoader.InitialiseSharedModules(scene); | ||
515 | |||
516 | //m_moduleLoader.PickupModules(scene, "ScriptEngines"); | ||
517 | //m_moduleLoader.LoadRegionModules(Path.Combine("ScriptEngines", m_scriptEngine), scene); | ||
518 | |||
519 | if (string.IsNullOrEmpty(m_scriptEngine)) | ||
520 | { | ||
521 | m_log.Info("[MODULES]: No script engien module specified"); | ||
522 | } | ||
523 | else | ||
524 | { | ||
525 | m_log.Info("[MODULES]: Loading scripting engine modules"); | ||
526 | foreach (string module in m_scriptEngine.Split(',')) | ||
527 | { | ||
528 | string mod = module.Trim(" \t".ToCharArray()); // Clean up name | ||
529 | m_log.Info("[MODULES]: Loading scripting engine: " + mod); | ||
530 | try | ||
531 | { | ||
532 | m_moduleLoader.LoadRegionModules(Path.Combine("ScriptEngines", mod), scene); | ||
533 | } | ||
534 | catch (Exception ex) | ||
535 | { | ||
536 | m_log.Error("[MODULES]: Failed to load script engine: " + ex.ToString()); | ||
537 | } | ||
538 | } | ||
539 | } | ||
540 | |||
541 | scene.SetModuleInterfaces(); | ||
542 | |||
543 | //moved these here as the terrain texture has to be created after the modules are initialized | ||
544 | // and has to happen before the region is registered with the grid. | ||
545 | scene.CreateTerrainTexture(true); | ||
546 | |||
547 | try | ||
548 | { | ||
549 | scene.RegisterRegionWithGrid(); | ||
550 | } | ||
551 | catch (Exception e) | ||
552 | { | ||
553 | m_log.ErrorFormat("[STARTUP]: Registration of region with grid failed, aborting startup - {0}", e); | ||
554 | |||
555 | // Carrying on now causes a lot of confusion down the line - we need to get the user's attention | ||
556 | System.Environment.Exit(1); | ||
557 | } | ||
558 | |||
559 | // We need to do this after we've initialized the scripting engines. | ||
560 | scene.StartScripts(); | ||
561 | |||
562 | scene.loadAllLandObjectsFromStorage(regionInfo.originRegionID); | ||
563 | scene.EventManager.TriggerParcelPrimCountUpdate(); | ||
564 | |||
565 | m_sceneManager.Add(scene); | ||
566 | |||
567 | m_clientServers.Add(clientServer); | ||
568 | m_regionData.Add(regionInfo); | ||
569 | clientServer.Start(); | ||
570 | |||
571 | if (do_post_init) | ||
572 | { | ||
573 | foreach (IRegionModule module in modules) | ||
574 | { | ||
575 | module.PostInitialise(); | ||
576 | } | ||
577 | } | ||
578 | |||
579 | return clientServer; | ||
580 | } | ||
581 | |||
582 | protected override StorageManager CreateStorageManager(string connectionstring) | ||
583 | { | ||
584 | return new StorageManager(m_storageDll, connectionstring, m_storagePersistPrimInventories); | ||
585 | } | ||
586 | |||
587 | protected override Scene CreateScene(RegionInfo regionInfo, StorageManager storageManager, | ||
588 | AgentCircuitManager circuitManager) | ||
589 | { | ||
590 | SceneCommunicationService sceneGridService = new SceneCommunicationService(m_commsManager); | ||
591 | return | ||
592 | new Scene(regionInfo, circuitManager, m_commsManager, sceneGridService, m_assetCache, | ||
593 | storageManager, m_httpServer, | ||
594 | m_moduleLoader, m_dumpAssetsToFile, m_physicalPrim, m_see_into_region_from_neighbor, m_config, | ||
595 | m_version); | ||
596 | |||
597 | } | ||
598 | |||
599 | public void handleRestartRegion(RegionInfo whichRegion) | ||
600 | { | ||
601 | m_log.Error("[OPENSIM MAIN]: Got restart signal from SceneManager"); | ||
602 | |||
603 | // Shutting down the client server | ||
604 | bool foundClientServer = false; | ||
605 | int clientServerElement = 0; | ||
606 | |||
607 | for (int i = 0; i < m_clientServers.Count; i++) | ||
608 | { | ||
609 | if (m_clientServers[i].HandlesRegion(new Location(whichRegion.RegionHandle))) | ||
610 | { | ||
611 | clientServerElement = i; | ||
612 | foundClientServer = true; | ||
613 | break; | ||
614 | } | ||
615 | } | ||
616 | if (foundClientServer) | ||
617 | { | ||
618 | m_clientServers[clientServerElement].Server.Close(); | ||
619 | m_clientServers.RemoveAt(clientServerElement); | ||
620 | } | ||
621 | |||
622 | //Removing the region from the sim's database of regions.. | ||
623 | int RegionHandleElement = -1; | ||
624 | for (int i = 0; i < m_regionData.Count; i++) | ||
625 | { | ||
626 | if (whichRegion.RegionHandle == m_regionData[i].RegionHandle) | ||
627 | { | ||
628 | RegionHandleElement = i; | ||
629 | } | ||
630 | } | ||
631 | if (RegionHandleElement >= 0) | ||
632 | { | ||
633 | m_regionData.RemoveAt(RegionHandleElement); | ||
634 | } | ||
635 | |||
636 | CreateRegion(whichRegion, true); | ||
637 | } | ||
638 | |||
639 | # region Setup methods | ||
640 | |||
641 | protected override PhysicsScene GetPhysicsScene() | ||
642 | { | ||
643 | return GetPhysicsScene(m_physicsEngine, m_meshEngineName, m_config); | ||
644 | } | ||
645 | |||
646 | /// <summary> | ||
647 | /// Handler to supply the current status of this sim | ||
648 | /// | ||
649 | /// Currently this is always OK if the simulator is still listening for connections on its HTTP service | ||
650 | /// </summary> | ||
651 | protected class SimStatusHandler : IStreamedRequestHandler | ||
652 | { | ||
653 | public byte[] Handle(string path, Stream request, | ||
654 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
655 | { | ||
656 | return Encoding.UTF8.GetBytes("OK"); | ||
657 | } | ||
658 | |||
659 | public string ContentType | ||
660 | { | ||
661 | get { return "text/plain"; } | ||
662 | } | ||
663 | |||
664 | public string HttpMethod | ||
665 | { | ||
666 | get { return "GET"; } | ||
667 | } | ||
668 | |||
669 | public string Path | ||
670 | { | ||
671 | get { return "/simstatus/"; } | ||
672 | } | ||
673 | } | ||
674 | |||
675 | #endregion | ||
676 | |||
677 | /// <summary> | ||
678 | /// Performs any last-minute sanity checking and shuts down the region server | ||
679 | /// </summary> | ||
680 | public override void Shutdown() | ||
681 | { | ||
682 | if (proxyUrl.Length > 0) | ||
683 | { | ||
684 | Util.XmlRpcCommand(proxyUrl, "Stop"); | ||
685 | } | ||
686 | |||
687 | m_log.Info("[SHUTDOWN]: Closing all threads"); | ||
688 | m_log.Info("[SHUTDOWN]: Killing listener thread"); | ||
689 | m_log.Info("[SHUTDOWN]: Killing clients"); | ||
690 | // TODO: implement this | ||
691 | m_log.Info("[SHUTDOWN]: Closing console and terminating"); | ||
692 | |||
693 | m_sceneManager.Close(); | ||
694 | |||
695 | WorldHasComeToAnEnd.Set(); | ||
696 | |||
697 | base.Shutdown(); | ||
698 | } | ||
699 | |||
700 | /// <summary> | ||
701 | /// Get the start time and up time of Region server | ||
702 | /// </summary> | ||
703 | /// <param name="starttime">The first out parameter describing when the Region server started</param> | ||
704 | /// <param name="uptime">The second out parameter describing how long the Region server has run</param> | ||
705 | public void GetRunTime(out string starttime, out string uptime) | ||
706 | { | ||
707 | starttime = m_startuptime.ToString(); | ||
708 | uptime = (DateTime.Now - m_startuptime).ToString(); | ||
709 | } | ||
710 | |||
711 | /// <summary> | ||
712 | /// Get the number of the avatars in the Region server | ||
713 | /// </summary> | ||
714 | /// <param name="usernum">The first out parameter describing the number of all the avatars in the Region server</param> | ||
715 | public void GetAvatarNumber(out int usernum) | ||
716 | { | ||
717 | usernum = m_sceneManager.GetCurrentSceneAvatars().Count; | ||
718 | } | ||
719 | |||
720 | /// <summary> | ||
721 | /// Get the number of regions | ||
722 | /// </summary> | ||
723 | /// <param name="regionnum">The first out parameter describing the number of regions</param> | ||
724 | public void GetRegionNumber(out int regionnum) | ||
725 | { | ||
726 | regionnum = m_sceneManager.Scenes.Count; | ||
727 | } | ||
728 | } | ||
729 | } | ||