forked from gamedig/node-gamedig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
palworld.js
32 lines (26 loc) · 1.04 KB
/
palworld.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
import Core from './core.js'
export default class palworld extends Core {
async makeCall (endpoint) {
const url = `http://${this.options.host}:${this.options.port}/v1/api/${endpoint}`
const headers = {
Authorization: `Basic ${Buffer.from(`${this.options.username}:${this.options.password}`).toString('base64')}`,
Accept: 'application/json'
}
return await this.request({ url, headers, method: 'GET', responseType: 'json' })
}
async run (state) {
const serverInfo = await this.makeCall('info')
state.version = serverInfo.version
state.name = serverInfo.servername
state.raw.serverInfo = serverInfo
const { players } = await this.makeCall('players')
state.numplayers = players.length
state.players = players.map(p => p.name)
state.raw.players = players
state.raw.settings = await this.makeCall('settings')
const metrics = await this.makeCall('metrics')
state.numplayers = metrics.currentplayernum
state.maxplayers = metrics.maxplayernum
state.raw.metrics = metrics
}
}