mirror of
https://github.com/minescope/mineping.git
synced 2025-02-26 09:03:26 +03:00
feat: add virtualHost option (#6)
This commit is contained in:
parent
9469564736
commit
73a2fffe8b
10
lib/java.js
10
lib/java.js
@ -11,12 +11,13 @@ import varint from "./varint.js";
|
|||||||
/**
|
/**
|
||||||
* Ping a Minecraft Java server.
|
* Ping a Minecraft Java server.
|
||||||
* @param {string} host The host of the 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 {number} [port=25565] The port of the Java server.
|
||||||
* @param {function} cb The callback function to handle the ping response.
|
* @param {function} cb The callback function to handle the ping response.
|
||||||
* @param {number} [timeout=5000] The timeout duration in milliseconds.
|
* @param {number} [timeout=5000] The timeout duration in milliseconds.
|
||||||
* @param {number} [protocolVersion=-1] The protocol version of the Java client.
|
* @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 });
|
const socket = net.createConnection({ host, port });
|
||||||
|
|
||||||
// Set manual timeout interval.
|
// Set manual timeout interval.
|
||||||
@ -56,8 +57,8 @@ function ping(host, port = 25565, cb, timeout = 5000, protocolVersion = -1) {
|
|||||||
const handshake = varint.concat([
|
const handshake = varint.concat([
|
||||||
varint.encodeInt(0),
|
varint.encodeInt(0),
|
||||||
varint.encodeInt(protocolVersion),
|
varint.encodeInt(protocolVersion),
|
||||||
varint.encodeInt(host.length),
|
varint.encodeInt(virtualHost.length),
|
||||||
varint.encodeString(host),
|
varint.encodeString(virtualHost),
|
||||||
varint.encodeUShort(port),
|
varint.encodeUShort(port),
|
||||||
varint.encodeInt(1),
|
varint.encodeInt(1),
|
||||||
]);
|
]);
|
||||||
@ -131,11 +132,12 @@ function ping(host, port = 25565, cb, timeout = 5000, protocolVersion = -1) {
|
|||||||
export function pingJava(host, options = {}) {
|
export function pingJava(host, options = {}) {
|
||||||
if (!host) throw new Error("Host argument is not provided");
|
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) => {
|
return new Promise((resolve, reject) => {
|
||||||
ping(
|
ping(
|
||||||
host,
|
host,
|
||||||
|
virtualHost || host,
|
||||||
port,
|
port,
|
||||||
(res, err) => {
|
(res, err) => {
|
||||||
err ? reject(err) : resolve(res);
|
err ? reject(err) : resolve(res);
|
||||||
|
1
types/lib/java.d.ts
vendored
1
types/lib/java.d.ts
vendored
@ -7,6 +7,7 @@ export type JavaPingOptions = {
|
|||||||
port?: number | undefined;
|
port?: number | undefined;
|
||||||
timeout?: number | undefined;
|
timeout?: number | undefined;
|
||||||
protocolVersion?: number | undefined;
|
protocolVersion?: number | undefined;
|
||||||
|
virtualHost?: string | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user