From 0d1577fa35035a148769b0230011aefad870f770 Mon Sep 17 00:00:00 2001 From: Michael Morrison Date: Mon, 9 Sep 2013 23:50:23 -0500 Subject: [PATCH] bunches of updates: find bots in source engine add altaddress pass address to query object output --- index.js | 10 ++++++++-- protocols/core.js | 1 + protocols/source.js | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 80a988b..a705dac 100644 --- a/index.js +++ b/index.js @@ -9,16 +9,20 @@ 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); for(var i = 0; i < activeQueries.length; i++) { var query = activeQueries[i]; - if(query.options.address != rinfo.address) continue; + if( + query.options.address != rinfo.address + && query.options.altaddress != rinfo.address + ) continue; if(query.options.port != rinfo.port) continue; query._udpResponse(buffer); break; } }); -module.exports = { +Gamedig = { query: function(options,callback) { if(callback) options.callback = callback; @@ -48,3 +52,5 @@ module.exports = { } }; + +module.exports = Gamedig; diff --git a/protocols/core.js b/protocols/core.js index c7c35a8..7865f86 100644 --- a/protocols/core.js +++ b/protocols/core.js @@ -62,6 +62,7 @@ module.exports = Class.extend(EventEmitter,{ state.query = {}; if('host' in this.options) state.query.host = this.options.host; + if('address' in this.options) state.query.address = this.options.address; if('port' in this.options) state.query.port = this.options.port; state.query.type = this.type; if('pretty' in this) state.query.pretty = this.pretty; diff --git a/protocols/source.js b/protocols/source.js index 436b985..dcabe6c 100644 --- a/protocols/source.js +++ b/protocols/source.js @@ -99,6 +99,24 @@ module.exports = require('./core').extend({ name:name, score:score, time:time }); } + + // if we didn't find the bots, iterate + // through and guess which ones they are + if(!state.bots.length) { + var maxTime = 0; + state.players.forEach(function(player) { + maxTime = Math.max(player.time,maxTime); + }); + for(var i = 0; i < state.players.length; i++) { + var player = state.players[i]; + if(state.bots.length >= state.raw.numbots) continue; + if(player.time != maxTime) continue; + state.bots.push(player); + state.players.splice(i, 1); + i--; + } + } + c(); }); },