ManInTheMiddleAmongUs/handler.py
2020-10-10 16:39:34 +02:00

22 lines
522 B
Python

import binascii
import itertools
from colordiff import Color, Diff
d_c = Diff(Color.GREEN, Color.RED)
d_s = Diff(Color.BLUE, Color.YELLOW)
def handle(tag: str, data: bytes):
msg = data.decode().strip()
if msg.startswith("0c") or msg.startswith("0a"):
if tag == "server":
print(f"{Color.YELLOW}{msg}{Color.RESET}")
else:
print(f"{Color.RED}{msg}{Color.RESET}")
else:
if tag == "server":
d_s.consume(msg)
else:
d_c.consume(msg)