def write_fields(self, packet_buffer): VarInt.send(self.message_id, packet_buffer) successful = getattr(self, 'data', None) is not None successful = getattr(self, 'successful', successful) Boolean.send(successful, packet_buffer) if successful: TrailingByteArray.send(self.data, packet_buffer)
def write_fields(self, packet_buffer): VarInt.send(self.map_id, packet_buffer) Byte.send(self.scale, packet_buffer) if self.context.protocol_version >= 107: Boolean.send(self.is_tracking_position, packet_buffer) VarInt.send(len(self.icons), packet_buffer) for icon in self.icons: if self.context.protocol_version >= 373: VarInt.send(icon.type, packet_buffer) else: type_and_direction = (icon.type << 4) & 0xF0 type_and_direction |= (icon.direction & 0xF) UnsignedByte.send(type_and_direction, packet_buffer) Byte.send(icon.location[0], packet_buffer) Byte.send(icon.location[1], packet_buffer) if self.context.protocol_version >= 373: UnsignedByte.send(icon.direction, packet_buffer) if self.context.protocol_version >= 364: Boolean.send(icon.display_name is not None, packet_buffer) if icon.display_name is not None: String.send(icon.display_name, packet_buffer) UnsignedByte.send(self.width, packet_buffer) if self.width: UnsignedByte.send(self.height, packet_buffer) UnsignedByte.send(self.offset[0], packet_buffer) # x UnsignedByte.send(self.offset[1], packet_buffer) # z VarIntPrefixedByteArray.send(self.pixels, packet_buffer)
def send(self, packet_buffer): String.send(self.name, packet_buffer) String.send(self.value, packet_buffer) if self.signature is not None: Boolean.send(True, packet_buffer) String.send(self.signature, packet_buffer) else: Boolean.send(False, packet_buffer)
def _send(self, packet_buffer): String.send(self.name, packet_buffer) VarInt.send(len(self.properties), packet_buffer) for property in self.properties: property.send(packet_buffer) VarInt.send(self.gamemode, packet_buffer) VarInt.send(self.ping, packet_buffer) if self.display_name is not None: Boolean.send(True, packet_buffer) String.send(self.display_name, packet_buffer) else: Boolean.send(False, packet_buffer)
def read(self, file_object): self.message_id = VarInt.read(file_object) self.successful = Boolean.read(file_object) if self.successful: self.data = TrailingByteArray.read(file_object) else: self.data = None
def read(self, file_object): self.name = String.read(file_object) self.value = String.read(file_object) is_signed = Boolean.read(file_object) if is_signed: self.signature = String.read(file_object) else: self.signature = None
def read(self, file_object): self.map_id = VarInt.read(file_object) self.scale = Byte.read(file_object) if self.context.protocol_version >= 107: self.is_tracking_position = Boolean.read(file_object) else: self.is_tracking_position = True if self.context.protocol_version >= 452: self.is_locked = Boolean.read(file_object) else: self.is_locked = False icon_count = VarInt.read(file_object) self.icons = [] for i in range(icon_count): if self.context.protocol_version >= 373: type = VarInt.read(file_object) else: type, direction = divmod(UnsignedByte.read(file_object), 16) x = Byte.read(file_object) z = Byte.read(file_object) if self.context.protocol_version >= 373: direction = UnsignedByte.read(file_object) if self.context.protocol_version >= 364: has_name = Boolean.read(file_object) display_name = String.read(file_object) if has_name else None else: display_name = None icon = MapPacket.MapIcon(type, direction, (x, z), display_name) self.icons.append(icon) self.width = UnsignedByte.read(file_object) if self.width: self.height = UnsignedByte.read(file_object) x = Byte.read(file_object) z = Byte.read(file_object) self.offset = (x, z) self.pixels = VarIntPrefixedByteArray.read(file_object) else: self.height = 0 self.offset = None self.pixels = None
def read(self, file_object): if self.context.protocol_version >= 353: self.origin = VarInt.read(file_object) self.x = Double.read(file_object) self.y = Double.read(file_object) self.z = Double.read(file_object) is_entity = Boolean.read(file_object) if is_entity: # If the entity given by entity ID cannot be found, # this packet should be treated as if is_entity was false. self.entity_id = VarInt.read(file_object) self.entity_origin = VarInt.read(file_object) else: self.entity_id = None else: # Protocol version 352 is_entity = Boolean.read(file_object) self.entity_id = VarInt.read(file_object) if is_entity else None if not is_entity: self.x = Double.read(file_object) self.y = Double.read(file_object) self.z = Double.read(file_object)
def _read(self, file_object): self.name = String.read(file_object) prop_count = VarInt.read(file_object) self.properties = [] for i in range(prop_count): property = PlayerListItemPacket.PlayerProperty() property.read(file_object) self.properties.append(property) self.gamemode = VarInt.read(file_object) self.ping = VarInt.read(file_object) has_display_name = Boolean.read(file_object) if has_display_name: self.display_name = String.read(file_object) else: self.display_name = None
def write_fields(self, packet_buffer): if self.context.protocol_version >= 353: VarInt.send(self.origin, packet_buffer) Double.send(self.x, packet_buffer) Double.send(self.y, packet_buffer) Double.send(self.z, packet_buffer) if self.entity_id is not None: Boolean.send(True, packet_buffer) VarInt.send(self.entity_id, packet_buffer) VarInt.send(self.entity_origin, packet_buffer) else: Boolean.send(False, packet_buffer) else: # Protocol version 352 if self.entity_id is not None: Boolean.send(True, packet_buffer) VarInt.send(self.entity_id, packet_buffer) else: Boolean.send(False, packet_buffer) Double.send(self.x, packet_buffer) Double.send(self.y, packet_buffer) Double.send(self.z, packet_buffer)
def _send(self, packet_buffer): if self.display_name is not None: Boolean.send(True, packet_buffer) String.send(self.display_name, packet_buffer) else: Boolean.send(False, packet_buffer)
def _read(self, file_object): has_display_name = Boolean.read(file_object) if has_display_name: self.display_name = String.read(file_object) else: self.display_name = None