mirror of
https://github.com/opensim/opensim.git
synced 2026-08-07 17:55:48 +08:00
Replace the console for all OpenSim apps with a new console featuring command
line editing, context sensitive help (press ? at any time), command line history, a new plugin command system and new appender features thet let you type while the console is scrolling. Seamlessly integrates the ICommander interfaces.
This commit is contained in:
@@ -34,6 +34,7 @@ using log4net.Config;
|
||||
using Nini.Config;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Console;
|
||||
using OpenSim.Region.Framework.Scenes;
|
||||
|
||||
namespace OpenSim
|
||||
{
|
||||
@@ -46,6 +47,8 @@ namespace OpenSim
|
||||
public static bool m_saveCrashDumps = false;
|
||||
public static string m_crashDir = "crashes";
|
||||
|
||||
protected static OpenSimBase m_sim = null;
|
||||
|
||||
//could move our main function into OpenSimMain and kill this class
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
@@ -93,18 +96,18 @@ namespace OpenSim
|
||||
|
||||
if (background)
|
||||
{
|
||||
OpenSimBase sim = new OpenSimBackground(configSource);
|
||||
sim.Startup();
|
||||
m_sim = new OpenSimBackground(configSource);
|
||||
m_sim.Startup();
|
||||
}
|
||||
else
|
||||
{
|
||||
OpenSimBase sim = null;
|
||||
m_sim = null;
|
||||
if (hgrid)
|
||||
sim = new HGOpenSimNode(configSource);
|
||||
m_sim = new HGOpenSimNode(configSource);
|
||||
else
|
||||
sim = new OpenSim(configSource);
|
||||
m_sim = new OpenSim(configSource);
|
||||
|
||||
sim.Startup();
|
||||
m_sim.Startup();
|
||||
|
||||
while (true)
|
||||
{
|
||||
|
||||
@@ -77,6 +77,9 @@ namespace OpenSim
|
||||
m_log.Info("====================================================================");
|
||||
|
||||
base.StartupSpecific();
|
||||
|
||||
MainConsole.Instance.Commands.AddCommand("hypergrid", "link-mapping", "link-mapping [<x> <y>] <cr>", "Set local coordinate to map HG regions to", RunCommand);
|
||||
MainConsole.Instance.Commands.AddCommand("hypergrid", "link-region", "link-region <Xloc> <Yloc> <HostName> <HttpPort> <LocalName> <cr>", "Link a hypergrid region", RunCommand);
|
||||
}
|
||||
|
||||
protected override void InitialiseStandaloneServices(LibraryRootFolder libraryRootFolder)
|
||||
@@ -143,11 +146,18 @@ namespace OpenSim
|
||||
m_configSettings.See_into_region_from_neighbor, m_config.Source, m_version);
|
||||
}
|
||||
|
||||
public override void RunCmd(string command, string[] cmdparams)
|
||||
public void RunCommand(string module, string[] cp)
|
||||
{
|
||||
List<string> cmdparams = new List<string>(cp);
|
||||
if (cmdparams.Count < 1)
|
||||
return;
|
||||
|
||||
string command = cmdparams[0];
|
||||
cmdparams.RemoveAt(0);
|
||||
|
||||
if (command.Equals("link-mapping"))
|
||||
{
|
||||
if (cmdparams.Length == 2)
|
||||
if (cmdparams.Count == 2)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -166,11 +176,11 @@ namespace OpenSim
|
||||
else if (command.Equals("link-region"))
|
||||
{
|
||||
// link-region <Xloc> <Yloc> <HostName> <HttpPort> <LocalName>
|
||||
if (cmdparams.Length < 4)
|
||||
if (cmdparams.Count < 4)
|
||||
{
|
||||
if ((cmdparams.Length == 1) || (cmdparams.Length ==2))
|
||||
if ((cmdparams.Count == 1) || (cmdparams.Count ==2))
|
||||
{
|
||||
LoadXmlLinkFile(cmdparams);
|
||||
LoadXmlLinkFile(cmdparams.ToArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -201,19 +211,16 @@ namespace OpenSim
|
||||
|
||||
if (TryCreateLink(xloc, yloc, externalPort, externalHostName, out regInfo))
|
||||
{
|
||||
if (cmdparams.Length >= 5)
|
||||
if (cmdparams.Count >= 5)
|
||||
{
|
||||
regInfo.RegionName = "";
|
||||
for (int i = 4; i < cmdparams.Length; i++)
|
||||
for (int i = 4; i < cmdparams.Count; i++)
|
||||
regInfo.RegionName += cmdparams[i] + " ";
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
base.RunCmd(command, cmdparams);
|
||||
|
||||
}
|
||||
|
||||
private void LoadXmlLinkFile(string[] cmdparams)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -198,6 +198,46 @@ namespace OpenSim
|
||||
|
||||
// Only enable logins to the regions once we have completely finished starting up (apart from scripts)
|
||||
m_commsManager.GridService.RegionLoginsEnabled = true;
|
||||
|
||||
List<string> topics = GetHelpTopics();
|
||||
|
||||
foreach (string topic in topics)
|
||||
{
|
||||
m_console.Commands.AddCommand("plugin", "help "+topic,
|
||||
"help "+topic,
|
||||
"Get help on plugin command '"+topic+"'",
|
||||
HandleCommanderHelp);
|
||||
|
||||
m_console.Commands.AddCommand("plugin", topic,
|
||||
topic,
|
||||
"Execute subcommand for plugin '"+topic+"'",
|
||||
null);
|
||||
|
||||
ICommander commander =
|
||||
SceneManager.CurrentOrFirstScene.GetCommanders()[topic];
|
||||
|
||||
if (commander == null)
|
||||
continue;
|
||||
|
||||
foreach (string command in commander.Commands.Keys)
|
||||
{
|
||||
m_console.Commands.AddCommand(topic, topic+" "+command,
|
||||
topic+" "+commander.Commands[command].ShortHelp(),
|
||||
String.Empty, HandleCommanderCommand);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleCommanderCommand(string module, string[] cmd)
|
||||
{
|
||||
m_sceneManager.SendCommandToPluginModules(cmd);
|
||||
}
|
||||
|
||||
private void HandleCommanderHelp(string module, string[] cmd)
|
||||
{
|
||||
ICommander moduleCommander = SceneManager.CurrentOrFirstScene.GetCommander(cmd[1]);
|
||||
if (moduleCommander != null)
|
||||
m_console.Notice(moduleCommander.Help);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -108,6 +108,8 @@ namespace OpenSim.Region.ClientStack
|
||||
|
||||
m_log.Info("[REGION]: Starting HTTP server");
|
||||
m_httpServer.Start();
|
||||
|
||||
base.StartupSpecific();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -88,6 +88,18 @@ namespace OpenSim.Region.Environment.Modules.Framework.InterfaceCommander
|
||||
}
|
||||
}
|
||||
|
||||
public string ShortHelp()
|
||||
{
|
||||
string help = m_name;
|
||||
|
||||
foreach (CommandArgument arg in m_args)
|
||||
{
|
||||
help += " <" + arg.Name + ">";
|
||||
}
|
||||
|
||||
return help;
|
||||
}
|
||||
|
||||
public void ShowConsoleHelp()
|
||||
{
|
||||
Console.WriteLine("== " + Name + " ==");
|
||||
|
||||
@@ -32,21 +32,20 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using log4net;
|
||||
using OpenSim;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.Framework.Interfaces;
|
||||
using OpenSim.Region.Framework.Scenes;
|
||||
using OpenSim.Region.Environment.Modules.Framework;
|
||||
using OpenSim.Region.Environment.Modules.Framework.InterfaceCommander;
|
||||
using OpenSim.Framework.Communications.Cache;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules.World.Permissions
|
||||
{
|
||||
public class PermissionsModule : IRegionModule, ICommandableModule
|
||||
public class PermissionsModule : IRegionModule
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
protected Scene m_scene;
|
||||
private readonly Commander m_commander = new Commander("permissions");
|
||||
|
||||
#region Constants
|
||||
// These are here for testing. They will be taken out
|
||||
@@ -94,60 +93,6 @@ namespace OpenSim.Region.Environment.Modules.World.Permissions
|
||||
|
||||
#endregion
|
||||
|
||||
#region ICommandableModule Members
|
||||
|
||||
public ICommander CommandInterface
|
||||
{
|
||||
get { throw new System.NotImplementedException(); }
|
||||
}
|
||||
|
||||
private void InterfaceDebugPermissions(Object[] args)
|
||||
{
|
||||
if ((bool)args[0] == true)
|
||||
{
|
||||
m_debugPermissions = true;
|
||||
m_log.Info("[PERMISSIONS]: Permissions Debugging Enabled.");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_debugPermissions = false;
|
||||
m_log.Info("[PERMISSIONS]: Permissions Debugging Disabled.");
|
||||
}
|
||||
}
|
||||
|
||||
private void InterfaceBypassPermissions(Object[] args)
|
||||
{
|
||||
if ((bool)args[0] == true)
|
||||
{
|
||||
m_log.Info("[PERMISSIONS]: Permissions Bypass Enabled.");
|
||||
m_bypassPermissionsValue = (bool)args[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
m_bypassPermissions = false;
|
||||
m_log.Info("[PERMISSIONS]: Permissions Bypass Disabled. Normal Operation.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes commandline input. Do not call directly.
|
||||
/// </summary>
|
||||
/// <param name="args">Commandline arguments</param>
|
||||
private void EventManager_OnPluginConsole(string[] args)
|
||||
{
|
||||
if (args[0] == "permissions")
|
||||
{
|
||||
string[] tmpArgs = new string[args.Length - 2];
|
||||
int i;
|
||||
for (i = 2; i < args.Length; i++)
|
||||
tmpArgs[i - 2] = args[i];
|
||||
|
||||
m_commander.ProcessConsoleCommand(args[1], tmpArgs);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IRegionModule Members
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
@@ -226,20 +171,89 @@ namespace OpenSim.Region.Environment.Modules.World.Permissions
|
||||
|
||||
m_scene.Permissions.AddCanTeleportHandler(CanTeleport); //NOT YET IMPLEMENTED
|
||||
|
||||
//Register Debug Commands
|
||||
Command bypassCommand = new Command("bypass", CommandIntentions.COMMAND_HAZARDOUS, InterfaceBypassPermissions, "Force the permissions a specific way to test permissions");
|
||||
bypassCommand.AddArgument("enable_bypass_perms", "true to enable bypassing all perms", "Boolean");
|
||||
bypassCommand.AddArgument("bypass_perms_value", "true/false: true will ignore all perms; false will restrict everything", "Boolean");
|
||||
m_scene.AddCommand("permissions", "bypass permissions",
|
||||
"bypass permissions <true / false>",
|
||||
"Bypass permission checks",
|
||||
HandleBypassPermissions);
|
||||
|
||||
m_commander.RegisterCommand("bypass", bypassCommand);
|
||||
m_scene.AddCommand("permissions", "force permissions",
|
||||
"force permissions <true / false>",
|
||||
"Force permissions on or off",
|
||||
HandleForcePermissions);
|
||||
|
||||
Command debugCommand = new Command("debug", CommandIntentions.COMMAND_STATISTICAL, InterfaceDebugPermissions, "Force the permissions a specific way to test permissions");
|
||||
debugCommand.AddArgument("enable_debug_perms", "true to enable debugging to console all perms", "Boolean");
|
||||
m_scene.AddCommand("permissions", "debug permissions",
|
||||
"debug permissions <true / false>",
|
||||
"Enable permissions debugging",
|
||||
HandleDebugPermissions);
|
||||
}
|
||||
|
||||
m_commander.RegisterCommand("debug", debugCommand);
|
||||
m_scene.RegisterModuleCommander(m_commander);
|
||||
public void HandleBypassPermissions(string module, string[] args)
|
||||
{
|
||||
if (m_scene.ConsoleScene() != null &&
|
||||
m_scene.ConsoleScene() != m_scene)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_scene.EventManager.OnPluginConsole += new EventManager.OnPluginConsoleDelegate(EventManager_OnPluginConsole);
|
||||
if (args.Length > 2)
|
||||
{
|
||||
bool val;
|
||||
|
||||
if (!bool.TryParse(args[2], out val))
|
||||
return;
|
||||
|
||||
m_bypassPermissions = val;
|
||||
|
||||
m_log.InfoFormat("[PERMISSIONS] Set permissions bypass to {0} for {1}", m_bypassPermissions, m_scene.RegionInfo.RegionName);
|
||||
}
|
||||
}
|
||||
|
||||
public void HandleForcePermissions(string module, string[] args)
|
||||
{
|
||||
if (m_scene.ConsoleScene() != null &&
|
||||
m_scene.ConsoleScene() != m_scene)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_bypassPermissions)
|
||||
{
|
||||
m_log.Error("[PERMISSIONS] Permissions can't be forced unless they are bypassed first");
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Length > 2)
|
||||
{
|
||||
bool val;
|
||||
|
||||
if (!bool.TryParse(args[2], out val))
|
||||
return;
|
||||
|
||||
m_bypassPermissionsValue = val;
|
||||
|
||||
m_log.InfoFormat("[PERMISSIONS] Forced permissions to {0} in {1}", m_bypassPermissionsValue, m_scene.RegionInfo.RegionName);
|
||||
}
|
||||
}
|
||||
|
||||
public void HandleDebugPermissions(string module, string[] args)
|
||||
{
|
||||
if (m_scene.ConsoleScene() != null &&
|
||||
m_scene.ConsoleScene() != m_scene)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Length > 2)
|
||||
{
|
||||
bool val;
|
||||
|
||||
if (!bool.TryParse(args[2], out val))
|
||||
return;
|
||||
|
||||
m_debugPermissions = val;
|
||||
|
||||
m_log.InfoFormat("[PERMISSIONS] Set permissions debugging to {0} in {1}", m_debugPermissions, m_scene.RegionInfo.RegionName);
|
||||
}
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
|
||||
@@ -46,5 +46,6 @@ namespace OpenSim.Region.Framework.Interfaces
|
||||
|
||||
void Run(object[] args);
|
||||
void ShowConsoleHelp();
|
||||
string ShortHelp();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ using OpenMetaverse;
|
||||
using OpenMetaverse.Imaging;
|
||||
using OpenMetaverse.Packets;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Console;
|
||||
using OpenSim.Framework.Communications;
|
||||
using OpenSim.Framework.Communications.Cache;
|
||||
using OpenSim.Framework.Servers;
|
||||
@@ -3384,7 +3385,7 @@ namespace OpenSim.Region.Framework.Scenes
|
||||
/// <param name="cmdparams"></param>
|
||||
public void HandleEditCommand(string[] cmdparams)
|
||||
{
|
||||
Console.WriteLine("Searching for Primitive: '" + cmdparams[0] + "'");
|
||||
Console.WriteLine("Searching for Primitive: '" + cmdparams[2] + "'");
|
||||
|
||||
List<EntityBase> EntityList = GetEntities();
|
||||
|
||||
@@ -3395,11 +3396,11 @@ namespace OpenSim.Region.Framework.Scenes
|
||||
SceneObjectPart part = ((SceneObjectGroup)ent).GetChildPart(((SceneObjectGroup)ent).UUID);
|
||||
if (part != null)
|
||||
{
|
||||
if (part.Name == cmdparams[0])
|
||||
if (part.Name == cmdparams[2])
|
||||
{
|
||||
part.Resize(
|
||||
new Vector3(Convert.ToSingle(cmdparams[1]), Convert.ToSingle(cmdparams[2]),
|
||||
Convert.ToSingle(cmdparams[3])));
|
||||
new Vector3(Convert.ToSingle(cmdparams[3]), Convert.ToSingle(cmdparams[4]),
|
||||
Convert.ToSingle(cmdparams[5])));
|
||||
|
||||
Console.WriteLine("Edited scale of Primitive: " + part.Name);
|
||||
}
|
||||
@@ -4235,5 +4236,14 @@ namespace OpenSim.Region.Framework.Scenes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Scene ConsoleScene()
|
||||
{
|
||||
if (MainConsole.Instance == null)
|
||||
return null;
|
||||
if (MainConsole.Instance.ConsoleScene is Scene)
|
||||
return (Scene)MainConsole.Instance.ConsoleScene;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ using System.Threading;
|
||||
using OpenMetaverse;
|
||||
using log4net;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Framework.Console;
|
||||
using OpenSim.Framework.Communications.Cache;
|
||||
using OpenSim.Region.Framework.Interfaces;
|
||||
|
||||
@@ -458,5 +459,12 @@ namespace OpenSim.Region.Framework.Scenes
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddCommand(string module, string command, string shorthelp, string longhelp, CommandDelegate callback)
|
||||
{
|
||||
if (MainConsole.Instance == null)
|
||||
return;
|
||||
MainConsole.Instance.Commands.AddCommand(module, command, shorthelp, longhelp, callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,12 +128,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||
get { return m_ScriptEngine.World; }
|
||||
}
|
||||
|
||||
// Extension commands use this:
|
||||
public ICommander GetCommander(string name)
|
||||
{
|
||||
return World.GetCommander(name);
|
||||
}
|
||||
|
||||
public void state(string newState)
|
||||
{
|
||||
m_ScriptEngine.SetState(m_itemID, newState);
|
||||
|
||||
Reference in New Issue
Block a user