コード例 #1
0
    def packet_roundtrip(self, context, **kwds):
        packet = self.make_map_packet(context, **kwds)

        packet_buffer = PacketBuffer()
        packet.write(packet_buffer)

        packet_buffer.reset_cursor()

        # Read the length and packet id
        VarInt.read(packet_buffer)
        packet_id = VarInt.read(packet_buffer)
        self.assertEqual(packet_id, packet.id)

        p = MapPacket(context)
        p.read(packet_buffer)

        self.assertEqual(p.map_id, packet.map_id)
        self.assertEqual(p.scale, packet.scale)
        self.assertEqual(p.is_tracking_position, packet.is_tracking_position)
        self.assertEqual(p.width, packet.width)
        self.assertEqual(p.height, packet.height)
        self.assertEqual(p.offset, packet.offset)
        self.assertEqual(p.pixels, packet.pixels)
        self.assertEqual(str(p.icons[0]), str(packet.icons[0]))
        self.assertEqual(str(p.icons[1]), str(packet.icons[1]))
        self.assertEqual(str(p), str(packet))
コード例 #2
0
    def packet_roundtrip(self, context, **kwds):
        packet = self.make_map_packet(context, **kwds)

        packet_buffer = PacketBuffer()
        packet.write(packet_buffer)

        packet_buffer.reset_cursor()

        # Read the length and packet id
        VarInt.read(packet_buffer)
        packet_id = VarInt.read(packet_buffer)
        self.assertEqual(packet_id, packet.id)

        p = MapPacket(context)
        p.read(packet_buffer)

        self.assertEqual(p.map_id, packet.map_id)
        self.assertEqual(p.scale, packet.scale)
        self.assertEqual(p.is_tracking_position, packet.is_tracking_position)
        self.assertEqual(p.width, packet.width)
        self.assertEqual(p.height, packet.height)
        self.assertEqual(p.offset, packet.offset)
        self.assertEqual(p.pixels, packet.pixels)
        self.assertEqual(str(p.icons[0]), str(packet.icons[0]))
        self.assertEqual(str(p.icons[1]), str(packet.icons[1]))
        self.assertEqual(str(p), str(packet))
コード例 #3
0
    def make_map_packet(
            context, width=2, height=2, offset=(2, 2), pixels=b"this"):

        packet = MapPacket(context)

        packet.map_id = 1
        packet.scale = 42
        packet.is_tracking_position = True
        packet.is_locked = False
        packet.icons = []
        d_name = u'Marshmallow' if context.protocol_version >= 364 else None
        packet.icons.append(MapPacket.MapIcon(
            type=2, direction=2, location=(1, 1), display_name=d_name
        ))
        packet.icons.append(MapPacket.MapIcon(
            type=3, direction=3, location=(3, 3)
        ))
        packet.width = width
        packet.height = height if width else 0
        packet.offset = offset if width else None
        packet.pixels = pixels if width else None
        return packet
コード例 #4
0
    def test_map_set(self):
        map_set = MapPacket.MapSet()

        context = ConnectionContext(protocol_version=107)
        packet = self.make_map_packet(context)

        packet.apply_to_map_set(map_set)
        self.assertEqual(len(map_set.maps_by_id), 1)

        packet = self.make_map_packet(
            context, width=1, height=0, offset=(2, 2), pixels=b"x"
        )
        packet.apply_to_map_set(map_set)
        map = map_set.maps_by_id[1]
        self.assertIn(b"xh", map.pixels)
        self.assertIn(b"is", map.pixels)
        self.assertIsNotNone(str(map_set))
コード例 #5
0
    def make_map_packet(
            context, width=2, height=2, offset=(2, 2), pixels=b"this"):

        packet = MapPacket(context)

        packet.map_id = 1
        packet.scale = 42
        packet.is_tracking_position = True
        packet.is_locked = False
        packet.icons = []
        d_name = u'Marshmallow' if context.protocol_version >= 364 else None
        packet.icons.append(MapPacket.MapIcon(
            type=2, direction=2, location=(1, 1), display_name=d_name
        ))
        packet.icons.append(MapPacket.MapIcon(
            type=3, direction=3, location=(3, 3)
        ))
        packet.width = width
        packet.height = height if width else 0
        packet.offset = offset if width else None
        packet.pixels = pixels if width else None
        return packet
コード例 #6
0
    def make_map_packet(context,
                        width=2,
                        height=2,
                        offset=(2, 2),
                        pixels=b"this"):
        packet = MapPacket(context)

        packet.map_id = 1
        packet.scale = 42
        packet.is_tracking_position = True
        packet.icons = []
        packet.icons.append(
            MapPacket.MapIcon(type=2, direction=2, location=(1, 1)))
        packet.icons.append(
            MapPacket.MapIcon(type=3, direction=3, location=(3, 3)))
        packet.width = width
        packet.height = height
        packet.offset = offset
        packet.pixels = pixels
        return packet