2018-02-13 11:07:31 +01:00
|
|
|
const request = require('request');
|
|
|
|
|
2017-08-10 13:49:42 +02:00
|
|
|
class FiveM extends require('./quake2') {
|
|
|
|
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
|
|
|
|
|
|
|
finish(state) {
|
|
|
|
request({
|
|
|
|
uri: 'http://'+this.options.address+':'+this.options.port_query+'/info.json',
|
|
|
|
timeout: this.options.socketTimeout
|
|
|
|
}, (e,r,body) => {
|
|
|
|
if(e) return this.fatal('HTTP error');
|
|
|
|
let json;
|
|
|
|
try {
|
|
|
|
json = JSON.parse(body);
|
|
|
|
} catch(e) {
|
|
|
|
return this.fatal('Invalid JSON');
|
|
|
|
}
|
|
|
|
|
|
|
|
state.raw.info = json;
|
|
|
|
|
|
|
|
request({
|
|
|
|
uri: 'http://'+this.options.address+':'+this.options.port_query+'/players.json',
|
|
|
|
timeout: this.options.socketTimeout
|
|
|
|
}, (e,r,body) => {
|
|
|
|
if(e) return this.fatal('HTTP error');
|
|
|
|
let json;
|
|
|
|
try {
|
|
|
|
json = JSON.parse(body);
|
|
|
|
} catch(e) {
|
|
|
|
return this.fatal('Invalid JSON');
|
|
|
|
}
|
|
|
|
|
|
|
|
state.raw.players = json;
|
|
|
|
|
|
|
|
state.players = [];
|
|
|
|
for (const player of json) {
|
|
|
|
state.players.push({name:player.name, ping:player.ping});
|
|
|
|
}
|
|
|
|
|
|
|
|
super.finish(state);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2017-08-10 13:49:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = FiveM;
|