client: wait for realm+microsoft auth before signaling connect_allowed - #1530
Open
DallasCarraher wants to merge 1 commit into
Open
DallasCarraher wants to merge 1 commit into
DallasCarraher wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
For
auth: 'microsoft'+realms,onReady()— which wires upsetProtocol,keepalive,encrypt,play,compress,pluginChannels(client.registerChannel), andversionChecking— only runs after therealmAuthenticate().then(authenticate)promise chain resolves. Nothing signals that delay to consumers, though:client.wait_connectis never set on this path, so mineflayer'sloader.js(if (!bot._client.wait_connect) next()) runs plugin injection immediately, beforeonReady()has executed at all.Any consumer that pins an explicit version — skipping
autoVersion.js, the only other placewait_connectgets set — crashes withbot._client.registerChannel is not a functionas soon as mineflayer'sgameplugin 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 ownlib/version.js/client.tsconventions around never usingversion: 'auto'), so realm connections are broken for exactly the use case this library is meant to support.The fix mirrors the existing
autoVersion.jsidiom exactly: setclient.wait_connect = truebefore the async work starts, emitconnect_allowedand 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
standardlint cleancreateBot()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