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