I'm eepy sorry no commit message 4u
This commit is contained in:
parent
2667b14bed
commit
dad34f61ec
|
@ -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()
|
||||
|
||||
|
||||
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()
|
||||
|
|
|
@ -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}>'
|
||||
|
|
|
@ -79,3 +79,4 @@ from .packet142openflagwindow import Packet142OpenFlagWindow
|
|||
from .packet108sethotbaroffset import Packet108SetHotbarOffset
|
||||
from .packet5playerinventory import Packet5PlayerInventory
|
||||
from .packet5playerinventory import Packet5PlayerInventory
|
||||
from .packet5playerinventory import Packet5PlayerInventory
|
||||
|
|
|
@ -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')
|
||||
]
|
||||
|
|
|
@ -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'))
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue