|
|
|
@ -12,37 +12,6 @@ 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.
|
|
|
|
@ -90,10 +59,11 @@ const parseAdvertiseString = (advertiseStr) => {
|
|
|
|
|
* @see {@link https://wiki.vg/Raknet_Protocol#Unconnected_Ping}
|
|
|
|
|
*/
|
|
|
|
|
const UNCONNECTED_PING = (pingId) => {
|
|
|
|
|
const buffer = createBuffer(35);
|
|
|
|
|
writeBigInt64BE(buffer, pingId, 1);
|
|
|
|
|
copyHexToBuffer(buffer, '00ffff00fefefefefdfdfdfd12345678', 9);
|
|
|
|
|
writeBigInt64BE(buffer, 0, 25);
|
|
|
|
|
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);
|
|
|
|
|
return buffer;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|