Added onlineplayers

Added onlineplayers which utilizes the length of the players array to
make it always available.

Possible to add bots to this count but i think just players would be
best.

Updated readme to include this change.
This commit is contained in:
xCausxn 2015-02-21 17:21:56 +00:00
parent 9c785bcda0
commit 4d31e29e70
2 changed files with 13 additions and 8 deletions

View File

@ -54,6 +54,7 @@ Otherwise, the returned object is guaranteed to contain the following keys:
* **name**
* **map**
* **password**: Boolean
* **onlineplayers**
* **maxplayers**
* **players**: (array of objects) Each object **may** contain name, ping, score, team, address
* **bots**: Same schema as players

View File

@ -39,9 +39,10 @@ module.exports = Class.extend(EventEmitter,{
name: '',
map: '',
password: false,
raw: {},
onlineplayers: 0,
maxplayers: 0,
players: [],
bots: []
@ -61,6 +62,9 @@ module.exports = Class.extend(EventEmitter,{
if(this.options.notes)
state.notes = this.options.notes;
//Additional Conditionals
if('players' in state) state.onlineplayers = state.players.length;
state.query = {};
if('host' in this.options) state.query.host = this.options.host;
if('address' in this.options) state.query.address = this.options.address;
@ -82,7 +86,7 @@ module.exports = Class.extend(EventEmitter,{
});
}
this.timers = [];
if(this.tcpSocket) {
this.tcpSocket.destroy();
delete this.tcpSocket;
@ -124,7 +128,7 @@ module.exports = Class.extend(EventEmitter,{
},
parseDns: function(host,c) {
var self = this;
function resolveStandard(host,c) {
dns.lookup(host, function(err,address,family) {
if(err) return self.fatal(err);
@ -139,7 +143,7 @@ module.exports = Class.extend(EventEmitter,{
var line = addresses[0];
self.options.port = line.port;
var srvhost = line.name;
if(srvhost.match(/\d+\.\d+\.\d+\.\d+/)) {
self.options.address = srvhost;
c();
@ -177,8 +181,8 @@ module.exports = Class.extend(EventEmitter,{
return id;
},
trueTest: function(str) {
if(typeof str == 'boolean') return str;
if(typeof str == 'number') return str != 0;
@ -228,7 +232,7 @@ module.exports = Class.extend(EventEmitter,{
socket.setTimeout(10000);
socket.setNoDelay(true);
if(this.debug) console.log(address+':'+port+" TCPCONNECT");
var writeHook = socket.write;
socket.write = function(data) {
if(self.debug) console.log(address+':'+port+" TCP--> "+data.toString('hex'));
@ -292,7 +296,7 @@ module.exports = Class.extend(EventEmitter,{
if(!('address' in this.options)) return this.fatal('Attempted to send without setting an address');
if(typeof buffer == 'string') buffer = new Buffer(buffer,'binary');
if(this.debug) console.log(this.options.address+':'+this.options.port_query+" UDP--> "+buffer.toString('hex'));
this.udpSocket.send(buffer,0,buffer.length,this.options.port_query,this.options.address);
},