diff --git a/lib/java.js b/lib/java.js index f6ecdb1..428a266 100644 --- a/lib/java.js +++ b/lib/java.js @@ -11,12 +11,13 @@ import varint from "./varint.js"; /** * Ping a Minecraft Java server. * @param {string} host The host of the Java server. + * @param {string} virtualHost The host sent in handshake. * @param {number} [port=25565] The port of the Java server. * @param {function} cb The callback function to handle the ping response. * @param {number} [timeout=5000] The timeout duration in milliseconds. * @param {number} [protocolVersion=-1] The protocol version of the Java client. */ -function ping(host, port = 25565, cb, timeout = 5000, protocolVersion = -1) { +function ping(host, virtualHost, port = 25565, cb, timeout = 5000, protocolVersion = -1) { const socket = net.createConnection({ host, port }); // Set manual timeout interval. @@ -56,8 +57,8 @@ function ping(host, port = 25565, cb, timeout = 5000, protocolVersion = -1) { const handshake = varint.concat([ varint.encodeInt(0), varint.encodeInt(protocolVersion), - varint.encodeInt(host.length), - varint.encodeString(host), + varint.encodeInt(virtualHost.length), + varint.encodeString(virtualHost), varint.encodeUShort(port), varint.encodeInt(1), ]); @@ -131,11 +132,12 @@ function ping(host, port = 25565, cb, timeout = 5000, protocolVersion = -1) { export function pingJava(host, options = {}) { if (!host) throw new Error("Host argument is not provided"); - const { port = 25565, timeout = 5000, protocolVersion = -1 } = options; + const { port = 25565, timeout = 5000, protocolVersion = -1, virtualHost = null } = options; return new Promise((resolve, reject) => { ping( host, + virtualHost || host, port, (res, err) => { err ? reject(err) : resolve(res); diff --git a/types/lib/java.d.ts b/types/lib/java.d.ts index f94d0c6..b6612fd 100644 --- a/types/lib/java.d.ts +++ b/types/lib/java.d.ts @@ -7,6 +7,7 @@ export type JavaPingOptions = { port?: number | undefined; timeout?: number | undefined; protocolVersion?: number | undefined; + virtualHost?: string | undefined; }; /**