diff --git a/CHANGELOG.md b/CHANGELOG.md index 43baad8..79cd2c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/protocols/beammp.js b/protocols/beammp.js index 87deda5..18bf85d 100644 --- a/protocols/beammp.js +++ b/protocols/beammp.js @@ -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 + } }