misc.mcserver: more debug

This commit is contained in:
Cynthia Foxwell 2023-06-28 00:10:27 -06:00
parent 1cbdda7c2d
commit e8dbdb94a1

View file

@ -759,7 +759,11 @@ mcserver.callback = async function (msg, line) {
const port = split[1] ?? 25565;
const data = await new Promise((resolve, reject) => {
const timeout = setTimeout(() => resolve("timeout"), 10000);
logger.verbose("mcserver", "querying", ip, port);
const timeout = setTimeout(() => {
logger.verbose("mcserver", "timeout");
resolve("timeout");
}, 10000);
const client = net.createConnection({
host: ip,
@ -767,18 +771,18 @@ mcserver.callback = async function (msg, line) {
timeout: 10000,
});
client.on("connect", function () {
logger.debug("mcserver", "connect");
logger.verbose("mcserver", "connect");
client.write(HANDSHAKE_PACKET);
});
let totalData = Buffer.alloc(0);
client.on("data", function (data) {
totalData = Buffer.concat([totalData, data]);
logger.debug("mcserver", "data", data.length, totalData.length);
logger.verbose("mcserver", "data", data.length, totalData.length);
});
client.on("close", function (err) {
if (err) {
logger.debug("mcserver", "close with error", err);
logger.verbose("mcserver", "close with error", err);
return reject(err);
}
const dataAsString = totalData.toString().trim();
@ -789,7 +793,7 @@ mcserver.callback = async function (msg, line) {
dataAsString.lastIndexOf("}") + 1
)
);
logger.debug("mcserver", "close", json);
logger.verbose("mcserver", "close", json);
clearTimeout(timeout);
return resolve(json);
});