UNPKG

jka-core

Version:

Library for working with Jedi Academy servers

76 lines (75 loc) 2.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.rconStatusYbeproxyParser = void 0; const index_1 = require("../../../index"); const gametype_mapper_1 = require("../../mappers/gametype.mapper"); const clientUsersFromRconStatusYbeproxy_parser_1 = require("../clientUsers/clientUsersFromRconStatusYbeproxy.parser"); function rconStatusYbeproxyParser(strToParse) { let lines = strToParse.split('\n'); if (lines.length < 7) throw new Error('No information provided!'); const clientsInfo = []; let hostname = ''; let ip = ''; let port = ''; let os = ''; let version = ''; let protocol = ''; let gamename = ''; let map = ''; let gametype = index_1.EGametypes.DUEL; lines.map(line => { // Skip rubbish lines if (!line || line.startsWith('-') || line.startsWith('score') || line.startsWith('players')) return; if (line.startsWith('hostname')) { const match = line.match(/^hostname:\s(.+)\^7/); if (match) { hostname = match[1]; } } else if (line.startsWith('server')) { const match = line.match(/^server\s{2}:\s([0-9\.]+):(\d{1,5}),\s(\S+),/); if (match) { ip = match[1]; port = match[2]; os = match[3]; } } else if (line.startsWith('game')) { const match = line.match(/^game\s{4}:\s([0-9\.]+)\s(\d+),\s(\S+)/); if (match) { version = match[1]; protocol = match[2]; gamename = match[3]; } } else if (line.startsWith('map')) { const match = line.match(/^map\s{5}:\s\^7(\S+)\^7, \S+\((\d)\)$/); if (match) { map = match[1]; gametype = (0, gametype_mapper_1.gametypeNumToNamesMapper)(match[2]); } } else { clientsInfo.push(line); } }); return { type: index_1.EServerTypes.YBEPROXY, hostname, ip, port, os, version, protocol, gamename, map, gametype, players: (0, clientUsersFromRconStatusYbeproxy_parser_1.clientUsersFromRconStatusYbeproxy)(clientsInfo), }; } exports.rconStatusYbeproxyParser = rconStatusYbeproxyParser;