mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-12-18 11:32:35 -05:00
5d723e9a04
* add node-fetch and @xboxreplay/xboxlive-auth for microsoft/xbox auth * decide which authentication to use based on options; if options.auth === 'microsoft' then use microsoft/xbox auth, else use Yggdrasil until they kill that. * push working auth * commentary * eslint does not like me :( * User-Agent works just fine without version * linting = 95% of development * revert changes to encrypt.js * set haveCredentials to whether or not we have a token. Technically this will always be true so...? * eslint * mod+create: api + example * mod: readme.md
32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
'use strict'
|
|
|
|
const mc = require('minecraft-protocol')
|
|
|
|
if (process.argv.length < 4 || process.argv.length > 6) {
|
|
console.log('Usage : node echo.js <host> <port> [<email>] [<password>]')
|
|
process.exit(1)
|
|
}
|
|
|
|
const client = mc.createClient({
|
|
host: process.argv[2],
|
|
port: parseInt(process.argv[3]),
|
|
username: process.argv[4], // your microsoft account email
|
|
password: process.argv[5], // 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 })
|
|
}
|
|
})
|