Optional packet decode dump to file and +packet

This commit is contained in:
Casey 2023-08-27 14:47:44 +03:00
parent 522814f574
commit d0f1962ae3
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
3 changed files with 28 additions and 4 deletions

View File

@ -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()

View File

@ -74,3 +74,4 @@ from .packet134itemdata import Packet134ItemData
from .packet137updateflag import Packet137UpdateFlag
from .packet139setpaintingmotive import Packet139SetPaintingMotive
from .packet141updateflag import Packet141UpdateFlag
from .packet105updateprogressbar import Packet105UpdateProgressbar

View File

@ -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'),
]