bta-proxy/bta_proxy/dpi.py

85 lines
2.4 KiB
Python

from asyncio.queues import Queue
import time
from bta_proxy.datainputstream import AsyncDataInputStream
from bta_proxy.packets import *
async def inspect_client(queue: Queue, addr: tuple[str, int]):
dis = AsyncDataInputStream(queue)
last_time = time.time()
# f = open("packets-%s-%d-client.txt" % addr, "w")
f = None
try:
while True:
try:
pkt = await Packet.read_packet(dis)
except EOFError:
break
now = time.time()
delta = now - last_time
last_time = now
if f:
print(f"{delta*1000:+8.1f}ms {pkt}", file=f)
match pkt.packet_id:
case Packet10Flying.packet_id:
continue
case Packet11PlayerPosition.packet_id:
continue
case Packet12PlayerLook.packet_id:
continue
case Packet13LookMove.packet_id:
continue
case Packet255KickDisconnect.packet_id:
break
case _:
print(f"C {delta*1000:+8.1f}ms {pkt}")
finally:
if f:
f.close()
async def inspect_server(queue: Queue, addr: tuple[str, int]):
dis = AsyncDataInputStream(queue)
last_time = time.time()
# f = open("packets-%s-%d-server.txt" % addr, "w")
f = None
try:
while True:
try:
pkt = await Packet.read_packet(dis)
except EOFError:
break
now = time.time()
delta = now - last_time
last_time = now
if f:
print(f"{delta*1000:+8.1f}ms {pkt}", file=f)
match pkt.packet_id:
case Packet50PreChunk.packet_id:
continue
case Packet51MapChunk.packet_id:
continue
case Packet28EntityVelocity.packet_id:
continue
case Packet31RelEntityMove.packet_id:
continue
case Packet32EntityLook.packet_id:
continue
case Packet33RelEntityMoveLook.packet_id:
continue
case Packet73WeatherStatus.packet_id:
continue
case _:
print(f"S {delta*1000:+8.1f}ms {pkt}")
finally:
if f:
f.close()