From d2b8281df9a651282639a4a2bdc80d558e950375 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Wed, 24 Sep 2014 23:03:39 +0100 Subject: [PATCH] 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. --- OpenSim/Tools/pCampBot/Bot.cs | 39 ++++++++++++++++++++++++++ OpenSim/Tools/pCampBot/BotManager.cs | 42 ++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/OpenSim/Tools/pCampBot/Bot.cs b/OpenSim/Tools/pCampBot/Bot.cs index 45a6682629..4f287339fd 100644 --- a/OpenSim/Tools/pCampBot/Bot.cs +++ b/OpenSim/Tools/pCampBot/Bot.cs @@ -35,6 +35,7 @@ using System.Timers; using log4net; using OpenMetaverse; using OpenMetaverse.Assets; +using OpenMetaverse.Packets; using Nini.Config; using OpenSim.Framework; using OpenSim.Framework.Console; @@ -56,6 +57,27 @@ namespace pCampBot { 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 /// @@ -231,6 +253,9 @@ namespace pCampBot if (Client != null) { + // Remove any registered debug handlers + Client.Network.UnregisterCallback(PacketType.Default, PacketReceivedDebugHandler); + newClient.Settings.LOGIN_SERVER = Client.Settings.LOGIN_SERVER; newClient.Settings.ALWAYS_DECODE_OBJECTS = Client.Settings.ALWAYS_DECODE_OBJECTS; newClient.Settings.AVATAR_TRACKING = Client.Settings.AVATAR_TRACKING; @@ -273,6 +298,9 @@ namespace pCampBot newClient.Network.Disconnected += Network_OnDisconnected; newClient.Objects.ObjectUpdate += Objects_NewPrim; + if (m_packetDebugLevel > 0) + newClient.Network.RegisterCallback(PacketType.Default, PacketReceivedDebugHandler); + Client = newClient; } @@ -705,5 +733,16 @@ namespace pCampBot // 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); + } } } diff --git a/OpenSim/Tools/pCampBot/BotManager.cs b/OpenSim/Tools/pCampBot/BotManager.cs index c7d8f05628..46094d6311 100644 --- a/OpenSim/Tools/pCampBot/BotManager.cs +++ b/OpenSim/Tools/pCampBot/BotManager.cs @@ -253,6 +253,16 @@ namespace pCampBot "Bots", false, "show bot", "show bot ", "Shows the detailed status and settings of a particular bot.", HandleShowBotStatus); + m_console.Commands.AddCommand( + "Debug", + false, + "debug lludp packet", + "debug lludp packet ", + "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( "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 "); + 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) { string outputFormat = "{0,-30} {1, -20} {2, -5} {3, -5}";