29 using System.Collections.Generic;
33 using System.Reflection;
38 using OpenSim.Framework;
39 using OpenSim.Framework.Console;
40 using OpenSim.Framework.Servers;
41 using OpenSim.Framework.Servers.HttpServer;
42 using OpenSim.Framework.Monitoring;
43 using OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts;
44 using OpenSim.Region.Framework;
45 using OpenSim.Region.Framework.Interfaces;
46 using OpenSim.Region.Framework.Scenes;
47 using OpenSim.Region.PhysicsModules.SharedBase;
48 using OpenSim.Server.Base;
49 using OpenSim.Services.Base;
50 using OpenSim.Services.Interfaces;
51 using OpenSim.Services.UserAccountService;
60 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
66 private const string PLUGIN_ASSET_CACHE =
"/OpenSim/AssetCache";
67 private const string PLUGIN_ASSET_SERVER_CLIENT =
"/OpenSim/AssetClient";
111 public List<IApplicationPlugin>
m_plugins =
new List<IApplicationPlugin>();
113 private List<string> m_permsModules;
115 private bool m_securePermissionsLoading =
true;
156 Config = ConfigSource.Source;
162 IConfig networkConfig = Config.Configs[
"Network"];
163 if (networkConfig != null)
165 proxyUrl = networkConfig.GetString(
"proxy_url",
"");
166 proxyOffset = Int32.Parse(networkConfig.GetString(
"proxy_offset",
"0"));
169 IConfig startupConfig = Config.Configs[
"Startup"];
170 if (startupConfig != null)
172 Util.LogOverloads = startupConfig.GetBoolean(
"LogOverloads",
true);
178 IConfig startupConfig = Config.Configs[
"Startup"];
179 string registryLocation = (startupConfig != null) ? startupConfig.GetString(
"RegistryLocation",
String.Empty) : String.Empty;
184 if (registryLocation ==
String.Empty)
188 loader.Load(
"/OpenSim/Startup");
196 loader.Load(
"/OpenSim/Startup");
204 List<string> topics = base.GetHelpTopics();
205 Scene s = SceneManager.CurrentOrFirstScene;
206 if (s != null && s.GetCommanders() != null)
207 topics.AddRange(s.GetCommanders().Keys);
218 IConfig startupConfig = Config.Configs[
"Startup"];
219 if (startupConfig != null)
221 string pidFile = startupConfig.GetString(
"PIDFile", String.Empty);
222 if (pidFile !=
String.Empty)
225 userStatsURI = startupConfig.GetString(
"Stats_URI", String.Empty);
227 m_securePermissionsLoading = startupConfig.GetBoolean(
"SecurePermissionsLoading",
true);
229 string permissionModules = Util.GetConfigVarFromSections<
string>(
Config,
"permissionmodules",
230 new string[] {
"Startup",
"Permissions" },
"DefaultPermissionsModule");
232 m_permsModules =
new List<string>(permissionModules.Split(
','));
234 managedStatsURI = startupConfig.GetString(
"ManagedStatsRemoteFetchURI", String.Empty);
238 IConfig simDataConfig = Config.Configs[
"SimulationDataStore"];
239 if (simDataConfig == null)
240 throw new Exception(
"Configuration file is missing the [SimulationDataStore] section. Have you copied OpenSim.ini.example to OpenSim.ini to reference config-include/ files?");
242 string module = simDataConfig.GetString(
"LocalServiceModule", String.Empty);
243 if (
String.IsNullOrEmpty(module))
244 throw new Exception(
"Configuration file is missing the LocalServiceModule parameter in the [SimulationDataStore] section.");
250 "Could not load an ISimulationDataService implementation from {0}, as configured in the LocalServiceModule parameter of the [SimulationDataStore] config section.",
254 module = Util.GetConfigVarFromSections<
string>(
Config,
"LocalServiceModule",
new string[]{
"EstateDataStore",
"EstateService"}, String.Empty);
255 if (
String.IsNullOrEmpty(module))
256 throw new Exception(
"Configuration file is missing the LocalServiceModule parameter in the [EstateDataStore] or [EstateService] section");
264 "Could not load an IEstateDataService implementation from {0}, as configured in the LocalServiceModule parameter of the [EstateDataStore] config section.",
268 base.StartupSpecific();
276 plugin.PostInitialise();
286 foreach (
string topic
in topics)
288 string capitalizedTopic = char.ToUpper(topic[0]) + topic.Substring(1);
292 console.Commands.AddCommand(capitalizedTopic,
false,
"help " + topic,
293 "help " + capitalizedTopic,
294 "Get help on plugin command '" + topic +
"'",
295 HandleCommanderHelp);
296 console.Commands.AddCommand(capitalizedTopic,
false,
"help " + capitalizedTopic,
297 "help " + capitalizedTopic,
298 "Get help on plugin command '" + topic +
"'",
299 HandleCommanderHelp);
303 Scene s = SceneManager.CurrentOrFirstScene;
308 commander = s.GetCommanders()[topic];
311 if (commander == null)
314 foreach (
string command
in commander.Commands.Keys)
316 console.Commands.AddCommand(capitalizedTopic,
false,
317 topic +
" " + command,
318 topic +
" " + commander.Commands[command].ShortHelp(),
319 String.Empty, HandleCommanderCommand);
324 private void HandleCommanderCommand(
string module,
string[] cmd)
326 SceneManager.SendCommandToPluginModules(cmd);
329 private void HandleCommanderHelp(
string module,
string[] cmd)
334 ICommander moduleCommander = SceneManager.CurrentOrFirstScene.GetCommander(cmd[1].ToLower());
335 if (moduleCommander != null)
336 m_console.Output(moduleCommander.Help);
343 IConfig startupConfig = Config.Configs[
"Startup"];
344 if (startupConfig == null || startupConfig.GetBoolean(
"JobEngineEnabled",
true))
345 WorkManager.JobEngine.Start();
355 SceneManager.OnRegionsReadyStatusChange
356 += sm => { MemoryWatchdog.Enabled = sm.AllRegionsReady; Watchdog.Enabled = sm.AllRegionsReady; };
367 CreateRegion(regionInfo, portadd_flag,
false, out scene);
389 int port = regionInfo.InternalEndPoint.Port;
400 regionInfo.ServerURI =
"http://" + regionInfo.ExternalHostName +
":" + regionInfo.HttpPort.ToString() +
"/";
404 if ((
proxyUrl.Length > 0) && (portadd_flag))
409 Util.XmlRpcCommand(
proxyUrl,
"AddPort", port, port +
proxyOffset, regionInfo.ExternalHostName);
414 m_log.Info(
"[MODULES]: Loading Region's modules (old style)");
417 m_log.Info(
"[REGIONMODULES]: Loading Region's modules (new style)");
421 controller.AddRegionToModules(scene);
423 else m_log.Error(
"[REGIONMODULES]: The new RegionModulesController is missing...");
425 if (m_securePermissionsLoading)
427 foreach (
string s
in m_permsModules)
431 m_log.Fatal(
"[MODULES]: Required module " + s +
" not found.");
436 m_log.InfoFormat(
"[SCENE]: Secure permissions loading enabled, modules loaded: {0}", String.Join(
" ", m_permsModules.ToArray()));
439 scene.SetModuleInterfaces();
443 scene.SnmpService.ColdStart(1,scene);
444 scene.SnmpService.LinkDown(scene);
449 scene.SnmpService.BootInfo(
"Loading prins", scene);
453 SetUpEstateOwner(scene);
456 scene.LoadPrimsFromStorage(regionInfo.originRegionID);
461 scene.loadAllLandObjectsFromStorage(regionInfo.originRegionID);
462 scene.EventManager.TriggerParcelPrimCountUpdate();
466 scene.SnmpService.BootInfo(
"Grid Registration in progress", scene);
471 scene.RegisterRegionWithGrid();
476 "[STARTUP]: Registration of region with grid failed, aborting startup due to {0} {1}",
477 e.Message, e.StackTrace);
481 scene.SnmpService.Critical(
"Grid registration failed. Startup aborted.", scene);
490 scene.SnmpService.BootInfo(
"Grid Registration done", scene);
495 scene.CreateScriptInstances();
499 scene.SnmpService.BootInfo(
"ScriptEngine started", scene);
502 SceneManager.Add(scene);
515 scene.SnmpService.BootInfo(
"Initializing region modules", scene);
517 scene.EventManager.OnShutdown += delegate() { ShutdownRegion(scene); };
523 scene.SnmpService.BootInfo(
"The region is operational", scene);
524 scene.SnmpService.LinkUp(scene);
538 private void SetUpEstateOwner(
Scene scene)
542 string estateOwnerFirstName = null;
543 string estateOwnerLastName = null;
544 string estateOwnerEMail = null;
545 string estateOwnerPassword = null;
546 string rawEstateOwnerUuid = null;
550 string defaultEstateOwnerName
552 string[] ownerNames = defaultEstateOwnerName.Split(
' ');
554 if (ownerNames.Length >= 2)
556 estateOwnerFirstName = ownerNames[0];
557 estateOwnerLastName = ownerNames[1];
561 rawEstateOwnerUuid = Config.Configs[
ESTATE_SECTION_NAME].GetString(
"DefaultEstateOwnerUUID", null);
562 estateOwnerEMail = Config.Configs[
ESTATE_SECTION_NAME].GetString(
"DefaultEstateOwnerEMail", null);
563 estateOwnerPassword = Config.Configs[
ESTATE_SECTION_NAME].GetString(
"DefaultEstateOwnerPassword", null);
566 MainConsole.Instance.OutputFormat(
"Estate {0} has no owner set.", regionInfo.EstateSettings.EstateName);
567 List<char> excluded =
new List<char>(
new char[1]{
' '});
570 if (estateOwnerFirstName == null || estateOwnerLastName == null)
572 estateOwnerFirstName = MainConsole.Instance.CmdPrompt(
"Estate owner first name",
"Test", excluded);
573 estateOwnerLastName = MainConsole.Instance.CmdPrompt(
"Estate owner last name",
"User", excluded);
577 = scene.UserAccountService.GetUserAccount(regionInfo.ScopeID, estateOwnerFirstName, estateOwnerLastName);
596 if (estateOwnerPassword == null)
597 estateOwnerPassword = MainConsole.Instance.PasswdPrompt(
"Password");
599 if (estateOwnerEMail == null)
600 estateOwnerEMail = MainConsole.Instance.CmdPrompt(
"Email");
602 if (rawEstateOwnerUuid == null)
603 rawEstateOwnerUuid = MainConsole.Instance.CmdPrompt(
"User ID", UUID.Random().ToString());
605 UUID estateOwnerUuid = UUID.Zero;
606 if (!
UUID.TryParse(rawEstateOwnerUuid, out estateOwnerUuid))
608 m_log.ErrorFormat(
"[OPENSIM]: ID {0} is not a valid UUID", rawEstateOwnerUuid);
613 if (estateOwnerUuid ==
UUID.Zero)
614 estateOwnerUuid = UUID.Random();
620 estateOwnerFirstName,
630 "[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.");
634 regionInfo.EstateSettings.EstateOwner = account.PrincipalID;
635 m_estateDataService.StoreEstateSettings(regionInfo.EstateSettings);
639 private void ShutdownRegion(
Scene scene)
641 m_log.DebugFormat(
"[SHUTDOWN]: Shutting down region {0}", scene.RegionInfo.RegionName);
644 scene.SnmpService.BootInfo(
"The region is shutting down", scene);
645 scene.SnmpService.LinkDown(scene);
650 controller.RemoveRegionFromModules(scene);
661 SceneManager.TrySetCurrentScene(
"..");
664 scene.DeleteAllSceneObjects();
665 SceneManager.CloseScene(scene);
675 File.Delete(scene.RegionInfo.RegionFile);
676 m_log.InfoFormat(
"[OPENSIM]: deleting region file \"{0}\"", scene.RegionInfo.RegionFile);
685 source.Configs.Remove(scene.RegionInfo.RegionName);
687 if (source.Configs.Count == 0)
689 File.Delete(scene.RegionInfo.RegionFile);
693 source.Save(scene.RegionInfo.RegionFile);
723 SceneManager.TrySetCurrentScene(
"..");
726 SceneManager.CloseScene(scene);
768 scene.LoadWorldMap();
777 regionInfo, circuitManager,
778 simDataService, estateDataService,
785 "[OPENSIM]: Got restart signal from SceneManager for region {0} ({1},{2})",
786 whichRegion.RegionName, whichRegion.RegionLocX, whichRegion.RegionLocY);
794 # region Setup methods
809 return Util.UTF8.GetBytes(
"OK");
814 get {
return "text/plain"; }
827 : base(
"GET",
"/" + Util.SHA1Hash(sim.
osSecret),
"XSimStatus",
"Simulator XStatus")
835 return Util.UTF8.GetBytes(m_opensim.StatReport(httpRequest));
840 get {
return "text/plain"; }
855 : base(
"GET",
"/" + sim.
userStatsURI,
"UXSimStatus",
"Simulator UXStatus")
863 return Util.UTF8.GetBytes(m_opensim.StatReport(httpRequest));
868 get {
return "text/plain"; }
881 Util.XmlRpcCommand(
proxyUrl,
"Stop");
884 m_log.Info(
"[SHUTDOWN]: Closing all threads");
885 m_log.Info(
"[SHUTDOWN]: Killing listener thread");
886 m_log.Info(
"[SHUTDOWN]: Killing clients");
887 m_log.Info(
"[SHUTDOWN]: Closing console and terminating");
891 SceneManager.Close();
898 m_log.Error(
"[SHUTDOWN]: Ignoring failure during shutdown - ", e);
901 base.ShutdownSpecific();
909 public void GetRunTime(out
string starttime, out
string uptime)
911 starttime = m_startuptime.ToString();
921 usernum = SceneManager.GetCurrentSceneAvatars().Count;
930 regionnum = SceneManager.Scenes.Count;
946 regInfo.EstateSettings = EstateDataService.LoadEstateSettings(regInfo.RegionID,
true);
949 if (!
string.IsNullOrEmpty(estateName))
950 newName = estateName;
952 newName = MainConsole.Instance.CmdPrompt(
"New estate name", regInfo.EstateSettings.EstateName);
954 if (estatesByName.ContainsKey(newName))
956 MainConsole.Instance.OutputFormat(
"An estate named {0} already exists. Please try again.", newName);
960 regInfo.EstateSettings.EstateName = newName;
967 EstateDataService.StoreEstateSettings(regInfo.EstateSettings);
979 regInfo.EstateSettings = EstateDataService.LoadEstateSettings(regInfo.RegionID,
false);
984 m_log.WarnFormat(
"[ESTATE] Region {0} is not part of an estate.", regInfo.RegionName);
986 List<EstateSettings> estates = EstateDataService.LoadEstateSettingsAll();
987 Dictionary<string, EstateSettings> estatesByName =
new Dictionary<string, EstateSettings>();
990 estatesByName[estate.EstateName] = estate;
992 string defaultEstateName = null;
996 defaultEstateName = Config.Configs[
ESTATE_SECTION_NAME].GetString(
"DefaultEstateName", null);
998 if (defaultEstateName != null)
1001 bool defaultEstateJoined =
false;
1003 if (estatesByName.ContainsKey(defaultEstateName))
1005 defaultEstate = estatesByName[defaultEstateName];
1008 defaultEstateJoined =
true;
1012 if (
CreateEstate(regInfo, estatesByName, defaultEstateName))
1013 defaultEstateJoined =
true;
1016 if (defaultEstateJoined)
1020 "[OPENSIM BASE]: Joining default estate {0} failed", defaultEstateName);
1027 if (estates.Count == 0)
1029 m_log.Info(
"[ESTATE]: No existing estates found. You must create a new one.");
1039 = MainConsole.Instance.CmdPrompt(
1041 "Do you wish to join region {0} to an existing estate (yes/no)?", regInfo.RegionName),
1043 new List<string>() {
"yes",
"no" });
1045 if (response ==
"no")
1054 string[] estateNames = estatesByName.Keys.ToArray();
1056 = MainConsole.Instance.CmdPrompt(
1058 "Name of estate to join. Existing estate names are ({0})",
1059 string.Join(
", ", estateNames)),
1062 List<int> estateIDs = EstateDataService.GetEstates(response);
1063 if (estateIDs.Count < 1)
1065 MainConsole.Instance.Output(
"The name you have entered matches no known estate. Please try again.");
1069 int estateID = estateIDs[0];
1071 regInfo.EstateSettings = EstateDataService.LoadEstateSettings(estateID);
1076 MainConsole.Instance.Output(
"Joining the estate failed. Please try again.");
override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
virtual void LoadConfigSettings(IConfigSource configSource)
void GetRegionNumber(out int regionnum)
Get the number of regions
Scene SetupScene(RegionInfo regionInfo, int proxyOffset, IConfigSource configSource)
Create a scene and its initial base structures.
EstateSettings EstateSettings
void GetAvatarNumber(out int usernum)
Get the number of the avatars in the Region server
Handler to supply the current status of this sim
void RemoveRegion(string name, bool cleanUp)
Loads the Configuration files into nIni
bool LinkRegion(UUID regionID, int estateID)
Link a region to an estate.
List< IApplicationPlugin > m_plugins
override string ContentType
override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
override Scene CreateScene(RegionInfo regionInfo, ISimulationDataService simDataService, IEstateDataService estateDataService, AgentCircuitManager circuitManager)
OpenSim.Framework.RegionInfo RegionInfo
OpenSimulator Application Plugin framework interface
Dictionary< string, ICommander > GetCommanders()
XSimStatusHandler(OpenSimBase sim)
IEstateDataService EstateDataService
Base streamed request handler.
UXSimStatusHandler(OpenSimBase sim)
Scene SetupScene(RegionInfo regionInfo)
Create a scene and its initial base structures.
OpenSimConfigSource ConfigSource
override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
ConfigSettings m_configSettings
Handler to supply the current extended status of this sim Sends the statistical data in a json serial...
virtual void LoadPlugins()
void CloseRegion(Scene scene)
Remove a region from the simulator without deleting it permanently.
EnvConfigSource envConfigSource
string m_version
Server version information. Usually VersionInfo + information about git commit, operating system...
IRegistryCore ApplicationRegistry
void GetRunTime(out string starttime, out string uptime)
Get the start time and up time of Region server
OpenSimBase(IConfigSource configSource)
Constructor.
ConfigurationLoader m_configLoader
Handler to supply the current extended status of this sim to a user configured URI Sends the statisti...
Dictionary< string, IRegionModuleBase > RegionModules
IRegistryCore m_applicationRegistry
virtual void HandleRestartRegion(RegionInfo whichRegion)
static ICommandConsole Instance
delegate void ConsoleCommand(string[] comParams)
Manager for adding, closing and restarting scenes.
override string ContentType
IUserAccountService UserAccountService
Scene CurrentScene
Scene selected from the console.
void CreateRegion(RegionInfo regionInfo, bool portadd_flag, bool do_post_init, out IScene mscene)
Execute the region creation process. This includes setting up scene infrastructure.
bool EnableInitialPluginLoad
Allow all plugin loading to be disabled for tests/debug.
bool LoadEstateDataService
Control whether we attempt to load an estate data service.
override void ShutdownSpecific()
Performs any last-minute sanity checking and shuts down the region server
override void Initialize()
const string DEFAULT_PRIM_BACKUP_FILENAME
void CreateRegion(RegionInfo regionInfo, out IScene scene)
Execute the region creation process. This includes setting up scene infrastructure.
NetworkServersInfo m_networkServersInfo
override List< string > GetHelpTopics()
Provides a list of help topics that are available. Overriding classes should append their topics to t...
Common OpenSimulator simulator code
bool m_autoCreateClientStack
string m_osSecret
Random uuid for private data
ICommandConsole m_console
Console to be used for any command line output. Can be null, in which case there should be no output...
override string ContentType
ConfigSettings ConfigurationSettings
void RemoveRegion(Scene scene, bool cleanup)
bool CreateEstate(RegionInfo regInfo, Dictionary< string, EstateSettings > estatesByName, string estateName)
Create an estate with an initial region.
EnvConfigSource m_EnvConfigSource
ConsoleCommand CreateAccount
void CloseRegion(string name)
Remove a region from the simulator without deleting it permanently.
void CreatePIDFile(string path)
bool PopulateRegionEstateInfo(RegionInfo regInfo)
Load the estate information for the provided RegionInfo object.
virtual RegionInfo RegionInfo
void CreateRegion(RegionInfo regionInfo, bool portadd_flag, out IScene scene)
Execute the region creation process. This includes setting up scene infrastructure.
const string ESTATE_SECTION_NAME
virtual void AddPluginCommands(ICommandConsole console)
IEstateDataService m_estateDataService
ISimulationDataService m_simulationDataService
bool TryGetScene(string regionName, out Scene scene)
override void StartupSpecific()
Performs startup specific to the region server, including initialization of the scene such as loading...
virtual void ReadExtraConfigSettings()