diff options
author | Jeff Ames | 2008-02-07 04:53:42 +0000 |
---|---|---|
committer | Jeff Ames | 2008-02-07 04:53:42 +0000 |
commit | 87e2dd7c809de5f1e9a8be1113ab39d3f647b1ca (patch) | |
tree | 33938eeb60f1e2f0f67d1f9d4f07b825313e36e8 /pCampBot/BotManager.cs | |
parent | Update version numbers to 0.5 (diff) | |
download | opensim-SC_OLD-87e2dd7c809de5f1e9a8be1113ab39d3f647b1ca.zip opensim-SC_OLD-87e2dd7c809de5f1e9a8be1113ab39d3f647b1ca.tar.gz opensim-SC_OLD-87e2dd7c809de5f1e9a8be1113ab39d3f647b1ca.tar.bz2 opensim-SC_OLD-87e2dd7c809de5f1e9a8be1113ab39d3f647b1ca.tar.xz |
Convert pCampBot to use log4net
Diffstat (limited to '')
-rw-r--r-- | pCampBot/BotManager.cs | 43 |
1 files changed, 15 insertions, 28 deletions
diff --git a/pCampBot/BotManager.cs b/pCampBot/BotManager.cs index a9cd643..ee5f82d 100644 --- a/pCampBot/BotManager.cs +++ b/pCampBot/BotManager.cs | |||
@@ -44,25 +44,24 @@ namespace pCampBot | |||
44 | /// </summary> | 44 | /// </summary> |
45 | public class BotManager : conscmd_callback | 45 | public class BotManager : conscmd_callback |
46 | { | 46 | { |
47 | protected LogBase m_log; | 47 | private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); |
48 | |||
49 | protected ConsoleBase m_console; | ||
48 | protected List<PhysicsBot> m_lBot; | 50 | protected List<PhysicsBot> m_lBot; |
49 | protected Thread[] m_td; | 51 | protected Thread[] m_td; |
50 | protected string m_logFilename = "botlog.log"; | ||
51 | protected bool m_verbose = true; | 52 | protected bool m_verbose = true; |
52 | protected Random somthing = new Random(System.Environment.TickCount); | 53 | protected Random somthing = new Random(System.Environment.TickCount); |
53 | protected int numbots = 0; | 54 | protected int numbots = 0; |
54 | protected IConfig Previous_config; | 55 | protected IConfig Previous_config; |
55 | 56 | ||
56 | /// <summary> | 57 | /// <summary> |
57 | /// Constructor Creates Mainlog.Instance to take commands and provide the place to write data | 58 | /// Constructor Creates MainConsole.Instance to take commands and provide the place to write data |
58 | /// </summary> | 59 | /// </summary> |
59 | public BotManager() | 60 | public BotManager() |
60 | { | 61 | { |
61 | 62 | m_console = CreateConsole(); | |
62 | m_log = CreateLog(); | 63 | MainConsole.Instance = m_console; |
63 | MainLog.Instance = m_log; | ||
64 | m_lBot = new List<PhysicsBot>(); | 64 | m_lBot = new List<PhysicsBot>(); |
65 | |||
66 | } | 65 | } |
67 | 66 | ||
68 | /// <summary> | 67 | /// <summary> |
@@ -101,7 +100,6 @@ namespace pCampBot | |||
101 | { | 100 | { |
102 | startupBot(i, Previous_config); | 101 | startupBot(i, Previous_config); |
103 | } | 102 | } |
104 | |||
105 | } | 103 | } |
106 | 104 | ||
107 | /// <summary> | 105 | /// <summary> |
@@ -151,19 +149,19 @@ namespace pCampBot | |||
151 | switch (eventt) | 149 | switch (eventt) |
152 | { | 150 | { |
153 | case EventType.CONNECTED: | 151 | case EventType.CONNECTED: |
154 | MainLog.Instance.Verbose(" " + callbot.firstname + " " + callbot.lastname, "Connected"); | 152 | m_log.Info("[ " + callbot.firstname + " " + callbot.lastname + "]: Connected"); |
155 | numbots++; | 153 | numbots++; |
156 | break; | 154 | break; |
157 | case EventType.DISCONNECTED: | 155 | case EventType.DISCONNECTED: |
158 | MainLog.Instance.Verbose(" " + callbot.firstname + " " + callbot.lastname, "Disconnected"); | 156 | m_log.Info("[ " + callbot.firstname + " " + callbot.lastname + "]: Disconnected"); |
159 | m_td[m_lBot.IndexOf(callbot)].Abort(); | 157 | m_td[m_lBot.IndexOf(callbot)].Abort(); |
160 | numbots--; | 158 | numbots--; |
161 | if (numbots >1) | 159 | if (numbots >1) |
162 | Environment.Exit(0); | 160 | Environment.Exit(0); |
163 | break; | 161 | break; |
164 | |||
165 | } | 162 | } |
166 | } | 163 | } |
164 | |||
167 | /// <summary> | 165 | /// <summary> |
168 | /// Shutting down all bots | 166 | /// Shutting down all bots |
169 | /// </summary> | 167 | /// </summary> |
@@ -173,23 +171,15 @@ namespace pCampBot | |||
173 | { | 171 | { |
174 | pb.shutdown(); | 172 | pb.shutdown(); |
175 | } | 173 | } |
176 | |||
177 | |||
178 | |||
179 | } | 174 | } |
180 | 175 | ||
181 | /// <summary> | 176 | /// <summary> |
182 | /// Standard Creatlog routine | 177 | /// Standard CreateConsole routine |
183 | /// </summary> | 178 | /// </summary> |
184 | /// <returns></returns> | 179 | /// <returns></returns> |
185 | protected LogBase CreateLog() | 180 | protected ConsoleBase CreateConsole() |
186 | { | 181 | { |
187 | if (!Directory.Exists(Util.logDir())) | 182 | return new ConsoleBase("Region", this); |
188 | { | ||
189 | Directory.CreateDirectory(Util.logDir()); | ||
190 | } | ||
191 | |||
192 | return new LogBase((Path.Combine(Util.logDir(), m_logFilename)), "Region", this, m_verbose); | ||
193 | } | 183 | } |
194 | 184 | ||
195 | /// <summary> | 185 | /// <summary> |
@@ -219,11 +209,11 @@ namespace pCampBot | |||
219 | switch (command) | 209 | switch (command) |
220 | { | 210 | { |
221 | case "shutdown": | 211 | case "shutdown": |
222 | MainLog.Instance.Warn("BOTMANAGER", "Shutting down bots"); | 212 | m_console.Warn("BOTMANAGER", "Shutting down bots"); |
223 | doBotShutdown(); | 213 | doBotShutdown(); |
224 | break; | 214 | break; |
225 | case "quit": | 215 | case "quit": |
226 | 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"); | 216 | 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"); |
227 | Environment.Exit(0); | 217 | Environment.Exit(0); |
228 | break; | 218 | break; |
229 | case "addbots": | 219 | case "addbots": |
@@ -234,10 +224,8 @@ namespace pCampBot | |||
234 | addbots(newbots); | 224 | addbots(newbots); |
235 | break; | 225 | break; |
236 | case "help": | 226 | case "help": |
237 | MainLog.Instance.Notice("HELP", "\nshutdown - graceful shutdown\naddbots <n> - adds n bots to the test\nquit - forcequits, dangerous if you have not already run shutdown"); | 227 | 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"); |
238 | break; | 228 | break; |
239 | |||
240 | |||
241 | } | 229 | } |
242 | } | 230 | } |
243 | 231 | ||
@@ -250,5 +238,4 @@ namespace pCampBot | |||
250 | 238 | ||
251 | } | 239 | } |
252 | } | 240 | } |
253 | |||
254 | } | 241 | } |