Compare commits
No commits in common. "d7256eabe7883a86822704cbdca9527cbdb5d105" and "6c297d0b8c6b31c088f65f7199fb11ecf89bf3bb" have entirely different histories.
d7256eabe7
...
6c297d0b8c
|
@ -12,6 +12,37 @@ import dgram from 'dgram';
|
|||
|
||||
const START_TIME = new Date().getTime();
|
||||
|
||||
/**
|
||||
* Creates a buffer with the specified length.
|
||||
* @param {number} length - The length of the buffer.
|
||||
* @returns {Buffer} - The created buffer.
|
||||
*/
|
||||
const createBuffer = (length) => {
|
||||
const buffer = Buffer.alloc(length);
|
||||
buffer[0] = 0x01;
|
||||
return buffer;
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes a BigInt value to the buffer at the specified offset using big-endian byte order.
|
||||
* @param {Buffer} buffer - The buffer to write to.
|
||||
* @param {number} value - The BigInt value to write.
|
||||
* @param {number} offset - The offset in the buffer to write the value.
|
||||
*/
|
||||
const writeBigInt64BE = (buffer, value, offset) => {
|
||||
buffer.writeBigInt64BE(BigInt(value), offset);
|
||||
};
|
||||
|
||||
/**
|
||||
* Copies the specified hex value to the buffer at the specified offset.
|
||||
* @param {Buffer} buffer - The buffer to copy to.
|
||||
* @param {string} hex - The hex value to copy.
|
||||
* @param {number} offset - The offset in the buffer to copy the value.
|
||||
*/
|
||||
const copyHexToBuffer = (buffer, hex, offset) => {
|
||||
Buffer.from(hex, 'hex').copy(buffer, offset);
|
||||
};
|
||||
|
||||
/**
|
||||
* Reads a BigInt value from the buffer at the specified offset using big-endian byte order.
|
||||
* @param {Buffer} buffer - The buffer to read from.
|
||||
|
@ -59,11 +90,10 @@ const parseAdvertiseString = (advertiseStr) => {
|
|||
* @see {@link https://wiki.vg/Raknet_Protocol#Unconnected_Ping}
|
||||
*/
|
||||
const UNCONNECTED_PING = (pingId) => {
|
||||
const buffer = Buffer.alloc(33);
|
||||
buffer.writeUInt8(0x01, 0);
|
||||
buffer.writeBigInt64LE(BigInt(pingId), 1);
|
||||
Buffer.from("00ffff00fefefefefdfdfdfd12345678", "hex").copy(buffer, 9);
|
||||
buffer.writeBigInt64LE(BigInt(0), 25);
|
||||
const buffer = createBuffer(35);
|
||||
writeBigInt64BE(buffer, pingId, 1);
|
||||
copyHexToBuffer(buffer, '00ffff00fefefefefdfdfdfd12345678', 9);
|
||||
writeBigInt64BE(buffer, 0, 25);
|
||||
return buffer;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@minescope/mineping",
|
||||
"version": "1.2.1",
|
||||
"version": "1.2.0",
|
||||
"description": "Ping both Minecraft Bedrock and Java servers.",
|
||||
"main": "index.js",
|
||||
"types": "types/index.d.ts",
|
||||
|
|
Loading…
Reference in New Issue