node-gamedig/protocols/terraria.js
Michael Morrison bc6b5c9225 Super epic commit 3
Move everything around
Add another 50 or so games
*** 'port' option should now be CONNECT port, not query port ***
add reference for many missing games
2014-02-03 14:00:51 -06:00

35 lines
801 B
JavaScript

var request = require('request');
module.exports = require('./core').extend({
run: function(state) {
var self = this;
request({
uri: 'http://'+this.options.address+':'+this.options.port_query+'/v2/server/status',
timeout: 3000,
qs: {
players: 'true',
token: this.options.token
}
}, function(e,r,body) {
if(e) return self.fatal('HTTP error');
var json;
try {
json = JSON.parse(body);
} catch(e) {
return self.fatal('Invalid JSON');
}
if(json.status != 200) return self.fatal('Invalid status');
json.players.forEach(function(one) {
state.players.push({name:one.nickname,team:one.team});
});
state.name = json.name;
state.raw.port = json.port;
state.raw.numplayers = json.playercount;
self.finish(state);
});
}
});