diff --git a/bin/gamedig.js b/bin/gamedig.js index 1a06c19..5fadfe6 100644 --- a/bin/gamedig.js +++ b/bin/gamedig.js @@ -4,6 +4,8 @@ var argv = require('optimist').argv; var debug = argv.debug; delete argv.debug; +var outputFormat = argv.output; +delete argv.output; var options = {}; for(var key in argv) { @@ -22,6 +24,10 @@ if(debug) Gamedig.debug = true; Gamedig.query( options, function(state) { - console.log(state); + if(outputFormat == 'pretty') { + console.log(JSON.stringify(state,null,' ')); + } else { + console.log(JSON.stringify(state)); + } } ); diff --git a/games/jcmp.js b/games/jcmp.js index 95c91c4..ea670d6 100644 --- a/games/jcmp.js +++ b/games/jcmp.js @@ -19,8 +19,6 @@ module.exports = require('./protocols/gamespy3').extend({ }, finalizeState: function(state) { this._super(state); - console.log(state.players.length); - console.log(state.raw.numplayers); if(!state.players.length && parseInt(state.raw.numplayers)) { for(var i = 0; i < parseInt(state.raw.numplayers); i++) { state.players.push({}); diff --git a/lib/index.js b/lib/index.js index 5619340..151ff74 100644 --- a/lib/index.js +++ b/lib/index.js @@ -10,7 +10,7 @@ var udpSocket = dgram.createSocket('udp4'); udpSocket.unref(); udpSocket.bind(21943); udpSocket.on('message', function(buffer, rinfo) { - if(Gamedig.debug) console.log("Received",buffer,rinfo.address,rinfo.port); + if(Gamedig.debug) console.log(rinfo.address+':'+rinfo.port+" <-- "+buffer.toString('hex')); for(var i = 0; i < activeQueries.length; i++) { var query = activeQueries[i]; if( diff --git a/lib/reader.js b/lib/reader.js index f95569a..c5404e9 100644 --- a/lib/reader.js +++ b/lib/reader.js @@ -105,6 +105,9 @@ Reader.prototype = { this.i += 4; return r; }, + rest: function() { + return this.buffer.slice(this.i); + }, done: function() { return this.i >= this.buffer.length; }