Example #1
0
 def send_with_context(value, socket, context):
     if context.protocol_version < 204:
         value *= 63.5
     if context.protocol_version >= 201:
         Float.send(value, socket)
     else:
         Byte.send(int(value), socket)
 def send_with_context(value, socket, context):
     if context.protocol_earlier(204):
         value *= 63.5
     if context.protocol_later_eq(201):
         Float.send(value, socket)
     else:
         Byte.send(int(value), socket)
Example #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)
        Byte.send(self.type_id, packet_buffer)

        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:
            UnsignedByte.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)
    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)

        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:
            UnsignedByte.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)
 def make_modlist_packet(self, packet):
     packet.channel = 'FML|HS'
     buffer = PacketBuffer()
     Byte.send(2, buffer)
     modlist = []
     __location__ = os.path.realpath(
         os.path.join(os.getcwd(), os.path.dirname(__file__)))
     with open(os.path.join(__location__, 'modlist5.txt'), 'r') as f:
         mods = f.read().split(',')
         for mod in mods:
             mod_name = mod.split('@')[0]
             mod_version = mod[len(mod_name) + 1:]
             modlist.append([mod_name, mod_version])
     VarInt.send(len(modlist), buffer)
     for mod in modlist:
         String.send(mod[0], buffer)
         String.send(mod[1], buffer)
     buffer.reset_cursor()
     packet.data = buffer.read()
     print(packet.data)
Example #6
0
    def write_fields(self, packet_buffer):
        VarInt.send(self.entity_id, packet_buffer)
        if self.context.protocol_later_eq(49):
            UUID.send(self.object_uuid, packet_buffer)

        if self.context.protocol_later_eq(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_later_eq(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_later_eq(49) or self.data > 0:
            for coord in self.velocity_x, self.velocity_y, self.velocity_z:
                Short.send(coord, 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)
Example #8
0
    def write(self, socket, compression_threshold=None):
        packet_buffer = PacketBuffer()
        VarInt.send(self.id, 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:
            type_and_direction = (icon.direction << 4) & 0xF0
            type_and_direction |= (icon.type & 0xF)
            UnsignedByte.send(type_and_direction, packet_buffer)
            Byte.send(icon.location[0], packet_buffer)
            Byte.send(icon.location[1], 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)

        self._write_buffer(socket, packet_buffer, compression_threshold)
Example #9
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)
Example #10
0
 def write_fields(self, packet_buffer):
     Float.send(self.x, packet_buffer)
     Float.send(self.y, packet_buffer)
     Float.send(self.z, packet_buffer)
     Float.send(self.radius, packet_buffer)
     Integer.send(len(self.records), packet_buffer)
     for record in self.records:
         Byte.send(record.x, packet_buffer)
         Byte.send(record.y, packet_buffer)
         Byte.send(record.z, packet_buffer)
     Float.send(self.player_motion_x, packet_buffer)
     Float.send(self.player_motion_y, packet_buffer)
     Float.send(self.player_motion_z, packet_buffer)
Example #11
0
 def write_fields(self, packet_buffer):
     Float.send(self.x, packet_buffer)
     Float.send(self.y, packet_buffer)
     Float.send(self.z, packet_buffer)
     Float.send(self.radius, packet_buffer)
     Integer.send(len(self.records), packet_buffer)
     for record in self.records:
         Byte.send(record.x, packet_buffer)
         Byte.send(record.y, packet_buffer)
         Byte.send(record.z, packet_buffer)
     Float.send(self.player_motion_x, packet_buffer)
     Float.send(self.player_motion_y, packet_buffer)
     Float.send(self.player_motion_z, packet_buffer)
Example #12
0
 def send(cls, record, socket):
     for coord in record:
         Byte.send(coord, socket)