forked from gamedig/node-gamedig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
beammp.js
33 lines (28 loc) · 977 Bytes
/
beammp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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.address)
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.maxplayers)
const players = server.playerslist.split(';')
if (players[players.length - 1] === '') {
players.pop()
}
players.forEach(player => {
state.players.push({ name: player })
})
state.raw = server
if ('version' in state.raw) state.version = state.raw.version
}
}