Default createClient to latest version, fix server motd version (#144)

* Default createClient to latest version, fix server motd version

* Update vanilla.js
This commit is contained in:
extremeheat 2021-10-08 05:56:10 -04:00 committed by GitHub
commit adfa248e2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 13 additions and 14 deletions

View file

@ -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
}
})

View file

@ -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",

View file

@ -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)
}

View file

@ -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<string, Player>} */
this.clients = {}

View file

@ -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)
}

View file

@ -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 }

View file

@ -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 }

View file

@ -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)