Travel <o/

This commit is contained in:
Emily 2021-04-25 17:39:47 +02:00
parent 59b30ed591
commit 4acb1adeb4
3 changed files with 22 additions and 12 deletions

View File

@ -75,8 +75,8 @@ class PlayerClient(BaseClient):
async def on_player_packet(self, packet: bytes):
bitstream = Bitstream(packet)
has_acks = bitstream.read(0x01)
if has_acks:
_, has_acks = bitstream.read(0x01)
if has_acks[0]:
logger.debug("Unfinished code hit; has_acks: True")
return
@ -86,28 +86,28 @@ class PlayerClient(BaseClient):
logger.debug("Internal packet were not handled")
async def handle_internal_packet(self, bitstream: Bitstream) -> bool:
if (len(bitstream.buffer) * 8) - bitstream.offset < 0x10:
if (bitstream.length * 8) - bitstream.offset < 0x10:
return False
message_number = bitstream.read(0x10)
reliability = bitstream.read(0x04)
isSplitPacket = bitstream.read(0x01)
_, message_number = bitstream.read(0x10)
_, reliability = bitstream.read(0x04)
_, is_split_packet = bitstream.read(0x01)
if isSplitPacket:
if is_split_packet[0]:
logger.warning("Skipping split packet")
return
# Something I dont understand yet
# TODO: ReadCompressed
bitstream.offset += 1
unknown = bitstream.read(0x01)
bit_length = bitstream.read(0x08)
_, unknown = bitstream.read(0x01)
_, bit_length = bitstream.read(0x08)
##
logger.debug("bit_length: %d" % bit_length)
logger.debug("bitstream: %s" % bitstream)
# TODO: ReadAlignedBytes
data = bitstream.read(bit_length)
_, data = bitstream.read(bit_length)
logger.debug("data: %s" % data)

View File

@ -2,7 +2,7 @@ import ctypes as c
from array import array
from typing import *
from typing import Tuple
import logging
logger = logging.getLogger(__name__)
@ -13,6 +13,14 @@ class Bitstream:
self._offset = 0
self._buffer = bytearray(data) # array("B", data)
@property
def offset(self) -> int:
return self._offset
@property
def length(self) -> int:
return len(self._buffer)
def _can_access_bits(self, bits_to_access: int) -> bool:
return self._offset + bits_to_access <= len(self._buffer) << 3

View File

@ -1,6 +1,8 @@
from ..shared import glob
from ..struct.server import ServerConfig
from typing import Tuple
import logging
logger = logging.getLogger(__name__)
@ -55,5 +57,5 @@ class StringCompressor:
def __init__(self):
pass
def decode_string(self, data: bytes) -> (str, int):
def decode_string(self, data: bytes) -> Tuple[str, int]:
pass