node-gamedig/protocols/fivem.js

34 lines
944 B
JavaScript
Raw Normal View History

import quake2 from './quake2.js';
2018-02-13 11:07:31 +01:00
export default class fivem extends quake2 {
2017-08-10 13:49:42 +02:00
constructor() {
super();
this.sendHeader = 'getinfo xxx';
this.responseHeader = 'infoResponse';
2018-05-05 10:31:25 +02:00
this.encoding = 'utf8';
2017-08-10 13:49:42 +02:00
}
2018-02-13 11:07:31 +01:00
2019-01-09 12:35:11 +01:00
async run(state) {
await super.run(state);
2018-02-13 11:07:31 +01:00
2019-01-09 12:35:11 +01:00
{
2020-07-05 06:28:03 +02:00
const json = await this.request({
url: 'http://' + this.options.address + ':' + this.options.port + '/info.json',
responseType: 'json'
2019-01-09 12:35:11 +01:00
});
2018-02-13 11:07:31 +01:00
state.raw.info = json;
2019-01-09 12:35:11 +01:00
}
2018-02-13 11:07:31 +01:00
2019-01-09 12:35:11 +01:00
{
2020-07-05 06:28:03 +02:00
const json = await this.request({
url: 'http://' + this.options.address + ':' + this.options.port + '/players.json',
responseType: 'json'
2018-02-13 11:07:31 +01:00
});
2019-01-09 12:35:11 +01:00
state.raw.players = json;
for (const player of json) {
state.players.push({name: player.name, ping: player.ping});
}
}
2018-02-13 11:07:31 +01:00
}
2017-08-10 13:49:42 +02:00
}