misc.mcserver: more srv resolving logic

This commit is contained in:
Cynthia Foxwell 2024-08-02 12:34:14 -06:00
parent 94f5ee7887
commit c6083ea062

View file

@ -2,7 +2,7 @@ const Command = require("../../lib/command.js");
const logger = require("../../lib/logger.js"); const logger = require("../../lib/logger.js");
const net = require("node:net"); const net = require("node:net");
const {resolveSrv} = require("node:dns/promises"); const {resolveCname, resolveSrv} = require("node:dns/promises");
function readVarInt(data) { function readVarInt(data) {
var result = 0; var result = 0;
@ -193,10 +193,13 @@ mcserver.callback = async function (msg, line) {
const port = split[1] ?? 25565; const port = split[1] ?? 25565;
try { try {
const addrs = await resolveSrv(ip); const addrs = await resolveSrv("_tcp." + ip);
if (addrs.length > 0) { if (addrs.length > 0) {
const mcAddr = addrs.find((a) => a.port == port); const mcAddr = addrs.find((a) => a.port == port);
if (mcAddr?.name) ip = mcAddr.name; if (mcAddr?.name) ip = mcAddr.name;
} else {
const addrs = await resolveCname("_tcp." + ip);
if (addrs.length > 0) ip = addrs[0];
} }
} catch { } catch {
// noop // noop