bunches of updates:

find bots in source engine
add altaddress
pass address to query object output
This commit is contained in:
Michael Morrison 2013-09-09 23:50:23 -05:00
parent f543b301dd
commit 0d1577fa35
3 changed files with 27 additions and 2 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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();
});
},