OpenSimMain.cs 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012
  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.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. using Timer=System.Timers.Timer;
  49. namespace OpenSim
  50. {
  51. public delegate void ConsoleCommand(string[] comParams);
  52. public class OpenSimMain : RegionApplicationBase, conscmd_callback
  53. {
  54. private const string DEFAULT_PRIM_BACKUP_FILENAME = "prim-backup.xml";
  55. public string m_physicsEngine;
  56. public string m_meshEngineName;
  57. public string m_scriptEngine;
  58. public bool m_sandbox;
  59. public bool user_accounts;
  60. public bool m_gridLocalAsset;
  61. public bool m_SendChildAgentTaskData;
  62. protected LocalLoginService m_loginService;
  63. protected string m_storageDll;
  64. protected string m_startupCommandsFile;
  65. protected string m_shutdownCommandsFile;
  66. protected List<UDPServer> m_udpServers = new List<UDPServer>();
  67. protected List<RegionInfo> m_regionData = new List<RegionInfo>();
  68. private bool m_verbose;
  69. private bool m_physicalPrim;
  70. private readonly string m_logFilename = "region-console.log";
  71. private bool m_permissions = false;
  72. private bool m_standaloneAuthenticate = false;
  73. private string m_standaloneWelcomeMessage = null;
  74. private string m_standaloneInventoryPlugin;
  75. private string m_standaloneAssetPlugin;
  76. private string m_standaloneUserPlugin;
  77. private string m_assetStorage = "sqlite";
  78. private string m_timedScript = "disabled";
  79. private Timer m_scriptTimer;
  80. public ConsoleCommand CreateAccount = null;
  81. private bool m_dumpAssetsToFile;
  82. private bool m_rexMode = false; //rex
  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. AddinManager.Initialize(".");
  105. AddinManager.Registry.Update(null);
  106. string iniFilePath = startupConfig.GetString("inifile", "OpenSim.ini");
  107. m_config = new IniConfigSource();
  108. //check for .INI file (either default or name passed in command line)
  109. if (File.Exists(iniFilePath))
  110. {
  111. m_config.Merge(new IniConfigSource(iniFilePath));
  112. m_config.Merge(configSource);
  113. }
  114. else
  115. {
  116. iniFilePath = Path.Combine(Util.configDir(), iniFilePath);
  117. if (File.Exists(iniFilePath))
  118. {
  119. m_config.Merge(new IniConfigSource(iniFilePath));
  120. m_config.Merge(configSource);
  121. }
  122. else
  123. {
  124. // no default config files, so set default values, and save it
  125. m_config.Merge(DefaultConfig());
  126. m_config.Merge(configSource);
  127. m_config.Save(iniFilePath);
  128. }
  129. }
  130. ReadConfigSettings();
  131. // rex, added globalconfig for easy access to config values outside OpenSimMain without using parameters.
  132. GlobalSettings.Instance.ConfigSource = m_config;
  133. GlobalSettings.Instance.m_3d_collision_models = m_config.Configs["Startup"].GetBoolean("3d_collision_models", true); // endrex
  134. }
  135. public static IConfigSource DefaultConfig()
  136. {
  137. IConfigSource DefaultConfig = new IniConfigSource();
  138. if (DefaultConfig.Configs["Startup"] == null)
  139. DefaultConfig.AddConfig("Startup");
  140. IConfig config = DefaultConfig.Configs["Startup"];
  141. if (config != null)
  142. {
  143. config.Set("gridmode", false);
  144. config.Set("physics", "basicphysics");
  145. config.Set("verbose", true);
  146. config.Set("physical_prim", true);
  147. config.Set("child_get_tasks", false);
  148. config.Set("serverside_object_permissions", false);
  149. config.Set("storage_plugin", "OpenSim.DataStore.MonoSqlite.dll");
  150. config.Set("storage_connection_string", "URI=file:OpenSim.db,version=3");
  151. config.Set("startup_console_commands_file", "");
  152. config.Set("shutdown_console_commands_file", "");
  153. config.Set("script_engine", "OpenSim.Region.ScriptEngine.DotNetEngine.dll");
  154. config.Set("asset_database", "sqlite");
  155. config.Set("worldlibraryfolder", true); // rex, added
  156. config.Set("replace_assets", true); // rex, added
  157. config.Set("rex_mode", false); //rex
  158. config.Set("3d_collision_models", true); //rex
  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. m_verbose = startupConfig.GetBoolean("verbose", true);
  209. m_physicalPrim = startupConfig.GetBoolean("physical_prim", true);
  210. m_SendChildAgentTaskData = startupConfig.GetBoolean("child_get_tasks", false);
  211. m_permissions = startupConfig.GetBoolean("serverside_object_permissions", false);
  212. m_storageDll = startupConfig.GetString("storage_plugin", "OpenSim.DataStore.MonoSqlite.dll");
  213. m_storageConnectionString
  214. = startupConfig.GetString("storage_connection_string", "URI=file:OpenSim.db,version=3");
  215. m_startupCommandsFile = startupConfig.GetString("startup_console_commands_file", "");
  216. m_shutdownCommandsFile = startupConfig.GetString("shutdown_console_commands_file", "");
  217. m_scriptEngine = startupConfig.GetString("script_engine", "OpenSim.Region.ScriptEngine.DotNetEngine.dll");
  218. m_assetStorage = startupConfig.GetString("asset_database", "sqlite");
  219. m_timedScript = startupConfig.GetString("timer_Script", "disabled");
  220. m_rexMode = startupConfig.GetBoolean("rex_mode", false);//rex
  221. }
  222. IConfig standaloneConfig = m_config.Configs["StandAlone"];
  223. if (standaloneConfig != null)
  224. {
  225. m_standaloneAuthenticate = standaloneConfig.GetBoolean("accounts_authenticate", false);
  226. m_standaloneWelcomeMessage = standaloneConfig.GetString("welcome_message", "Welcome to OpenSim");
  227. m_standaloneInventoryPlugin =
  228. standaloneConfig.GetString("inventory_plugin", "OpenSim.Framework.Data.SQLite.dll");
  229. m_standaloneUserPlugin =
  230. standaloneConfig.GetString("userDatabase_plugin", "OpenSim.Framework.Data.SQLite.dll");
  231. m_standaloneAssetPlugin =
  232. standaloneConfig.GetString("asset_plugin", "OpenSim.Framework.Data.SQLite.dll");
  233. m_dumpAssetsToFile = standaloneConfig.GetBoolean("dump_assets_to_file", false);
  234. }
  235. if (!m_sandbox)
  236. m_SendChildAgentTaskData = false;
  237. m_networkServersInfo.loadFromConfiguration(m_config);
  238. }
  239. /// <summary>
  240. /// Performs initialisation of the scene, such as loading configuration from disk.
  241. /// </summary>
  242. public override void StartUp()
  243. {
  244. //
  245. // Called from app startup (OpenSim.Application)
  246. //
  247. // Create log directory if it doesn't exist
  248. if (!Directory.Exists(Util.logDir()))
  249. {
  250. Directory.CreateDirectory(Util.logDir());
  251. }
  252. // Create a log instance
  253. m_log = CreateLog();
  254. MainLog.Instance = m_log;
  255. // Do baseclass startup sequence: OpenSim.Region.ClientStack.RegionApplicationBase.StartUp
  256. // TerrainManager, StorageManager, HTTP Server
  257. // This base will call abstract Initialize
  258. base.StartUp();
  259. // StandAlone mode? m_sandbox is determined by !startupConfig.GetBoolean("gridmode", false)
  260. if (m_sandbox)
  261. {
  262. LocalInventoryService inventoryService = new LocalInventoryService();
  263. inventoryService.AddPlugin(m_standaloneInventoryPlugin);
  264. LocalUserServices userService =
  265. new LocalUserServices(m_networkServersInfo, m_networkServersInfo.DefaultHomeLocX,
  266. m_networkServersInfo.DefaultHomeLocY, inventoryService);
  267. userService.AddPlugin(m_standaloneUserPlugin);
  268. LocalBackEndServices backendService = new LocalBackEndServices();
  269. CommunicationsLocal localComms =
  270. new CommunicationsLocal(m_networkServersInfo, m_httpServer, m_assetCache, userService,
  271. inventoryService, backendService, backendService, m_dumpAssetsToFile);
  272. m_commsManager = localComms;
  273. m_loginService =
  274. new LocalLoginService(userService, m_standaloneWelcomeMessage, localComms, m_networkServersInfo,
  275. m_standaloneAuthenticate, m_rexMode);
  276. m_loginService.OnLoginToRegion += backendService.AddNewSession;
  277. m_httpServer.AddXmlRPCHandler("login_to_simulator", m_loginService.XmlRpcLoginMethod);
  278. m_httpServer.SetLLSDHandler(m_loginService.LLSDLoginMethod);
  279. if (m_standaloneAuthenticate)
  280. {
  281. CreateAccount = localComms.doCreate;
  282. }
  283. }
  284. else
  285. {
  286. // We are in grid mode
  287. m_commsManager = new CommunicationsOGS1(m_networkServersInfo, m_httpServer, m_assetCache);
  288. m_httpServer.AddStreamHandler(new SimStatusHandler());
  289. }
  290. // Create a ModuleLoader instance
  291. m_moduleLoader = new ModuleLoader(m_log, m_config);
  292. ExtensionNodeList nodes = AddinManager.GetExtensionNodes("/OpenSim/Startup");
  293. MainLog.Instance.Verbose("PLUGINS", "Loading {0} OpenSim application plugins", nodes.Count);
  294. foreach (TypeExtensionNode node in nodes)
  295. {
  296. IApplicationPlugin plugin = (IApplicationPlugin)node.CreateInstance();
  297. plugin.Initialise(this);
  298. m_plugins.Add(plugin);
  299. }
  300. // Start UDP servers
  301. //for (int i = 0; i < m_udpServers.Count; i++)
  302. //{
  303. // m_udpServers[i].ServerListener();
  304. // }
  305. //Run Startup Commands
  306. if (m_startupCommandsFile != "")
  307. {
  308. RunCommandScript(m_startupCommandsFile);
  309. }
  310. else
  311. {
  312. MainLog.Instance.Verbose("STARTUP", "No startup command script specified. Moving on...");
  313. }
  314. // Start timer script (run a script every xx seconds)
  315. if (m_timedScript != "disabled")
  316. {
  317. m_scriptTimer = new Timer();
  318. m_scriptTimer.Enabled = true;
  319. m_scriptTimer.Interval = (int)(1200 * 1000);
  320. m_scriptTimer.Elapsed += new ElapsedEventHandler(RunAutoTimerScript);
  321. }
  322. // We are done with startup
  323. MainLog.Instance.Status("STARTUP",
  324. "Startup complete, serving " + m_udpServers.Count.ToString() + " region(s)");
  325. // When we return now we will be in a wait for input command loop.
  326. }
  327. protected override void Initialize()
  328. {
  329. //
  330. // Called from base.StartUp()
  331. //
  332. m_httpServerPort = m_networkServersInfo.HttpListenerPort;
  333. IAssetServer assetServer;
  334. if (m_assetStorage == "db4o")
  335. {
  336. assetServer = new LocalAssetServer();
  337. }
  338. else if (m_assetStorage == "grid")
  339. {
  340. assetServer = new GridAssetClient(m_networkServersInfo.AssetURL);
  341. }
  342. else if (m_assetStorage == "mssql")
  343. {
  344. SQLAssetServer sqlAssetServer = new SQLAssetServer("OpenSim.Framework.Data.MSSQL.dll");
  345. sqlAssetServer.LoadDefaultAssets();
  346. assetServer = sqlAssetServer;
  347. //assetServer = new GridAssetClient("");
  348. }
  349. else
  350. {
  351. SQLAssetServer sqlAssetServer = new SQLAssetServer(m_standaloneAssetPlugin);
  352. sqlAssetServer.LoadDefaultAssets();
  353. assetServer = sqlAssetServer;
  354. }
  355. m_assetCache = new AssetCache(assetServer, m_log);
  356. // m_assetCache = new assetCache("OpenSim.Region.GridInterfaces.Local.dll", m_networkServersInfo.AssetURL, m_networkServersInfo.AssetSendKey);
  357. m_sceneManager.OnRestartSim += handleRestartRegion;
  358. }
  359. public UDPServer CreateRegion(RegionInfo regionInfo)
  360. {
  361. UDPServer udpServer;
  362. Scene scene = SetupScene(regionInfo, out udpServer, m_permissions);
  363. MainLog.Instance.Verbose("MODULES", "Loading Region's modules");
  364. m_moduleLoader.PickupModules(scene, ".");
  365. //m_moduleLoader.PickupModules(scene, "ScriptEngines");
  366. //m_moduleLoader.LoadRegionModules(Path.Combine("ScriptEngines", m_scriptEngine), scene);
  367. MainLog.Instance.Verbose("MODULES", "Loading scripting engine modules");
  368. m_moduleLoader.LoadRegionModules(Path.Combine("ScriptEngines", m_scriptEngine), scene);
  369. m_moduleLoader.LoadRegionModules(Path.Combine("ScriptEngines", "OpenSim.Region.RexScriptModule.dll"), scene); // rex
  370. m_moduleLoader.InitialiseSharedModules(scene);
  371. scene.SetModuleInterfaces();
  372. //Server side object editing permissions checking
  373. scene.PermissionsMngr.BypassPermissions = !m_permissions;
  374. // We need to do this after we've initialized the scripting engines.
  375. scene.StartScripts();
  376. m_sceneManager.Add(scene);
  377. m_udpServers.Add(udpServer);
  378. m_regionData.Add(regionInfo);
  379. udpServer.ServerListener();
  380. return udpServer;
  381. }
  382. private static void CreateDefaultRegionInfoXml(string fileName)
  383. {
  384. new RegionInfo("DEFAULT REGION CONFIG", fileName,false);
  385. }
  386. protected override StorageManager CreateStorageManager(string connectionstring)
  387. {
  388. return new StorageManager(m_storageDll, connectionstring);
  389. }
  390. protected override Scene CreateScene(RegionInfo regionInfo, StorageManager storageManager,
  391. AgentCircuitManager circuitManager)
  392. {
  393. PermissionManager permissionManager = new PermissionManager();
  394. SceneCommunicationService sceneGridService = new SceneCommunicationService(m_commsManager);
  395. if (m_SendChildAgentTaskData)
  396. {
  397. MainLog.Instance.Error("WARNING",
  398. "Send Child Agent Task Updates is enabled. This is for testing only. It doesn't work on grid mode!");
  399. Thread.Sleep(12000);
  400. }
  401. return
  402. new Scene(regionInfo, circuitManager, permissionManager, m_commsManager, sceneGridService, m_assetCache,
  403. storageManager, m_httpServer,
  404. m_moduleLoader, m_dumpAssetsToFile, m_physicalPrim, m_SendChildAgentTaskData,
  405. m_rexMode);
  406. }
  407. public void handleRestartRegion(RegionInfo whichRegion)
  408. {
  409. MainLog.Instance.Error("MAIN", "Got restart signal from SceneManager");
  410. // Shutting down the UDP server
  411. bool foundUDPServer = false;
  412. int UDPServerElement = 0;
  413. for (int i = 0; i < m_udpServers.Count; i++)
  414. {
  415. if (m_udpServers[i].RegionHandle == whichRegion.RegionHandle)
  416. {
  417. UDPServerElement = i;
  418. foundUDPServer = true;
  419. break;
  420. }
  421. }
  422. if (foundUDPServer)
  423. {
  424. // m_udpServers[UDPServerElement].Server.End
  425. m_udpServers[UDPServerElement].Server.Close();
  426. m_udpServers.RemoveAt(UDPServerElement);
  427. }
  428. //Removing the region from the sim's database of regions..
  429. int RegionHandleElement = -1;
  430. for (int i = 0; i < m_regionData.Count; i++)
  431. {
  432. if (whichRegion.RegionHandle == m_regionData[i].RegionHandle)
  433. {
  434. RegionHandleElement = i;
  435. }
  436. }
  437. if (RegionHandleElement >= 0)
  438. {
  439. m_regionData.RemoveAt(RegionHandleElement);
  440. }
  441. CreateRegion(whichRegion);
  442. //UDPServer restartingRegion = CreateRegion(whichRegion);
  443. //restartingRegion.ServerListener();
  444. //m_sceneManager.SendSimOnlineNotification(restartingRegion.RegionHandle);
  445. }
  446. protected override LogBase CreateLog()
  447. {
  448. if (!Directory.Exists(Util.logDir()))
  449. {
  450. Directory.CreateDirectory(Util.logDir());
  451. }
  452. return new LogBase((Path.Combine(Util.logDir(), m_logFilename)), "Region", this, m_verbose);
  453. }
  454. # region Setup methods
  455. protected override PhysicsScene GetPhysicsScene()
  456. {
  457. return GetPhysicsScene(m_physicsEngine, m_meshEngineName);
  458. }
  459. private class SimStatusHandler : IStreamedRequestHandler
  460. {
  461. public byte[] Handle(string path, Stream request)
  462. {
  463. return Encoding.UTF8.GetBytes("OK");
  464. }
  465. public string ContentType
  466. {
  467. get { return "text/plain"; }
  468. }
  469. public string HttpMethod
  470. {
  471. get { return "GET"; }
  472. }
  473. public string Path
  474. {
  475. get { return "/simstatus/"; }
  476. }
  477. }
  478. #endregion
  479. /// <summary>
  480. /// Performs any last-minute sanity checking and shuts down the region server
  481. /// </summary>
  482. public virtual void Shutdown()
  483. {
  484. if (m_startupCommandsFile != "")
  485. {
  486. RunCommandScript(m_shutdownCommandsFile);
  487. }
  488. m_log.Verbose("SHUTDOWN", "Closing all threads");
  489. m_log.Verbose("SHUTDOWN", "Killing listener thread");
  490. m_log.Verbose("SHUTDOWN", "Killing clients");
  491. // TODO: implement this
  492. m_log.Verbose("SHUTDOWN", "Closing console and terminating");
  493. m_sceneManager.Close();
  494. m_log.Close();
  495. Environment.Exit(0);
  496. }
  497. private void RunAutoTimerScript(object sender, EventArgs e)
  498. {
  499. if (m_timedScript != "disabled")
  500. {
  501. RunCommandScript(m_timedScript);
  502. }
  503. }
  504. #region Console Commands
  505. /// <summary>
  506. ///
  507. /// </summary>
  508. /// <param name="fileName"></param>
  509. private void RunCommandScript(string fileName)
  510. {
  511. MainLog.Instance.Verbose("COMMANDFILE", "Running " + fileName);
  512. if (File.Exists(fileName))
  513. {
  514. StreamReader readFile = File.OpenText(fileName);
  515. string currentCommand = "";
  516. while ((currentCommand = readFile.ReadLine()) != null)
  517. {
  518. if (currentCommand != "")
  519. {
  520. MainLog.Instance.Verbose("COMMANDFILE", "Running '" + currentCommand + "'");
  521. MainLog.Instance.MainLogRunCommand(currentCommand);
  522. }
  523. }
  524. }
  525. else
  526. {
  527. MainLog.Instance.Error("COMMANDFILE", "Command script missing. Can not run commands");
  528. }
  529. }
  530. /// <summary>
  531. /// Runs commands issued by the server console from the operator
  532. /// </summary>
  533. /// <param name="command">The first argument of the parameter (the command)</param>
  534. /// <param name="cmdparams">Additional arguments passed to the command</param>
  535. public void RunCmd(string command, string[] cmdparams)
  536. {
  537. string result = "";
  538. switch (command)
  539. {
  540. case "set-time":
  541. m_sceneManager.SetCurrentSceneTimePhase(Convert.ToInt32(cmdparams[0]));
  542. break;
  543. case "force-update":
  544. Console.WriteLine("Updating all clients");
  545. m_sceneManager.ForceCurrentSceneClientUpdate();
  546. break;
  547. case "edit-scale":
  548. if (cmdparams.Length == 4)
  549. {
  550. m_sceneManager.HandleEditCommandOnCurrentScene(cmdparams);
  551. }
  552. break;
  553. case "debug":
  554. if (cmdparams.Length > 0)
  555. {
  556. Debug(cmdparams);
  557. }
  558. break;
  559. case "help":
  560. m_log.Error("alert - send alert to a designated user or all users.");
  561. m_log.Error(" alert [First] [Last] [Message] - send an alert to a user. Case sensitive.");
  562. m_log.Error(" alert general [Message] - send an alert to all users.");
  563. m_log.Error("backup - trigger a simulator backup");
  564. m_log.Error("change-region [name] - sets the region that many of these commands affect.");
  565. m_log.Error("command-script [filename] - Execute command in a file.");
  566. m_log.Error("debug - debugging commands");
  567. m_log.Error(" packet 0..255 - print incoming/outgoing packets (0=off)");
  568. m_log.Error("edit-scale [prim name] [x] [y] [z] - resize given prim");
  569. m_log.Error("export-map [filename] - save image of world map");
  570. m_log.Error("force-update - force an update of prims in the scene");
  571. m_log.Error("load-xml [filename] - load prims from XML");
  572. m_log.Error("load-xml2 [filename] - load prims from XML using version 2 format");
  573. m_log.Error("permissions [true/false] - turn on/off permissions on the scene");
  574. m_log.Error("quit - equivalent to shutdown.");
  575. m_log.Error("restart - disconnects all clients and restarts the sims in the instance.");
  576. m_log.Error("remove-region [name] - remove a region");
  577. m_log.Error("save-xml [filename] - save prims to XML");
  578. m_log.Error("save-xml2 [filename] - save prims to XML using version 2 format");
  579. m_log.Error("script - manually trigger scripts? or script commands?");
  580. m_log.Error("set-time [x] - set the current scene time phase");
  581. m_log.Error("show uptime - show simulator startup and uptime.");
  582. m_log.Error("show users - show info about connected users.");
  583. m_log.Error("show modules - shows info aboutloaded modules.");
  584. m_log.Error("status - show status window"); //rex
  585. m_log.Error("shutdown - disconnect all clients and shutdown.");
  586. m_log.Error("terrain help - show help for terrain commands.");
  587. break;
  588. case "show":
  589. if (cmdparams.Length > 0)
  590. {
  591. Show(cmdparams[0]);
  592. }
  593. break;
  594. case "save-xml":
  595. if (cmdparams.Length > 0)
  596. {
  597. m_sceneManager.SaveCurrentSceneToXml(cmdparams[0]);
  598. }
  599. else
  600. {
  601. m_sceneManager.SaveCurrentSceneToXml(DEFAULT_PRIM_BACKUP_FILENAME);
  602. }
  603. break;
  604. case "load-xml":
  605. LLVector3 loadOffset = new LLVector3(0, 0, 0);
  606. if (cmdparams.Length > 0)
  607. {
  608. bool generateNewIDS = false;
  609. if (cmdparams.Length > 1)
  610. {
  611. if (cmdparams[1] == "-newUID")
  612. {
  613. generateNewIDS = true;
  614. }
  615. if (cmdparams.Length > 2)
  616. {
  617. loadOffset.X = (float) Convert.ToDecimal(cmdparams[2]);
  618. if (cmdparams.Length > 3)
  619. {
  620. loadOffset.Y = (float) Convert.ToDecimal(cmdparams[3]);
  621. }
  622. if (cmdparams.Length > 4)
  623. {
  624. loadOffset.Z = (float) Convert.ToDecimal(cmdparams[4]);
  625. }
  626. m_log.Error("loadOffsets <X,Y,Z> = <" + loadOffset.X + "," + loadOffset.Y + "," +
  627. loadOffset.Z + ">");
  628. }
  629. }
  630. m_sceneManager.LoadCurrentSceneFromXml(cmdparams[0], generateNewIDS, loadOffset);
  631. }
  632. else
  633. {
  634. m_sceneManager.LoadCurrentSceneFromXml(DEFAULT_PRIM_BACKUP_FILENAME, false, loadOffset);
  635. }
  636. break;
  637. case "save-xml2":
  638. if (cmdparams.Length > 0)
  639. {
  640. m_sceneManager.SaveCurrentSceneToXml2(cmdparams[0]);
  641. }
  642. else
  643. {
  644. m_sceneManager.SaveCurrentSceneToXml2(DEFAULT_PRIM_BACKUP_FILENAME);
  645. }
  646. break;
  647. case "load-xml2":
  648. if (cmdparams.Length > 0)
  649. {
  650. m_sceneManager.LoadCurrentSceneFromXml2(cmdparams[0]);
  651. }
  652. else
  653. {
  654. m_sceneManager.LoadCurrentSceneFromXml2(DEFAULT_PRIM_BACKUP_FILENAME);
  655. }
  656. break;
  657. case "terrain":
  658. if (!m_sceneManager.RunTerrainCmdOnCurrentScene(cmdparams, ref result))
  659. {
  660. m_log.Error(result);
  661. }
  662. break;
  663. case "script":
  664. m_sceneManager.SendCommandToCurrentSceneScripts(cmdparams);
  665. break;
  666. case "command-script":
  667. if (cmdparams.Length > 0)
  668. {
  669. RunCommandScript(cmdparams[0]);
  670. }
  671. break;
  672. case "permissions":
  673. // Treats each user as a super-admin when disabled
  674. bool permissions = Convert.ToBoolean(cmdparams[0]);
  675. m_sceneManager.SetBypassPermissionsOnCurrentScene(!permissions);
  676. break;
  677. case "backup":
  678. m_sceneManager.BackupCurrentScene();
  679. break;
  680. case "alert":
  681. m_sceneManager.HandleAlertCommandOnCurrentScene(cmdparams);
  682. break;
  683. case "create":
  684. if (CreateAccount != null)
  685. {
  686. CreateAccount(cmdparams);
  687. }
  688. break;
  689. case "create-region":
  690. CreateRegion(new RegionInfo(cmdparams[0], "Regions/" + cmdparams[1],false));
  691. break;
  692. case "remove-region":
  693. string regName = CombineParams(cmdparams, 0);
  694. Scene killScene;
  695. if (m_sceneManager.TryGetScene(regName, out killScene))
  696. {
  697. if (m_sceneManager.CurrentScene.RegionInfo.RegionID == killScene.RegionInfo.RegionID)
  698. {
  699. m_sceneManager.TrySetCurrentScene("..");
  700. }
  701. m_regionData.Remove(killScene.RegionInfo);
  702. m_sceneManager.CloseScene(killScene);
  703. }
  704. break;
  705. case "quit":
  706. case "shutdown":
  707. Shutdown();
  708. break;
  709. case "restart":
  710. m_sceneManager.RestartCurrentScene();
  711. break;
  712. case "change-region":
  713. if (cmdparams.Length > 0)
  714. {
  715. string regionName = CombineParams(cmdparams, 0);
  716. if (!m_sceneManager.TrySetCurrentScene(regionName))
  717. {
  718. MainLog.Instance.Error("Couldn't set current region to: " + regionName);
  719. }
  720. }
  721. if (m_sceneManager.CurrentScene == null)
  722. {
  723. MainLog.Instance.Verbose("CONSOLE",
  724. "Currently at Root level. To change region please use 'change-region <regioname>'");
  725. }
  726. else
  727. {
  728. MainLog.Instance.Verbose("CONSOLE",
  729. "Current Region: " + m_sceneManager.CurrentScene.RegionInfo.RegionName +
  730. ". To change region please use 'change-region <regioname>'");
  731. }
  732. break;
  733. case "export-map":
  734. if (cmdparams.Length > 0)
  735. {
  736. m_sceneManager.CurrentOrFirstScene.ExportWorldMap(cmdparams[0]);
  737. }
  738. else
  739. {
  740. m_sceneManager.CurrentOrFirstScene.ExportWorldMap("exportmap.jpg");
  741. }
  742. break;
  743. // rex, new console command.
  744. case "save-db":
  745. MainLog.Instance.Verbose("COMMANDFILE", "Forced database save started...");
  746. m_sceneManager.ForcedBackupCurrentScene();
  747. MainLog.Instance.Verbose("COMMANDFILE", "Forced database save ended...");
  748. break;
  749. // rex, new console command.
  750. case "python":
  751. m_sceneManager.SendPythonScriptCommand(cmdparams);
  752. break;
  753. //rex
  754. case "status":
  755. OpenSim.Framework.ServerStatus.ServerStatus.ShowWindow();
  756. break;
  757. default:
  758. m_log.Error("Unknown command");
  759. break;
  760. }
  761. }
  762. public void Debug(string[] args)
  763. {
  764. switch (args[0])
  765. {
  766. case "packet":
  767. if (args.Length > 1)
  768. {
  769. int newDebug;
  770. if (int.TryParse(args[1], out newDebug))
  771. {
  772. m_sceneManager.SetDebugPacketOnCurrentScene(m_log, newDebug);
  773. }
  774. else
  775. {
  776. m_log.Error("packet debug should be 0..2");
  777. }
  778. Console.WriteLine("New packet debug: " + newDebug.ToString());
  779. }
  780. break;
  781. default:
  782. m_log.Error("Unknown debug");
  783. break;
  784. }
  785. }
  786. /// <summary>
  787. /// Outputs to the console information about the region
  788. /// </summary>
  789. /// <param name="ShowWhat">What information to display (valid arguments are "uptime", "users")</param>
  790. public void Show(string ShowWhat)
  791. {
  792. switch (ShowWhat)
  793. {
  794. case "uptime":
  795. m_log.Error("OpenSim has been running since " + m_startuptime.ToString());
  796. m_log.Error("That is " + (DateTime.Now - m_startuptime).ToString());
  797. break;
  798. case "users":
  799. m_log.Error(
  800. String.Format("{0,-16}{1,-16}{2,-37}{3,-16}{4,-22}{5,-16}", "Firstname", "Lastname",
  801. "Agent ID", "Circuit", "IP", "Region"));
  802. foreach (ScenePresence presence in m_sceneManager.GetCurrentSceneAvatars())
  803. {
  804. RegionInfo regionInfo = m_sceneManager.GetRegionInfo(presence.RegionHandle);
  805. string regionName;
  806. System.Net.EndPoint ep = null;
  807. if (regionInfo == null)
  808. {
  809. regionName = "Unresolvable";
  810. }
  811. else
  812. {
  813. regionName = regionInfo.RegionName;
  814. }
  815. for (int i = 0; i < m_udpServers.Count; i++)
  816. {
  817. if (m_udpServers[i].RegionHandle == presence.RegionHandle)
  818. {
  819. m_udpServers[i].clientCircuits_reverse.TryGetValue(presence.ControllingClient.CircuitCode, out ep);
  820. }
  821. }
  822. m_log.Error(
  823. String.Format("{0,-16}{1,-16}{2,-37}{3,-16}{4,-22}{5,-16}",
  824. presence.Firstname,
  825. presence.Lastname,
  826. presence.UUID,
  827. presence.ControllingClient.CircuitCode,
  828. ep,
  829. regionName));
  830. }
  831. break;
  832. case "modules":
  833. m_log.Error("The currently loaded shared modules are:");
  834. foreach (IRegionModule module in m_moduleLoader.GetLoadedSharedModules)
  835. {
  836. m_log.Error("Shared Module: " + module.Name);
  837. }
  838. break;
  839. case "regions":
  840. m_sceneManager.ForEachScene(
  841. delegate(Scene scene)
  842. {
  843. m_log.Error("Region Name: " + scene.RegionInfo.RegionName + " , Region XLoc: " +
  844. scene.RegionInfo.RegionLocX + " , Region YLoc: " +
  845. scene.RegionInfo.RegionLocY);
  846. });
  847. break;
  848. }
  849. }
  850. private string CombineParams(string[] commandParams, int pos)
  851. {
  852. string result = "";
  853. for (int i = pos; i < commandParams.Length; i++)
  854. {
  855. result += commandParams[i] + " ";
  856. }
  857. result = result.TrimEnd(' ');
  858. return result;
  859. }
  860. #endregion
  861. }
  862. }