aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tools/pCampBot/BotManager.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Tools/pCampBot/BotManager.cs78
1 files changed, 55 insertions, 23 deletions
diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs
index 29739dc..c7d8f05 100644
--- a/OpenSim/Tools/pCampBot/BotManager.cs
+++ b/OpenSim/Tools/pCampBot/BotManager.cs
@@ -43,6 +43,14 @@ using pCampBot.Interfaces;
43 43
44namespace pCampBot 44namespace pCampBot
45{ 45{
46 public enum BotManagerBotConnectingState
47 {
48 Initializing,
49 Ready,
50 Connecting,
51 Disconnecting
52 }
53
46 /// <summary> 54 /// <summary>
47 /// Thread/Bot manager for the application 55 /// Thread/Bot manager for the application
48 /// </summary> 56 /// </summary>
@@ -53,14 +61,14 @@ namespace pCampBot
53 public const int DefaultLoginDelay = 5000; 61 public const int DefaultLoginDelay = 5000;
54 62
55 /// <summary> 63 /// <summary>
56 /// Is pCampbot in the process of connecting bots? 64 /// Is pCampbot ready to connect or currently in the process of connecting or disconnecting bots?
57 /// </summary> 65 /// </summary>
58 public bool ConnectingBots { get; private set; } 66 public BotManagerBotConnectingState BotConnectingState { get; private set; }
59 67
60 /// <summary> 68 /// <summary>
61 /// Is pCampbot in the process of disconnecting bots? 69 /// Used to control locking as we can't lock an enum.
62 /// </summary> 70 /// </summary>
63 public bool DisconnectingBots { get; private set; } 71 private object BotConnectingStateChangeObject = new object();
64 72
65 /// <summary> 73 /// <summary>
66 /// Delay between logins of multiple bots. 74 /// Delay between logins of multiple bots.
@@ -239,12 +247,15 @@ namespace pCampBot
239 "Bots", false, "show regions", "show regions", "Show regions known to bots", HandleShowRegions); 247 "Bots", false, "show regions", "show regions", "Show regions known to bots", HandleShowRegions);
240 248
241 m_console.Commands.AddCommand( 249 m_console.Commands.AddCommand(
242 "Bots", false, "show bots", "show bots", "Shows the status of all bots", HandleShowBotsStatus); 250 "Bots", false, "show bots", "show bots", "Shows the status of all bots.", HandleShowBotsStatus);
243 251
244 m_console.Commands.AddCommand( 252 m_console.Commands.AddCommand(
245 "Bots", false, "show bot", "show bot <bot-number>", 253 "Bots", false, "show bot", "show bot <bot-number>",
246 "Shows the detailed status and settings of a particular bot.", HandleShowBotStatus); 254 "Shows the detailed status and settings of a particular bot.", HandleShowBotStatus);
247 255
256 m_console.Commands.AddCommand(
257 "Bots", false, "show status", "show status", "Shows pCampbot status.", HandleShowStatus);
258
248 m_bots = new List<Bot>(); 259 m_bots = new List<Bot>();
249 260
250 Watchdog.Enabled = true; 261 Watchdog.Enabled = true;
@@ -254,6 +265,8 @@ namespace pCampBot
254 m_serverStatsCollector.Initialise(null); 265 m_serverStatsCollector.Initialise(null);
255 m_serverStatsCollector.Enabled = true; 266 m_serverStatsCollector.Enabled = true;
256 m_serverStatsCollector.Start(); 267 m_serverStatsCollector.Start();
268
269 BotConnectingState = BotManagerBotConnectingState.Ready;
257 } 270 }
258 271
259 /// <summary> 272 /// <summary>
@@ -335,7 +348,17 @@ namespace pCampBot
335 348
336 public void ConnectBots(int botcount) 349 public void ConnectBots(int botcount)
337 { 350 {
338 ConnectingBots = true; 351 lock (BotConnectingStateChangeObject)
352 {
353 if (BotConnectingState != BotManagerBotConnectingState.Ready)
354 {
355 MainConsole.Instance.OutputFormat(
356 "Bot connecting status is {0}. Please wait for previous process to complete.", BotConnectingState);
357 return;
358 }
359
360 BotConnectingState = BotManagerBotConnectingState.Connecting;
361 }
339 362
340 Thread connectBotThread = new Thread(o => ConnectBotsInternal(botcount)); 363 Thread connectBotThread = new Thread(o => ConnectBotsInternal(botcount));
341 364
@@ -373,11 +396,14 @@ namespace pCampBot
373 396
374 foreach (Bot bot in botsToConnect) 397 foreach (Bot bot in botsToConnect)
375 { 398 {
376 if (!ConnectingBots) 399 lock (BotConnectingStateChangeObject)
377 { 400 {
378 MainConsole.Instance.Output( 401 if (BotConnectingState != BotManagerBotConnectingState.Connecting)
379 "[BOT MANAGER]: Aborting bot connection due to user-initiated disconnection"); 402 {
380 break; 403 MainConsole.Instance.Output(
404 "[BOT MANAGER]: Aborting bot connection due to user-initiated disconnection");
405 return;
406 }
381 } 407 }
382 408
383 bot.Connect(); 409 bot.Connect();
@@ -386,7 +412,11 @@ namespace pCampBot
386 Thread.Sleep(LoginDelay); 412 Thread.Sleep(LoginDelay);
387 } 413 }
388 414
389 ConnectingBots = false; 415 lock (BotConnectingStateChangeObject)
416 {
417 if (BotConnectingState == BotManagerBotConnectingState.Connecting)
418 BotConnectingState = BotManagerBotConnectingState.Ready;
419 }
390 } 420 }
391 421
392 /// <summary> 422 /// <summary>
@@ -491,13 +521,7 @@ namespace pCampBot
491 } 521 }
492 522
493 private void HandleConnect(string module, string[] cmd) 523 private void HandleConnect(string module, string[] cmd)
494 { 524 {
495 if (ConnectingBots)
496 {
497 MainConsole.Instance.Output("Still connecting bots. Please wait for previous process to complete.");
498 return;
499 }
500
501 lock (m_bots) 525 lock (m_bots)
502 { 526 {
503 int botsToConnect; 527 int botsToConnect;
@@ -653,7 +677,8 @@ namespace pCampBot
653 botsToDisconnectCount = Math.Min(botsToDisconnectCount, connectedBots.Count); 677 botsToDisconnectCount = Math.Min(botsToDisconnectCount, connectedBots.Count);
654 } 678 }
655 679
656 DisconnectingBots = true; 680 lock (BotConnectingStateChangeObject)
681 BotConnectingState = BotManagerBotConnectingState.Disconnecting;
657 682
658 Thread disconnectBotThread = new Thread(o => DisconnectBotsInternal(connectedBots, botsToDisconnectCount)); 683 Thread disconnectBotThread = new Thread(o => DisconnectBotsInternal(connectedBots, botsToDisconnectCount));
659 684
@@ -662,9 +687,7 @@ namespace pCampBot
662 } 687 }
663 688
664 private void DisconnectBotsInternal(List<Bot> connectedBots, int disconnectCount) 689 private void DisconnectBotsInternal(List<Bot> connectedBots, int disconnectCount)
665 { 690 {
666 ConnectingBots = false;
667
668 MainConsole.Instance.OutputFormat("Disconnecting {0} bots", disconnectCount); 691 MainConsole.Instance.OutputFormat("Disconnecting {0} bots", disconnectCount);
669 692
670 int disconnectedBots = 0; 693 int disconnectedBots = 0;
@@ -683,7 +706,8 @@ namespace pCampBot
683 } 706 }
684 } 707 }
685 708
686 DisconnectingBots = false; 709 lock (BotConnectingStateChangeObject)
710 BotConnectingState = BotManagerBotConnectingState.Ready;
687 } 711 }
688 712
689 private void HandleSit(string module, string[] cmd) 713 private void HandleSit(string module, string[] cmd)
@@ -775,6 +799,14 @@ namespace pCampBot
775 } 799 }
776 } 800 }
777 801
802 private void HandleShowStatus(string module, string[] cmd)
803 {
804 ConsoleDisplayList cdl = new ConsoleDisplayList();
805 cdl.AddRow("Bot connecting state", BotConnectingState);
806
807 MainConsole.Instance.Output(cdl.ToString());
808 }
809
778 private void HandleShowBotsStatus(string module, string[] cmd) 810 private void HandleShowBotsStatus(string module, string[] cmd)
779 { 811 {
780 ConsoleDisplayTable cdt = new ConsoleDisplayTable(); 812 ConsoleDisplayTable cdt = new ConsoleDisplayTable();