From e3f51df3c27c5bc74bc69789d18015c538220935 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 31 Oct 2011 21:33:25 +0000 Subject: Stop pCampbot from firing connected event twice, which results in double counting. --- OpenSim/Tools/pCampBot/BotManager.cs | 16 ++++++++-------- OpenSim/Tools/pCampBot/PhysicsBot.cs | 5 +++-- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'OpenSim/Tools/pCampBot') diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs index 614b350..c9d1446 100644 --- a/OpenSim/Tools/pCampBot/BotManager.cs +++ b/OpenSim/Tools/pCampBot/BotManager.cs @@ -81,16 +81,16 @@ namespace pCampBot m_console.Commands.AddCommand("bot", false, "shutdown", "shutdown", - "Gracefully shut down bots", HandleShutdown); + "Shutdown bots and exit", HandleShutdown); m_console.Commands.AddCommand("bot", false, "quit", "quit", - "Force quit (DANGEROUS, try shutdown first)", + "Shutdown bots and exit", HandleShutdown); - m_console.Commands.AddCommand("bot", false, "add bots", - "add bots ", - "Add more bots", HandleAddBots); +// m_console.Commands.AddCommand("bot", false, "add bots", +// "add bots ", +// "Add more bots", HandleAddBots); m_lBot = new List(); } @@ -177,14 +177,14 @@ 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 >1) + if (numbots <= 0) Environment.Exit(0); break; } diff --git a/OpenSim/Tools/pCampBot/PhysicsBot.cs b/OpenSim/Tools/pCampBot/PhysicsBot.cs index 5d4af31..de54836 100644 --- a/OpenSim/Tools/pCampBot/PhysicsBot.cs +++ b/OpenSim/Tools/pCampBot/PhysicsBot.cs @@ -165,7 +165,7 @@ namespace pCampBot m_action.AutoReset = false; m_action.Elapsed += new ElapsedEventHandler(m_action_Elapsed); m_action.Start(); - OnConnected(this, EventType.CONNECTED); +// OnConnected(this, EventType.CONNECTED); if (wear == "save") { client.Appearance.SetPreviousAppearance(); @@ -384,6 +384,7 @@ namespace pCampBot { client.Assets.RequestImage(prim.Textures.DefaultTexture.TextureID, ImageType.Normal, Asset_TextureCallback_Texture); } + for (int i = 0; i < prim.Textures.FaceTextures.Length; i++) { if (prim.Textures.FaceTextures[i] != null) @@ -392,10 +393,10 @@ namespace pCampBot { client.Assets.RequestImage(prim.Textures.FaceTextures[i].TextureID, ImageType.Normal, Asset_TextureCallback_Texture); } - } } } + if (prim.Sculpt.SculptTexture != UUID.Zero) { client.Assets.RequestImage(prim.Sculpt.SculptTexture, ImageType.Normal, Asset_TextureCallback_Texture); -- cgit v1.1 From b1647f6d045a4ec0559d0f49d09f17f6e4cf2930 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 31 Oct 2011 22:14:49 +0000 Subject: adjust pCampbot so it starts up bots with the name format " _" 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 --- OpenSim/Tools/pCampBot/BotManager.cs | 107 ++++++++++++++++------------------- OpenSim/Tools/pCampBot/PhysicsBot.cs | 45 +++++++++------ OpenSim/Tools/pCampBot/README.txt | 25 +++----- OpenSim/Tools/pCampBot/pCampBot.cs | 6 +- 4 files changed, 89 insertions(+), 94 deletions(-) (limited to 'OpenSim/Tools/pCampBot') diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs index c9d1446..0aaa226 100644 --- a/OpenSim/Tools/pCampBot/BotManager.cs +++ b/OpenSim/Tools/pCampBot/BotManager.cs @@ -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; /// /// Constructor Creates MainConsole.Instance to take commands and provide the place to write data @@ -102,72 +102,65 @@ namespace pCampBot /// The configuration for the bots to use 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); } } - /// - /// Add additional bots (and threads) to our bot pool - /// - /// How Many of them to add - 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); - } - } +// /// +// /// Add additional bots (and threads) to our bot pool +// /// +// /// How Many of them to add +// 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); +// } +// } /// /// This starts up the bot and stores the thread for the bot in the thread array /// /// The position in the thread array to stick the bot's thread /// Configuration of the bot - public void startupBot(int pos, IConfig cs) + /// First name + /// Last name + /// Password + /// Login URI + 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); } /// - /// Creates a random name for the bot - /// - /// - 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; - } - - /// /// High level connnected/disconnected events so we can keep track of our threads by proxy /// /// @@ -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); +// } } } diff --git a/OpenSim/Tools/pCampBot/PhysicsBot.cs b/OpenSim/Tools/pCampBot/PhysicsBot.cs index de54836..1531b27 100644 --- a/OpenSim/Tools/pCampBot/PhysicsBot.cs +++ b/OpenSim/Tools/pCampBot/PhysicsBot.cs @@ -45,10 +45,11 @@ namespace pCampBot public delegate void AnEvent(PhysicsBot callbot, EventType someevent); // event delegate for bot events public IConfig startupConfig; // bot config, passed from BotManager - public string firstname; - public string lastname; - public string password; - public string loginURI; + public string FirstName { get; private set; } + public string LastName { get; private set; } + public string Name { get; private set; } + public string Password { get; private set; } + public string LoginUri { get; private set; } public string saveDir; public string wear; @@ -60,16 +61,28 @@ namespace pCampBot protected Random somthing = new Random(Environment.TickCount);// We do stuff randomly here - //New instance of a SecondLife client + /// + /// New instance of a SecondLife client + /// public GridClient client = new GridClient(); protected string[] talkarray; + /// - /// + /// Constructor /// - /// nini config for the bot - public PhysicsBot(IConfig bsconfig) + /// + /// + /// + /// + /// + public PhysicsBot(IConfig bsconfig, string firstName, string lastName, string password, string loginUri) { + FirstName = firstName; + LastName = lastName; + Name = string.Format("{0} {1}", FirstName, LastName); + Password = password; + LoginUri = loginUri; startupConfig = bsconfig; readconfig(); talkarray = readexcuses(); @@ -116,10 +129,6 @@ namespace pCampBot /// public void readconfig() { - firstname = startupConfig.GetString("firstname", "random"); - lastname = startupConfig.GetString("lastname", "random"); - password = startupConfig.GetString("password", "12345"); - loginURI = startupConfig.GetString("loginuri"); wear = startupConfig.GetString("wear","no"); } @@ -136,7 +145,7 @@ namespace pCampBot /// public void startup() { - client.Settings.LOGIN_SERVER = loginURI; + client.Settings.LOGIN_SERVER = LoginUri; client.Settings.ALWAYS_DECODE_OBJECTS = false; client.Settings.AVATAR_TRACKING = false; client.Settings.OBJECT_TRACKING = false; @@ -153,10 +162,10 @@ namespace pCampBot client.Throttle.Total = 400000; client.Network.LoginProgress += this.Network_LoginProgress; client.Network.SimConnected += this.Network_SimConnected; - client.Network.Disconnected += this.Network_OnDisconnected; +// client.Network.Disconnected += this.Network_OnDisconnected; client.Objects.ObjectUpdate += Objects_NewPrim; //client.Assets.OnAssetReceived += Asset_ReceivedCallback; - if (client.Network.Login(firstname, lastname, password, "pCampBot", "Your name")) + if (client.Network.Login(FirstName, LastName, Password, "pCampBot", "Your name")) { if (OnConnected != null) { @@ -180,7 +189,9 @@ namespace pCampBot } else { - MainConsole.Instance.Output(firstname + " " + lastname + " Can't login: " + client.Network.LoginMessage); + MainConsole.Instance.OutputFormat( + "{0} {1} cannot login: {2}", FirstName, LastName, client.Network.LoginMessage); + if (OnDisconnected != null) { OnDisconnected(this, EventType.DISCONNECTED); @@ -190,7 +201,7 @@ namespace pCampBot public void SaveDefaultAppearance() { - saveDir = "MyAppearance/" + firstname + "_" + lastname; + saveDir = "MyAppearance/" + FirstName + "_" + LastName; if (!Directory.Exists(saveDir)) { Directory.CreateDirectory(saveDir); diff --git a/OpenSim/Tools/pCampBot/README.txt b/OpenSim/Tools/pCampBot/README.txt index 7ecbde1..c4fcf33 100644 --- a/OpenSim/Tools/pCampBot/README.txt +++ b/OpenSim/Tools/pCampBot/README.txt @@ -1,10 +1,13 @@ This is the PhysicsCamperbot libslBot tester. -This is designed to be run in standalone mode with authorize accounts -turned off as a way to stress test the simulator. It creates -clients that log in, randomly jump/walk around, and say excuses from +This is designed to stress test the simulator. It creates +clients that log in, randomly jump/walk around, and can say excuses from the BOFH. +Bots must have accounts already created. Each bot will have the same firstname and password +but their lastname will be appended with _ starting from 0. So if you have two bots called ima bot, their +first names will be ima_bot_0 and ima_bot_1. + *** WARNING *** Using this bot on a public grid could get you banned permanently, so just say No! to griefing! @@ -21,19 +24,8 @@ pCampBot.exe will end up in the regular opensim/bin folder ----- Running the bot ----- -windows: pCampBot.exe -botcount -loginuri -*nix: mono pCampBot.exe -botcount -loginuri - -The names it produces are random by default, however, you can specify -either a firstname or a lastname in the command line also. - -ex: pCampBot.exe -botcount -loginuri -lastname - -If you specify both a firstname *and* a lastname, you'll likely run -into trouble unless you're only running a single bot. In that case, -there's also a password option. - -pCampBot.exe -botcount 1 -loginuri http://somegrid.com:8002 -firstname SomeDude -lastname SomeDude -password GobbleDeGook +windows: pCampBot.exe -botcount -loginuri -firstname -lastname -password +*nix: mono pCampBot.exe -botcount -loginuri -firstname -lastname -password ----- Commands ----- @@ -41,4 +33,3 @@ The bot has console commands: help - lists the console commands and what they do shutdown - gracefully shuts down the bots quit - forcefully shuts things down leaving stuff unclean - addbots N - adds N number of random bots. (replace 'N' with a number) diff --git a/OpenSim/Tools/pCampBot/pCampBot.cs b/OpenSim/Tools/pCampBot/pCampBot.cs index 77110bf..a69fbf0 100644 --- a/OpenSim/Tools/pCampBot/pCampBot.cs +++ b/OpenSim/Tools/pCampBot/pCampBot.cs @@ -95,9 +95,9 @@ namespace pCampBot "Spawns a set of bots to test an OpenSim region\n\n" + " -l, -loginuri loginuri for sim to log into (required)\n" + " -n, -botcount number of bots to start (default: 1)\n" + - " -firstname first name for the bot(s) (default: random string)\n" + - " -lastname lastname for the bot(s) (default: random string)\n" + - " -password password for the bots(s) (default: random string)\n" + + " -firstname first name for the bots\n" + + " -lastname lastname for the bots. Each lastname will have _ appended, e.g. Ima Bot_0\n" + + " -password password for the bots\n" + " -wear set appearance folder to load from (default: no)\n" + " -h, -help show this message" ); -- cgit v1.1 From 43e07efbc843ba1edd0c0369c50da331b5a1b2d6 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 31 Oct 2011 22:27:12 +0000 Subject: Fix bot disconnection --- OpenSim/Tools/pCampBot/PhysicsBot.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Tools/pCampBot') diff --git a/OpenSim/Tools/pCampBot/PhysicsBot.cs b/OpenSim/Tools/pCampBot/PhysicsBot.cs index 1531b27..03c6f85 100644 --- a/OpenSim/Tools/pCampBot/PhysicsBot.cs +++ b/OpenSim/Tools/pCampBot/PhysicsBot.cs @@ -162,7 +162,7 @@ namespace pCampBot client.Throttle.Total = 400000; client.Network.LoginProgress += this.Network_LoginProgress; client.Network.SimConnected += this.Network_SimConnected; -// client.Network.Disconnected += this.Network_OnDisconnected; + client.Network.Disconnected += this.Network_OnDisconnected; client.Objects.ObjectUpdate += Objects_NewPrim; //client.Assets.OnAssetReceived += Asset_ReceivedCallback; if (client.Network.Login(FirstName, LastName, Password, "pCampBot", "Your name")) -- cgit v1.1 From d366a08ebbc861a9db8ab27dd7f375a349d297ff Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 31 Oct 2011 22:52:49 +0000 Subject: Stop individual bots attempting to download the same asset more than once --- OpenSim/Tools/pCampBot/PhysicsBot.cs | 50 ++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 14 deletions(-) (limited to 'OpenSim/Tools/pCampBot') diff --git a/OpenSim/Tools/pCampBot/PhysicsBot.cs b/OpenSim/Tools/pCampBot/PhysicsBot.cs index 03c6f85..0344a82 100644 --- a/OpenSim/Tools/pCampBot/PhysicsBot.cs +++ b/OpenSim/Tools/pCampBot/PhysicsBot.cs @@ -56,6 +56,11 @@ namespace pCampBot public event AnEvent OnConnected; public event AnEvent OnDisconnected; + /// + /// Track the assets we have and have not received so we don't endlessly repeat requests. + /// + public Dictionary AssetsReceived { get; private set; } + protected Timer m_action; // Action Timer protected List objectIDs = new List(); @@ -86,6 +91,8 @@ namespace pCampBot startupConfig = bsconfig; readconfig(); talkarray = readexcuses(); + + AssetsReceived = new Dictionary(); } //We do our actions here. This is where one would @@ -164,7 +171,7 @@ namespace pCampBot client.Network.SimConnected += this.Network_SimConnected; client.Network.Disconnected += this.Network_OnDisconnected; client.Objects.ObjectUpdate += Objects_NewPrim; - //client.Assets.OnAssetReceived += Asset_ReceivedCallback; + if (client.Network.Login(FirstName, LastName, Password, "pCampBot", "Your name")) { if (OnConnected != null) @@ -227,7 +234,7 @@ namespace pCampBot { if (asset.Decode()) { - File.WriteAllBytes(Path.Combine(saveDir, String.Format("{1}.{0}", + File.WriteAllBytes(Path.Combine(saveDir, String.Format("{1}.{0}", asset.AssetType.ToString().ToLower(), asset.WearableType)), asset.AssetData); } @@ -393,40 +400,55 @@ namespace pCampBot { if (prim.Textures.DefaultTexture.TextureID != UUID.Zero) { - client.Assets.RequestImage(prim.Textures.DefaultTexture.TextureID, ImageType.Normal, Asset_TextureCallback_Texture); + GetTexture(prim.Textures.DefaultTexture.TextureID); } for (int i = 0; i < prim.Textures.FaceTextures.Length; i++) { - if (prim.Textures.FaceTextures[i] != null) + UUID textureID = prim.Textures.FaceTextures[i].TextureID; + + if (textureID != null && textureID != UUID.Zero) { - if (prim.Textures.FaceTextures[i].TextureID != UUID.Zero) - { - client.Assets.RequestImage(prim.Textures.FaceTextures[i].TextureID, ImageType.Normal, Asset_TextureCallback_Texture); - } + GetTexture(textureID); } } } if (prim.Sculpt.SculptTexture != UUID.Zero) { - client.Assets.RequestImage(prim.Sculpt.SculptTexture, ImageType.Normal, Asset_TextureCallback_Texture); + GetTexture(prim.Sculpt.SculptTexture); } } } + private void GetTexture(UUID textureID) + { + lock (AssetsReceived) + { + // Don't request assets more than once. + if (AssetsReceived.ContainsKey(textureID)) + return; + + AssetsReceived[textureID] = false; + client.Assets.RequestImage(textureID, ImageType.Normal, Asset_TextureCallback_Texture); + } + } + public void Asset_TextureCallback_Texture(TextureRequestState state, AssetTexture assetTexture) { //TODO: Implement texture saving and applying } - public void Asset_ReceivedCallback(AssetDownload transfer,Asset asset) + public void Asset_ReceivedCallback(AssetDownload transfer, Asset asset) { - if (wear == "save") - { - SaveAsset((AssetWearable) asset); - } + lock (AssetsReceived) + AssetsReceived[asset.AssetID] = true; + +// if (wear == "save") +// { +// SaveAsset((AssetWearable) asset); +// } } public string[] readexcuses() -- cgit v1.1 From 210868a832439bb226dfcf153ca66563300dc2cf Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 31 Oct 2011 23:10:10 +0000 Subject: Remove OpenSim.TestSuite Hasn't been touched since 2009 and wasn't more than another copy of pCampBot --- OpenSim/Tools/pCampBot/BotManager.cs | 4 +++- OpenSim/Tools/pCampBot/PhysicsBot.cs | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'OpenSim/Tools/pCampBot') diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs index 0aaa226..a4b7f16 100644 --- a/OpenSim/Tools/pCampBot/BotManager.cs +++ b/OpenSim/Tools/pCampBot/BotManager.cs @@ -165,18 +165,20 @@ namespace pCampBot /// /// /// - public void handlebotEvent(PhysicsBot callbot, EventType eventt) + private void handlebotEvent(PhysicsBot callbot, EventType eventt) { switch (eventt) { case EventType.CONNECTED: m_log.Info("[" + callbot.FirstName + " " + callbot.LastName + "]: Connected"); numbots++; +// m_log.InfoFormat("NUMBOTS {0}", numbots); break; case EventType.DISCONNECTED: m_log.Info("[" + callbot.FirstName + " " + callbot.LastName + "]: Disconnected"); m_td[m_lBot.IndexOf(callbot)].Abort(); numbots--; +// m_log.InfoFormat("NUMBOTS {0}", numbots); if (numbots <= 0) Environment.Exit(0); break; diff --git a/OpenSim/Tools/pCampBot/PhysicsBot.cs b/OpenSim/Tools/pCampBot/PhysicsBot.cs index 0344a82..0c399e3 100644 --- a/OpenSim/Tools/pCampBot/PhysicsBot.cs +++ b/OpenSim/Tools/pCampBot/PhysicsBot.cs @@ -29,19 +29,23 @@ using System; using System.Collections.Generic; using System.Text; using System.IO; +using System.Reflection; using System.Threading; using System.Timers; +using log4net; using OpenMetaverse; using OpenMetaverse.Assets; using Nini.Config; using OpenSim.Framework; using OpenSim.Framework.Console; -using Timer=System.Timers.Timer; +using Timer = System.Timers.Timer; namespace pCampBot { public class PhysicsBot { + 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 IConfig startupConfig; // bot config, passed from BotManager @@ -384,6 +388,7 @@ namespace pCampBot public void Network_OnDisconnected(object sender, DisconnectedEventArgs args) { +// m_log.ErrorFormat("Fired Network_OnDisconnected"); if (OnDisconnected != null) { OnDisconnected(this, EventType.DISCONNECTED); -- cgit v1.1 From b951c7fb1e5a284a9bf95054cb168e64ebfe717d Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 31 Oct 2011 23:22:55 +0000 Subject: Make bots share a cache so that asset downloads attempts are only made once instead of once for each bot --- OpenSim/Tools/pCampBot/BotManager.cs | 15 +++++++++++---- OpenSim/Tools/pCampBot/PhysicsBot.cs | 29 +++++++++++++---------------- 2 files changed, 24 insertions(+), 20 deletions(-) (limited to 'OpenSim/Tools/pCampBot') diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs index a4b7f16..03bb820 100644 --- a/OpenSim/Tools/pCampBot/BotManager.cs +++ b/OpenSim/Tools/pCampBot/BotManager.cs @@ -53,13 +53,20 @@ namespace pCampBot protected bool m_verbose = true; protected Random somthing = new Random(Environment.TickCount); protected int numbots = 0; - private IConfig Config; + public IConfig Config { get; private set; } + + /// + /// Track the assets we have and have not received so we don't endlessly repeat requests. + /// + public Dictionary AssetsReceived { get; private set; } /// /// Constructor Creates MainConsole.Instance to take commands and provide the place to write data /// public BotManager() { + AssetsReceived = new Dictionary(); + m_console = CreateConsole(); MainConsole.Instance = m_console; @@ -113,7 +120,7 @@ namespace pCampBot for (int i = 0; i < botcount; 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 /// Last name /// Password /// Login URI - 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.OnDisconnected += handlebotEvent; diff --git a/OpenSim/Tools/pCampBot/PhysicsBot.cs b/OpenSim/Tools/pCampBot/PhysicsBot.cs index 0c399e3..2070bfd 100644 --- a/OpenSim/Tools/pCampBot/PhysicsBot.cs +++ b/OpenSim/Tools/pCampBot/PhysicsBot.cs @@ -47,7 +47,9 @@ namespace pCampBot 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 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 LastName { get; private set; } @@ -60,11 +62,6 @@ namespace pCampBot public event AnEvent OnConnected; public event AnEvent OnDisconnected; - /// - /// Track the assets we have and have not received so we don't endlessly repeat requests. - /// - public Dictionary AssetsReceived { get; private set; } - protected Timer m_action; // Action Timer protected List objectIDs = new List(); @@ -80,23 +77,23 @@ namespace pCampBot /// /// Constructor /// - /// + /// /// /// /// /// - 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; LastName = lastName; Name = string.Format("{0} {1}", FirstName, LastName); Password = password; LoginUri = loginUri; - startupConfig = bsconfig; + + BotManager = bm; + startupConfig = bm.Config; readconfig(); talkarray = readexcuses(); - - AssetsReceived = new Dictionary(); } //We do our actions here. This is where one would @@ -428,13 +425,13 @@ namespace pCampBot private void GetTexture(UUID textureID) { - lock (AssetsReceived) + lock (BotManager.AssetsReceived) { // Don't request assets more than once. - if (AssetsReceived.ContainsKey(textureID)) + if (BotManager.AssetsReceived.ContainsKey(textureID)) return; - AssetsReceived[textureID] = false; + BotManager.AssetsReceived[textureID] = false; client.Assets.RequestImage(textureID, ImageType.Normal, Asset_TextureCallback_Texture); } } @@ -447,8 +444,8 @@ namespace pCampBot public void Asset_ReceivedCallback(AssetDownload transfer, Asset asset) { - lock (AssetsReceived) - AssetsReceived[asset.AssetID] = true; + lock (BotManager.AssetsReceived) + BotManager.AssetsReceived[asset.AssetID] = true; // if (wear == "save") // { -- cgit v1.1 From 87ec8a4ecbafca79841117ba03cced0aa9f82193 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 1 Nov 2011 18:36:29 +0000 Subject: Retain a reference to an action thread rather than starting an infinite loop via a timer, so that we can actually abort the action thread on shutdown --- OpenSim/Tools/pCampBot/PhysicsBot.cs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'OpenSim/Tools/pCampBot') diff --git a/OpenSim/Tools/pCampBot/PhysicsBot.cs b/OpenSim/Tools/pCampBot/PhysicsBot.cs index 2070bfd..945697b 100644 --- a/OpenSim/Tools/pCampBot/PhysicsBot.cs +++ b/OpenSim/Tools/pCampBot/PhysicsBot.cs @@ -62,7 +62,11 @@ namespace pCampBot public event AnEvent OnConnected; public event AnEvent OnDisconnected; - protected Timer m_action; // Action Timer + /// + /// Keep a track of the continuously acting thread so that we can abort it. + /// + private Thread m_actionThread; + protected List objectIDs = new List(); protected Random somthing = new Random(Environment.TickCount);// We do stuff randomly here @@ -98,8 +102,7 @@ namespace pCampBot //We do our actions here. This is where one would //add additional steps and/or things the bot should do - - void m_action_Elapsed(object sender, ElapsedEventArgs e) + private void Action() { while (true) { @@ -145,6 +148,9 @@ namespace pCampBot /// public void shutdown() { + if (m_actionThread != null) + m_actionThread.Abort(); + client.Network.Logout(); } @@ -177,11 +183,10 @@ namespace pCampBot { if (OnConnected != null) { - m_action = new Timer(somthing.Next(1000, 10000)); - m_action.Enabled = true; - m_action.AutoReset = false; - m_action.Elapsed += new ElapsedEventHandler(m_action_Elapsed); - m_action.Start(); + Thread.Sleep(somthing.Next(1000, 10000)); + m_actionThread = new Thread(Action); + m_actionThread.Start(); + // OnConnected(this, EventType.CONNECTED); if (wear == "save") { @@ -386,6 +391,13 @@ namespace pCampBot public void Network_OnDisconnected(object sender, DisconnectedEventArgs args) { // m_log.ErrorFormat("Fired Network_OnDisconnected"); + + // Only pass on the disconnect message when we receive a SimShutdown type shutdown. We have to ignore + // the earlier ClientInitiated shutdown callback. +// if ( +// (args.Reason == NetworkManager.DisconnectType.SimShutdown +// || args.Reason == NetworkManager.DisconnectType.NetworkTimeout) +// && OnDisconnected != null) if (OnDisconnected != null) { OnDisconnected(this, EventType.DISCONNECTED); -- cgit v1.1 From 12bd0ebd3416a60faeec77bfcd3cb48c33ed5cce Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 1 Nov 2011 21:15:47 +0000 Subject: stop recording the threads on which we happen to start bots. These are pointless since they terminate quickly --- OpenSim/Tools/pCampBot/BotManager.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'OpenSim/Tools/pCampBot') diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs index 03bb820..bfb664f 100644 --- a/OpenSim/Tools/pCampBot/BotManager.cs +++ b/OpenSim/Tools/pCampBot/BotManager.cs @@ -49,7 +49,6 @@ namespace pCampBot protected CommandConsole m_console; protected List m_lBot; - protected Thread[] m_td; protected bool m_verbose = true; protected Random somthing = new Random(Environment.TickCount); protected int numbots = 0; @@ -110,7 +109,6 @@ namespace pCampBot public void dobotStartup(int botcount, IConfig cs) { Config = cs; - m_td = new Thread[botcount]; string firstName = cs.GetString("firstname"); string lastNameStem = cs.GetString("lastname"); @@ -160,11 +158,12 @@ namespace pCampBot pb.OnConnected += handlebotEvent; pb.OnDisconnected += handlebotEvent; - m_td[pos] = new Thread(pb.startup); - m_td[pos].Name = pb.Name; - m_td[pos].IsBackground = true; - m_td[pos].Start(); m_lBot.Add(pb); + + Thread pbThread = new Thread(pb.startup); + pbThread.Name = pb.Name; + pbThread.IsBackground = true; + pbThread.Start(); } /// @@ -183,7 +182,6 @@ namespace pCampBot break; case EventType.DISCONNECTED: m_log.Info("[" + callbot.FirstName + " " + callbot.LastName + "]: Disconnected"); - m_td[m_lBot.IndexOf(callbot)].Abort(); numbots--; // m_log.InfoFormat("NUMBOTS {0}", numbots); if (numbots <= 0) -- cgit v1.1 From 53f3b76a84e6fb90b1f197977054a16ec86ccc7f Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 1 Nov 2011 21:18:28 +0000 Subject: get rid of unused m_verbose field --- OpenSim/Tools/pCampBot/BotManager.cs | 1 - 1 file changed, 1 deletion(-) (limited to 'OpenSim/Tools/pCampBot') diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs index bfb664f..d2b7ded 100644 --- a/OpenSim/Tools/pCampBot/BotManager.cs +++ b/OpenSim/Tools/pCampBot/BotManager.cs @@ -49,7 +49,6 @@ namespace pCampBot protected CommandConsole m_console; protected List m_lBot; - protected bool m_verbose = true; protected Random somthing = new Random(Environment.TickCount); protected int numbots = 0; public IConfig Config { get; private set; } -- cgit v1.1 From 40750b44a09c9970497657c3a847af2d92c8b385 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 1 Nov 2011 21:47:14 +0000 Subject: Listen only for non SimShutdown Network.Disconnect firing so that we don't quite the program before all bots have actually logged off. --- OpenSim/Tools/pCampBot/PhysicsBot.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'OpenSim/Tools/pCampBot') diff --git a/OpenSim/Tools/pCampBot/PhysicsBot.cs b/OpenSim/Tools/pCampBot/PhysicsBot.cs index 945697b..5bcd35d 100644 --- a/OpenSim/Tools/pCampBot/PhysicsBot.cs +++ b/OpenSim/Tools/pCampBot/PhysicsBot.cs @@ -398,7 +398,13 @@ namespace pCampBot // (args.Reason == NetworkManager.DisconnectType.SimShutdown // || args.Reason == NetworkManager.DisconnectType.NetworkTimeout) // && OnDisconnected != null) - if (OnDisconnected != null) + + if ( + (args.Reason == NetworkManager.DisconnectType.ClientInitiated + || args.Reason == NetworkManager.DisconnectType.ServerInitiated + || args.Reason == NetworkManager.DisconnectType.NetworkTimeout) + && OnDisconnected != null) +// if (OnDisconnected != null) { OnDisconnected(this, EventType.DISCONNECTED); } -- cgit v1.1 From 8e2e4c47d95728ba25694a85454488074360445e Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 1 Nov 2011 22:09:21 +0000 Subject: Add "show status" command to pCambot --- OpenSim/Tools/pCampBot/BotManager.cs | 30 ++++++++++++++++++++++++----- OpenSim/Tools/pCampBot/PhysicsBot.cs | 37 +++++++++++++++++++----------------- 2 files changed, 45 insertions(+), 22 deletions(-) (limited to 'OpenSim/Tools/pCampBot') diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs index d2b7ded..b05bd6d 100644 --- a/OpenSim/Tools/pCampBot/BotManager.cs +++ b/OpenSim/Tools/pCampBot/BotManager.cs @@ -93,6 +93,11 @@ namespace pCampBot "Shutdown bots and exit", HandleShutdown); + m_console.Commands.AddCommand("bot", false, "show status", + "show status", + "Shows the status of all bots", + HandleShowStatus); + // m_console.Commands.AddCommand("bot", false, "add bots", // "add bots ", // "Add more bots", HandleAddBots); @@ -157,7 +162,8 @@ namespace pCampBot pb.OnConnected += handlebotEvent; pb.OnDisconnected += handlebotEvent; - m_lBot.Add(pb); + lock (m_lBot) + m_lBot.Add(pb); Thread pbThread = new Thread(pb.startup); pbThread.Name = pb.Name; @@ -194,10 +200,9 @@ namespace pCampBot /// public void doBotShutdown() { - foreach (PhysicsBot pb in m_lBot) - { - pb.shutdown(); - } + lock (m_lBot) + foreach (PhysicsBot pb in m_lBot) + pb.shutdown(); } /// @@ -215,6 +220,21 @@ namespace pCampBot doBotShutdown(); } + private void HandleShowStatus(string module, string[] cmd) + { + string outputFormat = "{0,-30} {1,-14}"; + MainConsole.Instance.OutputFormat(outputFormat, "Name", "Status"); + + lock (m_lBot) + { + foreach (PhysicsBot pb in m_lBot) + { + MainConsole.Instance.OutputFormat( + outputFormat, pb.Name, (pb.IsConnected ? "Connected" : "Disconnected")); + } + } + } + /* private void HandleQuit(string module, string[] cmd) { diff --git a/OpenSim/Tools/pCampBot/PhysicsBot.cs b/OpenSim/Tools/pCampBot/PhysicsBot.cs index 5bcd35d..14e9cca 100644 --- a/OpenSim/Tools/pCampBot/PhysicsBot.cs +++ b/OpenSim/Tools/pCampBot/PhysicsBot.cs @@ -51,6 +51,11 @@ namespace pCampBot public BotManager BotManager { get; private set; } private IConfig startupConfig; // bot config, passed from BotManager + /// + /// Is this bot connected to the grid? + /// + public bool IsConnected { get; private set; } + public string FirstName { get; private set; } public string LastName { get; private set; } public string Name { get; private set; } @@ -181,24 +186,23 @@ namespace pCampBot if (client.Network.Login(FirstName, LastName, Password, "pCampBot", "Your name")) { - if (OnConnected != null) - { - Thread.Sleep(somthing.Next(1000, 10000)); - m_actionThread = new Thread(Action); - m_actionThread.Start(); + IsConnected = true; + + Thread.Sleep(somthing.Next(1000, 10000)); + m_actionThread = new Thread(Action); + m_actionThread.Start(); // OnConnected(this, EventType.CONNECTED); - if (wear == "save") - { - client.Appearance.SetPreviousAppearance(); - SaveDefaultAppearance(); - } - else if (wear != "no") - { - MakeDefaultAppearance(wear); - } - client.Self.Jump(true); + if (wear == "save") + { + client.Appearance.SetPreviousAppearance(); + SaveDefaultAppearance(); } + else if (wear != "no") + { + MakeDefaultAppearance(wear); + } + client.Self.Jump(true); } else { @@ -392,8 +396,6 @@ namespace pCampBot { // m_log.ErrorFormat("Fired Network_OnDisconnected"); - // Only pass on the disconnect message when we receive a SimShutdown type shutdown. We have to ignore - // the earlier ClientInitiated shutdown callback. // if ( // (args.Reason == NetworkManager.DisconnectType.SimShutdown // || args.Reason == NetworkManager.DisconnectType.NetworkTimeout) @@ -406,6 +408,7 @@ namespace pCampBot && OnDisconnected != null) // if (OnDisconnected != null) { + IsConnected = false; OnDisconnected(this, EventType.DISCONNECTED); } } -- cgit v1.1 From 9456a540c50b90d2c2cdb1b556e9d6190f817426 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 1 Nov 2011 23:23:45 +0000 Subject: Add "appearance send" command to allow manual sending of appearance. --- OpenSim/Tools/pCampBot/PhysicsBot.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim/Tools/pCampBot') diff --git a/OpenSim/Tools/pCampBot/PhysicsBot.cs b/OpenSim/Tools/pCampBot/PhysicsBot.cs index 14e9cca..a8b2426 100644 --- a/OpenSim/Tools/pCampBot/PhysicsBot.cs +++ b/OpenSim/Tools/pCampBot/PhysicsBot.cs @@ -124,11 +124,11 @@ namespace pCampBot } // TODO: unused: Vector3 pos = client.Self.SimPosition; - Vector3 newpos = new Vector3(somthing.Next(255), somthing.Next(255), somthing.Next(255)); + Vector3 newpos = new Vector3(somthing.Next(1, 254), somthing.Next(1, 254), somthing.Next(1, 254)); client.Self.Movement.TurnToward(newpos); client.Self.Movement.AtPos = true; - Thread.Sleep(somthing.Next(3000,13000)); + Thread.Sleep(somthing.Next(3000, 13000)); client.Self.Movement.AtPos = false; client.Self.Jump(true); -- cgit v1.1