예제 #1
0
    def read(stream, packet_size):
        x = StreamIO.read_double(stream)
        y = StreamIO.read_double(stream)
        z = StreamIO.read_double(stream)
        on_ground = StreamIO.read_bool(stream)

        return PlayerPositionServerPacket(x, y, z, on_ground)
예제 #2
0
    def read(stream, packet_size):
        window_id = StreamIO.read_byte(stream)
        transaction_id = StreamIO.read_short(stream)
        accepted = StreamIO.read_bool(stream)

        return ConfirmTransactionServerPacket(window_id, transaction_id,
                                              accepted)
예제 #3
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)
예제 #4
0
    def read(stream):
        values = []
        len = StreamIO.read_long(stream)

        for i in xrange(len):
            values.append(StreamIO.read_long(stream))

        return NBTTagLongArray(values)
예제 #5
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)
예제 #6
0
    def read(stream):
        values = []
        len = StreamIO.read_int(stream)

        for i in xrange(len):
            values.append(StreamIO.read_byte(stream))

        return NBTTagByteArray(values)
예제 #7
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)

        return ClientSettingsPacket(locale, view_distance, chat_mode,
                                    chat_colors, skin_parts)
예제 #8
0
 def write(stream, packet):
     StreamIO.write_ubyte(stream, packet.get_window_id())
     StreamIO.write_string(stream, packet.get_window_type().encode("utf8"))
     StreamIO.write_string(
         stream,
         json.dumps(packet.get_window_title()).encode("utf8"))
     StreamIO.write_ubyte(stream, packet.get_slots_number())
     if packet.get_window_type() == "EntityHorse":
         StreamIO.write_int(stream, packet.get_entity_id())
예제 #9
0
    def read(stream):
        tag_type_id = StreamIO.read_ubyte(stream)
        tag_type = NBTProvider.get_tag_class(tag_type_id)
        values = []
        len = StreamIO.read_int(stream)

        for i in xrange(len):
            values.append(tag_type.read(stream))

        return NBTTagList(tag_type, values)
예제 #10
0
    def write(stream, packet):
        StreamIO.write_ubyte(stream, packet.get_window_id())
        StreamIO.write_short(stream, len(packet.get_slots()))

        for slot_data in packet.get_slots():
            StreamIO.write_short(stream, slot_data.get_id())
            if not slot_data.is_empty():
                StreamIO.write_byte(stream, slot_data.get_count())
                StreamIO.write_short(stream, slot_data.get_damage())
                NBTSerializer.write(stream, slot_data.get_tag())
예제 #11
0
    def read(stream, packet_size):
        window_id = StreamIO.read_ubyte(stream)
        window_type = StreamIO.read_string(stream).decode("utf8")
        window_title = json.loads(StreamIO.read_string(stream).decode("utf8"))
        slots_number = StreamIO.read_ubyte(stream)
        entity_id = None
        if window_type == "EntityHorse":
            entity_id = StreamIO.read_int(stream)

        return OpenWindowPacket(window_id, window_type, window_title,
                                slots_number, entity_id)
예제 #12
0
    def read(stream):
        compound_id = StreamIO.read_ubyte(stream)
        if compound_id == 0x00:
            return None

        if compound_id != NBTTagCompound.TYPE_ID:
            raise IOError("invalid magic number")

        name_len = StreamIO.read_ushort(stream)
        name = u""
        if name_len > 0:
            name = StreamIO.read(stream, name_len)

        return NBTTagCompound.read(stream)
예제 #13
0
    def write(stream, tag):
        for i in tag.keys():
            StreamIO.write_ubyte(stream, tag[i].__class__.TYPE_ID)
            StreamIO.write_ushort(stream, len(i.encode("utf8")))
            StreamIO.write(stream, i.encode("utf8"))
            tag[i].__class__.write(stream, tag[i])

        StreamIO.write_ubyte(stream, NBTTagEnd.TYPE_ID)
