Skip to content

Commit 84c5231

Browse files
authored
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
1 parent 1fee54f commit 84c5231

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

src/connection.js

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ class Connection extends EventEmitter {
3939
return this.options.protocolVersion >= (typeof version === 'string' ? Versions[version] : version)
4040
}
4141

42+
versionLessThanOrEqualTo (version) {
43+
return this.options.protocolVersion <= (typeof version === 'string' ? Versions[version] : version)
44+
}
45+
4246
startEncryption (iv) {
4347
this.encryptionEnabled = true
4448
this.inLog?.('Started encryption', this.sharedSecret, iv)

src/createClient.js

+26-20
Original file line numberDiff line numberDiff line change
@@ -56,35 +56,41 @@ function connect (client) {
5656
})
5757

5858
client.queue('client_cache_status', { enabled: false })
59-
client.queue('tick_sync', { request_time: BigInt(Date.now()), response_time: 0n })
59+
60+
if (client.versionLessThanOrEqualTo('1.20.80')) client.queue('tick_sync', { request_time: BigInt(Date.now()), response_time: 0n })
61+
6062
sleep(500).then(() => client.queue('request_chunk_radius', { chunk_radius: client.viewDistance || 10 }))
6163
})
6264

63-
// Send tick sync packets every 10 ticks
64-
const keepAliveInterval = 10
65-
const keepAliveIntervalBig = BigInt(keepAliveInterval)
66-
let keepalive
67-
client.tick = 0n
68-
client.once('spawn', () => {
69-
keepalive = setInterval(() => {
70-
// Client fills out the request_time and the server does response_time in its reply.
71-
client.queue('tick_sync', { request_time: client.tick, response_time: 0n })
72-
client.tick += keepAliveIntervalBig
73-
}, 50 * keepAliveInterval)
74-
75-
client.on('tick_sync', async packet => {
76-
client.emit('heartbeat', packet.response_time)
77-
client.tick = packet.response_time
65+
if (client.versionLessThanOrEqualTo('1.20.80')) {
66+
const keepAliveInterval = 10
67+
const keepAliveIntervalBig = BigInt(keepAliveInterval)
68+
69+
let keepalive
70+
client.tick = 0n
71+
72+
client.once('spawn', () => {
73+
keepalive = setInterval(() => {
74+
// Client fills out the request_time and the server does response_time in its reply.
75+
client.queue('tick_sync', { request_time: client.tick, response_time: 0n })
76+
client.tick += keepAliveIntervalBig
77+
}, 50 * keepAliveInterval)
78+
79+
client.on('tick_sync', async packet => {
80+
client.emit('heartbeat', packet.response_time)
81+
client.tick = packet.response_time
82+
})
7883
})
79-
})
8084

81-
client.once('close', () => {
82-
clearInterval(keepalive)
83-
})
85+
client.once('close', () => {
86+
clearInterval(keepalive)
87+
})
88+
}
8489
}
8590

8691
async function ping ({ host, port }) {
8792
const con = new RakClient({ host, port })
93+
8894
try {
8995
return advertisement.fromServerName(await con.ping())
9096
} finally {

0 commit comments

Comments
 (0)