UNPKG

jka-core

Version:

Library for working with Jedi Academy servers

84 lines (83 loc) 2.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.rconStatusJaproParser = void 0; const index_1 = require("../../../index"); const gametype_mapper_1 = require("../../mappers/gametype.mapper"); const clientUsersFromRconStatusJapro_parser_1 = require("../clientUsers/clientUsersFromRconStatusJapro.parser"); function rconStatusJaproParser(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; let uptime = ''; lines.map(line => { // Skip rubbish lines if (!line || line.startsWith('-') || line.startsWith('cl') || 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 if (line.startsWith('uptime')) { const match = line.match(/^uptime\s{2}:\s(\S+)/); if (match) { uptime = match[1]; } } else { clientsInfo.push(line); } }); return { type: index_1.EServerTypes.JAPRO, hostname, ip, port, os, version, protocol, gamename, map, gametype, uptime, players: (0, clientUsersFromRconStatusJapro_parser_1.clientUsersFromRconStatusJapro)(clientsInfo), }; } exports.rconStatusJaproParser = rconStatusJaproParser;