예제 #14
0
    def read(stream, packet_size):
        window_id = StreamIO.read_ubyte(stream)
        slots_len = StreamIO.read_short(stream)
        slots = []

        for i in xrange(slots_len):
            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))

            slots.append(slot_data)

        return WindowItemsPacket(window_id, slots)
예제 #15
0
    def read(stream):
        values = {}
        entry_type_id = StreamIO.read_ubyte(stream)

        while entry_type_id != NBTTagEnd.TYPE_ID:
            entry_name_len = StreamIO.read_ushort(stream)
            entry_name = u""
            if entry_name_len > 0:
                entry_name = StreamIO.read(stream, entry_name_len).decode("utf8")

            entry_type = NBTProvider.get_tag_class(entry_type_id)
            values[entry_name] = entry_type.read(stream)

            entry_type_id = StreamIO.read_ubyte(stream)

        return NBTTagCompound(values)
예제 #16
0
    def read(stream, packet_size):
        position = StreamIO.read_position(stream)
        face = StreamIO.read_byte(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))
        cursor_x = StreamIO.read_byte(stream)
        cursor_y = StreamIO.read_byte(stream)
        cursor_z = StreamIO.read_byte(stream)

        return PlayerBlockPlacementPacket(position, face, slot_data, cursor_x, cursor_y, cursor_z)
예제 #17
0
    def read(stream, packet_size):
        entity_id = StreamIO.read_int(stream)
        gamemode = StreamIO.read_ubyte(stream)
        dimension = StreamIO.read_int(stream)
        difficulty = StreamIO.read_ubyte(stream)
        max_players = StreamIO.read_ubyte(stream)
        level_type = StreamIO.read_string(stream).decode("utf8")
        debug_info = StreamIO.read_bool(stream)

        return JoinGamePacket(entity_id, gamemode, dimension, difficulty, max_players, level_type, debug_info)
예제 #18
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)
예제 #19
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_byte(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)
예제 #20
0
    def write(stream, tag):
        if tag is None:
            StreamIO.write_ubyte(0x00)
            return

        StreamIO.write_ubyte(stream, NBTTagCompound.TYPE_ID)
        StreamIO.write_ushort(stream, 0)

        NBTTagCompound.write(stream, tag)
예제 #21
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
예제 #22
0
    def read(stream, packet_size):
        slot = StreamIO.read_byte(stream)

        return HeldItemChangeClientPacket(slot)
예제 #23
0
 def write(stream, packet):
     StreamIO.write_byte(stream, packet.get_slot())
예제 #24
0
    def read(stream, packet_size):
        hand_type = StreamIO.read_varint(stream)

        return UseItemPacket(hand_type)
예제 #25
0
 def write(stream, packet):
     StreamIO.write_varint(stream, packet.get_hand_type())
예제 #26
0
    def read(stream, packet_size):
        action = StreamIO.read_varint(stream)

        return ClientStatusPacket(action)
예제 #27
0
 def write(stream, packet):
     StreamIO.write_varint(stream, packet.get_action())
예제 #28
0
 def write(stream, packet):
     StreamIO.write_ubyte(stream, packet.get_window_id())
     StreamIO.write_short(stream, packet.get_slot())
     StreamIO.write_byte(stream, packet.get_button())
     StreamIO.write_short(stream, packet.get_transaction_id())
     StreamIO.write_byte(stream, packet.get_mode())
     StreamIO.write_short(stream, packet.get_slot_data().get_id())
     if not packet.get_slot_data().is_empty():
         StreamIO.write_byte(stream, packet.get_slot_data().get_count())
         StreamIO.write_short(stream, packet.get_slot_data().get_damage())
         NBTSerializer.write(stream, packet.get_slot_data().get_tag())
예제 #29
0
    def read(stream, packet_size):
        slot = StreamIO.read_short(stream)

        return HeldItemChangeServerPacket(slot)
예제 #30
0
 def write(stream, packet):
     StreamIO.write_short(stream, packet.get_slot())