OpenSimBase.cs 29 KB

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