bunches of updates:
find bots in source engine add altaddress pass address to query object output
This commit is contained in:
parent
f543b301dd
commit
0d1577fa35
10
index.js
10
index.js
|
@ -9,16 +9,20 @@ 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);
|
||||||
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(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;
|
if(query.options.port != rinfo.port) continue;
|
||||||
query._udpResponse(buffer);
|
query._udpResponse(buffer);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = {
|
Gamedig = {
|
||||||
|
|
||||||
query: function(options,callback) {
|
query: function(options,callback) {
|
||||||
if(callback) options.callback = callback;
|
if(callback) options.callback = callback;
|
||||||
|
@ -48,3 +52,5 @@ module.exports = {
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports = Gamedig;
|
||||||
|
|
|
@ -62,6 +62,7 @@ module.exports = Class.extend(EventEmitter,{
|
||||||
|
|
||||||
state.query = {};
|
state.query = {};
|
||||||
if('host' in this.options) state.query.host = this.options.host;
|
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;
|
if('port' in this.options) state.query.port = this.options.port;
|
||||||
state.query.type = this.type;
|
state.query.type = this.type;
|
||||||
if('pretty' in this) state.query.pretty = this.pretty;
|
if('pretty' in this) state.query.pretty = this.pretty;
|
||||||
|
|
|
@ -99,6 +99,24 @@ module.exports = require('./core').extend({
|
||||||
name:name, score:score, time:time
|
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();
|
c();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue