private void Print(Packet packet, string direct) { byte[] packet_bytes = packet.GetBytes(); StringBuilder output = new StringBuilder(); output.AppendFormat("[" + direct + "][{0:X4}][{1} bytes]{2}{3}{4}{5}{6}", packet.Opcode, packet_bytes.Length, packet.Encrypted ? "[Encrypted]" : "", packet.Massive ? "[Massive]" : "", Environment.NewLine, Utility.HexDump(packet_bytes), Environment.NewLine); _mainForm.UpdateLog(output.ToString()); }
public void WritePacketLog(Packet pck, PacketDirection pckDir, RelaySessionState sessionState) { if (Global.EnablePacketLog && m_enable_file_output) { lock (m_class_lock) { //Format packet dump /* * Time * Packet direction / Opcode / encrypted / massive * RelaySessionState dump * Packet dump * */ string str = string.Format("[{0}]\r\n" + "[{1}, 0x{2:X}, {3}, {4}]\r\n" + "[RelaySessionState dump begin]\r\n" + "{5}" + "[RelaySessionState dump end]\r\n" + "{6}\r\n\r\n", DateTime.Now, pckDir, pck.Opcode, pck.Encrypted, pck.Massive, sessionState.Dump(), Utility.HexDump(pck.GetBytes()) ); WriteToPacketLogFile(str); } } }