Make it possible to disconnected a specified number of bots via the pCampbot console command "disconnect [<n>]"
Bots disconnected are ascending from last in numeric order. Temporarily no way to reconnect bots.0.7.6-extended
parent
49b7cbda72
commit
2fa42f24fd
|
@ -179,8 +179,8 @@ namespace OpenSim.Framework.Console
|
|||
/// Convert a console integer to an int, automatically complaining if a console is given.
|
||||
/// </summary>
|
||||
/// <param name='console'>Can be null if no console is available.</param>
|
||||
/// <param name='rawConsoleVector'>/param>
|
||||
/// <param name='vector'></param>
|
||||
/// <param name='rawConsoleInt'>/param>
|
||||
/// <param name='i'></param>
|
||||
/// <returns></returns>
|
||||
public static bool TryParseConsoleInt(ICommandConsole console, string rawConsoleInt, out int i)
|
||||
{
|
||||
|
@ -195,6 +195,31 @@ namespace OpenSim.Framework.Console
|
|||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a console integer to a natural int, automatically complaining if a console is given.
|
||||
/// </summary>
|
||||
/// <param name='console'>Can be null if no console is available.</param>
|
||||
/// <param name='rawConsoleInt'>/param>
|
||||
/// <param name='i'></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a minimum vector input from the console to an OpenMetaverse.Vector3
|
||||
/// </summary>
|
||||
|
|
|
@ -80,7 +80,7 @@ namespace pCampBot
|
|||
/// <summary>
|
||||
/// Created bots, whether active or inactive.
|
||||
/// </summary>
|
||||
protected List<Bot> m_lBot;
|
||||
protected List<Bot> m_bots;
|
||||
|
||||
/// <summary>
|
||||
/// 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",
|
||||
m_console.Commands.AddCommand(
|
||||
"bot", false, "disconnect", "disconnect [<n>]", "Disconnect bots",
|
||||
"Disconnecting bots will interupt any bot connection process, including connection on startup.\n"
|
||||
+ "If an <n> is given, then the last <n> connected bots by postfix number are disconnected.\n"
|
||||
+ "If no <n> 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 <number>",
|
||||
// "Add more bots", HandleAddBots);
|
||||
|
||||
m_lBot = new List<Bot>();
|
||||
m_bots = new List<Bot>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -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
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shut down all bots
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// We launch each shutdown on its own thread so that a slow shutting down bot doesn't hold up all the others.
|
||||
/// </remarks>
|
||||
private void ShutdownBots()
|
||||
{
|
||||
foreach (Bot bot in m_lBot)
|
||||
{
|
||||
Bot thisBot = bot;
|
||||
Util.FireAndForget(o => thisBot.shutdown());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Standard CreateConsole routine
|
||||
/// </summary>
|
||||
|
@ -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]++;
|
||||
|
|
Loading…
Reference in New Issue