mirror of
https://github.com/gamedig/node-gamedig.git
synced 2024-11-17 17:25:19 +01:00
Enhance fivem output fixes #79
This commit is contained in:
parent
86422d576e
commit
0de02523f0
1 changed files with 41 additions and 0 deletions
|
@ -1,9 +1,50 @@
|
|||
const request = require('request');
|
||||
|
||||
class FiveM extends require('./quake2') {
|
||||
constructor() {
|
||||
super();
|
||||
this.sendHeader = 'getinfo xxx';
|
||||
this.responseHeader = 'infoResponse';
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FiveM;
|
||||
|
|
Loading…
Reference in a new issue