Skip to content

Commit

Permalink
Ensure onReady in client is called once (#1287)
Browse files Browse the repository at this point in the history
Fix #1286

Server sending start_config packets will incorrectly cause onReady to call multiple times
  • Loading branch information
extremeheat committed Feb 11, 2024
1 parent 092e10c commit 85a26a5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/client/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ module.exports = function (client, options) {

if (mcData.supportFeature('hasConfigurationState')) {
client.write('login_acknowledged', {})
enterConfigState()
enterConfigState(onReady)
// Server can tell client to re-enter config state
client.on('start_configuration', enterConfigState)
client.on('start_configuration', () => enterConfigState())
} else {
client.state = states.PLAY
onReady()
}

function enterConfigState () {
function enterConfigState (finishCb) {
if (client.state === states.CONFIGURATION) return
// If we are returning to the configuration state from the play state, we ahve to acknowledge it.
if (client.state === states.PLAY) {
Expand All @@ -57,7 +57,7 @@ module.exports = function (client, options) {
client.once('finish_configuration', () => {
client.write('finish_configuration', {})
client.state = states.PLAY
onReady()
finishCb?.()
})
}

Expand Down

0 comments on commit 85a26a5

Please sign in to comment.