From 87e2dd7c809de5f1e9a8be1113ab39d3f647b1ca Mon Sep 17 00:00:00 2001 From: Jeff Ames Date: Thu, 7 Feb 2008 04:53:42 +0000 Subject: [PATCH] Convert pCampBot to use log4net --- bin/pCampBot.exe.config | 28 +++++++++++++++++++++++++++ pCampBot/BotManager.cs | 43 ++++++++++++++--------------------------- pCampBot/PhysicsBot.cs | 25 ++++-------------------- pCampBot/pCampBot.cs | 8 ++------ pCampBot/prebuild.xml | 1 + 5 files changed, 50 insertions(+), 55 deletions(-) create mode 100644 bin/pCampBot.exe.config diff --git a/bin/pCampBot.exe.config b/bin/pCampBot.exe.config new file mode 100644 index 0000000000..ff6ce7fb7d --- /dev/null +++ b/bin/pCampBot.exe.config @@ -0,0 +1,28 @@ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pCampBot/BotManager.cs b/pCampBot/BotManager.cs index a9cd643282..ee5f82d852 100644 --- a/pCampBot/BotManager.cs +++ b/pCampBot/BotManager.cs @@ -44,25 +44,24 @@ namespace pCampBot /// public class BotManager : conscmd_callback { - protected LogBase m_log; + private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + + protected ConsoleBase m_console; protected List m_lBot; protected Thread[] m_td; - protected string m_logFilename = "botlog.log"; protected bool m_verbose = true; protected Random somthing = new Random(System.Environment.TickCount); protected int numbots = 0; protected IConfig Previous_config; /// - /// Constructor Creates Mainlog.Instance to take commands and provide the place to write data + /// Constructor Creates MainConsole.Instance to take commands and provide the place to write data /// public BotManager() { - - m_log = CreateLog(); - MainLog.Instance = m_log; + m_console = CreateConsole(); + MainConsole.Instance = m_console; m_lBot = new List(); - } /// @@ -101,7 +100,6 @@ namespace pCampBot { startupBot(i, Previous_config); } - } /// @@ -151,19 +149,19 @@ namespace pCampBot switch (eventt) { case EventType.CONNECTED: - MainLog.Instance.Verbose(" " + callbot.firstname + " " + callbot.lastname, "Connected"); + m_log.Info("[ " + callbot.firstname + " " + callbot.lastname + "]: Connected"); numbots++; break; case EventType.DISCONNECTED: - MainLog.Instance.Verbose(" " + callbot.firstname + " " + callbot.lastname, "Disconnected"); + m_log.Info("[ " + callbot.firstname + " " + callbot.lastname + "]: Disconnected"); m_td[m_lBot.IndexOf(callbot)].Abort(); numbots--; if (numbots >1) Environment.Exit(0); break; - } } + /// /// Shutting down all bots /// @@ -173,23 +171,15 @@ namespace pCampBot { pb.shutdown(); } - - - } /// - /// Standard Creatlog routine + /// Standard CreateConsole routine /// /// - protected LogBase CreateLog() + protected ConsoleBase CreateConsole() { - if (!Directory.Exists(Util.logDir())) - { - Directory.CreateDirectory(Util.logDir()); - } - - return new LogBase((Path.Combine(Util.logDir(), m_logFilename)), "Region", this, m_verbose); + return new ConsoleBase("Region", this); } /// @@ -219,11 +209,11 @@ namespace pCampBot switch (command) { case "shutdown": - MainLog.Instance.Warn("BOTMANAGER", "Shutting down bots"); + m_console.Warn("BOTMANAGER", "Shutting down bots"); doBotShutdown(); break; case "quit": - MainLog.Instance.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"); + 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": @@ -234,10 +224,8 @@ namespace pCampBot addbots(newbots); break; case "help": - MainLog.Instance.Notice("HELP", "\nshutdown - graceful shutdown\naddbots - adds n bots to the test\nquit - forcequits, dangerous if you have not already run shutdown"); + 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; - - } } @@ -250,5 +238,4 @@ namespace pCampBot } } - } diff --git a/pCampBot/PhysicsBot.cs b/pCampBot/PhysicsBot.cs index 53a774ac93..500683abcb 100644 --- a/pCampBot/PhysicsBot.cs +++ b/pCampBot/PhysicsBot.cs @@ -38,8 +38,6 @@ using OpenSim.Framework; using OpenSim.Framework.Console; using Timer=System.Timers.Timer; - - namespace pCampBot { public class PhysicsBot @@ -122,12 +120,12 @@ namespace pCampBot { client.Network.Logout(); } + /// /// This is the bot startup loop. /// public void startup() { - client.Settings.LOGIN_SERVER = loginURI; client.Network.OnConnected += new NetworkManager.ConnectedCallback(this.Network_OnConnected); client.Network.OnSimConnected += new NetworkManager.SimConnectedCallback(this.Network_OnConnected); @@ -147,14 +145,12 @@ namespace pCampBot } else { - - MainLog.Instance.Error(firstname + " " + lastname,"Can't Log in: " + client.Network.LoginMessage); + MainConsole.Instance.Error(firstname + " " + lastname, "Can't login: " + client.Network.LoginMessage); if (OnDisconnected != null) { OnDisconnected(this, EventType.DISCONNECTED); } } - } public void Network_OnConnected(object sender) @@ -163,12 +159,10 @@ namespace pCampBot { OnConnected(this, EventType.CONNECTED); } - } + public void Simulator_Connected(object sender) { - - } public void Network_OnDisconnected(NetworkManager.DisconnectType reason, string message) @@ -177,16 +171,11 @@ namespace pCampBot { OnDisconnected(this,EventType.DISCONNECTED); } - - } + public string[] readexcuses() { - - - string allexcuses = ""; - string file = Path.Combine(Util.configDir(), "excuses"); if (File.Exists(file)) @@ -195,14 +184,8 @@ namespace pCampBot allexcuses = csr.ReadToEnd(); csr.Close(); } - return allexcuses.Split(Environment.NewLine.ToCharArray()); - } - - } - - } diff --git a/pCampBot/pCampBot.cs b/pCampBot/pCampBot.cs index 983eaf0681..704a3f5c9d 100644 --- a/pCampBot/pCampBot.cs +++ b/pCampBot/pCampBot.cs @@ -35,7 +35,6 @@ using Nini.Config; using System.Threading; using OpenSim.Framework.Console; - namespace pCampBot { /// @@ -47,10 +46,9 @@ namespace pCampBot CONNECTED = 1, DISCONNECTED = 2 } + public class pCampBot { - - [STAThread] public static void Main(string[] args) { @@ -63,7 +61,6 @@ namespace pCampBot cs.AddSwitch("Startup", "lastname"); cs.AddSwitch("Startup", "password"); - IConfig ol = cs.Configs["Startup"]; int botcount = ol.GetInt("botcount", 1); BotManager bm = new BotManager(); @@ -72,9 +69,8 @@ namespace pCampBot bm.dobotStartup(botcount, ol); while (true) { - MainLog.Instance.MainLogPrompt(); + MainConsole.Instance.Prompt(); } - } } } diff --git a/pCampBot/prebuild.xml b/pCampBot/prebuild.xml index d29d0fce32..1f49082319 100644 --- a/pCampBot/prebuild.xml +++ b/pCampBot/prebuild.xml @@ -52,6 +52,7 @@ +