2019-01-10 13:03:07 +01:00
|
|
|
const Core = require('./core');
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2019-01-07 01:52:03 +01:00
|
|
|
class Terraria extends Core {
|
2019-01-10 13:03:07 +01:00
|
|
|
async run(state) {
|
|
|
|
const body = await this.request({
|
2019-01-12 11:43:36 +01:00
|
|
|
uri: 'http://'+this.options.address+':'+this.options.port+'/v2/server/status',
|
2017-08-09 12:32:09 +02:00
|
|
|
qs: {
|
|
|
|
players: 'true',
|
|
|
|
token: this.options.token
|
|
|
|
}
|
2019-01-10 13:03:07 +01:00
|
|
|
});
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2019-01-10 13:03:07 +01:00
|
|
|
const json = JSON.parse(body);
|
|
|
|
if(json.status !== 200) throw new Error('Invalid status');
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2019-01-10 13:03:07 +01:00
|
|
|
for (const one of json.players) {
|
|
|
|
state.players.push({name:one.nickname,team:one.team});
|
|
|
|
}
|
2017-08-09 12:32:09 +02:00
|
|
|
|
2019-01-10 13:03:07 +01:00
|
|
|
state.name = json.name;
|
2019-01-12 12:45:09 +01:00
|
|
|
state.gamePort = json.port;
|
2019-01-10 13:03:07 +01:00
|
|
|
state.raw.numplayers = json.playercount;
|
2017-08-09 12:32:09 +02:00
|
|
|
}
|
2017-08-09 11:05:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Terraria;
|