2013-07-10 17:34:16 +02:00
|
|
|
var request = require('request');
|
|
|
|
|
2014-02-03 21:00:51 +01:00
|
|
|
module.exports = require('./core').extend({
|
2013-07-12 11:12:02 +02:00
|
|
|
run: function(state) {
|
2013-07-10 17:34:16 +02:00
|
|
|
var self = this;
|
|
|
|
request({
|
2014-02-03 21:00:51 +01:00
|
|
|
uri: 'http://'+this.options.address+':'+this.options.port_query+'/v2/server/status',
|
2013-07-10 17:34:16 +02:00
|
|
|
timeout: 3000,
|
2013-10-12 08:43:16 +02:00
|
|
|
qs: {
|
|
|
|
players: 'true',
|
|
|
|
token: this.options.token
|
|
|
|
}
|
2013-07-10 17:34:16 +02:00
|
|
|
}, function(e,r,body) {
|
2014-02-02 12:58:36 +01:00
|
|
|
if(e) return self.fatal('HTTP error');
|
2013-07-10 17:34:16 +02:00
|
|
|
var json;
|
|
|
|
try {
|
|
|
|
json = JSON.parse(body);
|
|
|
|
} catch(e) {
|
2014-02-02 12:58:36 +01:00
|
|
|
return self.fatal('Invalid JSON');
|
2013-07-10 17:34:16 +02:00
|
|
|
}
|
|
|
|
|
2014-02-02 12:58:36 +01:00
|
|
|
if(json.status != 200) return self.fatal('Invalid status');
|
2013-07-10 17:34:16 +02:00
|
|
|
|
2013-10-12 08:43:16 +02:00
|
|
|
json.players.forEach(function(one) {
|
|
|
|
state.players.push({name:one.nickname,team:one.team});
|
2013-07-10 17:34:16 +02:00
|
|
|
});
|
2013-07-12 11:12:02 +02:00
|
|
|
|
|
|
|
state.name = json.name;
|
|
|
|
state.raw.port = json.port;
|
|
|
|
state.raw.numplayers = json.playercount;
|
2013-07-10 17:34:16 +02:00
|
|
|
|
2013-07-12 11:12:02 +02:00
|
|
|
self.finish(state);
|
2013-07-10 17:34:16 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|