OpenSimMain.cs 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130
  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. */
  28. using System;
  29. using System.Collections.Generic;
  30. using System.IO;
  31. using System.Text;
  32. using System.Threading;
  33. using System.Timers;
  34. using libsecondlife;
  35. using Mono.Addins;
  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. using Timer=System.Timers.Timer;
  50. namespace OpenSim
  51. {
  52. public delegate void ConsoleCommand(string[] comParams);
  53. public class OpenSimMain : RegionApplicationBase, conscmd_callback
  54. {
  55. private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  56. private const string DEFAULT_PRIM_BACKUP_FILENAME = "prim-backup.xml";
  57. public string m_physicsEngine;
  58. public string m_meshEngineName;
  59. public string m_scriptEngine;
  60. public bool m_sandbox;
  61. public bool user_accounts;
  62. public bool m_gridLocalAsset;
  63. public bool m_see_into_region_from_neighbor;
  64. protected LocalLoginService m_loginService;
  65. protected string m_storageDll;
  66. protected string m_startupCommandsFile;
  67. protected string m_shutdownCommandsFile;
  68. protected List<UDPServer> m_udpServers = new List<UDPServer>();
  69. protected List<RegionInfo> m_regionData = new List<RegionInfo>();
  70. private bool m_verbose;
  71. private bool m_physicalPrim;
  72. private bool m_permissions = false;
  73. private bool m_standaloneAuthenticate = false;
  74. private string m_standaloneWelcomeMessage = null;
  75. private string m_standaloneInventoryPlugin;
  76. private string m_standaloneAssetPlugin;
  77. private string m_standaloneUserPlugin;
  78. private string m_assetStorage = "sqlite";
  79. private string m_timedScript = "disabled";
  80. private Timer m_scriptTimer;
  81. public ConsoleCommand CreateAccount = null;
  82. private bool m_dumpAssetsToFile;
  83. private List<IApplicationPlugin> m_plugins = new List<IApplicationPlugin>();
  84. private IniConfigSource m_config;
  85. public IniConfigSource ConfigSource
  86. {
  87. get { return m_config; }
  88. set { m_config = value; }
  89. }
  90. public BaseHttpServer HttpServer
  91. {
  92. get { return m_httpServer; }
  93. }
  94. private ModuleLoader m_moduleLoader;
  95. public ModuleLoader ModuleLoader
  96. {
  97. get { return m_moduleLoader; }
  98. set { m_moduleLoader = value; }
  99. }
  100. public OpenSimMain(IConfigSource configSource)
  101. : base()
  102. {
  103. IConfig startupConfig = configSource.Configs["Startup"];
  104. // The Mono addin manager (in Mono.Addins.dll version 0.2.0.0) occasionally seems to corrupt its addin cache
  105. // Hence, as a temporary solution we'll remove it before each startup
  106. if (Directory.Exists("addin-db-000"))
  107. {
  108. Directory.Delete("addin-db-000", true);
  109. }
  110. AddinManager.Initialize(".");
  111. AddinManager.Registry.Update(null);
  112. Application.iniFilePath = startupConfig.GetString("inifile", "OpenSim.ini");
  113. m_config = new IniConfigSource();
  114. //check for .INI file (either default or name passed in command line)
  115. if (File.Exists(Application.iniFilePath))
  116. {
  117. m_config.Merge(new IniConfigSource(Application.iniFilePath));
  118. m_config.Merge(configSource);
  119. }
  120. else
  121. {
  122. Application.iniFilePath = Path.Combine(Util.configDir(), Application.iniFilePath);
  123. if (File.Exists(Application.iniFilePath))
  124. {
  125. m_config.Merge(new IniConfigSource(Application.iniFilePath));
  126. m_config.Merge(configSource);
  127. }
  128. else
  129. {
  130. // no default config files, so set default values, and save it
  131. m_config.Merge(DefaultConfig());
  132. m_config.Merge(configSource);
  133. m_config.Save(Application.iniFilePath);
  134. }
  135. }
  136. ReadConfigSettings();
  137. }
  138. public static IConfigSource DefaultConfig()
  139. {
  140. IConfigSource DefaultConfig = new IniConfigSource();
  141. if (DefaultConfig.Configs["Startup"] == null)
  142. DefaultConfig.AddConfig("Startup");
  143. IConfig config = DefaultConfig.Configs["Startup"];
  144. if (config != null)
  145. {
  146. config.Set("gridmode", false);
  147. config.Set("physics", "basicphysics");
  148. config.Set("verbose", true);
  149. config.Set("physical_prim", true);
  150. config.Set("see_into_this_sim_from_neighbor", true);
  151. config.Set("serverside_object_permissions", false);
  152. config.Set("storage_plugin", "OpenSim.Framework.Data.SQLite.dll");
  153. config.Set("storage_connection_string", "URI=file:OpenSim.db,version=3");
  154. config.Set("storage_prim_inventories", true);
  155. config.Set("startup_console_commands_file", String.Empty);
  156. config.Set("shutdown_console_commands_file", String.Empty);
  157. config.Set("script_engine", "OpenSim.Region.ScriptEngine.DotNetEngine.dll");
  158. config.Set("asset_database", "sqlite");
  159. }
  160. if (DefaultConfig.Configs["StandAlone"] == null)
  161. DefaultConfig.AddConfig("StandAlone");
  162. config = DefaultConfig.Configs["StandAlone"];
  163. if (config != null)
  164. {
  165. config.Set("accounts_authenticate", false);
  166. config.Set("welcome_message", "Welcome to OpenSim");
  167. config.Set("inventory_plugin", "OpenSim.Framework.Data.SQLite.dll");
  168. config.Set("userDatabase_plugin", "OpenSim.Framework.Data.SQLite.dll");
  169. config.Set("asset_plugin", "OpenSim.Framework.Data.SQLite.dll");
  170. config.Set("dump_assets_to_file", false);
  171. }
  172. if (DefaultConfig.Configs["Network"] == null)
  173. DefaultConfig.AddConfig("Network");
  174. config = DefaultConfig.Configs["Network"];
  175. if (config != null)
  176. {
  177. config.Set("default_location_x", 1000);
  178. config.Set("default_location_y", 1000);
  179. config.Set("http_listener_port", NetworkServersInfo.DefaultHttpListenerPort);
  180. config.Set("remoting_listener_port", NetworkServersInfo.RemotingListenerPort);
  181. config.Set("grid_server_url", "http://127.0.0.1:" + GridConfig.DefaultHttpPort.ToString());
  182. config.Set("grid_send_key", "null");
  183. config.Set("grid_recv_key", "null");
  184. config.Set("user_server_url", "http://127.0.0.1:" + UserConfig.DefaultHttpPort.ToString());
  185. config.Set("user_send_key", "null");
  186. config.Set("user_recv_key", "null");
  187. config.Set("asset_server_url", "http://127.0.0.1:" + AssetConfig.DefaultHttpPort.ToString());
  188. config.Set("inventory_server_url", "http://127.0.0.1:" + InventoryConfig.DefaultHttpPort.ToString());
  189. }
  190. if (DefaultConfig.Configs["RemoteAdmin"] == null)
  191. DefaultConfig.AddConfig("RemoteAdmin");
  192. config = DefaultConfig.Configs["RemoteAdmin"];
  193. if (config != null)
  194. {
  195. config.Set("enabled", "false");
  196. }
  197. return DefaultConfig;
  198. }
  199. protected void ReadConfigSettings()
  200. {
  201. m_networkServersInfo = new NetworkServersInfo();
  202. IConfig startupConfig = m_config.Configs["Startup"];
  203. if (startupConfig != null)
  204. {
  205. m_sandbox = !startupConfig.GetBoolean("gridmode", false);
  206. m_physicsEngine = startupConfig.GetString("physics", "basicphysics");
  207. m_meshEngineName = startupConfig.GetString("meshing", "ZeroMesher");
  208. // TODO: since log4net changes, verbose flag doesn't do anything
  209. m_verbose = startupConfig.GetBoolean("verbose", true);
  210. m_physicalPrim = startupConfig.GetBoolean("physical_prim", true);
  211. m_see_into_region_from_neighbor = startupConfig.GetBoolean("see_into_this_sim_from_neighbor", true);
  212. m_permissions = startupConfig.GetBoolean("serverside_object_permissions", false);
  213. m_storageDll = startupConfig.GetString("storage_plugin", "OpenSim.Framework.Data.SQLite.dll");
  214. if (m_storageDll == "OpenSim.DataStore.MonoSqlite.dll")
  215. {
  216. m_storageDll = "OpenSim.Framework.Data.SQLite.dll";
  217. Console.WriteLine("WARNING: OpenSim.DataStore.MonoSqlite.dll is deprecated. Set storage_plugin to OpenSim.Framework.Data.SQLite.dll.");
  218. Thread.Sleep(3000);
  219. }
  220. m_storageConnectionString
  221. = startupConfig.GetString("storage_connection_string", "URI=file:OpenSim.db,version=3");
  222. m_storagePersistPrimInventories
  223. = startupConfig.GetBoolean("storage_prim_inventories", true);
  224. m_startupCommandsFile = startupConfig.GetString("startup_console_commands_file", String.Empty);
  225. m_shutdownCommandsFile = startupConfig.GetString("shutdown_console_commands_file", String.Empty);
  226. m_scriptEngine = startupConfig.GetString("script_engine", "OpenSim.Region.ScriptEngine.DotNetEngine.dll");
  227. m_assetStorage = startupConfig.GetString("asset_database", "sqlite");
  228. m_timedScript = startupConfig.GetString("timer_Script", "disabled");
  229. }
  230. IConfig standaloneConfig = m_config.Configs["StandAlone"];
  231. if (standaloneConfig != null)
  232. {
  233. m_standaloneAuthenticate = standaloneConfig.GetBoolean("accounts_authenticate", false);
  234. m_standaloneWelcomeMessage = standaloneConfig.GetString("welcome_message", "Welcome to OpenSim");
  235. m_standaloneInventoryPlugin =
  236. standaloneConfig.GetString("inventory_plugin", "OpenSim.Framework.Data.SQLite.dll");
  237. m_standaloneUserPlugin =
  238. standaloneConfig.GetString("userDatabase_plugin", "OpenSim.Framework.Data.SQLite.dll");
  239. m_standaloneAssetPlugin =
  240. standaloneConfig.GetString("asset_plugin", "OpenSim.Framework.Data.SQLite.dll");
  241. m_dumpAssetsToFile = standaloneConfig.GetBoolean("dump_assets_to_file", false);
  242. }
  243. //if (!m_sandbox)
  244. //m_SendChildAgentTaskData = false;
  245. m_networkServersInfo.loadFromConfiguration(m_config);
  246. }
  247. /// <summary>
  248. /// Performs initialisation of the scene, such as loading configuration from disk.
  249. /// </summary>
  250. public override void StartUp()
  251. {
  252. //
  253. // Called from app startup (OpenSim.Application)
  254. //
  255. m_console = CreateConsole();
  256. MainConsole.Instance = m_console;
  257. StatsManager.StartCollectingSimExtraStats();
  258. // Do baseclass startup sequence: OpenSim.Region.ClientStack.RegionApplicationBase.StartUp
  259. // TerrainManager, StorageManager, HTTP Server
  260. // This base will call abstract Initialize
  261. base.StartUp();
  262. // StandAlone mode? m_sandbox is determined by !startupConfig.GetBoolean("gridmode", false)
  263. if (m_sandbox)
  264. {
  265. LocalInventoryService inventoryService = new LocalInventoryService();
  266. inventoryService.AddPlugin(m_standaloneInventoryPlugin);
  267. LocalUserServices userService =
  268. new LocalUserServices(m_networkServersInfo, m_networkServersInfo.DefaultHomeLocX,
  269. m_networkServersInfo.DefaultHomeLocY, inventoryService);
  270. userService.AddPlugin(m_standaloneUserPlugin);
  271. LocalBackEndServices backendService = new LocalBackEndServices();
  272. CommunicationsLocal localComms =
  273. new CommunicationsLocal(m_networkServersInfo, m_httpServer, m_assetCache, userService,
  274. inventoryService, backendService, backendService, m_dumpAssetsToFile);
  275. m_commsManager = localComms;
  276. m_loginService =
  277. new LocalLoginService(userService, m_standaloneWelcomeMessage, localComms, m_networkServersInfo,
  278. m_standaloneAuthenticate);
  279. m_loginService.OnLoginToRegion += backendService.AddNewSession;
  280. // XMLRPC action
  281. m_httpServer.AddXmlRPCHandler("login_to_simulator", m_loginService.XmlRpcLoginMethod);
  282. // provides the web form login
  283. m_httpServer.AddHTTPHandler("login", m_loginService.ProcessHTMLLogin);
  284. // Provides the LLSD login
  285. m_httpServer.SetLLSDHandler(m_loginService.LLSDLoginMethod);
  286. if (m_standaloneAuthenticate)
  287. {
  288. CreateAccount = localComms.doCreate;
  289. }
  290. }
  291. else
  292. {
  293. // We are in grid mode
  294. m_commsManager = new CommunicationsOGS1(m_networkServersInfo, m_httpServer, m_assetCache);
  295. m_httpServer.AddStreamHandler(new SimStatusHandler());
  296. }
  297. // Create a ModuleLoader instance
  298. m_moduleLoader = new ModuleLoader(m_config);
  299. ExtensionNodeList nodes = AddinManager.GetExtensionNodes("/OpenSim/Startup");
  300. m_log.InfoFormat("[PLUGINS]: Loading {0} OpenSim application plugins", nodes.Count);
  301. foreach (TypeExtensionNode node in nodes)
  302. {
  303. IApplicationPlugin plugin = (IApplicationPlugin)node.CreateInstance();
  304. plugin.Initialise(this);
  305. m_plugins.Add(plugin);
  306. }
  307. // Start UDP servers
  308. //for (int i = 0; i < m_udpServers.Count; i++)
  309. //{
  310. // m_udpServers[i].ServerListener();
  311. // }
  312. //Run Startup Commands
  313. if (m_startupCommandsFile != String.Empty)
  314. {
  315. RunCommandScript(m_startupCommandsFile);
  316. }
  317. else
  318. {
  319. m_log.Info("[STARTUP]: No startup command script specified. Moving on...");
  320. }
  321. // Start timer script (run a script every xx seconds)
  322. if (m_timedScript != "disabled")
  323. {
  324. m_scriptTimer = new Timer();
  325. m_scriptTimer.Enabled = true;
  326. m_scriptTimer.Interval = (int)(1200 * 1000);
  327. m_scriptTimer.Elapsed += new ElapsedEventHandler(RunAutoTimerScript);
  328. }
  329. // We are done with startup
  330. m_log.Info("[STARTUP]: Startup complete, serving " + m_udpServers.Count.ToString() + " region(s)");
  331. }
  332. protected override void Initialize()
  333. {
  334. //
  335. // Called from base.StartUp()
  336. //
  337. m_httpServerPort = m_networkServersInfo.HttpListenerPort;
  338. IAssetServer assetServer;
  339. if (m_assetStorage == "db4o")
  340. {
  341. assetServer = new LocalAssetServer();
  342. }
  343. else if (m_assetStorage == "grid")
  344. {
  345. assetServer = new GridAssetClient(m_networkServersInfo.AssetURL);
  346. }
  347. else if (m_assetStorage == "mssql")
  348. {
  349. SQLAssetServer sqlAssetServer = new SQLAssetServer("OpenSim.Framework.Data.MSSQL.dll");
  350. sqlAssetServer.LoadDefaultAssets();
  351. assetServer = sqlAssetServer;
  352. //assetServer = new GridAssetClient(String.Empty);
  353. }
  354. else
  355. {
  356. SQLAssetServer sqlAssetServer = new SQLAssetServer(m_standaloneAssetPlugin);
  357. sqlAssetServer.LoadDefaultAssets();
  358. assetServer = sqlAssetServer;
  359. }
  360. m_assetCache = new AssetCache(assetServer);
  361. // m_assetCache = new assetCache("OpenSim.Region.GridInterfaces.Local.dll", m_networkServersInfo.AssetURL, m_networkServersInfo.AssetSendKey);
  362. m_sceneManager.OnRestartSim += handleRestartRegion;
  363. }
  364. public LLUUID CreateUser(string tempfirstname, string templastname, string tempPasswd, uint regX, uint regY)
  365. {
  366. return m_commsManager.AddUser(tempfirstname,templastname,tempPasswd,regX,regY);
  367. }
  368. public UDPServer CreateRegion(RegionInfo regionInfo)
  369. {
  370. UDPServer udpServer;
  371. Scene scene = SetupScene(regionInfo, out udpServer, m_permissions);
  372. m_log.Info("[MODULES]: Loading Region's modules");
  373. m_moduleLoader.PickupModules(scene, ".");
  374. //m_moduleLoader.PickupModules(scene, "ScriptEngines");
  375. //m_moduleLoader.LoadRegionModules(Path.Combine("ScriptEngines", m_scriptEngine), scene);
  376. m_log.Info("[MODULES]: Loading scripting engine modules");
  377. foreach (string module in m_scriptEngine.Split(','))
  378. {
  379. string mod = module.Trim(" \t".ToCharArray()); // Clean up name
  380. m_log.Info("[MODULES]: Loading scripting engine: " + mod);
  381. try
  382. {
  383. m_moduleLoader.LoadRegionModules(Path.Combine("ScriptEngines", mod), scene);
  384. }
  385. catch (Exception ex)
  386. {
  387. m_log.Error("[MODULES]: Failed to load script engine: " + ex.ToString());
  388. }
  389. }
  390. m_moduleLoader.InitialiseSharedModules(scene);
  391. scene.SetModuleInterfaces();
  392. //Server side object editing permissions checking
  393. scene.PermissionsMngr.BypassPermissions = !m_permissions;
  394. // We need to do this after we've initialized the scripting engines.
  395. scene.StartScripts();
  396. m_sceneManager.Add(scene);
  397. m_udpServers.Add(udpServer);
  398. m_regionData.Add(regionInfo);
  399. udpServer.ServerListener();
  400. return udpServer;
  401. }
  402. private static void CreateDefaultRegionInfoXml(string fileName)
  403. {
  404. new RegionInfo("DEFAULT REGION CONFIG", fileName,false);
  405. }
  406. protected override StorageManager CreateStorageManager(string connectionstring)
  407. {
  408. return new StorageManager(m_storageDll, connectionstring, m_storagePersistPrimInventories);
  409. }
  410. protected override Scene CreateScene(RegionInfo regionInfo, StorageManager storageManager,
  411. AgentCircuitManager circuitManager)
  412. {
  413. PermissionManager permissionManager = new PermissionManager();
  414. SceneCommunicationService sceneGridService = new SceneCommunicationService(m_commsManager);
  415. return
  416. new Scene(regionInfo, circuitManager, permissionManager, m_commsManager, sceneGridService, m_assetCache,
  417. storageManager, m_httpServer,
  418. m_moduleLoader, m_dumpAssetsToFile, m_physicalPrim, m_see_into_region_from_neighbor);
  419. }
  420. public void handleRestartRegion(RegionInfo whichRegion)
  421. {
  422. m_log.Error("[MAIN]: Got restart signal from SceneManager");
  423. // Shutting down the UDP server
  424. bool foundUDPServer = false;
  425. int UDPServerElement = 0;
  426. for (int i = 0; i < m_udpServers.Count; i++)
  427. {
  428. if (m_udpServers[i].RegionHandle == whichRegion.RegionHandle)
  429. {
  430. UDPServerElement = i;
  431. foundUDPServer = true;
  432. break;
  433. }
  434. }
  435. if (foundUDPServer)
  436. {
  437. // m_udpServers[UDPServerElement].Server.End
  438. m_udpServers[UDPServerElement].Server.Close();
  439. m_udpServers.RemoveAt(UDPServerElement);
  440. }
  441. //Removing the region from the sim's database of regions..
  442. int RegionHandleElement = -1;
  443. for (int i = 0; i < m_regionData.Count; i++)
  444. {
  445. if (whichRegion.RegionHandle == m_regionData[i].RegionHandle)
  446. {
  447. RegionHandleElement = i;
  448. }
  449. }
  450. if (RegionHandleElement >= 0)
  451. {
  452. m_regionData.RemoveAt(RegionHandleElement);
  453. }
  454. CreateRegion(whichRegion);
  455. //UDPServer restartingRegion = CreateRegion(whichRegion);
  456. //restartingRegion.ServerListener();
  457. //m_sceneManager.SendSimOnlineNotification(restartingRegion.RegionHandle);
  458. }
  459. protected override ConsoleBase CreateConsole()
  460. {
  461. return new ConsoleBase("Region", this);
  462. }
  463. # region Setup methods
  464. protected override PhysicsScene GetPhysicsScene()
  465. {
  466. return GetPhysicsScene(m_physicsEngine, m_meshEngineName);
  467. }
  468. private class SimStatusHandler : IStreamedRequestHandler
  469. {
  470. public byte[] Handle(string path, Stream request)
  471. {
  472. return Encoding.UTF8.GetBytes("OK");
  473. }
  474. public string ContentType
  475. {
  476. get { return "text/plain"; }
  477. }
  478. public string HttpMethod
  479. {
  480. get { return "GET"; }
  481. }
  482. public string Path
  483. {
  484. get { return "/simstatus/"; }
  485. }
  486. }
  487. #endregion
  488. /// <summary>
  489. /// Performs any last-minute sanity checking and shuts down the region server
  490. /// </summary>
  491. public virtual void Shutdown()
  492. {
  493. if (m_startupCommandsFile != String.Empty)
  494. {
  495. RunCommandScript(m_shutdownCommandsFile);
  496. }
  497. m_log.Info("[SHUTDOWN]: Closing all threads");
  498. m_log.Info("[SHUTDOWN]: Killing listener thread");
  499. m_log.Info("[SHUTDOWN]: Killing clients");
  500. // TODO: implement this
  501. m_log.Info("[SHUTDOWN]: Closing console and terminating");
  502. m_sceneManager.Close();
  503. m_console.Close();
  504. Environment.Exit(0);
  505. }
  506. private void RunAutoTimerScript(object sender, EventArgs e)
  507. {
  508. if (m_timedScript != "disabled")
  509. {
  510. RunCommandScript(m_timedScript);
  511. }
  512. }
  513. #region Console Commands
  514. /// <summary>
  515. ///
  516. /// </summary>
  517. /// <param name="fileName"></param>
  518. private void RunCommandScript(string fileName)
  519. {
  520. m_log.Info("[COMMANDFILE]: Running " + fileName);
  521. if (File.Exists(fileName))
  522. {
  523. StreamReader readFile = File.OpenText(fileName);
  524. string currentCommand = String.Empty;
  525. while ((currentCommand = readFile.ReadLine()) != null)
  526. {
  527. if (currentCommand != String.Empty)
  528. {
  529. m_log.Info("[COMMANDFILE]: Running '" + currentCommand + "'");
  530. m_console.RunCommand(currentCommand);
  531. }
  532. }
  533. }
  534. else
  535. {
  536. m_log.Error("[COMMANDFILE]: Command script missing. Can not run commands");
  537. }
  538. }
  539. /// <summary>
  540. /// Runs commands issued by the server console from the operator
  541. /// </summary>
  542. /// <param name="command">The first argument of the parameter (the command)</param>
  543. /// <param name="cmdparams">Additional arguments passed to the command</param>
  544. public override void RunCmd(string command, string[] cmdparams)
  545. {
  546. base.RunCmd(command, cmdparams);
  547. switch (command)
  548. {
  549. case "clear-assets":
  550. m_assetCache.Clear();
  551. break;
  552. case "set-time":
  553. m_sceneManager.SetCurrentSceneTimePhase(Convert.ToInt32(cmdparams[0]));
  554. break;
  555. case "force-update":
  556. m_console.Notice("Updating all clients");
  557. m_sceneManager.ForceCurrentSceneClientUpdate();
  558. break;
  559. case "edit-scale":
  560. if (cmdparams.Length == 4)
  561. {
  562. m_sceneManager.HandleEditCommandOnCurrentScene(cmdparams);
  563. }
  564. break;
  565. case "debug":
  566. if (cmdparams.Length > 0)
  567. {
  568. Debug(cmdparams);
  569. }
  570. break;
  571. case "scene-debug":
  572. if (cmdparams.Length == 3) {
  573. if (m_sceneManager.CurrentScene == null) {
  574. m_console.Error("CONSOLE", "Please use 'change-region <regioname>' first");
  575. } else {
  576. m_sceneManager.CurrentScene.SetSceneCoreDebug(!System.Convert.ToBoolean(cmdparams[0]), !System.Convert.ToBoolean(cmdparams[1]), !System.Convert.ToBoolean(cmdparams[2]));
  577. }
  578. } else {
  579. m_console.Error("scene-debug <scripting> <collisions> <physics> (where inside <> is true/false)");
  580. }
  581. break;
  582. case "help":
  583. m_console.Notice("alert - send alert to a designated user or all users.");
  584. m_console.Notice(" alert [First] [Last] [Message] - send an alert to a user. Case sensitive.");
  585. m_console.Notice(" alert general [Message] - send an alert to all users.");
  586. m_console.Notice("backup - trigger a simulator backup");
  587. m_console.Notice("clear-assets - clear asset cache");
  588. m_console.Notice("create user - adds a new user");
  589. m_console.Notice("change-region [name] - sets the region that many of these commands affect.");
  590. m_console.Notice("command-script [filename] - Execute command in a file.");
  591. m_console.Notice("debug - debugging commands");
  592. m_console.Notice(" packet 0..255 - print incoming/outgoing packets (0=off)");
  593. m_console.Notice("scene-debug [scripting] [collision] [physics] - Enable/Disable debug stuff, each can be True/False");
  594. m_console.Notice("edit-scale [prim name] [x] [y] [z] - resize given prim");
  595. m_console.Notice("export-map [filename] - save image of world map");
  596. m_console.Notice("force-update - force an update of prims in the scene");
  597. m_console.Notice("load-xml [filename] - load prims from XML");
  598. m_console.Notice("load-xml2 [filename] - load prims from XML using version 2 format");
  599. m_console.Notice("permissions [true/false] - turn on/off permissions on the scene");
  600. m_console.Notice("quit - equivalent to shutdown.");
  601. m_console.Notice("restart - disconnects all clients and restarts the sims in the instance.");
  602. m_console.Notice("remove-region [name] - remove a region");
  603. m_console.Notice("save-xml [filename] - save prims to XML");
  604. m_console.Notice("save-xml2 [filename] - save prims to XML using version 2 format");
  605. m_console.Notice("script - manually trigger scripts? or script commands?");
  606. m_console.Notice("set-time [x] - set the current scene time phase");
  607. m_console.Notice("show assets - show state of asset cache.");
  608. m_console.Notice("show users - show info about connected users.");
  609. m_console.Notice("show modules - shows info about loaded modules.");
  610. m_console.Notice("show stats - statistical information for this server not displayed in the client");
  611. m_console.Notice("shutdown - disconnect all clients and shutdown.");
  612. m_console.Notice("status - open server status window");
  613. m_console.Notice("config set section field value - set a config value");
  614. m_console.Notice("config get section field - get a config value");
  615. m_console.Notice("config save - save OpenSim.ini");
  616. m_console.Notice("terrain help - show help for terrain commands.");
  617. break;
  618. case "save-xml":
  619. if (cmdparams.Length > 0)
  620. {
  621. m_sceneManager.SaveCurrentSceneToXml(cmdparams[0]);
  622. }
  623. else
  624. {
  625. m_sceneManager.SaveCurrentSceneToXml(DEFAULT_PRIM_BACKUP_FILENAME);
  626. }
  627. break;
  628. case "load-xml":
  629. LLVector3 loadOffset = new LLVector3(0, 0, 0);
  630. if (cmdparams.Length > 0)
  631. {
  632. bool generateNewIDS = false;
  633. if (cmdparams.Length > 1)
  634. {
  635. if (cmdparams[1] == "-newUID")
  636. {
  637. generateNewIDS = true;
  638. }
  639. if (cmdparams.Length > 2)
  640. {
  641. loadOffset.X = (float) Convert.ToDecimal(cmdparams[2]);
  642. if (cmdparams.Length > 3)
  643. {
  644. loadOffset.Y = (float) Convert.ToDecimal(cmdparams[3]);
  645. }
  646. if (cmdparams.Length > 4)
  647. {
  648. loadOffset.Z = (float) Convert.ToDecimal(cmdparams[4]);
  649. }
  650. m_console.Error("loadOffsets <X,Y,Z> = <" + loadOffset.X + "," + loadOffset.Y + "," +
  651. loadOffset.Z + ">");
  652. }
  653. }
  654. m_sceneManager.LoadCurrentSceneFromXml(cmdparams[0], generateNewIDS, loadOffset);
  655. }
  656. else
  657. {
  658. m_sceneManager.LoadCurrentSceneFromXml(DEFAULT_PRIM_BACKUP_FILENAME, false, loadOffset);
  659. }
  660. break;
  661. case "save-xml2":
  662. if (cmdparams.Length > 0)
  663. {
  664. m_sceneManager.SaveCurrentSceneToXml2(cmdparams[0]);
  665. }
  666. else
  667. {
  668. m_sceneManager.SaveCurrentSceneToXml2(DEFAULT_PRIM_BACKUP_FILENAME);
  669. }
  670. break;
  671. case "load-xml2":
  672. if (cmdparams.Length > 0)
  673. {
  674. m_sceneManager.LoadCurrentSceneFromXml2(cmdparams[0]);
  675. }
  676. else
  677. {
  678. m_sceneManager.LoadCurrentSceneFromXml2(DEFAULT_PRIM_BACKUP_FILENAME);
  679. }
  680. break;
  681. case "terrain":
  682. string result = String.Empty;
  683. if (!m_sceneManager.RunTerrainCmdOnCurrentScene(cmdparams, ref result))
  684. {
  685. m_console.Error(result);
  686. }
  687. break;
  688. case "script":
  689. m_sceneManager.SendCommandToCurrentSceneScripts(cmdparams);
  690. break;
  691. case "command-script":
  692. if (cmdparams.Length > 0)
  693. {
  694. RunCommandScript(cmdparams[0]);
  695. }
  696. break;
  697. case "permissions":
  698. // Treats each user as a super-admin when disabled
  699. bool permissions = Convert.ToBoolean(cmdparams[0]);
  700. m_sceneManager.SetBypassPermissionsOnCurrentScene(!permissions);
  701. break;
  702. case "backup":
  703. m_sceneManager.BackupCurrentScene();
  704. break;
  705. case "alert":
  706. m_sceneManager.HandleAlertCommandOnCurrentScene(cmdparams);
  707. break;
  708. case "create":
  709. if (CreateAccount != null)
  710. {
  711. CreateAccount(cmdparams);
  712. }
  713. break;
  714. case "create-region":
  715. CreateRegion(new RegionInfo(cmdparams[0], "Regions/" + cmdparams[1],false));
  716. break;
  717. case "remove-region":
  718. string regName = CombineParams(cmdparams, 0);
  719. Scene killScene;
  720. if (m_sceneManager.TryGetScene(regName, out killScene))
  721. {
  722. if (m_sceneManager.CurrentScene.RegionInfo.RegionID == killScene.RegionInfo.RegionID)
  723. {
  724. m_sceneManager.TrySetCurrentScene("..");
  725. }
  726. m_regionData.Remove(killScene.RegionInfo);
  727. m_sceneManager.CloseScene(killScene);
  728. }
  729. break;
  730. case "quit":
  731. case "shutdown":
  732. Shutdown();
  733. break;
  734. case "restart":
  735. m_sceneManager.RestartCurrentScene();
  736. break;
  737. case "change-region":
  738. if (cmdparams.Length > 0)
  739. {
  740. string regionName = CombineParams(cmdparams, 0);
  741. if (!m_sceneManager.TrySetCurrentScene(regionName))
  742. {
  743. m_console.Error("Couldn't set current region to: " + regionName);
  744. }
  745. }
  746. if (m_sceneManager.CurrentScene == null)
  747. {
  748. m_console.Error("CONSOLE", "Currently at Root level. To change region please use 'change-region <regioname>'");
  749. }
  750. else
  751. {
  752. m_console.Error("CONSOLE", "Current Region: " + m_sceneManager.CurrentScene.RegionInfo.RegionName +
  753. ". To change region please use 'change-region <regioname>'");
  754. }
  755. break;
  756. case "export-map":
  757. if (cmdparams.Length > 0)
  758. {
  759. m_sceneManager.CurrentOrFirstScene.ExportWorldMap(cmdparams[0]);
  760. }
  761. else
  762. {
  763. m_sceneManager.CurrentOrFirstScene.ExportWorldMap("exportmap.jpg");
  764. }
  765. break;
  766. case "config":
  767. string n = command.ToUpper();
  768. if (cmdparams.Length > 0)
  769. {
  770. switch (cmdparams[0].ToLower())
  771. {
  772. case "set":
  773. if (cmdparams.Length < 4)
  774. {
  775. m_console.Error(n, "SYNTAX: " + n + " SET SECTION KEY VALUE");
  776. m_console.Error(n, "EXAMPLE: " + n + " SET ScriptEngine.DotNetEngine NumberOfScriptThreads 5");
  777. }
  778. else
  779. {
  780. IConfig c = DefaultConfig().Configs[cmdparams[1]];
  781. if (c == null)
  782. c = DefaultConfig().AddConfig(cmdparams[1]);
  783. string _value = String.Join(" ", cmdparams, 3, cmdparams.Length - 3);
  784. c.Set(cmdparams[2], _value);
  785. m_config.Merge(c.ConfigSource);
  786. m_console.Error(n, n + " " + n + " " + cmdparams[1] + " " + cmdparams[2] + " " +
  787. _value);
  788. }
  789. break;
  790. case "get":
  791. if (cmdparams.Length < 3)
  792. {
  793. m_console.Error(n, "SYNTAX: " + n + " GET SECTION KEY");
  794. m_console.Error(n, "EXAMPLE: " + n + " GET ScriptEngine.DotNetEngine NumberOfScriptThreads");
  795. }
  796. else
  797. {
  798. IConfig c = DefaultConfig().Configs[cmdparams[1]];
  799. if (c == null)
  800. {
  801. m_console.Notice(n, "Section \"" + cmdparams[1] + "\" does not exist.");
  802. break;
  803. }
  804. else
  805. {
  806. m_console.Notice(n + " GET " + cmdparams[1] + " " + cmdparams[2] + ": " +
  807. c.GetString(cmdparams[2]));
  808. }
  809. }
  810. break;
  811. case "save":
  812. m_console.Notice("Saving configuration file: " + Application.iniFilePath);
  813. m_config.Save(Application.iniFilePath);
  814. break;
  815. }
  816. }
  817. break;
  818. case "modules":
  819. if (cmdparams.Length > 0)
  820. {
  821. switch (cmdparams[0].ToLower())
  822. {
  823. case "list":
  824. foreach (IRegionModule irm in m_moduleLoader.GetLoadedSharedModules)
  825. {
  826. m_console.Notice("Shared region module: " + irm.Name);
  827. }
  828. break;
  829. case "unload":
  830. if (cmdparams.Length > 1)
  831. {
  832. foreach (IRegionModule rm in new System.Collections.ArrayList(m_moduleLoader.GetLoadedSharedModules))
  833. {
  834. if (rm.Name.ToLower() == cmdparams[1].ToLower())
  835. {
  836. m_console.Notice("Unloading module: " + rm.Name);
  837. m_moduleLoader.UnloadModule(rm);
  838. }
  839. }
  840. }
  841. break;
  842. case "load":
  843. if (cmdparams.Length > 1)
  844. {
  845. foreach (Scene s in new System.Collections.ArrayList(m_sceneManager.Scenes))
  846. {
  847. m_console.Notice("Loading module: " + cmdparams[1]);
  848. m_moduleLoader.LoadRegionModules(cmdparams[1], s);
  849. }
  850. }
  851. break;
  852. }
  853. }
  854. break;
  855. case "status":
  856. Framework.ServerStatus.ServerStatus.ShowWindow();
  857. break;
  858. /*
  859. * Temporarily disabled but it would be good to have this - needs to be levered
  860. * in to BaseOpenSimServer (which requires a RunCmd method restrcuture probably)
  861. default:
  862. m_console.Error("Unknown command");
  863. break;
  864. */
  865. }
  866. }
  867. public void Debug(string[] args)
  868. {
  869. switch (args[0])
  870. {
  871. case "packet":
  872. if (args.Length > 1)
  873. {
  874. int newDebug;
  875. if (int.TryParse(args[1], out newDebug))
  876. {
  877. m_sceneManager.SetDebugPacketOnCurrentScene(newDebug);
  878. }
  879. else
  880. {
  881. m_console.Error("packet debug should be 0..2");
  882. }
  883. m_console.Notice("New packet debug: " + newDebug.ToString());
  884. }
  885. break;
  886. default:
  887. m_console.Error("Unknown debug");
  888. break;
  889. }
  890. }
  891. // see BaseOpenSimServer
  892. public override void Show(string ShowWhat)
  893. {
  894. base.Show(ShowWhat);
  895. switch (ShowWhat)
  896. {
  897. case "assets":
  898. m_assetCache.ShowState();
  899. break;
  900. case "users":
  901. m_console.Notice(
  902. String.Format("{0,-16}{1,-16}{2,-37}{3,-16}{4,-22}{5,-16}", "Firstname", "Lastname",
  903. "Agent ID", "Circuit", "IP", "Region"));
  904. foreach (ScenePresence presence in m_sceneManager.GetCurrentSceneAvatars())
  905. {
  906. RegionInfo regionInfo = m_sceneManager.GetRegionInfo(presence.RegionHandle);
  907. string regionName;
  908. System.Net.EndPoint ep = null;
  909. if (regionInfo == null)
  910. {
  911. regionName = "Unresolvable";
  912. }
  913. else
  914. {
  915. regionName = regionInfo.RegionName;
  916. }
  917. for (int i = 0; i < m_udpServers.Count; i++)
  918. {
  919. if (m_udpServers[i].RegionHandle == presence.RegionHandle)
  920. {
  921. m_udpServers[i].clientCircuits_reverse.TryGetValue(presence.ControllingClient.CircuitCode, out ep);
  922. }
  923. }
  924. m_console.Notice(
  925. String.Format("{0,-16}{1,-16}{2,-37}{3,-16}{4,-22}{5,-16}",
  926. presence.Firstname,
  927. presence.Lastname,
  928. presence.UUID,
  929. presence.ControllingClient.CircuitCode,
  930. ep,
  931. regionName));
  932. }
  933. break;
  934. case "modules":
  935. m_console.Notice("The currently loaded shared modules are:");
  936. foreach (IRegionModule module in m_moduleLoader.GetLoadedSharedModules)
  937. {
  938. m_console.Notice("Shared Module: " + module.Name);
  939. }
  940. break;
  941. case "regions":
  942. m_sceneManager.ForEachScene(
  943. delegate(Scene scene)
  944. {
  945. m_console.Notice("Region Name: " + scene.RegionInfo.RegionName + " , Region XLoc: " +
  946. scene.RegionInfo.RegionLocX + " , Region YLoc: " +
  947. scene.RegionInfo.RegionLocY);
  948. });
  949. break;
  950. case "stats":
  951. if (StatsManager.SimExtraStats != null)
  952. {
  953. m_console.Notice(
  954. "STATS", Environment.NewLine + StatsManager.SimExtraStats.Report());
  955. }
  956. else
  957. {
  958. m_console.Notice("Extra sim statistics collection has not been enabled");
  959. }
  960. break;
  961. }
  962. }
  963. private string CombineParams(string[] commandParams, int pos)
  964. {
  965. string result = String.Empty;
  966. for (int i = pos; i < commandParams.Length; i++)
  967. {
  968. result += commandParams[i] + " ";
  969. }
  970. result = result.TrimEnd(' ');
  971. return result;
  972. }
  973. #endregion
  974. }
  975. }