feat: mark all msg 0 as ddnet_uuid for now
This will change as soon as ddnet uuids are properly implemented
This commit is contained in:
parent
936786901a
commit
cd7ec74bba
|
@ -513,6 +513,7 @@ from typing import Optional
|
|||
|
||||
import twnet_parser.msg{self.protocol_version}
|
||||
from twnet_parser.net_message import NetMessage
|
||||
from twnet_parser.ddnet_uuid import MsgDDNetUuid
|
||||
|
||||
"""
|
||||
|
||||
|
@ -538,12 +539,18 @@ def match_{msg_type}{self.protocol_version}(msg_id: int, data: bytes) -> NetMess
|
|||
msg = {msg_type}{self.protocol_version}_{name_snake}.Msg{name_camel}()"""
|
||||
if_ = 'elif'
|
||||
|
||||
match_code += '\n\n if msg is None:\n'
|
||||
match_code += ' '
|
||||
match_code += '\n'
|
||||
match_code += '\n # msg_id 0 is used by ddnet uuid messages'
|
||||
match_code += '\n # do not crash on those'
|
||||
match_code += '\n '
|
||||
match_code += 'if msg is None:\n'
|
||||
match_code += ' if msg_id != 0:\n'
|
||||
match_code += ' '
|
||||
match_code += 'raise ValueError('
|
||||
match_code += 'f"Error: unknown ' \
|
||||
+ msg_type + \
|
||||
' message id={msg_id} data={data[0]}")\n'
|
||||
match_code += ' msg = MsgDDNetUuid()\n'
|
||||
match_code += '\n'
|
||||
match_code += ' msg.unpack(data)\n'
|
||||
match_code += ' return msg\n'
|
||||
|
|
46
tests/packets7/ddnet_uuid_test.py
Normal file
46
tests/packets7/ddnet_uuid_test.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
from twnet_parser.packet import parse7
|
||||
|
||||
def test_parse_7_real_ddnet_07_bridge_packet():
|
||||
data = b'\x00\x01\x04\xff\xaa\xbb\xee' \
|
||||
b'\x40\x12\x01\x01\x12\x81\x0e\x1f\xa1\xdb\x33\x78\xb4\xfb\x16' \
|
||||
b'\x4e\xd6\x50\x59\x26\x00\x40\x13\x02\x01\xf6\x21\xa5\xa1\xf5\x85' \
|
||||
b'\x37\x75\x8e\x73\x41\xbe\xee\x79\xf2\xb2\x05\x3f\x41\x02\x03\x01' \
|
||||
b'\xf9\x11\x7b\x3c\x80\x39\x34\x16\x9f\xc0\xae\xf2\xbc\xb7\x5c\x03' \
|
||||
b'\x73\x75\x72\x76\x69\x76\x61\x6c\x00\xd8\x00\x26\xb9\x48\x92\xbe' \
|
||||
b'\x2e\xed\xef\xa7\x41\x13\xe2\x70\x7a\x5b\x87\xd6\xaa\x71\x27\xee' \
|
||||
b'\xc6\x49\xcc\xa7\xe8\xe8\x8b\xa1\x0a\x8a\xf7\xa0\x6b\x9c\x9d\x17' \
|
||||
b'\x00\x40\x34\x04\x05\x73\x75\x72\x76\x69\x76\x61\x6c\x00\x8a\xf7' \
|
||||
b'\xa0\x6b\x9c\x9d\x17\x0f\x80\x0e\xd8\x00\x26\xb9\x48\x92\xbe\x2e' \
|
||||
b'\xed\xef\xa7\x41\x13\xe2\x70\x7a\x5b\x87\xd6\xaa\x71\x27\xee\xc6' \
|
||||
b'\x49\xcc\xa7\xe8\xe8\x8b\xa1\x0a'
|
||||
packet = parse7(data)
|
||||
|
||||
# Teeworlds 0.7 Protocol chunk: sys.12810e1f-a1db-3378-b4fb-164ed6505926
|
||||
# Teeworlds 0.7 Protocol chunk: sys.f621a5a1-f585-3775-8e73-41beee79f2b2
|
||||
# Teeworlds 0.7 Protocol chunk: sys.f9117b3c-8039-3416-9fc0-aef2bcb75c03
|
||||
# Teeworlds 0.7 Protocol chunk: sys.map_change
|
||||
|
||||
assert packet.version == '0.7'
|
||||
|
||||
assert packet.header.token == b'\xff\xaa\xbb\xee'
|
||||
assert packet.header.num_chunks == 4
|
||||
assert packet.header.ack == 1
|
||||
|
||||
assert packet.header.flags.control is False
|
||||
assert packet.header.flags.compression is False
|
||||
assert packet.header.flags.resend is False
|
||||
assert packet.header.flags.connless is False
|
||||
|
||||
assert len(packet.messages) == 4
|
||||
|
||||
msg = packet.messages[0]
|
||||
assert msg.message_name == 'ddnet_uuid'
|
||||
msg = packet.messages[1]
|
||||
assert msg.message_name == 'ddnet_uuid'
|
||||
msg = packet.messages[2]
|
||||
assert msg.message_name == 'ddnet_uuid'
|
||||
|
||||
msg = packet.messages[3]
|
||||
assert msg.system_message is True
|
||||
assert msg.message_name == 'map_change'
|
||||
|
28
twnet_parser/ddnet_uuid.py
Normal file
28
twnet_parser/ddnet_uuid.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
from typing import Literal
|
||||
|
||||
from twnet_parser.pretty_print import PrettyPrint
|
||||
from twnet_parser.chunk_header import ChunkHeader
|
||||
|
||||
class MsgDDNetUuid(PrettyPrint):
|
||||
def __init__(
|
||||
self,
|
||||
chunk_header: ChunkHeader = ChunkHeader(),
|
||||
payload: bytes = b''
|
||||
) -> None:
|
||||
self.message_type: Literal['system', 'game'] = 'system'
|
||||
self.message_name: str = 'ddnet_uuid'
|
||||
self.system_message: bool = True
|
||||
self.message_id: int = 0
|
||||
self.header: ChunkHeader = chunk_header
|
||||
|
||||
self.payload: bytes = payload
|
||||
|
||||
# first byte of data
|
||||
# has to be the first byte of the message payload
|
||||
# NOT the chunk header and NOT the message id
|
||||
def unpack(self, data: bytes) -> bool:
|
||||
self.payload = data
|
||||
return True
|
||||
|
||||
def pack(self) -> bytes:
|
||||
return self.payload
|
|
@ -44,4 +44,4 @@ class MsgInput(PrettyPrint):
|
|||
return pack_int(self.ack_snapshot) + \
|
||||
pack_int(self.intended_tick) + \
|
||||
pack_int(self.input_size) + \
|
||||
self.input.pack()
|
||||
self.input.pack()
|
|
@ -3,6 +3,7 @@ from typing import Optional
|
|||
|
||||
import twnet_parser.msg6
|
||||
from twnet_parser.net_message import NetMessage
|
||||
from twnet_parser.ddnet_uuid import MsgDDNetUuid
|
||||
|
||||
import twnet_parser.messages6.game.sv_motd as \
|
||||
game6_sv_motd
|
||||
|
@ -109,8 +110,12 @@ def match_game6(msg_id: int, data: bytes) -> NetMessage:
|
|||
elif msg_id == twnet_parser.msg6.CL_CALL_VOTE:
|
||||
msg = game6_cl_call_vote.MsgClCallVote()
|
||||
|
||||
# msg_id 0 is used by ddnet uuid messages
|
||||
# do not crash on those
|
||||
if msg is None:
|
||||
raise ValueError(f"Error: unknown game message id={msg_id} data={data[0]}")
|
||||
if msg_id != 0:
|
||||
raise ValueError(f"Error: unknown game message id={msg_id} data={data[0]}")
|
||||
msg = MsgDDNetUuid()
|
||||
|
||||
msg.unpack(data)
|
||||
return msg
|
||||
|
|
|
@ -3,6 +3,7 @@ from typing import Optional
|
|||
|
||||
import twnet_parser.msg7
|
||||
from twnet_parser.net_message import NetMessage
|
||||
from twnet_parser.ddnet_uuid import MsgDDNetUuid
|
||||
|
||||
import twnet_parser.messages7.game.sv_motd as \
|
||||
game7_sv_motd
|
||||
|
@ -165,8 +166,12 @@ def match_game7(msg_id: int, data: bytes) -> NetMessage:
|
|||
elif msg_id == twnet_parser.msg7.CL_COMMAND:
|
||||
msg = game7_cl_command.MsgClCommand()
|
||||
|
||||
# msg_id 0 is used by ddnet uuid messages
|
||||
# do not crash on those
|
||||
if msg is None:
|
||||
raise ValueError(f"Error: unknown game message id={msg_id} data={data[0]}")
|
||||
if msg_id != 0:
|
||||
raise ValueError(f"Error: unknown game message id={msg_id} data={data[0]}")
|
||||
msg = MsgDDNetUuid()
|
||||
|
||||
msg.unpack(data)
|
||||
return msg
|
||||
|
|
|
@ -3,6 +3,7 @@ from typing import Optional
|
|||
|
||||
import twnet_parser.msg6
|
||||
from twnet_parser.net_message import NetMessage
|
||||
from twnet_parser.ddnet_uuid import MsgDDNetUuid
|
||||
|
||||
import twnet_parser.messages6.system.info as \
|
||||
system6_info
|
||||
|
@ -89,8 +90,12 @@ def match_system6(msg_id: int, data: bytes) -> NetMessage:
|
|||
elif msg_id == twnet_parser.msg6.RCON_CMD_REMOVE:
|
||||
msg = system6_rcon_cmd_remove.MsgRconCmdRemove()
|
||||
|
||||
# msg_id 0 is used by ddnet uuid messages
|
||||
# do not crash on those
|
||||
if msg is None:
|
||||
raise ValueError(f"Error: unknown system message id={msg_id} data={data[0]}")
|
||||
if msg_id != 0:
|
||||
raise ValueError(f"Error: unknown system message id={msg_id} data={data[0]}")
|
||||
msg = MsgDDNetUuid()
|
||||
|
||||
msg.unpack(data)
|
||||
return msg
|
||||
|
|
|
@ -3,6 +3,7 @@ from typing import Optional
|
|||
|
||||
import twnet_parser.msg7
|
||||
from twnet_parser.net_message import NetMessage
|
||||
from twnet_parser.ddnet_uuid import MsgDDNetUuid
|
||||
|
||||
import twnet_parser.messages7.system.info as \
|
||||
system7_info
|
||||
|
@ -105,8 +106,12 @@ def match_system7(msg_id: int, data: bytes) -> NetMessage:
|
|||
elif msg_id == twnet_parser.msg7.MAPLIST_ENTRY_REM:
|
||||
msg = system7_maplist_entry_rem.MsgMaplistEntryRem()
|
||||
|
||||
# msg_id 0 is used by ddnet uuid messages
|
||||
# do not crash on those
|
||||
if msg is None:
|
||||
raise ValueError(f"Error: unknown system message id={msg_id} data={data[0]}")
|
||||
if msg_id != 0:
|
||||
raise ValueError(f"Error: unknown system message id={msg_id} data={data[0]}")
|
||||
msg = MsgDDNetUuid()
|
||||
|
||||
msg.unpack(data)
|
||||
return msg
|
||||
|
|
Loading…
Reference in a new issue