From a362d1d11303796188296b60d66584551333b0c8 Mon Sep 17 00:00:00 2001 From: cetteup Date: Mon, 24 Aug 2020 20:27:44 +0200 Subject: [PATCH] Added givenPortOnly user option Allows user to disable gamedig's default behavior of adding query attempts using the default query port(-offset) --- README.md | 1 + bin/gamedig.js | 7 ++++++- lib/QueryRunner.js | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) mode change 100644 => 100755 bin/gamedig.js diff --git a/README.md b/README.md index 0493302..a1e8e9c 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ this query port may work instead. (defaults to protocol default port) will cause many queries to take longer even if the server is online. (default 2000) * **attemptTimeout**: number - Milliseconds allowed for an entire query attempt. This timeout is not commonly hit, as the socketTimeout typically fires first. (default 10000) +* **givenPortOnly**: boolean - Only attempt to query server on given port. (default false) * **debug**: boolean - Enables massive amounts of debug logging to stdout. (default false) ### Return Value diff --git a/bin/gamedig.js b/bin/gamedig.js old mode 100644 new mode 100755 index 720928e..040af19 --- a/bin/gamedig.js +++ b/bin/gamedig.js @@ -4,13 +4,15 @@ const Minimist = require('minimist'), Gamedig = require('..'); const argv = Minimist(process.argv.slice(2), { - boolean: ['pretty','debug'] + boolean: ['pretty','debug','givenPortOnly'] }); const debug = argv.debug; delete argv.debug; const pretty = !!argv.pretty || debug; delete argv.pretty; +const givenPortOnly = argv.givenPortOnly; +delete argv.givenPortOnly; const options = {}; for(const key of Object.keys(argv)) { @@ -34,6 +36,9 @@ if (argv._.length >= 1) { if (debug) { options.debug = true; } +if (givenPortOnly) { + options.givenPortOnly = true; +} Gamedig.query(options) .then((state) => { diff --git a/lib/QueryRunner.js b/lib/QueryRunner.js index 5919dee..062496a 100644 --- a/lib/QueryRunner.js +++ b/lib/QueryRunner.js @@ -30,7 +30,7 @@ class QueryRunner { const attempts = []; if (userOptions.port) { - if (gameQueryPortOffset) { + if (gameQueryPortOffset && !userOptions.givenPortOnly) { attempts.push({ ...defaultOptions, ...gameOptions, @@ -38,7 +38,7 @@ class QueryRunner { port: userOptions.port + gameQueryPortOffset }); } - if (userOptions.port === gameOptions.port && gameQueryPort) { + if (userOptions.port === gameOptions.port && gameQueryPort && !userOptions.givenPortOnly) { attempts.push({ ...defaultOptions, ...gameOptions,