OpenSim.cs 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266
  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 OpenSimulator 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;
  29. using System.Collections.Generic;
  30. using System.IO;
  31. using System.Reflection;
  32. using System.Timers;
  33. using log4net;
  34. using Nini.Config;
  35. using OpenMetaverse;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Console;
  38. using OpenSim.Framework.Statistics;
  39. using OpenSim.Region.Framework.Interfaces;
  40. using OpenSim.Region.Framework.Scenes;
  41. namespace OpenSim
  42. {
  43. /// <summary>
  44. /// Interactive OpenSim region server
  45. /// </summary>
  46. public class OpenSim : OpenSimBase
  47. {
  48. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  49. protected string m_startupCommandsFile;
  50. protected string m_shutdownCommandsFile;
  51. protected bool m_gui = false;
  52. private string m_timedScript = "disabled";
  53. private Timer m_scriptTimer;
  54. public OpenSim(IConfigSource configSource) : base(configSource)
  55. {
  56. }
  57. protected override void ReadExtraConfigSettings()
  58. {
  59. base.ReadExtraConfigSettings();
  60. IConfig startupConfig = m_config.Source.Configs["Startup"];
  61. if (startupConfig != null)
  62. {
  63. m_startupCommandsFile = startupConfig.GetString("startup_console_commands_file", "startup_commands.txt");
  64. m_shutdownCommandsFile = startupConfig.GetString("shutdown_console_commands_file", "shutdown_commands.txt");
  65. m_gui = startupConfig.GetBoolean("gui", false);
  66. m_timedScript = startupConfig.GetString("timer_Script", "disabled");
  67. if (m_logFileAppender != null)
  68. {
  69. if (m_logFileAppender is log4net.Appender.FileAppender)
  70. {
  71. log4net.Appender.FileAppender appender =
  72. (log4net.Appender.FileAppender)m_logFileAppender;
  73. string fileName = startupConfig.GetString("LogFile", String.Empty);
  74. if (fileName != String.Empty)
  75. {
  76. appender.File = fileName;
  77. appender.ActivateOptions();
  78. }
  79. m_log.InfoFormat("[LOGGING] Logging started to file {0}", appender.File);
  80. }
  81. }
  82. }
  83. }
  84. /// <summary>
  85. /// Performs initialisation of the scene, such as loading configuration from disk.
  86. /// </summary>
  87. protected override void StartupSpecific()
  88. {
  89. m_log.Info("====================================================================");
  90. m_log.Info("========================= STARTING OPENSIM =========================");
  91. m_log.Info("====================================================================");
  92. m_log.InfoFormat("[OPENSIM MAIN]: Running in {0} mode",
  93. (ConfigurationSettings.Standalone ? "sandbox" : "grid"));
  94. //m_log.InfoFormat("[OPENSIM MAIN]: GC Is Server GC: {0}", GCSettings.IsServerGC.ToString());
  95. // http://msdn.microsoft.com/en-us/library/bb384202.aspx
  96. //GCSettings.LatencyMode = GCLatencyMode.Batch;
  97. //m_log.InfoFormat("[OPENSIM MAIN]: GC Latency Mode: {0}", GCSettings.LatencyMode.ToString());
  98. if (m_gui) // Driven by external GUI
  99. m_console = new CommandConsole("Region");
  100. else
  101. m_console = new LocalConsole("Region");
  102. MainConsole.Instance = m_console;
  103. RegisterConsoleCommands();
  104. base.StartupSpecific();
  105. //Run Startup Commands
  106. if (String.IsNullOrEmpty(m_startupCommandsFile))
  107. {
  108. m_log.Info("[STARTUP]: No startup command script specified. Moving on...");
  109. }
  110. else
  111. {
  112. RunCommandScript(m_startupCommandsFile);
  113. }
  114. // Start timer script (run a script every xx seconds)
  115. if (m_timedScript != "disabled")
  116. {
  117. m_scriptTimer = new Timer();
  118. m_scriptTimer.Enabled = true;
  119. m_scriptTimer.Interval = 1200*1000;
  120. m_scriptTimer.Elapsed += RunAutoTimerScript;
  121. }
  122. PrintFileToConsole("startuplogo.txt");
  123. // For now, start at the 'root' level by default
  124. if (m_sceneManager.Scenes.Count == 1) // If there is only one region, select it
  125. ChangeSelectedRegion("region",
  126. new string[] {"change", "region", m_sceneManager.Scenes[0].RegionInfo.RegionName});
  127. else
  128. ChangeSelectedRegion("region", new string[] {"change", "region", "root"});
  129. }
  130. /// <summary>
  131. /// Register standard set of region console commands
  132. /// </summary>
  133. private void RegisterConsoleCommands()
  134. {
  135. m_console.Commands.AddCommand("region", false, "clear assets",
  136. "clear assets",
  137. "Clear the asset cache", HandleClearAssets);
  138. m_console.Commands.AddCommand("region", false, "force update",
  139. "force update",
  140. "Force the update of all objects on clients",
  141. HandleForceUpdate);
  142. m_console.Commands.AddCommand("region", false, "debug packet",
  143. "debug packet <level>",
  144. "Turn on packet debugging", Debug);
  145. m_console.Commands.AddCommand("region", false, "debug scene",
  146. "debug scene <cripting> <collisions> <physics>",
  147. "Turn on scene debugging", Debug);
  148. m_console.Commands.AddCommand("region", false, "change region",
  149. "change region <region name>",
  150. "Change current console region", ChangeSelectedRegion);
  151. m_console.Commands.AddCommand("region", false, "save xml",
  152. "save xml",
  153. "Save a region's data in XML format", SaveXml);
  154. m_console.Commands.AddCommand("region", false, "save xml2",
  155. "save xml2",
  156. "Save a region's data in XML2 format", SaveXml2);
  157. m_console.Commands.AddCommand("region", false, "load xml",
  158. "load xml [-newIDs [<x> <y> <z>]]",
  159. "Load a region's data from XML format", LoadXml);
  160. m_console.Commands.AddCommand("region", false, "load xml2",
  161. "load xml2",
  162. "Load a region's data from XML2 format", LoadXml2);
  163. m_console.Commands.AddCommand("region", false, "save prims xml2",
  164. "save prims xml2 [<prim name> <file name>]",
  165. "Save named prim to XML2", SavePrimsXml2);
  166. m_console.Commands.AddCommand("region", false, "load oar",
  167. "load oar <oar name>",
  168. "Load a region's data from OAR archive", LoadOar);
  169. m_console.Commands.AddCommand("region", false, "save oar",
  170. "save oar <oar name>",
  171. "Save a region's data to an OAR archive",
  172. "More information on forthcoming options here soon", SaveOar);
  173. m_console.Commands.AddCommand("region", false, "edit scale",
  174. "edit scale <name> <x> <y> <z>",
  175. "Change the scale of a named prim", HandleEditScale);
  176. m_console.Commands.AddCommand("region", false, "kick user",
  177. "kick user <first> <last> [message]",
  178. "Kick a user off the simulator", KickUserCommand);
  179. m_console.Commands.AddCommand("region", false, "show assets",
  180. "show assets",
  181. "Show asset data", HandleShow);
  182. m_console.Commands.AddCommand("region", false, "show users",
  183. "show users [full]",
  184. "Show user data", HandleShow);
  185. m_console.Commands.AddCommand("region", false, "show users full",
  186. "show users full",
  187. String.Empty, HandleShow);
  188. m_console.Commands.AddCommand("region", false, "show modules",
  189. "show modules",
  190. "Show module data", HandleShow);
  191. m_console.Commands.AddCommand("region", false, "show regions",
  192. "show regions",
  193. "Show region data", HandleShow);
  194. m_console.Commands.AddCommand("region", false, "show queues",
  195. "show queues",
  196. "Show queue data", HandleShow);
  197. m_console.Commands.AddCommand("region", false, "show ratings",
  198. "show ratings",
  199. "Show rating data", HandleShow);
  200. m_console.Commands.AddCommand("region", false, "backup",
  201. "backup",
  202. "Persist objects to the database now", RunCommand);
  203. m_console.Commands.AddCommand("region", false, "create region",
  204. "create region",
  205. "Create a new region", HandleCreateRegion);
  206. m_console.Commands.AddCommand("region", false, "login enable",
  207. "login enable",
  208. "Enable logins to the simulator", HandleLoginEnable);
  209. m_console.Commands.AddCommand("region", false, "login disable",
  210. "login disable",
  211. "Disable logins to the simulator", HandleLoginDisable);
  212. m_console.Commands.AddCommand("region", false, "login status",
  213. "login status",
  214. "Display status of logins", HandleLoginStatus);
  215. m_console.Commands.AddCommand("region", false, "restart",
  216. "restart",
  217. "Restart all sims in this instance", RunCommand);
  218. m_console.Commands.AddCommand("region", false, "config set",
  219. "config set <section> <field> <value>",
  220. "Set a config option", HandleConfig);
  221. m_console.Commands.AddCommand("region", false, "config get",
  222. "config get <section> <field>",
  223. "Read a config option", HandleConfig);
  224. m_console.Commands.AddCommand("region", false, "config save",
  225. "config save",
  226. "Save current configuration", HandleConfig);
  227. m_console.Commands.AddCommand("region", false, "command-script",
  228. "command-script <script>",
  229. "Run a command script from file", RunCommand);
  230. m_console.Commands.AddCommand("region", false, "remove-region",
  231. "remove-region <name>",
  232. "Remove a region from this simulator", RunCommand);
  233. m_console.Commands.AddCommand("region", false, "delete-region",
  234. "delete-region <name>",
  235. "Delete a region from disk", RunCommand);
  236. m_console.Commands.AddCommand("region", false, "predecode-j2k",
  237. "predecode-j2k [<num threads>]>",
  238. "Precache assets,decode j2k layerdata", RunCommand);
  239. m_console.Commands.AddCommand("region", false, "modules list",
  240. "modules list",
  241. "List modules", HandleModules);
  242. m_console.Commands.AddCommand("region", false, "modules load",
  243. "modules load <name>",
  244. "Load a module", HandleModules);
  245. m_console.Commands.AddCommand("region", false, "modules unload",
  246. "modules unload <name>",
  247. "Unload a module", HandleModules);
  248. m_console.Commands.AddCommand("region", false, "Add-InventoryHost",
  249. "Add-InventoryHost <host>",
  250. String.Empty, RunCommand);
  251. if (ConfigurationSettings.Standalone)
  252. {
  253. m_console.Commands.AddCommand("region", false, "create user",
  254. "create user [<first> [<last> [<pass> [<x> <y> [<email>]]]]]",
  255. "Create a new user", HandleCreateUser);
  256. m_console.Commands.AddCommand("region", false, "reset user password",
  257. "reset user password [<first> [<last> [<password>]]]",
  258. "Reset a user password", HandleResetUserPassword);
  259. }
  260. m_console.Commands.AddCommand("hypergrid", false, "link-mapping", "link-mapping [<x> <y>] <cr>",
  261. "Set local coordinate to map HG regions to", RunCommand);
  262. m_console.Commands.AddCommand("hypergrid", false, "link-region",
  263. "link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>] <cr>",
  264. "Link a hypergrid region", RunCommand);
  265. m_console.Commands.AddCommand("hypergrid", false, "unlink-region",
  266. "unlink-region <local name> or <HostName>:<HttpPort> <cr>",
  267. "Unlink a hypergrid region", RunCommand);
  268. }
  269. public override void ShutdownSpecific()
  270. {
  271. if (m_shutdownCommandsFile != String.Empty)
  272. {
  273. RunCommandScript(m_shutdownCommandsFile);
  274. }
  275. base.ShutdownSpecific();
  276. }
  277. /// <summary>
  278. /// Timer to run a specific text file as console commands. Configured in in the main ini file
  279. /// </summary>
  280. /// <param name="sender"></param>
  281. /// <param name="e"></param>
  282. private void RunAutoTimerScript(object sender, EventArgs e)
  283. {
  284. if (m_timedScript != "disabled")
  285. {
  286. RunCommandScript(m_timedScript);
  287. }
  288. }
  289. #region Console Commands
  290. /// <summary>
  291. /// Kicks users off the region
  292. /// </summary>
  293. /// <param name="module"></param>
  294. /// <param name="cmdparams">name of avatar to kick</param>
  295. private void KickUserCommand(string module, string[] cmdparams)
  296. {
  297. if (cmdparams.Length < 4)
  298. return;
  299. string alert = null;
  300. if (cmdparams.Length > 4)
  301. alert = String.Format("\n{0}\n", String.Join(" ", cmdparams, 4, cmdparams.Length - 4));
  302. IList agents = m_sceneManager.GetCurrentSceneAvatars();
  303. foreach (ScenePresence presence in agents)
  304. {
  305. RegionInfo regionInfo = m_sceneManager.GetRegionInfo(presence.RegionHandle);
  306. if (presence.Firstname.ToLower().Contains(cmdparams[2].ToLower()) &&
  307. presence.Lastname.ToLower().Contains(cmdparams[3].ToLower()))
  308. {
  309. m_log.Info(
  310. String.Format(
  311. "Kicking user: {0,-16}{1,-16}{2,-37} in region: {3,-16}",
  312. presence.Firstname, presence.Lastname, presence.UUID, regionInfo.RegionName));
  313. // kick client...
  314. if (alert != null)
  315. presence.ControllingClient.Kick(alert);
  316. else
  317. presence.ControllingClient.Kick("\nThe OpenSim manager kicked you out.\n");
  318. // ...and close on our side
  319. presence.Scene.IncomingCloseAgent(presence.UUID);
  320. }
  321. }
  322. m_log.Info("");
  323. }
  324. /// <summary>
  325. /// Run an optional startup list of commands
  326. /// </summary>
  327. /// <param name="fileName"></param>
  328. private void RunCommandScript(string fileName)
  329. {
  330. if (File.Exists(fileName))
  331. {
  332. m_log.Info("[COMMANDFILE]: Running " + fileName);
  333. StreamReader readFile = File.OpenText(fileName);
  334. string currentCommand;
  335. while ((currentCommand = readFile.ReadLine()) != null)
  336. {
  337. if (currentCommand != String.Empty)
  338. {
  339. m_log.Info("[COMMANDFILE]: Running '" + currentCommand + "'");
  340. m_console.RunCommand(currentCommand);
  341. }
  342. }
  343. }
  344. }
  345. /// <summary>
  346. /// Opens a file and uses it as input to the console command parser.
  347. /// </summary>
  348. /// <param name="fileName">name of file to use as input to the console</param>
  349. private static void PrintFileToConsole(string fileName)
  350. {
  351. if (File.Exists(fileName))
  352. {
  353. StreamReader readFile = File.OpenText(fileName);
  354. string currentLine;
  355. while ((currentLine = readFile.ReadLine()) != null)
  356. {
  357. m_log.Info("[!]" + currentLine);
  358. }
  359. }
  360. }
  361. private void HandleClearAssets(string module, string[] args)
  362. {
  363. m_log.Info("Not implemented.");
  364. }
  365. /// <summary>
  366. /// Force resending of all updates to all clients in active region(s)
  367. /// </summary>
  368. /// <param name="module"></param>
  369. /// <param name="args"></param>
  370. private void HandleForceUpdate(string module, string[] args)
  371. {
  372. m_log.Info("Updating all clients");
  373. m_sceneManager.ForceCurrentSceneClientUpdate();
  374. }
  375. /// <summary>
  376. /// Edits the scale of a primative with the name specified
  377. /// </summary>
  378. /// <param name="module"></param>
  379. /// <param name="args">0,1, name, x, y, z</param>
  380. private void HandleEditScale(string module, string[] args)
  381. {
  382. if (args.Length == 6)
  383. {
  384. m_sceneManager.HandleEditCommandOnCurrentScene(args);
  385. }
  386. else
  387. {
  388. m_log.Info("Argument error: edit scale <prim name> <x> <y> <z>");
  389. }
  390. }
  391. /// <summary>
  392. /// Creates a new region based on the parameters specified. This will ask the user questions on the console
  393. /// </summary>
  394. /// <param name="module"></param>
  395. /// <param name="cmd">0,1,region name, region XML file</param>
  396. private void HandleCreateRegion(string module, string[] cmd)
  397. {
  398. if (cmd.Length < 4)
  399. {
  400. m_log.Error("Usage: create region <region name> <region_file.xml>");
  401. return;
  402. }
  403. if (cmd[3].EndsWith(".xml"))
  404. {
  405. string regionsDir = ConfigSource.Source.Configs["Startup"].GetString("regionload_regionsdir", "Regions").Trim();
  406. string regionFile = String.Format("{0}/{1}", regionsDir, cmd[3]);
  407. // Allow absolute and relative specifiers
  408. if (cmd[3].StartsWith("/") || cmd[3].StartsWith("\\") || cmd[3].StartsWith(".."))
  409. regionFile = cmd[3];
  410. IScene scene;
  411. CreateRegion(new RegionInfo(cmd[2], regionFile, false, ConfigSource.Source), true, out scene);
  412. }
  413. else if (cmd[3].EndsWith(".ini"))
  414. {
  415. string regionsDir = ConfigSource.Source.Configs["Startup"].GetString("regionload_regionsdir", "Regions").Trim();
  416. string regionFile = String.Format("{0}/{1}", regionsDir, cmd[3]);
  417. // Allow absolute and relative specifiers
  418. if (cmd[3].StartsWith("/") || cmd[3].StartsWith("\\") || cmd[3].StartsWith(".."))
  419. regionFile = cmd[3];
  420. IScene scene;
  421. CreateRegion(new RegionInfo(cmd[2], regionFile, false, ConfigSource.Source, cmd[2]), true, out scene);
  422. }
  423. else
  424. {
  425. m_log.Error("Usage: create region <region name> <region_file.xml>");
  426. return;
  427. }
  428. }
  429. /// <summary>
  430. /// Enable logins
  431. /// </summary>
  432. /// <param name="module"></param>
  433. /// <param name="cmd"></param>
  434. private void HandleLoginEnable(string module, string[] cmd)
  435. {
  436. ProcessLogin(true);
  437. }
  438. /// <summary>
  439. /// Disable logins
  440. /// </summary>
  441. /// <param name="module"></param>
  442. /// <param name="cmd"></param>
  443. private void HandleLoginDisable(string module, string[] cmd)
  444. {
  445. ProcessLogin(false);
  446. }
  447. /// <summary>
  448. /// Log login status to the console
  449. /// </summary>
  450. /// <param name="module"></param>
  451. /// <param name="cmd"></param>
  452. private void HandleLoginStatus(string module, string[] cmd)
  453. {
  454. if (m_commsManager.GridService.RegionLoginsEnabled == false)
  455. m_log.Info("[ Login ] Login are disabled ");
  456. else
  457. m_log.Info("[ Login ] Login are enabled");
  458. }
  459. /// <summary>
  460. /// Change and load configuration file data.
  461. /// </summary>
  462. /// <param name="module"></param>
  463. /// <param name="cmd"></param>
  464. private void HandleConfig(string module, string[] cmd)
  465. {
  466. List<string> args = new List<string>(cmd);
  467. args.RemoveAt(0);
  468. string[] cmdparams = args.ToArray();
  469. string n = "CONFIG";
  470. if (cmdparams.Length > 0)
  471. {
  472. switch (cmdparams[0].ToLower())
  473. {
  474. case "set":
  475. if (cmdparams.Length < 4)
  476. {
  477. m_log.Error("SYNTAX: " + n + " SET SECTION KEY VALUE");
  478. m_log.Error("EXAMPLE: " + n + " SET ScriptEngine.DotNetEngine NumberOfScriptThreads 5");
  479. }
  480. else
  481. {
  482. IConfig c;
  483. IConfigSource source = new IniConfigSource();
  484. c = source.AddConfig(cmdparams[1]);
  485. if (c != null)
  486. {
  487. string _value = String.Join(" ", cmdparams, 3, cmdparams.Length - 3);
  488. c.Set(cmdparams[2], _value);
  489. m_config.Source.Merge(source);
  490. m_log.Error(n + " " + n + " " + cmdparams[1] + " " + cmdparams[2] + " " +
  491. _value);
  492. }
  493. }
  494. break;
  495. case "get":
  496. if (cmdparams.Length < 3)
  497. {
  498. m_log.Error("SYNTAX: " + n + " GET SECTION KEY");
  499. m_log.Error("EXAMPLE: " + n + " GET ScriptEngine.DotNetEngine NumberOfScriptThreads");
  500. }
  501. else
  502. {
  503. IConfig c = m_config.Source.Configs[cmdparams[1]];
  504. if (c == null)
  505. {
  506. m_log.Info("Section \"" + cmdparams[1] + "\" does not exist.");
  507. break;
  508. }
  509. else
  510. {
  511. m_log.Info(n + " GET " + cmdparams[1] + " " + cmdparams[2] + ": " +
  512. c.GetString(cmdparams[2]));
  513. }
  514. }
  515. break;
  516. case "save":
  517. m_log.Info("Saving configuration file: " + Application.iniFilePath);
  518. m_config.Save(Application.iniFilePath);
  519. break;
  520. }
  521. }
  522. }
  523. /// <summary>
  524. /// Load, Unload, and list Region modules in use
  525. /// </summary>
  526. /// <param name="module"></param>
  527. /// <param name="cmd"></param>
  528. private void HandleModules(string module, string[] cmd)
  529. {
  530. List<string> args = new List<string>(cmd);
  531. args.RemoveAt(0);
  532. string[] cmdparams = args.ToArray();
  533. if (cmdparams.Length > 0)
  534. {
  535. switch (cmdparams[0].ToLower())
  536. {
  537. case "list":
  538. foreach (IRegionModule irm in m_moduleLoader.GetLoadedSharedModules)
  539. {
  540. m_log.Info("Shared region module: " + irm.Name);
  541. }
  542. break;
  543. case "unload":
  544. if (cmdparams.Length > 1)
  545. {
  546. foreach (IRegionModule rm in new ArrayList(m_moduleLoader.GetLoadedSharedModules))
  547. {
  548. if (rm.Name.ToLower() == cmdparams[1].ToLower())
  549. {
  550. m_log.Info("Unloading module: " + rm.Name);
  551. m_moduleLoader.UnloadModule(rm);
  552. }
  553. }
  554. }
  555. break;
  556. case "load":
  557. if (cmdparams.Length > 1)
  558. {
  559. foreach (Scene s in new ArrayList(m_sceneManager.Scenes))
  560. {
  561. m_log.Info("Loading module: " + cmdparams[1]);
  562. m_moduleLoader.LoadRegionModules(cmdparams[1], s);
  563. }
  564. }
  565. break;
  566. }
  567. }
  568. }
  569. /// <summary>
  570. /// Runs commands issued by the server console from the operator
  571. /// </summary>
  572. /// <param name="command">The first argument of the parameter (the command)</param>
  573. /// <param name="cmdparams">Additional arguments passed to the command</param>
  574. public void RunCommand(string module, string[] cmdparams)
  575. {
  576. List<string> args = new List<string>(cmdparams);
  577. if (args.Count < 1)
  578. return;
  579. string command = args[0];
  580. args.RemoveAt(0);
  581. cmdparams = args.ToArray();
  582. switch (command)
  583. {
  584. case "command-script":
  585. if (cmdparams.Length > 0)
  586. {
  587. RunCommandScript(cmdparams[0]);
  588. }
  589. break;
  590. case "backup":
  591. m_sceneManager.BackupCurrentScene();
  592. break;
  593. case "remove-region":
  594. string regRemoveName = CombineParams(cmdparams, 0);
  595. Scene removeScene;
  596. if (m_sceneManager.TryGetScene(regRemoveName, out removeScene))
  597. RemoveRegion(removeScene, false);
  598. else
  599. m_log.Error("no region with that name");
  600. break;
  601. case "delete-region":
  602. string regDeleteName = CombineParams(cmdparams, 0);
  603. Scene killScene;
  604. if (m_sceneManager.TryGetScene(regDeleteName, out killScene))
  605. RemoveRegion(killScene, true);
  606. else
  607. m_log.Error("no region with that name");
  608. break;
  609. case "restart":
  610. m_sceneManager.RestartCurrentScene();
  611. break;
  612. case "Add-InventoryHost":
  613. if (cmdparams.Length > 0)
  614. {
  615. m_log.Info("Not implemented.");
  616. }
  617. break;
  618. case "predecode-j2k":
  619. if (cmdparams.Length > 0)
  620. {
  621. m_sceneManager.CacheJ2kDecode(Convert.ToInt32(cmdparams[0]));
  622. }
  623. else
  624. {
  625. m_sceneManager.CacheJ2kDecode(1);
  626. }
  627. break;
  628. case "link-region":
  629. case "unlink-region":
  630. case "link-mapping":
  631. HGCommands.RunHGCommand(command, cmdparams, m_sceneManager.CurrentOrFirstScene);
  632. break;
  633. }
  634. }
  635. /// <summary>
  636. /// Change the currently selected region. The selected region is that operated upon by single region commands.
  637. /// </summary>
  638. /// <param name="cmdParams"></param>
  639. protected void ChangeSelectedRegion(string module, string[] cmdparams)
  640. {
  641. if (cmdparams.Length > 2)
  642. {
  643. string newRegionName = CombineParams(cmdparams, 2);
  644. if (!m_sceneManager.TrySetCurrentScene(newRegionName))
  645. m_log.Error("Couldn't select region " + newRegionName);
  646. }
  647. else
  648. {
  649. m_log.Error("Usage: change region <region name>");
  650. }
  651. string regionName = (m_sceneManager.CurrentScene == null ? "root" : m_sceneManager.CurrentScene.RegionInfo.RegionName);
  652. m_log.Info(String.Format("Currently selected region is {0}", regionName));
  653. m_console.DefaultPrompt = String.Format("Region ({0}) ", regionName);
  654. m_console.ConsoleScene = m_sceneManager.CurrentScene;
  655. }
  656. /// <summary>
  657. /// Execute switch for some of the create commands
  658. /// </summary>
  659. /// <param name="args"></param>
  660. private void HandleCreateUser(string module, string[] cmd)
  661. {
  662. if (ConfigurationSettings.Standalone)
  663. {
  664. CreateUser(cmd);
  665. }
  666. else
  667. {
  668. m_log.Info("Create user is not available in grid mode, use the user server.");
  669. }
  670. }
  671. /// <summary>
  672. /// Execute switch for some of the reset commands
  673. /// </summary>
  674. /// <param name="args"></param>
  675. protected void HandleResetUserPassword(string module, string[] cmd)
  676. {
  677. if (ConfigurationSettings.Standalone)
  678. {
  679. ResetUserPassword(cmd);
  680. }
  681. else
  682. {
  683. m_log.Info("Reset user password is not available in grid mode, use the user-server.");
  684. }
  685. }
  686. /// <summary>
  687. /// Turn on some debugging values for OpenSim.
  688. /// </summary>
  689. /// <param name="args"></param>
  690. protected void Debug(string module, string[] args)
  691. {
  692. if (args.Length == 1)
  693. return;
  694. switch (args[1])
  695. {
  696. case "packet":
  697. if (args.Length > 2)
  698. {
  699. int newDebug;
  700. if (int.TryParse(args[2], out newDebug))
  701. {
  702. m_sceneManager.SetDebugPacketLevelOnCurrentScene(newDebug);
  703. }
  704. else
  705. {
  706. m_log.Error("packet debug should be 0..255");
  707. }
  708. m_log.Info("New packet debug: " + newDebug.ToString());
  709. }
  710. break;
  711. case "scene":
  712. if (args.Length == 5)
  713. {
  714. if (m_sceneManager.CurrentScene == null)
  715. {
  716. m_log.Info("Please use 'change region <regioname>' first");
  717. }
  718. else
  719. {
  720. bool scriptingOn = !Convert.ToBoolean(args[2]);
  721. bool collisionsOn = !Convert.ToBoolean(args[3]);
  722. bool physicsOn = !Convert.ToBoolean(args[4]);
  723. m_sceneManager.CurrentScene.SetSceneCoreDebug(scriptingOn, collisionsOn, physicsOn);
  724. m_log.Info(
  725. String.Format(
  726. "Set debug scene scripting = {0}, collisions = {1}, physics = {2}",
  727. !scriptingOn, !collisionsOn, !physicsOn));
  728. }
  729. }
  730. else
  731. {
  732. m_log.Error("debug scene <scripting> <collisions> <physics> (where inside <> is true/false)");
  733. }
  734. break;
  735. default:
  736. m_log.Error("Unknown debug");
  737. break;
  738. }
  739. }
  740. // see BaseOpenSimServer
  741. /// <summary>
  742. /// Many commands list objects for debugging. Some of the types are listed here
  743. /// </summary>
  744. /// <param name="mod"></param>
  745. /// <param name="cmd"></param>
  746. public override void HandleShow(string mod, string[] cmd)
  747. {
  748. base.HandleShow(mod, cmd);
  749. List<string> args = new List<string>(cmd);
  750. args.RemoveAt(0);
  751. string[] showParams = args.ToArray();
  752. switch (showParams[0])
  753. {
  754. case "assets":
  755. m_log.Info("Not implemented.");
  756. break;
  757. case "users":
  758. IList agents;
  759. if (showParams.Length > 1 && showParams[1] == "full")
  760. {
  761. agents = m_sceneManager.GetCurrentScenePresences();
  762. }
  763. else
  764. {
  765. agents = m_sceneManager.GetCurrentSceneAvatars();
  766. }
  767. m_log.Info(String.Format("\nAgents connected: {0}\n", agents.Count));
  768. m_log.Info(
  769. String.Format("{0,-16}{1,-16}{2,-37}{3,-11}{4,-16}", "Firstname", "Lastname",
  770. "Agent ID", "Root/Child", "Region"));
  771. foreach (ScenePresence presence in agents)
  772. {
  773. RegionInfo regionInfo = m_sceneManager.GetRegionInfo(presence.RegionHandle);
  774. string regionName;
  775. if (regionInfo == null)
  776. {
  777. regionName = "Unresolvable";
  778. }
  779. else
  780. {
  781. regionName = regionInfo.RegionName;
  782. }
  783. m_log.Info(
  784. String.Format(
  785. "{0,-16}{1,-16}{2,-37}{3,-11}{4,-16}",
  786. presence.Firstname,
  787. presence.Lastname,
  788. presence.UUID,
  789. presence.IsChildAgent ? "Child" : "Root",
  790. regionName));
  791. }
  792. m_log.Info("");
  793. break;
  794. case "modules":
  795. m_log.Info("The currently loaded shared modules are:");
  796. foreach (IRegionModule module in m_moduleLoader.GetLoadedSharedModules)
  797. {
  798. m_log.Info("Shared Module: " + module.Name);
  799. }
  800. break;
  801. case "regions":
  802. m_sceneManager.ForEachScene(
  803. delegate(Scene scene)
  804. {
  805. m_log.Info("Region Name: " + scene.RegionInfo.RegionName + " , Region XLoc: " +
  806. scene.RegionInfo.RegionLocX + " , Region YLoc: " +
  807. scene.RegionInfo.RegionLocY + " , Region Port: " +
  808. scene.RegionInfo.InternalEndPoint.Port.ToString());
  809. });
  810. break;
  811. case "queues":
  812. Notice(GetQueuesReport());
  813. break;
  814. case "ratings":
  815. m_sceneManager.ForEachScene(
  816. delegate(Scene scene)
  817. {
  818. string rating = "";
  819. if (scene.RegionInfo.RegionSettings.Maturity == 1)
  820. {
  821. rating = "MATURE";
  822. }
  823. else if (scene.RegionInfo.RegionSettings.Maturity == 2)
  824. {
  825. rating = "ADULT";
  826. }
  827. else
  828. {
  829. rating = "PG";
  830. }
  831. m_log.Info("Region Name: " + scene.RegionInfo.RegionName + " , Region Rating: " +
  832. rating);
  833. });
  834. break;
  835. }
  836. }
  837. /// <summary>
  838. /// print UDP Queue data for each client
  839. /// </summary>
  840. /// <returns></returns>
  841. private string GetQueuesReport()
  842. {
  843. string report = String.Empty;
  844. m_sceneManager.ForEachScene(delegate(Scene scene)
  845. {
  846. scene.ForEachClient(delegate(IClientAPI client)
  847. {
  848. if (client is IStatsCollector)
  849. {
  850. report = report + client.FirstName +
  851. " " + client.LastName + "\n";
  852. IStatsCollector stats =
  853. (IStatsCollector) client;
  854. report = report + string.Format("{0,7} {1,7} {2,7} {3,7} {4,7} {5,7} {6,7} {7,7} {8,7} {9,7}\n",
  855. "Send",
  856. "In",
  857. "Out",
  858. "Resend",
  859. "Land",
  860. "Wind",
  861. "Cloud",
  862. "Task",
  863. "Texture",
  864. "Asset");
  865. report = report + stats.Report() +
  866. "\n\n";
  867. }
  868. });
  869. });
  870. return report;
  871. }
  872. /// <summary>
  873. /// Create a new user
  874. /// </summary>
  875. /// <param name="cmdparams">string array with parameters: firstname, lastname, password, locationX, locationY, email</param>
  876. protected void CreateUser(string[] cmdparams)
  877. {
  878. string firstName;
  879. string lastName;
  880. string password;
  881. string email;
  882. uint regX = 1000;
  883. uint regY = 1000;
  884. if (cmdparams.Length < 3)
  885. firstName = MainConsole.Instance.CmdPrompt("First name", "Default");
  886. else firstName = cmdparams[2];
  887. if (cmdparams.Length < 4)
  888. lastName = MainConsole.Instance.CmdPrompt("Last name", "User");
  889. else lastName = cmdparams[3];
  890. if (cmdparams.Length < 5)
  891. password = MainConsole.Instance.PasswdPrompt("Password");
  892. else password = cmdparams[4];
  893. if (cmdparams.Length < 6)
  894. regX = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region X", regX.ToString()));
  895. else regX = Convert.ToUInt32(cmdparams[5]);
  896. if (cmdparams.Length < 7)
  897. regY = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region Y", regY.ToString()));
  898. else regY = Convert.ToUInt32(cmdparams[6]);
  899. if (cmdparams.Length < 8)
  900. email = MainConsole.Instance.CmdPrompt("Email", "");
  901. else email = cmdparams[7];
  902. if (null == m_commsManager.UserProfileCacheService.GetUserDetails(firstName, lastName))
  903. {
  904. m_commsManager.UserAdminService.AddUser(firstName, lastName, password, email, regX, regY);
  905. }
  906. else
  907. {
  908. m_log.ErrorFormat("[CONSOLE]: A user with the name {0} {1} already exists!", firstName, lastName);
  909. }
  910. }
  911. /// <summary>
  912. /// Reset a user password.
  913. /// </summary>
  914. /// <param name="cmdparams"></param>
  915. private void ResetUserPassword(string[] cmdparams)
  916. {
  917. string firstName;
  918. string lastName;
  919. string newPassword;
  920. if (cmdparams.Length < 4)
  921. firstName = MainConsole.Instance.CmdPrompt("First name");
  922. else firstName = cmdparams[3];
  923. if (cmdparams.Length < 5)
  924. lastName = MainConsole.Instance.CmdPrompt("Last name");
  925. else lastName = cmdparams[4];
  926. if (cmdparams.Length < 6)
  927. newPassword = MainConsole.Instance.PasswdPrompt("New password");
  928. else newPassword = cmdparams[5];
  929. m_commsManager.UserAdminService.ResetUserPassword(firstName, lastName, newPassword);
  930. }
  931. /// <summary>
  932. /// Use XML2 format to serialize data to a file
  933. /// </summary>
  934. /// <param name="module"></param>
  935. /// <param name="cmdparams"></param>
  936. protected void SavePrimsXml2(string module, string[] cmdparams)
  937. {
  938. if (cmdparams.Length > 5)
  939. {
  940. m_sceneManager.SaveNamedPrimsToXml2(cmdparams[3], cmdparams[4]);
  941. }
  942. else
  943. {
  944. m_sceneManager.SaveNamedPrimsToXml2("Primitive", DEFAULT_PRIM_BACKUP_FILENAME);
  945. }
  946. }
  947. /// <summary>
  948. /// Use XML format to serialize data to a file
  949. /// </summary>
  950. /// <param name="module"></param>
  951. /// <param name="cmdparams"></param>
  952. protected void SaveXml(string module, string[] cmdparams)
  953. {
  954. m_log.Error("[CONSOLE]: PLEASE NOTE, save-xml is DEPRECATED and may be REMOVED soon. If you are using this and there is some reason you can't use save-xml2, please file a mantis detailing the reason.");
  955. if (cmdparams.Length > 0)
  956. {
  957. m_sceneManager.SaveCurrentSceneToXml(cmdparams[2]);
  958. }
  959. else
  960. {
  961. m_sceneManager.SaveCurrentSceneToXml(DEFAULT_PRIM_BACKUP_FILENAME);
  962. }
  963. }
  964. /// <summary>
  965. /// Loads data and region objects from XML format.
  966. /// </summary>
  967. /// <param name="module"></param>
  968. /// <param name="cmdparams"></param>
  969. protected void LoadXml(string module, string[] cmdparams)
  970. {
  971. m_log.Error("[CONSOLE]: PLEASE NOTE, load-xml is DEPRECATED and may be REMOVED soon. If you are using this and there is some reason you can't use load-xml2, please file a mantis detailing the reason.");
  972. Vector3 loadOffset = new Vector3(0, 0, 0);
  973. if (cmdparams.Length > 2)
  974. {
  975. bool generateNewIDS = false;
  976. if (cmdparams.Length > 3)
  977. {
  978. if (cmdparams[3] == "-newUID")
  979. {
  980. generateNewIDS = true;
  981. }
  982. if (cmdparams.Length > 4)
  983. {
  984. loadOffset.X = (float) Convert.ToDecimal(cmdparams[4]);
  985. if (cmdparams.Length > 5)
  986. {
  987. loadOffset.Y = (float) Convert.ToDecimal(cmdparams[5]);
  988. }
  989. if (cmdparams.Length > 6)
  990. {
  991. loadOffset.Z = (float) Convert.ToDecimal(cmdparams[6]);
  992. }
  993. m_log.Error("loadOffsets <X,Y,Z> = <" + loadOffset.X + "," + loadOffset.Y + "," +
  994. loadOffset.Z + ">");
  995. }
  996. }
  997. m_sceneManager.LoadCurrentSceneFromXml(cmdparams[0], generateNewIDS, loadOffset);
  998. }
  999. else
  1000. {
  1001. try
  1002. {
  1003. m_sceneManager.LoadCurrentSceneFromXml(DEFAULT_PRIM_BACKUP_FILENAME, false, loadOffset);
  1004. }
  1005. catch (FileNotFoundException)
  1006. {
  1007. m_log.Error("Default xml not found. Usage: load-xml <filename>");
  1008. }
  1009. }
  1010. }
  1011. /// <summary>
  1012. /// Serialize region data to XML2Format
  1013. /// </summary>
  1014. /// <param name="module"></param>
  1015. /// <param name="cmdparams"></param>
  1016. protected void SaveXml2(string module, string[] cmdparams)
  1017. {
  1018. if (cmdparams.Length > 2)
  1019. {
  1020. m_sceneManager.SaveCurrentSceneToXml2(cmdparams[2]);
  1021. }
  1022. else
  1023. {
  1024. m_sceneManager.SaveCurrentSceneToXml2(DEFAULT_PRIM_BACKUP_FILENAME);
  1025. }
  1026. }
  1027. /// <summary>
  1028. /// Load region data from Xml2Format
  1029. /// </summary>
  1030. /// <param name="module"></param>
  1031. /// <param name="cmdparams"></param>
  1032. protected void LoadXml2(string module, string[] cmdparams)
  1033. {
  1034. if (cmdparams.Length > 2)
  1035. {
  1036. try
  1037. {
  1038. m_sceneManager.LoadCurrentSceneFromXml2(cmdparams[2]);
  1039. }
  1040. catch (FileNotFoundException)
  1041. {
  1042. m_log.Error("Specified xml not found. Usage: load xml2 <filename>");
  1043. }
  1044. }
  1045. else
  1046. {
  1047. try
  1048. {
  1049. m_sceneManager.LoadCurrentSceneFromXml2(DEFAULT_PRIM_BACKUP_FILENAME);
  1050. }
  1051. catch (FileNotFoundException)
  1052. {
  1053. m_log.Error("Default xml not found. Usage: load xml2 <filename>");
  1054. }
  1055. }
  1056. }
  1057. /// <summary>
  1058. /// Load a whole region from an opensimulator archive.
  1059. /// </summary>
  1060. /// <param name="cmdparams"></param>
  1061. protected void LoadOar(string module, string[] cmdparams)
  1062. {
  1063. try
  1064. {
  1065. if (cmdparams.Length > 2)
  1066. {
  1067. m_sceneManager.LoadArchiveToCurrentScene(cmdparams[2]);
  1068. }
  1069. else
  1070. {
  1071. m_sceneManager.LoadArchiveToCurrentScene(DEFAULT_OAR_BACKUP_FILENAME);
  1072. }
  1073. }
  1074. catch (Exception e)
  1075. {
  1076. m_log.Error(e.Message);
  1077. }
  1078. }
  1079. /// <summary>
  1080. /// Save a region to a file, including all the assets needed to restore it.
  1081. /// </summary>
  1082. /// <param name="cmdparams"></param>
  1083. protected void SaveOar(string module, string[] cmdparams)
  1084. {
  1085. if (cmdparams.Length > 2)
  1086. {
  1087. m_sceneManager.SaveCurrentSceneToArchive(cmdparams[2]);
  1088. }
  1089. else
  1090. {
  1091. m_sceneManager.SaveCurrentSceneToArchive(DEFAULT_OAR_BACKUP_FILENAME);
  1092. }
  1093. }
  1094. private static string CombineParams(string[] commandParams, int pos)
  1095. {
  1096. string result = String.Empty;
  1097. for (int i = pos; i < commandParams.Length; i++)
  1098. {
  1099. result += commandParams[i] + " ";
  1100. }
  1101. result = result.TrimEnd(' ');
  1102. return result;
  1103. }
  1104. #endregion
  1105. }
  1106. }