OpenSimBase.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  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.Net;
  31. using System.Reflection;
  32. using System.Text;
  33. using System.Threading;
  34. using libsecondlife;
  35. using log4net;
  36. using Nini.Config;
  37. using OpenSim.Framework;
  38. using OpenSim.Framework.Communications.Cache;
  39. using OpenSim.Framework.Console;
  40. using OpenSim.Framework.Servers;
  41. using OpenSim.Framework.Statistics;
  42. using OpenSim.Region.ClientStack;
  43. using OpenSim.Region.Communications.Local;
  44. using OpenSim.Region.Communications.OGS1;
  45. using OpenSim.Region.Environment;
  46. using OpenSim.Region.Environment.Interfaces;
  47. using OpenSim.Region.Environment.Scenes;
  48. using OpenSim.Region.Physics.Manager;
  49. namespace OpenSim
  50. {
  51. /// <summary>
  52. /// Common OpenSim region service code
  53. /// </summary>
  54. public class OpenSimBase : RegionApplicationBase
  55. {
  56. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  57. protected string proxyUrl;
  58. protected int proxyOffset = 0;
  59. /// <summary>
  60. /// The file used to load and save prim backup xml if none has been specified
  61. /// </summary>
  62. protected const string DEFAULT_PRIM_BACKUP_FILENAME = "prim-backup.xml";
  63. /// <summary>
  64. /// The file use to load and save an opensim archive if none has been specified
  65. /// </summary>
  66. protected const string DEFAULT_OAR_BACKUP_FILENAME = "scene_oar.tar.gz";
  67. public string m_physicsEngine;
  68. public string m_meshEngineName;
  69. public string m_scriptEngine;
  70. public bool m_sandbox;
  71. public bool user_accounts;
  72. public bool m_gridLocalAsset;
  73. public bool m_see_into_region_from_neighbor;
  74. protected LocalLoginService m_loginService;
  75. protected string m_storageDll;
  76. protected string m_clientstackDll;
  77. protected List<IClientNetworkServer> m_clientServers = new List<IClientNetworkServer>();
  78. protected List<RegionInfo> m_regionData = new List<RegionInfo>();
  79. protected bool m_physicalPrim;
  80. protected bool m_standaloneAuthenticate = false;
  81. protected string m_standaloneWelcomeMessage = null;
  82. protected string m_standaloneInventoryPlugin;
  83. protected string m_standaloneAssetPlugin;
  84. protected string m_standaloneUserPlugin;
  85. private string m_standaloneInventorySource;
  86. private string m_standaloneAssetSource;
  87. private string m_standaloneUserSource;
  88. protected string m_assetStorage = "local";
  89. public ConsoleCommand CreateAccount = null;
  90. protected bool m_dumpAssetsToFile;
  91. protected List<IApplicationPlugin> m_plugins = new List<IApplicationPlugin>();
  92. protected IConfigSource m_finalConfig = null;
  93. //protected IniConfigSource m_config;
  94. protected OpenSimConfigSource m_config;
  95. public OpenSimConfigSource ConfigSource
  96. {
  97. get { return m_config; }
  98. set { m_config = value; }
  99. }
  100. public List<IClientNetworkServer> ClientServers
  101. {
  102. get { return m_clientServers; }
  103. }
  104. public List<RegionInfo> RegionData
  105. {
  106. get { return m_regionData; }
  107. }
  108. public new BaseHttpServer HttpServer
  109. {
  110. get { return m_httpServer; }
  111. }
  112. // 6/28 Cfk: Commented out the new in this next line. It used to be
  113. // 6/28 cfk: public new uint HttpServerPort and it was causing a warning indicating there should not be a new
  114. // 6/28 cfk: There is still a new in the declaration above and it is unclear if it should be there or not.
  115. public uint HttpServerPort
  116. {
  117. get { return m_httpServerPort; }
  118. }
  119. protected ModuleLoader m_moduleLoader;
  120. public ModuleLoader ModuleLoader
  121. {
  122. get { return m_moduleLoader; }
  123. set { m_moduleLoader = value; }
  124. }
  125. public OpenSimBase(IConfigSource configSource)
  126. : base()
  127. {
  128. IConfig startupConfig = configSource.Configs["Startup"];
  129. Application.iniFilePath = startupConfig.GetString("inifile", "OpenSim.ini");
  130. m_config = new OpenSimConfigSource();
  131. m_config.Source = new IniConfigSource();
  132. // IConfigSource icong;
  133. //check for .INI file (either default or name passed in command line)
  134. if (File.Exists(Application.iniFilePath))
  135. {
  136. m_config.Source.Merge(new IniConfigSource(Application.iniFilePath));
  137. m_config.Source.Merge(configSource);
  138. }
  139. else
  140. {
  141. Application.iniFilePath = Path.Combine(Util.configDir(), Application.iniFilePath);
  142. if (File.Exists(Application.iniFilePath))
  143. {
  144. m_config.Source.Merge(new IniConfigSource(Application.iniFilePath));
  145. m_config.Source.Merge(configSource);
  146. }
  147. else
  148. {
  149. if (File.Exists("OpenSim.xml"))
  150. {
  151. //check for a xml config file
  152. Application.iniFilePath = "OpenSim.xml";
  153. m_config.Source = new XmlConfigSource();
  154. m_config.Source.Merge(new XmlConfigSource(Application.iniFilePath));
  155. m_config.Source.Merge(configSource);
  156. }
  157. else
  158. {
  159. //Application.iniFilePath = "OpenSim.xml";
  160. // m_config.ConfigSource = new XmlConfigSource();
  161. // no default config files, so set default values, and save it
  162. m_config.Source.Merge(DefaultConfig());
  163. m_config.Source.Merge(configSource);
  164. m_config.Save(Application.iniFilePath);
  165. }
  166. }
  167. }
  168. ReadConfigSettings();
  169. }
  170. public static IConfigSource DefaultConfig()
  171. {
  172. IConfigSource DefaultConfig = new IniConfigSource();
  173. if (DefaultConfig.Configs["Startup"] == null)
  174. DefaultConfig.AddConfig("Startup");
  175. IConfig config = DefaultConfig.Configs["Startup"];
  176. if (config != null)
  177. {
  178. config.Set("gridmode", false);
  179. config.Set("physics", "basicphysics");
  180. config.Set("physical_prim", true);
  181. config.Set("see_into_this_sim_from_neighbor", true);
  182. config.Set("serverside_object_permissions", false);
  183. config.Set("storage_plugin", "OpenSim.Data.SQLite.dll");
  184. config.Set("storage_connection_string", "URI=file:OpenSim.db,version=3");
  185. config.Set("storage_prim_inventories", true);
  186. config.Set("startup_console_commands_file", String.Empty);
  187. config.Set("shutdown_console_commands_file", String.Empty);
  188. config.Set("script_engine", "OpenSim.Region.ScriptEngine.DotNetEngine.dll");
  189. config.Set("asset_database", "sqlite");
  190. config.Set("clientstack_plugin", "OpenSim.Region.ClientStack.LindenUDP.dll");
  191. }
  192. if (DefaultConfig.Configs["StandAlone"] == null)
  193. DefaultConfig.AddConfig("StandAlone");
  194. config = DefaultConfig.Configs["StandAlone"];
  195. if (config != null)
  196. {
  197. config.Set("accounts_authenticate", false);
  198. config.Set("welcome_message", "Welcome to OpenSimulator");
  199. config.Set("inventory_plugin", "OpenSim.Data.SQLite.dll");
  200. config.Set("inventory_source", "");
  201. config.Set("userDatabase_plugin", "OpenSim.Data.SQLite.dll");
  202. config.Set("user_source", "");
  203. config.Set("asset_plugin", "OpenSim.Data.SQLite.dll");
  204. config.Set("asset_source", "");
  205. config.Set("dump_assets_to_file", false);
  206. }
  207. if (DefaultConfig.Configs["Network"] == null)
  208. DefaultConfig.AddConfig("Network");
  209. config = DefaultConfig.Configs["Network"];
  210. if (config != null)
  211. {
  212. config.Set("default_location_x", 1000);
  213. config.Set("default_location_y", 1000);
  214. config.Set("http_listener_port", NetworkServersInfo.DefaultHttpListenerPort);
  215. config.Set("remoting_listener_port", NetworkServersInfo.RemotingListenerPort);
  216. config.Set("grid_server_url", "http://127.0.0.1:" + GridConfig.DefaultHttpPort.ToString());
  217. config.Set("grid_send_key", "null");
  218. config.Set("grid_recv_key", "null");
  219. config.Set("user_server_url", "http://127.0.0.1:" + UserConfig.DefaultHttpPort.ToString());
  220. config.Set("user_send_key", "null");
  221. config.Set("user_recv_key", "null");
  222. config.Set("asset_server_url", "http://127.0.0.1:" + AssetConfig.DefaultHttpPort.ToString());
  223. config.Set("inventory_server_url", "http://127.0.0.1:" + InventoryConfig.DefaultHttpPort.ToString());
  224. }
  225. if (DefaultConfig.Configs["RemoteAdmin"] == null)
  226. DefaultConfig.AddConfig("RemoteAdmin");
  227. config = DefaultConfig.Configs["RemoteAdmin"];
  228. if (config != null)
  229. {
  230. config.Set("enabled", "false");
  231. }
  232. if (DefaultConfig.Configs["Voice"] == null)
  233. DefaultConfig.AddConfig("Voice");
  234. config = DefaultConfig.Configs["Voice"];
  235. if (config != null)
  236. {
  237. config.Set("enabled", "false");
  238. }
  239. return DefaultConfig;
  240. }
  241. protected virtual void ReadConfigSettings()
  242. {
  243. m_networkServersInfo = new NetworkServersInfo();
  244. IConfig startupConfig = m_config.Source.Configs["Startup"];
  245. if (startupConfig != null)
  246. {
  247. m_sandbox = !startupConfig.GetBoolean("gridmode", false);
  248. m_physicsEngine = startupConfig.GetString("physics", "basicphysics");
  249. m_meshEngineName = startupConfig.GetString("meshing", "ZeroMesher");
  250. m_physicalPrim = startupConfig.GetBoolean("physical_prim", true);
  251. m_see_into_region_from_neighbor = startupConfig.GetBoolean("see_into_this_sim_from_neighbor", true);
  252. m_storageDll = startupConfig.GetString("storage_plugin", "OpenSim.Data.SQLite.dll");
  253. if (m_storageDll == "OpenSim.DataStore.MonoSqlite.dll")
  254. {
  255. m_storageDll = "OpenSim.Data.SQLite.dll";
  256. Console.WriteLine("WARNING: OpenSim.DataStore.MonoSqlite.dll is deprecated. Set storage_plugin to OpenSim.Data.SQLite.dll.");
  257. Thread.Sleep(3000);
  258. }
  259. m_storageConnectionString
  260. = startupConfig.GetString("storage_connection_string", "URI=file:OpenSim.db,version=3");
  261. m_storagePersistPrimInventories
  262. = startupConfig.GetBoolean("storage_prim_inventories", true);
  263. m_scriptEngine = startupConfig.GetString("script_engine", "OpenSim.Region.ScriptEngine.DotNetEngine.dll");
  264. m_assetStorage = startupConfig.GetString("asset_database", "local");
  265. m_clientstackDll = startupConfig.GetString("clientstack_plugin", "OpenSim.Region.ClientStack.LindenUDP.dll");
  266. }
  267. IConfig standaloneConfig = m_config.Source.Configs["StandAlone"];
  268. if (standaloneConfig != null)
  269. {
  270. m_standaloneAuthenticate = standaloneConfig.GetBoolean("accounts_authenticate", false);
  271. m_standaloneWelcomeMessage = standaloneConfig.GetString("welcome_message", "Welcome to OpenSim");
  272. m_standaloneInventoryPlugin =
  273. standaloneConfig.GetString("inventory_plugin", "OpenSim.Data.SQLite.dll");
  274. m_standaloneInventorySource =
  275. standaloneConfig.GetString("inventory_source","");
  276. m_standaloneUserPlugin =
  277. standaloneConfig.GetString("userDatabase_plugin", "OpenSim.Data.SQLite.dll");
  278. m_standaloneUserSource =
  279. standaloneConfig.GetString("user_source","");
  280. m_standaloneAssetPlugin =
  281. standaloneConfig.GetString("asset_plugin", "OpenSim.Data.SQLite.dll");
  282. m_standaloneAssetSource =
  283. standaloneConfig.GetString("asset_source","");
  284. m_dumpAssetsToFile = standaloneConfig.GetBoolean("dump_assets_to_file", false);
  285. }
  286. m_networkServersInfo.loadFromConfiguration(m_config.Source);
  287. }
  288. protected void LoadPlugins()
  289. {
  290. PluginLoader<IApplicationPlugin> loader =
  291. new PluginLoader<IApplicationPlugin> (new ApplicationPluginInitialiser (this));
  292. loader.Load ("/OpenSim/Startup");
  293. m_plugins = loader.Plugins;
  294. }
  295. /// <summary>
  296. /// Performs initialisation of the scene, such as loading configuration from disk.
  297. /// </summary>
  298. public override void Startup()
  299. {
  300. base.Startup();
  301. m_stats = StatsManager.StartCollectingSimExtraStats();
  302. // StandAlone mode? m_sandbox is determined by !startupConfig.GetBoolean("gridmode", false)
  303. if (m_sandbox)
  304. {
  305. LocalInventoryService inventoryService = new LocalInventoryService();
  306. inventoryService.AddPlugin(m_standaloneInventoryPlugin, m_standaloneInventorySource);
  307. LocalUserServices userService =
  308. new LocalUserServices(m_networkServersInfo, m_networkServersInfo.DefaultHomeLocX,
  309. m_networkServersInfo.DefaultHomeLocY, inventoryService);
  310. userService.AddPlugin(m_standaloneUserPlugin, m_standaloneUserSource);
  311. LocalBackEndServices backendService = new LocalBackEndServices();
  312. CommunicationsLocal localComms =
  313. new CommunicationsLocal(m_networkServersInfo, m_httpServer, m_assetCache, userService,
  314. inventoryService, backendService, backendService, m_dumpAssetsToFile);
  315. m_commsManager = localComms;
  316. m_loginService =
  317. new LocalLoginService(userService, m_standaloneWelcomeMessage, localComms, m_networkServersInfo,
  318. m_standaloneAuthenticate);
  319. m_loginService.OnLoginToRegion += backendService.AddNewSession;
  320. // set up XMLRPC handler for client's initial login request message
  321. m_httpServer.AddXmlRPCHandler("login_to_simulator", m_loginService.XmlRpcLoginMethod);
  322. // provides the web form login
  323. m_httpServer.AddHTTPHandler("login", m_loginService.ProcessHTMLLogin);
  324. // Provides the LLSD login
  325. m_httpServer.SetLLSDHandler(m_loginService.LLSDLoginMethod);
  326. CreateAccount = localComms.doCreate;
  327. }
  328. else
  329. {
  330. // We are in grid mode
  331. m_commsManager = new CommunicationsOGS1(m_networkServersInfo, m_httpServer, m_assetCache);
  332. m_httpServer.AddStreamHandler(new SimStatusHandler());
  333. }
  334. proxyUrl = ConfigSource.Source.Configs["Network"].GetString("proxy_url", "");
  335. proxyOffset = Int32.Parse(ConfigSource.Source.Configs["Network"].GetString("proxy_offset", "0"));
  336. // Create a ModuleLoader instance
  337. m_moduleLoader = new ModuleLoader(m_config.Source);
  338. LoadPlugins();
  339. }
  340. protected override void Initialize()
  341. {
  342. //
  343. // Called from base.StartUp()
  344. //
  345. m_httpServerPort = m_networkServersInfo.HttpListenerPort;
  346. IAssetServer assetServer;
  347. if (m_assetStorage == "grid")
  348. {
  349. assetServer = new GridAssetClient(m_networkServersInfo.AssetURL);
  350. }
  351. else
  352. {
  353. SQLAssetServer sqlAssetServer = new SQLAssetServer(m_standaloneAssetPlugin, m_standaloneAssetSource);
  354. sqlAssetServer.LoadDefaultAssets();
  355. assetServer = sqlAssetServer;
  356. }
  357. m_assetCache = new AssetCache(assetServer);
  358. m_sceneManager.OnRestartSim += handleRestartRegion;
  359. }
  360. public LLUUID CreateUser(string tempfirstname, string templastname, string tempPasswd, uint regX, uint regY)
  361. {
  362. return m_commsManager.AddUser(tempfirstname,templastname,tempPasswd,regX,regY);
  363. }
  364. /// <summary>
  365. /// Execute the region creation process. This includes setting up scene infrastructure.
  366. /// </summary>
  367. /// <param name="regionInfo"></param>
  368. /// <param name="portadd_flag"></param>
  369. /// <returns></returns>
  370. public IClientNetworkServer CreateRegion(RegionInfo regionInfo, bool portadd_flag)
  371. {
  372. return CreateRegion(regionInfo, portadd_flag, false);
  373. }
  374. /// <summary>
  375. /// Execute the region creation process. This includes setting up scene infrastructure.
  376. /// </summary>
  377. /// <param name="regionInfo"></param>
  378. /// <param name="portadd_flag"></param>
  379. /// <returns></returns>
  380. public IClientNetworkServer CreateRegion(RegionInfo regionInfo)
  381. {
  382. return CreateRegion(regionInfo, false, true);
  383. }
  384. /// <summary>
  385. /// Execute the region creation process. This includes setting up scene infrastructure.
  386. /// </summary>
  387. /// <param name="regionInfo"></param>
  388. /// <param name="portadd_flag"></param>
  389. /// <param name="do_post_init"></param>
  390. /// <returns></returns>
  391. public IClientNetworkServer CreateRegion(RegionInfo regionInfo, bool portadd_flag, bool do_post_init)
  392. {
  393. int port = regionInfo.InternalEndPoint.Port;
  394. // set initial RegionID to originRegionID in RegionInfo. (it needs for loding prims)
  395. regionInfo.originRegionID = regionInfo.RegionID;
  396. // set initial ServerURI
  397. regionInfo.ServerURI = "http://" + regionInfo.ExternalHostName
  398. + ":" + regionInfo.InternalEndPoint.Port.ToString();
  399. regionInfo.HttpPort = m_httpServerPort;
  400. if ((proxyUrl.Length > 0) && (portadd_flag))
  401. {
  402. // set proxy url to RegionInfo
  403. regionInfo.proxyUrl = proxyUrl;
  404. Util.XmlRpcCommand(proxyUrl, "AddPort", port, port + proxyOffset, regionInfo.ExternalHostName);
  405. }
  406. IClientNetworkServer clientServer;
  407. Scene scene = SetupScene(regionInfo, proxyOffset, out clientServer);
  408. m_log.Info("[MODULES]: Loading Region's modules");
  409. List<IRegionModule> modules = m_moduleLoader.PickupModules(scene, ".");
  410. // This needs to be ahead of the script engine load, so the
  411. // script module can pick up events exposed by a module
  412. m_moduleLoader.InitialiseSharedModules(scene);
  413. //m_moduleLoader.PickupModules(scene, "ScriptEngines");
  414. //m_moduleLoader.LoadRegionModules(Path.Combine("ScriptEngines", m_scriptEngine), scene);
  415. if (string.IsNullOrEmpty(m_scriptEngine))
  416. {
  417. m_log.Info("[MODULES]: No script engine module specified");
  418. }
  419. else
  420. {
  421. m_log.Info("[MODULES]: Loading scripting engine modules");
  422. foreach (string module in m_scriptEngine.Split(','))
  423. {
  424. string mod = module.Trim(" \t".ToCharArray()); // Clean up name
  425. m_log.Info("[MODULES]: Loading scripting engine: " + mod);
  426. try
  427. {
  428. m_moduleLoader.LoadRegionModules(Path.Combine("ScriptEngines", mod), scene);
  429. }
  430. catch (Exception ex)
  431. {
  432. m_log.Error("[MODULES]: Failed to load script engine: " + ex.ToString());
  433. }
  434. }
  435. }
  436. scene.SetModuleInterfaces();
  437. //moved these here as the terrain texture has to be created after the modules are initialized
  438. // and has to happen before the region is registered with the grid.
  439. scene.CreateTerrainTexture(false);
  440. try
  441. {
  442. scene.RegisterRegionWithGrid();
  443. }
  444. catch (Exception e)
  445. {
  446. m_log.ErrorFormat("[STARTUP]: Registration of region with grid failed, aborting startup - {0}", e);
  447. // Carrying on now causes a lot of confusion down the line - we need to get the user's attention
  448. System.Environment.Exit(1);
  449. }
  450. // We need to do this after we've initialized the scripting engines.
  451. scene.CreateScriptInstances();
  452. scene.loadAllLandObjectsFromStorage(regionInfo.originRegionID);
  453. scene.EventManager.TriggerParcelPrimCountUpdate();
  454. m_sceneManager.Add(scene);
  455. m_clientServers.Add(clientServer);
  456. m_regionData.Add(regionInfo);
  457. clientServer.Start();
  458. if (do_post_init)
  459. {
  460. foreach (IRegionModule module in modules)
  461. {
  462. module.PostInitialise();
  463. }
  464. }
  465. return clientServer;
  466. }
  467. protected override StorageManager CreateStorageManager(string connectionstring)
  468. {
  469. return new StorageManager(m_storageDll, connectionstring, m_storagePersistPrimInventories);
  470. }
  471. protected override ClientStackManager CreateClientStackManager()
  472. {
  473. return new ClientStackManager(m_clientstackDll);
  474. }
  475. protected override Scene CreateScene(RegionInfo regionInfo, StorageManager storageManager,
  476. AgentCircuitManager circuitManager)
  477. {
  478. SceneCommunicationService sceneGridService = new SceneCommunicationService(m_commsManager);
  479. return
  480. new Scene(regionInfo, circuitManager, m_commsManager, sceneGridService, m_assetCache,
  481. storageManager, m_httpServer,
  482. m_moduleLoader, m_dumpAssetsToFile, m_physicalPrim, m_see_into_region_from_neighbor, m_config.Source,
  483. m_version);
  484. }
  485. public void handleRestartRegion(RegionInfo whichRegion)
  486. {
  487. m_log.Error("[OPENSIM MAIN]: Got restart signal from SceneManager");
  488. // Shutting down the client server
  489. bool foundClientServer = false;
  490. int clientServerElement = 0;
  491. for (int i = 0; i < m_clientServers.Count; i++)
  492. {
  493. if (m_clientServers[i].HandlesRegion(new Location(whichRegion.RegionHandle)))
  494. {
  495. clientServerElement = i;
  496. foundClientServer = true;
  497. break;
  498. }
  499. }
  500. if (foundClientServer)
  501. {
  502. m_clientServers[clientServerElement].Server.Close();
  503. m_clientServers.RemoveAt(clientServerElement);
  504. }
  505. //Removing the region from the sim's database of regions..
  506. int RegionHandleElement = -1;
  507. for (int i = 0; i < m_regionData.Count; i++)
  508. {
  509. if (whichRegion.RegionHandle == m_regionData[i].RegionHandle)
  510. {
  511. RegionHandleElement = i;
  512. }
  513. }
  514. if (RegionHandleElement >= 0)
  515. {
  516. m_regionData.RemoveAt(RegionHandleElement);
  517. }
  518. CreateRegion(whichRegion, true);
  519. }
  520. # region Setup methods
  521. protected override PhysicsScene GetPhysicsScene()
  522. {
  523. return GetPhysicsScene(m_physicsEngine, m_meshEngineName, m_config.Source);
  524. }
  525. /// <summary>
  526. /// Handler to supply the current status of this sim
  527. ///
  528. /// Currently this is always OK if the simulator is still listening for connections on its HTTP service
  529. /// </summary>
  530. protected class SimStatusHandler : IStreamedRequestHandler
  531. {
  532. public byte[] Handle(string path, Stream request,
  533. OSHttpRequest httpRequest, OSHttpResponse httpResponse)
  534. {
  535. return Encoding.UTF8.GetBytes("OK");
  536. }
  537. public string ContentType
  538. {
  539. get { return "text/plain"; }
  540. }
  541. public string HttpMethod
  542. {
  543. get { return "GET"; }
  544. }
  545. public string Path
  546. {
  547. get { return "/simstatus/"; }
  548. }
  549. }
  550. #endregion
  551. /// <summary>
  552. /// Performs any last-minute sanity checking and shuts down the region server
  553. /// </summary>
  554. public override void Shutdown()
  555. {
  556. if (proxyUrl.Length > 0)
  557. {
  558. Util.XmlRpcCommand(proxyUrl, "Stop");
  559. }
  560. m_log.Info("[SHUTDOWN]: Closing all threads");
  561. m_log.Info("[SHUTDOWN]: Killing listener thread");
  562. m_log.Info("[SHUTDOWN]: Killing clients");
  563. // TODO: implement this
  564. m_log.Info("[SHUTDOWN]: Closing console and terminating");
  565. m_sceneManager.Close();
  566. base.Shutdown();
  567. }
  568. /// <summary>
  569. /// Get the start time and up time of Region server
  570. /// </summary>
  571. /// <param name="starttime">The first out parameter describing when the Region server started</param>
  572. /// <param name="uptime">The second out parameter describing how long the Region server has run</param>
  573. public void GetRunTime(out string starttime, out string uptime)
  574. {
  575. starttime = m_startuptime.ToString();
  576. uptime = (DateTime.Now - m_startuptime).ToString();
  577. }
  578. /// <summary>
  579. /// Get the number of the avatars in the Region server
  580. /// </summary>
  581. /// <param name="usernum">The first out parameter describing the number of all the avatars in the Region server</param>
  582. public void GetAvatarNumber(out int usernum)
  583. {
  584. usernum = m_sceneManager.GetCurrentSceneAvatars().Count;
  585. }
  586. /// <summary>
  587. /// Get the number of regions
  588. /// </summary>
  589. /// <param name="regionnum">The first out parameter describing the number of regions</param>
  590. public void GetRegionNumber(out int regionnum)
  591. {
  592. regionnum = m_sceneManager.Scenes.Count;
  593. }
  594. }
  595. public class OpenSimConfigSource
  596. {
  597. public IConfigSource Source;
  598. public void Save(string path)
  599. {
  600. if (Source is IniConfigSource)
  601. {
  602. IniConfigSource iniCon = (IniConfigSource)Source;
  603. iniCon.Save(path);
  604. }
  605. else if (Source is XmlConfigSource)
  606. {
  607. XmlConfigSource xmlCon = (XmlConfigSource)Source;
  608. xmlCon.Save(path);
  609. }
  610. }
  611. }
  612. }