Make bots share a cache so that asset downloads attempts are only made once instead of once for each bot
parent
210868a832
commit
b951c7fb1e
|
@ -53,13 +53,20 @@ namespace pCampBot
|
||||||
protected bool m_verbose = true;
|
protected bool m_verbose = true;
|
||||||
protected Random somthing = new Random(Environment.TickCount);
|
protected Random somthing = new Random(Environment.TickCount);
|
||||||
protected int numbots = 0;
|
protected int numbots = 0;
|
||||||
private IConfig Config;
|
public IConfig Config { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Track the assets we have and have not received so we don't endlessly repeat requests.
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<UUID, bool> AssetsReceived { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor Creates MainConsole.Instance to take commands and provide the place to write data
|
/// Constructor Creates MainConsole.Instance to take commands and provide the place to write data
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public BotManager()
|
public BotManager()
|
||||||
{
|
{
|
||||||
|
AssetsReceived = new Dictionary<UUID, bool>();
|
||||||
|
|
||||||
m_console = CreateConsole();
|
m_console = CreateConsole();
|
||||||
MainConsole.Instance = m_console;
|
MainConsole.Instance = m_console;
|
||||||
|
|
||||||
|
@ -113,7 +120,7 @@ namespace pCampBot
|
||||||
for (int i = 0; i < botcount; i++)
|
for (int i = 0; i < botcount; i++)
|
||||||
{
|
{
|
||||||
string lastName = string.Format("{0}_{1}", lastNameStem, i);
|
string lastName = string.Format("{0}_{1}", lastNameStem, i);
|
||||||
startupBot(i, cs, firstName, lastName, password, loginUri);
|
startupBot(i, this, firstName, lastName, password, loginUri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,9 +153,9 @@ namespace pCampBot
|
||||||
/// <param name="lastName">Last name</param>
|
/// <param name="lastName">Last name</param>
|
||||||
/// <param name="password">Password</param>
|
/// <param name="password">Password</param>
|
||||||
/// <param name="loginUri">Login URI</param>
|
/// <param name="loginUri">Login URI</param>
|
||||||
public void startupBot(int pos, IConfig cs, string firstName, string lastName, string password, string loginUri)
|
public void startupBot(int pos, BotManager bm, string firstName, string lastName, string password, string loginUri)
|
||||||
{
|
{
|
||||||
PhysicsBot pb = new PhysicsBot(cs, firstName, lastName, password, loginUri);
|
PhysicsBot pb = new PhysicsBot(bm, firstName, lastName, password, loginUri);
|
||||||
|
|
||||||
pb.OnConnected += handlebotEvent;
|
pb.OnConnected += handlebotEvent;
|
||||||
pb.OnDisconnected += handlebotEvent;
|
pb.OnDisconnected += handlebotEvent;
|
||||||
|
|
|
@ -47,7 +47,9 @@ namespace pCampBot
|
||||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
public delegate void AnEvent(PhysicsBot callbot, EventType someevent); // event delegate for bot events
|
public delegate void AnEvent(PhysicsBot callbot, EventType someevent); // event delegate for bot events
|
||||||
public IConfig startupConfig; // bot config, passed from BotManager
|
|
||||||
|
public BotManager BotManager { get; private set; }
|
||||||
|
private IConfig startupConfig; // bot config, passed from BotManager
|
||||||
|
|
||||||
public string FirstName { get; private set; }
|
public string FirstName { get; private set; }
|
||||||
public string LastName { get; private set; }
|
public string LastName { get; private set; }
|
||||||
|
@ -60,11 +62,6 @@ namespace pCampBot
|
||||||
public event AnEvent OnConnected;
|
public event AnEvent OnConnected;
|
||||||
public event AnEvent OnDisconnected;
|
public event AnEvent OnDisconnected;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Track the assets we have and have not received so we don't endlessly repeat requests.
|
|
||||||
/// </summary>
|
|
||||||
public Dictionary<UUID, bool> AssetsReceived { get; private set; }
|
|
||||||
|
|
||||||
protected Timer m_action; // Action Timer
|
protected Timer m_action; // Action Timer
|
||||||
protected List<uint> objectIDs = new List<uint>();
|
protected List<uint> objectIDs = new List<uint>();
|
||||||
|
|
||||||
|
@ -80,23 +77,23 @@ namespace pCampBot
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="bsconfig"></param>
|
/// <param name="bm"></param>
|
||||||
/// <param name="firstName"></param>
|
/// <param name="firstName"></param>
|
||||||
/// <param name="lastName"></param>
|
/// <param name="lastName"></param>
|
||||||
/// <param name="password"></param>
|
/// <param name="password"></param>
|
||||||
/// <param name="loginUri"></param>
|
/// <param name="loginUri"></param>
|
||||||
public PhysicsBot(IConfig bsconfig, string firstName, string lastName, string password, string loginUri)
|
public PhysicsBot(BotManager bm, string firstName, string lastName, string password, string loginUri)
|
||||||
{
|
{
|
||||||
FirstName = firstName;
|
FirstName = firstName;
|
||||||
LastName = lastName;
|
LastName = lastName;
|
||||||
Name = string.Format("{0} {1}", FirstName, LastName);
|
Name = string.Format("{0} {1}", FirstName, LastName);
|
||||||
Password = password;
|
Password = password;
|
||||||
LoginUri = loginUri;
|
LoginUri = loginUri;
|
||||||
startupConfig = bsconfig;
|
|
||||||
|
BotManager = bm;
|
||||||
|
startupConfig = bm.Config;
|
||||||
readconfig();
|
readconfig();
|
||||||
talkarray = readexcuses();
|
talkarray = readexcuses();
|
||||||
|
|
||||||
AssetsReceived = new Dictionary<UUID, bool>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//We do our actions here. This is where one would
|
//We do our actions here. This is where one would
|
||||||
|
@ -428,13 +425,13 @@ namespace pCampBot
|
||||||
|
|
||||||
private void GetTexture(UUID textureID)
|
private void GetTexture(UUID textureID)
|
||||||
{
|
{
|
||||||
lock (AssetsReceived)
|
lock (BotManager.AssetsReceived)
|
||||||
{
|
{
|
||||||
// Don't request assets more than once.
|
// Don't request assets more than once.
|
||||||
if (AssetsReceived.ContainsKey(textureID))
|
if (BotManager.AssetsReceived.ContainsKey(textureID))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
AssetsReceived[textureID] = false;
|
BotManager.AssetsReceived[textureID] = false;
|
||||||
client.Assets.RequestImage(textureID, ImageType.Normal, Asset_TextureCallback_Texture);
|
client.Assets.RequestImage(textureID, ImageType.Normal, Asset_TextureCallback_Texture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -447,8 +444,8 @@ namespace pCampBot
|
||||||
|
|
||||||
public void Asset_ReceivedCallback(AssetDownload transfer, Asset asset)
|
public void Asset_ReceivedCallback(AssetDownload transfer, Asset asset)
|
||||||
{
|
{
|
||||||
lock (AssetsReceived)
|
lock (BotManager.AssetsReceived)
|
||||||
AssetsReceived[asset.AssetID] = true;
|
BotManager.AssetsReceived[asset.AssetID] = true;
|
||||||
|
|
||||||
// if (wear == "save")
|
// if (wear == "save")
|
||||||
// {
|
// {
|
||||||
|
|
Loading…
Reference in New Issue