1
0

OpenSimBase.cs 31 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 OpenSim 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.Reflection;
  31. using System.Text;
  32. using log4net;
  33. using Nini.Config;
  34. using OpenSim.Framework;
  35. using OpenSim.Framework.Communications;
  36. using OpenSim.Framework.Communications.Cache;
  37. using OpenSim.Framework.Console;
  38. using OpenSim.Framework.Servers;
  39. using OpenSim.Framework.Statistics;
  40. using OpenSim.Region.ClientStack;
  41. using OpenSim.Region.Communications.Local;
  42. using OpenSim.Region.Communications.OGS1;
  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 OpenSim 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/AssetServerClient";
  59. protected string proxyUrl;
  60. protected int proxyOffset = 0;
  61. /// <summary>
  62. /// The file used to load and save prim backup xml if no filename has been specified
  63. /// </summary>
  64. protected const string DEFAULT_PRIM_BACKUP_FILENAME = "prim-backup.xml";
  65. /// <summary>
  66. /// The file used to load and save an opensim archive if no filename has been specified
  67. /// </summary>
  68. protected const string DEFAULT_OAR_BACKUP_FILENAME = "scene_oar.tar.gz";
  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 OpenSim 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 new BaseHttpServer HttpServer
  94. {
  95. get { return m_httpServer; }
  96. }
  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. /// <summary>
  108. /// Constructor.
  109. /// </summary>
  110. /// <param name="configSource"></param>
  111. public OpenSimBase(IConfigSource configSource) : base()
  112. {
  113. LoadConfigSettings(configSource);
  114. }
  115. protected virtual void LoadConfigSettings(IConfigSource configSource)
  116. {
  117. m_configLoader = new ConfigurationLoader();
  118. m_config = m_configLoader.LoadConfigSettings(configSource, out m_configSettings, out m_networkServersInfo);
  119. ReadExtraConfigSettings();
  120. }
  121. protected virtual void ReadExtraConfigSettings()
  122. {
  123. IConfig networkConfig = m_config.Source.Configs["Network"];
  124. if (networkConfig != null)
  125. {
  126. proxyUrl = networkConfig.GetString("proxy_url", "");
  127. proxyOffset = Int32.Parse(networkConfig.GetString("proxy_offset", "0"));
  128. }
  129. }
  130. protected virtual void LoadPlugins()
  131. {
  132. PluginLoader<IApplicationPlugin> loader =
  133. new PluginLoader<IApplicationPlugin>(new ApplicationPluginInitialiser(this));
  134. loader.Load("/OpenSim/Startup");
  135. m_plugins = loader.Plugins;
  136. }
  137. protected override List<string> GetHelpTopics()
  138. {
  139. List<string> topics = base.GetHelpTopics();
  140. Scene s = SceneManager.CurrentOrFirstScene;
  141. if (s != null && s.GetCommanders() != null)
  142. topics.AddRange(s.GetCommanders().Keys);
  143. return topics;
  144. }
  145. /// <summary>
  146. /// Performs startup specific to the region server, including initialization of the scene
  147. /// such as loading configuration from disk.
  148. /// </summary>
  149. protected override void StartupSpecific()
  150. {
  151. base.StartupSpecific();
  152. m_stats = StatsManager.StartCollectingSimExtraStats();
  153. LibraryRootFolder libraryRootFolder = new LibraryRootFolder(m_configSettings.LibrariesXMLFile);
  154. // Standalone mode is determined by !startupConfig.GetBoolean("gridmode", false)
  155. if (m_configSettings.Standalone)
  156. {
  157. InitialiseStandaloneServices(libraryRootFolder);
  158. }
  159. else
  160. {
  161. // We are in grid mode
  162. InitialiseGridServices(libraryRootFolder);
  163. }
  164. // Create a ModuleLoader instance
  165. m_moduleLoader = new ModuleLoader(m_config.Source);
  166. LoadPlugins();
  167. // Only enable logins to the regions once we have completely finished starting up (apart from scripts)
  168. m_commsManager.GridService.RegionLoginsEnabled = true;
  169. List<string> topics = GetHelpTopics();
  170. foreach (string topic in topics)
  171. {
  172. m_console.Commands.AddCommand("plugin", false, "help " + topic,
  173. "help " + topic,
  174. "Get help on plugin command '" + topic + "'",
  175. HandleCommanderHelp);
  176. m_console.Commands.AddCommand("plugin", false, topic,
  177. topic,
  178. "Execute subcommand for plugin '" + topic + "'",
  179. null);
  180. ICommander commander = null;
  181. Scene s = SceneManager.CurrentOrFirstScene;
  182. if (s != null && s.GetCommanders() != null)
  183. {
  184. if (s.GetCommanders().ContainsKey(topic))
  185. commander = s.GetCommanders()[topic];
  186. }
  187. if (commander == null)
  188. continue;
  189. foreach (string command in commander.Commands.Keys)
  190. {
  191. m_console.Commands.AddCommand(topic, false,
  192. topic + " " + command,
  193. topic + " " + commander.Commands[command].ShortHelp(),
  194. String.Empty, HandleCommanderCommand);
  195. }
  196. }
  197. }
  198. private void HandleCommanderCommand(string module, string[] cmd)
  199. {
  200. m_sceneManager.SendCommandToPluginModules(cmd);
  201. }
  202. private void HandleCommanderHelp(string module, string[] cmd)
  203. {
  204. // Only safe for the interactive console, since it won't
  205. // let us come here unless both scene and commander exist
  206. //
  207. ICommander moduleCommander = SceneManager.CurrentOrFirstScene.GetCommander(cmd[1]);
  208. if (moduleCommander != null)
  209. m_console.Notice(moduleCommander.Help);
  210. }
  211. /// <summary>
  212. /// Initialises the backend services for standalone mode, and registers some http handlers
  213. /// </summary>
  214. /// <param name="libraryRootFolder"></param>
  215. protected virtual void InitialiseStandaloneServices(LibraryRootFolder libraryRootFolder)
  216. {
  217. LocalInventoryService inventoryService = new LocalInventoryService();
  218. inventoryService.AddPlugin(m_configSettings.StandaloneInventoryPlugin, m_configSettings.StandaloneInventorySource);
  219. LocalUserServices userService =
  220. new LocalUserServices(
  221. m_networkServersInfo.DefaultHomeLocX, m_networkServersInfo.DefaultHomeLocY, inventoryService);
  222. userService.AddPlugin(m_configSettings.StandaloneUserPlugin, m_configSettings.StandaloneUserSource);
  223. LocalBackEndServices backendService = new LocalBackEndServices();
  224. LocalLoginService loginService =
  225. new LocalLoginService(
  226. userService, m_configSettings.StandaloneWelcomeMessage, inventoryService, backendService, m_networkServersInfo,
  227. m_configSettings.StandaloneAuthenticate, libraryRootFolder);
  228. m_commsManager
  229. = new CommunicationsLocal(
  230. m_networkServersInfo, m_httpServer, m_assetCache, userService, userService,
  231. inventoryService, backendService, backendService, userService,
  232. libraryRootFolder, m_configSettings.DumpAssetsToFile);
  233. // set up XMLRPC handler for client's initial login request message
  234. m_httpServer.AddXmlRPCHandler("login_to_simulator", loginService.XmlRpcLoginMethod);
  235. // provides the web form login
  236. m_httpServer.AddHTTPHandler("login", loginService.ProcessHTMLLogin);
  237. // Provides the LLSD login
  238. m_httpServer.SetDefaultLLSDHandler(loginService.LLSDLoginMethod);
  239. // provide grid info
  240. // m_gridInfoService = new GridInfoService(m_config.Source.Configs["Startup"].GetString("inifile", Path.Combine(Util.configDir(), "OpenSim.ini")));
  241. m_gridInfoService = new GridInfoService(m_config.Source);
  242. m_httpServer.AddXmlRPCHandler("get_grid_info", m_gridInfoService.XmlRpcGridInfoMethod);
  243. m_httpServer.AddStreamHandler(new RestStreamHandler("GET", "/get_grid_info", m_gridInfoService.RestGetGridInfoMethod));
  244. }
  245. protected virtual void InitialiseGridServices(LibraryRootFolder libraryRootFolder)
  246. {
  247. m_commsManager
  248. = new CommunicationsOGS1(m_networkServersInfo, m_httpServer, m_assetCache, libraryRootFolder);
  249. m_httpServer.AddStreamHandler(new SimStatusHandler());
  250. }
  251. protected override void Initialize()
  252. {
  253. //
  254. // Called from base.StartUp()
  255. //
  256. m_httpServerPort = m_networkServersInfo.HttpListenerPort;
  257. InitialiseAssetCache();
  258. m_sceneManager.OnRestartSim += handleRestartRegion;
  259. }
  260. /// <summary>
  261. /// Initialises the asset cache. This supports legacy configuration values
  262. /// to ensure consistent operation, but values outside of that namespace
  263. /// are handled by the more generic resolution mechanism provided by
  264. /// the ResolveAssetServer virtual method. If extended resolution fails,
  265. /// then the normal default action is taken.
  266. /// Creation of the AssetCache is handled by ResolveAssetCache. This
  267. /// function accepts a reference to the instantiated AssetServer and
  268. /// returns an IAssetCache implementation, if possible. This is a virtual
  269. /// method.
  270. /// </summary>
  271. protected virtual void InitialiseAssetCache()
  272. {
  273. LegacyAssetServerClientPluginInitialiser linit = null;
  274. CryptoAssetServerClientPluginInitialiser cinit = null;
  275. AssetServerClientPluginInitialiser init = null;
  276. IAssetServer assetServer = null;
  277. string mode = m_configSettings.AssetStorage;
  278. if (mode == null | mode == String.Empty)
  279. mode = "default";
  280. // If "default" is specified, then the value is adjusted
  281. // according to whether or not the server is running in
  282. // standalone mode.
  283. if (mode.ToLower() == "default")
  284. {
  285. if (m_configSettings.Standalone == false)
  286. mode = "grid";
  287. else
  288. mode = "local";
  289. }
  290. switch (mode.ToLower())
  291. {
  292. // If grid is specified then the grid server is chose regardless
  293. // of whether the server is standalone.
  294. case "grid" :
  295. linit = new LegacyAssetServerClientPluginInitialiser(m_configSettings, m_networkServersInfo.AssetURL);
  296. assetServer = loadAssetServer("Grid", linit);
  297. break;
  298. // If cryptogrid is specified then the cryptogrid server is chose regardless
  299. // of whether the server is standalone.
  300. case "cryptogrid" :
  301. cinit = new CryptoAssetServerClientPluginInitialiser(m_configSettings, m_networkServersInfo.AssetURL,
  302. Environment.CurrentDirectory, true);
  303. assetServer = loadAssetServer("Crypto", cinit);
  304. break;
  305. // If cryptogrid_eou is specified then the cryptogrid_eou server is chose regardless
  306. // of whether the server is standalone.
  307. case "cryptogrid_eou" :
  308. cinit = new CryptoAssetServerClientPluginInitialiser(m_configSettings, m_networkServersInfo.AssetURL,
  309. Environment.CurrentDirectory, false);
  310. assetServer = loadAssetServer("Crypto", cinit);
  311. break;
  312. // If file is specified then the file server is chose regardless
  313. // of whether the server is standalone.
  314. case "file" :
  315. linit = new LegacyAssetServerClientPluginInitialiser(m_configSettings, m_networkServersInfo.AssetURL);
  316. assetServer = loadAssetServer("File", linit);
  317. break;
  318. // If local is specified then we're going to use the local SQL server
  319. // implementation. We drop through, because that will be the fallback
  320. // for the following default clause too.
  321. case "local" :
  322. break;
  323. // If the asset_database value is none of the previously mentioned strings, then we
  324. // try to load a turnkey plugin that matches this value. If not we drop through to
  325. // a local default.
  326. default :
  327. try
  328. {
  329. init = new AssetServerClientPluginInitialiser(m_configSettings);
  330. assetServer = loadAssetServer(m_configSettings.AssetStorage, init);
  331. break;
  332. }
  333. catch {}
  334. m_log.Info("[OPENSIMBASE] Default assetserver will be used");
  335. break;
  336. }
  337. // Open the local SQL-based database asset server
  338. if (assetServer == null)
  339. {
  340. init = new AssetServerClientPluginInitialiser(m_configSettings);
  341. SQLAssetServer sqlAssetServer = (SQLAssetServer) loadAssetServer("SQL", init);
  342. sqlAssetServer.LoadDefaultAssets(m_configSettings.AssetSetsXMLFile);
  343. assetServer = sqlAssetServer;
  344. }
  345. // Initialize the asset cache, passing a reference to the selected
  346. // asset server interface.
  347. m_assetCache = ResolveAssetCache(assetServer);
  348. }
  349. // This method loads the identified asset server, passing an approrpiately
  350. // initialized Initialise wrapper. There should to be exactly one match,
  351. // if not, then the first match is used.
  352. private IAssetServer loadAssetServer(string id, PluginInitialiserBase pi)
  353. {
  354. m_log.DebugFormat("[OPENSIMBASE] Attempting to load asset server id={0}", id);
  355. PluginLoader<IAssetServer> loader = new PluginLoader<IAssetServer>(pi);
  356. loader.AddFilter(PLUGIN_ASSET_SERVER_CLIENT, new PluginProviderFilter(id));
  357. loader.Load(PLUGIN_ASSET_SERVER_CLIENT);
  358. if (loader.Plugins.Count > 0)
  359. return (IAssetServer) loader.Plugins[0];
  360. else
  361. return null;
  362. }
  363. /// <summary>
  364. /// Attempt to instantiate an IAssetCache implementation, using the
  365. /// provided IAssetServer reference.
  366. /// An asset cache implementation must provide a constructor that
  367. /// accepts two parameters;
  368. /// [1] A ConfigSettings reference.
  369. /// [2] An IAssetServer reference.
  370. /// The AssetCache value is obtained from the
  371. /// [StartUp]/AssetCache value in the configuration file.
  372. /// </summary>
  373. protected virtual IAssetCache ResolveAssetCache(IAssetServer assetServer)
  374. {
  375. IAssetCache assetCache = null;
  376. m_log.DebugFormat("[OPENSIMBASE] Attempting to load asset cache id={0}", m_configSettings.AssetCache);
  377. if (m_configSettings.AssetCache != null && m_configSettings.AssetCache != String.Empty)
  378. {
  379. try
  380. {
  381. PluginInitialiserBase init = new AssetCachePluginInitialiser(m_configSettings, assetServer);
  382. PluginLoader<IAssetCache> loader = new PluginLoader<IAssetCache>(init);
  383. loader.AddFilter(PLUGIN_ASSET_SERVER_CLIENT, new PluginProviderFilter(m_configSettings.AssetCache));
  384. loader.Load(PLUGIN_ASSET_CACHE);
  385. if (loader.Plugins.Count > 0)
  386. assetCache = (IAssetCache) loader.Plugins[0];
  387. }
  388. catch (Exception e)
  389. {
  390. m_log.Debug("[OPENSIMBASE] ResolveAssetCache completed");
  391. m_log.Debug(e);
  392. }
  393. }
  394. // If everything else fails, we force load the built-in asset cache
  395. return (IAssetCache) ((assetCache != null) ? assetCache : new AssetCache(assetServer));
  396. }
  397. public void ProcessLogin(bool LoginEnabled)
  398. {
  399. if (LoginEnabled)
  400. {
  401. m_log.Info("[Login] Login are now enabled ");
  402. m_commsManager.GridService.RegionLoginsEnabled = true;
  403. }
  404. else
  405. {
  406. m_log.Info("[Login] Login are now disabled ");
  407. m_commsManager.GridService.RegionLoginsEnabled = false;
  408. }
  409. }
  410. /// <summary>
  411. /// Execute the region creation process. This includes setting up scene infrastructure.
  412. /// </summary>
  413. /// <param name="regionInfo"></param>
  414. /// <param name="portadd_flag"></param>
  415. /// <returns></returns>
  416. public IClientNetworkServer CreateRegion(RegionInfo regionInfo, bool portadd_flag)
  417. {
  418. return CreateRegion(regionInfo, portadd_flag, false);
  419. }
  420. /// <summary>
  421. /// Execute the region creation process. This includes setting up scene infrastructure.
  422. /// </summary>
  423. /// <param name="regionInfo"></param>
  424. /// <returns></returns>
  425. public IClientNetworkServer CreateRegion(RegionInfo regionInfo)
  426. {
  427. return CreateRegion(regionInfo, false, true);
  428. }
  429. /// <summary>
  430. /// Execute the region creation process. This includes setting up scene infrastructure.
  431. /// </summary>
  432. /// <param name="regionInfo"></param>
  433. /// <param name="portadd_flag"></param>
  434. /// <param name="do_post_init"></param>
  435. /// <returns></returns>
  436. public IClientNetworkServer CreateRegion(RegionInfo regionInfo, bool portadd_flag, bool do_post_init)
  437. {
  438. int port = regionInfo.InternalEndPoint.Port;
  439. // set initial originRegionID to RegionID in RegionInfo. (it needs for loding prims)
  440. regionInfo.originRegionID = regionInfo.RegionID;
  441. // set initial ServerURI
  442. regionInfo.ServerURI = "http://" + regionInfo.ExternalHostName + ":" + regionInfo.InternalEndPoint.Port;
  443. regionInfo.HttpPort = m_httpServerPort;
  444. if ((proxyUrl.Length > 0) && (portadd_flag))
  445. {
  446. // set proxy url to RegionInfo
  447. regionInfo.proxyUrl = proxyUrl;
  448. Util.XmlRpcCommand(proxyUrl, "AddPort", port, port + proxyOffset, regionInfo.ExternalHostName);
  449. }
  450. IClientNetworkServer clientServer;
  451. Scene scene = SetupScene(regionInfo, proxyOffset, m_config.Source, out clientServer);
  452. m_log.Info("[MODULES]: Loading Region's modules");
  453. List<IRegionModule> modules = m_moduleLoader.PickupModules(scene, ".");
  454. // This needs to be ahead of the script engine load, so the
  455. // script module can pick up events exposed by a module
  456. m_moduleLoader.InitialiseSharedModules(scene);
  457. scene.SetModuleInterfaces();
  458. // Prims have to be loaded after module configuration since some modules may be invoked during the load
  459. scene.LoadPrimsFromStorage(regionInfo.originRegionID);
  460. scene.StartTimer();
  461. // moved these here as the terrain texture has to be created after the modules are initialized
  462. // and has to happen before the region is registered with the grid.
  463. scene.CreateTerrainTexture(false);
  464. try
  465. {
  466. scene.RegisterRegionWithGrid();
  467. }
  468. catch (Exception e)
  469. {
  470. m_log.ErrorFormat("[STARTUP]: Registration of region with grid failed, aborting startup - {0}", e);
  471. // Carrying on now causes a lot of confusion down the
  472. // line - we need to get the user's attention
  473. Environment.Exit(1);
  474. }
  475. // We need to do this after we've initialized the
  476. // scripting engines.
  477. scene.CreateScriptInstances();
  478. scene.loadAllLandObjectsFromStorage(regionInfo.originRegionID);
  479. scene.EventManager.TriggerParcelPrimCountUpdate();
  480. m_sceneManager.Add(scene);
  481. m_clientServers.Add(clientServer);
  482. clientServer.Start();
  483. if (do_post_init)
  484. {
  485. foreach (IRegionModule module in modules)
  486. {
  487. module.PostInitialise();
  488. }
  489. }
  490. return clientServer;
  491. }
  492. public void RemoveRegion(Scene scene, bool cleanup)
  493. {
  494. // only need to check this if we are not at the
  495. // root level
  496. if ((m_sceneManager.CurrentScene != null) &&
  497. (m_sceneManager.CurrentScene.RegionInfo.RegionID == scene.RegionInfo.RegionID))
  498. {
  499. m_sceneManager.TrySetCurrentScene("..");
  500. }
  501. scene.DeleteAllSceneObjects();
  502. m_sceneManager.CloseScene(scene);
  503. if (!cleanup)
  504. return;
  505. if (!String.IsNullOrEmpty(scene.RegionInfo.RegionFile))
  506. {
  507. File.Delete(scene.RegionInfo.RegionFile);
  508. m_log.InfoFormat("[OPENSIM]: deleting region file \"{0}\"", scene.RegionInfo.RegionFile);
  509. }
  510. }
  511. public void RemoveRegion(string name, bool cleanUp)
  512. {
  513. Scene target;
  514. if (m_sceneManager.TryGetScene(name, out target))
  515. RemoveRegion(target, cleanUp);
  516. }
  517. protected override StorageManager CreateStorageManager()
  518. {
  519. return CreateStorageManager(m_configSettings.StorageConnectionString, m_configSettings.EstateConnectionString);
  520. }
  521. protected StorageManager CreateStorageManager(string connectionstring, string estateconnectionstring)
  522. {
  523. return new StorageManager(m_configSettings.StorageDll, connectionstring, estateconnectionstring);
  524. }
  525. protected override ClientStackManager CreateClientStackManager()
  526. {
  527. return new ClientStackManager(m_configSettings.ClientstackDll);
  528. }
  529. protected override Scene CreateScene(RegionInfo regionInfo, StorageManager storageManager,
  530. AgentCircuitManager circuitManager)
  531. {
  532. SceneCommunicationService sceneGridService = new SceneCommunicationService(m_commsManager);
  533. return new Scene(
  534. regionInfo, circuitManager, m_commsManager, sceneGridService,
  535. storageManager, m_moduleLoader, m_configSettings.DumpAssetsToFile, m_configSettings.PhysicalPrim,
  536. m_configSettings.See_into_region_from_neighbor, m_config.Source, m_version);
  537. }
  538. public void handleRestartRegion(RegionInfo whichRegion)
  539. {
  540. m_log.Info("[OPENSIM]: Got restart signal from SceneManager");
  541. // Shutting down the client server
  542. bool foundClientServer = false;
  543. int clientServerElement = 0;
  544. for (int i = 0; i < m_clientServers.Count; i++)
  545. {
  546. if (m_clientServers[i].HandlesRegion(new Location(whichRegion.RegionHandle)))
  547. {
  548. clientServerElement = i;
  549. foundClientServer = true;
  550. break;
  551. }
  552. }
  553. if (foundClientServer)
  554. {
  555. m_clientServers[clientServerElement].Server.Close();
  556. m_clientServers.RemoveAt(clientServerElement);
  557. }
  558. CreateRegion(whichRegion, true);
  559. }
  560. # region Setup methods
  561. protected override PhysicsScene GetPhysicsScene(string osSceneIdentifier)
  562. {
  563. return GetPhysicsScene(
  564. m_configSettings.PhysicsEngine, m_configSettings.MeshEngineName, m_config.Source, osSceneIdentifier);
  565. }
  566. /// <summary>
  567. /// Handler to supply the current status of this sim
  568. /// </summary>
  569. /// Currently this is always OK if the simulator is still listening for connections on its HTTP service
  570. protected class SimStatusHandler : IStreamedRequestHandler
  571. {
  572. public byte[] Handle(string path, Stream request,
  573. OSHttpRequest httpRequest, OSHttpResponse httpResponse)
  574. {
  575. return Encoding.UTF8.GetBytes("OK");
  576. }
  577. public string ContentType
  578. {
  579. get { return "text/plain"; }
  580. }
  581. public string HttpMethod
  582. {
  583. get { return "GET"; }
  584. }
  585. public string Path
  586. {
  587. get { return "/simstatus/"; }
  588. }
  589. }
  590. #endregion
  591. /// <summary>
  592. /// Performs any last-minute sanity checking and shuts down the region server
  593. /// </summary>
  594. public override void ShutdownSpecific()
  595. {
  596. if (proxyUrl.Length > 0)
  597. {
  598. Util.XmlRpcCommand(proxyUrl, "Stop");
  599. }
  600. m_log.Info("[SHUTDOWN]: Closing all threads");
  601. m_log.Info("[SHUTDOWN]: Killing listener thread");
  602. m_log.Info("[SHUTDOWN]: Killing clients");
  603. // TODO: implement this
  604. m_log.Info("[SHUTDOWN]: Closing console and terminating");
  605. try
  606. {
  607. m_sceneManager.Close();
  608. }
  609. catch (Exception e)
  610. {
  611. m_log.ErrorFormat("[SHUTDOWN]: Ignoring failure during shutdown - {0}", e);
  612. }
  613. }
  614. /// <summary>
  615. /// Get the start time and up time of Region server
  616. /// </summary>
  617. /// <param name="starttime">The first out parameter describing when the Region server started</param>
  618. /// <param name="uptime">The second out parameter describing how long the Region server has run</param>
  619. public void GetRunTime(out string starttime, out string uptime)
  620. {
  621. starttime = m_startuptime.ToString();
  622. uptime = (DateTime.Now - m_startuptime).ToString();
  623. }
  624. /// <summary>
  625. /// Get the number of the avatars in the Region server
  626. /// </summary>
  627. /// <param name="usernum">The first out parameter describing the number of all the avatars in the Region server</param>
  628. public void GetAvatarNumber(out int usernum)
  629. {
  630. usernum = m_sceneManager.GetCurrentSceneAvatars().Count;
  631. }
  632. /// <summary>
  633. /// Get the number of regions
  634. /// </summary>
  635. /// <param name="regionnum">The first out parameter describing the number of regions</param>
  636. public void GetRegionNumber(out int regionnum)
  637. {
  638. regionnum = m_sceneManager.Scenes.Count;
  639. }
  640. }
  641. public class OpenSimConfigSource
  642. {
  643. public IConfigSource Source;
  644. public void Save(string path)
  645. {
  646. if (Source is IniConfigSource)
  647. {
  648. IniConfigSource iniCon = (IniConfigSource)Source;
  649. iniCon.Save(path);
  650. }
  651. else if (Source is XmlConfigSource)
  652. {
  653. XmlConfigSource xmlCon = (XmlConfigSource)Source;
  654. xmlCon.Save(path);
  655. }
  656. }
  657. }
  658. }