コード例 #1
0
    def read(stream, packet_size):
        protocol = StreamIO.read_varint(stream)
        hostname = StreamIO.read_string(stream).decode("utf8")
        port = StreamIO.read_ushort(stream)
        next_state = StreamIO.read_varint(stream)

        return HandshakePacket(protocol, hostname, port, next_state)
コード例 #2
0
    def read(stream, packet_size):
        locale = StreamIO.read_string(stream)
        view_distance = StreamIO.read_byte(stream)
        chat_mode = StreamIO.read_varint(stream)
        chat_colors = StreamIO.read_bool(stream)
        skin_parts = StreamIO.read_ubyte(stream)
        main_hand = StreamIO.read_varint(stream)

        return ClientSettingsPacket(locale, view_distance, chat_mode,
                                    chat_colors, skin_parts, main_hand)
コード例 #3
0
    def read(stream, packet_size):
        channel_len = StreamIO.read_varint(stream)
        channel = StreamIO.read(stream, channel_len).decode("utf8")
        plugin_bytes = StreamIO.read(
            stream,
            packet_size - StreamIO.size_varint(channel_len) - channel_len)

        return PluginMessageServerPacket(channel, plugin_bytes)
コード例 #4
0
    def read(stream, packet_size):
        x = StreamIO.read_double(stream)
        y = StreamIO.read_double(stream)
        z = StreamIO.read_double(stream)
        yaw = StreamIO.read_float(stream)
        pitch = StreamIO.read_float(stream)
        flags = StreamIO.read_byte(stream)
        teleport_id = StreamIO.read_varint(stream)

        return PlayerPositionAndLookClientPacket(x, y, z, yaw, pitch, flags, teleport_id)
コード例 #5
0
    def read(self, stream):
        packet_size = StreamIO.read_varint(stream)

        if self.is_compression_enabled():
            data_size = StreamIO.read_varint(stream)

            if data_size == 0:
                packet_size -= StreamIO.size_varint(0)
                data = StreamIO.read(stream, packet_size)
            else:
                data = StreamIO.read(
                    stream, packet_size - StreamIO.size_varint(data_size))
                data = zlib.decompress(data)
                packet_size = data_size
        else:
            data = StreamIO.read(stream, packet_size)

        buf = StringIO(data)
        packet_id = StreamIO.read_varint(buf)
        packet_size -= StreamIO.size_varint(packet_id)

        packet_direction = None
        if self._mode == PacketSerializer.Mode.SERVER:
            packet_direction = PacketDirection.SERVERBOUND
        elif self._mode == PacketSerializer.Mode.CLIENT:
            packet_direction = PacketDirection.CLIENTBOUND

        try:
            packet_class = PacketProvider.get_packet_class(
                self._protocol, self._state, packet_direction, packet_id)
        except KeyError:
            buf.close()
            return BasePacket()  # Unknown packet

        packet = packet_class.read(buf, packet_size)
        buf.close()

        return packet
コード例 #6
0
    def read(stream, packet_size):
        window_id = StreamIO.read_ubyte(stream)
        slot = StreamIO.read_short(stream)
        button = StreamIO.read_byte(stream)
        transaction_id = StreamIO.read_short(stream)
        mode = StreamIO.read_varint(stream)
        slot_data = SlotData(StreamIO.read_short(stream))
        if not slot_data.is_empty():
            slot_data.set_count(StreamIO.read_byte(stream))
            slot_data.set_damage(StreamIO.read_short(stream))
            slot_data.set_tag(NBTSerializer.read(stream))

        return ClickWindowPacket(window_id, slot, button, transaction_id, mode,
                                 slot_data)
コード例 #7
0
    def read(stream, packet_size):
        hand_type = StreamIO.read_varint(stream)

        return UseItemPacket(hand_type)
コード例 #8
0
    def read(stream, packet_size):
        action = StreamIO.read_varint(stream)

        return ClientStatusPacket(action)
コード例 #9
0
    def read(stream, packet_size):
        keepalive_id = StreamIO.read_varint(stream)

        return KeepAliveClientPacket(keepalive_id)
コード例 #10
0
    def read(stream, packet_size):
        threshold = StreamIO.read_varint(stream)

        return SetCompressionPacket(threshold)
コード例 #11
0
    def read(stream, packet_size):
        teleport_id = StreamIO.read_varint(stream)

        return TeleportConfirmPacket(teleport_id)