Add "show status" command to pCambot

remove-scene-viewer
Justin Clark-Casey (justincc) 2011-11-01 22:09:21 +00:00
parent 40750b44a0
commit 8e2e4c47d9
2 changed files with 45 additions and 22 deletions

View File

@ -93,6 +93,11 @@ namespace pCampBot
"Shutdown bots and exit",
HandleShutdown);
m_console.Commands.AddCommand("bot", false, "show status",
"show status",
"Shows the status of all bots",
HandleShowStatus);
// m_console.Commands.AddCommand("bot", false, "add bots",
// "add bots <number>",
// "Add more bots", HandleAddBots);
@ -157,6 +162,7 @@ namespace pCampBot
pb.OnConnected += handlebotEvent;
pb.OnDisconnected += handlebotEvent;
lock (m_lBot)
m_lBot.Add(pb);
Thread pbThread = new Thread(pb.startup);
@ -194,11 +200,10 @@ namespace pCampBot
/// </summary>
public void doBotShutdown()
{
lock (m_lBot)
foreach (PhysicsBot pb in m_lBot)
{
pb.shutdown();
}
}
/// <summary>
/// Standard CreateConsole routine
@ -215,6 +220,21 @@ namespace pCampBot
doBotShutdown();
}
private void HandleShowStatus(string module, string[] cmd)
{
string outputFormat = "{0,-30} {1,-14}";
MainConsole.Instance.OutputFormat(outputFormat, "Name", "Status");
lock (m_lBot)
{
foreach (PhysicsBot pb in m_lBot)
{
MainConsole.Instance.OutputFormat(
outputFormat, pb.Name, (pb.IsConnected ? "Connected" : "Disconnected"));
}
}
}
/*
private void HandleQuit(string module, string[] cmd)
{

View File

@ -51,6 +51,11 @@ namespace pCampBot
public BotManager BotManager { get; private set; }
private IConfig startupConfig; // bot config, passed from BotManager
/// <summary>
/// Is this bot connected to the grid?
/// </summary>
public bool IsConnected { get; private set; }
public string FirstName { get; private set; }
public string LastName { get; private set; }
public string Name { get; private set; }
@ -181,8 +186,8 @@ namespace pCampBot
if (client.Network.Login(FirstName, LastName, Password, "pCampBot", "Your name"))
{
if (OnConnected != null)
{
IsConnected = true;
Thread.Sleep(somthing.Next(1000, 10000));
m_actionThread = new Thread(Action);
m_actionThread.Start();
@ -199,7 +204,6 @@ namespace pCampBot
}
client.Self.Jump(true);
}
}
else
{
MainConsole.Instance.OutputFormat(
@ -392,8 +396,6 @@ namespace pCampBot
{
// m_log.ErrorFormat("Fired Network_OnDisconnected");
// Only pass on the disconnect message when we receive a SimShutdown type shutdown. We have to ignore
// the earlier ClientInitiated shutdown callback.
// if (
// (args.Reason == NetworkManager.DisconnectType.SimShutdown
// || args.Reason == NetworkManager.DisconnectType.NetworkTimeout)
@ -406,6 +408,7 @@ namespace pCampBot
&& OnDisconnected != null)
// if (OnDisconnected != null)
{
IsConnected = false;
OnDisconnected(this, EventType.DISCONNECTED);
}
}