fix(protocols/beammp): not matching on given port (#730)

* fix(protocols/beammp): not matching on port

* chore: eslint

* docs: update CHANGELOG.md

* fix: some other cases

* fix: sorting on array contaning numbers and other forms of none
This commit is contained in:
CosminPerRam 2025-08-28 16:09:28 +03:00 committed by GitHub
parent 5d5273dce3
commit 27709572c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View file

@ -4,6 +4,7 @@
* Fix: detect BFBC2 Vietnam DLC as BFBC2 (By @cetteup #713)
* Feat: SCP: Secret Laboratory (2020) - Added support (#715, thanks @Draakoor)
* Fix: Farming Simulator handle possible missing mod attribute (By @yellowfromseegg #723)
* Fix: BeamMP would not match on given port (#730)
## 5.3.1
* Fix: HTTP requests would end up making more retries than needed due to got's internal retry mechanism (#690, thanks @RattleSN4K3)

View file

@ -7,7 +7,10 @@ export default class beammp extends Core {
master.options = this.options
const masterState = await master.runOnceSafe()
const servers = masterState.raw.servers
const server = servers.find(s => s.ip === this.options.address)
const sameIpServers = servers.filter(s => s.ip === this.options.address)
const sortedServers = sameIpServers.sort(s => parseInt(s.port))
// Cause some don't have ports specified, so we prioritize those who do
const server = sortedServers.find(s => s.ip === this.options.address && this.matchPort(s.port))
if (!server) {
throw new Error('Server not found in the master list')
@ -30,4 +33,14 @@ export default class beammp extends Core {
state.raw = server
if ('version' in state.raw) state.version = state.raw.version
}
matchPort (givenPort) {
const parsedPort = parseInt(givenPort)
const port = this.options.port
if (!port || isNaN(parsedPort)) {
return true
}
return port === parsedPort
}
}