Factor out command script code.

This also allows comments in command scripts (lines starting with ;, # or //) to be used across all servers
This commit is contained in:
Justin Clark-Casey (justincc)
2012-11-22 05:57:20 +00:00
parent 9fcf3f1a3f
commit 3ce00e97cc
3 changed files with 50 additions and 77 deletions

View File

@@ -196,11 +196,6 @@ namespace OpenSim.Server.Base
MainConsole.Instance.Commands.AddCommand("General", false, "shutdown",
"shutdown",
"Quit the application", HandleQuit);
// Register a command to read other commands from a file
MainConsole.Instance.Commands.AddCommand("General", false, "command-script",
"command-script <script>",
"Run a command script from file", HandleScript);
// Allow derived classes to perform initialization that
// needs to be done after the console has opened
@@ -239,40 +234,6 @@ namespace OpenSim.Server.Base
}
protected virtual void HandleScript(string module, string[] parms)
{
if (parms.Length != 2)
{
return;
}
RunCommandScript(parms[1]);
}
/// <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);
using (StreamReader readFile = File.OpenText(fileName))
{
string currentCommand;
while ((currentCommand = readFile.ReadLine()) != null)
{
if (currentCommand != String.Empty)
{
m_log.Info("[COMMANDFILE]: Running '" + currentCommand + "'");
MainConsole.Instance.RunCommand(currentCommand);
}
}
}
}
}
protected virtual void ReadConfig()
{
}