node-minecraft-protocol/examples/client_realms/client_realms.js
LucienHH 28093fb1fb
Realm Joining (#1056)
* Add docs

* Implement Realm joining

* Check for Microsoft auth

* Remove on chat event

* Add realmName option to example

* Passthrough client to `realmAuthenticate`

* Fix overwriting existing authflow

* Don't use  `??=`

* Lint
2023-01-15 18:30:33 +01:00

25 lines
754 B
JavaScript

'use strict'
const mc = require('minecraft-protocol')
const [,, username, realmName] = process.argv
if (!realmName) {
console.log('Usage : node client_realms.js <username/email> <realm_name>')
process.exit(1)
}
const client = mc.createClient({
realms: {
// realmId: '1234567', // Connect the client to a Realm using the Realms ID
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)
})