From 0de02523f0eb90c2f5a81bc5d62becf01eb0d288 Mon Sep 17 00:00:00 2001 From: mmorrison Date: Tue, 13 Feb 2018 04:07:31 -0600 Subject: [PATCH] Enhance fivem output fixes #79 --- protocols/fivem.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/protocols/fivem.js b/protocols/fivem.js index 438b986..595346f 100644 --- a/protocols/fivem.js +++ b/protocols/fivem.js @@ -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;