diff --git a/OpenSim/Framework/Console/ConsoleUtil.cs b/OpenSim/Framework/Console/ConsoleUtil.cs
index c0ff454831..794bfaf8dd 100644
--- a/OpenSim/Framework/Console/ConsoleUtil.cs
+++ b/OpenSim/Framework/Console/ConsoleUtil.cs
@@ -179,8 +179,8 @@ namespace OpenSim.Framework.Console
/// Convert a console integer to an int, automatically complaining if a console is given.
///
/// Can be null if no console is available.
- /// /param>
- ///
+ /// /param>
+ ///
///
public static bool TryParseConsoleInt(ICommandConsole console, string rawConsoleInt, out int i)
{
@@ -194,6 +194,31 @@ namespace OpenSim.Framework.Console
return true;
}
+
+ ///
+ /// Convert a console integer to a natural int, automatically complaining if a console is given.
+ ///
+ /// Can be null if no console is available.
+ /// /param>
+ ///
+ ///
+ public static bool TryParseConsoleNaturalInt(ICommandConsole console, string rawConsoleInt, out int i)
+ {
+ if (TryParseConsoleInt(console, rawConsoleInt, out i))
+ {
+ if (i < 0)
+ {
+ if (console != null)
+ console.OutputFormat("ERROR: {0} is not a positive integer", rawConsoleInt);
+
+ return false;
+ }
+
+ return true;
+ }
+
+ return false;
+ }
///
/// Convert a minimum vector input from the console to an OpenMetaverse.Vector3
diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs
index 5c0dc81c29..157c69cc03 100644
--- a/OpenSim/Tools/pCampBot/BotManager.cs
+++ b/OpenSim/Tools/pCampBot/BotManager.cs
@@ -80,7 +80,7 @@ namespace pCampBot
///
/// Created bots, whether active or inactive.
///
- protected List m_lBot;
+ protected List m_bots;
///
/// Random number generator.
@@ -130,35 +130,30 @@ namespace pCampBot
}
}
- m_console.Commands.AddCommand("bot", false, "shutdown",
- "shutdown",
- "Shutdown bots and exit", HandleShutdown);
+ m_console.Commands.AddCommand(
+ "bot", false, "shutdown", "shutdown", "Shutdown bots and exit", HandleShutdown);
- m_console.Commands.AddCommand("bot", false, "quit",
- "quit",
- "Shutdown bots and exit",
- HandleShutdown);
+ m_console.Commands.AddCommand(
+ "bot", false, "quit", "quit", "Shutdown bots and exit", HandleShutdown);
- m_console.Commands.AddCommand("bot", false, "disconnect",
- "disconnect",
- "Disconnect all bots",
- HandleDisconnect);
+ m_console.Commands.AddCommand(
+ "bot", false, "disconnect", "disconnect []", "Disconnect bots",
+ "Disconnecting bots will interupt any bot connection process, including connection on startup.\n"
+ + "If an is given, then the last connected bots by postfix number are disconnected.\n"
+ + "If no is given, then all currently connected bots are disconnected.",
+ HandleDisconnect);
- m_console.Commands.AddCommand("bot", false, "show regions",
- "show regions",
- "Show regions known to bots",
- HandleShowRegions);
+ m_console.Commands.AddCommand(
+ "bot", false, "show regions", "show regions", "Show regions known to bots", HandleShowRegions);
- m_console.Commands.AddCommand("bot", false, "show bots",
- "show bots",
- "Shows the status of all bots",
- HandleShowStatus);
+ m_console.Commands.AddCommand(
+ "bot", false, "show bots", "show bots", "Shows the status of all bots", HandleShowStatus);
// m_console.Commands.AddCommand("bot", false, "add bots",
// "add bots ",
// "Add more bots", HandleAddBots);
- m_lBot = new List();
+ m_bots = new List();
}
///
@@ -196,7 +191,7 @@ namespace pCampBot
for (int i = 0; i < botcount; i++)
{
- lock (m_lBot)
+ lock (m_bots)
{
if (DisconnectingBots)
break;
@@ -316,7 +311,7 @@ namespace pCampBot
pb.OnConnected += handlebotEvent;
pb.OnDisconnected += handlebotEvent;
- m_lBot.Add(pb);
+ m_bots.Add(pb);
Thread pbThread = new Thread(pb.startup);
pbThread.Name = pb.Name;
@@ -348,21 +343,6 @@ namespace pCampBot
}
}
- ///
- /// Shut down all bots
- ///
- ///
- /// We launch each shutdown on its own thread so that a slow shutting down bot doesn't hold up all the others.
- ///
- private void ShutdownBots()
- {
- foreach (Bot bot in m_lBot)
- {
- Bot thisBot = bot;
- Util.FireAndForget(o => thisBot.shutdown());
- }
- }
-
///
/// Standard CreateConsole routine
///
@@ -374,21 +354,50 @@ namespace pCampBot
private void HandleDisconnect(string module, string[] cmd)
{
- MainConsole.Instance.Output("Disconnecting bots");
-
- lock (m_lBot)
+ lock (m_bots)
{
+ int botsToDisconnect;
+ int connectedBots = m_bots.Count(b => b.ConnectionState == ConnectionState.Connected);
+
+ if (cmd.Length == 1)
+ {
+ botsToDisconnect = connectedBots;
+ }
+ else
+ {
+ if (!ConsoleUtil.TryParseConsoleNaturalInt(MainConsole.Instance, cmd[1], out botsToDisconnect))
+ return;
+
+ botsToDisconnect = Math.Min(botsToDisconnect, connectedBots);
+ }
+
DisconnectingBots = true;
- ShutdownBots();
+ MainConsole.Instance.OutputFormat("Disconnecting {0} bots", botsToDisconnect);
+
+ int disconnectedBots = 0;
+
+ for (int i = m_bots.Count - 1; i >= 0; i--)
+ {
+ if (disconnectedBots >= botsToDisconnect)
+ break;
+
+ Bot thisBot = m_bots[i];
+
+ if (thisBot.ConnectionState == ConnectionState.Connected)
+ {
+ Util.FireAndForget(o => thisBot.shutdown());
+ disconnectedBots++;
+ }
+ }
}
}
private void HandleShutdown(string module, string[] cmd)
{
- lock (m_lBot)
+ lock (m_bots)
{
- int connectedBots = m_lBot.Count(b => b.ConnectionState == ConnectionState.Connected);
+ int connectedBots = m_bots.Count(b => b.ConnectionState == ConnectionState.Connected);
if (connectedBots > 0)
{
@@ -429,9 +438,9 @@ namespace pCampBot
foreach (object o in Enum.GetValues(typeof(ConnectionState)))
totals[(ConnectionState)o] = 0;
- lock (m_lBot)
+ lock (m_bots)
{
- foreach (Bot pb in m_lBot)
+ foreach (Bot pb in m_bots)
{
Simulator currentSim = pb.Client.Network.CurrentSim;
totals[pb.ConnectionState]++;