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:
Timofey Gelazoniya 2025-06-14 23:26:11 +03:00
parent d8d4a9a467
commit 27011d4091
Signed by: zeldon
GPG Key ID: D99707D1FF69FAB0

View File

@ -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
* @returns {Object}
* @throws {Error} If packet is malformed or invalid
* @see {@link https://minecraft.wiki/w/Minecraft_Wiki:Projects/wiki.vg_merge/Raknet_Protocol#Unconnected_Pong}
*/
const extractModt = (unconnectedPongPacket) => {
const extractMotd = (unconnectedPongPacket) => {
if (
!Buffer.isBuffer(unconnectedPongPacket) ||
unconnectedPongPacket.length < 35
@ -50,17 +50,17 @@ const extractModt = (unconnectedPongPacket) => {
throw new Error("Malformed pong packet");
}
let modt = unconnectedPongPacket.toString(
let motd = unconnectedPongPacket.toString(
"utf-8",
offset + 2,
offset + 2 + length
);
const components = modt.split(";");
const components = motd.split(";");
// Validate required components
if (components.length < 9) {
throw new Error("Invalid MODT format");
if (components.length < 5) {
throw new Error("Invalid MOTD format");
}
const parsedComponents = {
@ -141,9 +141,9 @@ const ping = (host, port = 19132, cb, timeout = 5000) => {
}
try {
const modtObject = extractModt(pongPacket);
const motdObject = extractMotd(pongPacket);
closeSocket();
cb(modtObject, null);
cb(motdObject, null);
} catch (err) {
handleError(err);
}