From 6bfbc883bee463fcc64988d7cfb424f2d31c8712 Mon Sep 17 00:00:00 2001 From: CosminPerRam Date: Sat, 30 Dec 2023 22:41:56 +0200 Subject: [PATCH] feat: add BeamMP support (#447) * feat: add beammp support * fix: cleanup server name of escape codes * chore: add a new line for better readability --- CHANGELOG.md | 1 + GAMES_LIST.md | 1 + lib/games.js | 7 +++++++ protocols/beammp.js | 32 ++++++++++++++++++++++++++++++++ protocols/beammpmaster.js | 17 +++++++++++++++++ protocols/index.js | 4 +++- 6 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 protocols/beammp.js create mode 100644 protocols/beammpmaster.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 867e875..b0c239b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ see next point) and `tshock` (which is `terraria`). * Removed the players::setNum method, the library will no longer add empty players as a placeholder in the `players` fields. * Stabilized field `numplayers`. +* BeamMP (2021) - Added support. ### 4.3.1 * Fixed support for the Minecraft [Better Compatibility Checker](https://www.curseforge.com/minecraft/mc-mods/better-compatibility-checker) Mod (By @Douile, #436). diff --git a/GAMES_LIST.md b/GAMES_LIST.md index 52161f6..7172cef 100644 --- a/GAMES_LIST.md +++ b/GAMES_LIST.md @@ -31,6 +31,7 @@ | `ballisticoverkill` | Ballistic Overkill (2017) | [Valve Protocol](#valve) | | `barotrauma` | Barotrauma (2019) | [Valve Protocol](#valve) | | `bat1944` | Battalion 1944 (2018) | [Valve Protocol](#valve) | +| `beammp` | BeamMP (2021) | | | `bf1942` | Battlefield 1942 (2002) | | | `bf2` | Battlefield 2 (2005) | | | `bf2142` | Battlefield 2142 (2006) | | diff --git a/lib/games.js b/lib/games.js index 0ce8206..0ced694 100644 --- a/lib/games.js +++ b/lib/games.js @@ -227,6 +227,13 @@ export const games = { protocol: 'valve' } }, + beammp: { + name: 'BeamMP (2021)', + options: { + port: 30814, + protocol: 'beammp' + } + }, bf1942: { name: 'Battlefield 1942 (2002)', options: { diff --git a/protocols/beammp.js b/protocols/beammp.js new file mode 100644 index 0000000..0dfe866 --- /dev/null +++ b/protocols/beammp.js @@ -0,0 +1,32 @@ +import Core from './core.js' +import beammpmaster from './beammpmaster.js' + +export default class beammp extends Core { + async run (state) { + const master = new beammpmaster() + master.options = this.options + const masterState = await master.runOnceSafe() + const servers = masterState.raw.servers + const server = servers.find(s => s.ip === this.options.host) + + if (!server) { + throw new Error('Server not found in the master list') + } + + state.name = server.sname.replace(/\^./g, '') + state.map = server.map + state.password = server.password + state.numplayers = parseInt(server.players) + state.maxplayers = parseInt(server.players) + + const players = server.playerslist.split(';') + if (players[players.length - 1] === '') { + players.pop() + } + players.forEach(player => { + state.players.push({ name: player }) + }) + + state.raw = server + } +} diff --git a/protocols/beammpmaster.js b/protocols/beammpmaster.js new file mode 100644 index 0000000..e86fbee --- /dev/null +++ b/protocols/beammpmaster.js @@ -0,0 +1,17 @@ +import Core from './core.js' + +export default class beammpmaster extends Core { + constructor () { + super() + + // Don't use the tcp ping probing + this.usedTcp = true + } + + async run (state) { + state.raw.servers = await this.request({ + url: 'https://backend.beammp.com/servers-info', + responseType: 'json' + }) + } +} diff --git a/protocols/index.js b/protocols/index.js index 36c1e6e..d512804 100644 --- a/protocols/index.js +++ b/protocols/index.js @@ -48,11 +48,13 @@ import valve from './valve.js' import vcmp from './vcmp.js' import ventrilo from './ventrilo.js' import warsow from './warsow.js' +import beammpmaster from './beammpmaster.js' +import beammp from './beammp.js' export { armagetron, ase, asa, assettocorsa, battlefield, buildandshoot, cs2d, discord, doom3, eco, epic, ffow, fivem, gamespy1, gamespy2, gamespy3, geneshift, goldsrc, hexen2, jc2mp, kspdmp, mafia2mp, mafia2online, minecraft, minecraftbedrock, minecraftvanilla, mumble, mumbleping, nadeo, openttd, quake1, quake2, quake3, rfactor, samp, savage2, starmade, starsiege, teamspeak2, teamspeak3, terraria, tribes1, tribes1master, unreal2, ut3, valve, - vcmp, ventrilo, warsow, eldewrito + vcmp, ventrilo, warsow, eldewrito, beammpmaster, beammp }