OpenSimBase.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.IO;
  30. using System.Net;
  31. using System.Reflection;
  32. using System.Text;
  33. using log4net;
  34. using Nini.Config;
  35. using OpenMetaverse;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Communications;
  38. using OpenSim.Framework.Communications.Services;
  39. using OpenSim.Framework.Communications.Cache;
  40. using OpenSim.Framework.Console;
  41. using OpenSim.Framework.Servers;
  42. using OpenSim.Framework.Servers.HttpServer;
  43. using OpenSim.Framework.Statistics;
  44. using OpenSim.Region.ClientStack;
  45. using OpenSim.Region.Framework;
  46. using OpenSim.Region.Framework.Interfaces;
  47. using OpenSim.Region.Framework.Scenes;
  48. using OpenSim.Region.Physics.Manager;
  49. namespace OpenSim
  50. {
  51. /// <summary>
  52. /// Common OpenSimulator simulator code
  53. /// </summary>
  54. public class OpenSimBase : RegionApplicationBase
  55. {
  56. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  57. // These are the names of the plugin-points extended by this
  58. // class during system startup.
  59. private const string PLUGIN_ASSET_CACHE = "/OpenSim/AssetCache";
  60. private const string PLUGIN_ASSET_SERVER_CLIENT = "/OpenSim/AssetClient";
  61. protected string proxyUrl;
  62. protected int proxyOffset = 0;
  63. public string userStatsURI = String.Empty;
  64. protected bool m_autoCreateClientStack = true;
  65. /// <value>
  66. /// The file used to load and save prim backup xml if no filename has been specified
  67. /// </value>
  68. protected const string DEFAULT_PRIM_BACKUP_FILENAME = "prim-backup.xml";
  69. public ConfigSettings ConfigurationSettings
  70. {
  71. get { return m_configSettings; }
  72. set { m_configSettings = value; }
  73. }
  74. protected ConfigSettings m_configSettings;
  75. protected ConfigurationLoader m_configLoader;
  76. protected GridInfoService m_gridInfoService;
  77. public ConsoleCommand CreateAccount = null;
  78. protected List<IApplicationPlugin> m_plugins = new List<IApplicationPlugin>();
  79. /// <value>
  80. /// The config information passed into the OpenSimulator region server.
  81. /// </value>
  82. public OpenSimConfigSource ConfigSource
  83. {
  84. get { return m_config; }
  85. set { m_config = value; }
  86. }
  87. protected OpenSimConfigSource m_config;
  88. public List<IClientNetworkServer> ClientServers
  89. {
  90. get { return m_clientServers; }
  91. }
  92. protected List<IClientNetworkServer> m_clientServers = new List<IClientNetworkServer>();
  93. public uint HttpServerPort
  94. {
  95. get { return m_httpServerPort; }
  96. }
  97. public ModuleLoader ModuleLoader
  98. {
  99. get { return m_moduleLoader; }
  100. set { m_moduleLoader = value; }
  101. }
  102. protected ModuleLoader m_moduleLoader;
  103. protected IRegistryCore m_applicationRegistry = new RegistryCore();
  104. public IRegistryCore ApplicationRegistry
  105. {
  106. get { return m_applicationRegistry; }
  107. }
  108. /// <summary>
  109. /// Constructor.
  110. /// </summary>
  111. /// <param name="configSource"></param>
  112. public OpenSimBase(IConfigSource configSource) : base()
  113. {
  114. LoadConfigSettings(configSource);
  115. }
  116. protected virtual void LoadConfigSettings(IConfigSource configSource)
  117. {
  118. m_configLoader = new ConfigurationLoader();
  119. m_config = m_configLoader.LoadConfigSettings(configSource, out m_configSettings, out m_networkServersInfo);
  120. ReadExtraConfigSettings();
  121. }
  122. protected virtual void ReadExtraConfigSettings()
  123. {
  124. IConfig networkConfig = m_config.Source.Configs["Network"];
  125. if (networkConfig != null)
  126. {
  127. proxyUrl = networkConfig.GetString("proxy_url", "");
  128. proxyOffset = Int32.Parse(networkConfig.GetString("proxy_offset", "0"));
  129. }
  130. }
  131. protected virtual void LoadPlugins()
  132. {
  133. using (PluginLoader<IApplicationPlugin> loader = new PluginLoader<IApplicationPlugin>(new ApplicationPluginInitialiser(this)))
  134. {
  135. loader.Load("/OpenSim/Startup");
  136. m_plugins = loader.Plugins;
  137. }
  138. }
  139. protected override List<string> GetHelpTopics()
  140. {
  141. List<string> topics = base.GetHelpTopics();
  142. Scene s = SceneManager.CurrentOrFirstScene;
  143. if (s != null && s.GetCommanders() != null)
  144. topics.AddRange(s.GetCommanders().Keys);
  145. return topics;
  146. }
  147. /// <summary>
  148. /// Performs startup specific to the region server, including initialization of the scene
  149. /// such as loading configuration from disk.
  150. /// </summary>
  151. protected override void StartupSpecific()
  152. {
  153. IConfig startupConfig = m_config.Source.Configs["Startup"];
  154. if (startupConfig != null)
  155. {
  156. string pidFile = startupConfig.GetString("PIDFile", String.Empty);
  157. if (pidFile != String.Empty)
  158. CreatePIDFile(pidFile);
  159. userStatsURI = startupConfig.GetString("Stats_URI", String.Empty);
  160. }
  161. base.StartupSpecific();
  162. m_stats = StatsManager.StartCollectingSimExtraStats();
  163. // Create a ModuleLoader instance
  164. m_moduleLoader = new ModuleLoader(m_config.Source);
  165. LoadPlugins();
  166. foreach (IApplicationPlugin plugin in m_plugins)
  167. {
  168. plugin.PostInitialise();
  169. }
  170. AddPluginCommands();
  171. }
  172. protected virtual void AddPluginCommands()
  173. {
  174. // If console exists add plugin commands.
  175. if (m_console != null)
  176. {
  177. List<string> topics = GetHelpTopics();
  178. foreach (string topic in topics)
  179. {
  180. m_console.Commands.AddCommand("plugin", false, "help " + topic,
  181. "help " + topic,
  182. "Get help on plugin command '" + topic + "'",
  183. HandleCommanderHelp);
  184. m_console.Commands.AddCommand("plugin", false, topic,
  185. topic,
  186. "Execute subcommand for plugin '" + topic + "'",
  187. null);
  188. ICommander commander = null;
  189. Scene s = SceneManager.CurrentOrFirstScene;
  190. if (s != null && s.GetCommanders() != null)
  191. {
  192. if (s.GetCommanders().ContainsKey(topic))
  193. commander = s.GetCommanders()[topic];
  194. }
  195. if (commander == null)
  196. continue;
  197. foreach (string command in commander.Commands.Keys)
  198. {
  199. m_console.Commands.AddCommand(topic, false,
  200. topic + " " + command,
  201. topic + " " + commander.Commands[command].ShortHelp(),
  202. String.Empty, HandleCommanderCommand);
  203. }
  204. }
  205. }
  206. }
  207. private void HandleCommanderCommand(string module, string[] cmd)
  208. {
  209. m_sceneManager.SendCommandToPluginModules(cmd);
  210. }
  211. private void HandleCommanderHelp(string module, string[] cmd)
  212. {
  213. // Only safe for the interactive console, since it won't
  214. // let us come here unless both scene and commander exist
  215. //
  216. ICommander moduleCommander = SceneManager.CurrentOrFirstScene.GetCommander(cmd[1]);
  217. if (moduleCommander != null)
  218. m_console.Output(moduleCommander.Help);
  219. }
  220. protected override void Initialize()
  221. {
  222. // Called from base.StartUp()
  223. m_httpServerPort = m_networkServersInfo.HttpListenerPort;
  224. m_sceneManager.OnRestartSim += handleRestartRegion;
  225. }
  226. /// <summary>
  227. /// Execute the region creation process. This includes setting up scene infrastructure.
  228. /// </summary>
  229. /// <param name="regionInfo"></param>
  230. /// <param name="portadd_flag"></param>
  231. /// <returns></returns>
  232. public IClientNetworkServer CreateRegion(RegionInfo regionInfo, bool portadd_flag, out IScene scene)
  233. {
  234. return CreateRegion(regionInfo, portadd_flag, false, out scene);
  235. }
  236. /// <summary>
  237. /// Execute the region creation process. This includes setting up scene infrastructure.
  238. /// </summary>
  239. /// <param name="regionInfo"></param>
  240. /// <returns></returns>
  241. public IClientNetworkServer CreateRegion(RegionInfo regionInfo, out IScene scene)
  242. {
  243. return CreateRegion(regionInfo, false, true, out scene);
  244. }
  245. /// <summary>
  246. /// Execute the region creation process. This includes setting up scene infrastructure.
  247. /// </summary>
  248. /// <param name="regionInfo"></param>
  249. /// <param name="portadd_flag"></param>
  250. /// <param name="do_post_init"></param>
  251. /// <returns></returns>
  252. public IClientNetworkServer CreateRegion(RegionInfo regionInfo, bool portadd_flag, bool do_post_init, out IScene mscene)
  253. {
  254. int port = regionInfo.InternalEndPoint.Port;
  255. // set initial RegionID to originRegionID in RegionInfo. (it needs for loding prims)
  256. // Commented this out because otherwise regions can't register with
  257. // the grid as there is already another region with the same UUID
  258. // at those coordinates. This is required for the load balancer to work.
  259. // --Mike, 2009.02.25
  260. //regionInfo.originRegionID = regionInfo.RegionID;
  261. // set initial ServerURI
  262. regionInfo.ServerURI = "http://" + regionInfo.ExternalHostName + ":" + regionInfo.InternalEndPoint.Port;
  263. regionInfo.HttpPort = m_httpServerPort;
  264. regionInfo.osSecret = m_osSecret;
  265. if ((proxyUrl.Length > 0) && (portadd_flag))
  266. {
  267. // set proxy url to RegionInfo
  268. regionInfo.proxyUrl = proxyUrl;
  269. regionInfo.ProxyOffset = proxyOffset;
  270. Util.XmlRpcCommand(proxyUrl, "AddPort", port, port + proxyOffset, regionInfo.ExternalHostName);
  271. }
  272. IClientNetworkServer clientServer;
  273. Scene scene = SetupScene(regionInfo, proxyOffset, m_config.Source, out clientServer);
  274. m_log.Info("[MODULES]: Loading Region's modules (old style)");
  275. List<IRegionModule> modules = m_moduleLoader.PickupModules(scene, ".");
  276. // This needs to be ahead of the script engine load, so the
  277. // script module can pick up events exposed by a module
  278. m_moduleLoader.InitialiseSharedModules(scene);
  279. // Use this in the future, the line above will be deprecated soon
  280. m_log.Info("[MODULES]: Loading Region's modules (new style)");
  281. IRegionModulesController controller;
  282. if (ApplicationRegistry.TryGet(out controller))
  283. {
  284. controller.AddRegionToModules(scene);
  285. }
  286. else m_log.Error("[MODULES]: The new RegionModulesController is missing...");
  287. scene.SetModuleInterfaces();
  288. // Prims have to be loaded after module configuration since some modules may be invoked during the load
  289. scene.LoadPrimsFromStorage(regionInfo.originRegionID);
  290. // moved these here as the terrain texture has to be created after the modules are initialized
  291. // and has to happen before the region is registered with the grid.
  292. scene.CreateTerrainTexture(false);
  293. // TODO : Try setting resource for region xstats here on scene
  294. MainServer.Instance.AddStreamHandler(new Region.Framework.Scenes.RegionStatsHandler(regionInfo));
  295. try
  296. {
  297. scene.RegisterRegionWithGrid();
  298. }
  299. catch (Exception e)
  300. {
  301. m_log.ErrorFormat("[STARTUP]: Registration of region with grid failed, aborting startup - {0}", e.StackTrace);
  302. // Carrying on now causes a lot of confusion down the
  303. // line - we need to get the user's attention
  304. Environment.Exit(1);
  305. }
  306. // We need to do this after we've initialized the
  307. // scripting engines.
  308. scene.CreateScriptInstances();
  309. scene.loadAllLandObjectsFromStorage(regionInfo.originRegionID);
  310. scene.EventManager.TriggerParcelPrimCountUpdate();
  311. m_sceneManager.Add(scene);
  312. if (m_autoCreateClientStack)
  313. {
  314. m_clientServers.Add(clientServer);
  315. clientServer.Start();
  316. }
  317. if (do_post_init)
  318. {
  319. foreach (IRegionModule module in modules)
  320. {
  321. module.PostInitialise();
  322. }
  323. }
  324. scene.EventManager.OnShutdown += delegate() { ShutdownRegion(scene); };
  325. mscene = scene;
  326. scene.StartTimer();
  327. return clientServer;
  328. }
  329. private void ShutdownRegion(Scene scene)
  330. {
  331. m_log.DebugFormat("[SHUTDOWN]: Shutting down region {0}", scene.RegionInfo.RegionName);
  332. IRegionModulesController controller;
  333. if (ApplicationRegistry.TryGet<IRegionModulesController>(out controller))
  334. {
  335. controller.RemoveRegionFromModules(scene);
  336. }
  337. }
  338. public void RemoveRegion(Scene scene, bool cleanup)
  339. {
  340. // only need to check this if we are not at the
  341. // root level
  342. if ((m_sceneManager.CurrentScene != null) &&
  343. (m_sceneManager.CurrentScene.RegionInfo.RegionID == scene.RegionInfo.RegionID))
  344. {
  345. m_sceneManager.TrySetCurrentScene("..");
  346. }
  347. scene.DeleteAllSceneObjects();
  348. m_sceneManager.CloseScene(scene);
  349. ShutdownClientServer(scene.RegionInfo);
  350. if (!cleanup)
  351. return;
  352. if (!String.IsNullOrEmpty(scene.RegionInfo.RegionFile))
  353. {
  354. if (scene.RegionInfo.RegionFile.ToLower().EndsWith(".xml"))
  355. {
  356. File.Delete(scene.RegionInfo.RegionFile);
  357. m_log.InfoFormat("[OPENSIM]: deleting region file \"{0}\"", scene.RegionInfo.RegionFile);
  358. }
  359. if (scene.RegionInfo.RegionFile.ToLower().EndsWith(".ini"))
  360. {
  361. try
  362. {
  363. IniConfigSource source = new IniConfigSource(scene.RegionInfo.RegionFile);
  364. if (source.Configs[scene.RegionInfo.RegionName] != null)
  365. {
  366. source.Configs.Remove(scene.RegionInfo.RegionName);
  367. if (source.Configs.Count == 0)
  368. {
  369. File.Delete(scene.RegionInfo.RegionFile);
  370. }
  371. else
  372. {
  373. source.Save(scene.RegionInfo.RegionFile);
  374. }
  375. }
  376. }
  377. catch (Exception)
  378. {
  379. }
  380. }
  381. }
  382. }
  383. public void RemoveRegion(string name, bool cleanUp)
  384. {
  385. Scene target;
  386. if (m_sceneManager.TryGetScene(name, out target))
  387. RemoveRegion(target, cleanUp);
  388. }
  389. /// <summary>
  390. /// Remove a region from the simulator without deleting it permanently.
  391. /// </summary>
  392. /// <param name="scene"></param>
  393. /// <returns></returns>
  394. public void CloseRegion(Scene scene)
  395. {
  396. // only need to check this if we are not at the
  397. // root level
  398. if ((m_sceneManager.CurrentScene != null) &&
  399. (m_sceneManager.CurrentScene.RegionInfo.RegionID == scene.RegionInfo.RegionID))
  400. {
  401. m_sceneManager.TrySetCurrentScene("..");
  402. }
  403. m_sceneManager.CloseScene(scene);
  404. ShutdownClientServer(scene.RegionInfo);
  405. }
  406. /// <summary>
  407. /// Remove a region from the simulator without deleting it permanently.
  408. /// </summary>
  409. /// <param name="name"></param>
  410. /// <returns></returns>
  411. public void CloseRegion(string name)
  412. {
  413. Scene target;
  414. if (m_sceneManager.TryGetScene(name, out target))
  415. CloseRegion(target);
  416. }
  417. /// <summary>
  418. /// Create a scene and its initial base structures.
  419. /// </summary>
  420. /// <param name="regionInfo"></param>
  421. /// <param name="clientServer"> </param>
  422. /// <returns></returns>
  423. protected Scene SetupScene(RegionInfo regionInfo, out IClientNetworkServer clientServer)
  424. {
  425. return SetupScene(regionInfo, 0, null, out clientServer);
  426. }
  427. /// <summary>
  428. /// Create a scene and its initial base structures.
  429. /// </summary>
  430. /// <param name="regionInfo"></param>
  431. /// <param name="proxyOffset"></param>
  432. /// <param name="configSource"></param>
  433. /// <param name="clientServer"> </param>
  434. /// <returns></returns>
  435. protected Scene SetupScene(
  436. RegionInfo regionInfo, int proxyOffset, IConfigSource configSource, out IClientNetworkServer clientServer)
  437. {
  438. AgentCircuitManager circuitManager = new AgentCircuitManager();
  439. IPAddress listenIP = regionInfo.InternalEndPoint.Address;
  440. //if (!IPAddress.TryParse(regionInfo.InternalEndPoint, out listenIP))
  441. // listenIP = IPAddress.Parse("0.0.0.0");
  442. uint port = (uint) regionInfo.InternalEndPoint.Port;
  443. if (m_autoCreateClientStack)
  444. {
  445. clientServer
  446. = m_clientStackManager.CreateServer(
  447. listenIP, ref port, proxyOffset, regionInfo.m_allow_alternate_ports, configSource,
  448. circuitManager);
  449. }
  450. else
  451. {
  452. clientServer = null;
  453. }
  454. regionInfo.InternalEndPoint.Port = (int) port;
  455. Scene scene = CreateScene(regionInfo, m_storageManager, circuitManager);
  456. if (m_autoCreateClientStack)
  457. {
  458. clientServer.AddScene(scene);
  459. }
  460. scene.LoadWorldMap();
  461. scene.PhysicsScene = GetPhysicsScene(scene.RegionInfo.RegionName);
  462. scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised());
  463. scene.PhysicsScene.SetWaterLevel((float) regionInfo.RegionSettings.WaterHeight);
  464. // TODO: Remove this cruft once MasterAvatar is fully deprecated
  465. //Master Avatar Setup
  466. UserProfileData masterAvatar;
  467. if (scene.RegionInfo.MasterAvatarAssignedUUID == UUID.Zero)
  468. {
  469. masterAvatar =
  470. m_commsManager.UserService.SetupMasterUser(scene.RegionInfo.MasterAvatarFirstName,
  471. scene.RegionInfo.MasterAvatarLastName,
  472. scene.RegionInfo.MasterAvatarSandboxPassword);
  473. }
  474. else
  475. {
  476. masterAvatar = m_commsManager.UserService.SetupMasterUser(scene.RegionInfo.MasterAvatarAssignedUUID);
  477. scene.RegionInfo.MasterAvatarFirstName = masterAvatar.FirstName;
  478. scene.RegionInfo.MasterAvatarLastName = masterAvatar.SurName;
  479. }
  480. if (masterAvatar == null)
  481. {
  482. m_log.Info("[PARCEL]: No master avatar found, using null.");
  483. scene.RegionInfo.MasterAvatarAssignedUUID = UUID.Zero;
  484. }
  485. else
  486. {
  487. m_log.InfoFormat("[PARCEL]: Found master avatar {0} {1} [" + masterAvatar.ID.ToString() + "]",
  488. scene.RegionInfo.MasterAvatarFirstName, scene.RegionInfo.MasterAvatarLastName);
  489. scene.RegionInfo.MasterAvatarAssignedUUID = masterAvatar.ID;
  490. }
  491. return scene;
  492. }
  493. protected override StorageManager CreateStorageManager()
  494. {
  495. return
  496. CreateStorageManager(m_configSettings.StorageConnectionString, m_configSettings.EstateConnectionString);
  497. }
  498. protected StorageManager CreateStorageManager(string connectionstring, string estateconnectionstring)
  499. {
  500. return new StorageManager(m_configSettings.StorageDll, connectionstring, estateconnectionstring);
  501. }
  502. protected override ClientStackManager CreateClientStackManager()
  503. {
  504. return new ClientStackManager(m_configSettings.ClientstackDll);
  505. }
  506. protected override Scene CreateScene(RegionInfo regionInfo, StorageManager storageManager,
  507. AgentCircuitManager circuitManager)
  508. {
  509. bool hgrid = ConfigSource.Source.Configs["Startup"].GetBoolean("hypergrid", false);
  510. if (hgrid)
  511. return HGCommands.CreateScene(regionInfo, circuitManager, m_commsManager,
  512. storageManager, m_moduleLoader, m_configSettings, m_config, m_version);
  513. SceneCommunicationService sceneGridService = new SceneCommunicationService(m_commsManager);
  514. return new Scene(
  515. regionInfo, circuitManager, m_commsManager, sceneGridService,
  516. storageManager, m_moduleLoader, false, m_configSettings.PhysicalPrim,
  517. m_configSettings.See_into_region_from_neighbor, m_config.Source, m_version);
  518. }
  519. protected void ShutdownClientServer(RegionInfo whichRegion)
  520. {
  521. // Close and remove the clientserver for a region
  522. bool foundClientServer = false;
  523. int clientServerElement = 0;
  524. Location location = new Location(whichRegion.RegionHandle);
  525. for (int i = 0; i < m_clientServers.Count; i++)
  526. {
  527. if (m_clientServers[i].HandlesRegion(location))
  528. {
  529. clientServerElement = i;
  530. foundClientServer = true;
  531. break;
  532. }
  533. }
  534. if (foundClientServer)
  535. {
  536. m_clientServers[clientServerElement].NetworkStop();
  537. m_clientServers.RemoveAt(clientServerElement);
  538. }
  539. }
  540. public void handleRestartRegion(RegionInfo whichRegion)
  541. {
  542. m_log.Info("[OPENSIM]: Got restart signal from SceneManager");
  543. ShutdownClientServer(whichRegion);
  544. IScene scene;
  545. CreateRegion(whichRegion, true, out scene);
  546. }
  547. # region Setup methods
  548. protected override PhysicsScene GetPhysicsScene(string osSceneIdentifier)
  549. {
  550. return GetPhysicsScene(
  551. m_configSettings.PhysicsEngine, m_configSettings.MeshEngineName, m_config.Source, osSceneIdentifier);
  552. }
  553. /// <summary>
  554. /// Handler to supply the current status of this sim
  555. /// </summary>
  556. /// Currently this is always OK if the simulator is still listening for connections on its HTTP service
  557. public class SimStatusHandler : IStreamedRequestHandler
  558. {
  559. public byte[] Handle(string path, Stream request,
  560. OSHttpRequest httpRequest, OSHttpResponse httpResponse)
  561. {
  562. return Util.UTF8.GetBytes("OK");
  563. }
  564. public string ContentType
  565. {
  566. get { return "text/plain"; }
  567. }
  568. public string HttpMethod
  569. {
  570. get { return "GET"; }
  571. }
  572. public string Path
  573. {
  574. get { return "/simstatus/"; }
  575. }
  576. }
  577. /// <summary>
  578. /// Handler to supply the current extended status of this sim
  579. /// Sends the statistical data in a json serialization
  580. /// </summary>
  581. public class XSimStatusHandler : IStreamedRequestHandler
  582. {
  583. OpenSimBase m_opensim;
  584. string osXStatsURI = String.Empty;
  585. public XSimStatusHandler(OpenSimBase sim)
  586. {
  587. m_opensim = sim;
  588. osXStatsURI = Util.SHA1Hash(sim.osSecret);
  589. }
  590. public byte[] Handle(string path, Stream request,
  591. OSHttpRequest httpRequest, OSHttpResponse httpResponse)
  592. {
  593. return Util.UTF8.GetBytes(m_opensim.StatReport(httpRequest));
  594. }
  595. public string ContentType
  596. {
  597. get { return "text/plain"; }
  598. }
  599. public string HttpMethod
  600. {
  601. get { return "GET"; }
  602. }
  603. public string Path
  604. {
  605. // This is for the OpenSimulator instance and is the osSecret hashed
  606. get { return "/" + osXStatsURI + "/"; }
  607. }
  608. }
  609. /// <summary>
  610. /// Handler to supply the current extended status of this sim to a user configured URI
  611. /// Sends the statistical data in a json serialization
  612. /// If the request contains a key, "callback" the response will be wrappend in the
  613. /// associated value for jsonp used with ajax/javascript
  614. /// </summary>
  615. public class UXSimStatusHandler : IStreamedRequestHandler
  616. {
  617. OpenSimBase m_opensim;
  618. string osUXStatsURI = String.Empty;
  619. public UXSimStatusHandler(OpenSimBase sim)
  620. {
  621. m_opensim = sim;
  622. osUXStatsURI = sim.userStatsURI;
  623. }
  624. public byte[] Handle(string path, Stream request,
  625. OSHttpRequest httpRequest, OSHttpResponse httpResponse)
  626. {
  627. return Util.UTF8.GetBytes(m_opensim.StatReport(httpRequest));
  628. }
  629. public string ContentType
  630. {
  631. get { return "text/plain"; }
  632. }
  633. public string HttpMethod
  634. {
  635. get { return "GET"; }
  636. }
  637. public string Path
  638. {
  639. // This is for the OpenSimulator instance and is the user provided URI
  640. get { return "/" + osUXStatsURI + "/"; }
  641. }
  642. }
  643. #endregion
  644. /// <summary>
  645. /// Performs any last-minute sanity checking and shuts down the region server
  646. /// </summary>
  647. public override void ShutdownSpecific()
  648. {
  649. if (proxyUrl.Length > 0)
  650. {
  651. Util.XmlRpcCommand(proxyUrl, "Stop");
  652. }
  653. m_log.Info("[SHUTDOWN]: Closing all threads");
  654. m_log.Info("[SHUTDOWN]: Killing listener thread");
  655. m_log.Info("[SHUTDOWN]: Killing clients");
  656. // TODO: implement this
  657. m_log.Info("[SHUTDOWN]: Closing console and terminating");
  658. try
  659. {
  660. m_sceneManager.Close();
  661. }
  662. catch (Exception e)
  663. {
  664. m_log.ErrorFormat("[SHUTDOWN]: Ignoring failure during shutdown - {0}", e);
  665. }
  666. }
  667. /// <summary>
  668. /// Get the start time and up time of Region server
  669. /// </summary>
  670. /// <param name="starttime">The first out parameter describing when the Region server started</param>
  671. /// <param name="uptime">The second out parameter describing how long the Region server has run</param>
  672. public void GetRunTime(out string starttime, out string uptime)
  673. {
  674. starttime = m_startuptime.ToString();
  675. uptime = (DateTime.Now - m_startuptime).ToString();
  676. }
  677. /// <summary>
  678. /// Get the number of the avatars in the Region server
  679. /// </summary>
  680. /// <param name="usernum">The first out parameter describing the number of all the avatars in the Region server</param>
  681. public void GetAvatarNumber(out int usernum)
  682. {
  683. usernum = m_sceneManager.GetCurrentSceneAvatars().Count;
  684. }
  685. /// <summary>
  686. /// Get the number of regions
  687. /// </summary>
  688. /// <param name="regionnum">The first out parameter describing the number of regions</param>
  689. public void GetRegionNumber(out int regionnum)
  690. {
  691. regionnum = m_sceneManager.Scenes.Count;
  692. }
  693. }
  694. public class OpenSimConfigSource
  695. {
  696. public IConfigSource Source;
  697. public void Save(string path)
  698. {
  699. if (Source is IniConfigSource)
  700. {
  701. IniConfigSource iniCon = (IniConfigSource) Source;
  702. iniCon.Save(path);
  703. }
  704. else if (Source is XmlConfigSource)
  705. {
  706. XmlConfigSource xmlCon = (XmlConfigSource) Source;
  707. xmlCon.Save(path);
  708. }
  709. }
  710. }
  711. }