12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130 |
- /*
- * Copyright (c) Contributors, http://opensimulator.org/
- * See CONTRIBUTORS.TXT for a full list of copyright holders.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the OpenSim Project nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Net;
- using System.Reflection;
- using System.Runtime;
- using System.Threading;
- using OpenMetaverse;
- using log4net;
- using Nini.Config;
- using OpenSim.Framework;
- using OpenSim.Framework.Console;
- using OpenSim.Framework.Statistics;
- using OpenSim.Region.Environment.Interfaces;
- using OpenSim.Region.Environment.Scenes;
- using OpenSim.Region.Environment.Modules.Avatar.Inventory.Archiver;
- using Timer=System.Timers.Timer;
- namespace OpenSim
- {
- /// <summary>
- /// Interactive OpenSim region server
- /// </summary>
- public class OpenSim : OpenSimBase, conscmd_callback
- {
- private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
- protected string m_startupCommandsFile;
- protected string m_shutdownCommandsFile;
- private string m_timedScript = "disabled";
- private Timer m_scriptTimer;
- /// <summary>
- /// List of Console Plugin Commands
- /// </summary>
- private static List<ConsolePluginCommand> m_PluginCommandInfos = new List<ConsolePluginCommand>();
- public OpenSim(IConfigSource configSource) : base(configSource)
- {
- }
- protected override void ReadExtraConfigSettings()
- {
- base.ReadExtraConfigSettings();
- IConfig startupConfig = m_config.Source.Configs["Startup"];
- if (startupConfig != null)
- {
- m_startupCommandsFile = startupConfig.GetString("startup_console_commands_file", String.Empty);
- m_shutdownCommandsFile = startupConfig.GetString("shutdown_console_commands_file", String.Empty);
- m_timedScript = startupConfig.GetString("timer_Script", "disabled");
- }
- }
- /// <summary>
- /// Performs initialisation of the scene, such as loading configuration from disk.
- /// </summary>
- protected override void StartupSpecific()
- {
- m_log.Info("====================================================================");
- m_log.Info("========================= STARTING OPENSIM =========================");
- m_log.Info("====================================================================");
- m_log.InfoFormat("[OPENSIM MAIN]: Running in {0} mode", (ConfigurationSettings.Standalone ? "sandbox" : "grid"));
- //m_log.InfoFormat("[OPENSIM MAIN]: GC Is Server GC: {0}", GCSettings.IsServerGC.ToString());
- // http://msdn.microsoft.com/en-us/library/bb384202.aspx
- //GCSettings.LatencyMode = GCLatencyMode.Batch;
- //m_log.InfoFormat("[OPENSIM MAIN]: GC Latency Mode: {0}", GCSettings.LatencyMode.ToString());
- m_console = new ConsoleBase("Region", this);
- MainConsole.Instance = m_console;
- base.StartupSpecific();
- //Run Startup Commands
- if (String.IsNullOrEmpty( m_startupCommandsFile ))
- {
- m_log.Info("[STARTUP]: No startup command script specified. Moving on...");
- }
- else
- {
- RunCommandScript(m_startupCommandsFile);
- }
- // Start timer script (run a script every xx seconds)
- if (m_timedScript != "disabled")
- {
- m_scriptTimer = new Timer();
- m_scriptTimer.Enabled = true;
- m_scriptTimer.Interval = 1200 * 1000;
- m_scriptTimer.Elapsed += RunAutoTimerScript;
- }
- PrintFileToConsole("startuplogo.txt");
- RegisterCmd("echoTest", RunEchoTest, "this echos your command args to see how they are parsed");
- RegisterCmd("kickuser", KickUserCommand, "kickuser [first] [last] - attempts to log off a user from any region we are serving");
- // For now, start at the 'root' level by default
- ChangeSelectedRegion(new string[] {"root"});
- }
- public override void ShutdownSpecific()
- {
- if (m_shutdownCommandsFile != String.Empty)
- {
- RunCommandScript(m_shutdownCommandsFile);
- }
- base.ShutdownSpecific();
- }
- private void RunAutoTimerScript(object sender, EventArgs e)
- {
- if (m_timedScript != "disabled")
- {
- RunCommandScript(m_timedScript);
- }
- }
- #region Console Commands
- private void RunEchoTest(string[] cmdparams)
- {
- for (int i = 0; i < cmdparams.Length; i++)
- {
- m_log.Info("[EchoTest]: <arg" + i + ">"+cmdparams[i]+"</arg" + i + ">");
- }
- }
- private void KickUserCommand(string[] cmdparams)
- {
- if (cmdparams.Length < 2)
- return;
- IList agents = m_sceneManager.GetCurrentSceneAvatars();
- foreach (ScenePresence presence in agents)
- {
- RegionInfo regionInfo = m_sceneManager.GetRegionInfo(presence.RegionHandle);
- if (presence.Firstname.ToLower().Contains(cmdparams[0].ToLower()) && presence.Lastname.ToLower().Contains(cmdparams[1].ToLower()))
- {
- m_console.Notice(
- String.Format(
- "Kicking user: {0,-16}{1,-16}{2,-37} in region: {3,-16}",
- presence.Firstname,
- presence.Lastname,
- presence.UUID,
- regionInfo.RegionName));
- presence.Scene.IncomingCloseAgent(presence.UUID);
- }
- }
- m_console.Notice("");
- }
- /// <summary>
- /// Run an optional startup list of commands
- /// </summary>
- /// <param name="fileName"></param>
- private void RunCommandScript(string fileName)
- {
- if (File.Exists(fileName))
- {
- m_log.Info("[COMMANDFILE]: Running " + fileName);
- StreamReader readFile = File.OpenText(fileName);
- string currentCommand;
- while ((currentCommand = readFile.ReadLine()) != null)
- {
- if (currentCommand != String.Empty)
- {
- m_log.Info("[COMMANDFILE]: Running '" + currentCommand + "'");
- m_console.RunCommand(currentCommand);
- }
- }
- }
- }
- private static void PrintFileToConsole(string fileName)
- {
- if (File.Exists(fileName))
- {
- StreamReader readFile = File.OpenText(fileName);
- string currentLine;
- while ((currentLine = readFile.ReadLine()) != null)
- {
- m_log.Info("[!]" + currentLine);
- }
- }
- }
- /// <summary>
- /// Runs commands issued by the server console from the operator
- /// </summary>
- /// <param name="command">The first argument of the parameter (the command)</param>
- /// <param name="cmdparams">Additional arguments passed to the command</param>
- public override void RunCmd(string command, string[] cmdparams)
- {
- base.RunCmd(command, cmdparams);
- RunPluginCommands(command , cmdparams);
- switch (command)
- {
- case "clear-assets":
- m_assetCache.Clear();
- break;
- case "force-update":
- m_console.Notice("Updating all clients");
- m_sceneManager.ForceCurrentSceneClientUpdate();
- break;
- case "edit-scale":
- if (cmdparams.Length == 4)
- {
- m_sceneManager.HandleEditCommandOnCurrentScene(cmdparams);
- }
- break;
- case "debug":
- Debug(cmdparams);
- break;
- case "save-xml":
- SaveXml(cmdparams);
- break;
- case "load-xml":
- LoadXml(cmdparams);
- break;
- case "save-xml2":
- SaveXml2(cmdparams);
- break;
- case "load-xml2":
- LoadXml2(cmdparams);
- break;
- case "save-prims-xml2":
- if (cmdparams.Length > 1)
- {
- m_sceneManager.SaveNamedPrimsToXml2(cmdparams[0], cmdparams[1]);
- }
- else
- {
- m_sceneManager.SaveNamedPrimsToXml2("Primitive", DEFAULT_PRIM_BACKUP_FILENAME);
- }
- break;
- case "load-oar":
- LoadOar(cmdparams);
- break;
- case "save-oar":
- SaveOar(cmdparams);
- break;
- case "save-inv":
- SaveInv(cmdparams);
- break;
- case "load-inv":
- LoadInv(cmdparams);
- break;
- case "plugin":
- m_sceneManager.SendCommandToPluginModules(cmdparams);
- break;
- case "command-script":
- if (cmdparams.Length > 0)
- {
- RunCommandScript(cmdparams[0]);
- }
- break;
- case "backup":
- m_sceneManager.BackupCurrentScene();
- break;
- case "alert":
- m_sceneManager.HandleAlertCommandOnCurrentScene(cmdparams);
- break;
- case "create":
- Create(cmdparams);
- break;
- case "login-enable":
- ProcessLogin(true);
- break;
- case "login-disable":
- ProcessLogin(false);
- break;
- case "login-status":
- if (m_commsManager.GridService.RegionLoginsEnabled == false)
- m_log.Info("[ Login ] Login are disabled ");
- else
- m_log.Info("[ Login ] Login are enabled");
- break;
- case "create-region":
- if (cmdparams.Length < 2)
- {
- m_console.Error("Usage: create-region <region name> <region_file.xml>");
- break;
- }
- string regionsDir = ConfigSource.Source.Configs["Startup"].GetString("regionload_regionsdir", "Regions").Trim();
- string regionFile = String.Format("{0}/{1}", regionsDir, cmdparams[1]);
- // Allow absolute and relative specifiers
- if (cmdparams[1].StartsWith("/") || cmdparams[1].StartsWith("\\") || cmdparams[1].StartsWith(".."))
- regionFile = cmdparams[1];
- CreateRegion(new RegionInfo(cmdparams[0], regionFile, false, ConfigSource.Source), true);
- break;
- case "remove-region":
- string regRemoveName = CombineParams(cmdparams, 0);
- Scene removeScene;
- if (m_sceneManager.TryGetScene(regRemoveName, out removeScene))
- RemoveRegion(removeScene, false);
- else
- m_console.Error("no region with that name");
- break;
- case "delete-region":
- string regDeleteName = CombineParams(cmdparams, 0);
- Scene killScene;
- if (m_sceneManager.TryGetScene(regDeleteName, out killScene))
- RemoveRegion(killScene, true);
- else
- m_console.Error("no region with that name");
- break;
- case "restart":
- m_sceneManager.RestartCurrentScene();
- break;
- case "change-region":
- ChangeSelectedRegion(cmdparams);
- break;
- case "export-map":
- if (cmdparams.Length > 0)
- {
- m_sceneManager.CurrentOrFirstScene.ExportWorldMap(cmdparams[0]);
- }
- else
- {
- m_sceneManager.CurrentOrFirstScene.ExportWorldMap("exportmap.jpg");
- }
- break;
- case "config":
- string n = command.ToUpper();
- if (cmdparams.Length > 0)
- {
- switch (cmdparams[0].ToLower())
- {
- case "set":
- if (cmdparams.Length < 4)
- {
- m_console.Error(n, "SYNTAX: " + n + " SET SECTION KEY VALUE");
- m_console.Error(n, "EXAMPLE: " + n + " SET ScriptEngine.DotNetEngine NumberOfScriptThreads 5");
- }
- else
- {
- // IConfig c = DefaultConfig().Configs[cmdparams[1]];
- // if (c == null)
- // c = DefaultConfig().AddConfig(cmdparams[1]);
- IConfig c;
- IConfigSource source = new IniConfigSource();
- c = source.AddConfig(cmdparams[1]);
- if (c != null)
- {
- string _value = String.Join(" ", cmdparams, 3, cmdparams.Length - 3);
- c.Set(cmdparams[2], _value);
- m_config.Source.Merge(source);
- m_console.Error(n, n + " " + n + " " + cmdparams[1] + " " + cmdparams[2] + " " +
- _value);
- }
- }
- break;
- case "get":
- if (cmdparams.Length < 3)
- {
- m_console.Error(n, "SYNTAX: " + n + " GET SECTION KEY");
- m_console.Error(n, "EXAMPLE: " + n + " GET ScriptEngine.DotNetEngine NumberOfScriptThreads");
- }
- else
- {
- IConfig c = m_config.Source.Configs[cmdparams[1]]; // DefaultConfig().Configs[cmdparams[1]];
- if (c == null)
- {
- m_console.Notice(n, "Section \"" + cmdparams[1] + "\" does not exist.");
- break;
- }
- else
- {
- m_console.Notice(n + " GET " + cmdparams[1] + " " + cmdparams[2] + ": " +
- c.GetString(cmdparams[2]));
- }
- }
- break;
- case "save":
- m_console.Notice("Saving configuration file: " + Application.iniFilePath);
- m_config.Save(Application.iniFilePath);
- break;
- }
- }
- break;
- case "modules":
- if (cmdparams.Length > 0)
- {
- switch (cmdparams[0].ToLower())
- {
- case "list":
- foreach (IRegionModule irm in m_moduleLoader.GetLoadedSharedModules)
- {
- m_console.Notice("Shared region module: " + irm.Name);
- }
- break;
- case "unload":
- if (cmdparams.Length > 1)
- {
- foreach (IRegionModule rm in new ArrayList(m_moduleLoader.GetLoadedSharedModules))
- {
- if (rm.Name.ToLower() == cmdparams[1].ToLower())
- {
- m_console.Notice("Unloading module: " + rm.Name);
- m_moduleLoader.UnloadModule(rm);
- }
- }
- }
- break;
- case "load":
- if (cmdparams.Length > 1)
- {
- foreach (Scene s in new ArrayList(m_sceneManager.Scenes))
- {
- m_console.Notice("Loading module: " + cmdparams[1]);
- m_moduleLoader.LoadRegionModules(cmdparams[1], s);
- }
- }
- break;
- }
- }
- break;
- case "Add-InventoryHost":
- if (cmdparams.Length > 0)
- {
- m_commsManager.AddInventoryService(cmdparams[0]);
- }
- break;
- case "reset":
- Reset(cmdparams);
- break;
- default:
- string[] tmpPluginArgs = new string[cmdparams.Length + 1];
- cmdparams.CopyTo(tmpPluginArgs, 1);
- tmpPluginArgs[0] = command;
- m_sceneManager.SendCommandToPluginModules(tmpPluginArgs);
- break;
- }
- }
- /// <summary>
- /// Change the currently selected region. The selected region is that operated upon by single region commands.
- /// </summary>
- /// <param name="cmdParams"></param>
- protected void ChangeSelectedRegion(string[] cmdparams)
- {
- if (cmdparams.Length > 0)
- {
- string newRegionName = CombineParams(cmdparams, 0);
- if (!m_sceneManager.TrySetCurrentScene(newRegionName))
- m_console.Error("Couldn't select region " + newRegionName);
- }
- else
- {
- m_console.Error("Usage: change-region <region name>");
- }
- string regionName = (m_sceneManager.CurrentScene == null ? "root" : m_sceneManager.CurrentScene.RegionInfo.RegionName);
- m_console.Notice(String.Format("Currently selected region is {0}", regionName));
- m_console.DefaultPrompt = String.Format("Region ({0}) ", regionName);
- }
- /// <summary>
- /// Execute switch for some of the create commands
- /// </summary>
- /// <param name="args"></param>
- protected void Create(string[] args)
- {
- if (args.Length == 0)
- return;
- switch (args[0])
- {
- case "user":
- if (ConfigurationSettings.Standalone)
- {
- CreateUser(args);
- }
- else
- {
- m_console.Notice("Create user is not available in grid mode, use the user server.");
- }
- break;
- }
- }
- /// <summary>
- /// Execute switch for some of the reset commands
- /// </summary>
- /// <param name="args"></param>
- protected void Reset(string[] args)
- {
- if (args.Length == 0)
- return;
- switch (args[0])
- {
- case "user":
- switch (args[1])
- {
- case "password":
- if (ConfigurationSettings.Standalone)
- {
- ResetUserPassword(args);
- }
- else
- {
- m_console.Notice("Reset user password is not available in grid mode, use the user-server.");
- }
- break;
- }
- break;
- }
- }
- /// <summary>
- /// Turn on some debugging values for OpenSim.
- /// </summary>
- /// <param name="args"></param>
- protected void Debug(string[] args)
- {
- if (args.Length == 0)
- return;
- switch (args[0])
- {
- case "packet":
- if (args.Length > 1)
- {
- int newDebug;
- if (int.TryParse(args[1], out newDebug))
- {
- m_sceneManager.SetDebugPacketLevelOnCurrentScene(newDebug);
- }
- else
- {
- m_console.Error("packet debug should be 0..255");
- }
- m_console.Notice("New packet debug: " + newDebug.ToString());
- }
- break;
- case "scene":
- if (args.Length == 4)
- {
- if (m_sceneManager.CurrentScene == null)
- {
- m_console.Error("CONSOLE", "Please use 'change-region <regioname>' first");
- }
- else
- {
- bool scriptingOn = !Convert.ToBoolean(args[1]);
- bool collisionsOn = !Convert.ToBoolean(args[2]);
- bool physicsOn = !Convert.ToBoolean(args[3]);
- m_sceneManager.CurrentScene.SetSceneCoreDebug(scriptingOn, collisionsOn, physicsOn);
- m_console.Notice(
- "CONSOLE",
- String.Format(
- "Set debug scene scripting = {0}, collisions = {1}, physics = {2}",
- !scriptingOn, !collisionsOn, !physicsOn));
- }
- }
- else
- {
- m_console.Error("debug scene <scripting> <collisions> <physics> (where inside <> is true/false)");
- }
- break;
- default:
- m_console.Error("Unknown debug");
- break;
- }
- }
- protected override void ShowHelp(string[] helpArgs)
- {
- base.ShowHelp(helpArgs);
- m_console.Notice("alert - send alert to a designated user or all users.");
- m_console.Notice(" alert [First] [Last] [Message] - send an alert to a user. Case sensitive.");
- m_console.Notice(" alert general [Message] - send an alert to all users.");
- m_console.Notice("backup - persist simulator objects to the database ahead of the normal schedule.");
- m_console.Notice("clear-assets - clear the asset cache");
- m_console.Notice("create-region <name> <regionfile.xml> - create a new region");
- m_console.Notice("change-region <name> - select the region that single region commands operate upon.");
- m_console.Notice("command-script [filename] - Execute command in a file.");
- m_console.Notice("debug - debugging commands");
- m_console.Notice(" debug packet 0..255 - print incoming/outgoing packets (0=off)");
- m_console.Notice(" debug scene [scripting] [collision] [physics] - Enable/Disable debug stuff, each can be True/False");
- m_console.Notice("edit-scale [prim name] [x] [y] [z] - resize given prim");
- m_console.Notice("export-map [filename] - save image of world map");
- m_console.Notice("force-update - force an update of prims in the scene");
- m_console.Notice("restart - disconnects all clients and restarts the sims in the instance.");
- m_console.Notice("remove-region [name] - remove a region");
- m_console.Notice("delete-region [name] - delete a region and its associated region file");
- m_console.Notice("load-xml [filename] - load prims from XML (DEPRECATED)");
- m_console.Notice("save-xml [filename] - save prims to XML (DEPRECATED)");
- m_console.Notice("save-xml2 [filename] - save prims to XML using version 2 format");
- m_console.Notice("load-xml2 [filename] - load prims from XML using version 2 format");
- m_console.Notice("load-oar [filename] - load an OpenSimulator region archive. This replaces everything in the current region.");
- m_console.Notice("save-oar [filename] - Save the current region to an OpenSimulator region archive.");
- m_console.Notice("script - manually trigger scripts? or script commands?");
- m_console.Notice("show assets - show state of asset cache.");
- m_console.Notice("show modules - shows info about loaded modules.");
- m_console.Notice("show queues - show packet queues length for all clients.");
- m_console.Notice("show regions - show running region information.");
- m_console.Notice("show users - show info about connected users (only root agents).");
- m_console.Notice("show users full - show info about connected users (root and child agents).");
- m_console.Notice("config set section field value - set a config value");
- m_console.Notice("config get section field - get a config value");
- m_console.Notice("config save - save OpenSim.ini");
- m_console.Notice("terrain help - show help for terrain commands.");
- m_console.Notice("login-enable - Allows login at sim level");
- m_console.Notice("login-disable - Disable login at sim level");
- m_console.Notice("login-status - Show the actual login status");
- ShowPluginCommandsHelp(CombineParams(helpArgs, 0), m_console);
- if (ConfigurationSettings.Standalone)
- {
- m_console.Notice("");
- m_console.Notice("create user - adds a new user.");
- m_console.Notice("reset user password - reset a user's password.");
- }
- }
- // see BaseOpenSimServer
- public override void Show(string[] showParams)
- {
- base.Show(showParams);
- switch (showParams[0])
- {
- case "assets":
- m_assetCache.ShowState();
- break;
- case "users":
- IList agents;
- if (showParams.Length > 1 && showParams[1] == "full")
- {
- agents = m_sceneManager.GetCurrentScenePresences();
- }
- else
- {
- agents = m_sceneManager.GetCurrentSceneAvatars();
- }
- m_console.Notice(String.Format("\nAgents connected: {0}\n", agents.Count));
- m_console.Notice(
- String.Format("{0,-16}{1,-16}{2,-37}{3,-11}{4,-16}", "Firstname", "Lastname",
- "Agent ID", "Root/Child", "Region"));
- foreach (ScenePresence presence in agents)
- {
- RegionInfo regionInfo = m_sceneManager.GetRegionInfo(presence.RegionHandle);
- string regionName;
- if (regionInfo == null)
- {
- regionName = "Unresolvable";
- }
- else
- {
- regionName = regionInfo.RegionName;
- }
- m_console.Notice(
- String.Format(
- "{0,-16}{1,-16}{2,-37}{3,-11}{4,-16}",
- presence.Firstname,
- presence.Lastname,
- presence.UUID,
- presence.IsChildAgent ? "Child" : "Root",
- regionName));
- }
- m_console.Notice("");
- break;
- case "modules":
- m_console.Notice("The currently loaded shared modules are:");
- foreach (IRegionModule module in m_moduleLoader.GetLoadedSharedModules)
- {
- m_console.Notice("Shared Module: " + module.Name);
- }
- break;
- case "regions":
- m_sceneManager.ForEachScene(
- delegate(Scene scene)
- {
- m_console.Notice("Region Name: " + scene.RegionInfo.RegionName + " , Region XLoc: " +
- scene.RegionInfo.RegionLocX + " , Region YLoc: " +
- scene.RegionInfo.RegionLocY + " , Region Port: " + scene.RegionInfo.InternalEndPoint.Port.ToString());
- });
- break;
- case "queues":
- Notice(GetQueuesReport());
- break;
- }
- }
- private string GetQueuesReport()
- {
- string report = String.Empty;
- m_sceneManager.ForEachScene(delegate(Scene scene)
- {
- scene.ForEachClient(delegate(IClientAPI client)
- {
- if (client is IStatsCollector)
- {
- report = report + client.FirstName +
- " " + client.LastName + "\n";
- IStatsCollector stats =
- (IStatsCollector) client;
- 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",
- "Send",
- "In",
- "Out",
- "Resend",
- "Land",
- "Wind",
- "Cloud",
- "Task",
- "Texture",
- "Asset");
- report = report + stats.Report() +
- "\n\n";
- }
- });
- });
- return report;
- }
- /// <summary>
- /// Create a new user
- /// </summary>
- /// <param name="cmdparams">string array with parameters: firstname, lastname, password, locationX, locationY, email</param>
- protected void CreateUser(string[] cmdparams)
- {
- string firstName;
- string lastName;
- string password;
- string email;
- uint regX = 1000;
- uint regY = 1000;
- if (cmdparams.Length < 2)
- firstName = MainConsole.Instance.CmdPrompt("First name", "Default");
- else firstName = cmdparams[1];
- if ( cmdparams.Length < 3 )
- lastName = MainConsole.Instance.CmdPrompt("Last name", "User");
- else lastName = cmdparams[2];
- if (cmdparams.Length < 4)
- password = MainConsole.Instance.PasswdPrompt("Password");
- else password = cmdparams[3];
- if ( cmdparams.Length < 5 )
- regX = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region X", regX.ToString()));
- else regX = Convert.ToUInt32(cmdparams[4]);
- if ( cmdparams.Length < 6 )
- regY = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region Y", regY.ToString()));
- else regY = Convert.ToUInt32(cmdparams[5]);
- if (cmdparams.Length < 7)
- email = MainConsole.Instance.CmdPrompt("Email", "");
- else email = cmdparams[6];
- if (null == m_commsManager.UserService.GetUserProfile(firstName, lastName))
- {
- m_commsManager.UserAdminService.AddUser(firstName, lastName, password, email, regX, regY);
- }
- else
- {
- m_log.ErrorFormat("[CONSOLE]: A user with the name {0} {1} already exists!", firstName, lastName);
- }
- }
- /// <summary>
- /// Reset a user password.
- /// </summary>
- /// <param name="cmdparams"></param>
- private void ResetUserPassword(string[] cmdparams)
- {
- string firstName;
- string lastName;
- string newPassword;
- if (cmdparams.Length < 3)
- firstName = MainConsole.Instance.CmdPrompt("First name");
- else firstName = cmdparams[2];
- if ( cmdparams.Length < 4 )
- lastName = MainConsole.Instance.CmdPrompt("Last name");
- else lastName = cmdparams[3];
- if ( cmdparams.Length < 5 )
- newPassword = MainConsole.Instance.PasswdPrompt("New password");
- else newPassword = cmdparams[4];
- m_commsManager.UserAdminService.ResetUserPassword(firstName, lastName, newPassword);
- }
- protected void SaveXml(string[] cmdparams)
- {
- 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.");
- if (cmdparams.Length > 0)
- {
- m_sceneManager.SaveCurrentSceneToXml(cmdparams[0]);
- }
- else
- {
- m_sceneManager.SaveCurrentSceneToXml(DEFAULT_PRIM_BACKUP_FILENAME);
- }
- }
- protected void LoadXml(string[] cmdparams)
- {
- 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.");
- Vector3 loadOffset = new Vector3(0, 0, 0);
- if (cmdparams.Length > 0)
- {
- bool generateNewIDS = false;
- if (cmdparams.Length > 1)
- {
- if (cmdparams[1] == "-newUID")
- {
- generateNewIDS = true;
- }
- if (cmdparams.Length > 2)
- {
- loadOffset.X = (float) Convert.ToDecimal(cmdparams[2]);
- if (cmdparams.Length > 3)
- {
- loadOffset.Y = (float) Convert.ToDecimal(cmdparams[3]);
- }
- if (cmdparams.Length > 4)
- {
- loadOffset.Z = (float) Convert.ToDecimal(cmdparams[4]);
- }
- m_console.Error("loadOffsets <X,Y,Z> = <" + loadOffset.X + "," + loadOffset.Y + "," +
- loadOffset.Z + ">");
- }
- }
- m_sceneManager.LoadCurrentSceneFromXml(cmdparams[0], generateNewIDS, loadOffset);
- }
- else
- {
- try
- {
- m_sceneManager.LoadCurrentSceneFromXml(DEFAULT_PRIM_BACKUP_FILENAME, false, loadOffset);
- }
- catch
- {
- m_console.Error("Default xml not found. Usage: load-xml <filename>");
- }
- }
- }
- protected void SaveXml2(string[] cmdparams)
- {
- if (cmdparams.Length > 0)
- {
- m_sceneManager.SaveCurrentSceneToXml2(cmdparams[0]);
- }
- else
- {
- m_sceneManager.SaveCurrentSceneToXml2(DEFAULT_PRIM_BACKUP_FILENAME);
- }
- }
- protected void LoadXml2(string[] cmdparams)
- {
- if (cmdparams.Length > 0)
- {
- m_sceneManager.LoadCurrentSceneFromXml2(cmdparams[0]);
- }
- else
- {
- try
- {
- m_sceneManager.LoadCurrentSceneFromXml2(DEFAULT_PRIM_BACKUP_FILENAME);
- }
- catch
- {
- m_console.Error("Default xml not found. Usage: load-xml2 <filename>");
- }
- }
- }
- /// <summary>
- /// Load a whole region from an opensim archive.
- /// </summary>
- /// <param name="cmdparams"></param>
- protected void LoadOar(string[] cmdparams)
- {
- if (cmdparams.Length > 0)
- {
- m_sceneManager.LoadArchiveToCurrentScene(cmdparams[0]);
- }
- else
- {
- try
- {
- m_sceneManager.LoadArchiveToCurrentScene(DEFAULT_OAR_BACKUP_FILENAME);
- }
- catch
- {
- m_console.Error("Default oar not found. Usage: load-oar <filename>");
- }
- }
- }
- /// <summary>
- /// Save a region to a file, including all the assets needed to restore it.
- /// </summary>
- /// <param name="cmdparams"></param>
- protected void SaveOar(string[] cmdparams)
- {
- if (cmdparams.Length > 0)
- {
- m_sceneManager.SaveCurrentSceneToArchive(cmdparams[0]);
- }
- else
- {
- m_sceneManager.SaveCurrentSceneToArchive(DEFAULT_OAR_BACKUP_FILENAME);
- }
- }
- /// <summary>
- /// Load inventory from an inventory file archive
- /// </summary>
- /// <param name="cmdparams"></param>
- protected void LoadInv(string[] cmdparams)
- {
- m_log.Error("[CONSOLE]: This command has not yet been implemented!");
- if (cmdparams.Length < 3)
- {
- m_log.Error("[CONSOLE]: usage is load-inv <first name> <last name> <inventory path> [<load file path>]");
- return;
- }
- string firstName = cmdparams[0];
- string lastName = cmdparams[1];
- string invPath = cmdparams[2];
- string loadPath = (cmdparams.Length > 3 ? cmdparams[3] : DEFAULT_INV_BACKUP_FILENAME);
- new InventoryArchiveReadRequest(
- m_sceneManager.CurrentOrFirstScene, m_commsManager).execute(
- firstName, lastName, invPath, loadPath);
- }
- /// <summary>
- /// Save inventory to a file archive
- /// </summary>
- /// <param name="cmdparams"></param>
- protected void SaveInv(string[] cmdparams)
- {
- m_log.Error("[CONSOLE]: This command has not yet been implemented!");
- if (cmdparams.Length < 3)
- {
- m_log.Error("[CONSOLE]: usage is save-inv <first name> <last name> <inventory path> [<save file path>]");
- return;
- }
- string firstName = cmdparams[0];
- string lastName = cmdparams[1];
- string invPath = cmdparams[2];
- string savePath = (cmdparams.Length > 3 ? cmdparams[3] : DEFAULT_INV_BACKUP_FILENAME);
- new InventoryArchiveWriteRequest(
- m_sceneManager.CurrentOrFirstScene,m_commsManager).execute(
- firstName, lastName, invPath, savePath);
- }
- private static string CombineParams(string[] commandParams, int pos)
- {
- string result = String.Empty;
- for (int i = pos; i < commandParams.Length; i++)
- {
- result += commandParams[i] + " ";
- }
- result = result.TrimEnd(' ');
- return result;
- }
- /// <summary>
- /// Runs the best matching plugin command
- ///
- /// returns true if a match was found, false otherwise.
- /// </summary>
- public bool RunPluginCommands(string cmd, string[] withParams)
- {
- ConsolePluginCommand bestMatch = null;
- int bestLength = 0;
- String cmdWithParams = cmd + " " + String.Join(" ",withParams);
- foreach (ConsolePluginCommand cmdinfo in m_PluginCommandInfos)
- {
- int matchLen = cmdinfo.matchLength(cmdWithParams);
- if (matchLen > bestLength)
- {
- bestMatch = cmdinfo;
- bestLength = matchLen;
- }
- }
- if (bestMatch == null) return false;
- bestMatch.Run(cmd,withParams);//.Substring(bestLength));
- return true;
- }
- /// <summary>
- /// Show the matching plugins command help
- /// </summary>
- public void ShowPluginCommandsHelp(string cmdWithParams, ConsoleBase console)
- {
- foreach (ConsolePluginCommand cmdinfo in m_PluginCommandInfos)
- {
- if (cmdinfo.IsHelpfull(cmdWithParams))
- {
- cmdinfo.ShowHelp(console);
- }
- }
- }
- /// <summary>
- /// Registers a new console plugin command
- /// </summary>
- public static void RegisterCmd(string cmd, ConsoleCommand deligate, string help)
- {
- RegisterConsolePluginCommand(new ConsolePluginCommand(cmd, deligate, help));
- }
- /// <summary>
- /// Registers a new console plugin command
- /// </summary>
- public static void RegisterConsolePluginCommand(ConsolePluginCommand pluginCommand)
- {
- m_PluginCommandInfos.Add(pluginCommand);
- }
- #endregion
- }
- }
|