mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-24 00:07:51 -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)
|
||||
}
|
||||
|
||||
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],
|
||||
|
@ -13,10 +21,11 @@ const client = mc.createClient({
|
|||
password: process.argv[5]
|
||||
})
|
||||
|
||||
client.registerChannel('MC|Brand', ['string', []])
|
||||
client.on('MC|Brand', console.log)
|
||||
client.on('error', console.log)
|
||||
|
||||
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]),
|
||||
username: process.argv[4] ? process.argv[4] : 'test',
|
||||
password: process.argv[5],
|
||||
version: '1.10'
|
||||
version: false
|
||||
})
|
||||
|
||||
client.on('login', onlogin)
|
||||
client.on('error', console.log)
|
||||
|
||||
function onlogin () {
|
||||
client.registerChannel('CUSTOM|ChannelOne', ['i32', []], true)
|
||||
client.registerChannel('CUSTOM|ChannelTwo', ['i32', []], true)
|
||||
client.writeChannel('CUSTOM|ChannelOne', 4)
|
||||
client.on('CUSTOM|ChannelTwo', console.log)
|
||||
client.registerChannel('node-minecraft-protocol:custom_channel_one', ['string', []], true)
|
||||
client.registerChannel('node-minecraft-protocol:custom_channel_two', ['string', []], true)
|
||||
client.writeChannel('node-minecraft-protocol:custom_channel_one', 'hello from the client')
|
||||
client.on('node-minecraft-protocol:custom_channel_two', console.log)
|
||||
}
|
||||
|
|
|
@ -3,16 +3,14 @@ const mc = require('minecraft-protocol')
|
|||
const server = mc.createServer({
|
||||
'online-mode': false, // optional
|
||||
encryption: false, // optional
|
||||
host: '0.0.0.0', // optional
|
||||
port: 25565, // optional
|
||||
version: '1.16'
|
||||
version: '1.18.2'
|
||||
})
|
||||
const mcData = require('minecraft-data')(server.version)
|
||||
const loginPacket = mcData.loginPacket
|
||||
|
||||
server.on('login', function (client) {
|
||||
client.registerChannel('MC|Brand', ['string', []])
|
||||
client.on('MC|Brand', console.log)
|
||||
client.registerChannel('minecraft:brand', ['string', []])
|
||||
client.on('minecraft:brand', console.log)
|
||||
|
||||
client.write('login', {
|
||||
entityId: client.id,
|
||||
|
@ -39,5 +37,5 @@ server.on('login', function (client) {
|
|||
pitch: 0,
|
||||
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({
|
||||
'online-mode': false, // optional
|
||||
encryption: false, // optional
|
||||
host: '0.0.0.0', // optional
|
||||
port: 25565, // optional
|
||||
version: '1.16'
|
||||
version: '1.18.2'
|
||||
})
|
||||
const mcData = require('minecraft-data')(server.version)
|
||||
const loginPacket = mcData.loginPacket
|
||||
|
@ -28,8 +26,8 @@ server.on('login', function (client) {
|
|||
isDebug: false,
|
||||
isFlat: false
|
||||
})
|
||||
client.registerChannel('CUSTOM|ChannelOne', ['i32', []], true)
|
||||
client.registerChannel('CUSTOM|ChannelTwo', ['i32', []], true)
|
||||
client.registerChannel('node-minecraft-protocol:custom_channel_one', ['string', []], true)
|
||||
client.registerChannel('node-minecraft-protocol:custom_channel_two', ['string', []], true)
|
||||
client.write('position', {
|
||||
x: 0,
|
||||
y: 1.62,
|
||||
|
@ -38,6 +36,6 @@ server.on('login', function (client) {
|
|||
pitch: 0,
|
||||
flags: 0x00
|
||||
})
|
||||
client.writeChannel('CUSTOM|ChannelTwo', 10)
|
||||
client.on('CUSTOM|ChannelOne', console.log)
|
||||
client.writeChannel('node-minecraft-protocol:custom_channel_two', 'hello from the server')
|
||||
client.on('node-minecraft-protocol:custom_channel_one', console.log)
|
||||
})
|
||||
|
|
|
@ -14,15 +14,15 @@ module.exports = function (client, options) {
|
|||
client.unregisterChannel = unregisterChannel
|
||||
client.writeChannel = writeChannel
|
||||
|
||||
client.registerChannel('REGISTER', ['registerarr', []])
|
||||
client.registerChannel('UNREGISTER', ['registerarr', []])
|
||||
|
||||
const above385 = options.protocolVersion >= 385
|
||||
const above385 = mcdata.version.version >= 385
|
||||
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)
|
||||
}
|
||||
const channelNames = above385 ? ['minecraft:register', 'minecraft:unregister'] : ['REGISTER', 'UNREGISTER']
|
||||
|
||||
client.registerChannel(channelNames[0], ['registerarr', []])
|
||||
client.registerChannel(channelNames[1], ['registerarr', []])
|
||||
|
||||
function registerChannel (name, parser, custom) {
|
||||
if (custom) {
|
||||
client.writeChannel(channelNames[0], [name])
|
||||
|
|
Loading…
Reference in a new issue