node-gamedig/protocols/kspdmp.js
CosminPerRam ad9adff06c
Move to ES6 module (#357)
* Redo imports and exports for lib

* Redo imports and exports for bim

* Redo imports and exports for games

* Remove remaining module.exports

* Use export default in lib

* Use export default in protocols

* Fix import in genreadme.js

* Make package module and solve __dirname

* Fix minecraft protocol imports

* Fix imports on games and make binary runnable

* Renamed protocol class exports to lowercase

* Export promises class as default

* Update README.md to use imports instead of require

* Update CHANGELOG to mention the changes.

* Remove Valve unused imports

* Fix iconv import
2023-09-14 23:28:31 +03:00

27 lines
794 B
JavaScript

import Core from './core.js';
export default class kspdmp extends Core {
async run(state) {
const json = await this.request({
url: 'http://'+this.options.address+':'+this.options.port,
responseType: '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;
state.gamePort = json.port;
if (json.players) {
const split = json.players.split(', ');
for (const name of split) {
state.players.push({name:name});
}
}
}
}