/// <summary>
        /// Logs the packet received for this client.
        /// </summary>
        /// <remarks>
        /// This handler assumes that packets are processed one at a time.
        /// </remarks>
        /// <param name="sender">Sender.</param>
        /// <param name="args">Arguments.</param>
        private void HandlePacket(object sender, PacketReceivedEventArgs args)
        {
            //            Console.WriteLine(
            //                "Received packet {0} from {1} for {2}", args.Packet.Type, args.Simulator.Name, m_client.Self.Name);

            lock (this)
            {
                if (!m_isLogging)
                {
                    return;
                }

                m_logStreamWriter.WriteLine("Received: {0}", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.fff"));

                try
                {
                    m_logStreamWriter.WriteLine(PacketDecoder.PacketToString(args.Packet));
                }
                catch (Exception e)
                {
                    m_logStreamWriter.WriteLine("Failed to write decode of {0}, exception {1}", args.Packet.Type, e);
                }

                if (--m_packetsToLogRemaining <= 0)
                {
                    m_client.Network.UnregisterCallback(PacketType.Default, HandlePacket);
                    m_logStreamWriter.Close();
                    Console.WriteLine("Finished logging packets for {0}", m_client.Self.Name);
                    m_isLogging = false;
                }
            }
        }
Exemple #2
0
    // LogPacket: dump a packet to the console
    private void LogPacket(Packet packet, IPEndPoint endPoint, Direction direction)
    {
        //string packetText = DecodePacket.PacketToString(packet);
        string packetText = PacketDecoder.PacketToString(packet);

        if (logGrep == null || (logGrep != null && Regex.IsMatch(packetText, logGrep)))
        {
            string line = String.Format("{0}\n{1} {2,21} {3,5} {4}{5}{6}"
                                        , packet.Type
                                        , direction == Direction.Incoming ? "<--" : "-->"
                                        , endPoint
                                        , packet.Header.Sequence
                                        , InterpretOptions(packet.Header)
                                        , Environment.NewLine
                                        , packetText
                                        );

            Console.WriteLine(line);

            if (output != null)
            {
                output.WriteLine(line);
            }
        }
    }
 public override string ToRawString(Direction direction)
 {
     if (direction == this.Direction)
     {
         return(PacketDecoder.PacketToString(this.Packet));
     }
     else
     {
         return(String.Empty);
     }
 }