feat: make port_query_offset accept a number or an array of numbers (#471)

* feat: add port_query_offset_alt

* feat: port_query_offset can now handle arrays of numbers

* back to previous state

* refactor gameQueryPortOffset ifs

* simpler code
This commit is contained in:
Pedro Ivo Hudson 2024-01-17 18:14:01 -03:00 committed by GitHub
parent e01190a458
commit 1f0563f7d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 4 deletions

View File

@ -45,18 +45,21 @@ export default class QueryRunner {
}) })
} }
let portOffsetArray = gameQueryPortOffset
if (!Array.isArray(portOffsetArray)) {
gameQueryPortOffset ? portOffsetArray = [gameQueryPortOffset] : portOffsetArray = [0]
}
if (userOptions.port) { if (userOptions.port) {
if (!userOptions.givenPortOnly) { if (!userOptions.givenPortOnly) {
if (gameQueryPortOffset) { addAttemptWithPort(userOptions.port + gameQueryPortOffset) } portOffsetArray.forEach((portOffset) => { addAttemptWithPort(userOptions.port + portOffset) })
if (userOptions.port === gameOptions.port && gameQueryPort) { addAttemptWithPort(gameQueryPort) } if (userOptions.port === gameOptions.port && gameQueryPort) { addAttemptWithPort(gameQueryPort) }
} }
attempts.push(optionsCollection) attempts.push(optionsCollection)
} else if (gameQueryPort) { } else if (gameQueryPort) {
addAttemptWithPort(gameQueryPort) addAttemptWithPort(gameQueryPort)
} else if (gameOptions.port) { } else if (gameOptions.port) {
addAttemptWithPort(gameOptions.port + (gameQueryPortOffset || 0)) portOffsetArray.forEach((portOffset) => { addAttemptWithPort(gameOptions.port + portOffset) })
} else { } else {
// Hopefully the request doesn't need a port. If it does, it'll fail when making the request. // Hopefully the request doesn't need a port. If it does, it'll fail when making the request.
attempts.push(optionsCollection) attempts.push(optionsCollection)