mirror of
https://github.com/gamedig/node-gamedig.git
synced 2024-09-29 21:51:31 +02:00
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:
parent
9c785bcda0
commit
4d31e29e70
@ -54,6 +54,7 @@ Otherwise, the returned object is guaranteed to contain the following keys:
|
|||||||
* **name**
|
* **name**
|
||||||
* **map**
|
* **map**
|
||||||
* **password**: Boolean
|
* **password**: Boolean
|
||||||
|
* **onlineplayers**
|
||||||
* **maxplayers**
|
* **maxplayers**
|
||||||
* **players**: (array of objects) Each object **may** contain name, ping, score, team, address
|
* **players**: (array of objects) Each object **may** contain name, ping, score, team, address
|
||||||
* **bots**: Same schema as players
|
* **bots**: Same schema as players
|
||||||
|
@ -39,9 +39,10 @@ module.exports = Class.extend(EventEmitter,{
|
|||||||
name: '',
|
name: '',
|
||||||
map: '',
|
map: '',
|
||||||
password: false,
|
password: false,
|
||||||
|
|
||||||
raw: {},
|
raw: {},
|
||||||
|
|
||||||
|
onlineplayers: 0,
|
||||||
maxplayers: 0,
|
maxplayers: 0,
|
||||||
players: [],
|
players: [],
|
||||||
bots: []
|
bots: []
|
||||||
@ -61,6 +62,9 @@ module.exports = Class.extend(EventEmitter,{
|
|||||||
if(this.options.notes)
|
if(this.options.notes)
|
||||||
state.notes = this.options.notes;
|
state.notes = this.options.notes;
|
||||||
|
|
||||||
|
//Additional Conditionals
|
||||||
|
if('players' in state) state.onlineplayers = state.players.length;
|
||||||
|
|
||||||
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('address' in this.options) state.query.address = this.options.address;
|
||||||
@ -82,7 +86,7 @@ module.exports = Class.extend(EventEmitter,{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.timers = [];
|
this.timers = [];
|
||||||
|
|
||||||
if(this.tcpSocket) {
|
if(this.tcpSocket) {
|
||||||
this.tcpSocket.destroy();
|
this.tcpSocket.destroy();
|
||||||
delete this.tcpSocket;
|
delete this.tcpSocket;
|
||||||
@ -124,7 +128,7 @@ module.exports = Class.extend(EventEmitter,{
|
|||||||
},
|
},
|
||||||
parseDns: function(host,c) {
|
parseDns: function(host,c) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
function resolveStandard(host,c) {
|
function resolveStandard(host,c) {
|
||||||
dns.lookup(host, function(err,address,family) {
|
dns.lookup(host, function(err,address,family) {
|
||||||
if(err) return self.fatal(err);
|
if(err) return self.fatal(err);
|
||||||
@ -139,7 +143,7 @@ module.exports = Class.extend(EventEmitter,{
|
|||||||
var line = addresses[0];
|
var line = addresses[0];
|
||||||
self.options.port = line.port;
|
self.options.port = line.port;
|
||||||
var srvhost = line.name;
|
var srvhost = line.name;
|
||||||
|
|
||||||
if(srvhost.match(/\d+\.\d+\.\d+\.\d+/)) {
|
if(srvhost.match(/\d+\.\d+\.\d+\.\d+/)) {
|
||||||
self.options.address = srvhost;
|
self.options.address = srvhost;
|
||||||
c();
|
c();
|
||||||
@ -177,8 +181,8 @@ module.exports = Class.extend(EventEmitter,{
|
|||||||
return id;
|
return id;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
trueTest: function(str) {
|
trueTest: function(str) {
|
||||||
if(typeof str == 'boolean') return str;
|
if(typeof str == 'boolean') return str;
|
||||||
if(typeof str == 'number') return str != 0;
|
if(typeof str == 'number') return str != 0;
|
||||||
@ -228,7 +232,7 @@ module.exports = Class.extend(EventEmitter,{
|
|||||||
socket.setTimeout(10000);
|
socket.setTimeout(10000);
|
||||||
socket.setNoDelay(true);
|
socket.setNoDelay(true);
|
||||||
if(this.debug) console.log(address+':'+port+" TCPCONNECT");
|
if(this.debug) console.log(address+':'+port+" TCPCONNECT");
|
||||||
|
|
||||||
var writeHook = socket.write;
|
var writeHook = socket.write;
|
||||||
socket.write = function(data) {
|
socket.write = function(data) {
|
||||||
if(self.debug) console.log(address+':'+port+" TCP--> "+data.toString('hex'));
|
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(!('address' in this.options)) return this.fatal('Attempted to send without setting an address');
|
||||||
|
|
||||||
if(typeof buffer == 'string') buffer = new Buffer(buffer,'binary');
|
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'));
|
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);
|
this.udpSocket.send(buffer,0,buffer.length,this.options.port_query,this.options.address);
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user