refactor: start bot connection thread within BotManager rather than externally

0.7.6-extended
Justin Clark-Casey (justincc) 2013-08-19 21:25:17 +01:00
parent 079cd4e94f
commit ea3f024b8a
2 changed files with 27 additions and 5 deletions

View File

@ -51,6 +51,11 @@ namespace pCampBot
public const int DefaultLoginDelay = 5000; public const int DefaultLoginDelay = 5000;
/// <summary>
/// Is pCampbot in the process of connecting bots?
/// </summary>
public bool ConnectingBots { get; private set; }
/// <summary> /// <summary>
/// Is pCampbot in the process of disconnecting bots? /// Is pCampbot in the process of disconnecting bots?
/// </summary> /// </summary>
@ -219,7 +224,25 @@ namespace pCampBot
botcount, m_firstName, m_lastNameStem, m_password, m_loginUri, m_startUri, m_fromBotNumber, m_wearSetting, m_behaviourSwitches); botcount, m_firstName, m_lastNameStem, m_password, m_loginUri, m_startUri, m_fromBotNumber, m_wearSetting, m_behaviourSwitches);
} }
private void ConnectBots( private bool ConnectBots(
int botcount, string firstName, string lastNameStem, string password, string loginUri, string startUri, int fromBotNumber, string wearSetting,
HashSet<string> behaviourSwitches)
{
ConnectingBots = true;
Thread startBotThread
= new Thread(
o => ConnectBotsInternal(
botcount, firstName, lastNameStem, password, loginUri, startUri, fromBotNumber, wearSetting,
behaviourSwitches));
startBotThread.Name = "Bots connection thread";
startBotThread.Start();
return true;
}
private void ConnectBotsInternal(
int botcount, string firstName, string lastNameStem, string password, string loginUri, string startUri, int fromBotNumber, string wearSetting, int botcount, string firstName, string lastNameStem, string password, string loginUri, string startUri, int fromBotNumber, string wearSetting,
HashSet<string> behaviourSwitches) HashSet<string> behaviourSwitches)
{ {
@ -273,6 +296,8 @@ namespace pCampBot
// Stagger logins // Stagger logins
Thread.Sleep(LoginDelay); Thread.Sleep(LoginDelay);
} }
ConnectingBots = false;
} }
/// <summary> /// <summary>

View File

@ -95,10 +95,7 @@ namespace pCampBot
int botcount = commandLineConfig.GetInt("botcount", 1); int botcount = commandLineConfig.GetInt("botcount", 1);
//startup specified number of bots. 1 is the default bm.dobotStartup(botcount, commandLineConfig);
Thread startBotThread = new Thread(o => bm.dobotStartup(botcount, commandLineConfig));
startBotThread.Name = "Initial start bots thread";
startBotThread.Start();
while (true) while (true)
{ {