OpenSimMain.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  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 System.Threading;
  33. using libsecondlife;
  34. using log4net;
  35. using Mono.Addins;
  36. using Nini.Config;
  37. using OpenSim.Framework;
  38. using OpenSim.Framework.Communications.Cache;
  39. using OpenSim.Framework.Servers;
  40. using OpenSim.Framework.Statistics;
  41. using OpenSim.Region.ClientStack;
  42. using OpenSim.Region.Communications.Local;
  43. using OpenSim.Region.Communications.OGS1;
  44. using OpenSim.Region.Environment;
  45. using OpenSim.Region.Environment.Interfaces;
  46. using OpenSim.Region.Environment.Scenes;
  47. using OpenSim.Region.Physics.Manager;
  48. namespace OpenSim
  49. {
  50. public class OpenSimMain : RegionApplicationBase
  51. {
  52. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  53. protected string proxyUrl;
  54. protected int proxyOffset = 0;
  55. protected const string DEFAULT_PRIM_BACKUP_FILENAME = "prim-backup.xml";
  56. public string m_physicsEngine;
  57. public string m_meshEngineName;
  58. public string m_scriptEngine;
  59. public bool m_sandbox;
  60. public bool user_accounts;
  61. public bool m_gridLocalAsset;
  62. public bool m_see_into_region_from_neighbor;
  63. protected LocalLoginService m_loginService;
  64. protected string m_storageDll;
  65. protected List<UDPServer> m_udpServers = new List<UDPServer>();
  66. protected List<RegionInfo> m_regionData = new List<RegionInfo>();
  67. protected bool m_physicalPrim;
  68. protected bool m_permissions = false;
  69. protected bool m_standaloneAuthenticate = false;
  70. protected string m_standaloneWelcomeMessage = null;
  71. protected string m_standaloneInventoryPlugin;
  72. protected string m_standaloneAssetPlugin;
  73. protected string m_standaloneUserPlugin;
  74. private string m_standaloneInventorySource;
  75. private string m_standaloneAssetSource;
  76. private string m_standaloneUserSource;
  77. protected string m_assetStorage = "local";
  78. public ConsoleCommand CreateAccount = null;
  79. protected bool m_dumpAssetsToFile;
  80. protected List<IApplicationPlugin> m_plugins = new List<IApplicationPlugin>();
  81. protected IniConfigSource m_config;
  82. public IniConfigSource ConfigSource
  83. {
  84. get { return m_config; }
  85. set { m_config = value; }
  86. }
  87. public BaseHttpServer HttpServer
  88. {
  89. get { return m_httpServer; }
  90. }
  91. public List<UDPServer> UdpServers
  92. {
  93. get { return m_udpServers; }
  94. }
  95. public List<RegionInfo> RegionData
  96. {
  97. get { return m_regionData; }
  98. }
  99. protected ModuleLoader m_moduleLoader;
  100. public ModuleLoader ModuleLoader
  101. {
  102. get { return m_moduleLoader; }
  103. set { m_moduleLoader = value; }
  104. }
  105. public OpenSimMain(IConfigSource configSource)
  106. : base()
  107. {
  108. IConfig startupConfig = configSource.Configs["Startup"];
  109. // The Mono addin manager (in Mono.Addins.dll version 0.2.0.0) occasionally seems to corrupt its addin cache
  110. // Hence, as a temporary solution we'll remove it before each startup
  111. if (Directory.Exists("addin-db-000"))
  112. Directory.Delete("addin-db-000", true);
  113. if (Directory.Exists("addin-db-001"))
  114. Directory.Delete("addin-db-001", true);
  115. m_log.Info("[OPENSIM MAIN]: PLEASE IGNORE THE SCANNING ERRORS BELOW. These are the result of a temporary problem with our plugins manager.");
  116. AddinManager.Initialize(".");
  117. AddinManager.Registry.Update(null);
  118. Application.iniFilePath = startupConfig.GetString("inifile", "OpenSim.ini");
  119. m_config = new IniConfigSource();
  120. //check for .INI file (either default or name passed in command line)
  121. if (File.Exists(Application.iniFilePath))
  122. {
  123. m_config.Merge(new IniConfigSource(Application.iniFilePath));
  124. m_config.Merge(configSource);
  125. }
  126. else
  127. {
  128. Application.iniFilePath = Path.Combine(Util.configDir(), Application.iniFilePath);
  129. if (File.Exists(Application.iniFilePath))
  130. {
  131. m_config.Merge(new IniConfigSource(Application.iniFilePath));
  132. m_config.Merge(configSource);
  133. }
  134. else
  135. {
  136. // no default config files, so set default values, and save it
  137. m_config.Merge(DefaultConfig());
  138. m_config.Merge(configSource);
  139. m_config.Save(Application.iniFilePath);
  140. }
  141. }
  142. ReadConfigSettings();
  143. }
  144. public static IConfigSource DefaultConfig()
  145. {
  146. IConfigSource DefaultConfig = new IniConfigSource();
  147. if (DefaultConfig.Configs["Startup"] == null)
  148. DefaultConfig.AddConfig("Startup");
  149. IConfig config = DefaultConfig.Configs["Startup"];
  150. if (config != null)
  151. {
  152. config.Set("gridmode", false);
  153. config.Set("physics", "basicphysics");
  154. config.Set("physical_prim", true);
  155. config.Set("see_into_this_sim_from_neighbor", true);
  156. config.Set("serverside_object_permissions", false);
  157. config.Set("storage_plugin", "OpenSim.Data.SQLite.dll");
  158. config.Set("storage_connection_string", "URI=file:OpenSim.db,version=3");
  159. config.Set("storage_prim_inventories", true);
  160. config.Set("startup_console_commands_file", String.Empty);
  161. config.Set("shutdown_console_commands_file", String.Empty);
  162. config.Set("script_engine", "OpenSim.Region.ScriptEngine.DotNetEngine.dll");
  163. config.Set("asset_database", "sqlite");
  164. }
  165. if (DefaultConfig.Configs["StandAlone"] == null)
  166. DefaultConfig.AddConfig("StandAlone");
  167. config = DefaultConfig.Configs["StandAlone"];
  168. if (config != null)
  169. {
  170. config.Set("accounts_authenticate", false);
  171. config.Set("welcome_message", "Welcome to OpenSimulator");
  172. config.Set("inventory_plugin", "OpenSim.Data.SQLite.dll");
  173. config.Set("inventory_source", "");
  174. config.Set("userDatabase_plugin", "OpenSim.Data.SQLite.dll");
  175. config.Set("user_source", "");
  176. config.Set("asset_plugin", "OpenSim.Data.SQLite.dll");
  177. config.Set("asset_source", "");
  178. config.Set("dump_assets_to_file", false);
  179. }
  180. if (DefaultConfig.Configs["Network"] == null)
  181. DefaultConfig.AddConfig("Network");
  182. config = DefaultConfig.Configs["Network"];
  183. if (config != null)
  184. {
  185. config.Set("default_location_x", 1000);
  186. config.Set("default_location_y", 1000);
  187. config.Set("http_listener_port", NetworkServersInfo.DefaultHttpListenerPort);
  188. config.Set("remoting_listener_port", NetworkServersInfo.RemotingListenerPort);
  189. config.Set("grid_server_url", "http://127.0.0.1:" + GridConfig.DefaultHttpPort.ToString());
  190. config.Set("grid_send_key", "null");
  191. config.Set("grid_recv_key", "null");
  192. config.Set("user_server_url", "http://127.0.0.1:" + UserConfig.DefaultHttpPort.ToString());
  193. config.Set("user_send_key", "null");
  194. config.Set("user_recv_key", "null");
  195. config.Set("asset_server_url", "http://127.0.0.1:" + AssetConfig.DefaultHttpPort.ToString());
  196. config.Set("inventory_server_url", "http://127.0.0.1:" + InventoryConfig.DefaultHttpPort.ToString());
  197. }
  198. if (DefaultConfig.Configs["RemoteAdmin"] == null)
  199. DefaultConfig.AddConfig("RemoteAdmin");
  200. config = DefaultConfig.Configs["RemoteAdmin"];
  201. if (config != null)
  202. {
  203. config.Set("enabled", "false");
  204. }
  205. if (DefaultConfig.Configs["Voice"] == null)
  206. DefaultConfig.AddConfig("Voice");
  207. config = DefaultConfig.Configs["Voice"];
  208. if (config != null)
  209. {
  210. config.Set("enabled", "false");
  211. }
  212. return DefaultConfig;
  213. }
  214. protected virtual void ReadConfigSettings()
  215. {
  216. m_networkServersInfo = new NetworkServersInfo();
  217. IConfig startupConfig = m_config.Configs["Startup"];
  218. if (startupConfig != null)
  219. {
  220. m_sandbox = !startupConfig.GetBoolean("gridmode", false);
  221. m_physicsEngine = startupConfig.GetString("physics", "basicphysics");
  222. m_meshEngineName = startupConfig.GetString("meshing", "ZeroMesher");
  223. m_physicalPrim = startupConfig.GetBoolean("physical_prim", true);
  224. m_see_into_region_from_neighbor = startupConfig.GetBoolean("see_into_this_sim_from_neighbor", true);
  225. m_permissions = startupConfig.GetBoolean("serverside_object_permissions", false);
  226. m_storageDll = startupConfig.GetString("storage_plugin", "OpenSim.Data.SQLite.dll");
  227. if (m_storageDll == "OpenSim.DataStore.MonoSqlite.dll")
  228. {
  229. m_storageDll = "OpenSim.Data.SQLite.dll";
  230. Console.WriteLine("WARNING: OpenSim.DataStore.MonoSqlite.dll is deprecated. Set storage_plugin to OpenSim.Data.SQLite.dll.");
  231. Thread.Sleep(3000);
  232. }
  233. m_storageConnectionString
  234. = startupConfig.GetString("storage_connection_string", "URI=file:OpenSim.db,version=3");
  235. m_storagePersistPrimInventories
  236. = startupConfig.GetBoolean("storage_prim_inventories", true);
  237. m_scriptEngine = startupConfig.GetString("script_engine", "OpenSim.Region.ScriptEngine.DotNetEngine.dll");
  238. m_assetStorage = startupConfig.GetString("asset_database", "local");
  239. }
  240. IConfig standaloneConfig = m_config.Configs["StandAlone"];
  241. if (standaloneConfig != null)
  242. {
  243. m_standaloneAuthenticate = standaloneConfig.GetBoolean("accounts_authenticate", false);
  244. m_standaloneWelcomeMessage = standaloneConfig.GetString("welcome_message", "Welcome to OpenSim");
  245. m_standaloneInventoryPlugin =
  246. standaloneConfig.GetString("inventory_plugin", "OpenSim.Data.SQLite.dll");
  247. m_standaloneInventorySource =
  248. standaloneConfig.GetString("inventory_source","");
  249. m_standaloneUserPlugin =
  250. standaloneConfig.GetString("userDatabase_plugin", "OpenSim.Data.SQLite.dll");
  251. m_standaloneUserSource =
  252. standaloneConfig.GetString("user_source","");
  253. m_standaloneAssetPlugin =
  254. standaloneConfig.GetString("asset_plugin", "OpenSim.Data.SQLite.dll");
  255. m_standaloneAssetSource =
  256. standaloneConfig.GetString("asset_source","");
  257. m_dumpAssetsToFile = standaloneConfig.GetBoolean("dump_assets_to_file", false);
  258. }
  259. //if (!m_sandbox)
  260. //m_SendChildAgentTaskData = false;
  261. m_networkServersInfo.loadFromConfiguration(m_config);
  262. }
  263. private ManualResetEvent WorldHasComeToAnEnd = new ManualResetEvent(false);
  264. /// <summary>
  265. /// Performs initialisation of the scene, such as loading configuration from disk.
  266. /// </summary>
  267. public override void StartUp()
  268. {
  269. //
  270. // Called from app startup (OpenSim.Application)
  271. //
  272. m_log.Info("====================================================================");
  273. m_log.Info("========================= STARTING OPENSIM =========================");
  274. m_log.Info("====================================================================");
  275. m_log.InfoFormat("[OPENSIM MAIN]: Running in background {0} mode", m_sandbox ? "sandbox" : "grid");
  276. InternalStartUp();
  277. // We are done with startup
  278. m_log.InfoFormat("[OPENSIM MAIN]: Startup complete, serving {0} region{1}",
  279. m_udpServers.Count.ToString(), m_udpServers.Count > 1 ? "s" : "");
  280. WorldHasComeToAnEnd.WaitOne();
  281. m_log.Info("[OPENSIM MAIN]: Shutdown complete, goodbye.");
  282. Environment.Exit(0);
  283. }
  284. /// <summary>
  285. /// Signal that the end of the world is now.
  286. /// </summary>
  287. public void ApocalypseNow()
  288. {
  289. WorldHasComeToAnEnd.Set();
  290. }
  291. /// <summary>
  292. /// Performs initialisation of the scene, such as loading configuration from disk.
  293. /// </summary>
  294. protected void InternalStartUp()
  295. {
  296. StatsManager.StartCollectingSimExtraStats();
  297. // Do baseclass startup sequence: OpenSim.Region.ClientStack.RegionApplicationBase.StartUp
  298. // TerrainManager, StorageManager, HTTP Server
  299. // This base will call abstract Initialize
  300. base.StartUp();
  301. // StandAlone mode? m_sandbox is determined by !startupConfig.GetBoolean("gridmode", false)
  302. if (m_sandbox)
  303. {
  304. LocalInventoryService inventoryService = new LocalInventoryService();
  305. inventoryService.AddPlugin(m_standaloneInventoryPlugin, m_standaloneInventorySource);
  306. LocalUserServices userService =
  307. new LocalUserServices(m_networkServersInfo, m_networkServersInfo.DefaultHomeLocX,
  308. m_networkServersInfo.DefaultHomeLocY, inventoryService);
  309. userService.AddPlugin(m_standaloneUserPlugin);
  310. LocalBackEndServices backendService = new LocalBackEndServices();
  311. CommunicationsLocal localComms =
  312. new CommunicationsLocal(m_networkServersInfo, m_httpServer, m_assetCache, userService,
  313. inventoryService, backendService, backendService, m_dumpAssetsToFile);
  314. m_commsManager = localComms;
  315. m_loginService =
  316. new LocalLoginService(userService, m_standaloneWelcomeMessage, localComms, m_networkServersInfo,
  317. m_standaloneAuthenticate);
  318. m_loginService.OnLoginToRegion += backendService.AddNewSession;
  319. // set up XMLRPC handler for client's initial login request message
  320. m_httpServer.AddXmlRPCHandler("login_to_simulator", m_loginService.XmlRpcLoginMethod);
  321. // provides the web form login
  322. m_httpServer.AddHTTPHandler("login", m_loginService.ProcessHTMLLogin);
  323. // Provides the LLSD login
  324. m_httpServer.SetLLSDHandler(m_loginService.LLSDLoginMethod);
  325. CreateAccount = localComms.doCreate;
  326. }
  327. else
  328. {
  329. // We are in grid mode
  330. m_commsManager = new CommunicationsOGS1(m_networkServersInfo, m_httpServer, m_assetCache);
  331. m_httpServer.AddStreamHandler(new SimStatusHandler());
  332. }
  333. proxyUrl = ConfigSource.Configs["Network"].GetString("proxy_url", "");
  334. proxyOffset = Int32.Parse(ConfigSource.Configs["Network"].GetString("proxy_offset", "0"));
  335. // Create a ModuleLoader instance
  336. m_moduleLoader = new ModuleLoader(m_config);
  337. ExtensionNodeList nodes = AddinManager.GetExtensionNodes("/OpenSim/Startup");
  338. foreach (TypeExtensionNode node in nodes)
  339. {
  340. m_log.InfoFormat("[PLUGINS]: Loading OpenSim application plugin {0}", node.Path);
  341. IApplicationPlugin plugin = (IApplicationPlugin)node.CreateInstance();
  342. plugin.Initialise(this);
  343. m_plugins.Add(plugin);
  344. }
  345. // Start UDP servers
  346. //for (int i = 0; i < m_udpServers.Count; i++)
  347. //{
  348. // m_udpServers[i].ServerListener();
  349. // }
  350. }
  351. protected override void Initialize()
  352. {
  353. //
  354. // Called from base.StartUp()
  355. //
  356. m_httpServerPort = m_networkServersInfo.HttpListenerPort;
  357. IAssetServer assetServer;
  358. if (m_assetStorage == "db4o")
  359. {
  360. assetServer = new LocalAssetServer();
  361. }
  362. else if (m_assetStorage == "grid")
  363. {
  364. assetServer = new GridAssetClient(m_networkServersInfo.AssetURL);
  365. }
  366. else
  367. {
  368. SQLAssetServer sqlAssetServer = new SQLAssetServer(m_standaloneAssetPlugin, m_standaloneAssetSource);
  369. sqlAssetServer.LoadDefaultAssets();
  370. assetServer = sqlAssetServer;
  371. }
  372. m_assetCache = new AssetCache(assetServer);
  373. m_sceneManager.OnRestartSim += handleRestartRegion;
  374. }
  375. public LLUUID CreateUser(string tempfirstname, string templastname, string tempPasswd, uint regX, uint regY)
  376. {
  377. return m_commsManager.AddUser(tempfirstname,templastname,tempPasswd,regX,regY);
  378. }
  379. /// <summary>
  380. /// Execute the region creation process. This includes setting up scene infrastructure.
  381. /// </summary>
  382. /// <param name="regionInfo"></param>
  383. /// <param name="portadd_flag"></param>
  384. /// <returns></returns>
  385. public UDPServer CreateRegion(RegionInfo regionInfo, bool portadd_flag) {
  386. return CreateRegion(regionInfo, portadd_flag, false);
  387. }
  388. /// <summary>
  389. /// Execute the region creation process. This includes setting up scene infrastructure.
  390. /// </summary>
  391. /// <param name="regionInfo"></param>
  392. /// <param name="portadd_flag"></param>
  393. /// <returns></returns>
  394. public UDPServer CreateRegion(RegionInfo regionInfo) {
  395. return CreateRegion(regionInfo, false, true);
  396. }
  397. /// <summary>
  398. /// Execute the region creation process. This includes setting up scene infrastructure.
  399. /// </summary>
  400. /// <param name="regionInfo"></param>
  401. /// <param name="portadd_flag"></param>
  402. /// <param name="do_post_init"></param>
  403. /// <returns></returns>
  404. public UDPServer CreateRegion(RegionInfo regionInfo, bool portadd_flag, bool do_post_init)
  405. {
  406. int port = regionInfo.InternalEndPoint.Port;
  407. // set initial RegionID to originRegionID in RegionInfo. (it needs for loding prims)
  408. regionInfo.originRegionID = regionInfo.RegionID;
  409. // set initial ServerURI
  410. regionInfo.ServerURI = "http://" + regionInfo.ExternalHostName
  411. + ":" + regionInfo.InternalEndPoint.Port.ToString();
  412. regionInfo.HttpPort = m_httpServerPort;
  413. if ((proxyUrl.Length > 0) && (portadd_flag))
  414. {
  415. // set proxy url to RegionInfo
  416. regionInfo.proxyUrl = proxyUrl;
  417. Util.XmlRpcCommand(proxyUrl, "AddPort", port, port + proxyOffset, regionInfo.ExternalHostName);
  418. }
  419. UDPServer udpServer;
  420. Scene scene = SetupScene(regionInfo, proxyOffset, out udpServer, m_permissions);
  421. m_log.Info("[MODULES]: Loading Region's modules");
  422. List<IRegionModule> modules = m_moduleLoader.PickupModules(scene, ".");
  423. // This needs to be ahead of the script engine load, so the
  424. // script module can pick up events exposed by a module
  425. m_moduleLoader.InitialiseSharedModules(scene);
  426. //m_moduleLoader.PickupModules(scene, "ScriptEngines");
  427. //m_moduleLoader.LoadRegionModules(Path.Combine("ScriptEngines", m_scriptEngine), scene);
  428. if (string.IsNullOrEmpty(m_scriptEngine))
  429. {
  430. m_log.Info("[MODULES]: No script engien module specified");
  431. }
  432. else
  433. {
  434. m_log.Info("[MODULES]: Loading scripting engine modules");
  435. foreach (string module in m_scriptEngine.Split(','))
  436. {
  437. string mod = module.Trim(" \t".ToCharArray()); // Clean up name
  438. m_log.Info("[MODULES]: Loading scripting engine: " + mod);
  439. try
  440. {
  441. m_moduleLoader.LoadRegionModules(Path.Combine("ScriptEngines", mod), scene);
  442. }
  443. catch (Exception ex)
  444. {
  445. m_log.Error("[MODULES]: Failed to load script engine: " + ex.ToString());
  446. }
  447. }
  448. }
  449. scene.SetModuleInterfaces();
  450. //moved these here as the terrain texture has to be created after the modules are initialized
  451. // and has to happen before the region is registered with the grid.
  452. scene.CreateTerrainTexture(true);
  453. scene.RegisterRegionWithGrid();
  454. //Server side object editing permissions checking
  455. scene.PermissionsMngr.BypassPermissions = !m_permissions;
  456. // We need to do this after we've initialized the scripting engines.
  457. scene.StartScripts();
  458. scene.loadAllLandObjectsFromStorage(regionInfo.originRegionID);
  459. scene.LandChannel.performParcelPrimCountUpdate();
  460. m_sceneManager.Add(scene);
  461. m_udpServers.Add(udpServer);
  462. m_regionData.Add(regionInfo);
  463. udpServer.ServerListener();
  464. if (do_post_init)
  465. {
  466. foreach (IRegionModule module in modules)
  467. {
  468. module.PostInitialise();
  469. }
  470. }
  471. return udpServer;
  472. }
  473. protected override StorageManager CreateStorageManager(string connectionstring)
  474. {
  475. return new StorageManager(m_storageDll, connectionstring, m_storagePersistPrimInventories);
  476. }
  477. protected override Scene CreateScene(RegionInfo regionInfo, StorageManager storageManager,
  478. AgentCircuitManager circuitManager)
  479. {
  480. PermissionManager permissionManager = new PermissionManager();
  481. SceneCommunicationService sceneGridService = new SceneCommunicationService(m_commsManager);
  482. return
  483. new Scene(regionInfo, circuitManager, permissionManager, m_commsManager, sceneGridService, m_assetCache,
  484. storageManager, m_httpServer,
  485. m_moduleLoader, m_dumpAssetsToFile, m_physicalPrim, m_see_into_region_from_neighbor);
  486. }
  487. public void handleRestartRegion(RegionInfo whichRegion)
  488. {
  489. m_log.Error("[OPENSIM MAIN]: Got restart signal from SceneManager");
  490. // Shutting down the UDP server
  491. bool foundUDPServer = false;
  492. int UDPServerElement = 0;
  493. for (int i = 0; i < m_udpServers.Count; i++)
  494. {
  495. if (m_udpServers[i].RegionHandle == whichRegion.RegionHandle)
  496. {
  497. UDPServerElement = i;
  498. foundUDPServer = true;
  499. break;
  500. }
  501. }
  502. if (foundUDPServer)
  503. {
  504. // m_udpServers[UDPServerElement].Server.End
  505. m_udpServers[UDPServerElement].Server.Close();
  506. m_udpServers.RemoveAt(UDPServerElement);
  507. }
  508. //Removing the region from the sim's database of regions..
  509. int RegionHandleElement = -1;
  510. for (int i = 0; i < m_regionData.Count; i++)
  511. {
  512. if (whichRegion.RegionHandle == m_regionData[i].RegionHandle)
  513. {
  514. RegionHandleElement = i;
  515. }
  516. }
  517. if (RegionHandleElement >= 0)
  518. {
  519. m_regionData.RemoveAt(RegionHandleElement);
  520. }
  521. CreateRegion(whichRegion, true);
  522. //UDPServer restartingRegion = CreateRegion(whichRegion);
  523. //restartingRegion.ServerListener();
  524. //m_sceneManager.SendSimOnlineNotification(restartingRegion.RegionHandle);
  525. }
  526. # region Setup methods
  527. protected override PhysicsScene GetPhysicsScene()
  528. {
  529. return GetPhysicsScene(m_physicsEngine, m_meshEngineName);
  530. }
  531. protected class SimStatusHandler : IStreamedRequestHandler
  532. {
  533. public byte[] Handle(string path, Stream request)
  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. protected virtual void InternalShutdown()
  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. // needs to be called by Shutdown() method
  567. // Environment.Exit(0);
  568. }
  569. public virtual void Shutdown()
  570. {
  571. InternalShutdown();
  572. ApocalypseNow();
  573. }
  574. /// <summary>
  575. /// Get the start time and up time of Region server
  576. /// </summary>
  577. /// <param name="starttime">The first out parameter describing when the Region server started</param>
  578. /// <param name="uptime">The second out parameter describing how long the Region server has run</param>
  579. public void GetRunTime(out string starttime, out string uptime)
  580. {
  581. starttime = m_startuptime.ToString();
  582. uptime = (DateTime.Now - m_startuptime).ToString();
  583. }
  584. /// <summary>
  585. /// Get the number of the avatars in the Region server
  586. /// </summary>
  587. /// <param name="usernum">The first out parameter describing the number of all the avatars in the Region server</param>
  588. public void GetAvatarNumber(out int usernum)
  589. {
  590. usernum = m_sceneManager.GetCurrentSceneAvatars().Count;
  591. }
  592. /// <summary>
  593. /// Get the number of the avatars in the Region server
  594. /// </summary>
  595. /// <param name="usernum">The first out parameter describing the number of all the avatars in the Region server</param>
  596. public void GetRegionNumber(out int regionnum)
  597. {
  598. int accounter = 0;
  599. //List<string> regionNameList = new List<string>();
  600. m_sceneManager.ForEachScene(delegate(Scene scene) {
  601. accounter++;
  602. });
  603. regionnum = accounter;
  604. }
  605. }
  606. }