2024-04-08 18:41:52 +02:00
|
|
|
import Core from './core.js'
|
2024-01-20 23:36:05 +01:00
|
|
|
|
2024-04-08 18:41:52 +02:00
|
|
|
export default class palworld extends Core {
|
2024-04-08 18:58:50 +02:00
|
|
|
async makeCall (endpoint) {
|
|
|
|
const url = `http://${this.options.host}:${this.options.port}/v1/api/${endpoint}`
|
2024-04-08 18:41:52 +02:00
|
|
|
const headers = {
|
|
|
|
Authorization: `Basic ${Buffer.from(`${this.options.username}:${this.options.password}`).toString('base64')}`,
|
|
|
|
Accept: 'application/json'
|
|
|
|
}
|
2024-01-20 23:36:05 +01:00
|
|
|
|
2024-04-08 18:58:50 +02:00
|
|
|
return await this.request({ url, headers, method: 'GET', responseType: 'json' })
|
|
|
|
}
|
|
|
|
|
|
|
|
async run (state) {
|
|
|
|
const serverInfo = await this.makeCall('info')
|
2024-04-08 18:44:43 +02:00
|
|
|
state.version = serverInfo.version
|
|
|
|
state.name = serverInfo.servername
|
|
|
|
state.raw.serverInfo = serverInfo
|
2024-04-08 18:58:50 +02:00
|
|
|
|
|
|
|
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
|
2024-01-21 22:16:56 +01:00
|
|
|
}
|
2024-01-20 23:36:05 +01:00
|
|
|
}
|