2007-07-16 15:40:11 +00:00
/ *
2008-03-18 05:16:43 +00:00
* Copyright ( c ) Contributors , http : //opensimulator.org/
* See CONTRIBUTORS . TXT for a full list of copyright holders .
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions are met :
* * Redistributions of source code must retain the above copyright
* notice , this list of conditions and the following disclaimer .
* * Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution .
2009-06-01 06:37:14 +00:00
* * Neither the name of the OpenSimulator Project nor the
2008-03-18 05:16:43 +00:00
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission .
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ` ` AS IS ' ' AND ANY
* EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED . IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES
* ( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ;
* LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
* /
2007-07-16 15:40:11 +00:00
using System ;
2007-09-11 14:20:09 +00:00
using System.Collections.Generic ;
2007-07-16 15:40:11 +00:00
using System.IO ;
2012-03-10 01:27:05 +00:00
using System.Linq ;
2009-03-02 16:33:11 +00:00
using System.Net ;
2008-04-21 07:09:17 +00:00
using System.Reflection ;
2007-09-11 14:20:09 +00:00
using System.Text ;
2008-04-21 07:09:17 +00:00
using log4net ;
2007-08-04 18:15:48 +00:00
using Nini.Config ;
2009-03-02 16:33:11 +00:00
using OpenMetaverse ;
2007-10-30 09:05:31 +00:00
using OpenSim.Framework ;
2008-08-16 20:42:43 +00:00
using OpenSim.Framework.Communications ;
2008-07-12 19:29:49 +00:00
using OpenSim.Framework.Console ;
2007-07-16 15:40:11 +00:00
using OpenSim.Framework.Servers ;
2009-05-04 20:15:39 +00:00
using OpenSim.Framework.Servers.HttpServer ;
2012-07-25 22:11:50 +00:00
using OpenSim.Framework.Monitoring ;
2007-07-16 15:40:11 +00:00
using OpenSim.Region.ClientStack ;
2011-09-15 23:12:12 +00:00
using OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts ;
2009-02-06 16:55:34 +00:00
using OpenSim.Region.Framework ;
using OpenSim.Region.Framework.Interfaces ;
using OpenSim.Region.Framework.Scenes ;
2007-09-11 14:20:09 +00:00
using OpenSim.Region.Physics.Manager ;
2011-12-20 22:45:32 +00:00
using OpenSim.Server.Base ;
2011-09-16 18:54:23 +00:00
using OpenSim.Services.Base ;
2011-09-15 23:12:12 +00:00
using OpenSim.Services.Interfaces ;
using OpenSim.Services.UserAccountService ;
2008-09-29 14:41:16 +00:00
2007-07-16 15:40:11 +00:00
namespace OpenSim
{
2008-06-01 01:01:16 +00:00
/// <summary>
2009-07-10 11:03:38 +00:00
/// Common OpenSimulator simulator code
2008-06-01 01:01:16 +00:00
/// </summary>
public class OpenSimBase : RegionApplicationBase
2008-05-16 01:22:11 +00:00
{
2008-04-21 07:09:17 +00:00
private static readonly ILog m_log = LogManager . GetLogger ( MethodBase . GetCurrentMethod ( ) . DeclaringType ) ;
2008-02-05 19:44:27 +00:00
2009-02-16 12:20:31 +00:00
// These are the names of the plugin-points extended by this
// class during system startup.
2011-12-07 16:21:50 +00:00
/ /
2009-02-16 12:20:31 +00:00
2009-03-10 20:27:41 +00:00
private const string PLUGIN_ASSET_CACHE = "/OpenSim/AssetCache" ;
2009-02-18 13:15:07 +00:00
private const string PLUGIN_ASSET_SERVER_CLIENT = "/OpenSim/AssetClient" ;
2009-02-16 12:20:31 +00:00
2012-03-10 01:27:05 +00:00
// OpenSim.ini Section name for ESTATES Settings
public const string ESTATE_SECTION_NAME = "Estates" ;
2014-07-02 22:48:44 +00:00
/// <summary>
/// Allow all plugin loading to be disabled for tests/debug.
/// </summary>
/// <remarks>
/// true by default
/// </remarks>
public bool EnableInitialPluginLoad { get ; set ; }
/// <summary>
/// Control whether we attempt to load an estate data service.
/// </summary>
/// <remarks>For tests/debugging</remarks>
public bool LoadEstateDataService { get ; set ; }
2008-04-28 14:41:46 +00:00
protected string proxyUrl ;
2009-03-02 16:33:11 +00:00
protected int proxyOffset = 0 ;
2009-05-02 16:28:30 +00:00
public string userStatsURI = String . Empty ;
2013-08-06 15:21:16 +00:00
public string managedStatsURI = String . Empty ;
2009-03-02 16:33:11 +00:00
2009-03-02 18:04:00 +00:00
protected bool m_autoCreateClientStack = true ;
2008-04-28 14:41:46 +00:00
2009-08-17 19:25:14 +00:00
/// <value>
2008-07-29 14:28:08 +00:00
/// The file used to load and save prim backup xml if no filename has been specified
2009-08-17 19:25:14 +00:00
/// </value>
2008-09-06 14:58:23 +00:00
protected const string DEFAULT_PRIM_BACKUP_FILENAME = "prim-backup.xml" ;
2008-05-25 23:27:38 +00:00
2008-11-05 17:18:16 +00:00
public ConfigSettings ConfigurationSettings
{
get { return m_configSettings ; }
set { m_configSettings = value ; }
}
2009-03-10 20:27:41 +00:00
2009-02-05 18:36:53 +00:00
protected ConfigSettings m_configSettings ;
2007-08-28 14:21:17 +00:00
2008-11-05 20:14:52 +00:00
protected ConfigurationLoader m_configLoader ;
2007-08-11 11:59:51 +00:00
public ConsoleCommand CreateAccount = null ;
2009-03-10 20:27:41 +00:00
2014-07-02 22:48:44 +00:00
public List < IApplicationPlugin > m_plugins = new List < IApplicationPlugin > ( ) ;
2007-11-04 22:16:13 +00:00
2008-11-03 18:36:04 +00:00
/// <value>
2009-07-10 11:03:38 +00:00
/// The config information passed into the OpenSimulator region server.
2009-09-30 16:00:09 +00:00
/// </value>
2012-11-22 05:48:41 +00:00
public OpenSimConfigSource ConfigSource { get ; private set ; }
2008-05-16 01:22:11 +00:00
2008-05-02 18:26:19 +00:00
public List < IClientNetworkServer > ClientServers
2008-03-04 05:31:54 +00:00
{
2008-05-02 16:41:08 +00:00
get { return m_clientServers ; }
2009-03-10 20:27:41 +00:00
}
2011-11-19 16:01:51 +00:00
protected EnvConfigSource m_EnvConfigSource = new EnvConfigSource ( ) ;
public EnvConfigSource envConfigSource
{
get { return m_EnvConfigSource ; }
}
2009-03-10 20:27:41 +00:00
protected List < IClientNetworkServer > m_clientServers = new List < IClientNetworkServer > ( ) ;
2009-04-03 20:56:36 +00:00
2008-06-28 14:46:20 +00:00
public uint HttpServerPort
2008-05-14 19:13:54 +00:00
{
get { return m_httpServerPort ; }
2009-03-10 20:27:41 +00:00
}
2007-11-04 22:16:13 +00:00
2009-02-26 20:11:13 +00:00
protected IRegistryCore m_applicationRegistry = new RegistryCore ( ) ;
2009-02-26 20:01:20 +00:00
2009-02-26 20:11:13 +00:00
public IRegistryCore ApplicationRegistry
2009-02-26 20:01:20 +00:00
{
get { return m_applicationRegistry ; }
}
2007-11-04 22:16:13 +00:00
2008-10-04 20:27:55 +00:00
/// <summary>
/// Constructor.
/// </summary>
/// <param name="configSource"></param>
2008-10-03 19:42:35 +00:00
public OpenSimBase ( IConfigSource configSource ) : base ( )
2008-11-10 15:17:50 +00:00
{
2014-07-02 22:48:44 +00:00
EnableInitialPluginLoad = true ;
LoadEstateDataService = true ;
2008-11-10 15:17:50 +00:00
LoadConfigSettings ( configSource ) ;
}
protected virtual void LoadConfigSettings ( IConfigSource configSource )
2008-11-05 17:18:16 +00:00
{
2008-11-05 20:14:52 +00:00
m_configLoader = new ConfigurationLoader ( ) ;
2012-11-22 05:48:41 +00:00
ConfigSource = m_configLoader . LoadConfigSettings ( configSource , envConfigSource , out m_configSettings , out m_networkServersInfo ) ;
Config = ConfigSource . Source ;
2008-11-05 20:14:52 +00:00
ReadExtraConfigSettings ( ) ;
2008-11-05 17:18:16 +00:00
}
2008-11-05 20:14:52 +00:00
protected virtual void ReadExtraConfigSettings ( )
2007-07-16 15:40:11 +00:00
{
2012-11-22 05:48:41 +00:00
IConfig networkConfig = Config . Configs [ "Network" ] ;
2008-11-06 20:17:20 +00:00
if ( networkConfig ! = null )
{
proxyUrl = networkConfig . GetString ( "proxy_url" , "" ) ;
proxyOffset = Int32 . Parse ( networkConfig . GetString ( "proxy_offset" , "0" ) ) ;
}
2014-04-25 20:34:29 +00:00
IConfig startupConfig = Config . Configs [ "Startup" ] ;
if ( startupConfig ! = null )
{
Util . LogOverloads = startupConfig . GetBoolean ( "LogOverloads" , true ) ;
}
2008-04-28 14:41:46 +00:00
}
2008-05-16 01:22:11 +00:00
2008-11-06 20:17:20 +00:00
protected virtual void LoadPlugins ( )
2008-06-27 02:15:57 +00:00
{
2014-03-22 00:43:26 +00:00
IConfig startupConfig = Config . Configs [ "Startup" ] ;
2014-03-22 01:47:48 +00:00
string registryLocation = ( startupConfig ! = null ) ? startupConfig . GetString ( "RegistryLocation" , String . Empty ) : String . Empty ;
2014-03-22 00:43:26 +00:00
2014-03-22 01:47:48 +00:00
// The location can also be specified in the environment. If there
// is no location in the configuration, we must call the constructor
// without a location parameter to allow that to happen.
if ( registryLocation = = String . Empty )
2009-10-23 20:14:29 +00:00
{
2014-03-22 01:47:48 +00:00
using ( PluginLoader < IApplicationPlugin > loader = new PluginLoader < IApplicationPlugin > ( new ApplicationPluginInitialiser ( this ) ) )
{
loader . Load ( "/OpenSim/Startup" ) ;
m_plugins = loader . Plugins ;
}
}
else
{
using ( PluginLoader < IApplicationPlugin > loader = new PluginLoader < IApplicationPlugin > ( new ApplicationPluginInitialiser ( this ) , registryLocation ) )
{
loader . Load ( "/OpenSim/Startup" ) ;
m_plugins = loader . Plugins ;
}
2009-10-23 20:14:29 +00:00
}
2008-06-27 02:15:57 +00:00
}
2009-03-10 20:27:41 +00:00
protected override List < string > GetHelpTopics ( )
2009-02-05 21:35:59 +00:00
{
List < string > topics = base . GetHelpTopics ( ) ;
2009-02-13 20:49:23 +00:00
Scene s = SceneManager . CurrentOrFirstScene ;
if ( s ! = null & & s . GetCommanders ( ) ! = null )
topics . AddRange ( s . GetCommanders ( ) . Keys ) ;
2009-03-10 20:27:41 +00:00
2009-02-05 21:35:59 +00:00
return topics ;
2009-03-10 20:27:41 +00:00
}
2008-04-28 14:41:46 +00:00
/// <summary>
2009-02-11 18:46:51 +00:00
/// Performs startup specific to the region server, including initialization of the scene
2008-10-03 19:42:35 +00:00
/// such as loading configuration from disk.
2008-04-28 14:41:46 +00:00
/// </summary>
2008-10-03 15:11:29 +00:00
protected override void StartupSpecific ( )
2008-04-28 14:41:46 +00:00
{
2012-11-22 05:48:41 +00:00
IConfig startupConfig = Config . Configs [ "Startup" ] ;
2009-04-01 12:13:42 +00:00
if ( startupConfig ! = null )
{
string pidFile = startupConfig . GetString ( "PIDFile" , String . Empty ) ;
if ( pidFile ! = String . Empty )
CreatePIDFile ( pidFile ) ;
2009-05-02 16:28:30 +00:00
userStatsURI = startupConfig . GetString ( "Stats_URI" , String . Empty ) ;
2013-08-06 15:21:16 +00:00
managedStatsURI = startupConfig . GetString ( "ManagedStatsRemoteFetchURI" , String . Empty ) ;
2009-04-01 12:13:42 +00:00
}
2010-09-12 21:20:26 +00:00
// Load the simulation data service
2012-11-22 05:48:41 +00:00
IConfig simDataConfig = Config . Configs [ "SimulationDataStore" ] ;
2010-09-12 21:20:26 +00:00
if ( simDataConfig = = null )
2012-01-24 22:35:55 +00:00
throw new Exception ( "Configuration file is missing the [SimulationDataStore] section. Have you copied OpenSim.ini.example to OpenSim.ini to reference config-include/ files?" ) ;
2012-11-14 04:17:39 +00:00
2010-09-12 21:20:26 +00:00
string module = simDataConfig . GetString ( "LocalServiceModule" , String . Empty ) ;
if ( String . IsNullOrEmpty ( module ) )
2012-01-24 22:35:55 +00:00
throw new Exception ( "Configuration file is missing the LocalServiceModule parameter in the [SimulationDataStore] section." ) ;
2012-11-14 04:17:39 +00:00
2012-11-22 05:48:41 +00:00
m_simulationDataService = ServerUtils . LoadPlugin < ISimulationDataService > ( module , new object [ ] { Config } ) ;
2012-11-14 04:17:39 +00:00
if ( m_simulationDataService = = null )
throw new Exception (
string . Format (
"Could not load an ISimulationDataService implementation from {0}, as configured in the LocalServiceModule parameter of the [SimulationDataStore] config section." ,
module ) ) ;
2010-09-12 21:20:26 +00:00
// Load the estate data service
2014-06-01 17:06:26 +00:00
module = Util . GetConfigVarFromSections < string > ( Config , "LocalServiceModule" , new string [ ] { "EstateDataStore" , "EstateService" } , String . Empty ) ;
2010-09-12 21:20:26 +00:00
if ( String . IsNullOrEmpty ( module ) )
2014-06-01 17:06:26 +00:00
throw new Exception ( "Configuration file is missing the LocalServiceModule parameter in the [EstateDataStore] or [EstateService] section" ) ;
2012-11-14 04:17:39 +00:00
2014-07-02 22:48:44 +00:00
if ( LoadEstateDataService )
{
m_estateDataService = ServerUtils . LoadPlugin < IEstateDataService > ( module , new object [ ] { Config } ) ;
if ( m_estateDataService = = null )
throw new Exception (
string . Format (
"Could not load an IEstateDataService implementation from {0}, as configured in the LocalServiceModule parameter of the [EstateDataStore] config section." ,
module ) ) ;
}
2010-09-12 21:20:26 +00:00
2008-10-03 15:11:29 +00:00
base . StartupSpecific ( ) ;
2009-03-10 20:27:41 +00:00
2014-07-02 22:48:44 +00:00
if ( EnableInitialPluginLoad )
LoadPlugins ( ) ;
// We still want to post initalize any plugins even if loading has been disabled since a test may have
// inserted them manually.
2009-02-26 17:06:06 +00:00
foreach ( IApplicationPlugin plugin in m_plugins )
plugin . PostInitialise ( ) ;
2009-03-10 20:27:41 +00:00
2012-10-11 22:28:53 +00:00
if ( m_console ! = null )
AddPluginCommands ( m_console ) ;
2009-02-26 22:51:52 +00:00
}
2012-11-22 04:05:09 +00:00
protected virtual void AddPluginCommands ( ICommandConsole console )
2009-02-26 22:51:52 +00:00
{
2012-10-11 22:28:53 +00:00
List < string > topics = GetHelpTopics ( ) ;
foreach ( string topic in topics )
2009-02-07 12:25:39 +00:00
{
2012-10-11 22:28:53 +00:00
string capitalizedTopic = char . ToUpper ( topic [ 0 ] ) + topic . Substring ( 1 ) ;
// This is a hack to allow the user to enter the help command in upper or lowercase. This will go
// away at some point.
console . Commands . AddCommand ( capitalizedTopic , false , "help " + topic ,
"help " + capitalizedTopic ,
"Get help on plugin command '" + topic + "'" ,
HandleCommanderHelp ) ;
console . Commands . AddCommand ( capitalizedTopic , false , "help " + capitalizedTopic ,
"help " + capitalizedTopic ,
"Get help on plugin command '" + topic + "'" ,
HandleCommanderHelp ) ;
ICommander commander = null ;
Scene s = SceneManager . CurrentOrFirstScene ;
if ( s ! = null & & s . GetCommanders ( ) ! = null )
{
if ( s . GetCommanders ( ) . ContainsKey ( topic ) )
commander = s . GetCommanders ( ) [ topic ] ;
}
if ( commander = = null )
continue ;
2009-02-07 12:25:39 +00:00
2012-10-11 22:28:53 +00:00
foreach ( string command in commander . Commands . Keys )
2009-02-07 12:25:39 +00:00
{
2012-10-11 22:28:53 +00:00
console . Commands . AddCommand ( capitalizedTopic , false ,
topic + " " + command ,
topic + " " + commander . Commands [ command ] . ShortHelp ( ) ,
String . Empty , HandleCommanderCommand ) ;
2009-02-07 12:25:39 +00:00
}
}
}
private void HandleCommanderCommand ( string module , string [ ] cmd )
{
2012-07-25 21:29:40 +00:00
SceneManager . SendCommandToPluginModules ( cmd ) ;
2009-02-07 12:25:39 +00:00
}
private void HandleCommanderHelp ( string module , string [ ] cmd )
{
2009-02-13 20:49:23 +00:00
// Only safe for the interactive console, since it won't
// let us come here unless both scene and commander exist
/ /
2012-03-08 02:17:45 +00:00
ICommander moduleCommander = SceneManager . CurrentOrFirstScene . GetCommander ( cmd [ 1 ] . ToLower ( ) ) ;
2009-02-07 12:25:39 +00:00
if ( moduleCommander ! = null )
2009-05-20 13:50:33 +00:00
m_console . Output ( moduleCommander . Help ) ;
2007-08-24 16:17:57 +00:00
}
2008-01-05 16:38:37 +00:00
protected override void Initialize ( )
{
// Called from base.StartUp()
2014-11-21 01:44:30 +00:00
IConfig startupConfig = Config . Configs [ "Startup" ] ;
2014-11-21 02:16:56 +00:00
if ( startupConfig = = null | | startupConfig . GetBoolean ( "JobEngineEnabled" , true ) )
2014-11-21 01:44:30 +00:00
Watchdog . JobEngine . Start ( ) ;
2014-10-14 16:13:53 +00:00
2008-01-05 16:38:37 +00:00
m_httpServerPort = m_networkServersInfo . HttpListenerPort ;
2012-11-23 02:22:30 +00:00
SceneManager . OnRestartSim + = HandleRestartRegion ;
2012-07-25 21:29:40 +00:00
2012-08-15 21:43:32 +00:00
// Only enable the watchdogs when all regions are ready. Otherwise we get false positives when cpu is
// heavily used during initial startup.
/ /
// FIXME: It's also possible that region ready status should be flipped during an OAR load since this
// also makes heavy use of the CPU.
SceneManager . OnRegionsReadyStatusChange
+ = sm = > { MemoryWatchdog . Enabled = sm . AllRegionsReady ; Watchdog . Enabled = sm . AllRegionsReady ; } ;
2008-11-05 17:45:56 +00:00
}
2008-03-24 20:22:58 +00:00
/// <summary>
/// Execute the region creation process. This includes setting up scene infrastructure.
/// </summary>
/// <param name="regionInfo"></param>
/// <param name="portadd_flag"></param>
/// <returns></returns>
2013-02-03 12:44:45 +00:00
public List < IClientNetworkServer > CreateRegion ( RegionInfo regionInfo , bool portadd_flag , out IScene scene )
2008-05-02 03:40:38 +00:00
{
2009-02-26 20:01:20 +00:00
return CreateRegion ( regionInfo , portadd_flag , false , out scene ) ;
2008-04-21 12:42:56 +00:00
}
/// <summary>
/// Execute the region creation process. This includes setting up scene infrastructure.
/// </summary>
/// <param name="regionInfo"></param>
/// <returns></returns>
2013-02-03 12:44:45 +00:00
public List < IClientNetworkServer > CreateRegion ( RegionInfo regionInfo , out IScene scene )
2008-05-02 03:40:38 +00:00
{
2009-02-26 20:01:20 +00:00
return CreateRegion ( regionInfo , false , true , out scene ) ;
2008-04-21 12:42:56 +00:00
}
/// <summary>
/// Execute the region creation process. This includes setting up scene infrastructure.
/// </summary>
/// <param name="regionInfo"></param>
/// <param name="portadd_flag"></param>
/// <param name="do_post_init"></param>
/// <returns></returns>
2013-02-03 12:44:45 +00:00
public List < IClientNetworkServer > CreateRegion ( RegionInfo regionInfo , bool portadd_flag , bool do_post_init , out IScene mscene )
2007-10-23 12:44:12 +00:00
{
2008-03-04 05:31:54 +00:00
int port = regionInfo . InternalEndPoint . Port ;
2009-02-25 00:32:26 +00:00
// set initial RegionID to originRegionID in RegionInfo. (it needs for loding prims)
// Commented this out because otherwise regions can't register with
// the grid as there is already another region with the same UUID
// at those coordinates. This is required for the load balancer to work.
// --Mike, 2009.02.25
//regionInfo.originRegionID = regionInfo.RegionID;
2008-03-04 05:31:54 +00:00
2008-03-07 08:10:52 +00:00
// set initial ServerURI
2008-05-16 01:22:11 +00:00
regionInfo . HttpPort = m_httpServerPort ;
2010-10-03 22:03:53 +00:00
regionInfo . ServerURI = "http://" + regionInfo . ExternalHostName + ":" + regionInfo . HttpPort . ToString ( ) + "/" ;
2009-05-02 16:28:30 +00:00
regionInfo . osSecret = m_osSecret ;
2008-05-16 01:22:11 +00:00
if ( ( proxyUrl . Length > 0 ) & & ( portadd_flag ) )
2008-03-07 08:10:52 +00:00
{
// set proxy url to RegionInfo
regionInfo . proxyUrl = proxyUrl ;
2009-03-02 16:33:11 +00:00
regionInfo . ProxyOffset = proxyOffset ;
2008-03-24 01:37:00 +00:00
Util . XmlRpcCommand ( proxyUrl , "AddPort" , port , port + proxyOffset , regionInfo . ExternalHostName ) ;
2008-03-04 05:31:54 +00:00
}
2008-03-07 08:10:52 +00:00
2013-02-03 12:44:45 +00:00
List < IClientNetworkServer > clientServers ;
Scene scene = SetupScene ( regionInfo , proxyOffset , Config , out clientServers ) ;
2007-10-23 12:44:12 +00:00
2009-04-05 17:08:11 +00:00
m_log . Info ( "[MODULES]: Loading Region's modules (old style)" ) ;
2007-10-23 12:44:12 +00:00
2009-04-05 17:08:11 +00:00
// Use this in the future, the line above will be deprecated soon
2010-12-04 00:56:53 +00:00
m_log . Info ( "[REGIONMODULES]: Loading Region's modules (new style)" ) ;
2009-04-05 17:08:11 +00:00
IRegionModulesController controller ;
if ( ApplicationRegistry . TryGet ( out controller ) )
{
controller . AddRegionToModules ( scene ) ;
}
2010-12-04 00:56:53 +00:00
else m_log . Error ( "[REGIONMODULES]: The new RegionModulesController is missing..." ) ;
2009-04-05 17:08:11 +00:00
2007-10-23 12:44:12 +00:00
scene . SetModuleInterfaces ( ) ;
2009-03-10 20:27:41 +00:00
2011-09-15 23:12:12 +00:00
while ( regionInfo . EstateSettings . EstateOwner = = UUID . Zero & & MainConsole . Instance ! = null )
2011-09-15 23:24:23 +00:00
SetUpEstateOwner ( scene ) ;
2011-09-15 23:12:12 +00:00
2009-09-30 16:00:09 +00:00
// Prims have to be loaded after module configuration since some modules may be invoked during the load
2009-07-29 16:32:56 +00:00
scene . LoadPrimsFromStorage ( regionInfo . originRegionID ) ;
2009-09-30 16:00:09 +00:00
// TODO : Try setting resource for region xstats here on scene
2012-05-03 00:45:49 +00:00
MainServer . Instance . AddStreamHandler ( new RegionStatsHandler ( regionInfo ) ) ;
2009-05-02 16:28:30 +00:00
2012-01-31 03:09:44 +00:00
scene . loadAllLandObjectsFromStorage ( regionInfo . originRegionID ) ;
scene . EventManager . TriggerParcelPrimCountUpdate ( ) ;
2008-09-06 08:10:40 +00:00
try
{
2008-05-12 16:57:56 +00:00
scene . RegisterRegionWithGrid ( ) ;
2008-09-06 08:10:40 +00:00
}
catch ( Exception e )
{
2010-08-30 20:23:19 +00:00
m_log . ErrorFormat (
"[STARTUP]: Registration of region with grid failed, aborting startup due to {0} {1}" ,
e . Message , e . StackTrace ) ;
2008-05-16 01:22:11 +00:00
2008-09-02 12:07:23 +00:00
// Carrying on now causes a lot of confusion down the
// line - we need to get the user's attention
2009-02-12 09:53:12 +00:00
Environment . Exit ( 1 ) ;
2008-09-06 08:10:40 +00:00
}
2008-05-16 01:22:11 +00:00
2008-09-02 12:07:23 +00:00
// We need to do this after we've initialized the
// scripting engines.
2008-06-28 16:08:12 +00:00
scene . CreateScriptInstances ( ) ;
2008-03-22 23:10:22 +00:00
2012-07-25 21:29:40 +00:00
SceneManager . Add ( scene ) ;
2007-10-23 12:44:12 +00:00
2009-03-02 18:04:00 +00:00
if ( m_autoCreateClientStack )
2009-03-02 16:33:11 +00:00
{
2013-02-03 12:44:45 +00:00
foreach ( IClientNetworkServer clientserver in clientServers )
{
m_clientServers . Add ( clientserver ) ;
clientserver . Start ( ) ;
}
2009-03-02 16:33:11 +00:00
}
2007-10-23 12:44:12 +00:00
2009-04-05 17:08:11 +00:00
scene . EventManager . OnShutdown + = delegate ( ) { ShutdownRegion ( scene ) ; } ;
2008-04-21 12:42:56 +00:00
2009-02-26 20:01:20 +00:00
mscene = scene ;
2009-05-26 16:45:30 +00:00
2013-02-03 12:44:45 +00:00
return clientServers ;
2007-10-23 12:44:12 +00:00
}
2011-09-15 23:36:43 +00:00
/// <summary>
/// Try to set up the estate owner for the given scene.
/// </summary>
/// <remarks>
/// The involves asking the user for information about the user on the console. If the user does not already
/// exist then it is created.
/// </remarks>
/// <param name="scene"></param>
2011-09-15 23:24:23 +00:00
private void SetUpEstateOwner ( Scene scene )
{
RegionInfo regionInfo = scene . RegionInfo ;
2012-03-10 01:27:05 +00:00
string estateOwnerFirstName = null ;
string estateOwnerLastName = null ;
string estateOwnerEMail = null ;
string estateOwnerPassword = null ;
string rawEstateOwnerUuid = null ;
2012-11-22 05:48:41 +00:00
if ( Config . Configs [ ESTATE_SECTION_NAME ] ! = null )
2012-03-10 01:27:05 +00:00
{
string defaultEstateOwnerName
2012-11-22 05:48:41 +00:00
= Config . Configs [ ESTATE_SECTION_NAME ] . GetString ( "DefaultEstateOwnerName" , "" ) . Trim ( ) ;
2012-03-10 01:27:05 +00:00
string [ ] ownerNames = defaultEstateOwnerName . Split ( ' ' ) ;
if ( ownerNames . Length > = 2 )
{
estateOwnerFirstName = ownerNames [ 0 ] ;
estateOwnerLastName = ownerNames [ 1 ] ;
}
// Info to be used only on Standalone Mode
2012-11-22 05:48:41 +00:00
rawEstateOwnerUuid = Config . Configs [ ESTATE_SECTION_NAME ] . GetString ( "DefaultEstateOwnerUUID" , null ) ;
estateOwnerEMail = Config . Configs [ ESTATE_SECTION_NAME ] . GetString ( "DefaultEstateOwnerEMail" , null ) ;
estateOwnerPassword = Config . Configs [ ESTATE_SECTION_NAME ] . GetString ( "DefaultEstateOwnerPassword" , null ) ;
2012-03-10 01:27:05 +00:00
}
2011-09-15 23:24:23 +00:00
MainConsole . Instance . OutputFormat ( "Estate {0} has no owner set." , regionInfo . EstateSettings . EstateName ) ;
List < char > excluded = new List < char > ( new char [ 1 ] { ' ' } ) ;
2012-03-10 01:27:05 +00:00
if ( estateOwnerFirstName = = null | | estateOwnerLastName = = null )
{
estateOwnerFirstName = MainConsole . Instance . CmdPrompt ( "Estate owner first name" , "Test" , excluded ) ;
estateOwnerLastName = MainConsole . Instance . CmdPrompt ( "Estate owner last name" , "User" , excluded ) ;
}
UserAccount account
= scene . UserAccountService . GetUserAccount ( regionInfo . ScopeID , estateOwnerFirstName , estateOwnerLastName ) ;
2011-09-15 23:24:23 +00:00
if ( account = = null )
{
// XXX: The LocalUserAccountServicesConnector is currently registering its inner service rather than
// itself!
// if (scene.UserAccountService is LocalUserAccountServicesConnector)
// {
// IUserAccountService innerUas
// = ((LocalUserAccountServicesConnector)scene.UserAccountService).UserAccountService;
/ /
// m_log.DebugFormat("B {0}", innerUas.GetType());
/ /
// if (innerUas is UserAccountService)
// {
if ( scene . UserAccountService is UserAccountService )
{
2012-03-10 01:27:05 +00:00
if ( estateOwnerPassword = = null )
estateOwnerPassword = MainConsole . Instance . PasswdPrompt ( "Password" ) ;
if ( estateOwnerEMail = = null )
estateOwnerEMail = MainConsole . Instance . CmdPrompt ( "Email" ) ;
2011-09-15 23:24:23 +00:00
2012-03-10 01:27:05 +00:00
if ( rawEstateOwnerUuid = = null )
rawEstateOwnerUuid = MainConsole . Instance . CmdPrompt ( "User ID" , UUID . Random ( ) . ToString ( ) ) ;
2011-10-04 22:48:35 +00:00
2012-03-10 01:27:05 +00:00
UUID estateOwnerUuid = UUID . Zero ;
if ( ! UUID . TryParse ( rawEstateOwnerUuid , out estateOwnerUuid ) )
2011-10-04 22:48:35 +00:00
{
2012-03-10 01:27:05 +00:00
m_log . ErrorFormat ( "[OPENSIM]: ID {0} is not a valid UUID" , rawEstateOwnerUuid ) ;
2011-10-04 22:48:35 +00:00
return ;
}
2012-03-10 01:27:05 +00:00
// If we've been given a zero uuid then this signals that we should use a random user id
if ( estateOwnerUuid = = UUID . Zero )
estateOwnerUuid = UUID . Random ( ) ;
2011-09-15 23:36:43 +00:00
account
= ( ( UserAccountService ) scene . UserAccountService ) . CreateUser (
2012-03-10 01:27:05 +00:00
regionInfo . ScopeID ,
estateOwnerUuid ,
estateOwnerFirstName ,
estateOwnerLastName ,
estateOwnerPassword ,
estateOwnerEMail ) ;
2011-09-15 23:24:23 +00:00
}
}
if ( account = = null )
{
m_log . ErrorFormat (
2012-10-26 01:36:58 +00:00
"[OPENSIM]: Unable to store account. If this simulator is connected to a grid, you must create the estate owner account first at the grid level." ) ;
2011-09-15 23:24:23 +00:00
}
else
{
regionInfo . EstateSettings . EstateOwner = account . PrincipalID ;
2014-06-01 17:06:26 +00:00
m_estateDataService . StoreEstateSettings ( regionInfo . EstateSettings ) ;
2011-09-15 23:24:23 +00:00
}
}
2009-04-05 17:08:11 +00:00
private void ShutdownRegion ( Scene scene )
{
m_log . DebugFormat ( "[SHUTDOWN]: Shutting down region {0}" , scene . RegionInfo . RegionName ) ;
IRegionModulesController controller ;
if ( ApplicationRegistry . TryGet < IRegionModulesController > ( out controller ) )
{
controller . RemoveRegionFromModules ( scene ) ;
}
}
2008-09-18 15:44:05 +00:00
public void RemoveRegion ( Scene scene , bool cleanup )
{
// only need to check this if we are not at the
// root level
2012-07-25 21:29:40 +00:00
if ( ( SceneManager . CurrentScene ! = null ) & &
( SceneManager . CurrentScene . RegionInfo . RegionID = = scene . RegionInfo . RegionID ) )
2008-09-18 15:44:05 +00:00
{
2012-07-25 21:29:40 +00:00
SceneManager . TrySetCurrentScene ( ".." ) ;
2008-09-18 15:44:05 +00:00
}
2009-03-10 20:27:41 +00:00
2008-09-18 15:44:05 +00:00
scene . DeleteAllSceneObjects ( ) ;
2012-07-25 21:29:40 +00:00
SceneManager . CloseScene ( scene ) ;
2009-10-09 16:28:16 +00:00
ShutdownClientServer ( scene . RegionInfo ) ;
2009-03-10 20:27:41 +00:00
if ( ! cleanup )
2008-09-18 15:44:05 +00:00
return ;
if ( ! String . IsNullOrEmpty ( scene . RegionInfo . RegionFile ) )
{
2009-06-26 00:00:20 +00:00
if ( scene . RegionInfo . RegionFile . ToLower ( ) . EndsWith ( ".xml" ) )
{
File . Delete ( scene . RegionInfo . RegionFile ) ;
m_log . InfoFormat ( "[OPENSIM]: deleting region file \"{0}\"" , scene . RegionInfo . RegionFile ) ;
}
if ( scene . RegionInfo . RegionFile . ToLower ( ) . EndsWith ( ".ini" ) )
{
try
{
IniConfigSource source = new IniConfigSource ( scene . RegionInfo . RegionFile ) ;
if ( source . Configs [ scene . RegionInfo . RegionName ] ! = null )
{
source . Configs . Remove ( scene . RegionInfo . RegionName ) ;
if ( source . Configs . Count = = 0 )
{
File . Delete ( scene . RegionInfo . RegionFile ) ;
}
else
{
source . Save ( scene . RegionInfo . RegionFile ) ;
}
}
}
catch ( Exception )
{
}
}
2008-09-18 15:44:05 +00:00
}
}
public void RemoveRegion ( string name , bool cleanUp )
{
Scene target ;
2012-07-25 21:29:40 +00:00
if ( SceneManager . TryGetScene ( name , out target ) )
2008-09-18 15:44:05 +00:00
RemoveRegion ( target , cleanUp ) ;
2008-11-05 18:00:45 +00:00
}
2009-07-08 20:53:22 +00:00
/// <summary>
/// Remove a region from the simulator without deleting it permanently.
/// </summary>
/// <param name="scene"></param>
2009-09-30 16:00:09 +00:00
/// <returns></returns>
2009-07-08 20:53:22 +00:00
public void CloseRegion ( Scene scene )
{
// only need to check this if we are not at the
// root level
2012-07-25 21:29:40 +00:00
if ( ( SceneManager . CurrentScene ! = null ) & &
( SceneManager . CurrentScene . RegionInfo . RegionID = = scene . RegionInfo . RegionID ) )
2009-07-08 20:53:22 +00:00
{
2012-07-25 21:29:40 +00:00
SceneManager . TrySetCurrentScene ( ".." ) ;
2009-07-08 20:53:22 +00:00
}
2012-07-25 21:29:40 +00:00
SceneManager . CloseScene ( scene ) ;
2009-10-09 16:28:16 +00:00
ShutdownClientServer ( scene . RegionInfo ) ;
2009-07-08 20:53:22 +00:00
}
/// <summary>
/// Remove a region from the simulator without deleting it permanently.
/// </summary>
/// <param name="name"></param>
2009-09-30 16:00:09 +00:00
/// <returns></returns>
2009-07-08 20:53:22 +00:00
public void CloseRegion ( string name )
{
Scene target ;
2012-07-25 21:29:40 +00:00
if ( SceneManager . TryGetScene ( name , out target ) )
2009-07-08 20:53:22 +00:00
CloseRegion ( target ) ;
}
2009-03-02 16:33:11 +00:00
/// <summary>
/// Create a scene and its initial base structures.
/// </summary>
/// <param name="regionInfo"></param>
/// <param name="clientServer"> </param>
2009-09-30 16:00:09 +00:00
/// <returns></returns>
2013-02-03 12:44:45 +00:00
protected Scene SetupScene ( RegionInfo regionInfo , out List < IClientNetworkServer > clientServer )
2009-03-02 16:33:11 +00:00
{
return SetupScene ( regionInfo , 0 , null , out clientServer ) ;
}
/// <summary>
/// Create a scene and its initial base structures.
/// </summary>
/// <param name="regionInfo"></param>
/// <param name="proxyOffset"></param>
/// <param name="configSource"></param>
/// <param name="clientServer"> </param>
/// <returns></returns>
protected Scene SetupScene (
2013-02-03 12:44:45 +00:00
RegionInfo regionInfo , int proxyOffset , IConfigSource configSource , out List < IClientNetworkServer > clientServer )
2009-03-02 16:33:11 +00:00
{
2013-02-03 12:44:45 +00:00
List < IClientNetworkServer > clientNetworkServers = null ;
2009-03-02 16:33:11 +00:00
AgentCircuitManager circuitManager = new AgentCircuitManager ( ) ;
IPAddress listenIP = regionInfo . InternalEndPoint . Address ;
//if (!IPAddress.TryParse(regionInfo.InternalEndPoint, out listenIP))
// listenIP = IPAddress.Parse("0.0.0.0");
2009-03-10 20:27:41 +00:00
uint port = ( uint ) regionInfo . InternalEndPoint . Port ;
2013-02-27 22:31:47 +00:00
2009-03-02 18:04:00 +00:00
if ( m_autoCreateClientStack )
2009-03-02 16:33:11 +00:00
{
2013-02-03 12:44:45 +00:00
clientNetworkServers = m_clientStackManager . CreateServers (
2009-03-02 16:33:11 +00:00
listenIP , ref port , proxyOffset , regionInfo . m_allow_alternate_ports , configSource ,
2009-05-15 05:00:25 +00:00
circuitManager ) ;
2009-03-02 16:33:11 +00:00
}
else
{
clientServer = null ;
}
2009-03-10 20:27:41 +00:00
regionInfo . InternalEndPoint . Port = ( int ) port ;
2009-03-02 16:33:11 +00:00
2010-09-12 21:20:26 +00:00
Scene scene = CreateScene ( regionInfo , m_simulationDataService , m_estateDataService , circuitManager ) ;
2009-03-02 16:33:11 +00:00
2009-03-02 18:04:00 +00:00
if ( m_autoCreateClientStack )
2009-03-02 16:33:11 +00:00
{
2013-02-03 12:44:45 +00:00
foreach ( IClientNetworkServer clientnetserver in clientNetworkServers )
{
clientnetserver . AddScene ( scene ) ;
}
2009-03-02 16:33:11 +00:00
}
2013-02-03 12:44:45 +00:00
clientServer = clientNetworkServers ;
2009-03-02 16:33:11 +00:00
scene . LoadWorldMap ( ) ;
2012-08-01 21:36:24 +00:00
scene . PhysicsScene . RequestAssetMethod = scene . PhysicsRequestAsset ;
2009-03-02 16:33:11 +00:00
scene . PhysicsScene . SetTerrain ( scene . Heightmap . GetFloatsSerialised ( ) ) ;
2009-03-10 20:27:41 +00:00
scene . PhysicsScene . SetWaterLevel ( ( float ) regionInfo . RegionSettings . WaterHeight ) ;
2009-03-02 16:33:11 +00:00
return scene ;
}
2008-06-20 01:35:54 +00:00
protected override ClientStackManager CreateClientStackManager ( )
{
2008-11-05 17:18:16 +00:00
return new ClientStackManager ( m_configSettings . ClientstackDll ) ;
2008-06-20 01:35:54 +00:00
}
2010-09-12 21:20:26 +00:00
protected override Scene CreateScene ( RegionInfo regionInfo , ISimulationDataService simDataService ,
IEstateDataService estateDataService , AgentCircuitManager circuitManager )
2007-07-16 23:25:35 +00:00
{
2014-07-29 00:21:15 +00:00
Vector3 regionExtent = new Vector3 ( regionInfo . RegionSizeX , regionInfo . RegionSizeY , regionInfo . RegionSizeZ ) ;
PhysicsScene physicsScene = GetPhysicsScene ( regionInfo . RegionName , regionExtent ) ;
2010-01-11 15:45:47 +00:00
SceneCommunicationService sceneGridService = new SceneCommunicationService ( ) ;
2009-03-10 20:27:41 +00:00
2009-01-06 15:09:52 +00:00
return new Scene (
2014-07-29 00:21:15 +00:00
regionInfo , circuitManager , physicsScene , sceneGridService ,
2013-02-06 02:21:17 +00:00
simDataService , estateDataService ,
2012-11-22 05:48:41 +00:00
Config , m_version ) ;
2007-07-16 23:25:35 +00:00
}
2009-10-09 16:28:16 +00:00
protected void ShutdownClientServer ( RegionInfo whichRegion )
2007-11-25 04:52:14 +00:00
{
2009-10-09 16:28:16 +00:00
// Close and remove the clientserver for a region
2008-05-02 18:26:19 +00:00
bool foundClientServer = false ;
int clientServerElement = 0 ;
2009-05-20 13:37:25 +00:00
Location location = new Location ( whichRegion . RegionHandle ) ;
2007-12-27 21:41:48 +00:00
2008-05-02 16:41:08 +00:00
for ( int i = 0 ; i < m_clientServers . Count ; i + + )
2007-11-25 04:52:14 +00:00
{
2009-05-20 13:37:25 +00:00
if ( m_clientServers [ i ] . HandlesRegion ( location ) )
2007-11-25 04:52:14 +00:00
{
2008-05-02 18:26:19 +00:00
clientServerElement = i ;
foundClientServer = true ;
2007-11-25 04:52:14 +00:00
break ;
}
}
2009-03-10 20:27:41 +00:00
2008-05-02 18:26:19 +00:00
if ( foundClientServer )
2007-11-25 04:52:14 +00:00
{
2013-04-16 20:58:24 +00:00
m_clientServers [ clientServerElement ] . Stop ( ) ;
2008-05-02 18:26:19 +00:00
m_clientServers . RemoveAt ( clientServerElement ) ;
2007-11-25 04:52:14 +00:00
}
2009-10-09 16:28:16 +00:00
}
2012-11-23 02:22:30 +00:00
protected virtual void HandleRestartRegion ( RegionInfo whichRegion )
2009-10-09 16:28:16 +00:00
{
2012-11-23 02:22:30 +00:00
m_log . InfoFormat (
"[OPENSIM]: Got restart signal from SceneManager for region {0} ({1},{2})" ,
2013-12-14 15:53:01 +00:00
whichRegion . RegionName , whichRegion . RegionLocX , whichRegion . RegionLocY ) ;
2009-10-09 16:28:16 +00:00
ShutdownClientServer ( whichRegion ) ;
2009-02-26 20:01:20 +00:00
IScene scene ;
CreateRegion ( whichRegion , true , out scene ) ;
2013-05-03 17:48:50 +00:00
scene . Start ( ) ;
2007-07-16 21:53:39 +00:00
}
# region Setup methods
2013-11-05 06:10:54 +00:00
protected override PhysicsScene GetPhysicsScene ( string osSceneIdentifier , Vector3 regionExtent )
2007-07-16 18:37:31 +00:00
{
2008-12-15 18:39:54 +00:00
return GetPhysicsScene (
2013-11-05 06:10:54 +00:00
m_configSettings . PhysicsEngine , m_configSettings . MeshEngineName , Config , osSceneIdentifier , regionExtent ) ;
2007-07-16 18:37:31 +00:00
}
2008-05-12 16:16:50 +00:00
/// <summary>
/// Handler to supply the current status of this sim
/// </summary>
2013-07-05 23:12:48 +00:00
/// <remarks>
2008-12-15 18:39:54 +00:00
/// Currently this is always OK if the simulator is still listening for connections on its HTTP service
2013-07-05 23:12:48 +00:00
/// </remarks>
public class SimStatusHandler : BaseStreamHandler
2007-07-16 15:40:11 +00:00
{
2013-07-05 23:12:48 +00:00
public SimStatusHandler ( ) : base ( "GET" , "/simstatus" , "SimStatus" , "Simulator Status" ) { }
2013-07-08 21:03:07 +00:00
protected override byte [ ] ProcessRequest ( string path , Stream request ,
2011-12-05 20:44:20 +00:00
IOSHttpRequest httpRequest , IOSHttpResponse httpResponse )
2007-07-16 15:40:11 +00:00
{
2009-10-03 01:31:08 +00:00
return Util . UTF8 . GetBytes ( "OK" ) ;
2007-07-16 15:40:11 +00:00
}
2013-07-05 23:12:48 +00:00
public override string ContentType
2007-07-16 15:40:11 +00:00
{
get { return "text/plain" ; }
}
}
2009-04-17 21:48:48 +00:00
/// <summary>
2009-05-02 16:28:30 +00:00
/// Handler to supply the current extended status of this sim
/// Sends the statistical data in a json serialization
2009-04-17 21:48:48 +00:00
/// </summary>
2013-07-05 23:12:48 +00:00
public class XSimStatusHandler : BaseStreamHandler
2009-04-17 21:48:48 +00:00
{
2009-04-22 00:48:56 +00:00
OpenSimBase m_opensim ;
2013-07-05 23:12:48 +00:00
public XSimStatusHandler ( OpenSimBase sim )
: base ( "GET" , "/" + Util . SHA1Hash ( sim . osSecret ) , "XSimStatus" , "Simulator XStatus" )
2009-04-22 00:48:56 +00:00
{
m_opensim = sim ;
}
2013-07-08 21:03:07 +00:00
protected override byte [ ] ProcessRequest ( string path , Stream request ,
2011-12-05 20:44:20 +00:00
IOSHttpRequest httpRequest , IOSHttpResponse httpResponse )
2009-04-17 21:48:48 +00:00
{
2009-10-03 01:31:08 +00:00
return Util . UTF8 . GetBytes ( m_opensim . StatReport ( httpRequest ) ) ;
2009-04-17 21:48:48 +00:00
}
2013-07-05 23:12:48 +00:00
public override string ContentType
2009-04-17 21:48:48 +00:00
{
get { return "text/plain" ; }
}
}
2009-05-02 16:28:30 +00:00
/// <summary>
2009-05-13 01:27:23 +00:00
/// Handler to supply the current extended status of this sim to a user configured URI
2009-05-02 16:28:30 +00:00
/// Sends the statistical data in a json serialization
2009-05-13 01:27:23 +00:00
/// If the request contains a key, "callback" the response will be wrappend in the
/// associated value for jsonp used with ajax/javascript
2009-05-02 16:28:30 +00:00
/// </summary>
2013-07-08 21:03:07 +00:00
protected class UXSimStatusHandler : BaseStreamHandler
2009-05-02 16:28:30 +00:00
{
OpenSimBase m_opensim ;
public UXSimStatusHandler ( OpenSimBase sim )
2013-07-05 23:12:48 +00:00
: base ( "GET" , "/" + sim . userStatsURI , "UXSimStatus" , "Simulator UXStatus" )
2009-05-02 16:28:30 +00:00
{
2013-07-05 23:12:48 +00:00
m_opensim = sim ;
2009-05-02 16:28:30 +00:00
}
2013-07-08 21:03:07 +00:00
protected override byte [ ] ProcessRequest ( string path , Stream request ,
2011-12-05 20:44:20 +00:00
IOSHttpRequest httpRequest , IOSHttpResponse httpResponse )
2009-05-02 16:28:30 +00:00
{
2009-10-03 01:31:08 +00:00
return Util . UTF8 . GetBytes ( m_opensim . StatReport ( httpRequest ) ) ;
2009-05-02 16:28:30 +00:00
}
2013-07-05 23:12:48 +00:00
public override string ContentType
2009-05-02 16:28:30 +00:00
{
get { return "text/plain" ; }
}
}
2009-04-17 21:48:48 +00:00
2007-07-16 15:40:11 +00:00
# endregion
2008-08-18 00:39:10 +00:00
2007-07-16 15:40:11 +00:00
/// <summary>
/// Performs any last-minute sanity checking and shuts down the region server
/// </summary>
2013-06-17 21:39:00 +00:00
protected override void ShutdownSpecific ( )
2007-07-16 15:40:11 +00:00
{
2008-05-16 01:22:11 +00:00
if ( proxyUrl . Length > 0 )
2008-03-24 03:03:21 +00:00
{
2008-05-16 01:22:11 +00:00
Util . XmlRpcCommand ( proxyUrl , "Stop" ) ;
2008-03-24 03:03:21 +00:00
}
2008-03-18 15:30:38 +00:00
2008-02-05 19:44:27 +00:00
m_log . Info ( "[SHUTDOWN]: Closing all threads" ) ;
m_log . Info ( "[SHUTDOWN]: Killing listener thread" ) ;
m_log . Info ( "[SHUTDOWN]: Killing clients" ) ;
m_log . Info ( "[SHUTDOWN]: Closing console and terminating" ) ;
2007-09-17 06:57:17 +00:00
2008-09-29 15:40:16 +00:00
try
2009-03-10 20:27:41 +00:00
{
2012-07-25 21:29:40 +00:00
SceneManager . Close ( ) ;
2014-07-02 22:48:44 +00:00
foreach ( IApplicationPlugin plugin in m_plugins )
plugin . Dispose ( ) ;
2008-09-29 15:40:16 +00:00
}
catch ( Exception e )
{
2012-11-23 02:22:30 +00:00
m_log . Error ( "[SHUTDOWN]: Ignoring failure during shutdown - " , e ) ;
2008-09-29 15:40:16 +00:00
}
2013-06-17 21:39:00 +00:00
base . ShutdownSpecific ( ) ;
2007-09-04 16:39:44 +00:00
}
2007-10-30 09:05:31 +00:00
2008-03-04 05:31:54 +00:00
/// <summary>
/// Get the start time and up time of Region server
/// </summary>
/// <param name="starttime">The first out parameter describing when the Region server started</param>
/// <param name="uptime">The second out parameter describing how long the Region server has run</param>
public void GetRunTime ( out string starttime , out string uptime )
2008-03-18 15:30:38 +00:00
{
starttime = m_startuptime . ToString ( ) ;
uptime = ( DateTime . Now - m_startuptime ) . ToString ( ) ;
}
2008-03-04 05:31:54 +00:00
/// <summary>
/// Get the number of the avatars in the Region server
/// </summary>
/// <param name="usernum">The first out parameter describing the number of all the avatars in the Region server</param>
public void GetAvatarNumber ( out int usernum )
2008-03-18 15:30:38 +00:00
{
2012-07-25 21:29:40 +00:00
usernum = SceneManager . GetCurrentSceneAvatars ( ) . Count ;
2008-03-18 15:30:38 +00:00
}
2008-03-04 05:31:54 +00:00
/// <summary>
2008-05-02 03:40:38 +00:00
/// Get the number of regions
2008-03-04 05:31:54 +00:00
/// </summary>
2008-05-02 03:40:38 +00:00
/// <param name="regionnum">The first out parameter describing the number of regions</param>
2008-03-04 05:31:54 +00:00
public void GetRegionNumber ( out int regionnum )
2008-03-18 15:30:38 +00:00
{
2012-07-25 21:29:40 +00:00
regionnum = SceneManager . Scenes . Count ;
2008-03-18 15:30:38 +00:00
}
2010-08-13 15:08:43 +00:00
2011-03-21 22:57:20 +00:00
/// <summary>
/// Create an estate with an initial region.
/// </summary>
2011-03-21 23:16:57 +00:00
/// <remarks>
/// This method doesn't allow an estate to be created with the same name as existing estates.
/// </remarks>
2011-03-21 22:57:20 +00:00
/// <param name="regInfo"></param>
2012-03-10 01:27:05 +00:00
/// <param name="estatesByName">A list of estate names that already exist.</param>
/// <param name="estateName">Estate name to create if already known</param>
2011-03-21 23:16:57 +00:00
/// <returns>true if the estate was created, false otherwise</returns>
2012-03-10 01:27:05 +00:00
public bool CreateEstate ( RegionInfo regInfo , Dictionary < string , EstateSettings > estatesByName , string estateName )
2011-03-21 22:57:20 +00:00
{
// Create a new estate
regInfo . EstateSettings = EstateDataService . LoadEstateSettings ( regInfo . RegionID , true ) ;
2012-03-10 01:27:05 +00:00
string newName ;
2013-11-15 21:45:08 +00:00
if ( ! string . IsNullOrEmpty ( estateName ) )
2012-03-10 01:27:05 +00:00
newName = estateName ;
else
newName = MainConsole . Instance . CmdPrompt ( "New estate name" , regInfo . EstateSettings . EstateName ) ;
if ( estatesByName . ContainsKey ( newName ) )
2011-03-21 23:16:57 +00:00
{
MainConsole . Instance . OutputFormat ( "An estate named {0} already exists. Please try again." , newName ) ;
return false ;
}
regInfo . EstateSettings . EstateName = newName ;
2011-03-21 22:57:20 +00:00
// FIXME: Later on, the scene constructor will reload the estate settings no matter what.
// Therefore, we need to do an initial save here otherwise the new estate name will be reset
// back to the default. The reloading of estate settings by scene could be eliminated if it
// knows that the passed in settings in RegionInfo are already valid. Also, it might be
// possible to eliminate some additional later saves made by callers of this method.
2014-06-01 17:06:26 +00:00
EstateDataService . StoreEstateSettings ( regInfo . EstateSettings ) ;
2011-03-21 23:16:57 +00:00
return true ;
2011-03-21 22:57:20 +00:00
}
2010-08-13 15:08:43 +00:00
/// <summary>
/// Load the estate information for the provided RegionInfo object.
/// </summary>
2011-02-12 01:08:56 +00:00
/// <param name="regInfo"></param>
2012-05-10 16:08:40 +00:00
public bool PopulateRegionEstateInfo ( RegionInfo regInfo )
2010-08-13 15:08:43 +00:00
{
2011-03-21 22:47:02 +00:00
if ( EstateDataService ! = null )
regInfo . EstateSettings = EstateDataService . LoadEstateSettings ( regInfo . RegionID , false ) ;
2010-09-12 21:20:26 +00:00
2012-03-10 01:27:05 +00:00
if ( regInfo . EstateSettings . EstateID ! = 0 )
2012-05-10 16:08:40 +00:00
return false ; // estate info in the database did not change
2012-03-10 01:27:05 +00:00
m_log . WarnFormat ( "[ESTATE] Region {0} is not part of an estate." , regInfo . RegionName ) ;
List < EstateSettings > estates = EstateDataService . LoadEstateSettingsAll ( ) ;
Dictionary < string , EstateSettings > estatesByName = new Dictionary < string , EstateSettings > ( ) ;
foreach ( EstateSettings estate in estates )
estatesByName [ estate . EstateName ] = estate ;
string defaultEstateName = null ;
2012-11-22 05:48:41 +00:00
if ( Config . Configs [ ESTATE_SECTION_NAME ] ! = null )
2010-08-13 15:08:43 +00:00
{
2012-11-22 05:48:41 +00:00
defaultEstateName = Config . Configs [ ESTATE_SECTION_NAME ] . GetString ( "DefaultEstateName" , null ) ;
2012-03-10 01:27:05 +00:00
if ( defaultEstateName ! = null )
2010-08-13 15:08:43 +00:00
{
2012-03-10 01:27:05 +00:00
EstateSettings defaultEstate ;
bool defaultEstateJoined = false ;
if ( estatesByName . ContainsKey ( defaultEstateName ) )
{
defaultEstate = estatesByName [ defaultEstateName ] ;
if ( EstateDataService . LinkRegion ( regInfo . RegionID , ( int ) defaultEstate . EstateID ) )
defaultEstateJoined = true ;
}
else
{
if ( CreateEstate ( regInfo , estatesByName , defaultEstateName ) )
defaultEstateJoined = true ;
}
if ( defaultEstateJoined )
2012-05-10 16:08:40 +00:00
return true ; // need to update the database
2012-03-10 01:27:05 +00:00
else
m_log . ErrorFormat (
"[OPENSIM BASE]: Joining default estate {0} failed" , defaultEstateName ) ;
}
}
// If we have no default estate or creation of the default estate failed then ask the user.
while ( true )
{
if ( estates . Count = = 0 )
{
m_log . Info ( "[ESTATE]: No existing estates found. You must create a new one." ) ;
if ( CreateEstate ( regInfo , estatesByName , null ) )
break ;
else
continue ;
}
else
{
string response
= MainConsole . Instance . CmdPrompt (
string . Format (
"Do you wish to join region {0} to an existing estate (yes/no)?" , regInfo . RegionName ) ,
"yes" ,
new List < string > ( ) { "yes" , "no" } ) ;
if ( response = = "no" )
{
if ( CreateEstate ( regInfo , estatesByName , null ) )
break ;
2011-03-21 23:16:57 +00:00
else
continue ;
2010-08-13 15:08:43 +00:00
}
else
{
2012-03-10 01:27:05 +00:00
string [ ] estateNames = estatesByName . Keys . ToArray ( ) ;
response
2011-03-21 21:37:06 +00:00
= MainConsole . Instance . CmdPrompt (
2011-03-21 23:26:35 +00:00
string . Format (
2012-03-10 01:27:05 +00:00
"Name of estate to join. Existing estate names are ({0})" ,
string . Join ( ", " , estateNames ) ) ,
estateNames [ 0 ] ) ;
List < int > estateIDs = EstateDataService . GetEstates ( response ) ;
if ( estateIDs . Count < 1 )
2010-08-13 15:08:43 +00:00
{
2012-03-10 01:27:05 +00:00
MainConsole . Instance . Output ( "The name you have entered matches no known estate. Please try again." ) ;
continue ;
2011-03-21 22:57:20 +00:00
}
2012-03-10 01:27:05 +00:00
int estateID = estateIDs [ 0 ] ;
regInfo . EstateSettings = EstateDataService . LoadEstateSettings ( estateID ) ;
if ( EstateDataService . LinkRegion ( regInfo . RegionID , estateID ) )
break ;
MainConsole . Instance . Output ( "Joining the estate failed. Please try again." ) ;
2010-08-13 15:08:43 +00:00
}
}
2012-11-22 05:48:41 +00:00
}
2012-05-10 16:08:40 +00:00
2012-11-22 05:48:41 +00:00
return true ; // need to update the database
}
2007-07-16 15:40:11 +00:00
}
2009-05-02 16:28:30 +00:00
2008-06-26 17:20:08 +00:00
public class OpenSimConfigSource
{
2008-06-26 17:23:05 +00:00
public IConfigSource Source ;
2008-06-26 17:20:08 +00:00
}
2014-03-22 01:47:48 +00:00
}