mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-14 19:04:59 -05:00
Ensure onReady
in client is called once (#1287)
Fix https://github.com/PrismarineJS/node-minecraft-protocol/issues/1286 Server sending start_config packets will incorrectly cause onReady to call multiple times
This commit is contained in:
parent
092e10c53d
commit
85a26a5294
1 changed files with 4 additions and 4 deletions
|
@ -37,15 +37,15 @@ module.exports = function (client, options) {
|
||||||
|
|
||||||
if (mcData.supportFeature('hasConfigurationState')) {
|
if (mcData.supportFeature('hasConfigurationState')) {
|
||||||
client.write('login_acknowledged', {})
|
client.write('login_acknowledged', {})
|
||||||
enterConfigState()
|
enterConfigState(onReady)
|
||||||
// Server can tell client to re-enter config state
|
// Server can tell client to re-enter config state
|
||||||
client.on('start_configuration', enterConfigState)
|
client.on('start_configuration', () => enterConfigState())
|
||||||
} else {
|
} else {
|
||||||
client.state = states.PLAY
|
client.state = states.PLAY
|
||||||
onReady()
|
onReady()
|
||||||
}
|
}
|
||||||
|
|
||||||
function enterConfigState () {
|
function enterConfigState (finishCb) {
|
||||||
if (client.state === states.CONFIGURATION) return
|
if (client.state === states.CONFIGURATION) return
|
||||||
// If we are returning to the configuration state from the play state, we ahve to acknowledge it.
|
// If we are returning to the configuration state from the play state, we ahve to acknowledge it.
|
||||||
if (client.state === states.PLAY) {
|
if (client.state === states.PLAY) {
|
||||||
|
@ -57,7 +57,7 @@ module.exports = function (client, options) {
|
||||||
client.once('finish_configuration', () => {
|
client.once('finish_configuration', () => {
|
||||||
client.write('finish_configuration', {})
|
client.write('finish_configuration', {})
|
||||||
client.state = states.PLAY
|
client.state = states.PLAY
|
||||||
onReady()
|
finishCb?.()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue