From a2835108d62b586c9cc62084d4aaa37b00531092 Mon Sep 17 00:00:00 2001 From: cetteup <17167062+cetteup@users.noreply.github.com> Date: Mon, 9 Jun 2025 15:53:45 +0200 Subject: [PATCH] fix: ignore cached ports when givenPortOnly is set (#710) closes #709 --- CHANGELOG.md | 1 + README.md | 2 +- lib/QueryRunner.js | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b635b1f..cfb7be9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Feat: Update OpenTTD (By @mwkaicz #695) * Fix: Skip non-response packets in protocol-battlefield (By @cetteup #704) * Fix: throwing in tcpSend onData callback would crash gamedig (#705, thanks @cetteup) +* Fix: ignore cached ports when givenPortOnly is set (By @cetteup #710) ## 5.3.0 * Docs: Arma Reforger query setup note (#670, thanks @xCausxn) diff --git a/README.md b/README.md index 98ec8bd..9b24834 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Note that some games might require additional values to be specified. | **maxRetries** | number | `1` | Number of retries to query server in case of failure. Note that this amount multiplies with the number of attempts. | | **socketTimeout** | number | `2000` | Milliseconds to wait for a single packet. Beware that increasing this will cause many queries to take longer even if the server is online. | | **attemptTimeout** | number | `10000` | Milliseconds allowed for an entire query attempt (including `socketTimeout`, beware that if this value is smaller (or even equal) to the socket one, the query will always fail). | -| **givenPortOnly** | boolean | `false` | Only attempt to query server on given port. It will ignore the game's default port. | +| **givenPortOnly** | boolean | `false` | Only attempt to query server on given port. Causes any default ports, port offsets or cached ports to be ignored. | | **ipFamily** | number | `0` | IP family/version returned when looking up hostnames via DNS, can be 0 (IPv4 and IPv6), 4 (IPv4 only) or 6 (IPv6 only). | | **debug** | boolean | `false` | Enables massive amounts of debug logging to stdout. | | **requestRules** | boolean | `false` | Valve games only. Additional 'rules' may be fetched into the `raw` key. | diff --git a/lib/QueryRunner.js b/lib/QueryRunner.js index 2cfe79d..2af3caa 100644 --- a/lib/QueryRunner.js +++ b/lib/QueryRunner.js @@ -56,7 +56,8 @@ export default class QueryRunner { const cachedPort = this.portCache[`${userOptions.address}:${userOptions.port}`] - if (cachedPort && optionsCollection.portCache) { + // Use any cached port if port caching is enabled and user is not explicitly enforcing their given port + if (cachedPort && optionsCollection.portCache && !userOptions.givenPortOnly) { addAttemptWithPort(cachedPort) }