feat: implement dict on connless messages

This commit is contained in:
ChillerDragon 2024-06-16 11:08:55 +08:00
parent 545c93cff1
commit 5291c403a0
23 changed files with 168 additions and 0 deletions

View file

@ -115,6 +115,19 @@ def name_to_snake(name_list: list[str]) -> str:
name = '_'.join(name_list)
return fix_name_conflict(name)
def gen_iter(messages: list[NetMessageMemberJson]) -> str:
lines: list[str] = []
lines.append(' def __iter__(self):')
lines.append(" yield 'message_type', self.message_type")
lines.append(" yield 'message_name', self.message_name")
lines.append(" yield 'message_id', self.message_id")
if len(messages) > 0:
lines.append("")
for msg in messages:
name = name_to_snake(msg['name'])
lines.append(f" yield '{name}', self.{name}")
return '\n'.join(lines)
def gen_unpack_members_connless7(msg: NetConnlessJson) -> str:
res: str = ''
for member in msg['members']:
@ -915,6 +928,9 @@ def match_connless{self.protocol_version}(msg_id: bytes, data: bytes) -> Connles
else:
out_file.write(f" self.{name}{ftype} = {name}\n")
out_file.write('\n')
out_file.write(gen_iter(msg['members']))
out_file.write('\n')
out_file.write('\n')
out_file.write(' # first byte of data\n')
out_file.write(' # has to be the first byte of the message payload\n')
out_file.write(' # NOT the chunk header and NOT the message id\n')

View file

@ -16,6 +16,13 @@ class MsgCount(PrettyPrint):
self.count: int = count
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
yield 'count', self.count
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -12,6 +12,11 @@ class MsgForwardCheck(PrettyPrint):
self.message_id: list[int] = [255, 255, 255, 255, 102, 119, 63, 63]
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -12,6 +12,11 @@ class MsgForwardError(PrettyPrint):
self.message_id: list[int] = [255, 255, 255, 255, 102, 119, 101, 114]
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -12,6 +12,11 @@ class MsgForwardOk(PrettyPrint):
self.message_id: list[int] = [255, 255, 255, 255, 102, 119, 111, 107]
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -12,6 +12,11 @@ class MsgForwardResponse(PrettyPrint):
self.message_id: list[int] = [255, 255, 255, 255, 102, 119, 33, 33]
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -16,6 +16,13 @@ class MsgHeartbeat(PrettyPrint):
self.alt_port: int = alt_port
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
yield 'alt_port', self.alt_port
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -36,6 +36,23 @@ class MsgInfo(PrettyPrint):
self.max_clients: int = max_clients
self.clients: bytes = clients
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
yield 'token', self.token
yield 'version', self.version
yield 'name', self.name
yield 'map', self.map
yield 'game_type', self.game_type
yield 'flags', self.flags
yield 'num_players', self.num_players
yield 'max_players', self.max_players
yield 'num_clients', self.num_clients
yield 'max_clients', self.max_clients
yield 'clients', self.clients
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -17,6 +17,13 @@ class MsgList(PrettyPrint):
self.servers: list[MastersrvAddr] = servers
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
yield 'servers', self.servers
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -12,6 +12,11 @@ class MsgRequestCount(PrettyPrint):
self.message_id: list[int] = [255, 255, 255, 255, 99, 111, 117, 50]
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -16,6 +16,13 @@ class MsgRequestInfo(PrettyPrint):
self.token: int = token
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
yield 'token', self.token
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -12,6 +12,11 @@ class MsgRequestList(PrettyPrint):
self.message_id: list[int] = [255, 255, 255, 255, 114, 101, 113, 50]
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -16,6 +16,13 @@ class MsgCount(PrettyPrint):
self.count: int = count
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
yield 'count', self.count
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -12,6 +12,11 @@ class MsgForwardCheck(PrettyPrint):
self.message_id: list[int] = [255, 255, 255, 255, 102, 119, 63, 63]
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -12,6 +12,11 @@ class MsgForwardError(PrettyPrint):
self.message_id: list[int] = [255, 255, 255, 255, 102, 119, 101, 114]
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -12,6 +12,11 @@ class MsgForwardOk(PrettyPrint):
self.message_id: list[int] = [255, 255, 255, 255, 102, 119, 111, 107]
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -12,6 +12,11 @@ class MsgForwardResponse(PrettyPrint):
self.message_id: list[int] = [255, 255, 255, 255, 102, 119, 33, 33]
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -16,6 +16,13 @@ class MsgHeartbeat(PrettyPrint):
self.alt_port: int = alt_port
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
yield 'alt_port', self.alt_port
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -40,6 +40,25 @@ class MsgInfo(PrettyPrint):
self.max_clients: int = max_clients
self.clients: bytes = clients
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
yield 'token', self.token
yield 'version', self.version
yield 'name', self.name
yield 'hostname', self.hostname
yield 'map', self.map
yield 'game_type', self.game_type
yield 'flags', self.flags
yield 'skill_level', self.skill_level
yield 'num_players', self.num_players
yield 'max_players', self.max_players
yield 'num_clients', self.num_clients
yield 'max_clients', self.max_clients
yield 'clients', self.clients
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -17,6 +17,13 @@ class MsgList(PrettyPrint):
self.servers: list[MastersrvAddr] = servers
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
yield 'servers', self.servers
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -12,6 +12,11 @@ class MsgRequestCount(PrettyPrint):
self.message_id: list[int] = [255, 255, 255, 255, 99, 111, 117, 50]
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -16,6 +16,13 @@ class MsgRequestInfo(PrettyPrint):
self.token: int = token
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
yield 'token', self.token
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -12,6 +12,11 @@ class MsgRequestList(PrettyPrint):
self.message_id: list[int] = [255, 255, 255, 255, 114, 101, 113, 50]
def __iter__(self):
yield 'message_type', self.message_type
yield 'message_name', self.message_name
yield 'message_id', self.message_id
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id