import binascii import itertools import proto from colordiff import Color, Diff d_c = Diff(Color.GREEN, Color.RED) d_s = Diff(Color.BLUE, Color.YELLOW) def handle3(tag: str, data: str): if data.startswith("0c") or data.startswith("0a"): if tag == "server": print(f"{Color.YELLOW}{data}{Color.RESET}") elif tag == "client": print(f"{Color.RED}{data}{Color.RESET}") else: if tag == "server": d_s.consume(data) elif tag == "client": d_c.consume(data) def handle2(tag: str, data: str): if tag == "stdin": # print(f"[stdin] {data}") return d_bytes = binascii.unhexlify(data) if d_bytes[0] not in (8, 9): return print(f"[{tag}] {data}") ignore = [ proto.AckPacket, proto.PingPacket, proto.FinPacket, ] def handle(tag: str, data: str): if tag == "stdin": print(f"{Color.GRAY}# {data}{Color.RESET}") return d_bytes = binascii.unhexlify(data) pkt = proto.Parser.parse_packet(d_bytes) for packet_type in ignore: if isinstance(pkt, packet_type): return print(f"[{Color.BLUE if tag == 'server' else Color.GREEN}{tag}{Color.RESET}] {pkt}")