OpenSimBase.cs 32 KB

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