From 27011d4091dc5fbcc47f3bd658dac1e5881a5a29 Mon Sep 17 00:00:00 2001 From: Timofey Gelazoniya Date: Sat, 14 Jun 2025 23:26:11 +0300 Subject: [PATCH] fix: change minimum motd components to 5 and fix typos A valid motd message has at least 5 components, not 9 --- lib/bedrock.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/bedrock.js b/lib/bedrock.js index 1b73818..848dad8 100644 --- a/lib/bedrock.js +++ b/lib/bedrock.js @@ -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); }