mirror of
https://github.com/minescope/mineping.git
synced 2025-06-19 00:46:21 +03:00
fix: change minimum motd components to 5 and fix typos
A valid motd message has at least 5 components, not 9
This commit is contained in:
parent
d8d4a9a467
commit
27011d4091
@ -28,13 +28,13 @@ const createUnconnectedPingFrame = (timestamp) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract Modt from Unconnected Pong Packet and convert to an object
|
* Extract Motd from Unconnected Pong Packet and convert to an object
|
||||||
* @param {Buffer} unconnectedPongPacket
|
* @param {Buffer} unconnectedPongPacket
|
||||||
* @returns {Object}
|
* @returns {Object}
|
||||||
* @throws {Error} If packet is malformed or invalid
|
* @throws {Error} If packet is malformed or invalid
|
||||||
* @see {@link https://minecraft.wiki/w/Minecraft_Wiki:Projects/wiki.vg_merge/Raknet_Protocol#Unconnected_Pong}
|
* @see {@link https://minecraft.wiki/w/Minecraft_Wiki:Projects/wiki.vg_merge/Raknet_Protocol#Unconnected_Pong}
|
||||||
*/
|
*/
|
||||||
const extractModt = (unconnectedPongPacket) => {
|
const extractMotd = (unconnectedPongPacket) => {
|
||||||
if (
|
if (
|
||||||
!Buffer.isBuffer(unconnectedPongPacket) ||
|
!Buffer.isBuffer(unconnectedPongPacket) ||
|
||||||
unconnectedPongPacket.length < 35
|
unconnectedPongPacket.length < 35
|
||||||
@ -50,17 +50,17 @@ const extractModt = (unconnectedPongPacket) => {
|
|||||||
throw new Error("Malformed pong packet");
|
throw new Error("Malformed pong packet");
|
||||||
}
|
}
|
||||||
|
|
||||||
let modt = unconnectedPongPacket.toString(
|
let motd = unconnectedPongPacket.toString(
|
||||||
"utf-8",
|
"utf-8",
|
||||||
offset + 2,
|
offset + 2,
|
||||||
offset + 2 + length
|
offset + 2 + length
|
||||||
);
|
);
|
||||||
|
|
||||||
const components = modt.split(";");
|
const components = motd.split(";");
|
||||||
|
|
||||||
// Validate required components
|
// Validate required components
|
||||||
if (components.length < 9) {
|
if (components.length < 5) {
|
||||||
throw new Error("Invalid MODT format");
|
throw new Error("Invalid MOTD format");
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsedComponents = {
|
const parsedComponents = {
|
||||||
@ -141,9 +141,9 @@ const ping = (host, port = 19132, cb, timeout = 5000) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const modtObject = extractModt(pongPacket);
|
const motdObject = extractMotd(pongPacket);
|
||||||
closeSocket();
|
closeSocket();
|
||||||
cb(modtObject, null);
|
cb(motdObject, null);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
handleError(err);
|
handleError(err);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user