PrismarineJS / node-minecraft-protocol

Parse and serialize minecraft packets, plus authentication and encryption.
https://prismarinejs.github.io/node-minecraft-protocol/
BSD 3-Clause "New" or "Revised" License
1.2k stars 241 forks source link

pickRealm silently fails to connect #1302

Open B2H990 opened 2 months ago

B2H990 commented 2 months ago
'use strict'

const mineflayer = require('mineflayer')

const [,, username, realmName] = process.argv
if (!realmName) {
  console.log('Usage : node client_realms.js <username/email> <realm_name>')
  process.exit(1)
}

const client = mineflayer.createBot({
  realms: {
    pickRealm: (realms) => realms.find(e => e.name === realmName) // Connect the client to a Realm using a function that returns a Realm
  },
  username,
  auth: 'microsoft' // This option must be present and set to 'microsoft' to  join a Realm.
})

client.on('connect', function () {
  console.info('connected')
})

client.on('disconnect', function (packet) {
  console.log('disconnected: ' + packet.reason)
})

prints connected, but never actually connects to realm.

extremeheat commented 2 months ago

cc @LucienHH

B2H990 commented 2 months ago

This works:

const bot = mineflayer.createBot({
    host: 'realhost',
    realms: {
        pickRealm: (realms) => realms[0]
    },
    auth: 'microsoft'
})

But not this:

const bot = mineflayer.createBot({
    realms: {
        pickRealm: (realms) => realms[0]
    },
    auth: 'microsoft'
})
extremeheat commented 2 months ago

That is strange since the realm handling will replace the host and port with the correct one. Can anyone else with realms reproduce?

extremeheat commented 1 month ago

If you can still repro with latest, can you add process.env.DEBUG = '*' to the top of your code and provide the debug console output?

B2H990 commented 1 month ago

I am able to reproduce the issue on latest. The debug log has sensitive information that I would rather not post publicly on a github issue. Is there another way I can send it to you?

extremeheat commented 1 month ago

Ah, I think I see the issue. We're not waiting for realm auth (where host information gets deduced) inside https://github.com/PrismarineJS/node-minecraft-protocol/blob/master/src/createClient.js#L50 before loading the other plugins (so at their init time there is indeed no host/port which can cause problems).

I'll transfer the issue to nmp