aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tools
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2014-08-05 01:15:07 +0100
committerJustin Clark-Casey (justincc)2014-08-05 01:15:07 +0100
commitfcc665a56725eaa1e92b096fdbd0190d7a20b2ec (patch)
tree8800ee64a2856c12b1022a030b045ce3c554111f /OpenSim/Tools
parentAllow "show bots" pCampbot console command to quickly report status by not lo... (diff)
downloadopensim-SC_OLD-fcc665a56725eaa1e92b096fdbd0190d7a20b2ec.zip
opensim-SC_OLD-fcc665a56725eaa1e92b096fdbd0190d7a20b2ec.tar.gz
opensim-SC_OLD-fcc665a56725eaa1e92b096fdbd0190d7a20b2ec.tar.bz2
opensim-SC_OLD-fcc665a56725eaa1e92b096fdbd0190d7a20b2ec.tar.xz
Put pCampbot "disconnect" command on separate thread like "connect" so that we can continue to run status commands whilst bots are disconnecting.
Diffstat (limited to 'OpenSim/Tools')
-rw-r--r--OpenSim/Tools/pCampBot/BotManager.cs62
1 files changed, 35 insertions, 27 deletions
diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs
index f54d586..a872dbc 100644
--- a/OpenSim/Tools/pCampBot/BotManager.cs
+++ b/OpenSim/Tools/pCampBot/BotManager.cs
@@ -611,45 +611,53 @@ namespace pCampBot
611 611
612 private void HandleDisconnect(string module, string[] cmd) 612 private void HandleDisconnect(string module, string[] cmd)
613 { 613 {
614 List<Bot> connectedBots;
615 int botsToDisconnectCount;
616
614 lock (m_bots) 617 lock (m_bots)
618 connectedBots = m_bots.FindAll(b => b.ConnectionState == ConnectionState.Connected);
619
620 if (cmd.Length == 1)
615 { 621 {
616 int botsToDisconnect; 622 botsToDisconnectCount = connectedBots.Count;
617 int connectedBots = m_bots.Count(b => b.ConnectionState == ConnectionState.Connected); 623 }
624 else
625 {
626 if (!ConsoleUtil.TryParseConsoleNaturalInt(MainConsole.Instance, cmd[1], out botsToDisconnectCount))
627 return;
618 628
619 if (cmd.Length == 1) 629 botsToDisconnectCount = Math.Min(botsToDisconnectCount, connectedBots.Count);
620 { 630 }
621 botsToDisconnect = connectedBots;
622 }
623 else
624 {
625 if (!ConsoleUtil.TryParseConsoleNaturalInt(MainConsole.Instance, cmd[1], out botsToDisconnect))
626 return;
627 631
628 botsToDisconnect = Math.Min(botsToDisconnect, connectedBots); 632 Thread disconnectBotThread = new Thread(o => DisconnectBotsInternal(connectedBots, botsToDisconnectCount));
629 }
630 633
631 DisconnectingBots = true; 634 disconnectBotThread.Name = "Bots disconnection thread";
635 disconnectBotThread.Start();
636 }
632 637
633 MainConsole.Instance.OutputFormat("Disconnecting {0} bots", botsToDisconnect); 638 private void DisconnectBotsInternal(List<Bot> connectedBots, int disconnectCount)
639 {
640 DisconnectingBots = true;
634 641
635 int disconnectedBots = 0; 642 MainConsole.Instance.OutputFormat("Disconnecting {0} bots", disconnectCount);
636 643
637 for (int i = m_bots.Count - 1; i >= 0; i--) 644 int disconnectedBots = 0;
638 {
639 if (disconnectedBots >= botsToDisconnect)
640 break;
641 645
642 Bot thisBot = m_bots[i]; 646 for (int i = connectedBots.Count - 1; i >= 0; i--)
647 {
648 if (disconnectedBots >= disconnectCount)
649 break;
643 650
644 if (thisBot.ConnectionState == ConnectionState.Connected) 651 Bot thisBot = connectedBots[i];
645 {
646 Util.FireAndForget(o => thisBot.Disconnect());
647 disconnectedBots++;
648 }
649 }
650 652
651 DisconnectingBots = false; 653 if (thisBot.ConnectionState == ConnectionState.Connected)
654 {
655 thisBot.Disconnect();
656 disconnectedBots++;
657 }
652 } 658 }
659
660 DisconnectingBots = false;
653 } 661 }
654 662
655 private void HandleSit(string module, string[] cmd) 663 private void HandleSit(string module, string[] cmd)