From e394f83df0d4af9f7efb826dbb49fe0eabedabdc Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 23 Nov 2011 18:00:41 +0000 Subject: Change random number generator property name in pCampbot --- OpenSim/Tools/pCampBot/BotManager.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'OpenSim/Tools/pCampBot') diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs index f5dd5e0..056f991 100644 --- a/OpenSim/Tools/pCampBot/BotManager.cs +++ b/OpenSim/Tools/pCampBot/BotManager.cs @@ -50,7 +50,12 @@ namespace pCampBot protected CommandConsole m_console; protected List m_lBot; - protected Random somthing = new Random(Environment.TickCount); + + /// + /// Random number generator. + /// + public Random Rng { get; private set; } + public IConfig Config { get; private set; } /// @@ -63,6 +68,7 @@ namespace pCampBot /// public BotManager() { + Rng = new Random(Environment.TickCount); AssetsReceived = new Dictionary(); m_console = CreateConsole(); -- cgit v1.1 From e9f2a9bddbb47ac8c80aeccea0022ad534cbd552 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 23 Nov 2011 21:19:10 +0000 Subject: get pCampBot to extract nearby and store nearby region information --- OpenSim/Tools/pCampBot/Bot.cs | 12 ++++++++ OpenSim/Tools/pCampBot/BotManager.cs | 54 +++++++++++++++++++++++++++++++++--- 2 files changed, 62 insertions(+), 4 deletions(-) (limited to 'OpenSim/Tools/pCampBot') diff --git a/OpenSim/Tools/pCampBot/Bot.cs b/OpenSim/Tools/pCampBot/Bot.cs index 7f941a4..7c16bf4 100644 --- a/OpenSim/Tools/pCampBot/Bot.cs +++ b/OpenSim/Tools/pCampBot/Bot.cs @@ -218,7 +218,19 @@ namespace pCampBot { MakeDefaultAppearance(wear); } + Client.Self.Jump(true); + + // Extract nearby region information. + Client.Grid.GridRegion += BotManager.Grid_GridRegion; + uint xUint, yUint; + Utils.LongToUInts(Client.Network.CurrentSim.Handle, out xUint, out yUint); + ushort minX, minY, maxX, maxY; + minX = (ushort)Math.Min(0, xUint - 5); + minY = (ushort)Math.Min(0, yUint - 5); + maxX = (ushort)(xUint + 5); + maxY = (ushort)(yUint + 5); + Client.Grid.RequestMapBlocks(GridLayerType.Terrain, minX, minY, maxX, maxY, false); } else { diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs index 056f991..f372f9b 100644 --- a/OpenSim/Tools/pCampBot/BotManager.cs +++ b/OpenSim/Tools/pCampBot/BotManager.cs @@ -55,7 +55,7 @@ namespace pCampBot /// Random number generator. /// public Random Rng { get; private set; } - + public IConfig Config { get; private set; } /// @@ -64,12 +64,18 @@ namespace pCampBot public Dictionary AssetsReceived { get; private set; } /// + /// The regions that we know about. + /// + public Dictionary RegionsKnown { get; private set; } + + /// /// Constructor Creates MainConsole.Instance to take commands and provide the place to write data /// public BotManager() { Rng = new Random(Environment.TickCount); AssetsReceived = new Dictionary(); + RegionsKnown = new Dictionary(); m_console = CreateConsole(); MainConsole.Instance = m_console; @@ -99,6 +105,11 @@ namespace pCampBot "Shutdown bots and exit", HandleShutdown); + m_console.Commands.AddCommand("bot", false, "show regions", + "show regions", + "Show regions known to bots", + HandleShowRegions); + m_console.Commands.AddCommand("bot", false, "show status", "show status", "Shows the status of all bots", @@ -246,17 +257,33 @@ namespace pCampBot }); } + private void HandleShowRegions(string module, string[] cmd) + { + string outputFormat = "{0,-30} {1, -20} {2, -5} {3, -5}"; + MainConsole.Instance.OutputFormat(outputFormat, "Name", "Handle", "X", "Y"); + + lock (RegionsKnown) + { + foreach (GridRegion region in RegionsKnown.Values) + { + MainConsole.Instance.OutputFormat( + outputFormat, region.Name, region.RegionHandle, region.X, region.Y); + } + } + } + private void HandleShowStatus(string module, string[] cmd) { - string outputFormat = "{0,-30} {1,-14}"; - MainConsole.Instance.OutputFormat(outputFormat, "Name", "Status"); + string outputFormat = "{0,-30} {1, -30} {2,-14}"; + MainConsole.Instance.OutputFormat(outputFormat, "Name", "Region", "Status"); lock (m_lBot) { foreach (Bot pb in m_lBot) { MainConsole.Instance.OutputFormat( - outputFormat, pb.Name, (pb.IsConnected ? "Connected" : "Disconnected")); + outputFormat, + pb.Name, pb.Client.Network.CurrentSim.Name, pb.IsConnected ? "Connected" : "Disconnected"); } } } @@ -280,5 +307,24 @@ namespace pCampBot // if (newbots > 0) // addbots(newbots); // } + + internal void Grid_GridRegion(object o, GridRegionEventArgs args) + { + lock (RegionsKnown) + { + GridRegion newRegion = args.Region; + + if (RegionsKnown.ContainsKey(newRegion.RegionHandle)) + { + return; + } + else + { + m_log.DebugFormat( + "[BOT MANAGER]: Adding {0} {1} to known regions", newRegion.Name, newRegion.RegionHandle); + RegionsKnown[newRegion.RegionHandle] = newRegion; + } + } + } } } -- cgit v1.1 From 9ae0641871418813ad4e9dd4591396e0b023140b Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 23 Nov 2011 21:33:10 +0000 Subject: Rename Bot.BotManager to Manager --- OpenSim/Tools/pCampBot/Bot.cs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'OpenSim/Tools/pCampBot') diff --git a/OpenSim/Tools/pCampBot/Bot.cs b/OpenSim/Tools/pCampBot/Bot.cs index 7c16bf4..7a73e3f 100644 --- a/OpenSim/Tools/pCampBot/Bot.cs +++ b/OpenSim/Tools/pCampBot/Bot.cs @@ -49,8 +49,15 @@ namespace pCampBot public delegate void AnEvent(Bot callbot, EventType someevent); // event delegate for bot events - public BotManager BotManager { get; private set; } - private IConfig startupConfig; // bot config, passed from BotManager + /// + /// Bot manager. + /// + public BotManager Manager { get; private set; } + + /// + /// Bot config, passed from BotManager. + /// + private IConfig startupConfig; /// /// Behaviours implemented by this bot. @@ -132,7 +139,7 @@ namespace pCampBot Password = password; LoginUri = loginUri; - BotManager = bm; + Manager = bm; startupConfig = bm.Config; readconfig(); @@ -222,7 +229,7 @@ namespace pCampBot Client.Self.Jump(true); // Extract nearby region information. - Client.Grid.GridRegion += BotManager.Grid_GridRegion; + Client.Grid.GridRegion += Manager.Grid_GridRegion; uint xUint, yUint; Utils.LongToUInts(Client.Network.CurrentSim.Handle, out xUint, out yUint); ushort minX, minY, maxX, maxY; @@ -484,13 +491,13 @@ namespace pCampBot private void GetTexture(UUID textureID) { - lock (BotManager.AssetsReceived) + lock (Manager.AssetsReceived) { // Don't request assets more than once. - if (BotManager.AssetsReceived.ContainsKey(textureID)) + if (Manager.AssetsReceived.ContainsKey(textureID)) return; - BotManager.AssetsReceived[textureID] = false; + Manager.AssetsReceived[textureID] = false; Client.Assets.RequestImage(textureID, ImageType.Normal, Asset_TextureCallback_Texture); } } @@ -502,8 +509,8 @@ namespace pCampBot public void Asset_ReceivedCallback(AssetDownload transfer, Asset asset) { - lock (BotManager.AssetsReceived) - BotManager.AssetsReceived[asset.AssetID] = true; + lock (Manager.AssetsReceived) + Manager.AssetsReceived[asset.AssetID] = true; // if (wear == "save") // { -- cgit v1.1 From 1126efdcd062c46e7e6212c86b692d11e570d8b3 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 23 Nov 2011 21:33:54 +0000 Subject: In pCampbot, change "show status" command to "show bots" --- OpenSim/Tools/pCampBot/BotManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'OpenSim/Tools/pCampBot') diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs index f372f9b..836d3f7 100644 --- a/OpenSim/Tools/pCampBot/BotManager.cs +++ b/OpenSim/Tools/pCampBot/BotManager.cs @@ -110,8 +110,8 @@ namespace pCampBot "Show regions known to bots", HandleShowRegions); - m_console.Commands.AddCommand("bot", false, "show status", - "show status", + m_console.Commands.AddCommand("bot", false, "show bots", + "show bots", "Shows the status of all bots", HandleShowStatus); -- cgit v1.1 From d145750e878c75e7d7a78eb9ef8dddaab81cc159 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 23 Nov 2011 22:05:11 +0000 Subject: Add teleport behaviour to pCampBot This teleports the bot to any other regions +/- 5 on the x or y axis. Quite aggressive at the moment since teleports keep occuring at a 1-10secs random interval. No checking yet to see if teleport was successful. --- .../Tools/pCampBot/Behaviours/TeleportBehaviour.cs | 73 ++++++++++++++++++++++ OpenSim/Tools/pCampBot/BotManager.cs | 3 + OpenSim/Tools/pCampBot/pCampBot.cs | 2 +- 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 OpenSim/Tools/pCampBot/Behaviours/TeleportBehaviour.cs (limited to 'OpenSim/Tools/pCampBot') diff --git a/OpenSim/Tools/pCampBot/Behaviours/TeleportBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/TeleportBehaviour.cs new file mode 100644 index 0000000..4624494 --- /dev/null +++ b/OpenSim/Tools/pCampBot/Behaviours/TeleportBehaviour.cs @@ -0,0 +1,73 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using log4net; +using OpenMetaverse; +using pCampBot.Interfaces; + +namespace pCampBot +{ + /// + /// Teleport to a random region on the grid. + /// + public class TeleportBehaviour : IBehaviour + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + public void Action(Bot bot) + { + Random rng = bot.Manager.Rng; + GridRegion[] knownRegions; + + lock (bot.Manager.RegionsKnown) + { + if (bot.Manager.RegionsKnown.Count == 0) + { + m_log.DebugFormat( + "[TELEPORT BEHAVIOUR]: Ignoring teleport action for {0} since no regions are known yet", bot.Name); + return; + } + + knownRegions = bot.Manager.RegionsKnown.Values.ToArray(); + } + + Simulator sourceRegion = bot.Client.Network.CurrentSim; + GridRegion destRegion = knownRegions[rng.Next(knownRegions.Length)]; + Vector3 destPosition = new Vector3(rng.Next(255), rng.Next(255), 50); + + m_log.DebugFormat( + "[TELEPORT BEHAVIOUR]: Teleporting {0} from {1} {2} to {3} {4}", + bot.Name, sourceRegion.Name, bot.Client.Self.SimPosition, destRegion.Name, destPosition); + + bot.Client.Self.Teleport(destRegion.RegionHandle, destPosition); + } + } +} \ No newline at end of file diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs index 836d3f7..c67b3e4 100644 --- a/OpenSim/Tools/pCampBot/BotManager.cs +++ b/OpenSim/Tools/pCampBot/BotManager.cs @@ -153,6 +153,9 @@ namespace pCampBot if (behaviourSwitches.Contains("g")) behaviours.Add(new GrabbingBehaviour()); + if (behaviourSwitches.Contains("t")) + behaviours.Add(new TeleportBehaviour()); + StartBot(this, behaviours, firstName, lastName, password, loginUri); } } diff --git a/OpenSim/Tools/pCampBot/pCampBot.cs b/OpenSim/Tools/pCampBot/pCampBot.cs index 4d3b06d..e7288d5 100644 --- a/OpenSim/Tools/pCampBot/pCampBot.cs +++ b/OpenSim/Tools/pCampBot/pCampBot.cs @@ -111,7 +111,7 @@ namespace pCampBot " -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" + - " -b, behaviours behaviours for bots. Current options p (physics), g (grab). Comma separated, e.g. p,g. Default is p", + " -b, behaviours behaviours for bots. Current options p (physics), g (grab), t (teleport). Comma separated, e.g. p,g. Default is p", " -wear set appearance folder to load from (default: no)\n" + " -h, -help show this message" ); -- cgit v1.1 From ed7ddeecf2df370638feb0a83b70a0883a711650 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 23 Nov 2011 22:18:10 +0000 Subject: Print out what behaviours are active when pCampBot starts up --- .../Tools/pCampBot/Behaviours/GrabbingBehaviour.cs | 2 ++ .../Tools/pCampBot/Behaviours/PhysicsBehaviour.cs | 2 ++ .../Tools/pCampBot/Behaviours/TeleportBehaviour.cs | 2 ++ OpenSim/Tools/pCampBot/BotManager.cs | 39 +++++++++++++++------- OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs | 9 +++++ 5 files changed, 42 insertions(+), 12 deletions(-) (limited to 'OpenSim/Tools/pCampBot') diff --git a/OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs index 7084ab4..0a6d5d2 100644 --- a/OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs +++ b/OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs @@ -41,6 +41,8 @@ namespace pCampBot /// public class GrabbingBehaviour : IBehaviour { + public string Name { get { return "Grabbing"; } } + public void Action(Bot bot) { Dictionary objects = bot.Objects; diff --git a/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs index 3ce08bf..f782bb5 100644 --- a/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs +++ b/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs @@ -42,6 +42,8 @@ namespace pCampBot /// public class PhysicsBehaviour : IBehaviour { + public string Name { get { return "Physics"; } } + private string[] talkarray; public PhysicsBehaviour() diff --git a/OpenSim/Tools/pCampBot/Behaviours/TeleportBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/TeleportBehaviour.cs index 4624494..fc2ed2c 100644 --- a/OpenSim/Tools/pCampBot/Behaviours/TeleportBehaviour.cs +++ b/OpenSim/Tools/pCampBot/Behaviours/TeleportBehaviour.cs @@ -42,6 +42,8 @@ namespace pCampBot { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + public string Name { get { return "Teleport"; } } + public void Action(Bot bot) { Random rng = bot.Manager.Rng; diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs index c67b3e4..29cb1ba 100644 --- a/OpenSim/Tools/pCampBot/BotManager.cs +++ b/OpenSim/Tools/pCampBot/BotManager.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Reflection; using System.Threading; using OpenMetaverse; @@ -48,7 +49,14 @@ namespace pCampBot { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + /// + /// Command console + /// protected CommandConsole m_console; + + /// + /// Created bots, whether active or inactive. + /// protected List m_lBot; /// @@ -56,6 +64,9 @@ namespace pCampBot /// public Random Rng { get; private set; } + /// + /// Overall configuration. + /// public IConfig Config { get; private set; } /// @@ -140,22 +151,26 @@ namespace pCampBot Array.ForEach( cs.GetString("behaviours", "p").Split(new char[] { ',' }), b => behaviourSwitches.Add(b)); + List behaviours = new List(); + + // Hard-coded for now + if (behaviourSwitches.Contains("p")) + behaviours.Add(new PhysicsBehaviour()); + + if (behaviourSwitches.Contains("g")) + behaviours.Add(new GrabbingBehaviour()); + + if (behaviourSwitches.Contains("t")) + behaviours.Add(new TeleportBehaviour()); + + MainConsole.Instance.OutputFormat( + "[BOT MANAGER]: Bots configured for behaviours {0}", + string.Join(",", behaviours.ConvertAll(b => b.Name).ToArray())); + for (int i = 0; i < botcount; i++) { string lastName = string.Format("{0}_{1}", lastNameStem, i); - List behaviours = new List(); - - // Hard-coded for now - if (behaviourSwitches.Contains("p")) - behaviours.Add(new PhysicsBehaviour()); - - if (behaviourSwitches.Contains("g")) - behaviours.Add(new GrabbingBehaviour()); - - if (behaviourSwitches.Contains("t")) - behaviours.Add(new TeleportBehaviour()); - StartBot(this, behaviours, firstName, lastName, password, loginUri); } } diff --git a/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs b/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs index d4ae0f0..912216f 100644 --- a/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs +++ b/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs @@ -31,6 +31,15 @@ namespace pCampBot.Interfaces { public interface IBehaviour { + /// + /// Name of this behaviour. + /// + string Name { get; } + + /// + /// Action to take when this behaviour is invoked. + /// + /// void Action(Bot bot); } } \ No newline at end of file -- cgit v1.1