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

+2 -2
View File
@@ -89,11 +89,11 @@ class FakeClientHandler(object):
# Handshake packet, which is provided as an argument.
pass
def handle_login(self, join_game_packet):
def handle_login(self, login_start_packet):
# Called to transition from the login state to the play state, after
# compression and encryption, if applicable, have been set up. The
# client's LoginStartPacket is given as an argument.
self.user_name = join_game_packet.name
self.user_name = login_start_packet.name
self.user_uuid = uuid.UUID(bytes=hashlib.md5(
('OfflinePlayer:%s' % self.user_name).encode('utf8')).digest())
self.write_packet(clientbound.login.LoginSuccessPacket(
+47 -2
View File
@@ -1,9 +1,9 @@
from minecraft import SUPPORTED_MINECRAFT_VERSIONS
from minecraft import SUPPORTED_PROTOCOL_VERSIONS
from minecraft.networking.packets import clientbound, serverbound
from minecraft.networking.connection import Connection, IgnorePacket
from minecraft.networking.connection import Connection
from minecraft.exceptions import (
VersionMismatch, LoginDisconnect, InvalidState
VersionMismatch, LoginDisconnect, InvalidState, IgnorePacket
)
from minecraft.compat import unicode
@@ -134,6 +134,51 @@ class ConnectStatusTest(ConnectTwiceTest):
client.status()
class LoginPluginTest(fake_server._FakeServerTest):
class client_handler_type(fake_server.FakeClientHandler):
def handle_login(self, login_start_packet):
request = clientbound.login.PluginRequestPacket(
message_id=1, channel='pyCraft:tests/fail', data=b'ignored')
self.write_packet(request)
response = self.read_packet()
assert isinstance(response, serverbound.login.PluginResponsePacket)
assert response.message_id == request.message_id
assert response.successful is False
assert response.data is None
request = clientbound.login.PluginRequestPacket(
message_id=2, channel='pyCraft:tests/echo', data=b'hello')
self.write_packet(request)
response = self.read_packet()
assert isinstance(response, serverbound.login.PluginResponsePacket)
assert response.message_id == request.message_id
assert response.successful is True
assert response.data == request.data
super(LoginPluginTest.client_handler_type, self) \
.handle_login(login_start_packet)
def handle_play_start(self):
super(LoginPluginTest.client_handler_type, self) \
.handle_play_start()
raise fake_server.FakeServerDisconnect
def _start_client(self, client):
def handle_plugin_request(packet):
if packet.channel == 'pyCraft:tests/echo':
client.write_packet(serverbound.login.PluginResponsePacket(
message_id=packet.message_id, data=packet.data))
raise IgnorePacket
client.register_packet_listener(
handle_plugin_request, clientbound.login.PluginRequestPacket,
early=True)
super(LoginPluginTest, self)._start_client(client)
def test_login_plugin_messages(self):
self._test_connect()
class EarlyPacketListenerTest(ConnectTest):
""" Early packet listeners should be called before ordinary ones, even when
the early packet listener is registered afterwards.
+7
View File
@@ -3,17 +3,23 @@ try:
from unittest import mock
except ImportError:
import mock
from minecraft import SUPPORTED_PROTOCOL_VERSIONS
from minecraft.networking.connection import (
LoginReactor, PlayingReactor, ConnectionContext
)
from minecraft.networking.packets import clientbound
max_proto_ver = max(SUPPORTED_PROTOCOL_VERSIONS)
class LoginReactorTest(unittest.TestCase):
@mock.patch('minecraft.networking.connection.encryption')
def test_encryption_online_server(self, encrypt):
connection = mock.MagicMock()
connection.context = ConnectionContext(protocol_version=max_proto_ver)
reactor = LoginReactor(connection)
packet = clientbound.login.EncryptionRequestPacket()
@@ -37,6 +43,7 @@ class LoginReactorTest(unittest.TestCase):
@mock.patch('minecraft.networking.connection.encryption')
def test_encryption_offline_server(self, encrypt):
connection = mock.MagicMock()
connection.context = ConnectionContext(protocol_version=max_proto_ver)
reactor = LoginReactor(connection)
packet = clientbound.login.EncryptionRequestPacket()