OpenSimMain.cs 31 KB

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