mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-28 02:05:40 -05:00
2a2cc1ee92
* Update prismarine-auth usage add new `deviceType` parameter * remove whitespace * use nintendo switch title id * update examples
33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
'use strict'
|
|
|
|
const mc = require('minecraft-protocol')
|
|
|
|
const [,, host, port, userOrEmail, password] = process.argv
|
|
if (!userOrEmail) {
|
|
console.log('Usage : node client_microsoft_auth.js <host> <port> <username/email> [<password>]')
|
|
process.exit(1)
|
|
}
|
|
|
|
const client = mc.createClient({
|
|
host,
|
|
port: parseInt(port),
|
|
username: userOrEmail, // your microsoft account email
|
|
password: password, // your microsoft account password
|
|
auth: 'microsoft' // This option must be present and set to 'microsoft' to use Microsoft Account Authentication. Failure to do so will result in yggdrasil throwing invalid account information.
|
|
})
|
|
|
|
client.on('connect', function () {
|
|
console.info('connected')
|
|
})
|
|
client.on('disconnect', function (packet) {
|
|
console.log('disconnected: ' + packet.reason)
|
|
})
|
|
client.on('chat', function (packet) {
|
|
const jsonMsg = JSON.parse(packet.message)
|
|
if (jsonMsg.translate === 'chat.type.announcement' || jsonMsg.translate === 'chat.type.text') {
|
|
const username = jsonMsg.with[0].text
|
|
const msg = jsonMsg.with[1]
|
|
if (username === client.username) return
|
|
client.write('chat', { message: msg })
|
|
}
|
|
})
|