Some DPI changes

This commit is contained in:
Casey 2023-08-28 17:42:35 +03:00
parent dad34f61ec
commit 36b2264471
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
4 changed files with 28 additions and 6 deletions

2
.gitignore vendored
View File

@ -3,4 +3,6 @@ __pycache__/
venv/ venv/
state state
packets.txt packets.txt
packets.txt.gz
packets*.txt packets*.txt
packets*.txt.gz

View File

@ -4,6 +4,7 @@ import time
from asyncio import get_event_loop from asyncio import get_event_loop
from typing import TextIO from typing import TextIO
from json import dumps from json import dumps
from gzip import open as open_gzip
from bta_proxy.datainputstream import AsyncDataInputStream from bta_proxy.datainputstream import AsyncDataInputStream
from bta_proxy.packets import * from bta_proxy.packets import *
@ -24,9 +25,11 @@ async def inspect_client(queue: Queue, addr: tuple[str, int]):
last_time = time.time() last_time = time.time()
f = open("packets-%s-%d-client.txt" % addr, "w") f = open_gzip("packets-%s-%d-client.txt.gz" % addr, "wt")
get_event_loop().create_task(queue_writer(queue, stream_queue, f)) get_event_loop().create_task(queue_writer(queue, stream_queue, f))
stats: dict[int, int] = {}
try: try:
while True: while True:
try: try:
@ -37,6 +40,8 @@ async def inspect_client(queue: Queue, addr: tuple[str, int]):
delta = now - last_time delta = now - last_time
last_time = now last_time = now
stats[pkt.packet_id] = stats.get(pkt.packet_id, 0) + 1
match pkt.packet_id: match pkt.packet_id:
case Packet10Flying.packet_id: case Packet10Flying.packet_id:
continue continue
@ -46,11 +51,14 @@ async def inspect_client(queue: Queue, addr: tuple[str, int]):
continue continue
case Packet13LookMove.packet_id: case Packet13LookMove.packet_id:
continue continue
case Packet255KickDisconnect.packet_id:
break
case _: case _:
print(f"C {delta*1000:+8.1f}ms {pkt}") print(f"C {delta*1000:+8.1f}ms {pkt}")
if pkt.packet_id == Packet255KickDisconnect.packet_id:
break
finally: finally:
print("[C] Closing output file")
for pkt_id, count in sorted(stats.items(), key=lambda kv: kv[1], reverse=True):
print(f"[C] {Packet.REGISTRY[pkt_id].__name__}: {count}")
f.close() f.close()
@ -60,9 +68,11 @@ async def inspect_server(queue: Queue, addr: tuple[str, int]):
last_time = time.time() last_time = time.time()
f = open("packets-%s-%d-server.txt" % addr, "w") f = open_gzip("packets-%s-%d-server.txt.gz" % addr, "wt")
get_event_loop().create_task(queue_writer(queue, stream_queue, f)) get_event_loop().create_task(queue_writer(queue, stream_queue, f))
stats: dict[int, int] = {}
try: try:
while True: while True:
try: try:
@ -73,11 +83,17 @@ async def inspect_server(queue: Queue, addr: tuple[str, int]):
delta = now - last_time delta = now - last_time
last_time = now last_time = now
stats[pkt.packet_id] = stats.get(pkt.packet_id, 0) + 1
match pkt.packet_id: match pkt.packet_id:
case Packet53BlockChange.packet_id:
continue
case Packet50PreChunk.packet_id: case Packet50PreChunk.packet_id:
continue continue
case Packet51MapChunk.packet_id: case Packet51MapChunk.packet_id:
continue continue
case Packet34EntityTeleport.packet_id:
continue
case Packet28EntityVelocity.packet_id: case Packet28EntityVelocity.packet_id:
continue continue
case Packet31RelEntityMove.packet_id: case Packet31RelEntityMove.packet_id:
@ -88,7 +104,12 @@ async def inspect_server(queue: Queue, addr: tuple[str, int]):
continue continue
case Packet73WeatherStatus.packet_id: case Packet73WeatherStatus.packet_id:
continue continue
case Packet52MultiBlockChange.packet_id:
continue
case _: case _:
print(f"S {delta*1000:+8.1f}ms {pkt}") print(f"S {delta*1000:+8.1f}ms {pkt}")
finally: finally:
print("[S] Closing output file")
for pkt_id, count in sorted(stats.items(), key=lambda kv: kv[1], reverse=True):
print(f"[S] {Packet.REGISTRY[pkt_id].__name__}: {count}")
f.close() f.close()

View File

@ -26,7 +26,6 @@ class EntityData:
async def read_from(cls, dis: AsyncDataInputStream) -> list[DataItem]: async def read_from(cls, dis: AsyncDataInputStream) -> list[DataItem]:
items = [] items = []
while (data := await dis.read()) != 0x7F: while (data := await dis.read()) != 0x7F:
print(f"========= EntityData.read_from {data=} ({(data & 0xE0) >> 5})")
item_type = DataItemType((data & 0xE0) >> 5) item_type = DataItemType((data & 0xE0) >> 5)
item_id: int = data & 0x1F item_id: int = data & 0x1F
match item_type: match item_type:

View File

@ -1,4 +1,3 @@
from asyncio.protocols import Protocol
from asyncio.queues import Queue from asyncio.queues import Queue
from asyncio import AbstractEventLoop, get_event_loop from asyncio import AbstractEventLoop, get_event_loop
from asyncio.streams import StreamReader, StreamWriter, open_connection from asyncio.streams import StreamReader, StreamWriter, open_connection
@ -21,6 +20,7 @@ class BTAProxy:
queue.put_nowait(packet) queue.put_nowait(packet)
writer.write(packet) writer.write(packet)
finally: finally:
queue.put_nowait(None)
writer.close() writer.close()
async def handle_client(self, cli_reader: StreamReader, cli_writer: StreamWriter): async def handle_client(self, cli_reader: StreamReader, cli_writer: StreamWriter):