public static void Parse(Packet packet)
{
var opcode = packet.GetOpcode();
var time = packet.GetTime();
var direction = packet.GetDirection();
var length = packet.GetLength();
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("{0}: {1} (0x{2}) Length: {3} Time: {4}", direction,
opcode, ((int)opcode).ToString("X4"), length, time);
Console.ForegroundColor = ConsoleColor.White;
var handlerFound = false;
if (Handlers.ContainsKey(opcode))
{
var handler = Handlers[opcode];
try
{
handlerFound = true;
handler(packet);
}
catch (Exception ex)
{
Console.WriteLine(ex.GetType());
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
}
else
Console.WriteLine(Utilities.DumpPacketAsHex(packet));
#if DEBUG
if (handlerFound && packet.GetPosition() < packet.GetLength())
{
Console.ForegroundColor = ConsoleColor.Red;
var pos = packet.GetPosition();
var len = packet.GetLength();
Console.WriteLine("Packet not fully read! Current position is {0}, length is {1}, and diff is {2}.",
pos, len, len - pos);
Console.ForegroundColor = ConsoleColor.White;
}
#endif
Console.ResetColor();
Console.WriteLine();
}