node-minecraft-protocol/examples/client_channel/client_channel.js
Artur Khusainov 0134f1599f
Fix plugin channels support (#1096)
* fix custom channel registation

* update channel examples

* use actual protocol version

* update custom channel examples

* use default host & port

* select channel name based on the feature set
2023-05-20 14:44:03 +02:00

31 lines
875 B
JavaScript

const mc = require('minecraft-protocol')
if (process.argv.length < 4 || process.argv.length > 6) {
console.log('Usage : node client_channel.js <host> <port> [<name>] [<password>]')
process.exit(1)
}
function getBrandChannelName () {
const mcData = require('minecraft-data')(client.version)
if (mcData.supportFeature('customChannelIdentifier')) {
return 'minecraft:brand' // 1.13+
}
return 'MC|Brand'
}
const client = mc.createClient({
version: false,
host: process.argv[2],
port: parseInt(process.argv[3]),
username: process.argv[4] ? process.argv[4] : 'test',
password: process.argv[5]
})
client.on('error', console.log)
client.on('login', function () {
const brandChannel = getBrandChannelName()
client.registerChannel(brandChannel, ['string', []])
client.on(brandChannel, console.log)
client.writeChannel(brandChannel, 'vanilla')
})