node-gamedig/protocols/terraria.js

25 lines
711 B
JavaScript
Raw Normal View History

import Core from './core.js';
2014-10-29 08:02:03 +01:00
export default class terraria extends Core {
2019-01-10 13:03:07 +01:00
async run(state) {
2020-07-05 06:28:03 +02:00
const json = await this.request({
url: 'http://'+this.options.address+':'+this.options.port+'/v2/server/status',
searchParams: {
2017-08-09 12:32:09 +02:00
players: 'true',
token: this.options.token
2020-07-05 06:28:03 +02:00
},
responseType: 'json'
2019-01-10 13:03:07 +01:00
});
2014-10-29 08:02:03 +01:00
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
}
}