From 54c6a920baa0ef02a9ea09e08cc1effcef3b0a3a Mon Sep 17 00:00:00 2001
From: Melanie Thielker
Date: Sat, 7 Feb 2009 12:25:39 +0000
Subject: 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.
---
OpenSim/Tools/pCampBot/BotManager.cs | 85 ++++++++++++++++++++++--------------
1 file changed, 52 insertions(+), 33 deletions(-)
(limited to 'OpenSim/Tools')
diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs
index 100f2d4..3b08adc 100644
--- a/OpenSim/Tools/pCampBot/BotManager.cs
+++ b/OpenSim/Tools/pCampBot/BotManager.cs
@@ -31,6 +31,9 @@ using System.Reflection;
using System.Threading;
using OpenMetaverse;
using log4net;
+using log4net.Appender;
+using log4net.Core;
+using log4net.Repository;
using Nini.Config;
using OpenSim.Framework;
using OpenSim.Framework.Console;
@@ -40,7 +43,7 @@ namespace pCampBot
///
/// Thread/Bot manager for the application
///
- public class BotManager : conscmd_callback
+ public class BotManager
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@@ -59,6 +62,36 @@ namespace pCampBot
{
m_console = CreateConsole();
MainConsole.Instance = m_console;
+
+ // Make log4net see the console
+ //
+ ILoggerRepository repository = LogManager.GetRepository();
+ IAppender[] appenders = repository.GetAppenders();
+ OpenSimAppender consoleAppender = null;
+
+ foreach (IAppender appender in appenders)
+ {
+ if (appender.Name == "Console")
+ {
+ consoleAppender = (OpenSimAppender)appender;
+ consoleAppender.Console = m_console;
+ break;
+ }
+ }
+
+ m_console.Commands.AddCommand("bot", "shutdown",
+ "shutdown",
+ "Gracefully shut down bots", HandleShutdown);
+
+ m_console.Commands.AddCommand("bot", "quit",
+ "quit",
+ "Force quit (DANGEROUS, try shutdown first)",
+ HandleShutdown);
+
+ m_console.Commands.AddCommand("bot", "add bots",
+ "add bots ",
+ "Add more bots", HandleAddBots);
+
m_lBot = new List();
}
@@ -175,45 +208,31 @@ namespace pCampBot
///
protected ConsoleBase CreateConsole()
{
- return new ConsoleBase("Region", this);
+ return new ConsoleBase("Region");
}
- ///
- /// Command runnint tool.. Currently use it to add bots, shutdown and (dangerous)Forcequit
- ///
- ///
- ///
- public void RunCmd(string command, string[] cmdparams)
+ private void HandleShutdown(string module, string[] cmd)
{
- switch (command)
- {
- case "shutdown":
- m_console.Warn("BOTMANAGER", "Shutting down bots");
- doBotShutdown();
- break;
- case "quit":
- m_console.Warn("DANGER", "This should only be used to quit the program if you've already used the shutdown command and the program hasn't quit");
- Environment.Exit(0);
- break;
- case "addbots":
- int newbots;
- Int32.TryParse(cmdparams[0], out newbots);
+ m_console.Warn("BOTMANAGER", "Shutting down bots");
+ doBotShutdown();
+ }
- if (newbots > 0)
- addbots(newbots);
- break;
- case "help":
- m_console.Notice("HELP", "\nshutdown - graceful shutdown\naddbots - adds n bots to the test\nquit - forcequits, dangerous if you have not already run shutdown");
- break;
- }
+ private void HandleQuit(string module, string[] cmd)
+ {
+ m_console.Warn("DANGER", "This should only be used to quit the program if you've already used the shutdown command and the program hasn't quit");
+ Environment.Exit(0);
}
- ///
- /// Required method to implement the conscmd_callback interface
- ///
- /// What to show
- public void Show(string[] showParams)
+ private void HandleAddBots(string module, string[] cmd)
{
+ int newbots = 0;
+
+ if (cmd.Length > 2)
+ {
+ Int32.TryParse(cmd[2], out newbots);
+ }
+ if (newbots > 0)
+ addbots(newbots);
}
}
}
--
cgit v1.1