aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tools
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Tools')
-rw-r--r--OpenSim/Tools/pCampBot/Bot.cs27
-rw-r--r--OpenSim/Tools/pCampBot/BotManager.cs67
-rw-r--r--OpenSim/Tools/pCampBot/pCampBot.cs5
3 files changed, 75 insertions, 24 deletions
diff --git a/OpenSim/Tools/pCampBot/Bot.cs b/OpenSim/Tools/pCampBot/Bot.cs
index da090dd..b6cd287 100644
--- a/OpenSim/Tools/pCampBot/Bot.cs
+++ b/OpenSim/Tools/pCampBot/Bot.cs
@@ -43,6 +43,14 @@ using Timer = System.Timers.Timer;
43 43
44namespace pCampBot 44namespace pCampBot
45{ 45{
46 public enum ConnectionState
47 {
48 Disconnected,
49 Connecting,
50 Connected,
51 Disconnecting
52 }
53
46 public class Bot 54 public class Bot
47 { 55 {
48 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 56 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@@ -86,7 +94,7 @@ namespace pCampBot
86 /// <summary> 94 /// <summary>
87 /// Is this bot connected to the grid? 95 /// Is this bot connected to the grid?
88 /// </summary> 96 /// </summary>
89 public bool IsConnected { get; private set; } 97 public ConnectionState ConnectionState { get; private set; }
90 98
91 public string FirstName { get; private set; } 99 public string FirstName { get; private set; }
92 public string LastName { get; private set; } 100 public string LastName { get; private set; }
@@ -130,6 +138,8 @@ namespace pCampBot
130 BotManager bm, List<IBehaviour> behaviours, 138 BotManager bm, List<IBehaviour> behaviours,
131 string firstName, string lastName, string password, string loginUri) 139 string firstName, string lastName, string password, string loginUri)
132 { 140 {
141 ConnectionState = ConnectionState.Disconnected;
142
133 behaviours.ForEach(b => b.Initialize(this)); 143 behaviours.ForEach(b => b.Initialize(this));
134 144
135 Client = new GridClient(); 145 Client = new GridClient();
@@ -157,10 +167,10 @@ namespace pCampBot
157 Behaviours.ForEach( 167 Behaviours.ForEach(
158 b => 168 b =>
159 { 169 {
170 Thread.Sleep(Random.Next(3000, 10000));
171
160 // m_log.DebugFormat("[pCAMPBOT]: For {0} performing action {1}", Name, b.GetType()); 172 // m_log.DebugFormat("[pCAMPBOT]: For {0} performing action {1}", Name, b.GetType());
161 b.Action(); 173 b.Action();
162
163 Thread.Sleep(Random.Next(1000, 10000));
164 } 174 }
165 ); 175 );
166 } 176 }
@@ -178,6 +188,8 @@ namespace pCampBot
178 /// </summary> 188 /// </summary>
179 public void shutdown() 189 public void shutdown()
180 { 190 {
191 ConnectionState = ConnectionState.Disconnecting;
192
181 if (m_actionThread != null) 193 if (m_actionThread != null)
182 m_actionThread.Abort(); 194 m_actionThread.Abort();
183 195
@@ -209,9 +221,11 @@ namespace pCampBot
209 Client.Network.Disconnected += this.Network_OnDisconnected; 221 Client.Network.Disconnected += this.Network_OnDisconnected;
210 Client.Objects.ObjectUpdate += Objects_NewPrim; 222 Client.Objects.ObjectUpdate += Objects_NewPrim;
211 223
224 ConnectionState = ConnectionState.Connecting;
225
212 if (Client.Network.Login(FirstName, LastName, Password, "pCampBot", "Your name")) 226 if (Client.Network.Login(FirstName, LastName, Password, "pCampBot", "Your name"))
213 { 227 {
214 IsConnected = true; 228 ConnectionState = ConnectionState.Connected;
215 229
216 Thread.Sleep(Random.Next(1000, 10000)); 230 Thread.Sleep(Random.Next(1000, 10000));
217 m_actionThread = new Thread(Action); 231 m_actionThread = new Thread(Action);
@@ -241,6 +255,8 @@ namespace pCampBot
241 } 255 }
242 else 256 else
243 { 257 {
258 ConnectionState = ConnectionState.Disconnected;
259
244 m_log.ErrorFormat( 260 m_log.ErrorFormat(
245 "{0} {1} cannot login: {2}", FirstName, LastName, Client.Network.LoginMessage); 261 "{0} {1} cannot login: {2}", FirstName, LastName, Client.Network.LoginMessage);
246 262
@@ -439,6 +455,8 @@ namespace pCampBot
439 455
440 public void Network_OnDisconnected(object sender, DisconnectedEventArgs args) 456 public void Network_OnDisconnected(object sender, DisconnectedEventArgs args)
441 { 457 {
458 ConnectionState = ConnectionState.Disconnected;
459
442 m_log.DebugFormat( 460 m_log.DebugFormat(
443 "[BOT]: Bot {0} disconnected reason {1}, message {2}", Name, args.Reason, args.Message); 461 "[BOT]: Bot {0} disconnected reason {1}, message {2}", Name, args.Reason, args.Message);
444 462
@@ -456,7 +474,6 @@ namespace pCampBot
456 && OnDisconnected != null) 474 && OnDisconnected != null)
457// if (OnDisconnected != null) 475// if (OnDisconnected != null)
458 { 476 {
459 IsConnected = false;
460 OnDisconnected(this, EventType.DISCONNECTED); 477 OnDisconnected(this, EventType.DISCONNECTED);
461 } 478 }
462 } 479 }
diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs
index 0f501b7..d615b3f 100644
--- a/OpenSim/Tools/pCampBot/BotManager.cs
+++ b/OpenSim/Tools/pCampBot/BotManager.cs
@@ -49,6 +49,14 @@ namespace pCampBot
49 { 49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 51
52 public const int DefaultLoginDelay = 5000;
53
54 /// <summary>
55 /// Delay between logins of multiple bots.
56 /// </summary>
57 /// <remarks>TODO: This value needs to be configurable by a command line argument.</remarks>
58 public int LoginDelay { get; set; }
59
52 /// <summary> 60 /// <summary>
53 /// Command console 61 /// Command console
54 /// </summary> 62 /// </summary>
@@ -84,6 +92,8 @@ namespace pCampBot
84 /// </summary> 92 /// </summary>
85 public BotManager() 93 public BotManager()
86 { 94 {
95 LoginDelay = DefaultLoginDelay;
96
87 Rng = new Random(Environment.TickCount); 97 Rng = new Random(Environment.TickCount);
88 AssetsReceived = new Dictionary<UUID, bool>(); 98 AssetsReceived = new Dictionary<UUID, bool>();
89 RegionsKnown = new Dictionary<ulong, GridRegion>(); 99 RegionsKnown = new Dictionary<ulong, GridRegion>();
@@ -151,28 +161,34 @@ namespace pCampBot
151 Array.ForEach<string>( 161 Array.ForEach<string>(
152 cs.GetString("behaviours", "p").Split(new char[] { ',' }), b => behaviourSwitches.Add(b)); 162 cs.GetString("behaviours", "p").Split(new char[] { ',' }), b => behaviourSwitches.Add(b));
153 163
164 MainConsole.Instance.OutputFormat(
165 "[BOT MANAGER]: Starting {0} bots connecting to {1}, named {2} {3}_<n>",
166 botcount,
167 loginUri,
168 firstName,
169 lastNameStem);
170
171 MainConsole.Instance.OutputFormat("[BOT MANAGER]: Delay between logins is {0}ms", LoginDelay);
172
154 for (int i = 0; i < botcount; i++) 173 for (int i = 0; i < botcount; i++)
155 { 174 {
156 string lastName = string.Format("{0}_{1}", lastNameStem, i); 175 string lastName = string.Format("{0}_{1}", lastNameStem, i);
157 176
177 // We must give each bot its own list of instantiated behaviours since they store state.
158 List<IBehaviour> behaviours = new List<IBehaviour>(); 178 List<IBehaviour> behaviours = new List<IBehaviour>();
159 179
160 // Hard-coded for now 180 // Hard-coded for now
161 if (behaviourSwitches.Contains("p")) 181 if (behaviourSwitches.Contains("p"))
162 behaviours.Add(new PhysicsBehaviour()); 182 behaviours.Add(new PhysicsBehaviour());
163 183
164 if (behaviourSwitches.Contains("g")) 184 if (behaviourSwitches.Contains("g"))
165 behaviours.Add(new GrabbingBehaviour()); 185 behaviours.Add(new GrabbingBehaviour());
166 186
167 if (behaviourSwitches.Contains("t")) 187 if (behaviourSwitches.Contains("t"))
168 behaviours.Add(new TeleportBehaviour()); 188 behaviours.Add(new TeleportBehaviour());
169 189
170 if (behaviourSwitches.Contains("c")) 190 if (behaviourSwitches.Contains("c"))
171 behaviours.Add(new CrossBehaviour()); 191 behaviours.Add(new CrossBehaviour());
172
173 MainConsole.Instance.OutputFormat(
174 "[BOT MANAGER]: Bot {0} {1} configured for behaviours {2}",
175 firstName, lastName, string.Join(",", behaviours.ConvertAll<string>(b => b.Name).ToArray()));
176 192
177 StartBot(this, behaviours, firstName, lastName, password, loginUri); 193 StartBot(this, behaviours, firstName, lastName, password, loginUri);
178 } 194 }
@@ -211,6 +227,10 @@ namespace pCampBot
211 BotManager bm, List<IBehaviour> behaviours, 227 BotManager bm, List<IBehaviour> behaviours,
212 string firstName, string lastName, string password, string loginUri) 228 string firstName, string lastName, string password, string loginUri)
213 { 229 {
230 MainConsole.Instance.OutputFormat(
231 "[BOT MANAGER]: Starting bot {0} {1}, behaviours are {2}",
232 firstName, lastName, string.Join(",", behaviours.ConvertAll<string>(b => b.Name).ToArray()));
233
214 Bot pb = new Bot(bm, behaviours, firstName, lastName, password, loginUri); 234 Bot pb = new Bot(bm, behaviours, firstName, lastName, password, loginUri);
215 235
216 pb.OnConnected += handlebotEvent; 236 pb.OnConnected += handlebotEvent;
@@ -222,7 +242,11 @@ namespace pCampBot
222 Thread pbThread = new Thread(pb.startup); 242 Thread pbThread = new Thread(pb.startup);
223 pbThread.Name = pb.Name; 243 pbThread.Name = pb.Name;
224 pbThread.IsBackground = true; 244 pbThread.IsBackground = true;
245
225 pbThread.Start(); 246 pbThread.Start();
247
248 // Stagger logins
249 Thread.Sleep(LoginDelay);
226 } 250 }
227 251
228 /// <summary> 252 /// <summary>
@@ -242,7 +266,7 @@ namespace pCampBot
242 266
243 lock (m_lBot) 267 lock (m_lBot)
244 { 268 {
245 if (m_lBot.TrueForAll(b => !b.IsConnected)) 269 if (m_lBot.TrueForAll(b => b.ConnectionState == ConnectionState.Disconnected))
246 Environment.Exit(0); 270 Environment.Exit(0);
247 271
248 break; 272 break;
@@ -251,13 +275,21 @@ namespace pCampBot
251 } 275 }
252 276
253 /// <summary> 277 /// <summary>
254 /// Shutting down all bots 278 /// Shut down all bots
255 /// </summary> 279 /// </summary>
280 /// <remarks>
281 /// We launch each shutdown on its own thread so that a slow shutting down bot doesn't hold up all the others.
282 /// </remarks>
256 public void doBotShutdown() 283 public void doBotShutdown()
257 { 284 {
258 lock (m_lBot) 285 lock (m_lBot)
259 foreach (Bot pb in m_lBot) 286 {
260 pb.shutdown(); 287 foreach (Bot bot in m_lBot)
288 {
289 Bot thisBot = bot;
290 Util.FireAndForget(o => thisBot.shutdown());
291 }
292 }
261 } 293 }
262 294
263 /// <summary> 295 /// <summary>
@@ -271,11 +303,8 @@ namespace pCampBot
271 303
272 private void HandleShutdown(string module, string[] cmd) 304 private void HandleShutdown(string module, string[] cmd)
273 { 305 {
274 Util.FireAndForget(o => 306 m_log.Info("[BOTMANAGER]: Shutting down bots");
275 { 307 doBotShutdown();
276 m_log.Warn("[BOTMANAGER]: Shutting down bots");
277 doBotShutdown();
278 });
279 } 308 }
280 309
281 private void HandleShowRegions(string module, string[] cmd) 310 private void HandleShowRegions(string module, string[] cmd)
@@ -302,9 +331,11 @@ namespace pCampBot
302 { 331 {
303 foreach (Bot pb in m_lBot) 332 foreach (Bot pb in m_lBot)
304 { 333 {
334 Simulator currentSim = pb.Client.Network.CurrentSim;
335
305 MainConsole.Instance.OutputFormat( 336 MainConsole.Instance.OutputFormat(
306 outputFormat, 337 outputFormat,
307 pb.Name, pb.Client.Network.CurrentSim.Name, pb.IsConnected ? "Connected" : "Disconnected"); 338 pb.Name, currentSim != null ? currentSim.Name : "(none)", pb.ConnectionState);
308 } 339 }
309 } 340 }
310 } 341 }
diff --git a/OpenSim/Tools/pCampBot/pCampBot.cs b/OpenSim/Tools/pCampBot/pCampBot.cs
index ec5ad04..52e7501 100644
--- a/OpenSim/Tools/pCampBot/pCampBot.cs
+++ b/OpenSim/Tools/pCampBot/pCampBot.cs
@@ -27,6 +27,7 @@
27 27
28using System; 28using System;
29using System.Reflection; 29using System.Reflection;
30using System.Threading;
30using log4net; 31using log4net;
31using Nini.Config; 32using Nini.Config;
32using OpenSim.Framework; 33using OpenSim.Framework;
@@ -67,7 +68,9 @@ namespace pCampBot
67 BotManager bm = new BotManager(); 68 BotManager bm = new BotManager();
68 69
69 //startup specified number of bots. 1 is the default 70 //startup specified number of bots. 1 is the default
70 bm.dobotStartup(botcount, config); 71 Thread startBotThread = new Thread(o => bm.dobotStartup(botcount, config));
72 startBotThread.Name = "Initial start bots thread";
73 startBotThread.Start();
71 74
72 while (true) 75 while (true)
73 { 76 {