aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJeff Ames2008-02-07 04:53:42 +0000
committerJeff Ames2008-02-07 04:53:42 +0000
commit87e2dd7c809de5f1e9a8be1113ab39d3f647b1ca (patch)
tree33938eeb60f1e2f0f67d1f9d4f07b825313e36e8
parentUpdate version numbers to 0.5 (diff)
downloadopensim-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--bin/pCampBot.exe.config28
-rw-r--r--pCampBot/BotManager.cs43
-rw-r--r--pCampBot/PhysicsBot.cs25
-rw-r--r--pCampBot/pCampBot.cs8
-rw-r--r--pCampBot/prebuild.xml1
5 files changed, 50 insertions, 55 deletions
diff --git a/bin/pCampBot.exe.config b/bin/pCampBot.exe.config
new file mode 100644
index 0000000..ff6ce7f
--- /dev/null
+++ b/bin/pCampBot.exe.config
@@ -0,0 +1,28 @@
1<?xml version="1.0" encoding="utf-8" ?>
2<configuration>
3 <configSections>
4 <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
5 </configSections>
6 <appSettings>
7 </appSettings>
8 <log4net>
9 <appender name="Console" type="OpenSim.Framework.Console.OpenSimAppender, OpenSim.Framework.Console">
10 <layout type="log4net.Layout.PatternLayout">
11 <conversionPattern value="%date{HH:mm:ss} - %message%newline" />
12 </layout>
13 </appender>
14 <appender name="LogFileAppender" type="log4net.Appender.FileAppender">
15 <file value="pCampBot.log" />
16 <appendToFile value="false" />
17 <layout type="log4net.Layout.PatternLayout">
18 <conversionPattern value="%date %-5level - %logger %message%newline" />
19 </layout>
20 </appender>
21
22 <root>
23 <level value="DEBUG" />
24 <appender-ref ref="Console" />
25 <appender-ref ref="LogFileAppender" />
26 </root>
27 </log4net>
28</configuration>
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}
diff --git a/pCampBot/PhysicsBot.cs b/pCampBot/PhysicsBot.cs
index 53a774a..500683a 100644
--- a/pCampBot/PhysicsBot.cs
+++ b/pCampBot/PhysicsBot.cs
@@ -38,8 +38,6 @@ using OpenSim.Framework;
38using OpenSim.Framework.Console; 38using OpenSim.Framework.Console;
39using Timer=System.Timers.Timer; 39using Timer=System.Timers.Timer;
40 40
41
42
43namespace pCampBot 41namespace pCampBot
44{ 42{
45 public class PhysicsBot 43 public class PhysicsBot
@@ -122,12 +120,12 @@ namespace pCampBot
122 { 120 {
123 client.Network.Logout(); 121 client.Network.Logout();
124 } 122 }
123
125 /// <summary> 124 /// <summary>
126 /// This is the bot startup loop. 125 /// This is the bot startup loop.
127 /// </summary> 126 /// </summary>
128 public void startup() 127 public void startup()
129 { 128 {
130
131 client.Settings.LOGIN_SERVER = loginURI; 129 client.Settings.LOGIN_SERVER = loginURI;
132 client.Network.OnConnected += new NetworkManager.ConnectedCallback(this.Network_OnConnected); 130 client.Network.OnConnected += new NetworkManager.ConnectedCallback(this.Network_OnConnected);
133 client.Network.OnSimConnected += new NetworkManager.SimConnectedCallback(this.Network_OnConnected); 131 client.Network.OnSimConnected += new NetworkManager.SimConnectedCallback(this.Network_OnConnected);
@@ -147,14 +145,12 @@ namespace pCampBot
147 } 145 }
148 else 146 else
149 { 147 {
150 148 MainConsole.Instance.Error(firstname + " " + lastname, "Can't login: " + client.Network.LoginMessage);
151 MainLog.Instance.Error(firstname + " " + lastname,"Can't Log in: " + client.Network.LoginMessage);
152 if (OnDisconnected != null) 149 if (OnDisconnected != null)
153 { 150 {
154 OnDisconnected(this, EventType.DISCONNECTED); 151 OnDisconnected(this, EventType.DISCONNECTED);
155 } 152 }
156 } 153 }
157
158 } 154 }
159 155
160 public void Network_OnConnected(object sender) 156 public void Network_OnConnected(object sender)
@@ -163,12 +159,10 @@ namespace pCampBot
163 { 159 {
164 OnConnected(this, EventType.CONNECTED); 160 OnConnected(this, EventType.CONNECTED);
165 } 161 }
166
167 } 162 }
163
168 public void Simulator_Connected(object sender) 164 public void Simulator_Connected(object sender)
169 { 165 {
170
171
172 } 166 }
173 167
174 public void Network_OnDisconnected(NetworkManager.DisconnectType reason, string message) 168 public void Network_OnDisconnected(NetworkManager.DisconnectType reason, string message)
@@ -177,16 +171,11 @@ namespace pCampBot
177 { 171 {
178 OnDisconnected(this,EventType.DISCONNECTED); 172 OnDisconnected(this,EventType.DISCONNECTED);
179 } 173 }
180
181
182 } 174 }
175
183 public string[] readexcuses() 176 public string[] readexcuses()
184 { 177 {
185
186
187
188 string allexcuses = ""; 178 string allexcuses = "";
189
190 179
191 string file = Path.Combine(Util.configDir(), "excuses"); 180 string file = Path.Combine(Util.configDir(), "excuses");
192 if (File.Exists(file)) 181 if (File.Exists(file))
@@ -195,14 +184,8 @@ namespace pCampBot
195 allexcuses = csr.ReadToEnd(); 184 allexcuses = csr.ReadToEnd();
196 csr.Close(); 185 csr.Close();
197 } 186 }
198
199 187
200 return allexcuses.Split(Environment.NewLine.ToCharArray()); 188 return allexcuses.Split(Environment.NewLine.ToCharArray());
201
202 } 189 }
203
204
205 } 190 }
206
207
208} 191}
diff --git a/pCampBot/pCampBot.cs b/pCampBot/pCampBot.cs
index 983eaf0..704a3f5 100644
--- a/pCampBot/pCampBot.cs
+++ b/pCampBot/pCampBot.cs
@@ -35,7 +35,6 @@ using Nini.Config;
35using System.Threading; 35using System.Threading;
36using OpenSim.Framework.Console; 36using OpenSim.Framework.Console;
37 37
38
39namespace pCampBot 38namespace pCampBot
40{ 39{
41 /// <summary> 40 /// <summary>
@@ -47,10 +46,9 @@ namespace pCampBot
47 CONNECTED = 1, 46 CONNECTED = 1,
48 DISCONNECTED = 2 47 DISCONNECTED = 2
49 } 48 }
49
50 public class pCampBot 50 public class pCampBot
51 { 51 {
52
53
54 [STAThread] 52 [STAThread]
55 public static void Main(string[] args) 53 public static void Main(string[] args)
56 { 54 {
@@ -63,7 +61,6 @@ namespace pCampBot
63 cs.AddSwitch("Startup", "lastname"); 61 cs.AddSwitch("Startup", "lastname");
64 cs.AddSwitch("Startup", "password"); 62 cs.AddSwitch("Startup", "password");
65 63
66
67 IConfig ol = cs.Configs["Startup"]; 64 IConfig ol = cs.Configs["Startup"];
68 int botcount = ol.GetInt("botcount", 1); 65 int botcount = ol.GetInt("botcount", 1);
69 BotManager bm = new BotManager(); 66 BotManager bm = new BotManager();
@@ -72,9 +69,8 @@ namespace pCampBot
72 bm.dobotStartup(botcount, ol); 69 bm.dobotStartup(botcount, ol);
73 while (true) 70 while (true)
74 { 71 {
75 MainLog.Instance.MainLogPrompt(); 72 MainConsole.Instance.Prompt();
76 } 73 }
77
78 } 74 }
79 } 75 }
80} 76}
diff --git a/pCampBot/prebuild.xml b/pCampBot/prebuild.xml
index d29d0fc..1f49082 100644
--- a/pCampBot/prebuild.xml
+++ b/pCampBot/prebuild.xml
@@ -52,6 +52,7 @@
52 <Reference name="OpenSim.Framework.dll"/> 52 <Reference name="OpenSim.Framework.dll"/>
53 <Reference name="OpenSim.Framework.Console.dll"/> 53 <Reference name="OpenSim.Framework.Console.dll"/>
54 <Reference name="Nini.dll" /> 54 <Reference name="Nini.dll" />
55 <Reference name="log4net"/>
55 56
56 <Files> 57 <Files>
57 <Match pattern="*.cs" recurse="true"/> 58 <Match pattern="*.cs" recurse="true"/>