jka-core
Version:
Library for working with Jedi Academy servers
89 lines (88 loc) • 2.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.rconStatusOpenjkParser = void 0;
const index_1 = require("../../../index");
const gametype_mapper_1 = require("../../mappers/gametype.mapper");
const clientUsersFromRconStatusOpenjk_parser_1 = require("../clientUsers/clientUsersFromRconStatusOpenjk.parser");
function rconStatusOpenjkParser(strToParse) {
let lines = strToParse.split('\n');
if (lines.length < 9)
throw new Error('No information provided!');
const clientsInfo = [];
let hostname = '';
let version = '';
let protocol = '26';
let gamename = '';
let ip = '';
let os = '';
let map = '';
let port = '';
let uptime = '';
let gametype = index_1.EGametypes.DUEL;
lines.map(line => {
// Skip rubbish lines
if (!line ||
line.startsWith('players') ||
line.startsWith('-') ||
line.startsWith('cl '))
return;
if (line.startsWith('hostname')) {
const match = line.match(/^hostname\s*:\s(.+)\^7$/);
if (match) {
hostname = match[1];
}
}
else if (line.startsWith('version')) {
const match = line.match(/^version\s*:\s(.+) (\d+)$/);
if (match) {
version = match[1];
protocol = match[2];
}
}
else if (line.startsWith('udp/ip')) {
const match = line.match(/^udp\/ip\s*:\s([0-9\.]+):(\d+)\sos\((\S+)\) .+$/);
if (match) {
ip = match[1];
port = match[2];
os = match[3];
}
}
else if (line.startsWith('game')) {
const match = line.match(/^game\s+:\s(.+)$/);
if (match) {
gamename = match[1];
}
}
else if (line.startsWith('uptime')) {
const match = line.match(/^uptime\s+:\s(\S+)$/);
if (match) {
uptime = match[1];
}
}
else if (line.startsWith('map')) {
const match = line.match(/^map\s+:\s(\S+) gametype\((\d)\)$/);
if (match) {
map = match[1];
gametype = (0, gametype_mapper_1.gametypeNumToNamesMapper)(match[2]);
}
}
else {
clientsInfo.push(line);
}
});
return {
type: index_1.EServerTypes.OPENJK,
hostname,
ip,
port,
os,
version,
protocol,
gamename,
map,
uptime,
gametype,
players: (0, clientUsersFromRconStatusOpenjk_parser_1.clientUsersFromRconStatusOpenjk)(clientsInfo),
};
}
exports.rconStatusOpenjkParser = rconStatusOpenjkParser;