aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tools/pCampBot/BotManager.cs
diff options
context:
space:
mode:
authorMelanie Thielker2009-02-07 12:25:39 +0000
committerMelanie Thielker2009-02-07 12:25:39 +0000
commit54c6a920baa0ef02a9ea09e08cc1effcef3b0a3a (patch)
treef606cbdbc383ec21fee28f0a1454140a1c714278 /OpenSim/Tools/pCampBot/BotManager.cs
parentThank you dslake for a patch that: (diff)
downloadopensim-SC_OLD-54c6a920baa0ef02a9ea09e08cc1effcef3b0a3a.zip
opensim-SC_OLD-54c6a920baa0ef02a9ea09e08cc1effcef3b0a3a.tar.gz
opensim-SC_OLD-54c6a920baa0ef02a9ea09e08cc1effcef3b0a3a.tar.bz2
opensim-SC_OLD-54c6a920baa0ef02a9ea09e08cc1effcef3b0a3a.tar.xz
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.
Diffstat (limited to 'OpenSim/Tools/pCampBot/BotManager.cs')
-rw-r--r--OpenSim/Tools/pCampBot/BotManager.cs85
1 files changed, 52 insertions, 33 deletions
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;
31using System.Threading; 31using System.Threading;
32using OpenMetaverse; 32using OpenMetaverse;
33using log4net; 33using log4net;
34using log4net.Appender;
35using log4net.Core;
36using log4net.Repository;
34using Nini.Config; 37using Nini.Config;
35using OpenSim.Framework; 38using OpenSim.Framework;
36using OpenSim.Framework.Console; 39using OpenSim.Framework.Console;
@@ -40,7 +43,7 @@ namespace pCampBot
40 /// <summary> 43 /// <summary>
41 /// Thread/Bot manager for the application 44 /// Thread/Bot manager for the application
42 /// </summary> 45 /// </summary>
43 public class BotManager : conscmd_callback 46 public class BotManager
44 { 47 {
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 48 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 49
@@ -59,6 +62,36 @@ namespace pCampBot
59 { 62 {
60 m_console = CreateConsole(); 63 m_console = CreateConsole();
61 MainConsole.Instance = m_console; 64 MainConsole.Instance = m_console;
65
66 // Make log4net see the console
67 //
68 ILoggerRepository repository = LogManager.GetRepository();
69 IAppender[] appenders = repository.GetAppenders();
70 OpenSimAppender consoleAppender = null;
71
72 foreach (IAppender appender in appenders)
73 {
74 if (appender.Name == "Console")
75 {
76 consoleAppender = (OpenSimAppender)appender;
77 consoleAppender.Console = m_console;
78 break;
79 }
80 }
81
82 m_console.Commands.AddCommand("bot", "shutdown",
83 "shutdown",
84 "Gracefully shut down bots", HandleShutdown);
85
86 m_console.Commands.AddCommand("bot", "quit",
87 "quit",
88 "Force quit (DANGEROUS, try shutdown first)",
89 HandleShutdown);
90
91 m_console.Commands.AddCommand("bot", "add bots",
92 "add bots <number>",
93 "Add more bots", HandleAddBots);
94
62 m_lBot = new List<PhysicsBot>(); 95 m_lBot = new List<PhysicsBot>();
63 } 96 }
64 97
@@ -175,45 +208,31 @@ namespace pCampBot
175 /// <returns></returns> 208 /// <returns></returns>
176 protected ConsoleBase CreateConsole() 209 protected ConsoleBase CreateConsole()
177 { 210 {
178 return new ConsoleBase("Region", this); 211 return new ConsoleBase("Region");
179 } 212 }
180 213
181 /// <summary> 214 private void HandleShutdown(string module, string[] cmd)
182 /// Command runnint tool.. Currently use it to add bots, shutdown and (dangerous)Forcequit
183 /// </summary>
184 /// <param name="command"></param>
185 /// <param name="cmdparams"></param>
186 public void RunCmd(string command, string[] cmdparams)
187 { 215 {
188 switch (command) 216 m_console.Warn("BOTMANAGER", "Shutting down bots");
189 { 217 doBotShutdown();
190 case "shutdown": 218 }
191 m_console.Warn("BOTMANAGER", "Shutting down bots");
192 doBotShutdown();
193 break;
194 case "quit":
195 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");
196 Environment.Exit(0);
197 break;
198 case "addbots":
199 int newbots;
200 Int32.TryParse(cmdparams[0], out newbots);
201 219
202 if (newbots > 0) 220 private void HandleQuit(string module, string[] cmd)
203 addbots(newbots); 221 {
204 break; 222 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");
205 case "help": 223 Environment.Exit(0);
206 m_console.Notice("HELP", "\nshutdown - graceful shutdown\naddbots <n> - adds n bots to the test\nquit - forcequits, dangerous if you have not already run shutdown");
207 break;
208 }
209 } 224 }
210 225
211 /// <summary> 226 private void HandleAddBots(string module, string[] cmd)
212 /// Required method to implement the conscmd_callback interface
213 /// </summary>
214 /// <param name="showParams">What to show</param>
215 public void Show(string[] showParams)
216 { 227 {
228 int newbots = 0;
229
230 if (cmd.Length > 2)
231 {
232 Int32.TryParse(cmd[2], out newbots);
233 }
234 if (newbots > 0)
235 addbots(newbots);
217 } 236 }
218 } 237 }
219} 238}