node-gamedig/protocols/kspdmp.js

30 lines
812 B
JavaScript
Raw Normal View History

2019-01-10 13:03:07 +01:00
const Core = require('./core');
2018-02-13 10:24:40 +01:00
class Kspdmp 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
2019-01-10 13:03:07 +01:00
});
2018-02-13 10:24:40 +01:00
2019-01-10 13:03:07 +01:00
const json = JSON.parse(body);
for (const one of json.players) {
state.players.push({name:one.nickname,team:one.team});
}
2018-02-13 10:24:40 +01:00
2019-01-10 13:03:07 +01:00
for (const key of Object.keys(json)) {
state.raw[key] = json[key];
}
state.name = json.server_name;
state.maxplayers = json.max_players;
2019-01-12 12:45:09 +01:00
state.gamePort = json.port;
2019-01-10 13:03:07 +01:00
if (json.players) {
const split = json.players.split(', ');
for (const name of split) {
state.players.push({name:name});
2018-02-13 10:24:40 +01:00
}
2019-01-10 13:03:07 +01:00
}
2018-02-13 10:24:40 +01:00
}
}
module.exports = Kspdmp;