diff --git a/src/util/sourcequery.js b/src/util/sourcequery.js index 4a9188d..8575475 100644 --- a/src/util/sourcequery.js +++ b/src/util/sourcequery.js @@ -11,11 +11,15 @@ module.exports = class SourceQuery { constructor(ip, port) { this.ip = ip; this.port = port; - this.client = dgram.createSocket("udp4"); this.rulePackets = []; this.chunks = -1; } + _createSocket() { + this.client = dgram.createSocket("udp4"); + this.client.bind(27020); + } + _handlerInfo(message, resolve, reject, wrapper) { clearTimeout(this.timeout); const msg = new DataView(message.buffer); @@ -161,7 +165,7 @@ module.exports = class SourceQuery { getInfo() { return new Promise((resolve, reject) => { - this.client = dgram.createSocket("udp4"); + this._createSocket(); this.client.send(Buffer.from(REQUEST_INFO), this.port, this.ip, function (err) { if (err) { this.client.close(); @@ -235,7 +239,7 @@ module.exports = class SourceQuery { getPlayers() { return new Promise((resolve, reject) => { - this.client = dgram.createSocket("udp4"); + this._createSocket(); this.client.send(Buffer.from([...REQUEST_PLAYER, 0xff, 0xff, 0xff, 0xff]), this.port, this.ip, function (err) { if (err) { this.client.close(); @@ -337,7 +341,7 @@ module.exports = class SourceQuery { getRules() { return new Promise((resolve, reject) => { - this.client = dgram.createSocket("udp4"); + this._createSocket(); this.client.send(Buffer.from([...REQUEST_RULES, 0xff, 0xff, 0xff, 0xff]), this.port, this.ip, function (err) { if (err) { this.client.close();