mirror of
https://github.com/minescope/mineping.git
synced 2025-07-18 17:26:37 +03:00
Compare commits
2 Commits
2bd5d9c9bf
...
1e6b5b3973
Author | SHA1 | Date | |
---|---|---|---|
1e6b5b3973
|
|||
23299a9a07
|
19
lib/java.js
19
lib/java.js
@ -6,7 +6,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import net from "node:net";
|
import net from "node:net";
|
||||||
import dns from "node:dns/promises";
|
import { Resolver } from "node:dns/promises";
|
||||||
import createDebug from "debug";
|
import createDebug from "debug";
|
||||||
import * as varint from "./varint.js";
|
import * as varint from "./varint.js";
|
||||||
|
|
||||||
@ -148,22 +148,27 @@ export async function pingJava(host, options = {}) {
|
|||||||
let targetPort = fallbackPort;
|
let targetPort = fallbackPort;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
debug("attempting SRV lookup for _minecraft._tcp.%s", host);
|
debug(
|
||||||
const srvRecords = await dns.resolveSrv(`_minecraft._tcp.${host}`);
|
"attempting SRV lookup for _minecraft._tcp.%s with %dms timeout",
|
||||||
|
host,
|
||||||
|
timeout
|
||||||
|
);
|
||||||
|
const resolver = new Resolver({ timeout, tries: 3 });
|
||||||
|
const srvRecords = await resolver.resolveSrv(`_minecraft._tcp.${host}`);
|
||||||
if (srvRecords.length > 0) {
|
if (srvRecords.length > 0) {
|
||||||
targetHost = srvRecords[0].name;
|
targetHost = srvRecords[0].name;
|
||||||
targetPort = srvRecords[0].port;
|
targetPort = srvRecords[0].port;
|
||||||
debug("SRV lookup successful, new target: %s:%d", targetHost, targetPort);
|
debug("SRV lookup successful, new target: %s:%d", targetHost, targetPort);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Common errors like ENODATA or ENOTFOUND are expected when a server
|
// Common errors like ENODATA, ENOTFOUND, or a DNS timeout (ETIMEOUT) are expected
|
||||||
// does not have an SRV record, so we ignore them and proceed
|
// when a server does not have an SRV record, so we ignore them and proceed.
|
||||||
|
const nonFatalDnsCodes = ["ENODATA", "ENOTFOUND", "ETIMEOUT"];
|
||||||
if (
|
if (
|
||||||
err instanceof Error &&
|
err instanceof Error &&
|
||||||
"code" in err &&
|
"code" in err &&
|
||||||
(err.code === "ENODATA" || err.code === "ENOTFOUND")
|
nonFatalDnsCodes.includes(err.code)
|
||||||
) {
|
) {
|
||||||
// Non fatal DNS error, log it and continue
|
|
||||||
debug("SRV lookup for %s failed (%s), using fallback.", host, err.code);
|
debug("SRV lookup for %s failed (%s), using fallback.", host, err.code);
|
||||||
} else {
|
} else {
|
||||||
// Re-throw anything else to fail the operation
|
// Re-throw anything else to fail the operation
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@minescope/mineping",
|
"name": "@minescope/mineping",
|
||||||
"version": "1.7.0-beta.2",
|
"version": "1.7.0-beta.3",
|
||||||
"description": "Ping both Minecraft Bedrock and Java servers.",
|
"description": "Ping both Minecraft Bedrock and Java servers.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
Reference in New Issue
Block a user