2017-08-09 11:05:55 +02:00
|
|
|
const request = require('request');
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2017-08-09 11:05:55 +02:00
|
|
|
class Terraria extends require('./core') {
|
2017-08-09 12:32:09 +02:00
|
|
|
run(state) {
|
|
|
|
request({
|
|
|
|
uri: 'http://'+this.options.address+':'+this.options.port_query+'/v2/server/status',
|
|
|
|
timeout: 3000,
|
|
|
|
qs: {
|
|
|
|
players: 'true',
|
|
|
|
token: this.options.token
|
|
|
|
}
|
|
|
|
}, (e,r,body) => {
|
|
|
|
if(e) return this.fatal('HTTP error');
|
|
|
|
let json;
|
|
|
|
try {
|
|
|
|
json = JSON.parse(body);
|
|
|
|
} catch(e) {
|
|
|
|
return this.fatal('Invalid JSON');
|
|
|
|
}
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2017-08-09 12:32:09 +02:00
|
|
|
if(json.status !== 200) return this.fatal('Invalid status');
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2017-08-09 12:32:09 +02:00
|
|
|
for (const one of json.players) {
|
|
|
|
state.players.push({name:one.nickname,team:one.team});
|
|
|
|
}
|
|
|
|
|
|
|
|
state.name = json.name;
|
|
|
|
state.raw.port = json.port;
|
|
|
|
state.raw.numplayers = json.playercount;
|
|
|
|
|
|
|
|
this.finish(state);
|
|
|
|
});
|
|
|
|
}
|
2017-08-09 11:05:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Terraria;
|