Add a SendAgentUpdates setting to a new pCampbot.ini.example file which can control whether bots send agent updates

pCampbot.ini.example is used by copying to pCampbot.ini, like other ini files
0.7.6-extended
Justin Clark-Casey (justincc) 2013-08-13 23:54:50 +01:00
parent e311f902ff
commit 5933f9448d
4 changed files with 59 additions and 40 deletions

View File

@ -63,11 +63,6 @@ namespace pCampBot
/// </summary> /// </summary>
public BotManager Manager { get; private set; } public BotManager Manager { get; private set; }
/// <summary>
/// Bot config, passed from BotManager.
/// </summary>
private IConfig startupConfig;
/// <summary> /// <summary>
/// Behaviours implemented by this bot. /// Behaviours implemented by this bot.
/// </summary> /// </summary>
@ -153,9 +148,6 @@ namespace pCampBot
LoginUri = loginUri; LoginUri = loginUri;
Manager = bm; Manager = bm;
startupConfig = bm.Config;
readconfig();
Behaviours = behaviours; Behaviours = behaviours;
} }
@ -176,14 +168,6 @@ namespace pCampBot
); );
} }
/// <summary>
/// Read the Nini config and initialize
/// </summary>
public void readconfig()
{
wear = startupConfig.GetString("wear", "no");
}
/// <summary> /// <summary>
/// Tells LibSecondLife to logout and disconnect. Raises the disconnect events once it finishes. /// Tells LibSecondLife to logout and disconnect. Raises the disconnect events once it finishes.
/// </summary> /// </summary>
@ -207,6 +191,7 @@ namespace pCampBot
Client.Settings.AVATAR_TRACKING = false; Client.Settings.AVATAR_TRACKING = false;
Client.Settings.OBJECT_TRACKING = false; Client.Settings.OBJECT_TRACKING = false;
Client.Settings.SEND_AGENT_THROTTLE = true; Client.Settings.SEND_AGENT_THROTTLE = true;
Client.Settings.SEND_AGENT_UPDATES = false;
Client.Settings.SEND_PINGS = true; Client.Settings.SEND_PINGS = true;
Client.Settings.STORE_LAND_PATCHES = false; Client.Settings.STORE_LAND_PATCHES = false;
Client.Settings.USE_ASSET_CACHE = false; Client.Settings.USE_ASSET_CACHE = false;
@ -481,9 +466,6 @@ namespace pCampBot
public void Objects_NewPrim(object sender, PrimEventArgs args) public void Objects_NewPrim(object sender, PrimEventArgs args)
{ {
// if (Name.EndsWith("4"))
// throw new Exception("Aaargh");
Primitive prim = args.Prim; Primitive prim = args.Prim;
if (prim != null) if (prim != null)

View File

@ -62,6 +62,11 @@ namespace pCampBot
/// </summary> /// </summary>
protected CommandConsole m_console; protected CommandConsole m_console;
/// <summary>
/// Controls whether bots start out sending agent updates on connection.
/// </summary>
public bool BotsInitSendAgentUpdates { get; set; }
/// <summary> /// <summary>
/// Created bots, whether active or inactive. /// Created bots, whether active or inactive.
/// </summary> /// </summary>
@ -72,11 +77,6 @@ namespace pCampBot
/// </summary> /// </summary>
public Random Rng { get; private set; } public Random Rng { get; private set; }
/// <summary>
/// Overall configuration.
/// </summary>
public IConfig Config { get; private set; }
/// <summary> /// <summary>
/// Track the assets we have and have not received so we don't endlessly repeat requests. /// Track the assets we have and have not received so we don't endlessly repeat requests.
/// </summary> /// </summary>
@ -92,6 +92,8 @@ namespace pCampBot
/// </summary> /// </summary>
public BotManager() public BotManager()
{ {
BotsInitSendAgentUpdates = true;
LoginDelay = DefaultLoginDelay; LoginDelay = DefaultLoginDelay;
Rng = new Random(Environment.TickCount); Rng = new Random(Environment.TickCount);
@ -148,18 +150,17 @@ namespace pCampBot
/// </summary> /// </summary>
/// <param name="botcount">How many bots to start up</param> /// <param name="botcount">How many bots to start up</param>
/// <param name="cs">The configuration for the bots to use</param> /// <param name="cs">The configuration for the bots to use</param>
public void dobotStartup(int botcount, IConfig cs) public void dobotStartup(int botcount, IConfig startupConfig)
{ {
Config = cs; string firstName = startupConfig.GetString("firstname");
string lastNameStem = startupConfig.GetString("lastname");
string firstName = cs.GetString("firstname"); string password = startupConfig.GetString("password");
string lastNameStem = cs.GetString("lastname"); string loginUri = startupConfig.GetString("loginuri");
string password = cs.GetString("password"); string wearSetting = startupConfig.GetString("wear", "no");
string loginUri = cs.GetString("loginuri");
HashSet<string> behaviourSwitches = new HashSet<string>(); HashSet<string> behaviourSwitches = new HashSet<string>();
Array.ForEach<string>( Array.ForEach<string>(
cs.GetString("behaviours", "p").Split(new char[] { ',' }), b => behaviourSwitches.Add(b)); startupConfig.GetString("behaviours", "p").Split(new char[] { ',' }), b => behaviourSwitches.Add(b));
MainConsole.Instance.OutputFormat( MainConsole.Instance.OutputFormat(
"[BOT MANAGER]: Starting {0} bots connecting to {1}, named {2} {3}_<n>", "[BOT MANAGER]: Starting {0} bots connecting to {1}, named {2} {3}_<n>",
@ -169,6 +170,7 @@ namespace pCampBot
lastNameStem); lastNameStem);
MainConsole.Instance.OutputFormat("[BOT MANAGER]: Delay between logins is {0}ms", LoginDelay); MainConsole.Instance.OutputFormat("[BOT MANAGER]: Delay between logins is {0}ms", LoginDelay);
MainConsole.Instance.OutputFormat("[BOT MANAGER]: BotsSendAgentUpdates is {0}", BotsInitSendAgentUpdates);
for (int i = 0; i < botcount; i++) for (int i = 0; i < botcount; i++)
{ {
@ -193,7 +195,7 @@ namespace pCampBot
if (behaviourSwitches.Contains("t")) if (behaviourSwitches.Contains("t"))
behaviours.Add(new TeleportBehaviour()); behaviours.Add(new TeleportBehaviour());
StartBot(this, behaviours, firstName, lastName, password, loginUri); StartBot(this, behaviours, firstName, lastName, password, loginUri, wearSetting);
} }
} }
@ -226,15 +228,18 @@ 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>
/// <param name="wearSetting"></param>
public void StartBot( public void StartBot(
BotManager bm, List<IBehaviour> behaviours, BotManager bm, List<IBehaviour> behaviours,
string firstName, string lastName, string password, string loginUri) string firstName, string lastName, string password, string loginUri, string wearSetting)
{ {
MainConsole.Instance.OutputFormat( MainConsole.Instance.OutputFormat(
"[BOT MANAGER]: Starting bot {0} {1}, behaviours are {2}", "[BOT MANAGER]: Starting bot {0} {1}, behaviours are {2}",
firstName, lastName, string.Join(",", behaviours.ConvertAll<string>(b => b.Name).ToArray())); firstName, lastName, string.Join(",", behaviours.ConvertAll<string>(b => b.Name).ToArray()));
Bot pb = new Bot(bm, behaviours, firstName, lastName, password, loginUri); Bot pb = new Bot(bm, behaviours, firstName, lastName, password, loginUri);
pb.wear = wearSetting;
pb.Client.Settings.SEND_AGENT_UPDATES = BotsInitSendAgentUpdates;
pb.OnConnected += handlebotEvent; pb.OnConnected += handlebotEvent;
pb.OnDisconnected += handlebotEvent; pb.OnDisconnected += handlebotEvent;

View File

@ -26,6 +26,7 @@
*/ */
using System; using System;
using System.IO;
using System.Reflection; using System.Reflection;
using System.Threading; using System.Threading;
using log4net; using log4net;
@ -50,28 +51,50 @@ 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 const string ConfigFileName = "pCampbot.ini";
[STAThread] [STAThread]
public static void Main(string[] args) public static void Main(string[] args)
{ {
XmlConfigurator.Configure(); XmlConfigurator.Configure();
IConfig config = ParseConfig(args); IConfig commandLineConfig = ParseConfig(args);
if (config.Get("help") != null || config.Get("loginuri") == null) if (commandLineConfig.Get("help") != null || commandLineConfig.Get("loginuri") == null)
{ {
Help(); Help();
} }
else if (config.Get("firstname") == null || config.Get("lastname") == null || config.Get("password") == null) else if (
commandLineConfig.Get("firstname") == null
|| commandLineConfig.Get("lastname") == null
|| commandLineConfig.Get("password") == null)
{ {
Console.WriteLine("ERROR: You must supply a firstname, lastname and password for the bots."); Console.WriteLine("ERROR: You must supply a firstname, lastname and password for the bots.");
} }
else else
{ {
int botcount = config.GetInt("botcount", 1);
BotManager bm = new BotManager(); BotManager bm = new BotManager();
string iniFilePath = Path.GetFullPath(Path.Combine(Util.configDir(), ConfigFileName));
if (File.Exists(iniFilePath))
{
m_log.InfoFormat("[PCAMPBOT]: Reading configuration settings from {0}", iniFilePath);
IConfigSource configSource = new IniConfigSource(iniFilePath);
IConfig botConfig = configSource.Configs["Bot"];
if (botConfig != null)
{
bm.BotsInitSendAgentUpdates
= botConfig.GetBoolean("SendAgentUpdates", bm.BotsInitSendAgentUpdates);
}
}
int botcount = commandLineConfig.GetInt("botcount", 1);
//startup specified number of bots. 1 is the default //startup specified number of bots. 1 is the default
Thread startBotThread = new Thread(o => bm.dobotStartup(botcount, config)); Thread startBotThread = new Thread(o => bm.dobotStartup(botcount, commandLineConfig));
startBotThread.Name = "Initial start bots thread"; startBotThread.Name = "Initial start bots thread";
startBotThread.Start(); startBotThread.Start();

9
bin/pCampbot.ini.example Normal file
View File

@ -0,0 +1,9 @@
; This is the example config file for pCampbot
; To use it, copy this file to pCampbot.ini and change settings if required
[Bot]
; Control whether bots should regularly send agent updates
; Not sending agent updates will reduce CPU requirements for pCampbot but greatly
; reduce the realism compared to viewers which are constantly sending AgentUpdates UDP packets
; Defaults to true.
SendAgentUpdates = true