12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Reflection;
- using System.Text;
- using log4net;
- using Nini.Config;
- using OpenMetaverse;
- using OpenSim.Framework;
- using OpenSim.Framework.Console;
- using OpenSim.Framework.Servers;
- using OpenSim.Framework.Servers.HttpServer;
- using OpenSim.Framework.Monitoring;
- using OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts;
- using OpenSim.Region.Framework;
- using OpenSim.Region.Framework.Interfaces;
- using OpenSim.Region.Framework.Scenes;
- using OpenSim.Region.PhysicsModules.SharedBase;
- using OpenSim.Server.Base;
- using OpenSim.Services.Base;
- using OpenSim.Services.Interfaces;
- using OpenSim.Services.UserAccountService;
- namespace OpenSim
- {
-
-
-
- public class OpenSimBase : RegionApplicationBase
- {
- private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
-
-
-
- private const string PLUGIN_ASSET_CACHE = "/OpenSim/AssetCache";
- private const string PLUGIN_ASSET_SERVER_CLIENT = "/OpenSim/AssetClient";
-
- public const string ESTATE_SECTION_NAME = "Estates";
-
-
-
-
-
-
- public bool EnableInitialPluginLoad { get; set; }
-
-
-
-
- public bool LoadEstateDataService { get; set; }
- protected string proxyUrl;
- protected int proxyOffset = 0;
- public string userStatsURI = String.Empty;
- public string managedStatsURI = String.Empty;
- public string managedStatsPassword = String.Empty;
- protected bool m_autoCreateClientStack = true;
-
-
-
- protected const string DEFAULT_PRIM_BACKUP_FILENAME = "prim-backup.xml";
- public ConfigSettings ConfigurationSettings
- {
- get { return m_configSettings; }
- set { m_configSettings = value; }
- }
- protected ConfigSettings m_configSettings;
- protected ConfigurationLoader m_configLoader;
- public ConsoleCommand CreateAccount = null;
- public List<IApplicationPlugin> m_plugins = new List<IApplicationPlugin>();
- private List<string> m_permsModules;
- private bool m_securePermissionsLoading = true;
-
-
-
- public OpenSimConfigSource ConfigSource { get; private set; }
- protected EnvConfigSource m_EnvConfigSource = new EnvConfigSource();
- public EnvConfigSource envConfigSource
- {
- get { return m_EnvConfigSource; }
- }
- public uint HttpServerPort
- {
- get { return m_httpServerPort; }
- }
- protected IRegistryCore m_applicationRegistry = new RegistryCore();
- public IRegistryCore ApplicationRegistry
- {
- get { return m_applicationRegistry; }
- }
-
-
-
-
- public OpenSimBase(IConfigSource configSource) : base()
- {
- EnableInitialPluginLoad = true;
- LoadEstateDataService = true;
- LoadConfigSettings(configSource);
- }
- protected virtual void LoadConfigSettings(IConfigSource configSource)
- {
- m_configLoader = new ConfigurationLoader();
- ConfigSource = m_configLoader.LoadConfigSettings(configSource, envConfigSource, out m_configSettings, out m_networkServersInfo);
- Config = ConfigSource.Source;
- ReadExtraConfigSettings();
- }
- protected virtual void ReadExtraConfigSettings()
- {
- IConfig networkConfig = Config.Configs["Network"];
- if (networkConfig != null)
- {
- proxyUrl = networkConfig.GetString("proxy_url", "");
- proxyOffset = Int32.Parse(networkConfig.GetString("proxy_offset", "0"));
- }
- IConfig startupConfig = Config.Configs["Startup"];
- if (startupConfig != null)
- {
- Util.LogOverloads = startupConfig.GetBoolean("LogOverloads", true);
- }
- }
- protected virtual void LoadPlugins()
- {
- IConfig startupConfig = Config.Configs["Startup"];
- string registryLocation = (startupConfig != null) ? startupConfig.GetString("RegistryLocation", String.Empty) : String.Empty;
-
-
-
- if (registryLocation == String.Empty)
- {
- 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;
- }
- }
- }
- protected override List<string> GetHelpTopics()
- {
- List<string> topics = base.GetHelpTopics();
- Scene s = SceneManager.CurrentOrFirstScene;
- if (s != null && s.GetCommanders() != null)
- topics.AddRange(s.GetCommanders().Keys);
- return topics;
- }
-
-
-
-
- protected override void StartupSpecific()
- {
- IConfig startupConfig = Config.Configs["Startup"];
- if (startupConfig != null)
- {
-
- if(startupConfig.GetBoolean("CombineContiguousRegions", false))
- {
- m_log.Fatal("CombineContiguousRegions (MegaRegions) option is no longer suported. Use a older version to save region contents as OAR, then import into a fresh install of this new version");
- throw new Exception("CombineContiguousRegions not suported");
- }
- string pidFile = startupConfig.GetString("PIDFile", String.Empty);
- if (pidFile != String.Empty)
- CreatePIDFile(pidFile);
- userStatsURI = startupConfig.GetString("Stats_URI", String.Empty);
- m_securePermissionsLoading = startupConfig.GetBoolean("SecurePermissionsLoading", true);
- string permissionModules = Util.GetConfigVarFromSections<string>(Config, "permissionmodules",
- new string[] { "Startup", "Permissions" }, "DefaultPermissionsModule");
- m_permsModules = new List<string>(permissionModules.Split(',').Select(m => m.Trim()));
- managedStatsURI = startupConfig.GetString("ManagedStatsRemoteFetchURI", String.Empty);
- managedStatsPassword = startupConfig.GetString("ManagedStatsRemoteFetchPassword", String.Empty);
- }
-
- IConfig simDataConfig = Config.Configs["SimulationDataStore"];
- if (simDataConfig == null)
- throw new Exception("Configuration file is missing the [SimulationDataStore] section. Have you copied OpenSim.ini.example to OpenSim.ini to reference config-include/ files?");
- string module = simDataConfig.GetString("LocalServiceModule", String.Empty);
- if (String.IsNullOrEmpty(module))
- throw new Exception("Configuration file is missing the LocalServiceModule parameter in the [SimulationDataStore] section.");
- m_simulationDataService = ServerUtils.LoadPlugin<ISimulationDataService>(module, new object[] { Config });
- 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));
-
- module = Util.GetConfigVarFromSections<string>(Config, "LocalServiceModule", new string[]{"EstateDataStore", "EstateService"}, String.Empty);
- if (String.IsNullOrEmpty(module))
- throw new Exception("Configuration file is missing the LocalServiceModule parameter in the [EstateDataStore] or [EstateService] section");
- 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));
- }
- base.StartupSpecific();
- if (EnableInitialPluginLoad)
- LoadPlugins();
-
-
- foreach (IApplicationPlugin plugin in m_plugins)
- plugin.PostInitialise();
- if (m_console != null)
- AddPluginCommands(m_console);
- }
- protected virtual void AddPluginCommands(ICommandConsole console)
- {
- List<string> topics = GetHelpTopics();
- foreach (string topic in topics)
- {
- string capitalizedTopic = char.ToUpper(topic[0]) + topic.Substring(1);
-
-
- 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;
- foreach (string command in commander.Commands.Keys)
- {
- console.Commands.AddCommand(capitalizedTopic, false,
- topic + " " + command,
- topic + " " + commander.Commands[command].ShortHelp(),
- String.Empty, HandleCommanderCommand);
- }
- }
- }
- private void HandleCommanderCommand(string module, string[] cmd)
- {
- SceneManager.SendCommandToPluginModules(cmd);
- }
- private void HandleCommanderHelp(string module, string[] cmd)
- {
-
-
-
- ICommander moduleCommander = SceneManager.CurrentOrFirstScene.GetCommander(cmd[1].ToLower());
- if (moduleCommander != null)
- m_console.Output(moduleCommander.Help);
- }
- protected override void Initialize()
- {
-
- IConfig startupConfig = Config.Configs["Startup"];
- if (startupConfig == null || startupConfig.GetBoolean("JobEngineEnabled", true))
- WorkManager.JobEngine.Start();
-
- if(m_networkServersInfo.HttpUsesSSL)
- {
- m_httpServerSSL = true;
- m_httpServerPort = m_networkServersInfo.httpSSLPort;
- }
- else
- {
- m_httpServerSSL = false;
- m_httpServerPort = m_networkServersInfo.HttpListenerPort;
- }
- SceneManager.OnRestartSim += HandleRestartRegion;
-
-
-
-
-
- SceneManager.OnRegionsReadyStatusChange
- += sm => { MemoryWatchdog.Enabled = sm.AllRegionsReady; Watchdog.Enabled = sm.AllRegionsReady; };
- }
-
-
-
-
-
-
- public void CreateRegion(RegionInfo regionInfo, bool portadd_flag, out IScene scene)
- {
- CreateRegion(regionInfo, portadd_flag, false, out scene);
- }
-
-
-
-
-
- public void CreateRegion(RegionInfo regionInfo, out IScene scene)
- {
- CreateRegion(regionInfo, false, true, out scene);
- }
-
-
-
-
-
-
-
- public void CreateRegion(RegionInfo regionInfo, bool portadd_flag, bool do_post_init, out IScene mscene)
- {
- int port = regionInfo.InternalEndPoint.Port;
-
-
-
-
-
-
-
- regionInfo.HttpPort = m_httpServerPort;
- if(m_httpServerSSL)
- {
- if(!m_httpServer.CheckSSLCertHost(regionInfo.ExternalHostName))
- throw new Exception("main http cert CN doesn't match region External IP");
- regionInfo.ServerURI = "https://" + regionInfo.ExternalHostName +
- ":" + regionInfo.HttpPort.ToString() + "/";
- }
- else
- regionInfo.ServerURI = "http://" + regionInfo.ExternalHostName +
- ":" + regionInfo.HttpPort.ToString() + "/";
- regionInfo.osSecret = m_osSecret;
- if ((proxyUrl.Length > 0) && (portadd_flag))
- {
-
- regionInfo.proxyUrl = proxyUrl;
- regionInfo.ProxyOffset = proxyOffset;
- Util.XmlRpcCommand(proxyUrl, "AddPort", port, port + proxyOffset, regionInfo.ExternalHostName);
- }
- Scene scene = SetupScene(regionInfo, proxyOffset, Config);
- m_log.Info("[MODULES]: Loading Region's modules (old style)");
-
- m_log.Info("[REGIONMODULES]: Loading Region's modules (new style)");
- IRegionModulesController controller;
- if (ApplicationRegistry.TryGet(out controller))
- {
- controller.AddRegionToModules(scene);
- }
- else m_log.Error("[REGIONMODULES]: The new RegionModulesController is missing...");
- if (m_securePermissionsLoading)
- {
- foreach (string s in m_permsModules)
- {
- if (!scene.RegionModules.ContainsKey(s))
- {
- m_log.Fatal("[MODULES]: Required module " + s + " not found.");
- Environment.Exit(0);
- }
- }
- m_log.InfoFormat("[SCENE]: Secure permissions loading enabled, modules loaded: {0}", String.Join(" ", m_permsModules.ToArray()));
- }
- scene.SetModuleInterfaces();
- if (scene.SnmpService != null)
- {
- scene.SnmpService.ColdStart(1,scene);
- scene.SnmpService.LinkDown(scene);
- }
- if (scene.SnmpService != null)
- {
- scene.SnmpService.BootInfo("Loading prims", scene);
- }
- while (regionInfo.EstateSettings.EstateOwner == UUID.Zero && MainConsole.Instance != null)
- SetUpEstateOwner(scene);
- scene.loadAllLandObjectsFromStorage(regionInfo.originRegionID);
-
- scene.LoadPrimsFromStorage(regionInfo.originRegionID);
-
- MainServer.Instance.AddSimpleStreamHandler(new RegionStatsSimpleHandler(regionInfo));
- if (scene.SnmpService != null)
- {
- scene.SnmpService.BootInfo("Grid Registration in progress", scene);
- }
- try
- {
- scene.RegisterRegionWithGrid();
- }
- catch (Exception e)
- {
- m_log.ErrorFormat(
- "[STARTUP]: Registration of region with grid failed, aborting startup due to {0} {1}",
- e.Message, e.StackTrace);
- if (scene.SnmpService != null)
- {
- scene.SnmpService.Critical("Grid registration failed. Startup aborted.", scene);
- }
-
-
- Environment.Exit(1);
- }
- if (scene.SnmpService != null)
- {
- scene.SnmpService.BootInfo("Grid Registration done", scene);
- }
-
-
- scene.CreateScriptInstances();
- if (scene.SnmpService != null)
- {
- scene.SnmpService.BootInfo("ScriptEngine started", scene);
- }
- SceneManager.Add(scene);
-
-
-
-
-
-
-
-
- if (scene.SnmpService != null)
- {
- scene.SnmpService.BootInfo("Initializing region modules", scene);
- }
- scene.EventManager.OnShutdown += delegate() { ShutdownRegion(scene); };
- mscene = scene;
- if (scene.SnmpService != null)
- {
- scene.SnmpService.BootInfo("The region is operational", scene);
- scene.SnmpService.LinkUp(scene);
- }
-
- }
-
-
-
-
-
-
-
-
- private void SetUpEstateOwner(Scene scene)
- {
- RegionInfo regionInfo = scene.RegionInfo;
- string estateOwnerFirstName = null;
- string estateOwnerLastName = null;
- string estateOwnerEMail = null;
- string estateOwnerPassword = null;
- string rawEstateOwnerUuid = null;
- if (Config.Configs[ESTATE_SECTION_NAME] != null)
- {
- string defaultEstateOwnerName
- = Config.Configs[ESTATE_SECTION_NAME].GetString("DefaultEstateOwnerName", "").Trim();
- string[] ownerNames = defaultEstateOwnerName.Split(' ');
- if (ownerNames.Length >= 2)
- {
- estateOwnerFirstName = ownerNames[0];
- estateOwnerLastName = ownerNames[1];
- }
-
- 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);
- }
- MainConsole.Instance.Output("Estate {0} has no owner set.", regionInfo.EstateSettings.EstateName);
- List<char> excluded = new List<char>(new char[1]{' '});
- if (estateOwnerFirstName == null || estateOwnerLastName == null)
- {
- estateOwnerFirstName = MainConsole.Instance.Prompt("Estate owner first name", "Test", excluded);
- estateOwnerLastName = MainConsole.Instance.Prompt("Estate owner last name", "User", excluded);
- }
- UserAccount account
- = scene.UserAccountService.GetUserAccount(regionInfo.ScopeID, estateOwnerFirstName, estateOwnerLastName);
- if (account == null)
- {
-
-
- if (scene.UserAccountService is UserAccountService)
- {
- if (estateOwnerPassword == null)
- estateOwnerPassword = MainConsole.Instance.Prompt("Password", null, null, false);
- if (estateOwnerEMail == null)
- estateOwnerEMail = MainConsole.Instance.Prompt("Email");
- if (rawEstateOwnerUuid == null)
- rawEstateOwnerUuid = MainConsole.Instance.Prompt("User ID", UUID.Random().ToString());
- UUID estateOwnerUuid = UUID.Zero;
- if (!UUID.TryParse(rawEstateOwnerUuid, out estateOwnerUuid))
- {
- m_log.ErrorFormat("[OPENSIM]: ID {0} is not a valid UUID", rawEstateOwnerUuid);
- return;
- }
-
- if (estateOwnerUuid == UUID.Zero)
- estateOwnerUuid = UUID.Random();
- account
- = ((UserAccountService)scene.UserAccountService).CreateUser(
- regionInfo.ScopeID,
- estateOwnerUuid,
- estateOwnerFirstName,
- estateOwnerLastName,
- estateOwnerPassword,
- estateOwnerEMail);
- }
- }
- if (account == null)
- {
- m_log.ErrorFormat(
- "[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.");
- }
- else
- {
- regionInfo.EstateSettings.EstateOwner = account.PrincipalID;
- m_estateDataService.StoreEstateSettings(regionInfo.EstateSettings);
- }
- }
- private void ShutdownRegion(Scene scene)
- {
- m_log.DebugFormat("[SHUTDOWN]: Shutting down region {0}", scene.RegionInfo.RegionName);
- if (scene.SnmpService != null)
- {
- scene.SnmpService.BootInfo("The region is shutting down", scene);
- scene.SnmpService.LinkDown(scene);
- }
- IRegionModulesController controller;
- if (ApplicationRegistry.TryGet<IRegionModulesController>(out controller))
- {
- controller.RemoveRegionFromModules(scene);
- }
- }
- public void RemoveRegion(Scene scene, bool cleanup)
- {
-
-
- if ((SceneManager.CurrentScene != null) &&
- (SceneManager.CurrentScene.RegionInfo.RegionID == scene.RegionInfo.RegionID))
- {
- SceneManager.TrySetCurrentScene("..");
- }
- scene.DeleteAllSceneObjects();
- SceneManager.CloseScene(scene);
-
- if (!cleanup)
- return;
- if (!String.IsNullOrEmpty(scene.RegionInfo.RegionFile))
- {
- 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)
- {
- }
- }
- }
- }
- public void RemoveRegion(string name, bool cleanUp)
- {
- Scene target;
- if (SceneManager.TryGetScene(name, out target))
- RemoveRegion(target, cleanUp);
- }
-
-
-
-
-
- public void CloseRegion(Scene scene)
- {
-
-
- if ((SceneManager.CurrentScene != null) &&
- (SceneManager.CurrentScene.RegionInfo.RegionID == scene.RegionInfo.RegionID))
- {
- SceneManager.TrySetCurrentScene("..");
- }
- SceneManager.CloseScene(scene);
-
- }
-
-
-
-
-
- public void CloseRegion(string name)
- {
- Scene target;
- if (SceneManager.TryGetScene(name, out target))
- CloseRegion(target);
- }
-
-
-
-
-
-
- protected Scene SetupScene(RegionInfo regionInfo)
- {
- return SetupScene(regionInfo, 0, null);
- }
-
-
-
-
-
-
-
-
- protected Scene SetupScene(RegionInfo regionInfo, int proxyOffset, IConfigSource configSource)
- {
-
- AgentCircuitManager circuitManager = new AgentCircuitManager();
- Scene scene = CreateScene(regionInfo, m_simulationDataService, m_estateDataService, circuitManager);
- scene.LoadWorldMap();
- return scene;
- }
- protected override Scene CreateScene(RegionInfo regionInfo, ISimulationDataService simDataService,
- IEstateDataService estateDataService, AgentCircuitManager circuitManager)
- {
- return new Scene(
- regionInfo, circuitManager,
- simDataService, estateDataService,
- Config, m_version);
- }
- protected virtual void HandleRestartRegion(RegionInfo whichRegion)
- {
- m_log.InfoFormat(
- "[OPENSIM]: Got restart signal from SceneManager for region {0} ({1},{2})",
- whichRegion.RegionName, whichRegion.RegionLocX, whichRegion.RegionLocY);
-
- IScene scene;
- CreateRegion(whichRegion, true, out scene);
- scene.Start();
- }
- # region Setup methods
-
-
-
-
-
-
- public class SimStatusHandler : SimpleStreamHandler
- {
- public SimStatusHandler() : base("/simstatus", "SimStatus") {}
- protected override void ProcessRequest(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
- {
- httpResponse.KeepAlive = false;
- httpResponse.RawBuffer = Util.UTF8.GetBytes("OK");
- httpResponse.StatusCode = (int)HttpStatusCode.OK;
- }
- }
-
-
-
-
- public class XSimStatusHandler : SimpleStreamHandler
- {
- OpenSimBase m_opensim;
- public XSimStatusHandler(OpenSimBase sim)
- : base("/" + Util.SHA1Hash(sim.osSecret), "XSimStatus")
- {
- m_opensim = sim;
- }
- protected override void ProcessRequest(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
- {
- httpResponse.KeepAlive = false;
- try
- {
- httpResponse.RawBuffer = Util.UTF8.GetBytes(m_opensim.StatReport(httpRequest));
- httpResponse.StatusCode = (int)HttpStatusCode.OK;
- }
- catch
- {
- httpResponse.StatusCode = (int)HttpStatusCode.InternalServerError;
- }
- }
- }
-
-
-
-
-
-
- protected class UXSimStatusHandler : SimpleStreamHandler
- {
- OpenSimBase m_opensim;
- public UXSimStatusHandler(OpenSimBase sim)
- : base("/" + sim.userStatsURI, "UXSimStatus")
- {
- m_opensim = sim;
- }
- protected override void ProcessRequest(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
- {
- httpResponse.KeepAlive = false;
- try
- {
- httpResponse.RawBuffer = Util.UTF8.GetBytes(m_opensim.StatReport(httpRequest));
- httpResponse.StatusCode = (int)HttpStatusCode.OK;
- }
- catch
- {
- httpResponse.StatusCode = (int)HttpStatusCode.InternalServerError;
- }
- }
- }
-
-
-
- public class SimRobotsHandler : SimpleStreamHandler
- {
- private readonly byte[] binmsg;
- public SimRobotsHandler() : base("/robots.txt", "SimRobots")
- {
- binmsg = Util.UTF8.GetBytes("# go away\nUser-agent: *\nDisallow: /\n");
- }
- protected override void ProcessRequest(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
- {
- httpResponse.KeepAlive = false;
- httpResponse.RawBuffer = binmsg;
- httpResponse.StatusCode = (int)HttpStatusCode.OK;
- return;
- }
- }
- #endregion
-
-
-
- protected override void ShutdownSpecific()
- {
- if (proxyUrl.Length > 0)
- {
- Util.XmlRpcCommand(proxyUrl, "Stop");
- }
- 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");
- try
- {
- SceneManager.Close();
- foreach (IApplicationPlugin plugin in m_plugins)
- plugin.Dispose();
- }
- catch (Exception e)
- {
- m_log.Error("[SHUTDOWN]: Ignoring failure during shutdown - ", e);
- }
- base.ShutdownSpecific();
- }
-
-
-
-
-
- public void GetRunTime(out string starttime, out string uptime)
- {
- starttime = m_startuptime.ToString();
- uptime = (DateTime.Now - m_startuptime).ToString();
- }
-
-
-
-
- public void GetAvatarNumber(out int usernum)
- {
- usernum = SceneManager.GetCurrentSceneAvatars().Count;
- }
-
-
-
-
- public void GetRegionNumber(out int regionnum)
- {
- regionnum = SceneManager.Scenes.Count;
- }
-
-
-
-
-
-
-
-
-
-
- public bool CreateEstate(RegionInfo regInfo, Dictionary<string, EstateSettings> estatesByName, string estateName)
- {
-
- regInfo.EstateSettings = EstateDataService.LoadEstateSettings(regInfo.RegionID, true);
- string newName;
- if (!string.IsNullOrEmpty(estateName))
- newName = estateName;
- else
- newName = MainConsole.Instance.Prompt("New estate name", regInfo.EstateSettings.EstateName);
- if (estatesByName.ContainsKey(newName))
- {
- MainConsole.Instance.Output("An estate named {0} already exists. Please try again.", newName);
- return false;
- }
- regInfo.EstateSettings.EstateName = newName;
-
-
-
-
-
- EstateDataService.StoreEstateSettings(regInfo.EstateSettings);
- return true;
- }
-
-
-
-
- public bool PopulateRegionEstateInfo(RegionInfo regInfo)
- {
- if (EstateDataService != null)
- regInfo.EstateSettings = EstateDataService.LoadEstateSettings(regInfo.RegionID, false);
- if (regInfo.EstateSettings.EstateID != 0)
- return false;
- 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;
- if (Config.Configs[ESTATE_SECTION_NAME] != null)
- {
- defaultEstateName = Config.Configs[ESTATE_SECTION_NAME].GetString("DefaultEstateName", null);
- if (defaultEstateName != null)
- {
- 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)
- return true;
- else
- m_log.ErrorFormat(
- "[OPENSIM BASE]: Joining default estate {0} failed", defaultEstateName);
- }
- }
-
- 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.Prompt(
- 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;
- else
- continue;
- }
- else
- {
- string[] estateNames = estatesByName.Keys.ToArray();
- response
- = MainConsole.Instance.Prompt(
- string.Format(
- "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)
- {
- MainConsole.Instance.Output("The name you have entered matches no known estate. Please try again.");
- continue;
- }
- 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.");
- }
- }
- }
- return true;
- }
- }
- public class OpenSimConfigSource
- {
- public IConfigSource Source;
- }
- }
|