aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tools
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Tools')
-rw-r--r--OpenSim/Tools/pCampBot/BotManager.cs110
1 files changed, 67 insertions, 43 deletions
diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs
index 8f31bdf..5c0dc81 100644
--- a/OpenSim/Tools/pCampBot/BotManager.cs
+++ b/OpenSim/Tools/pCampBot/BotManager.cs
@@ -52,9 +52,9 @@ namespace pCampBot
52 public const int DefaultLoginDelay = 5000; 52 public const int DefaultLoginDelay = 5000;
53 53
54 /// <summary> 54 /// <summary>
55 /// True if pCampbot is in the process of shutting down. 55 /// Is pCampbot in the process of disconnecting bots?
56 /// </summary> 56 /// </summary>
57 public bool ShuttingDown { get; private set; } 57 public bool DisconnectingBots { get; private set; }
58 58
59 /// <summary> 59 /// <summary>
60 /// Delay between logins of multiple bots. 60 /// Delay between logins of multiple bots.
@@ -139,6 +139,11 @@ namespace pCampBot
139 "Shutdown bots and exit", 139 "Shutdown bots and exit",
140 HandleShutdown); 140 HandleShutdown);
141 141
142 m_console.Commands.AddCommand("bot", false, "disconnect",
143 "disconnect",
144 "Disconnect all bots",
145 HandleDisconnect);
146
142 m_console.Commands.AddCommand("bot", false, "show regions", 147 m_console.Commands.AddCommand("bot", false, "show regions",
143 "show regions", 148 "show regions",
144 "Show regions known to bots", 149 "Show regions known to bots",
@@ -191,31 +196,37 @@ namespace pCampBot
191 196
192 for (int i = 0; i < botcount; i++) 197 for (int i = 0; i < botcount; i++)
193 { 198 {
194 if (ShuttingDown) 199 lock (m_lBot)
195 break; 200 {
201 if (DisconnectingBots)
202 break;
203
204 string lastName = string.Format("{0}_{1}", lastNameStem, i + fromBotNumber);
196 205
197 string lastName = string.Format("{0}_{1}", lastNameStem, i + fromBotNumber); 206 // We must give each bot its own list of instantiated behaviours since they store state.
207 List<IBehaviour> behaviours = new List<IBehaviour>();
208
209 // Hard-coded for now
210 if (behaviourSwitches.Contains("c"))
211 behaviours.Add(new CrossBehaviour());
198 212
199 // We must give each bot its own list of instantiated behaviours since they store state. 213 if (behaviourSwitches.Contains("g"))
200 List<IBehaviour> behaviours = new List<IBehaviour>(); 214 behaviours.Add(new GrabbingBehaviour());
201
202 // Hard-coded for now
203 if (behaviourSwitches.Contains("c"))
204 behaviours.Add(new CrossBehaviour());
205 215
206 if (behaviourSwitches.Contains("g")) 216 if (behaviourSwitches.Contains("n"))
207 behaviours.Add(new GrabbingBehaviour()); 217 behaviours.Add(new NoneBehaviour());
208 218
209 if (behaviourSwitches.Contains("n")) 219 if (behaviourSwitches.Contains("p"))
210 behaviours.Add(new NoneBehaviour()); 220 behaviours.Add(new PhysicsBehaviour());
221
222 if (behaviourSwitches.Contains("t"))
223 behaviours.Add(new TeleportBehaviour());
211 224
212 if (behaviourSwitches.Contains("p")) 225 StartBot(this, behaviours, firstName, lastName, password, loginUri, startUri, wearSetting);
213 behaviours.Add(new PhysicsBehaviour()); 226 }
214
215 if (behaviourSwitches.Contains("t"))
216 behaviours.Add(new TeleportBehaviour());
217 227
218 StartBot(this, behaviours, firstName, lastName, password, loginUri, startUri, wearSetting); 228 // Stagger logins
229 Thread.Sleep(LoginDelay);
219 } 230 }
220 } 231 }
221 232
@@ -305,17 +316,13 @@ namespace pCampBot
305 pb.OnConnected += handlebotEvent; 316 pb.OnConnected += handlebotEvent;
306 pb.OnDisconnected += handlebotEvent; 317 pb.OnDisconnected += handlebotEvent;
307 318
308 lock (m_lBot) 319 m_lBot.Add(pb);
309 m_lBot.Add(pb);
310 320
311 Thread pbThread = new Thread(pb.startup); 321 Thread pbThread = new Thread(pb.startup);
312 pbThread.Name = pb.Name; 322 pbThread.Name = pb.Name;
313 pbThread.IsBackground = true; 323 pbThread.IsBackground = true;
314 324
315 pbThread.Start(); 325 pbThread.Start();
316
317 // Stagger logins
318 Thread.Sleep(LoginDelay);
319 } 326 }
320 327
321 /// <summary> 328 /// <summary>
@@ -328,18 +335,16 @@ namespace pCampBot
328 switch (eventt) 335 switch (eventt)
329 { 336 {
330 case EventType.CONNECTED: 337 case EventType.CONNECTED:
338 {
331 m_log.Info("[" + callbot.FirstName + " " + callbot.LastName + "]: Connected"); 339 m_log.Info("[" + callbot.FirstName + " " + callbot.LastName + "]: Connected");
332 break; 340 break;
341 }
342
333 case EventType.DISCONNECTED: 343 case EventType.DISCONNECTED:
344 {
334 m_log.Info("[" + callbot.FirstName + " " + callbot.LastName + "]: Disconnected"); 345 m_log.Info("[" + callbot.FirstName + " " + callbot.LastName + "]: Disconnected");
335 346 break;
336 lock (m_lBot) 347 }
337 {
338 if (m_lBot.TrueForAll(b => b.ConnectionState == ConnectionState.Disconnected))
339 Environment.Exit(0);
340
341 break;
342 }
343 } 348 }
344 } 349 }
345 350
@@ -349,15 +354,12 @@ namespace pCampBot
349 /// <remarks> 354 /// <remarks>
350 /// We launch each shutdown on its own thread so that a slow shutting down bot doesn't hold up all the others. 355 /// We launch each shutdown on its own thread so that a slow shutting down bot doesn't hold up all the others.
351 /// </remarks> 356 /// </remarks>
352 public void doBotShutdown() 357 private void ShutdownBots()
353 { 358 {
354 lock (m_lBot) 359 foreach (Bot bot in m_lBot)
355 { 360 {
356 foreach (Bot bot in m_lBot) 361 Bot thisBot = bot;
357 { 362 Util.FireAndForget(o => thisBot.shutdown());
358 Bot thisBot = bot;
359 Util.FireAndForget(o => thisBot.shutdown());
360 }
361 } 363 }
362 } 364 }
363 365
@@ -370,12 +372,34 @@ namespace pCampBot
370 return new LocalConsole("pCampbot"); 372 return new LocalConsole("pCampbot");
371 } 373 }
372 374
375 private void HandleDisconnect(string module, string[] cmd)
376 {
377 MainConsole.Instance.Output("Disconnecting bots");
378
379 lock (m_lBot)
380 {
381 DisconnectingBots = true;
382
383 ShutdownBots();
384 }
385 }
386
373 private void HandleShutdown(string module, string[] cmd) 387 private void HandleShutdown(string module, string[] cmd)
374 { 388 {
389 lock (m_lBot)
390 {
391 int connectedBots = m_lBot.Count(b => b.ConnectionState == ConnectionState.Connected);
392
393 if (connectedBots > 0)
394 {
395 MainConsole.Instance.OutputFormat("Please disconnect {0} connected bots first", connectedBots);
396 return;
397 }
398 }
399
375 MainConsole.Instance.Output("Shutting down"); 400 MainConsole.Instance.Output("Shutting down");
376 401
377 ShuttingDown = true; 402 Environment.Exit(0);
378 doBotShutdown();
379 } 403 }
380 404
381 private void HandleShowRegions(string module, string[] cmd) 405 private void HandleShowRegions(string module, string[] cmd)