Пример #1
0
 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))
Пример #2
0
 def serialize(self, stream: bitstream.WriteStream) -> None:
     stream.write(bitstream.c_uint64(self.object_id))
     stream.write(bitstream.c_uint32(0))
     stream.write(self.current_name, allocated_length=33)
     stream.write(self.unapproved_name, allocated_length=33)
     stream.write(bitstream.c_bool(self.name_rejected))
     stream.write(bitstream.c_bool(self.is_ftp))
     stream.write(bitstream.c_uint32(self.head_color))
     stream.write(bitstream.c_uint16(0))
     stream.write(bitstream.c_uint32(self.head))
     stream.write(bitstream.c_uint32(self.chest_color))
     stream.write(bitstream.c_uint32(self.chest))
     stream.write(bitstream.c_uint32(self.legs))
     stream.write(bitstream.c_uint32(self.hair_style))
     stream.write(bitstream.c_uint32(self.hair_color))
     stream.write(bitstream.c_uint32(self.left_hand))
     stream.write(bitstream.c_uint32(self.right_hand))
     stream.write(bitstream.c_uint32(self.eyebrows_style))
     stream.write(bitstream.c_uint32(self.eyes_style))
     stream.write(bitstream.c_uint32(self.mouth_style))
     stream.write(bitstream.c_uint32(0))
     stream.write(bitstream.c_uint16(self.last_zone))
     stream.write(bitstream.c_uint16(self.last_map_instance))
     stream.write(bitstream.c_uint32(self.last_map_clone))
     stream.write(bitstream.c_uint64(0))
     stream.write(bitstream.c_uint16(len(self.equipped_items)))
     for item in self.equipped_items:
         stream.write(bitstream.c_uint32(item))
Пример #3
0
    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
Пример #4
0
 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)
Пример #5
0
    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))
Пример #6
0
 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))
Пример #7
0
 def serialize(self, stream: bitstream.WriteStream) -> None:
     temp_stream = bitstream.WriteStream()
     temp_stream.write(self.ldf)
     temp_bytes = temp_stream.__bytes__()
     compressed_bytes = zlib.compress(temp_bytes)
     stream.write(bitstream.c_ulong(len(compressed_bytes) + 9))
     stream.write(bitstream.c_bool(True))
     stream.write(bitstream.c_ulong(len(temp_bytes)))
     stream.write(bitstream.c_ulong(len(compressed_bytes)))
     stream.write(compressed_bytes)
Пример #8
0
 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))
Пример #9
0
    def serialize(self, stream: WriteStream):
        super().serialize(stream)

        wstr = WriteStream()
        wstr.write(self.ldf)
        data = bytes(wstr)
        compressed_data = zlib.compress(data)

        stream.write(c_uint32(len(compressed_data) + 9))
        stream.write(c_bool(True))
        stream.write(c_uint32(len(data)))
        stream.write(c_uint32(len(compressed_data)))
        stream.write(compressed_data)
Пример #10
0
 def serialize(self, stream: bitstream.WriteStream) -> None:
     stream.write(CString(self.redirect_ip, allocated_length=33))
     stream.write(bitstream.c_uint16(self.redirect_port))
     stream.write(bitstream.c_bool(self.is_mythran_dimension_shift))