Compare commits

...

2 Commits

Author SHA1 Message Date
Timofey Gelazoniya d7256eabe7
chore(package.json): bump version to 1.2.1 2023-12-09 12:58:53 +03:00
Timofey Gelazoniya afa2c3025f
fix(bedrock.js): resolve UNCONNECTED_PING formation issue
- Simplify UNCONNECTED_PING function
- Address an issue where certain servers, particularly those based on Pocketmine, were unresponsive to Unconnected Ping requests
2023-12-09 12:57:43 +03:00
2 changed files with 6 additions and 36 deletions

View File

@ -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;
};

View File

@ -1,6 +1,6 @@
{
"name": "@minescope/mineping",
"version": "1.2.0",
"version": "1.2.1",
"description": "Ping both Minecraft Bedrock and Java servers.",
"main": "index.js",
"types": "types/index.d.ts",