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)
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)
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)
def read(stream): values = [] len = StreamIO.read_long(stream) for i in xrange(len): values.append(StreamIO.read_long(stream)) return NBTTagLongArray(values)
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)
def read(stream): values = [] len = StreamIO.read_int(stream) for i in xrange(len): values.append(StreamIO.read_byte(stream)) return NBTTagByteArray(values)
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)
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())
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)
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())
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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
def read(stream, packet_size): slot = StreamIO.read_byte(stream) return HeldItemChangeClientPacket(slot)
def write(stream, packet): StreamIO.write_byte(stream, packet.get_slot())
def read(stream, packet_size): hand_type = StreamIO.read_varint(stream) return UseItemPacket(hand_type)
def write(stream, packet): StreamIO.write_varint(stream, packet.get_hand_type())
def read(stream, packet_size): action = StreamIO.read_varint(stream) return ClientStatusPacket(action)
def write(stream, packet): StreamIO.write_varint(stream, packet.get_action())
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())
def read(stream, packet_size): slot = StreamIO.read_short(stream) return HeldItemChangeServerPacket(slot)
def write(stream, packet): StreamIO.write_short(stream, packet.get_slot())