mirror of
https://github.com/tribufu/node-gamedig
synced 2026-06-01 09:42:41 +00:00
Misc tidying
This commit is contained in:
parent
a3c14a8d42
commit
add06a7d8f
4 changed files with 11 additions and 4 deletions
|
|
@ -4,6 +4,8 @@ var argv = require('optimist').argv;
|
||||||
|
|
||||||
var debug = argv.debug;
|
var debug = argv.debug;
|
||||||
delete argv.debug;
|
delete argv.debug;
|
||||||
|
var outputFormat = argv.output;
|
||||||
|
delete argv.output;
|
||||||
|
|
||||||
var options = {};
|
var options = {};
|
||||||
for(var key in argv) {
|
for(var key in argv) {
|
||||||
|
|
@ -22,6 +24,10 @@ if(debug) Gamedig.debug = true;
|
||||||
Gamedig.query(
|
Gamedig.query(
|
||||||
options,
|
options,
|
||||||
function(state) {
|
function(state) {
|
||||||
console.log(state);
|
if(outputFormat == 'pretty') {
|
||||||
|
console.log(JSON.stringify(state,null,' '));
|
||||||
|
} else {
|
||||||
|
console.log(JSON.stringify(state));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,6 @@ module.exports = require('./protocols/gamespy3').extend({
|
||||||
},
|
},
|
||||||
finalizeState: function(state) {
|
finalizeState: function(state) {
|
||||||
this._super(state);
|
this._super(state);
|
||||||
console.log(state.players.length);
|
|
||||||
console.log(state.raw.numplayers);
|
|
||||||
if(!state.players.length && parseInt(state.raw.numplayers)) {
|
if(!state.players.length && parseInt(state.raw.numplayers)) {
|
||||||
for(var i = 0; i < parseInt(state.raw.numplayers); i++) {
|
for(var i = 0; i < parseInt(state.raw.numplayers); i++) {
|
||||||
state.players.push({});
|
state.players.push({});
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ var udpSocket = dgram.createSocket('udp4');
|
||||||
udpSocket.unref();
|
udpSocket.unref();
|
||||||
udpSocket.bind(21943);
|
udpSocket.bind(21943);
|
||||||
udpSocket.on('message', function(buffer, rinfo) {
|
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++) {
|
for(var i = 0; i < activeQueries.length; i++) {
|
||||||
var query = activeQueries[i];
|
var query = activeQueries[i];
|
||||||
if(
|
if(
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,9 @@ Reader.prototype = {
|
||||||
this.i += 4;
|
this.i += 4;
|
||||||
return r;
|
return r;
|
||||||
},
|
},
|
||||||
|
rest: function() {
|
||||||
|
return this.buffer.slice(this.i);
|
||||||
|
},
|
||||||
done: function() {
|
done: function() {
|
||||||
return this.i >= this.buffer.length;
|
return this.i >= this.buffer.length;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue