Esempio n. 1
0
 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)
Esempio n. 2
0
 def write(self, socket, compression_threshold=None):
     # buffer the data since we need to know the length of each packet's
     # payload
     packet_buffer = PacketBuffer()
     # write packet's id right off the bat in the header
     VarInt.send(self.id, packet_buffer)
     # write every individual field
     self.write_fields(packet_buffer)
     self.data = copy.deepcopy(packet_buffer.bytes.getvalue())
     self._write_buffer(socket, packet_buffer, compression_threshold)
Esempio n. 3
0
    def write_fields(self, packet_buffer):
        VarInt.send(self.entity_id, packet_buffer)
        if self.context.protocol_version >= 49:
            UUID.send(self.object_uuid, packet_buffer)

        if self.context.protocol_version >= 458:
            VarInt.send(self.type_id, packet_buffer)
        else:
            Byte.send(self.type_id, packet_buffer)

        # pylint: disable=no-member
        xyz_type = Double if self.context.protocol_version >= 100 else Integer
        for coord in self.x, self.y, self.z:
            xyz_type.send(coord, packet_buffer)
        for coord in self.pitch, self.yaw:
            Angle.send(coord, packet_buffer)

        Integer.send(self.data, packet_buffer)
        if self.context.protocol_version >= 49 or self.data > 0:
            for coord in self.velocity_x, self.velocity_y, self.velocity_z:
                Short.send(coord, packet_buffer)
Esempio n. 4
0
    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)
Esempio n. 5
0
 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)
Esempio n. 6
0
    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)
Esempio n. 7
0
    def _write_buffer(self, socket, packet_buffer, compression_threshold):
        # compression_threshold of None means compression is disabled
        if compression_threshold is not None:
            if len(packet_buffer.get_writable()) > compression_threshold != -1:
                # compress the current payload
                packet_data = packet_buffer.get_writable()
                compressed_data = compress(packet_data)
                packet_buffer.reset()
                # write out the length of the uncompressed payload
                VarInt.send(len(packet_data), packet_buffer)
                # write the compressed payload itself
                packet_buffer.send(compressed_data)
            else:
                # write out a 0 to indicate uncompressed data
                packet_data = packet_buffer.get_writable()
                packet_buffer.reset()
                VarInt.send(0, packet_buffer)
                packet_buffer.send(packet_data)

        VarInt.send(len(packet_buffer.get_writable()), socket)  # Packet Size
        socket.send(packet_buffer.get_writable())  # Packet Payload
Esempio n. 8
0
 def write_fields(self, packet_buffer):
     VarInt.send(self.event.id, packet_buffer)
     self.event.write(packet_buffer)
Esempio n. 9
0
 def write(self, packet_buffer):
     VarInt.send(self.player_id, packet_buffer)
     Integer.send(self.entity_id, packet_buffer)
     String.send(self.message, packet_buffer)
Esempio n. 10
0
 def write(self, packet_buffer):
     VarInt.send(self.duration, packet_buffer)
     Integer.send(self.entity_id, packet_buffer)
Esempio n. 11
0
 def write_fields(self, packet_buffer):
     Integer.send(self.chunk_x, packet_buffer)
     Integer.send(self.chunk_z, packet_buffer)
     VarInt.send(len(self.records), packet_buffer)
     for record in self.records:
         record.write(packet_buffer)
Esempio n. 12
0
 def write(self, packet_buffer):
     UnsignedByte.send(self.x << 4 | self.z & 0xF, packet_buffer)
     UnsignedByte.send(self.y, packet_buffer)
     VarInt.send(self.block_state_id, packet_buffer)
Esempio n. 13
0
 def write_fields(self, packet_buffer):
     VarInt.send(self.action_type.action_id, packet_buffer)
     VarInt.send(len(self.actions), packet_buffer)
     for action in self.actions:
         action.send(packet_buffer)
Esempio n. 14
0
 def _send(self, packet_buffer):
     VarInt.send(self.ping, packet_buffer)
Esempio n. 15
0
 def _send(self, packet_buffer):
     VarInt.send(self.gamemode, packet_buffer)