forked from gamedig/node-gamedig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minetest.js
39 lines (31 loc) · 1.04 KB
/
minetest.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
34
35
36
37
38
39
import Core from './core.js'
export default class minetest extends Core {
constructor () {
super()
this.usedTcp = true
}
async run (state) {
const servers = await this.request({
url: 'https://servers.minetest.net/list',
responseType: 'json'
})
if (servers == null) {
throw new Error('Unable to retrieve master server list')
}
const serverInfo = servers.list.find(
(server) =>
server.ip === this.options.address && server.port === this.options.port
)
if (serverInfo == null) {
throw new Error('Server not found in master server list')
}
const players = serverInfo.clients_list || [] // the 'players' field is undefined if there are no players
state.name = serverInfo.name
state.password = serverInfo.password
state.numplayers = serverInfo.clients || players.length
state.maxplayers = serverInfo.clients_max
state.players = players.map((player) => ({ name: player, raw: {} }))
state.raw = serverInfo
state.version = serverInfo.version
}
}