Don't send now deprecated tick sync packets on 1.21 and newer (#504)

* Tick Sync is now deprecated

* Add new function here

* Add check

* Remove useless require by me

* Fix
This commit is contained in:
w0ahL 2024-06-16 16:51:22 -04:00 committed by GitHub
commit 84c5231b92
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 20 deletions

View file

@ -39,6 +39,10 @@ class Connection extends EventEmitter {
return this.options.protocolVersion >= (typeof version === 'string' ? Versions[version] : version)
}
versionLessThanOrEqualTo (version) {
return this.options.protocolVersion <= (typeof version === 'string' ? Versions[version] : version)
}
startEncryption (iv) {
this.encryptionEnabled = true
this.inLog?.('Started encryption', this.sharedSecret, iv)

View file

@ -56,35 +56,41 @@ function connect (client) {
})
client.queue('client_cache_status', { enabled: false })
client.queue('tick_sync', { request_time: BigInt(Date.now()), response_time: 0n })
if (client.versionLessThanOrEqualTo('1.20.80')) client.queue('tick_sync', { request_time: BigInt(Date.now()), response_time: 0n })
sleep(500).then(() => client.queue('request_chunk_radius', { chunk_radius: client.viewDistance || 10 }))
})
// Send tick sync packets every 10 ticks
const keepAliveInterval = 10
const keepAliveIntervalBig = BigInt(keepAliveInterval)
let keepalive
client.tick = 0n
client.once('spawn', () => {
keepalive = setInterval(() => {
// Client fills out the request_time and the server does response_time in its reply.
client.queue('tick_sync', { request_time: client.tick, response_time: 0n })
client.tick += keepAliveIntervalBig
}, 50 * keepAliveInterval)
if (client.versionLessThanOrEqualTo('1.20.80')) {
const keepAliveInterval = 10
const keepAliveIntervalBig = BigInt(keepAliveInterval)
client.on('tick_sync', async packet => {
client.emit('heartbeat', packet.response_time)
client.tick = packet.response_time
let keepalive
client.tick = 0n
client.once('spawn', () => {
keepalive = setInterval(() => {
// Client fills out the request_time and the server does response_time in its reply.
client.queue('tick_sync', { request_time: client.tick, response_time: 0n })
client.tick += keepAliveIntervalBig
}, 50 * keepAliveInterval)
client.on('tick_sync', async packet => {
client.emit('heartbeat', packet.response_time)
client.tick = packet.response_time
})
})
})
client.once('close', () => {
clearInterval(keepalive)
})
client.once('close', () => {
clearInterval(keepalive)
})
}
}
async function ping ({ host, port }) {
const con = new RakClient({ host, port })
try {
return advertisement.fromServerName(await con.ping())
} finally {