diff options
author | Justin Clark-Casey (justincc) | 2012-11-22 05:57:20 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-11-22 05:57:20 +0000 |
commit | 3ce00e97cc6a7801738e72af8b8033fd81d09d12 (patch) | |
tree | b4b65c59375af3b4e2bbedb83153bb6bda2558e3 /OpenSim/Framework/Servers | |
parent | Make "config show/set/get/save" console commands available on all servers (diff) | |
download | opensim-SC-3ce00e97cc6a7801738e72af8b8033fd81d09d12.zip opensim-SC-3ce00e97cc6a7801738e72af8b8033fd81d09d12.tar.gz opensim-SC-3ce00e97cc6a7801738e72af8b8033fd81d09d12.tar.bz2 opensim-SC-3ce00e97cc6a7801738e72af8b8033fd81d09d12.tar.xz |
Factor out command script code.
This also allows comments in command scripts (lines starting with ;, # or //) to be used across all servers
Diffstat (limited to 'OpenSim/Framework/Servers')
-rw-r--r-- | OpenSim/Framework/Servers/ServerBase.cs | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/OpenSim/Framework/Servers/ServerBase.cs b/OpenSim/Framework/Servers/ServerBase.cs index 27cfc9b..c182a3a 100644 --- a/OpenSim/Framework/Servers/ServerBase.cs +++ b/OpenSim/Framework/Servers/ServerBase.cs | |||
@@ -201,6 +201,11 @@ namespace OpenSim.Framework.Servers | |||
201 | "General", false, "config save", | 201 | "General", false, "config save", |
202 | "config save <path>", | 202 | "config save <path>", |
203 | "Save current configuration to a file at the given path", HandleConfig); | 203 | "Save current configuration to a file at the given path", HandleConfig); |
204 | |||
205 | m_console.Commands.AddCommand( | ||
206 | "General", false, "command-script", | ||
207 | "command-script <script>", | ||
208 | "Run a command script from file", HandleScript); | ||
204 | } | 209 | } |
205 | 210 | ||
206 | public virtual void HandleShow(string module, string[] cmd) | 211 | public virtual void HandleShow(string module, string[] cmd) |
@@ -363,7 +368,50 @@ namespace OpenSim.Framework.Servers | |||
363 | 368 | ||
364 | private void ShowLogLevel() | 369 | private void ShowLogLevel() |
365 | { | 370 | { |
366 | Notice(String.Format("Console log level is {0}", m_consoleAppender.Threshold)); | 371 | Notice("Console log level is {0}", m_consoleAppender.Threshold); |
372 | } | ||
373 | |||
374 | protected virtual void HandleScript(string module, string[] parms) | ||
375 | { | ||
376 | if (parms.Length != 2) | ||
377 | { | ||
378 | Notice("Usage: command-script <path-to-script"); | ||
379 | return; | ||
380 | } | ||
381 | |||
382 | RunCommandScript(parms[1]); | ||
383 | } | ||
384 | |||
385 | /// <summary> | ||
386 | /// Run an optional startup list of commands | ||
387 | /// </summary> | ||
388 | /// <param name="fileName"></param> | ||
389 | protected void RunCommandScript(string fileName) | ||
390 | { | ||
391 | if (m_console == null) | ||
392 | return; | ||
393 | |||
394 | if (File.Exists(fileName)) | ||
395 | { | ||
396 | m_log.Info("[SERVER BASE]: Running " + fileName); | ||
397 | |||
398 | using (StreamReader readFile = File.OpenText(fileName)) | ||
399 | { | ||
400 | string currentCommand; | ||
401 | while ((currentCommand = readFile.ReadLine()) != null) | ||
402 | { | ||
403 | currentCommand = currentCommand.Trim(); | ||
404 | if (!(currentCommand == "" | ||
405 | || currentCommand.StartsWith(";") | ||
406 | || currentCommand.StartsWith("//") | ||
407 | || currentCommand.StartsWith("#"))) | ||
408 | { | ||
409 | m_log.Info("[SERVER BASE]: Running '" + currentCommand + "'"); | ||
410 | m_console.RunCommand(currentCommand); | ||
411 | } | ||
412 | } | ||
413 | } | ||
414 | } | ||
367 | } | 415 | } |
368 | 416 | ||
369 | /// <summary> | 417 | /// <summary> |
@@ -509,7 +557,7 @@ namespace OpenSim.Framework.Servers | |||
509 | /// </summary> | 557 | /// </summary> |
510 | /// <param name="format"></param> | 558 | /// <param name="format"></param> |
511 | /// <param name="components"></param> | 559 | /// <param name="components"></param> |
512 | protected void Notice(string format, params string[] components) | 560 | protected void Notice(string format, params object[] components) |
513 | { | 561 | { |
514 | if (m_console != null) | 562 | if (m_console != null) |
515 | m_console.OutputFormat(format, components); | 563 | m_console.OutputFormat(format, components); |