mirror of
https://github.com/opensim/opensim.git
synced 2026-08-10 11:33:28 +08:00
adjust pCampbot so it starts up bots with the name format "<firstname> <lastname>_<bot-number>"
e.g. starting up two bots called "Ima Bot" will give them the names "Ima Bot_0" and "Ima Bot_1" This is necessary since bots with random names can no longer be created, as there's no easy way to turn off account authentication
This commit is contained in:
@@ -53,7 +53,7 @@ namespace pCampBot
|
||||
protected bool m_verbose = true;
|
||||
protected Random somthing = new Random(Environment.TickCount);
|
||||
protected int numbots = 0;
|
||||
protected IConfig Previous_config;
|
||||
private IConfig Config;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor Creates MainConsole.Instance to take commands and provide the place to write data
|
||||
@@ -102,71 +102,64 @@ namespace pCampBot
|
||||
/// <param name="cs">The configuration for the bots to use</param>
|
||||
public void dobotStartup(int botcount, IConfig cs)
|
||||
{
|
||||
Previous_config = cs;
|
||||
Config = cs;
|
||||
m_td = new Thread[botcount];
|
||||
|
||||
string firstName = cs.GetString("firstname");
|
||||
string lastNameStem = cs.GetString("lastname");
|
||||
string password = cs.GetString("password");
|
||||
string loginUri = cs.GetString("loginuri");
|
||||
|
||||
for (int i = 0; i < botcount; i++)
|
||||
{
|
||||
startupBot(i, cs);
|
||||
string lastName = string.Format("{0}_{1}", lastNameStem, i);
|
||||
startupBot(i, cs, firstName, lastName, password, loginUri);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add additional bots (and threads) to our bot pool
|
||||
/// </summary>
|
||||
/// <param name="botcount">How Many of them to add</param>
|
||||
public void addbots(int botcount)
|
||||
{
|
||||
int len = m_td.Length;
|
||||
Thread[] m_td2 = new Thread[len + botcount];
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
m_td2[i] = m_td[i];
|
||||
}
|
||||
m_td = m_td2;
|
||||
int newlen = len + botcount;
|
||||
for (int i = len; i < newlen; i++)
|
||||
{
|
||||
startupBot(i, Previous_config);
|
||||
}
|
||||
}
|
||||
// /// <summary>
|
||||
// /// Add additional bots (and threads) to our bot pool
|
||||
// /// </summary>
|
||||
// /// <param name="botcount">How Many of them to add</param>
|
||||
// public void addbots(int botcount)
|
||||
// {
|
||||
// int len = m_td.Length;
|
||||
// Thread[] m_td2 = new Thread[len + botcount];
|
||||
// for (int i = 0; i < len; i++)
|
||||
// {
|
||||
// m_td2[i] = m_td[i];
|
||||
// }
|
||||
// m_td = m_td2;
|
||||
// int newlen = len + botcount;
|
||||
// for (int i = len; i < newlen; i++)
|
||||
// {
|
||||
// startupBot(i, Config);
|
||||
// }
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// This starts up the bot and stores the thread for the bot in the thread array
|
||||
/// </summary>
|
||||
/// <param name="pos">The position in the thread array to stick the bot's thread</param>
|
||||
/// <param name="cs">Configuration of the bot</param>
|
||||
public void startupBot(int pos, IConfig cs)
|
||||
/// <param name="firstName">First name</param>
|
||||
/// <param name="lastName">Last name</param>
|
||||
/// <param name="password">Password</param>
|
||||
/// <param name="loginUri">Login URI</param>
|
||||
public void startupBot(int pos, IConfig cs, string firstName, string lastName, string password, string loginUri)
|
||||
{
|
||||
PhysicsBot pb = new PhysicsBot(cs);
|
||||
PhysicsBot pb = new PhysicsBot(cs, firstName, lastName, password, loginUri);
|
||||
|
||||
pb.OnConnected += handlebotEvent;
|
||||
pb.OnDisconnected += handlebotEvent;
|
||||
if (cs.GetString("firstname", "random") == "random") pb.firstname = CreateRandomName();
|
||||
if (cs.GetString("lastname", "random") == "random") pb.lastname = CreateRandomName();
|
||||
|
||||
m_td[pos] = new Thread(pb.startup);
|
||||
m_td[pos].Name = "CampBot_" + pos;
|
||||
m_td[pos].Name = pb.Name;
|
||||
m_td[pos].IsBackground = true;
|
||||
m_td[pos].Start();
|
||||
m_lBot.Add(pb);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random name for the bot
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private string CreateRandomName()
|
||||
{
|
||||
string returnstring = "";
|
||||
string chars = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||
|
||||
for (int i = 0; i < 7; i++)
|
||||
{
|
||||
returnstring += chars.Substring(somthing.Next(chars.Length),1);
|
||||
}
|
||||
return returnstring;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// High level connnected/disconnected events so we can keep track of our threads by proxy
|
||||
/// </summary>
|
||||
@@ -177,11 +170,11 @@ namespace pCampBot
|
||||
switch (eventt)
|
||||
{
|
||||
case EventType.CONNECTED:
|
||||
m_log.Info("[" + callbot.firstname + " " + callbot.lastname + "]: Connected");
|
||||
m_log.Info("[" + callbot.FirstName + " " + callbot.LastName + "]: Connected");
|
||||
numbots++;
|
||||
break;
|
||||
case EventType.DISCONNECTED:
|
||||
m_log.Info("[" + callbot.firstname + " " + callbot.lastname + "]: Disconnected");
|
||||
m_log.Info("[" + callbot.FirstName + " " + callbot.LastName + "]: Disconnected");
|
||||
m_td[m_lBot.IndexOf(callbot)].Abort();
|
||||
numbots--;
|
||||
if (numbots <= 0)
|
||||
@@ -223,17 +216,17 @@ namespace pCampBot
|
||||
Environment.Exit(0);
|
||||
}
|
||||
*/
|
||||
|
||||
private void HandleAddBots(string module, string[] cmd)
|
||||
{
|
||||
int newbots = 0;
|
||||
|
||||
if (cmd.Length > 2)
|
||||
{
|
||||
Int32.TryParse(cmd[2], out newbots);
|
||||
}
|
||||
if (newbots > 0)
|
||||
addbots(newbots);
|
||||
}
|
||||
//
|
||||
// private void HandleAddBots(string module, string[] cmd)
|
||||
// {
|
||||
// int newbots = 0;
|
||||
//
|
||||
// if (cmd.Length > 2)
|
||||
// {
|
||||
// Int32.TryParse(cmd[2], out newbots);
|
||||
// }
|
||||
// if (newbots > 0)
|
||||
// addbots(newbots);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user