More async conversion

This commit is contained in:
mmorrison 2019-01-10 06:03:07 -06:00
parent 484e99b29c
commit efe12a00aa
25 changed files with 774 additions and 858 deletions

View file

@ -1,38 +1,27 @@
const request = require('request'),
Core = require('./core');
const Core = require('./core');
class Kspdmp extends Core {
run(state) {
request({
uri: 'http://'+this.options.address+':'+this.options.port_query,
timeout: this.options.socketTimeout
}, (e,r,body) => {
if(e) return this.fatal('HTTP error');
let json;
try {
json = JSON.parse(body);
} catch(e) {
return this.fatal('Invalid JSON');
}
for (const one of json.players) {
state.players.push({name:one.nickname,team:one.team});
}
for (const key of Object.keys(json)) {
state.raw[key] = json[key];
}
state.name = json.server_name;
state.maxplayers = json.max_players;
if (json.players) {
const split = json.players.split(', ');
for (const name of split) {
state.players.push({name:name});
}
}
this.finish(state);
async run(state) {
const body = await this.request({
uri: 'http://'+this.options.address+':'+this.options.port_query
});
const json = JSON.parse(body);
for (const one of json.players) {
state.players.push({name:one.nickname,team:one.team});
}
for (const key of Object.keys(json)) {
state.raw[key] = json[key];
}
state.name = json.server_name;
state.maxplayers = json.max_players;
if (json.players) {
const split = json.players.split(', ');
for (const name of split) {
state.players.push({name:name});
}
}
}
}