From c6afe25429de7dc89c741eeaa9ca782430796884 Mon Sep 17 00:00:00 2001 From: joo Date: Wed, 12 Aug 2020 12:46:08 +0200 Subject: [PATCH] Remove 'UUIDIntegerArray' type, as 'UUID' already exists --- .../packets/clientbound/login/__init__.py | 6 ++-- minecraft/networking/types/basic.py | 36 +------------------ 2 files changed, 3 insertions(+), 39 deletions(-) diff --git a/minecraft/networking/packets/clientbound/login/__init__.py b/minecraft/networking/packets/clientbound/login/__init__.py index 1c1d866..38e0d8b 100644 --- a/minecraft/networking/packets/clientbound/login/__init__.py +++ b/minecraft/networking/packets/clientbound/login/__init__.py @@ -1,8 +1,7 @@ from minecraft.networking.packets import Packet from minecraft.networking.types import ( - VarInt, String, VarIntPrefixedByteArray, TrailingByteArray, - UUIDIntegerArray + VarInt, String, VarIntPrefixedByteArray, TrailingByteArray, UUID, ) @@ -56,8 +55,7 @@ class LoginSuccessPacket(Packet): packet_name = "login success" get_definition = staticmethod(lambda context: [ - {'UUID': UUIDIntegerArray} if context.protocol_version >= 707 - else {'UUID': String}, + {'UUID': UUID if context.protocol_version >= 707 else String}, {'Username': String} ]) diff --git a/minecraft/networking/types/basic.py b/minecraft/networking/types/basic.py index b2b1166..4ccf627 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', 'UUIDIntegerArray' + 'Position', ) @@ -253,40 +253,6 @@ class VarIntPrefixedByteArray(Type): socket.send(struct.pack(str(len(value)) + "s", value)) -# https://stackoverflow.com/questions/1604464/twos-complement-in-python -def twos_comp(val, bits): - """compute the 2's complement of int value val""" - if (val & (1 << (bits - 1))) != 0: # if sign bit is set - val = val - (1 << bits) # compute negative value - return val # return positive value as is - - -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 >> 32, - twos_comp(msb & 0xffffffff, 32), - lsb >> 32, - twos_comp(lsb & 0xffffffff, 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. """