Add chunk parsing tests

This commit is contained in:
ChillerDragon 2023-03-18 11:47:20 +01:00
parent a58ae3aaca
commit dd888341d3

View file

@ -0,0 +1,74 @@
from twnet_parser.packet import *
def test_parse_7_real_map_change():
packet = parse7(b'\x00\x01\x01\x58\xeb\x9a\xf4' \
b'\x40\x38\x01' \
b'\x05BlmapChill\x00' \
b'\xde\xcf\xaa\xee\x0b' \
b'\x8b\xbe\x8a\x01' \
b'\x08' \
b'\xa8\x15' \
b'\x81\x7d\xbf\x48\xc5\xf1\x94\x37\xc4\x58\x2c\x6f\x98\xc9\xc2\x04\xc1\xf1\x69\x76\x32\xf0\x44\x58\x74\x54\x55\x89\x84\x00\xfb\x28')
assert packet.version == '0.7'
assert packet.header.token == b'\x58\xeb\x9a\xf4'
assert packet.header.num_chunks == 1
assert packet.header.ack == 1
assert packet.header.flags.control == False
assert packet.header.flags.compression == False
# TODO: uncomment
# assert len(packet.messages) == 1
# assert packet.messages[0].name = 'map_change'
# Teeworlds 0.7 Protocol packet
# Flags: none (..00 00..)
# ..0. .... = Connection-oriented
# ...0 .... = Not compressed
# .... 0... = No resend requested
# .... .0.. = Not a control message
# Acknowledged sequence number: 1 (.... ..00 0000 0001)
# Number of chunks: 1
# Token: 58eb9af4
# Payload (59 bytes)
# Teeworlds 0.7 Protocol chunk: sys.map_change
# Header (vital: 1)
# Flags: vital (01.. ....)
# Size: 56 bytes (..00 0000 ..11 1000)
# Sequence number: 1 (00.. .... 0000 0001)
# Message: sys.map_change
# Name: "BlmapChill"
# Crc: -1592087519
# Size: 1134475
# Num response chunks per request: 8
# Chunk size: 1384
# Sha256: 817dbf48c5f19437c4582c6f98c9c204c1f1697632f04458745455898400fb28
def test_parse_7_real_multi_chunk_compressed():
# 0.7 motd, srv settings, ready
packet = parse7(b'\x10\x02\x03\x58\xeb\x9a\xf4\x4a\x42\x88\x4a\x6e\x16\xba\x31\x46\xa2\x84\x9e\xbf\xe2\x06')
# ^ ^ ^ ^ ^ ^ ^
# |ack=2 | \_____________/ \_________________________________________________________/
# | | | |
# | chunks=3 token huffman compressed
# | 3 chunks:
# compression=true game.sv_motd, game.sv_server_settings, sys.con_ready
assert packet.version == '0.7'
assert packet.header.token == b'\x58\xeb\x9a\xf4'
assert packet.header.num_chunks == 3
assert packet.header.ack == 2
assert packet.header.flags.compression == True
assert packet.header.flags.control == False
# TODO: uncomment
# assert len(packet.messages) == 3
# assert packet.messages[0].name == 'sv_motd'
# assert packet.messages[1].name == 'sv_server_settings'
# assert packet.messages[2].name == 'con_ready'