mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-27 17:55:45 -05:00
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
This commit is contained in:
parent
0625b29d52
commit
0134f1599f
5 changed files with 31 additions and 26 deletions
|
@ -5,6 +5,14 @@ if (process.argv.length < 4 || process.argv.length > 6) {
|
||||||
process.exit(1)
|
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({
|
const client = mc.createClient({
|
||||||
version: false,
|
version: false,
|
||||||
host: process.argv[2],
|
host: process.argv[2],
|
||||||
|
@ -13,10 +21,11 @@ const client = mc.createClient({
|
||||||
password: process.argv[5]
|
password: process.argv[5]
|
||||||
})
|
})
|
||||||
|
|
||||||
client.registerChannel('MC|Brand', ['string', []])
|
client.on('error', console.log)
|
||||||
client.on('MC|Brand', console.log)
|
|
||||||
|
|
||||||
client.on('login', function () {
|
client.on('login', function () {
|
||||||
client.writeChannel('MC|Brand', 'vanilla')
|
const brandChannel = getBrandChannelName()
|
||||||
|
client.registerChannel(brandChannel, ['string', []])
|
||||||
|
client.on(brandChannel, console.log)
|
||||||
|
client.writeChannel(brandChannel, 'vanilla')
|
||||||
})
|
})
|
||||||
client.on('error', console.log)
|
|
||||||
|
|
|
@ -10,15 +10,15 @@ const client = mc.createClient({
|
||||||
port: parseInt(process.argv[3]),
|
port: parseInt(process.argv[3]),
|
||||||
username: process.argv[4] ? process.argv[4] : 'test',
|
username: process.argv[4] ? process.argv[4] : 'test',
|
||||||
password: process.argv[5],
|
password: process.argv[5],
|
||||||
version: '1.10'
|
version: false
|
||||||
})
|
})
|
||||||
|
|
||||||
client.on('login', onlogin)
|
client.on('login', onlogin)
|
||||||
client.on('error', console.log)
|
client.on('error', console.log)
|
||||||
|
|
||||||
function onlogin () {
|
function onlogin () {
|
||||||
client.registerChannel('CUSTOM|ChannelOne', ['i32', []], true)
|
client.registerChannel('node-minecraft-protocol:custom_channel_one', ['string', []], true)
|
||||||
client.registerChannel('CUSTOM|ChannelTwo', ['i32', []], true)
|
client.registerChannel('node-minecraft-protocol:custom_channel_two', ['string', []], true)
|
||||||
client.writeChannel('CUSTOM|ChannelOne', 4)
|
client.writeChannel('node-minecraft-protocol:custom_channel_one', 'hello from the client')
|
||||||
client.on('CUSTOM|ChannelTwo', console.log)
|
client.on('node-minecraft-protocol:custom_channel_two', console.log)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,16 +3,14 @@ const mc = require('minecraft-protocol')
|
||||||
const server = mc.createServer({
|
const server = mc.createServer({
|
||||||
'online-mode': false, // optional
|
'online-mode': false, // optional
|
||||||
encryption: false, // optional
|
encryption: false, // optional
|
||||||
host: '0.0.0.0', // optional
|
version: '1.18.2'
|
||||||
port: 25565, // optional
|
|
||||||
version: '1.16'
|
|
||||||
})
|
})
|
||||||
const mcData = require('minecraft-data')(server.version)
|
const mcData = require('minecraft-data')(server.version)
|
||||||
const loginPacket = mcData.loginPacket
|
const loginPacket = mcData.loginPacket
|
||||||
|
|
||||||
server.on('login', function (client) {
|
server.on('login', function (client) {
|
||||||
client.registerChannel('MC|Brand', ['string', []])
|
client.registerChannel('minecraft:brand', ['string', []])
|
||||||
client.on('MC|Brand', console.log)
|
client.on('minecraft:brand', console.log)
|
||||||
|
|
||||||
client.write('login', {
|
client.write('login', {
|
||||||
entityId: client.id,
|
entityId: client.id,
|
||||||
|
@ -39,5 +37,5 @@ server.on('login', function (client) {
|
||||||
pitch: 0,
|
pitch: 0,
|
||||||
flags: 0x00
|
flags: 0x00
|
||||||
})
|
})
|
||||||
client.writeChannel('MC|Brand', 'vanilla')
|
client.writeChannel('minecraft:brand', 'vanilla')
|
||||||
})
|
})
|
||||||
|
|
|
@ -3,9 +3,7 @@ const mc = require('minecraft-protocol')
|
||||||
const server = mc.createServer({
|
const server = mc.createServer({
|
||||||
'online-mode': false, // optional
|
'online-mode': false, // optional
|
||||||
encryption: false, // optional
|
encryption: false, // optional
|
||||||
host: '0.0.0.0', // optional
|
version: '1.18.2'
|
||||||
port: 25565, // optional
|
|
||||||
version: '1.16'
|
|
||||||
})
|
})
|
||||||
const mcData = require('minecraft-data')(server.version)
|
const mcData = require('minecraft-data')(server.version)
|
||||||
const loginPacket = mcData.loginPacket
|
const loginPacket = mcData.loginPacket
|
||||||
|
@ -28,8 +26,8 @@ server.on('login', function (client) {
|
||||||
isDebug: false,
|
isDebug: false,
|
||||||
isFlat: false
|
isFlat: false
|
||||||
})
|
})
|
||||||
client.registerChannel('CUSTOM|ChannelOne', ['i32', []], true)
|
client.registerChannel('node-minecraft-protocol:custom_channel_one', ['string', []], true)
|
||||||
client.registerChannel('CUSTOM|ChannelTwo', ['i32', []], true)
|
client.registerChannel('node-minecraft-protocol:custom_channel_two', ['string', []], true)
|
||||||
client.write('position', {
|
client.write('position', {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 1.62,
|
y: 1.62,
|
||||||
|
@ -38,6 +36,6 @@ server.on('login', function (client) {
|
||||||
pitch: 0,
|
pitch: 0,
|
||||||
flags: 0x00
|
flags: 0x00
|
||||||
})
|
})
|
||||||
client.writeChannel('CUSTOM|ChannelTwo', 10)
|
client.writeChannel('node-minecraft-protocol:custom_channel_two', 'hello from the server')
|
||||||
client.on('CUSTOM|ChannelOne', console.log)
|
client.on('node-minecraft-protocol:custom_channel_one', console.log)
|
||||||
})
|
})
|
||||||
|
|
|
@ -14,15 +14,15 @@ module.exports = function (client, options) {
|
||||||
client.unregisterChannel = unregisterChannel
|
client.unregisterChannel = unregisterChannel
|
||||||
client.writeChannel = writeChannel
|
client.writeChannel = writeChannel
|
||||||
|
|
||||||
client.registerChannel('REGISTER', ['registerarr', []])
|
const above385 = mcdata.version.version >= 385
|
||||||
client.registerChannel('UNREGISTER', ['registerarr', []])
|
|
||||||
|
|
||||||
const above385 = options.protocolVersion >= 385
|
|
||||||
if (above385) { // 1.13-pre3 (385) added Added Login Plugin Message (https://wiki.vg/Protocol_History#1.13-pre3)
|
if (above385) { // 1.13-pre3 (385) added Added Login Plugin Message (https://wiki.vg/Protocol_History#1.13-pre3)
|
||||||
client.on('login_plugin_request', onLoginPluginRequest)
|
client.on('login_plugin_request', onLoginPluginRequest)
|
||||||
}
|
}
|
||||||
const channelNames = above385 ? ['minecraft:register', 'minecraft:unregister'] : ['REGISTER', 'UNREGISTER']
|
const channelNames = above385 ? ['minecraft:register', 'minecraft:unregister'] : ['REGISTER', 'UNREGISTER']
|
||||||
|
|
||||||
|
client.registerChannel(channelNames[0], ['registerarr', []])
|
||||||
|
client.registerChannel(channelNames[1], ['registerarr', []])
|
||||||
|
|
||||||
function registerChannel (name, parser, custom) {
|
function registerChannel (name, parser, custom) {
|
||||||
if (custom) {
|
if (custom) {
|
||||||
client.writeChannel(channelNames[0], [name])
|
client.writeChannel(channelNames[0], [name])
|
||||||
|
|
Loading…
Reference in a new issue