def construct_packet(self, packet): stream = ReadStream(packet) # TODO - figure out why we aren't receiving user credentials correctly? """ uname = stream.read(str, allocated_length=33) pword = stream.read(str, allocated_length=41) self.logger.debug('user with credentials {0}:{1} attempting to login'.format(uname, pword)) """ uname = 'dev' pword = 'dev' res = WriteStream() res.write(PacketHeaders.CLIENT_LOGIN_RES.value) for account in self.database.accounts: if account.username == uname and account.password == pword: self.logger.debug('found user {} in database'.format(uname)) res.write(c_uint8(0x01)) break elif account.banned: res.write(c_uint8(0x02)) break res.write(CString('Talk_Like_A_Pirate', allocated_length=33)) # unknown res.write(CString(allocated_length=33 * 7)) # unknown res.write(c_uint16(1)) # v. major res.write(c_uint16(10)) # v. current res.write(c_uint16(64)) # v. minor user_token = str(uuid.uuid4()) res.write(user_token[0:18], allocated_length=33) res.write(CString('127.0.0.1', allocated_length=33)) # world IP res.write(CString('127.0.0.1', allocated_length=33)) # chat IP res.write(c_uint16(2002)) # world port res.write(c_ushort(3003)) # chat port res.write(CString('0', allocated_length=33)) # unknown IP res.write( CString('00000000-0000-0000-0000-000000000000', allocated_length=37)) res.write(c_ulong(0)) res.write(CString('US', allocated_length=3)) # localization res.write(c_bool(False)) res.write(c_bool(False)) res.write(c_ulonglong(0)) res.write('error', length_type=c_uint16) # custom err msg res.write(c_uint16(0)) res.write(c_ulong(4)) return res
def serialize(self, stream: bitstream.WriteStream) -> None: stream.write(bitstream.c_uint8(self.login_return_code)) stream.write(CString("Talk_Like_A_Pirate", allocated_length=33)) stream.write(CString("", allocated_length=33 * 7)) stream.write(bitstream.c_uint16(self.client_version_major)) stream.write(bitstream.c_uint16(self.client_version_current)) stream.write(bitstream.c_uint16(self.client_version_minor)) stream.write(self.user_key, allocated_length=33) stream.write(CString(self.char_ip, allocated_length=33)) stream.write(CString(self.chat_ip, allocated_length=33)) stream.write(bitstream.c_uint16(self.char_port)) stream.write(bitstream.c_uint16(self.chat_port)) stream.write(CString('0', allocated_length=33)) stream.write( CString('00000000-0000-0000-0000-000000000000', allocated_length=37)) stream.write(bitstream.c_uint32(0)) stream.write(CString(self.localization, allocated_length=3)) # US Localization stream.write(bitstream.c_bool(self.display_first_time)) stream.write(bitstream.c_bool(self.is_ftp)) stream.write(bitstream.c_uint64(0)) stream.write(self.custom_error, length_type=bitstream.c_uint16) # Custom error message stream.write(bitstream.c_uint16(0)) stream.write(bitstream.c_uint32(4))
def serialize(self, stream: bitstream.WriteStream) -> None: key_num = len(self._keys) stream.write(bitstream.c_uint(key_num)) for key in self._keys: name = key[0] value = key[1] value_type = key[2] stream.write(bitstream.c_uint8(len(name) * 2)) for char in name: stream.write(char.encode('latin1')) stream.write(b'\0') stream.write(bitstream.c_ubyte(value_type)) if value_type == 0: stream.write(value, length_type=bitstream.c_uint) elif value_type == 1: stream.write(bitstream.c_int(value)) elif value_type == 3: stream.write(bitstream.c_float(value)) elif value_type == 5: stream.write(bitstream.c_uint(value)) elif value_type == 7: stream.write(bitstream.c_bool(value)) elif value_type == 8 or value_type == 9: stream.write(bitstream.c_int64(value)) elif value_type == 13: xml_str = bytes(ElementTree.tostring(value)) xml_str = b'<?xml version="1.0">' + xml_str stream.write(bitstream.c_ulong(xml_str.__len__())) stream.write(xml_str)
def serialize(self, stream): super().serialize(stream) front_char = self.server.handle_until_value('char:front_char_index', True, self.characters[0].user_id) stream.write(c_uint8(front_char)) stream.write(len(self.characters)) for character in self.characters: character.serialize(stream)
def _write_part2(self, stream: WriteStream): stream.write(c_bit(True)) stream.write(c_bit(self.pvp)) stream.write(c_bit(self.gm)) stream.write(c_uint8(self.gm_level)) stream.write(c_bit(False)) stream.write(c_uint8(0)) stream.write(c_bit(True)) stream.write(c_uint32(1 if self.glowing_head else 0)) stream.write(c_bit(self.guild)) if self.guild: stream.write(c_int64(self.guild_id)) stream.write(self.guild_name, allocated_length=33) stream.write(c_bit(True)) stream.write(c_int32(-1))
def serialize(self, stream: WriteStream): stream.write(c_uint8(0x53)) stream.write(c_uint16(0x05)) stream.write(c_uint32(0x00)) stream.write(c_uint8(0)) stream.write(c_uint8(self.login_code)) stream.write(b'Talk_Like_A_Pirate', allocated_length=33) for _ in range(7): stream.write(b'', allocated_length=33) stream.write(c_uint16(1)) stream.write(c_uint16(10)) stream.write(c_uint16(64)) stream.write(self.user_key, allocated_length=33) stream.write(self.char_ip.encode('latin1'), allocated_length=33) stream.write(self.chat_ip.encode('latin1'), allocated_length=33) stream.write(c_uint16(self.char_port)) stream.write(c_uint16(self.chat_port)) stream.write(self.ip.encode('latin1'), allocated_length=33) stream.write(b'00000000-0000-0000-0000-000000000000', allocated_length=37) stream.write(c_uint32(0)) stream.write(self.locale.encode('latin1'), allocated_length=3) stream.write(c_bool(self.first_login_sub)) stream.write(c_bool(self.free_to_play)) stream.write(c_uint64(0)) if self.error: stream.write(c_uint16(len(self.error))) stream.write(self.error, allocated_length=len(self.error)) else: stream.write(c_uint16(0)) stream.write(c_uint32(4))
def serialize(self, stream: bitstream.WriteStream) -> None: stream.write(bitstream.c_uint16(self.zone_id)) stream.write(bitstream.c_uint16(self.map_instance)) stream.write(bitstream.c_uint32(self.map_clone)) stream.write(bitstream.c_uint32(self.map_checksum)) stream.write(bitstream.c_bool(self.editor_enabled)) stream.write(bitstream.c_uint8(self.editor_level)) stream.write(self.player_position) stream.write(bitstream.c_uint32(self.activity))
def _write_part1(self, stream: WriteStream): stream.write(c_bit(True)) stream.write(c_bit(self.vehicle_id is not None)) if self.vehicle_id is not None: stream.write(c_int64(self.vehicle_id)) stream.write(c_uint8(0)) stream.write(c_bit(self.level is not None)) if self.level is not None: stream.write(c_uint32(self.level)) stream.write(c_bit(True)) stream.write(c_bit(False)) stream.write(c_bit(True))
def serialize(self, stream: WriteStream): stream.write(c_uint8(len(self.key) * 2)) for c in self.key: stream.write(c.encode('latin1')) stream.write(b'\0') stream.write(c_uint8(self.value_type)) if self.value_type == 0: if isinstance(self.value, bytes): stream.write(self.value.decode('latin1'), length_type=c_uint32) else: stream.write(self.value, length_type=c_uint32) elif self.value_type == 13: if isinstance(self.value, ElementTree.Element): stream.write(b'<?xml version="1.0">' + ElementTree.tostring(self.value), length_type=c_uint32) elif isinstance(self.value, bytes): stream.write(self.value, length_type=c_uint32) else: stream.write(self.value.encode('latin1'), length_type=c_uint32) else: stream.write(LDF_VALUE_TYPES[self.value_type](self.value))
def serialize(self, stream): super().serialize(stream) stream.write(c_uint8(self.auth_status_code)) stream.write(CString(self.unknown, allocated_length=33)) stream.write(CString(self.unknown1, allocated_length=33*7)) stream.write(self.client_version) stream.write(self.auth_token, allocated_length=33) stream.write(CString(self.char_ip, allocated_length=33)) stream.write(CString(self.chat_ip, allocated_length=33)) stream.write(c_uint16(self.char_port)) stream.write(c_uint16(self.chat_port)) stream.write(CString(self.unknown2, allocated_length=33)) stream.write(CString(self.unknown3, allocated_length=37)) stream.write(c_uint32(self.unknown4)) stream.write(CString(self.localization, allocated_length=3)) stream.write(c_bool(self.new_subscriber)) stream.write(c_bool(self.is_ftp)) stream.write(c_uint64(self.unknown5)) stream.write(self.permission_error, length_type=c_uint16) # TODO: Implement stamps stream.write(c_uint32(4))
def serialize(self, stream: WriteStream): stream.write(c_uint8(0x53)) stream.write(c_uint16(self.connection_type.value)) stream.write(c_uint32(self.packet_id)) stream.write(c_uint8(0))
def serialize(self, stream: WriteStream) -> None: super().serialize(stream) stream.write(c_uint8(self.response_code))
def serialize(self, stream): stream.write(c_uint8(0x53)) stream.write(c_uint16(self.remote_conn_id)) stream.write(c_uint32(self.packet_id)) stream.write(c_uint8(0x00))
def serialize(self, stream: bitstream.WriteStream) -> None: stream.write(bitstream.c_uint8(self.response))
def serialize(self, stream: bitstream.WriteStream) -> None: stream.write(bitstream.c_uint8(len(self.minifigs))) stream.write(bitstream.c_uint8(self.current_index)) for m in self.minifigs: stream.write(m)