mirror of
https://github.com/tribufu/node-gamedig
synced 2026-05-18 09:35:50 +00:00
More async conversion
This commit is contained in:
parent
484e99b29c
commit
efe12a00aa
25 changed files with 774 additions and 858 deletions
|
|
@ -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});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue