I'm eepy sorry no commit message 4u

This commit is contained in:
Casey 2023-08-28 01:51:35 +03:00
parent 2667b14bed
commit dad34f61ec
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
5 changed files with 36 additions and 20 deletions

View File

@ -1,16 +1,31 @@
from asyncio.queues import Queue
import time
from asyncio import get_event_loop
from typing import TextIO
from json import dumps
from bta_proxy.datainputstream import AsyncDataInputStream
from bta_proxy.packets import *
async def queue_writer(queue_in: Queue, queue_out: Queue, fp: TextIO):
packet: bytes
while (packet := await queue_in.get()) != b'':
fp.write(dumps({
"t": time.time(),
"s": len(packet),
"b": packet.hex()
}) + "\n")
queue_out.put_nowait(packet)
async def inspect_client(queue: Queue, addr: tuple[str, int]):
dis = AsyncDataInputStream(queue)
stream_queue = Queue()
dis = AsyncDataInputStream(stream_queue)
last_time = time.time()
# f = open("packets-%s-%d-client.txt" % addr, "w")
f = None
f = open("packets-%s-%d-client.txt" % addr, "w")
get_event_loop().create_task(queue_writer(queue, stream_queue, f))
try:
while True:
@ -22,9 +37,6 @@ async def inspect_client(queue: Queue, addr: tuple[str, int]):
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
@ -39,15 +51,17 @@ async def inspect_client(queue: Queue, addr: tuple[str, int]):
case _:
print(f"C {delta*1000:+8.1f}ms {pkt}")
finally:
if f:
f.close()
f.close()
async def inspect_server(queue: Queue, addr: tuple[str, int]):
dis = AsyncDataInputStream(queue)
stream_queue = Queue()
dis = AsyncDataInputStream(stream_queue)
last_time = time.time()
# f = open("packets-%s-%d-server.txt" % addr, "w")
f = None
f = open("packets-%s-%d-server.txt" % addr, "w")
get_event_loop().create_task(queue_writer(queue, stream_queue, f))
try:
while True:
@ -59,9 +73,6 @@ async def inspect_server(queue: Queue, addr: tuple[str, int]):
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
@ -80,5 +91,4 @@ async def inspect_server(queue: Queue, addr: tuple[str, int]):
case _:
print(f"S {delta*1000:+8.1f}ms {pkt}")
finally:
if f:
f.close()
f.close()

View File

@ -25,6 +25,9 @@ class ItemStack:
data = stream.read_ushort()
return cls(item_id, count, data)
def __bool__(self):
return self.item_id > 0 and self.count > 0
def __repr__(self):
if self.tag:
return f'<ItemStack! {self.item_id}:{self.data} x{self.count}>'

View File

@ -79,3 +79,4 @@ from .packet142openflagwindow import Packet142OpenFlagWindow
from .packet108sethotbaroffset import Packet108SetHotbarOffset
from .packet5playerinventory import Packet5PlayerInventory
from .packet5playerinventory import Packet5PlayerInventory
from .packet5playerinventory import Packet5PlayerInventory

View File

@ -5,7 +5,7 @@ class Packet102WindowClick(Packet, packet_id=102):
('window_id', 'byte'),
('action', 'byte'),
('size', 'byte'),
('args', ('bytes', 'size')),
('args', ('list', 'size', 'ubyte')),
('action_id', 'short'),
('item', 'itemstack_optional')
]

View File

@ -1,9 +1,11 @@
from .base import Packet
class Packet5PlayerInventory(Packet, packet_id=5):
__slots__ = ('entity_id', 'item', 'data')
__slots__ = ('entity_id', 'slot', 'item', 'data')
FIELDS = [
('entity_id', 'int'),
('item', 'itemstack'),
('data', 'nbt'),
('slot', 'short'),
('item', 'itemstack_optional'),
('size?item', 'short'),
('data?item', ('bytes', 'size'))
]