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 | |
parent | Make "config show/set/get/save" console commands available on all servers (diff) | |
download | opensim-SC_OLD-3ce00e97cc6a7801738e72af8b8033fd81d09d12.zip opensim-SC_OLD-3ce00e97cc6a7801738e72af8b8033fd81d09d12.tar.gz opensim-SC_OLD-3ce00e97cc6a7801738e72af8b8033fd81d09d12.tar.bz2 opensim-SC_OLD-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
-rw-r--r-- | OpenSim/Framework/Servers/ServerBase.cs | 52 | ||||
-rw-r--r-- | OpenSim/Region/Application/OpenSim.cs | 36 | ||||
-rw-r--r-- | OpenSim/Server/Base/ServicesServerBase.cs | 39 |
3 files changed, 50 insertions, 77 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); |
diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index e654cf7..17b2167 100644 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs | |||
@@ -467,35 +467,6 @@ namespace OpenSim | |||
467 | } | 467 | } |
468 | 468 | ||
469 | /// <summary> | 469 | /// <summary> |
470 | /// Run an optional startup list of commands | ||
471 | /// </summary> | ||
472 | /// <param name="fileName"></param> | ||
473 | private void RunCommandScript(string fileName) | ||
474 | { | ||
475 | if (File.Exists(fileName)) | ||
476 | { | ||
477 | m_log.Info("[COMMANDFILE]: Running " + fileName); | ||
478 | |||
479 | using (StreamReader readFile = File.OpenText(fileName)) | ||
480 | { | ||
481 | string currentCommand; | ||
482 | while ((currentCommand = readFile.ReadLine()) != null) | ||
483 | { | ||
484 | currentCommand = currentCommand.Trim(); | ||
485 | if (!(currentCommand == "" | ||
486 | || currentCommand.StartsWith(";") | ||
487 | || currentCommand.StartsWith("//") | ||
488 | || currentCommand.StartsWith("#"))) | ||
489 | { | ||
490 | m_log.Info("[COMMANDFILE]: Running '" + currentCommand + "'"); | ||
491 | m_console.RunCommand(currentCommand); | ||
492 | } | ||
493 | } | ||
494 | } | ||
495 | } | ||
496 | } | ||
497 | |||
498 | /// <summary> | ||
499 | /// Opens a file and uses it as input to the console command parser. | 470 | /// Opens a file and uses it as input to the console command parser. |
500 | /// </summary> | 471 | /// </summary> |
501 | /// <param name="fileName">name of file to use as input to the console</param> | 472 | /// <param name="fileName">name of file to use as input to the console</param> |
@@ -650,13 +621,6 @@ namespace OpenSim | |||
650 | 621 | ||
651 | switch (command) | 622 | switch (command) |
652 | { | 623 | { |
653 | case "command-script": | ||
654 | if (cmdparams.Length > 0) | ||
655 | { | ||
656 | RunCommandScript(cmdparams[0]); | ||
657 | } | ||
658 | break; | ||
659 | |||
660 | case "backup": | 624 | case "backup": |
661 | MainConsole.Instance.Output("Triggering save of pending object updates to persistent store"); | 625 | MainConsole.Instance.Output("Triggering save of pending object updates to persistent store"); |
662 | SceneManager.BackupCurrentScene(); | 626 | SceneManager.BackupCurrentScene(); |
diff --git a/OpenSim/Server/Base/ServicesServerBase.cs b/OpenSim/Server/Base/ServicesServerBase.cs index 2c2b8ed..5b23149 100644 --- a/OpenSim/Server/Base/ServicesServerBase.cs +++ b/OpenSim/Server/Base/ServicesServerBase.cs | |||
@@ -196,11 +196,6 @@ namespace OpenSim.Server.Base | |||
196 | MainConsole.Instance.Commands.AddCommand("General", false, "shutdown", | 196 | MainConsole.Instance.Commands.AddCommand("General", false, "shutdown", |
197 | "shutdown", | 197 | "shutdown", |
198 | "Quit the application", HandleQuit); | 198 | "Quit the application", HandleQuit); |
199 | |||
200 | // Register a command to read other commands from a file | ||
201 | MainConsole.Instance.Commands.AddCommand("General", false, "command-script", | ||
202 | "command-script <script>", | ||
203 | "Run a command script from file", HandleScript); | ||
204 | 199 | ||
205 | // Allow derived classes to perform initialization that | 200 | // Allow derived classes to perform initialization that |
206 | // needs to be done after the console has opened | 201 | // needs to be done after the console has opened |
@@ -239,40 +234,6 @@ namespace OpenSim.Server.Base | |||
239 | 234 | ||
240 | } | 235 | } |
241 | 236 | ||
242 | protected virtual void HandleScript(string module, string[] parms) | ||
243 | { | ||
244 | if (parms.Length != 2) | ||
245 | { | ||
246 | return; | ||
247 | } | ||
248 | RunCommandScript(parms[1]); | ||
249 | } | ||
250 | |||
251 | /// <summary> | ||
252 | /// Run an optional startup list of commands | ||
253 | /// </summary> | ||
254 | /// <param name="fileName"></param> | ||
255 | private void RunCommandScript(string fileName) | ||
256 | { | ||
257 | if (File.Exists(fileName)) | ||
258 | { | ||
259 | m_log.Info("[COMMANDFILE]: Running " + fileName); | ||
260 | |||
261 | using (StreamReader readFile = File.OpenText(fileName)) | ||
262 | { | ||
263 | string currentCommand; | ||
264 | while ((currentCommand = readFile.ReadLine()) != null) | ||
265 | { | ||
266 | if (currentCommand != String.Empty) | ||
267 | { | ||
268 | m_log.Info("[COMMANDFILE]: Running '" + currentCommand + "'"); | ||
269 | MainConsole.Instance.RunCommand(currentCommand); | ||
270 | } | ||
271 | } | ||
272 | } | ||
273 | } | ||
274 | } | ||
275 | |||
276 | protected virtual void ReadConfig() | 237 | protected virtual void ReadConfig() |
277 | { | 238 | { |
278 | } | 239 | } |