From 403b6d8f34ec19a4bb438cfde99312b2cd239580 Mon Sep 17 00:00:00 2001 From: HardiReady Date: Mon, 6 Nov 2017 14:22:18 +0100 Subject: [PATCH] Use player map for scoreboard players --- api/tools/log-parse-tool.js | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/api/tools/log-parse-tool.js b/api/tools/log-parse-tool.js index f780177..7340d7c 100644 --- a/api/tools/log-parse-tool.js +++ b/api/tools/log-parse-tool.js @@ -17,13 +17,12 @@ const parseWarLog = (lineArray, war) => { players: [] }; - const addPlayersIfNotExists = (inputPlayers) => { - inputPlayers.forEach(player => { - if (player && player.name && player.fraction && !playerArrayContains(stats.players, player)) { - player['warId'] = war._id; - stats.players.push(player); - } - }) + const addPlayerIfNotExists = (inputPlayer) => { + const player = getPlayerAndFractionFromString(inputPlayer); + if (player && player.name && player.fraction && !playerArrayContains(stats.players, player)) { + player['warId'] = war._id; + stats.players.push(player); + } }; lineArray.some(line => { @@ -52,14 +51,12 @@ const parseWarLog = (lineArray, war) => { friendlyFire: shooter ? target.fraction === shooter.fraction : false, fraction: shooter ? shooter.fraction : 'NONE' }); - - addPlayersIfNotExists([shooter, target]); } /** * BUDGET */ - if (line.includes('Budget')) { + else if (line.includes('Budget')) { stats.clean.push(line); const budg = line.split(' '); if (line.includes('Endbudget')) { @@ -79,7 +76,7 @@ const parseWarLog = (lineArray, war) => { /** * FLAG */ - if (line.includes('Fahne')) { + else if (line.includes('Fahne')) { stats.clean.push(line); const playerName = line.substring(line.lastIndexOf('t von ') + 6, line.lastIndexOf(' :OPT LOG END')); const flagFraction = line.includes('NATO Flagge') ? 'BLUFOR' : 'OPFOR'; @@ -97,7 +94,7 @@ const parseWarLog = (lineArray, war) => { /** * POINTS */ - if (line.includes('Punkte')) { + else if (line.includes('Punkte')) { stats.clean.push(line); const pt = line.split(' '); @@ -114,7 +111,7 @@ const parseWarLog = (lineArray, war) => { /** * RESPAWN */ - if (line.includes('Respawn')) { + else if (line.includes('Respawn')) { stats.clean.push(line); const resp = line.split(' '); const playerName = line.substring(line.lastIndexOf('Spieler:') + 9, line.lastIndexOf('-') - 1); @@ -124,7 +121,7 @@ const parseWarLog = (lineArray, war) => { /** * REVIVE */ - if (line.includes('Revive')) { + else if (line.includes('Revive')) { stats.clean.push(line); const stabilized = !!line.includes('stabilisiert'); const medicName = line.substring(line.lastIndexOf('wurde von ') + 10, @@ -141,14 +138,12 @@ const parseWarLog = (lineArray, war) => { patient: patient.name, fraction: medic.fraction }); - - addPlayersIfNotExists([medic, patient]); } /** * TRANSPORT */ - if (line.includes('Transport ||')) { + else if (line.includes('Transport ||')) { stats.clean.push(line); const driverString = line.substring(line.lastIndexOf('wurde von ') + 10, line.lastIndexOf(' eingeflogen')); const driver = getPlayerAndFractionFromString(driverString); @@ -164,8 +159,14 @@ const parseWarLog = (lineArray, war) => { fraction: driver.fraction, distance: distance }); + } - addPlayersIfNotExists([driver, passenger]); + /** + * PLAYERS + */ + else if (line.includes('Fraktionsübersicht ||')) { + const playerString = line.substring(line.lastIndexOf('Fraktionsübersicht || ') + 22, line.lastIndexOf(' :OPT LOG END')); + addPlayerIfNotExists(playerString) } });