From e9f2a9bddbb47ac8c80aeccea0022ad534cbd552 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Wed, 23 Nov 2011 21:19:10 +0000 Subject: [PATCH] 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(-) diff --git a/OpenSim/Tools/pCampBot/Bot.cs b/OpenSim/Tools/pCampBot/Bot.cs index 7f941a497f..7c16bf4e97 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 056f991708..f372f9ba0d 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; } /// @@ -63,6 +63,11 @@ 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 /// @@ -70,6 +75,7 @@ namespace pCampBot { 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; + } + } + } } }