1
0

OpenSimBase.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  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 OpenSim 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 opensim 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 OpenSim 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. // moved these here as the terrain texture has to be created after the modules are initialized
  321. // and has to happen before the region is registered with the grid.
  322. scene.CreateTerrainTexture(false);
  323. // Prims have to be loaded after module configuration since some modules may be invoked during the load
  324. scene.LoadPrimsFromStorage(regionInfo.originRegionID);
  325. // TODO : Try setting resource for region xstats here on scene
  326. scene.CommsManager.HttpServer.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. /// Create a scene and its initial base structures.
  422. /// </summary>
  423. /// <param name="regionInfo"></param>
  424. /// <param name="clientServer"> </param>
  425. /// <returns></returns>
  426. protected Scene SetupScene(RegionInfo regionInfo, out IClientNetworkServer clientServer)
  427. {
  428. return SetupScene(regionInfo, 0, null, out clientServer);
  429. }
  430. /// <summary>
  431. /// Create a scene and its initial base structures.
  432. /// </summary>
  433. /// <param name="regionInfo"></param>
  434. /// <param name="proxyOffset"></param>
  435. /// <param name="configSource"></param>
  436. /// <param name="clientServer"> </param>
  437. /// <returns></returns>
  438. protected Scene SetupScene(
  439. RegionInfo regionInfo, int proxyOffset, IConfigSource configSource, out IClientNetworkServer clientServer)
  440. {
  441. AgentCircuitManager circuitManager = new AgentCircuitManager();
  442. IPAddress listenIP = regionInfo.InternalEndPoint.Address;
  443. //if (!IPAddress.TryParse(regionInfo.InternalEndPoint, out listenIP))
  444. // listenIP = IPAddress.Parse("0.0.0.0");
  445. uint port = (uint) regionInfo.InternalEndPoint.Port;
  446. if (m_autoCreateClientStack)
  447. {
  448. clientServer
  449. = m_clientStackManager.CreateServer(
  450. listenIP, ref port, proxyOffset, regionInfo.m_allow_alternate_ports, configSource,
  451. circuitManager);
  452. }
  453. else
  454. {
  455. clientServer = null;
  456. }
  457. regionInfo.InternalEndPoint.Port = (int) port;
  458. Scene scene = CreateScene(regionInfo, m_storageManager, circuitManager);
  459. if (m_autoCreateClientStack)
  460. {
  461. clientServer.AddScene(scene);
  462. }
  463. scene.LoadWorldMap();
  464. scene.PhysicsScene = GetPhysicsScene(scene.RegionInfo.RegionName);
  465. scene.PhysicsScene.SetTerrain(scene.Heightmap.GetFloatsSerialised());
  466. scene.PhysicsScene.SetWaterLevel((float) regionInfo.RegionSettings.WaterHeight);
  467. // TODO: Remove this cruft once MasterAvatar is fully deprecated
  468. //Master Avatar Setup
  469. UserProfileData masterAvatar;
  470. if (scene.RegionInfo.MasterAvatarAssignedUUID == UUID.Zero)
  471. {
  472. masterAvatar =
  473. m_commsManager.UserService.SetupMasterUser(scene.RegionInfo.MasterAvatarFirstName,
  474. scene.RegionInfo.MasterAvatarLastName,
  475. scene.RegionInfo.MasterAvatarSandboxPassword);
  476. }
  477. else
  478. {
  479. masterAvatar = m_commsManager.UserService.SetupMasterUser(scene.RegionInfo.MasterAvatarAssignedUUID);
  480. scene.RegionInfo.MasterAvatarFirstName = masterAvatar.FirstName;
  481. scene.RegionInfo.MasterAvatarLastName = masterAvatar.SurName;
  482. }
  483. if (masterAvatar == null)
  484. {
  485. m_log.Info("[PARCEL]: No master avatar found, using null.");
  486. scene.RegionInfo.MasterAvatarAssignedUUID = UUID.Zero;
  487. }
  488. else
  489. {
  490. m_log.InfoFormat("[PARCEL]: Found master avatar {0} {1} [" + masterAvatar.ID.ToString() + "]",
  491. scene.RegionInfo.MasterAvatarFirstName, scene.RegionInfo.MasterAvatarLastName);
  492. scene.RegionInfo.MasterAvatarAssignedUUID = masterAvatar.ID;
  493. }
  494. return scene;
  495. }
  496. protected override StorageManager CreateStorageManager()
  497. {
  498. return
  499. CreateStorageManager(m_configSettings.StorageConnectionString, m_configSettings.EstateConnectionString);
  500. }
  501. protected StorageManager CreateStorageManager(string connectionstring, string estateconnectionstring)
  502. {
  503. return new StorageManager(m_configSettings.StorageDll, connectionstring, estateconnectionstring);
  504. }
  505. protected override ClientStackManager CreateClientStackManager()
  506. {
  507. return new ClientStackManager(m_configSettings.ClientstackDll);
  508. }
  509. protected override Scene CreateScene(RegionInfo regionInfo, StorageManager storageManager,
  510. AgentCircuitManager circuitManager)
  511. {
  512. bool hgrid = ConfigSource.Source.Configs["Startup"].GetBoolean("hypergrid", false);
  513. if (hgrid)
  514. return HGCommands.CreateScene(regionInfo, circuitManager, m_commsManager,
  515. storageManager, m_moduleLoader, m_configSettings, m_config, m_version);
  516. SceneCommunicationService sceneGridService = new SceneCommunicationService(m_commsManager);
  517. return new Scene(
  518. regionInfo, circuitManager, m_commsManager, sceneGridService,
  519. storageManager, m_moduleLoader, false, m_configSettings.PhysicalPrim,
  520. m_configSettings.See_into_region_from_neighbor, m_config.Source, m_version);
  521. }
  522. public void handleRestartRegion(RegionInfo whichRegion)
  523. {
  524. m_log.Info("[OPENSIM]: Got restart signal from SceneManager");
  525. // Shutting down the client server
  526. bool foundClientServer = false;
  527. int clientServerElement = 0;
  528. Location location = new Location(whichRegion.RegionHandle);
  529. for (int i = 0; i < m_clientServers.Count; i++)
  530. {
  531. if (m_clientServers[i].HandlesRegion(location))
  532. {
  533. clientServerElement = i;
  534. foundClientServer = true;
  535. break;
  536. }
  537. }
  538. if (foundClientServer)
  539. {
  540. m_clientServers[clientServerElement].Server.Close();
  541. m_clientServers.RemoveAt(clientServerElement);
  542. }
  543. IScene scene;
  544. CreateRegion(whichRegion, true, out scene);
  545. }
  546. # region Setup methods
  547. protected override PhysicsScene GetPhysicsScene(string osSceneIdentifier)
  548. {
  549. return GetPhysicsScene(
  550. m_configSettings.PhysicsEngine, m_configSettings.MeshEngineName, m_config.Source, osSceneIdentifier);
  551. }
  552. /// <summary>
  553. /// Handler to supply the current status of this sim
  554. /// </summary>
  555. /// Currently this is always OK if the simulator is still listening for connections on its HTTP service
  556. public class SimStatusHandler : IStreamedRequestHandler
  557. {
  558. public byte[] Handle(string path, Stream request,
  559. OSHttpRequest httpRequest, OSHttpResponse httpResponse)
  560. {
  561. return Encoding.UTF8.GetBytes("OK");
  562. }
  563. public string ContentType
  564. {
  565. get { return "text/plain"; }
  566. }
  567. public string HttpMethod
  568. {
  569. get { return "GET"; }
  570. }
  571. public string Path
  572. {
  573. get { return "/simstatus/"; }
  574. }
  575. }
  576. /// <summary>
  577. /// Handler to supply the current extended status of this sim
  578. /// Sends the statistical data in a json serialization
  579. /// </summary>
  580. public class XSimStatusHandler : IStreamedRequestHandler
  581. {
  582. OpenSimBase m_opensim;
  583. string osXStatsURI = String.Empty;
  584. public XSimStatusHandler(OpenSimBase sim)
  585. {
  586. m_opensim = sim;
  587. osXStatsURI = Util.SHA1Hash(sim.osSecret);
  588. }
  589. public byte[] Handle(string path, Stream request,
  590. OSHttpRequest httpRequest, OSHttpResponse httpResponse)
  591. {
  592. return Encoding.UTF8.GetBytes(m_opensim.StatReport(httpRequest));
  593. }
  594. public string ContentType
  595. {
  596. get { return "text/plain"; }
  597. }
  598. public string HttpMethod
  599. {
  600. get { return "GET"; }
  601. }
  602. public string Path
  603. {
  604. // This is for the OpenSim instance and is the osSecret hashed
  605. get { return "/" + osXStatsURI + "/"; }
  606. }
  607. }
  608. /// <summary>
  609. /// Handler to supply the current extended status of this sim to a user configured URI
  610. /// Sends the statistical data in a json serialization
  611. /// If the request contains a key, "callback" the response will be wrappend in the
  612. /// associated value for jsonp used with ajax/javascript
  613. /// </summary>
  614. public class UXSimStatusHandler : IStreamedRequestHandler
  615. {
  616. OpenSimBase m_opensim;
  617. string osUXStatsURI = String.Empty;
  618. public UXSimStatusHandler(OpenSimBase sim)
  619. {
  620. m_opensim = sim;
  621. osUXStatsURI = sim.userStatsURI;
  622. }
  623. public byte[] Handle(string path, Stream request,
  624. OSHttpRequest httpRequest, OSHttpResponse httpResponse)
  625. {
  626. return Encoding.UTF8.GetBytes(m_opensim.StatReport(httpRequest));
  627. }
  628. public string ContentType
  629. {
  630. get { return "text/plain"; }
  631. }
  632. public string HttpMethod
  633. {
  634. get { return "GET"; }
  635. }
  636. public string Path
  637. {
  638. // This is for the OpenSim instance and is the user provided URI
  639. get { return "/" + osUXStatsURI + "/"; }
  640. }
  641. }
  642. #endregion
  643. /// <summary>
  644. /// Performs any last-minute sanity checking and shuts down the region server
  645. /// </summary>
  646. public override void ShutdownSpecific()
  647. {
  648. if (proxyUrl.Length > 0)
  649. {
  650. Util.XmlRpcCommand(proxyUrl, "Stop");
  651. }
  652. m_log.Info("[SHUTDOWN]: Closing all threads");
  653. m_log.Info("[SHUTDOWN]: Killing listener thread");
  654. m_log.Info("[SHUTDOWN]: Killing clients");
  655. // TODO: implement this
  656. m_log.Info("[SHUTDOWN]: Closing console and terminating");
  657. try
  658. {
  659. m_sceneManager.Close();
  660. }
  661. catch (Exception e)
  662. {
  663. m_log.ErrorFormat("[SHUTDOWN]: Ignoring failure during shutdown - {0}", e);
  664. }
  665. }
  666. /// <summary>
  667. /// Get the start time and up time of Region server
  668. /// </summary>
  669. /// <param name="starttime">The first out parameter describing when the Region server started</param>
  670. /// <param name="uptime">The second out parameter describing how long the Region server has run</param>
  671. public void GetRunTime(out string starttime, out string uptime)
  672. {
  673. starttime = m_startuptime.ToString();
  674. uptime = (DateTime.Now - m_startuptime).ToString();
  675. }
  676. /// <summary>
  677. /// Get the number of the avatars in the Region server
  678. /// </summary>
  679. /// <param name="usernum">The first out parameter describing the number of all the avatars in the Region server</param>
  680. public void GetAvatarNumber(out int usernum)
  681. {
  682. usernum = m_sceneManager.GetCurrentSceneAvatars().Count;
  683. }
  684. /// <summary>
  685. /// Get the number of regions
  686. /// </summary>
  687. /// <param name="regionnum">The first out parameter describing the number of regions</param>
  688. public void GetRegionNumber(out int regionnum)
  689. {
  690. regionnum = m_sceneManager.Scenes.Count;
  691. }
  692. }
  693. public class OpenSimConfigSource
  694. {
  695. public IConfigSource Source;
  696. public void Save(string path)
  697. {
  698. if (Source is IniConfigSource)
  699. {
  700. IniConfigSource iniCon = (IniConfigSource) Source;
  701. iniCon.Save(path);
  702. }
  703. else if (Source is XmlConfigSource)
  704. {
  705. XmlConfigSource xmlCon = (XmlConfigSource) Source;
  706. xmlCon.Save(path);
  707. }
  708. }
  709. }
  710. }