node-gamedig/games/terraria.js
Michael Morrison c82554ad1a Super mega-commit
Organize files
Rewrite readme for new game IDs and command line
Add command line access
Replace some dependencies that required binaries with simpler alternatives
Switch gbxremote back to upstream, Closes #2
Moved simple aliases into an alias file, rather than seperate files for each
Patched nearly every protocol variant with tons of bug fixes
Re-tested every combination of server and protocol types except nadeo
Added alternative minecraft query check (minecraftping)
Fixed mutant factions query
Fixed valve gold not working at all
Stripped colors more reliably from protocols that support colors
Added a couple more fields to ut2004 and killing floor
and more that I probably forgot.

This shouldn't break compatibility too bad -- at the most, some game IDs may have changed.
2014-01-31 16:27:52 -06:00

41 lines
902 B
JavaScript

var request = require('request');
module.exports = require('./protocols/core').extend({
init: function() {
this._super();
this.pretty = 'Terraria';
this.options.port = 7878;
},
run: function(state) {
var self = this;
request({
uri: 'http://'+this.options.address+':'+this.options.port+'/v2/server/status',
timeout: 3000,
qs: {
players: 'true',
token: this.options.token
}
}, function(e,r,body) {
if(e) return self.error('HTTP error');
var json;
try {
json = JSON.parse(body);
} catch(e) {
return self.error('Invalid JSON');
}
if(json.status != 200) return self.error('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);
});
}
});