Skip to content

client: wait for realm+microsoft auth before signaling connect_allowed - #1530

Open
DallasCarraher wants to merge 1 commit into
PrismarineJS:masterfrom
DallasCarraher:pc-realm-microsoft-wait-connect
Open

DallasCarraher wants to merge 1 commit into
PrismarineJS:masterfrom
DallasCarraher:pc-realm-microsoft-wait-connect

Conversation

@DallasCarraher

Copy link
Copy Markdown

Summary

For auth: 'microsoft' + realms, onReady() — which wires up setProtocol, keepalive, encrypt, play, compress, pluginChannels (client.registerChannel), and versionChecking — only runs after the realmAuthenticate().then(authenticate) promise chain resolves. Nothing signals that delay to consumers, though: client.wait_connect is never set on this path, so mineflayer's loader.js (if (!bot._client.wait_connect) next()) runs plugin injection immediately, before onReady() has executed at all.

Any consumer that pins an explicit version — skipping autoVersion.js, the only other place wait_connect gets set — crashes with bot._client.registerChannel is not a function as soon as mineflayer's game plugin injects, before the device-code sign-in prompt even has a chance to appear. This is the documented, recommended way to use mineflayer in production (see its own lib/version.js/client.ts conventions around never using version: 'auto'), so realm connections are broken for exactly the use case this library is meant to support.

The fix mirrors the existing autoVersion.js idiom exactly: set client.wait_connect = true before the async work starts, emit connect_allowed and clear the flag once it resolves.

Scope: only touches auth:'microsoft' + realms. The direct (non-realm) microsoft branch, offline auth, and mojang auth are untouched.

Test plan

  • standard lint clean
  • Live-validated against a real Minecraft Realm (Java Edition, protocol 776) using mineflayer's own createBot() with an explicitly pinned version and a real Microsoft account: reproduced the crash on every attempt before this fix (failed within ~1s, before any device-code prompt appeared); after the fix, device-code sign-in, realm resolution, and connection all completed normally and the bot spawned successfully
  • No existing test coverage exercises this path (it requires live realm + Microsoft credentials), so I haven't added an automated regression test — happy to sketch one with a mocked Authflow if that's wanted

For auth:'microsoft' + realms, onReady() (which wires up setProtocol,
keepalive, encrypt, play, compress, pluginChannels, versionChecking —
including client.registerChannel) only runs after the
realmAuthenticate().then(authenticate) promise chain resolves. But
nothing signaled that delay to consumers: client.wait_connect was
never set, so mineflayer's loader.js (`if (!bot._client.wait_connect)
next()`) ran plugin injection immediately, before onReady() had ever
executed. Any consumer that pins an explicit version (skipping
autoVersion, the only other place wait_connect gets set) crashed with
`bot._client.registerChannel is not a function` as soon as the 'game'
plugin injected — before the device-code prompt even had a chance to
appear.

Mirrors the existing autoVersion.js idiom exactly: set
client.wait_connect = true before the async work starts, emit
'connect_allowed' and clear the flag once it's done.

Only affects auth:'microsoft' + realms + an explicitly pinned version
(the documented, recommended way to use this library in production —
see PrismarineJS/mineflayer's own version.js comments). The direct
(non-realm) microsoft branch and offline/mojang auth are untouched.

Validated live: previously reproduced the crash on every attempt
against a real Minecraft Realm (Java, protocol 776) using
mineflayer's own createBot() with a pinned version and a real
Microsoft account; with this fix, device-code sign-in, realm
resolution, and connection all completed normally and the bot spawned.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant