From 76f7b4bdc990bbaaf66def85ba09928e9e4cff3e Mon Sep 17 00:00:00 2001 From: Tristan Gosselin-Hane Date: Fri, 20 Mar 2020 10:42:41 -0400 Subject: [PATCH] Added support for snapshot 20w12a --- minecraft/__init__.py | 1 + .../packets/clientbound/login/__init__.py | 11 +++++---- .../packets/clientbound/play/__init__.py | 6 +++-- .../clientbound/play/sound_effect_packet.py | 1 - minecraft/networking/types/basic.py | 24 ++++++++++++++++++- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/minecraft/__init__.py b/minecraft/__init__.py index 9bdbb39..722abed 100644 --- a/minecraft/__init__.py +++ b/minecraft/__init__.py @@ -231,6 +231,7 @@ SUPPORTED_MINECRAFT_VERSIONS = { '20w09a': 704, '20w10a': 705, '20w11a': 706, + '20w12a': 707, } # Those Minecraft versions supported by pyCraft which are "release" versions, diff --git a/minecraft/networking/packets/clientbound/login/__init__.py b/minecraft/networking/packets/clientbound/login/__init__.py index d323fe1..1c1d866 100644 --- a/minecraft/networking/packets/clientbound/login/__init__.py +++ b/minecraft/networking/packets/clientbound/login/__init__.py @@ -1,7 +1,8 @@ from minecraft.networking.packets import Packet from minecraft.networking.types import ( - VarInt, String, VarIntPrefixedByteArray, TrailingByteArray + VarInt, String, VarIntPrefixedByteArray, TrailingByteArray, + UUIDIntegerArray ) @@ -54,9 +55,11 @@ class LoginSuccessPacket(Packet): 0x02 packet_name = "login success" - definition = [ - {'UUID': String}, - {'Username': String}] + get_definition = staticmethod(lambda context: [ + {'UUID': UUIDIntegerArray} if context.protocol_version >= 707 + else {'UUID': String}, + {'Username': String} + ]) class SetCompressionPacket(Packet): diff --git a/minecraft/networking/packets/clientbound/play/__init__.py b/minecraft/networking/packets/clientbound/play/__init__.py index 30c62aa..8c602d0 100644 --- a/minecraft/networking/packets/clientbound/play/__init__.py +++ b/minecraft/networking/packets/clientbound/play/__init__.py @@ -206,7 +206,8 @@ class SpawnPlayerPacket(Packet): class EntityVelocityPacket(Packet): @staticmethod def get_id(context): - return 0x46 if context.protocol_version >= 550 else \ + return 0x47 if context.protocol_version >= 707 else \ + 0x46 if context.protocol_version >= 550 else \ 0x45 if context.protocol_version >= 471 else \ 0x41 if context.protocol_version >= 461 else \ 0x42 if context.protocol_version >= 451 else \ @@ -232,7 +233,8 @@ class EntityVelocityPacket(Packet): class UpdateHealthPacket(Packet): @staticmethod def get_id(context): - return 0x49 if context.protocol_version >= 550 else \ + return 0x4A if context.protocol_version >= 707 else \ + 0x49 if context.protocol_version >= 550 else \ 0x48 if context.protocol_version >= 471 else \ 0x44 if context.protocol_version >= 461 else \ 0x45 if context.protocol_version >= 451 else \ diff --git a/minecraft/networking/packets/clientbound/play/sound_effect_packet.py b/minecraft/networking/packets/clientbound/play/sound_effect_packet.py index 4c53a0e..da04940 100644 --- a/minecraft/networking/packets/clientbound/play/sound_effect_packet.py +++ b/minecraft/networking/packets/clientbound/play/sound_effect_packet.py @@ -13,7 +13,6 @@ class SoundEffectPacket(Packet): 0x51 if context.protocol_version >= 471 else \ 0x4D if context.protocol_version >= 461 else \ 0x4E if context.protocol_version >= 451 else \ - 0x4E if context.protocol_version >= 451 else \ 0x4D if context.protocol_version >= 389 else \ 0x4C if context.protocol_version >= 352 else \ 0x4B if context.protocol_version >= 345 else \ diff --git a/minecraft/networking/types/basic.py b/minecraft/networking/types/basic.py index 4ccf627..99aeba0 100644 --- a/minecraft/networking/types/basic.py +++ b/minecraft/networking/types/basic.py @@ -14,7 +14,7 @@ __all__ = ( 'Integer', 'FixedPointInteger', 'Angle', 'VarInt', 'Long', 'UnsignedLong', 'Float', 'Double', 'ShortPrefixedByteArray', 'VarIntPrefixedByteArray', 'TrailingByteArray', 'String', 'UUID', - 'Position', + 'Position', 'UUIDIntegerArray' ) @@ -253,6 +253,28 @@ class VarIntPrefixedByteArray(Type): socket.send(struct.pack(str(len(value)) + "s", value)) +class UUIDIntegerArray(Type): + """ Minecraft sends an array of 4 integers to represent the most + significant and least significant bits (as longs) of a UUID + because that is how UUIDs are constructed in Java. We need to + unpack this array and repack it with the right endianness to be + used as a python UUID. """ + @staticmethod + def read(file_object): + ints = struct.unpack("4i", file_object.read(4 * 4)) + packed = struct.pack("qq", player_uuid.bytes) + socket.send(struct.pack("4i", msb & 0xffffffff, msb >> 32, + lsb & 0xffffffff, lsb >> 32)) + + class TrailingByteArray(Type): """ A byte array consisting of all remaining data. If present in a packet definition, this should only be the type of the last field. """