diff --git a/docs/API.md b/docs/API.md index 5062fb6..3f9baa9 100644 --- a/docs/API.md +++ b/docs/API.md @@ -61,7 +61,7 @@ const server = bedrock.createServer({ port: 19132, // optional, port to bind to, default 19132 offline: false, // default false. verify connections with XBL motd: { - name: 'Funtime Server', // Top level message shown in server list + motd: 'Funtime Server', // Top level message shown in server list levelName: 'Wonderland' // Sub-level header } }) diff --git a/package.json b/package.json index 003ee35..c9b3b6a 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "debug": "^4.3.1", "jsonwebtoken": "^8.5.1", "jsp-raknet": "^2.1.3", - "minecraft-data": "^2.89.4", + "minecraft-data": "^2.95.0", "minecraft-folder-path": "^1.2.0", "prismarine-auth": "^1.1.0", "prismarine-nbt": "^1.5.0", diff --git a/src/createClient.js b/src/createClient.js index 4485acb..a7e9fd4 100644 --- a/src/createClient.js +++ b/src/createClient.js @@ -1,8 +1,9 @@ const { Client } = require('./client') const { RakClient } = require('./rak')(true) +const { Versions, CURRENT_VERSION } = require('./options') +const { sleep } = require('./datatypes/util') const assert = require('assert') const advertisement = require('./server/advertisement') -const { sleep } = require('./datatypes/util') /** @param {{ version?: number, host: string, port?: number, connectTimeout?: number, skipPing?: boolean }} options */ function createClient (options) { @@ -13,9 +14,9 @@ function createClient (options) { connect(client) } else { // Try to ping client.ping().then(data => { - const advert = advertisement.fromServerName(data) - console.log(`Connecting to server ${advert.motd} (${advert.name}), version ${advert.version}`) - client.options.version = options.version ?? advert.version + const ad = advertisement.fromServerName(data) + client.options.version = options.version ?? (Versions[ad.version] ? ad.version : CURRENT_VERSION) + console.log(`Connecting to server ${ad.motd} (${ad.name}), version ${ad.version}`, client.options.version !== ad.version ? ` (as ${client.options.version})` : undefined) connect(client) }, client) } diff --git a/src/server.js b/src/server.js index e13ca92..3a7684e 100644 --- a/src/server.js +++ b/src/server.js @@ -16,7 +16,7 @@ class Server extends EventEmitter { this.serializer = createSerializer(this.options.version) this.deserializer = createDeserializer(this.options.version) - this.advertisement = new ServerAdvertisement(this.options.motd) + this.advertisement = new ServerAdvertisement(this.options.motd, this.options.version) this.advertisement.playersMax = options.maxPlayers ?? 3 /** @type {Object} */ this.clients = {} diff --git a/src/server/advertisement.js b/src/server/advertisement.js index 3a2fee8..3e069db 100644 --- a/src/server/advertisement.js +++ b/src/server/advertisement.js @@ -3,16 +3,15 @@ const { Versions, CURRENT_VERSION } = require('../options') class ServerAdvertisement { motd = 'Bedrock Protocol Server' levelName = 'bedrock-protocol' - protocol = Versions[CURRENT_VERSION] - version = CURRENT_VERSION playersOnline = 0 playersMax = 5 - gamemode = 'Creative' serverId = '0' - constructor (obj, version) { + constructor (obj, version = CURRENT_VERSION) { if (obj?.name) obj.motd = obj.name + this.protocol = Versions[version] + this.version = version Object.assign(this, obj) } diff --git a/test/internal.js b/test/internal.js index c03a498..de1c95f 100644 --- a/test/internal.js +++ b/test/internal.js @@ -205,5 +205,5 @@ async function timedTest (version, timeout = 1000 * 220) { console.info('✔ ok') } -if (!module.parent) timedTest() +// if (!module.parent) timedTest() module.exports = { startTest, timedTest, requestChunks } diff --git a/test/vanilla.js b/test/vanilla.js index 13c6069..5d20b89 100644 --- a/test/vanilla.js +++ b/test/vanilla.js @@ -3,7 +3,6 @@ const vanillaServer = require('../tools/startVanillaServer') const { Client } = require('../src/client') const { waitFor } = require('../src/datatypes/util') const { ChunkColumn, Version } = require('bedrock-provider') -const { CURRENT_VERSION } = require('../src/options') async function test (version) { // Start the server, wait for it to accept clients, throws on timeout @@ -67,5 +66,4 @@ async function test (version) { clearInterval(loop) } -if (!module.parent) test(CURRENT_VERSION) module.exports = { clientTest: test } diff --git a/tools/genPacketDumps.js b/tools/genPacketDumps.js index a0a676f..a6741ea 100644 --- a/tools/genPacketDumps.js +++ b/tools/genPacketDumps.js @@ -21,6 +21,7 @@ async function dump (version, force = true) { const random = ((Math.random() * 100) | 0) const port = 19130 + random + console.log('Starting dump server', version) const handle = await vanillaServer.startServerAndWait(version || CURRENT_VERSION, 1000 * 120, { 'server-port': port }) console.log('Started dump server', version)