Fix parsing messages with ids higher than 31

See my thought process here
https://github.com/ChillerDragon/teeworlds-protocol/pull/15
This commit is contained in:
ChillerDragon 2023-04-07 16:10:56 +02:00
parent bd4353538a
commit 9615392156
2 changed files with 6 additions and 6 deletions

View file

@ -24,8 +24,7 @@ def test_parse_7_real_call_vote():
assert msg.message_name == 'cl_call_vote' assert msg.message_name == 'cl_call_vote'
# TODO: this fails because it somehow prefixes a leading space assert msg.type == 'option'
# assert msg.type == 'option'
assert msg.value == 'test' assert msg.value == 'test'
assert msg.reason == '' assert msg.reason == ''
assert msg.force == False assert msg.force == False

View file

@ -3,7 +3,7 @@
from typing import Union from typing import Union
from typing import cast from typing import cast
from twnet_parser import packer from twnet_parser.packer import Unpacker
from twnet_parser.pretty_print import PrettyPrint from twnet_parser.pretty_print import PrettyPrint
from twnet_parser.message_parser import MessageParser from twnet_parser.message_parser import MessageParser
from twnet_parser.net_message import NetMessage from twnet_parser.net_message import NetMessage
@ -134,15 +134,16 @@ class PacketParser():
i = 2 i = 2
if chunk_header.flags.vital: if chunk_header.flags.vital:
i += 1 i += 1
msg_id: int = packer.unpack_int(data[i:]) unpacker = Unpacker(data[i:])
msg_id: int = unpacker.get_int()
i += 1 i += 1
sys: bool = (msg_id & 1) == 1 sys: bool = (msg_id & 1) == 1
msg_id >>= 1 msg_id >>= 1
msg: NetMessage msg: NetMessage
if sys: if sys:
msg = MessageParser().parse_sys_message(msg_id, data[i:]) msg = MessageParser().parse_sys_message(msg_id, unpacker.get_raw())
else: else:
msg = MessageParser().parse_game_message(msg_id, data[i:]) msg = MessageParser().parse_game_message(msg_id, unpacker.get_raw())
msg.header = chunk_header msg.header = chunk_header
return msg return msg