From c4ed8e6d68566b4dd6e4562b0d88d2fe4ad895b2 Mon Sep 17 00:00:00 2001 From: joo Date: Sun, 25 Sep 2016 22:16:46 +0200 Subject: [PATCH] Add support for Minecraft pre-release 16w36a (protocol 305). Add max_length property to ChatPacket. --- minecraft/__init__.py | 1 + minecraft/networking/packets.py | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/minecraft/__init__.py b/minecraft/__init__.py index b80249b..4975811 100644 --- a/minecraft/__init__.py +++ b/minecraft/__init__.py @@ -26,6 +26,7 @@ SUPPORTED_MINECRAFT_VERSIONS = { '16w33a': 303, '16w35a': 304, '16w36a': 305, + '16w38a': 306, } SUPPORTED_PROTOCOL_VERSIONS = sorted(SUPPORTED_MINECRAFT_VERSIONS.values()) diff --git a/minecraft/networking/packets.py b/minecraft/networking/packets.py index 07ada31..5b31fea 100644 --- a/minecraft/networking/packets.py +++ b/minecraft/networking/packets.py @@ -86,9 +86,12 @@ class Packet(object): @context.setter def context(self, _context): self._context = _context - if _context is not None: - self.id = self.get_id(_context) - self.definition = self.get_definition(_context) + self._context_changed() + + def _context_changed(self): + if self._context is not None: + self.id = self.get_id(self._context) + self.definition = self.get_definition(self._context) else: self.id = None self.definition = None @@ -700,6 +703,16 @@ class ChatPacket(Packet): return 0x02 if context.protocol_version >= 107 else \ 0x01 + @staticmethod + def get_max_length(context): + return 256 if context.protocol_version >= 305 else \ + 100 + + @property + def max_length(self): + if self.context is not None: + return self.get_max_length(self.context) + packet_name = "chat" definition = [ {'message': String}]