Skip to content

Commit

Permalink
Fix handling of disconnect in versionChecking on 1.20.3+. (#1291)
Browse files Browse the repository at this point in the history
* Fix handling of disconnect in versionChecking on 1.20.3+. Also handle newer translate string used in 1.20.2+

* Comments why we ignore PLAY and CONFIGURATION state disconnects, and un-inline an if

* Add extra comment on why we are ignoring those states.

* Change bitwise or to logical or
  • Loading branch information
wgaylord committed Mar 17, 2024
1 parent e50b604 commit ccab9fb
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/client/versionChecking.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const states = require('../states')

module.exports = function (client, options) {
client.on('disconnect', message => {
if (!message.reason) { return }
// Prevent the disconnect packet handler in the versionChecking code from triggering on PLAY or CONFIGURATION state disconnects
// Since version checking only happens during that HANDSHAKE / LOGIN state.
if (client.state === states.PLAY || client.state === states.CONFIGURATION) { return }
let parsed
try {
parsed = JSON.parse(message.reason)
Expand All @@ -11,7 +16,9 @@ module.exports = function (client, options) {
let text = parsed.text ? parsed.text : parsed
let versionRequired

if (text.translate && text.translate.startsWith('multiplayer.disconnect.outdated_')) { versionRequired = text.with[0] } else {
if (text.translate && (text.translate.startsWith('multiplayer.disconnect.outdated_') || text.translate.startsWith('multiplayer.disconnect.incompatible'))) {
versionRequired = text.with[0]
} else {
if (text.extra) text = text.extra[0].text
versionRequired = /(?:Outdated client! Please use|Outdated server! I'm still on) (.+)/.exec(text)
versionRequired = versionRequired ? versionRequired[1] : null
Expand Down

0 comments on commit ccab9fb

Please sign in to comment.