Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions src/createClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ function createClient (options) {
break
case 'microsoft':
if (options.realms) {
microsoftAuth.realmAuthenticate(client, options).then(() => microsoftAuth.authenticate(client, options)).catch((err) => client.emit('error', err)).then(onReady)
// realm auth is async, so onReady() (which sets up registerChannel/pluginChannels) can
// still be pending when this function returns. mineflayer's loader checks wait_connect
// right after createClient() returns and, if unset, injects plugins immediately -
// crashing with "registerChannel is not a function" before onReady ever runs.
client.wait_connect = true
microsoftAuth.realmAuthenticate(client, options).then(() => microsoftAuth.authenticate(client, options)).catch((err) => client.emit('error', err)).then(() => {
onReady()
client.wait_connect = false

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Astra agent review — AI-generated, not manually written by the maintainer.

With options.version === false, onReady() starts autoVersion, which deliberately keeps client.wait_connect set while its asynchronous status ping chooses the protocol. This continuation immediately emits connect_allowed and clears that gate before the ping finishes, so Mineflayer can inject against the wrong version/schema. Also, the preceding .catch(err => client.emit(...)) resolves when an error listener handles the auth error, so this success continuation runs after failed authentication. Please keep one readiness owner: stop on auth/setup failure, and let auto-version completion release the gate when it is active. An explicit-version Realm case and a delayed auto-version case can be covered without live credentials by controlling the existing auth/ping boundaries.

Skills used: prismarine-review checked the current diff and discussion; prismarine-lifecycle-action-review traced asynchronous readiness and error paths; prismarine-architecture-review checked which function owns the gate.

client.emit('connect_allowed')
})
} else {
microsoftAuth.authenticate(client, options).catch((err) => client.emit('error', err))
onReady()
Expand All @@ -66,14 +75,18 @@ function createClient (options) {
}

function onReady () {
if (options.version === false) autoVersion(client, options)
setProtocol(client, options)
keepalive(client, options)
encrypt(client, options)
play(client, options)
compress(client, options)
pluginChannels(client, options)
versionChecking(client, options)
try {
if (options.version === false) autoVersion(client, options)
setProtocol(client, options)
keepalive(client, options)
encrypt(client, options)
play(client, options)
compress(client, options)
pluginChannels(client, options)
versionChecking(client, options)
} catch (err) {
client.emit('error', err)
}
}

return client
Expand Down
Loading