Add "debug lludp packet" command to pCampbot.

This allows one to log the packets received by a particular bot that are not duplicates of already received packets.
Similar to the OpenSimulator command at the same name but currently any positive level logs all received packets.
No facility yet for logging outgoing packets.
For debug purposes.
mb-throttle-test
Justin Clark-Casey (justincc) 2014-09-24 23:03:39 +01:00
parent c015cb3134
commit 6ac12a42ec
2 changed files with 81 additions and 0 deletions

View File

@ -35,6 +35,7 @@ using System.Timers;
using log4net; using log4net;
using OpenMetaverse; using OpenMetaverse;
using OpenMetaverse.Assets; using OpenMetaverse.Assets;
using OpenMetaverse.Packets;
using Nini.Config; using Nini.Config;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Framework.Console; using OpenSim.Framework.Console;
@ -56,6 +57,27 @@ namespace pCampBot
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public int PacketDebugLevel
{
get { return m_packetDebugLevel; }
set
{
if (value == m_packetDebugLevel)
return;
m_packetDebugLevel = value;
if (Client != null)
{
if (m_packetDebugLevel <= 0)
Client.Network.UnregisterCallback(PacketType.Default, PacketReceivedDebugHandler);
else
Client.Network.RegisterCallback(PacketType.Default, PacketReceivedDebugHandler, false);
}
}
}
private int m_packetDebugLevel;
public delegate void AnEvent(Bot callbot, EventType someevent); // event delegate for bot events public delegate void AnEvent(Bot callbot, EventType someevent); // event delegate for bot events
/// <summary> /// <summary>
@ -231,6 +253,9 @@ namespace pCampBot
if (Client != null) if (Client != null)
{ {
// Remove any registered debug handlers
Client.Network.UnregisterCallback(PacketType.Default, PacketReceivedDebugHandler);
newClient.Settings.LOGIN_SERVER = Client.Settings.LOGIN_SERVER; newClient.Settings.LOGIN_SERVER = Client.Settings.LOGIN_SERVER;
newClient.Settings.ALWAYS_DECODE_OBJECTS = Client.Settings.ALWAYS_DECODE_OBJECTS; newClient.Settings.ALWAYS_DECODE_OBJECTS = Client.Settings.ALWAYS_DECODE_OBJECTS;
newClient.Settings.AVATAR_TRACKING = Client.Settings.AVATAR_TRACKING; newClient.Settings.AVATAR_TRACKING = Client.Settings.AVATAR_TRACKING;
@ -273,6 +298,9 @@ namespace pCampBot
newClient.Network.Disconnected += Network_OnDisconnected; newClient.Network.Disconnected += Network_OnDisconnected;
newClient.Objects.ObjectUpdate += Objects_NewPrim; newClient.Objects.ObjectUpdate += Objects_NewPrim;
if (m_packetDebugLevel > 0)
newClient.Network.RegisterCallback(PacketType.Default, PacketReceivedDebugHandler);
Client = newClient; Client = newClient;
} }
@ -705,5 +733,16 @@ namespace pCampBot
// SaveAsset((AssetWearable) asset); // SaveAsset((AssetWearable) asset);
// } // }
} }
private void PacketReceivedDebugHandler(object o, PacketReceivedEventArgs args)
{
Packet p = args.Packet;
Header h = p.Header;
Simulator s = args.Simulator;
m_log.DebugFormat(
"[BOT]: Bot {0} received from {1} packet {2} #{3}, rel {4}, res {5}",
Name, s.Name, p.Type, h.Sequence, h.Reliable, h.Resent);
}
} }
} }

View File

@ -253,6 +253,16 @@ namespace pCampBot
"Bots", false, "show bot", "show bot <bot-number>", "Bots", false, "show bot", "show bot <bot-number>",
"Shows the detailed status and settings of a particular bot.", HandleShowBotStatus); "Shows the detailed status and settings of a particular bot.", HandleShowBotStatus);
m_console.Commands.AddCommand(
"Debug",
false,
"debug lludp packet",
"debug lludp packet <level> <avatar-first-name> <avatar-last-name>",
"Turn on received packet logging.",
"If level > 0 then all received packets that are not duplicates are logged.\n"
+ "If level <= 0 then no received packets are logged.",
HandleDebugLludpPacketCommand);
m_console.Commands.AddCommand( m_console.Commands.AddCommand(
"Bots", false, "show status", "show status", "Shows pCampbot status.", HandleShowStatus); "Bots", false, "show status", "show status", "Shows pCampbot status.", HandleShowStatus);
@ -784,6 +794,38 @@ namespace pCampBot
} }
} }
private void HandleDebugLludpPacketCommand(string module, string[] args)
{
if (args.Length != 6)
{
MainConsole.Instance.OutputFormat("Usage: debug lludp packet <level> <bot-first-name> <bot-last-name>");
return;
}
int level;
if (!ConsoleUtil.TryParseConsoleInt(MainConsole.Instance, args[3], out level))
return;
string botFirstName = args[4];
string botLastName = args[5];
Bot bot;
lock (m_bots)
bot = m_bots.FirstOrDefault(b => b.FirstName == botFirstName && b.LastName == botLastName);
if (bot == null)
{
MainConsole.Instance.OutputFormat("No bot named {0} {1}", botFirstName, botLastName);
return;
}
bot.PacketDebugLevel = level;
MainConsole.Instance.OutputFormat("Set debug level of {0} to {1}", bot.Name, bot.PacketDebugLevel);
}
private void HandleShowRegions(string module, string[] cmd) private void HandleShowRegions(string module, string[] cmd)
{ {
string outputFormat = "{0,-30} {1, -20} {2, -5} {3, -5}"; string outputFormat = "{0,-30} {1, -20} {2, -5} {3, -5}";