Add support for Minecraft 1.13 and 1.13-pre3 to pre10 (protocols 385 to 393).

Add clientbound.login.PluginRequestPacket and serverbound.login.PluginResponsePacket.
This commit is contained in:
joo committed 2018-07-19 09:50:13 +01:00
1 parent 745aa054b0
commit adc8d15ddc
19 files changed
+258 -48

No files matched your search

@@ -1,7 +1,7 @@
from minecraft.networking.packets import Packet
from minecraft.networking.types import (
String, VarIntPrefixedByteArray
VarInt, Boolean, String, VarIntPrefixedByteArray, TrailingByteArray
)
@@ -11,19 +11,67 @@ def get_packets(context):
LoginStartPacket,
EncryptionResponsePacket
}
if context.protocol_version >= 385:
packets |= {
PluginResponsePacket
}
return packets
class LoginStartPacket(Packet):
id = 0x00
@staticmethod
def get_id(context):
return 0x00 if context.protocol_version >= 391 else \
0x01 if context.protocol_version >= 385 else \
0x00
packet_name = "login start"
definition = [
{'name': String}]
class EncryptionResponsePacket(Packet):
id = 0x01
@staticmethod
def get_id(context):
return 0x01 if context.protocol_version >= 391 else \
0x02 if context.protocol_version >= 385 else \
0x01
packet_name = "encryption response"
definition = [
{'shared_secret': VarIntPrefixedByteArray},
{'verify_token': VarIntPrefixedByteArray}]
class PluginResponsePacket(Packet):
""" NOTE: see comments on 'clientbound.login.PluginRequestPacket' for
important information on the usage of this packet.
"""
@staticmethod
def get_id(context):
return 0x02 if context.protocol_version >= 391 else \
0x00
packet_name = 'login plugin response'
fields = (
'message_id', # str
'successful', # bool
'data', # bytes, or None if 'successful' is False
)
def read(self, file_object):
self.message_id = VarInt.read(file_object)
self.successful = Boolean.read(file_object)
if self.successful:
self.data = TrailingByteArray.read(file_object)
else:
self.data = None
def write_fields(self, packet_buffer):
VarInt.send(self.message_id, packet_buffer)
successful = getattr(self, 'data', None) is not None
successful = getattr(self, 'successful', successful)
Boolean.send(successful, packet_buffer)
if successful:
TrailingByteArray.send(self.data, packet_buffer)