node-gamedig/protocols/fivem.js

37 lines
988 B
JavaScript
Raw Normal View History

2019-01-09 12:35:11 +01:00
const Quake2 = require('./quake2');
2018-02-13 11:07:31 +01:00
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;
state.players = [];
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
}
module.exports = FiveM;