2018-05-13 16:50:16 -04:00
|
|
|
const mc = require('minecraft-protocol')
|
2016-08-10 12:54:06 -04:00
|
|
|
|
2018-05-13 16:50:16 -04:00
|
|
|
if (process.argv.length < 4 || process.argv.length > 6) {
|
|
|
|
console.log('Usage : node client_channel.js <host> <port> [<name>] [<password>]')
|
|
|
|
process.exit(1)
|
2016-08-10 12:54:06 -04:00
|
|
|
}
|
|
|
|
|
2023-05-20 08:44:03 -04:00
|
|
|
function getBrandChannelName () {
|
|
|
|
const mcData = require('minecraft-data')(client.version)
|
|
|
|
if (mcData.supportFeature('customChannelIdentifier')) {
|
|
|
|
return 'minecraft:brand' // 1.13+
|
|
|
|
}
|
|
|
|
return 'MC|Brand'
|
|
|
|
}
|
|
|
|
|
2017-07-13 08:03:52 -04:00
|
|
|
const client = mc.createClient({
|
|
|
|
version: false,
|
2016-08-10 12:54:06 -04:00
|
|
|
host: process.argv[2],
|
|
|
|
port: parseInt(process.argv[3]),
|
2018-05-13 16:50:16 -04:00
|
|
|
username: process.argv[4] ? process.argv[4] : 'test',
|
2016-08-10 12:54:06 -04:00
|
|
|
password: process.argv[5]
|
2018-05-13 16:50:16 -04:00
|
|
|
})
|
2016-08-10 12:54:06 -04:00
|
|
|
|
2023-05-20 08:44:03 -04:00
|
|
|
client.on('error', console.log)
|
2016-08-10 12:54:06 -04:00
|
|
|
|
2018-05-13 16:50:16 -04:00
|
|
|
client.on('login', function () {
|
2023-05-20 08:44:03 -04:00
|
|
|
const brandChannel = getBrandChannelName()
|
|
|
|
client.registerChannel(brandChannel, ['string', []])
|
|
|
|
client.on(brandChannel, console.log)
|
|
|
|
client.writeChannel(brandChannel, 'vanilla')
|
2018-05-13 16:50:16 -04:00
|
|
|
})
|