From d0f1962ae309591c3efadec596b027f261538cd7 Mon Sep 17 00:00:00 2001 From: hkc Date: Sun, 27 Aug 2023 14:47:44 +0300 Subject: [PATCH] Optional packet decode dump to file and +packet --- bta_proxy/dpi.py | 22 +++++++++++++++---- bta_proxy/packets/__init__.py | 1 + .../packets/packet105updateprogressbar.py | 9 ++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 bta_proxy/packets/packet105updateprogressbar.py diff --git a/bta_proxy/dpi.py b/bta_proxy/dpi.py index 554a650..3a7cdae 100644 --- a/bta_proxy/dpi.py +++ b/bta_proxy/dpi.py @@ -9,7 +9,10 @@ async def inspect_client(queue: Queue, addr: tuple[str, int]): dis = AsyncDataInputStream(queue) last_time = time.time() - with open("packets-%s-%d-client.txt" % addr, "w") as f: + # f = open("packets-%s-%d-client.txt" % addr, "w") + f = None + + try: while True: try: pkt = await Packet.read_packet(dis) @@ -19,7 +22,8 @@ async def inspect_client(queue: Queue, addr: tuple[str, int]): delta = now - last_time last_time = now - print(f"{delta*1000:+8.1f}ms {pkt}", file=f) + if f: + print(f"{delta*1000:+8.1f}ms {pkt}", file=f) match pkt.packet_id: case Packet10Flying.packet_id: @@ -34,12 +38,18 @@ async def inspect_client(queue: Queue, addr: tuple[str, int]): 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() - with open("packets-%s-%d-server.txt" % addr, "w") as f: + # f = open("packets-%s-%d-server.txt" % addr, "w") + f = None + + try: while True: try: pkt = await Packet.read_packet(dis) @@ -49,7 +59,8 @@ async def inspect_server(queue: Queue, addr: tuple[str, int]): delta = now - last_time last_time = now - print(f"{delta*1000:+8.1f}ms {pkt}", file=f) + if f: + print(f"{delta*1000:+8.1f}ms {pkt}", file=f) match pkt.packet_id: case Packet50PreChunk.packet_id: @@ -68,3 +79,6 @@ async def inspect_server(queue: Queue, addr: tuple[str, int]): continue case _: print(f"S {delta*1000:+8.1f}ms {pkt}") + finally: + if f: + f.close() diff --git a/bta_proxy/packets/__init__.py b/bta_proxy/packets/__init__.py index ca11702..4226831 100644 --- a/bta_proxy/packets/__init__.py +++ b/bta_proxy/packets/__init__.py @@ -74,3 +74,4 @@ from .packet134itemdata import Packet134ItemData from .packet137updateflag import Packet137UpdateFlag from .packet139setpaintingmotive import Packet139SetPaintingMotive from .packet141updateflag import Packet141UpdateFlag +from .packet105updateprogressbar import Packet105UpdateProgressbar diff --git a/bta_proxy/packets/packet105updateprogressbar.py b/bta_proxy/packets/packet105updateprogressbar.py new file mode 100644 index 0000000..7a01da9 --- /dev/null +++ b/bta_proxy/packets/packet105updateprogressbar.py @@ -0,0 +1,9 @@ +from .base import Packet + +class Packet105UpdateProgressbar(Packet, packet_id=105): + __slots__ = ('window_id', 'bar', 'value') + FIELDS = [ + ('window_id', 'ubyte'), + ('bar', 'short'), + ('value', 'short'), + ]