Generate messages with array fields
This commit was fully automated by ./scripts/generate_messages.py
This commit is contained in:
parent
822074ea47
commit
559f63d033
|
@ -3,34 +3,41 @@
|
|||
from twnet_parser.pretty_print import PrettyPrint
|
||||
from twnet_parser.packer import Unpacker
|
||||
from twnet_parser.chunk_header import ChunkHeader
|
||||
from twnet_parser.packer import pack_int
|
||||
from twnet_parser.packer import SANITIZE_CC, pack_int, pack_str
|
||||
from typing import Annotated
|
||||
|
||||
class MsgClSkinChange(PrettyPrint):
|
||||
def __init__(
|
||||
self,
|
||||
skin_part_names: int = 0,
|
||||
use_custom_colors: int = 0,
|
||||
skin_part_colors: int = 0
|
||||
skin_part_names: Annotated[list[str], 6] = \
|
||||
['', '', '', '', '', ''],
|
||||
use_custom_colors: Annotated[list[bool], 6] = \
|
||||
[False, False, False, False, False, False],
|
||||
skin_part_colors: Annotated[list[int], 6] = \
|
||||
[0, 0, 0, 0, 0, 0]
|
||||
) -> None:
|
||||
self.message_name = 'cl_skin_change'
|
||||
self.system_message = False
|
||||
self.header: ChunkHeader
|
||||
|
||||
self.skin_part_names: int = skin_part_names
|
||||
self.use_custom_colors: int = use_custom_colors
|
||||
self.skin_part_colors: int = skin_part_colors
|
||||
self.skin_part_names = skin_part_names
|
||||
self.use_custom_colors = use_custom_colors
|
||||
self.skin_part_colors = skin_part_colors
|
||||
|
||||
# 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:
|
||||
unpacker = Unpacker(data)
|
||||
self.skin_part_names = unpacker.get_int() # TODO: this is an array
|
||||
self.use_custom_colors = unpacker.get_int() # TODO: this is an array
|
||||
self.skin_part_colors = unpacker.get_int() # TODO: this is an array
|
||||
for i in range(0, 6):
|
||||
self.skin_part_names[i] = unpacker.get_str(SANITIZE_CC)
|
||||
for i in range(0, 6):
|
||||
self.use_custom_colors[i] = unpacker.get_int() == 1
|
||||
for i in range(0, 6):
|
||||
self.skin_part_colors[i] = unpacker.get_int()
|
||||
return True
|
||||
|
||||
def pack(self) -> bytes:
|
||||
return pack_int(self.skin_part_names) + \
|
||||
pack_int(self.use_custom_colors) + \
|
||||
pack_int(self.skin_part_colors)
|
||||
return b''.join([pack_str(x) for x in self.skin_part_names]) + \
|
||||
b''.join([pack_int(x) for x in self.use_custom_colors]) + \
|
||||
b''.join([pack_int(x) for x in self.skin_part_colors])
|
|
@ -4,6 +4,7 @@ from twnet_parser.pretty_print import PrettyPrint
|
|||
from twnet_parser.packer import Unpacker
|
||||
from twnet_parser.chunk_header import ChunkHeader
|
||||
from twnet_parser.packer import SANITIZE_CC, pack_int, pack_str
|
||||
from typing import Annotated
|
||||
|
||||
class MsgClStartInfo(PrettyPrint):
|
||||
def __init__(
|
||||
|
@ -11,9 +12,12 @@ class MsgClStartInfo(PrettyPrint):
|
|||
name: str = 'default',
|
||||
clan: str = 'default',
|
||||
country: int = 0,
|
||||
skin_part_names: int = 0,
|
||||
use_custom_colors: int = 0,
|
||||
skin_part_colors: int = 0
|
||||
skin_part_names: Annotated[list[str], 6] = \
|
||||
['', '', '', '', '', ''],
|
||||
use_custom_colors: Annotated[list[bool], 6] = \
|
||||
[False, False, False, False, False, False],
|
||||
skin_part_colors: Annotated[list[int], 6] = \
|
||||
[0, 0, 0, 0, 0, 0]
|
||||
) -> None:
|
||||
self.message_name = 'cl_start_info'
|
||||
self.system_message = False
|
||||
|
@ -22,9 +26,9 @@ class MsgClStartInfo(PrettyPrint):
|
|||
self.name: str = name
|
||||
self.clan: str = clan
|
||||
self.country: int = country
|
||||
self.skin_part_names: int = skin_part_names
|
||||
self.use_custom_colors: int = use_custom_colors
|
||||
self.skin_part_colors: int = skin_part_colors
|
||||
self.skin_part_names = skin_part_names
|
||||
self.use_custom_colors = use_custom_colors
|
||||
self.skin_part_colors = skin_part_colors
|
||||
|
||||
# first byte of data
|
||||
# has to be the first byte of the message payload
|
||||
|
@ -34,15 +38,18 @@ class MsgClStartInfo(PrettyPrint):
|
|||
self.name = unpacker.get_str(SANITIZE_CC)
|
||||
self.clan = unpacker.get_str(SANITIZE_CC)
|
||||
self.country = unpacker.get_int()
|
||||
self.skin_part_names = unpacker.get_int() # TODO: this is an array
|
||||
self.use_custom_colors = unpacker.get_int() # TODO: this is an array
|
||||
self.skin_part_colors = unpacker.get_int() # TODO: this is an array
|
||||
for i in range(0, 6):
|
||||
self.skin_part_names[i] = unpacker.get_str(SANITIZE_CC)
|
||||
for i in range(0, 6):
|
||||
self.use_custom_colors[i] = unpacker.get_int() == 1
|
||||
for i in range(0, 6):
|
||||
self.skin_part_colors[i] = unpacker.get_int()
|
||||
return True
|
||||
|
||||
def pack(self) -> bytes:
|
||||
return pack_str(self.name) + \
|
||||
pack_str(self.clan) + \
|
||||
pack_int(self.country) + \
|
||||
pack_int(self.skin_part_names) + \
|
||||
pack_int(self.use_custom_colors) + \
|
||||
pack_int(self.skin_part_colors)
|
||||
b''.join([pack_str(x) for x in self.skin_part_names]) + \
|
||||
b''.join([pack_int(x) for x in self.use_custom_colors]) + \
|
||||
b''.join([pack_int(x) for x in self.skin_part_colors])
|
|
@ -4,6 +4,7 @@ from twnet_parser.pretty_print import PrettyPrint
|
|||
from twnet_parser.packer import Unpacker
|
||||
from twnet_parser.chunk_header import ChunkHeader
|
||||
from twnet_parser.packer import SANITIZE_CC, pack_int, pack_str
|
||||
from typing import Annotated
|
||||
|
||||
class MsgSvClientInfo(PrettyPrint):
|
||||
def __init__(
|
||||
|
@ -14,9 +15,12 @@ class MsgSvClientInfo(PrettyPrint):
|
|||
name: str = 'default',
|
||||
clan: str = 'default',
|
||||
country: int = 0,
|
||||
skin_part_names: int = 0,
|
||||
use_custom_colors: int = 0,
|
||||
skin_part_colors: int = 0,
|
||||
skin_part_names: Annotated[list[str], 6] = \
|
||||
['', '', '', '', '', ''],
|
||||
use_custom_colors: Annotated[list[bool], 6] = \
|
||||
[False, False, False, False, False, False],
|
||||
skin_part_colors: Annotated[list[int], 6] = \
|
||||
[0, 0, 0, 0, 0, 0],
|
||||
silent: bool = False
|
||||
) -> None:
|
||||
self.message_name = 'sv_client_info'
|
||||
|
@ -29,9 +33,9 @@ class MsgSvClientInfo(PrettyPrint):
|
|||
self.name: str = name
|
||||
self.clan: str = clan
|
||||
self.country: int = country
|
||||
self.skin_part_names: int = skin_part_names
|
||||
self.use_custom_colors: int = use_custom_colors
|
||||
self.skin_part_colors: int = skin_part_colors
|
||||
self.skin_part_names = skin_part_names
|
||||
self.use_custom_colors = use_custom_colors
|
||||
self.skin_part_colors = skin_part_colors
|
||||
self.silent: bool = silent
|
||||
|
||||
# first byte of data
|
||||
|
@ -45,9 +49,12 @@ class MsgSvClientInfo(PrettyPrint):
|
|||
self.name = unpacker.get_str(SANITIZE_CC)
|
||||
self.clan = unpacker.get_str(SANITIZE_CC)
|
||||
self.country = unpacker.get_int()
|
||||
self.skin_part_names = unpacker.get_int() # TODO: this is an array
|
||||
self.use_custom_colors = unpacker.get_int() # TODO: this is an array
|
||||
self.skin_part_colors = unpacker.get_int() # TODO: this is an array
|
||||
for i in range(0, 6):
|
||||
self.skin_part_names[i] = unpacker.get_str(SANITIZE_CC)
|
||||
for i in range(0, 6):
|
||||
self.use_custom_colors[i] = unpacker.get_int() == 1
|
||||
for i in range(0, 6):
|
||||
self.skin_part_colors[i] = unpacker.get_int()
|
||||
self.silent = unpacker.get_int() == 1
|
||||
return True
|
||||
|
||||
|
@ -58,7 +65,7 @@ class MsgSvClientInfo(PrettyPrint):
|
|||
pack_str(self.name) + \
|
||||
pack_str(self.clan) + \
|
||||
pack_int(self.country) + \
|
||||
pack_int(self.skin_part_names) + \
|
||||
pack_int(self.use_custom_colors) + \
|
||||
pack_int(self.skin_part_colors) + \
|
||||
b''.join([pack_str(x) for x in self.skin_part_names]) + \
|
||||
b''.join([pack_int(x) for x in self.use_custom_colors]) + \
|
||||
b''.join([pack_int(x) for x in self.skin_part_colors]) + \
|
||||
pack_int(self.silent)
|
|
@ -3,24 +3,28 @@
|
|||
from twnet_parser.pretty_print import PrettyPrint
|
||||
from twnet_parser.packer import Unpacker
|
||||
from twnet_parser.chunk_header import ChunkHeader
|
||||
from twnet_parser.packer import pack_int
|
||||
from twnet_parser.packer import SANITIZE_CC, pack_int, pack_str
|
||||
from typing import Annotated
|
||||
|
||||
class MsgSvSkinChange(PrettyPrint):
|
||||
def __init__(
|
||||
self,
|
||||
client_id: int = 0,
|
||||
skin_part_names: int = 0,
|
||||
use_custom_colors: int = 0,
|
||||
skin_part_colors: int = 0
|
||||
skin_part_names: Annotated[list[str], 6] = \
|
||||
['', '', '', '', '', ''],
|
||||
use_custom_colors: Annotated[list[bool], 6] = \
|
||||
[False, False, False, False, False, False],
|
||||
skin_part_colors: Annotated[list[int], 6] = \
|
||||
[0, 0, 0, 0, 0, 0]
|
||||
) -> None:
|
||||
self.message_name = 'sv_skin_change'
|
||||
self.system_message = False
|
||||
self.header: ChunkHeader
|
||||
|
||||
self.client_id: int = client_id
|
||||
self.skin_part_names: int = skin_part_names
|
||||
self.use_custom_colors: int = use_custom_colors
|
||||
self.skin_part_colors: int = skin_part_colors
|
||||
self.skin_part_names = skin_part_names
|
||||
self.use_custom_colors = use_custom_colors
|
||||
self.skin_part_colors = skin_part_colors
|
||||
|
||||
# first byte of data
|
||||
# has to be the first byte of the message payload
|
||||
|
@ -28,13 +32,16 @@ class MsgSvSkinChange(PrettyPrint):
|
|||
def unpack(self, data: bytes) -> bool:
|
||||
unpacker = Unpacker(data)
|
||||
self.client_id = unpacker.get_int()
|
||||
self.skin_part_names = unpacker.get_int() # TODO: this is an array
|
||||
self.use_custom_colors = unpacker.get_int() # TODO: this is an array
|
||||
self.skin_part_colors = unpacker.get_int() # TODO: this is an array
|
||||
for i in range(0, 6):
|
||||
self.skin_part_names[i] = unpacker.get_str(SANITIZE_CC)
|
||||
for i in range(0, 6):
|
||||
self.use_custom_colors[i] = unpacker.get_int() == 1
|
||||
for i in range(0, 6):
|
||||
self.skin_part_colors[i] = unpacker.get_int()
|
||||
return True
|
||||
|
||||
def pack(self) -> bytes:
|
||||
return pack_int(self.client_id) + \
|
||||
pack_int(self.skin_part_names) + \
|
||||
pack_int(self.use_custom_colors) + \
|
||||
pack_int(self.skin_part_colors)
|
||||
b''.join([pack_str(x) for x in self.skin_part_names]) + \
|
||||
b''.join([pack_int(x) for x in self.use_custom_colors]) + \
|
||||
b''.join([pack_int(x) for x in self.skin_part_colors])
|
Loading…
Reference in a new issue