sourcequery: fix timeout try 2
This commit is contained in:
parent
4bceaa5ede
commit
ae47f775a6
2 changed files with 25 additions and 9 deletions
|
@ -32,17 +32,12 @@ sourcequery.callback = async function (msg, line) {
|
|||
await msg.addReaction("\uD83C\uDFD3");
|
||||
|
||||
let data;
|
||||
let timeout = false;
|
||||
try {
|
||||
const doTimeout = setTimeout(() => {
|
||||
timeout = true;
|
||||
}, 60000);
|
||||
const query = new SourceQuery(ip, port);
|
||||
const info = await query.getInfo();
|
||||
const players = await query.getPlayers();
|
||||
const rules = await query.getRules();
|
||||
|
||||
clearTimeout(doTimeout);
|
||||
data = {
|
||||
info,
|
||||
players,
|
||||
|
@ -50,13 +45,15 @@ sourcequery.callback = async function (msg, line) {
|
|||
};
|
||||
} catch (err) {
|
||||
await msg.removeReaction("\uD83C\uDFD3");
|
||||
return `:warning: An error occured while querying:\n\`\`\`\n${err.message}\n\`\`\``;
|
||||
if (err == "timeout") {
|
||||
return "Timed out trying to query server.";
|
||||
} else {
|
||||
return `:warning: An error occured while querying:\n\`\`\`\n${err.message ?? err}\n\`\`\``;
|
||||
}
|
||||
}
|
||||
|
||||
await msg.removeReaction("\uD83C\uDFD3");
|
||||
if (timeout) {
|
||||
return "Failed to query server after 1 minute.";
|
||||
} else if (data?.info == null) {
|
||||
if (data?.info == null) {
|
||||
return "Failed to query any data.";
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ module.exports = class SourceQuery {
|
|||
}
|
||||
|
||||
_handlerInfo(message, resolve, reject, wrapper) {
|
||||
clearTimeout(this.timeout);
|
||||
const msg = new DataView(message.buffer);
|
||||
|
||||
if (msg.getUint8(4) == 0x41) {
|
||||
|
@ -168,6 +169,11 @@ module.exports = class SourceQuery {
|
|||
}
|
||||
});
|
||||
|
||||
this.timeout = setTimeout(() => {
|
||||
this.client.close();
|
||||
reject("timeout");
|
||||
}, 5000);
|
||||
|
||||
const wrapper = function wrapper(message) {
|
||||
this._handlerInfo(message, resolve, reject, wrapper);
|
||||
}.bind(this);
|
||||
|
@ -177,7 +183,9 @@ module.exports = class SourceQuery {
|
|||
}
|
||||
|
||||
_handlerPlayer(message, resolve, reject, wrapper) {
|
||||
clearTimeout(this.timeout);
|
||||
const msg = new DataView(message.buffer);
|
||||
|
||||
if (msg.getUint8(4) == 0x41) {
|
||||
const challenge = [msg.getUint8(5), msg.getUint8(6), msg.getUint8(7), msg.getUint8(8)];
|
||||
|
||||
|
@ -235,6 +243,11 @@ module.exports = class SourceQuery {
|
|||
}
|
||||
});
|
||||
|
||||
this.timeout = setTimeout(() => {
|
||||
this.client.close();
|
||||
reject("timeout");
|
||||
}, 5000);
|
||||
|
||||
const wrapper = function wrapper(message) {
|
||||
this._handlerPlayer(message, resolve, reject, wrapper);
|
||||
}.bind(this);
|
||||
|
@ -286,6 +299,7 @@ module.exports = class SourceQuery {
|
|||
}
|
||||
|
||||
_handlerRules(message, resolve, reject, wrapper) {
|
||||
clearTimeout(this.timeout);
|
||||
const msg = new DataView(message.buffer);
|
||||
|
||||
if (msg.getUint8(4) == 0x41) {
|
||||
|
@ -331,6 +345,11 @@ module.exports = class SourceQuery {
|
|||
}
|
||||
});
|
||||
|
||||
this.timeout = setTimeout(() => {
|
||||
this.client.close();
|
||||
reject("timeout");
|
||||
}, 5000);
|
||||
|
||||
const wrapper = function wrapper(message) {
|
||||
this._handlerRules(message, resolve, reject, wrapper);
|
||||
}.bind(this);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue