From a777ec79e186814525d139f823fd4659d1bc1fd9 Mon Sep 17 00:00:00 2001 From: Michael Morrison Date: Wed, 10 Jul 2013 10:34:16 -0500 Subject: [PATCH] Add tshock --- protocols/tshock.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 protocols/tshock.js diff --git a/protocols/tshock.js b/protocols/tshock.js new file mode 100644 index 0000000..170473d --- /dev/null +++ b/protocols/tshock.js @@ -0,0 +1,38 @@ +var request = require('request'); + +module.exports = require('./core').extend({ + init: function() { + this._super(); + this.options.port = 7878; + }, + run: function() { + var self = this; + request({ + uri: 'http://'+this.options.address+':'+this.options.port+'/status', + timeout: 3000, + }, 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'); + + var players = []; + var split = json.players.split(','); + split.forEach(function(one) { + players.push({name:one}); + }); + + self.finish({ + 'name': json.name, + 'port': json.port, + 'numplayers': json.playercount, + 'players': players + }); + }); + } +});