OpenSim.cs 49 KB

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