From 90d414335872f6216a010dcca52be9aaff8007eb Mon Sep 17 00:00:00 2001 From: Frej Alexander Nielsen Date: Sun, 19 Feb 2023 23:59:18 +0100 Subject: [PATCH] Fix client sending chat_session packet before server state transition (#1081) * Fix client sending session packet when server is in offline mode * Don't send chat session packet before server is in play state * Fix lint --------- Co-authored-by: Frej Alexander Nielsen --- src/client/play.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/client/play.js b/src/client/play.js index 4504129..5ca43d7 100644 --- a/src/client/play.js +++ b/src/client/play.js @@ -11,15 +11,10 @@ module.exports = function (client, options) { } }) - client.once('success', onLogin) + const mcData = require('minecraft-data')(client.version) - function onLogin (packet) { - const mcData = require('minecraft-data')(client.version) - client.state = states.PLAY - client.uuid = packet.uuid - client.username = packet.username - - if (mcData.supportFeature('useChatSessions') && client.profileKeys && client._cipher) { + client.once('login', () => { + if (mcData.supportFeature('useChatSessions') && client.profileKeys && client.cipher) { client._session = { index: 0, uuid: uuid.v4fast() @@ -32,6 +27,14 @@ module.exports = function (client, options) { signature: client.profileKeys ? client.profileKeys.signatureV2 : undefined }) } + }) + + client.once('success', onLogin) + + function onLogin (packet) { + client.state = states.PLAY + client.uuid = packet.uuid + client.username = packet.username if (mcData.supportFeature('signedChat')) { if (options.disableChatSigning && client.serverFeatures.enforcesSecureChat) {