Fix: MapPacket.write_fields() is incorrect.

This commit is contained in:
joo 2018-05-27 17:12:50 +01:00
parent 8578326c2f
commit db714f9490
3 changed files with 34 additions and 16 deletions

View File

@ -114,11 +114,20 @@ class MapPacket(Packet):
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)
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:

View File

@ -45,26 +45,28 @@ class MapPacketTest(unittest.TestCase):
@staticmethod
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))
)
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
packet.offset = offset
packet.pixels = pixels
packet.height = height if width else 0
packet.offset = offset if width else None
packet.pixels = pixels if width else None
return packet
def packet_roundtrip(self, context):
packet = self.make_map_packet(context)
def packet_roundtrip(self, context, **kwds):
packet = self.make_map_packet(context, **kwds)
packet_buffer = PacketBuffer()
packet.write(packet_buffer)
@ -93,6 +95,9 @@ class MapPacketTest(unittest.TestCase):
def test_packet_roundtrip(self):
self.packet_roundtrip(ConnectionContext(protocol_version=106))
self.packet_roundtrip(ConnectionContext(protocol_version=107))
self.packet_roundtrip(ConnectionContext(protocol_version=379))
self.packet_roundtrip(ConnectionContext(protocol_version=379),
width=0)
def test_map_set(self):
map_set = MapPacket.MapSet()

View File

@ -4,7 +4,8 @@ import unittest
from minecraft.networking.types import (
Type, Boolean, UnsignedByte, Byte, Short, UnsignedShort,
Integer, VarInt, Long, Float, Double, ShortPrefixedByteArray,
VarIntPrefixedByteArray, UUID, String as StringType
VarIntPrefixedByteArray, UUID, String as StringType, Position,
TrailingByteArray, UnsignedLong,
)
from minecraft.networking.packets import PacketBuffer
@ -15,6 +16,7 @@ TEST_DATA = {
Byte: [-22, 22],
Short: [-340, 22, 350],
UnsignedShort: [0, 400],
UnsignedLong: [0, 400],
Integer: [-1000, 1000],
VarInt: [1, 250, 50000, 10000000],
Long: [50000000],
@ -22,8 +24,10 @@ TEST_DATA = {
Double: [36.004002],
ShortPrefixedByteArray: [bytes(245)],
VarIntPrefixedByteArray: [bytes(1234)],
TrailingByteArray: [b'Q^jO<5*|+o LGc('],
UUID: ["12345678-1234-5678-1234-567812345678"],
StringType: ["hello world"]
StringType: ["hello world"],
Position: [(758, 0, 691)],
}