get pCampBot to extract nearby and store nearby region information

iar_mods
Justin Clark-Casey (justincc) 2011-11-23 21:19:10 +00:00
parent 617f139aac
commit e9f2a9bddb
2 changed files with 62 additions and 4 deletions

View File

@ -218,7 +218,19 @@ namespace pCampBot
{ {
MakeDefaultAppearance(wear); MakeDefaultAppearance(wear);
} }
Client.Self.Jump(true); 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 else
{ {

View File

@ -63,6 +63,11 @@ namespace pCampBot
/// </summary> /// </summary>
public Dictionary<UUID, bool> AssetsReceived { get; private set; } public Dictionary<UUID, bool> AssetsReceived { get; private set; }
/// <summary>
/// The regions that we know about.
/// </summary>
public Dictionary<ulong, GridRegion> RegionsKnown { get; private set; }
/// <summary> /// <summary>
/// Constructor Creates MainConsole.Instance to take commands and provide the place to write data /// Constructor Creates MainConsole.Instance to take commands and provide the place to write data
/// </summary> /// </summary>
@ -70,6 +75,7 @@ namespace pCampBot
{ {
Rng = new Random(Environment.TickCount); Rng = new Random(Environment.TickCount);
AssetsReceived = new Dictionary<UUID, bool>(); AssetsReceived = new Dictionary<UUID, bool>();
RegionsKnown = new Dictionary<ulong, GridRegion>();
m_console = CreateConsole(); m_console = CreateConsole();
MainConsole.Instance = m_console; MainConsole.Instance = m_console;
@ -99,6 +105,11 @@ namespace pCampBot
"Shutdown bots and exit", "Shutdown bots and exit",
HandleShutdown); 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", m_console.Commands.AddCommand("bot", false, "show status",
"show status", "show status",
"Shows the status of all bots", "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) private void HandleShowStatus(string module, string[] cmd)
{ {
string outputFormat = "{0,-30} {1,-14}"; string outputFormat = "{0,-30} {1, -30} {2,-14}";
MainConsole.Instance.OutputFormat(outputFormat, "Name", "Status"); MainConsole.Instance.OutputFormat(outputFormat, "Name", "Region", "Status");
lock (m_lBot) lock (m_lBot)
{ {
foreach (Bot pb in m_lBot) foreach (Bot pb in m_lBot)
{ {
MainConsole.Instance.OutputFormat( 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) // if (newbots > 0)
// addbots(newbots); // 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;
}
}
}
} }
} }