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:
parent
ac2e9852be
commit
adfa248e2d
8 changed files with 13 additions and 14 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 = {}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue