Skip to content
This repository was archived by the owner on Mar 22, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/packet.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

const { Writable } = require('stream')
const varint = require('varint')
const Int64 = require('node-int64')

const PROTOCOL_VERSION = 736 // Minecraft 1.16.1

Expand All @@ -45,7 +44,9 @@ module.exports.createHandshakePacket = (address, port) => {
}

module.exports.createPingPacket = (timestamp) => {
return createPacket(1, new Int64(timestamp).toBuffer())
let timestampBuffer = Buffer.allocUnsafe(8)
timestampBuffer.writeBigInt64BE(BigInt(timestamp), 0)
return createPacket(1, timestampBuffer)
}

function createPacket (packetId, data) {
Expand Down Expand Up @@ -140,7 +141,7 @@ function decodeHandshakeResponse (packet) {
function decodePong (packet) {
return new Promise((resolve, reject) => {
// Decode timestamp
let timestamp = new Int64(packet.data)
let timestamp = Number(BigInt(`0x${packet.data.toString('hex')}`))

packet.result = Date.now() - timestamp
resolve(packet)
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"standard": "^7.1.2"
},
"dependencies": {
"node-int64": "^0.4.0",
"varint": "^4.0.1"
}
}