From 5933f9448d839b9f6db391dedc493bb5cc951d66 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 13 Aug 2013 23:54:50 +0100 Subject: [PATCH] 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 --- OpenSim/Tools/pCampBot/Bot.cs | 20 +--------------- OpenSim/Tools/pCampBot/BotManager.cs | 35 ++++++++++++++++------------ OpenSim/Tools/pCampBot/pCampBot.cs | 35 +++++++++++++++++++++++----- bin/pCampbot.ini.example | 9 +++++++ 4 files changed, 59 insertions(+), 40 deletions(-) create mode 100644 bin/pCampbot.ini.example diff --git a/OpenSim/Tools/pCampBot/Bot.cs b/OpenSim/Tools/pCampBot/Bot.cs index 9821180bc6..c56d29b975 100644 --- a/OpenSim/Tools/pCampBot/Bot.cs +++ b/OpenSim/Tools/pCampBot/Bot.cs @@ -63,11 +63,6 @@ namespace pCampBot /// public BotManager Manager { get; private set; } - /// - /// Bot config, passed from BotManager. - /// - private IConfig startupConfig; - /// /// Behaviours implemented by this bot. /// @@ -153,9 +148,6 @@ namespace pCampBot LoginUri = loginUri; Manager = bm; - startupConfig = bm.Config; - readconfig(); - Behaviours = behaviours; } @@ -176,14 +168,6 @@ namespace pCampBot ); } - /// - /// Read the Nini config and initialize - /// - public void readconfig() - { - wear = startupConfig.GetString("wear", "no"); - } - /// /// Tells LibSecondLife to logout and disconnect. Raises the disconnect events once it finishes. /// @@ -207,6 +191,7 @@ namespace pCampBot Client.Settings.AVATAR_TRACKING = false; Client.Settings.OBJECT_TRACKING = false; Client.Settings.SEND_AGENT_THROTTLE = true; + Client.Settings.SEND_AGENT_UPDATES = false; Client.Settings.SEND_PINGS = true; Client.Settings.STORE_LAND_PATCHES = false; Client.Settings.USE_ASSET_CACHE = false; @@ -481,9 +466,6 @@ namespace pCampBot public void Objects_NewPrim(object sender, PrimEventArgs args) { -// if (Name.EndsWith("4")) -// throw new Exception("Aaargh"); - Primitive prim = args.Prim; if (prim != null) diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs index 74bd36a9a9..16b02b9c1b 100644 --- a/OpenSim/Tools/pCampBot/BotManager.cs +++ b/OpenSim/Tools/pCampBot/BotManager.cs @@ -62,6 +62,11 @@ namespace pCampBot /// protected CommandConsole m_console; + /// + /// Controls whether bots start out sending agent updates on connection. + /// + public bool BotsInitSendAgentUpdates { get; set; } + /// /// Created bots, whether active or inactive. /// @@ -72,11 +77,6 @@ namespace pCampBot /// public Random Rng { get; private set; } - /// - /// Overall configuration. - /// - public IConfig Config { get; private set; } - /// /// Track the assets we have and have not received so we don't endlessly repeat requests. /// @@ -92,6 +92,8 @@ namespace pCampBot /// public BotManager() { + BotsInitSendAgentUpdates = true; + LoginDelay = DefaultLoginDelay; Rng = new Random(Environment.TickCount); @@ -148,18 +150,17 @@ namespace pCampBot /// /// How many bots to start up /// The configuration for the bots to use - public void dobotStartup(int botcount, IConfig cs) + public void dobotStartup(int botcount, IConfig startupConfig) { - Config = cs; - - string firstName = cs.GetString("firstname"); - string lastNameStem = cs.GetString("lastname"); - string password = cs.GetString("password"); - string loginUri = cs.GetString("loginuri"); + string firstName = startupConfig.GetString("firstname"); + string lastNameStem = startupConfig.GetString("lastname"); + string password = startupConfig.GetString("password"); + string loginUri = startupConfig.GetString("loginuri"); + string wearSetting = startupConfig.GetString("wear", "no"); HashSet behaviourSwitches = new HashSet(); Array.ForEach( - 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( "[BOT MANAGER]: Starting {0} bots connecting to {1}, named {2} {3}_", @@ -169,6 +170,7 @@ namespace pCampBot lastNameStem); 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++) { @@ -193,7 +195,7 @@ namespace pCampBot if (behaviourSwitches.Contains("t")) 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 /// Last name /// Password /// Login URI + /// public void StartBot( BotManager bm, List behaviours, - string firstName, string lastName, string password, string loginUri) + string firstName, string lastName, string password, string loginUri, string wearSetting) { MainConsole.Instance.OutputFormat( "[BOT MANAGER]: Starting bot {0} {1}, behaviours are {2}", firstName, lastName, string.Join(",", behaviours.ConvertAll(b => b.Name).ToArray())); Bot pb = new Bot(bm, behaviours, firstName, lastName, password, loginUri); + pb.wear = wearSetting; + pb.Client.Settings.SEND_AGENT_UPDATES = BotsInitSendAgentUpdates; pb.OnConnected += handlebotEvent; pb.OnDisconnected += handlebotEvent; diff --git a/OpenSim/Tools/pCampBot/pCampBot.cs b/OpenSim/Tools/pCampBot/pCampBot.cs index 2707a49f7d..e43037d9cb 100644 --- a/OpenSim/Tools/pCampBot/pCampBot.cs +++ b/OpenSim/Tools/pCampBot/pCampBot.cs @@ -26,6 +26,7 @@ */ using System; +using System.IO; using System.Reflection; using System.Threading; using log4net; @@ -50,28 +51,50 @@ namespace pCampBot { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + public const string ConfigFileName = "pCampbot.ini"; + [STAThread] public static void Main(string[] args) { XmlConfigurator.Configure(); - IConfig config = ParseConfig(args); - if (config.Get("help") != null || config.Get("loginuri") == null) + IConfig commandLineConfig = ParseConfig(args); + if (commandLineConfig.Get("help") != null || commandLineConfig.Get("loginuri") == null) { 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."); } else { - int botcount = config.GetInt("botcount", 1); - 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 - 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.Start(); diff --git a/bin/pCampbot.ini.example b/bin/pCampbot.ini.example new file mode 100644 index 0000000000..81cdcf4b1d --- /dev/null +++ b/bin/pCampbot.ini.example @@ -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