181 lines
5.9 KiB
JavaScript
181 lines
5.9 KiB
JavaScript
"use strict";
|
|
|
|
const arrayContains = require('../middleware/util').arrayContains;
|
|
|
|
const parseWarLog = (lineArray, war) => {
|
|
const clean = [];
|
|
const budget = [];
|
|
const points = [];
|
|
const kills = [];
|
|
const respawn = [];
|
|
const revive = [];
|
|
const flag = [];
|
|
const transport = [];
|
|
const playerNames = [];
|
|
const addPlayerIfNotExists = (playerName) => {
|
|
if (playerName !== 'Error: No unit' && !arrayContains(playerNames, playerName)) {
|
|
playerNames.push(playerName);
|
|
}
|
|
};
|
|
|
|
lineArray.forEach(line => {
|
|
if (line.includes("Abschuss")) {
|
|
clean.push(line);
|
|
// const kill = line.split(" ");
|
|
// for (let i=0; i< kill.length; i++ ) {
|
|
// console.log(i + " +++ " + kill[i]);
|
|
// }
|
|
|
|
}
|
|
|
|
if (line.includes("Budget")) {
|
|
clean.push(line);
|
|
const budg = line.split(" ");
|
|
if (line.includes("Endbudget")) {
|
|
war["endBudgetBlufor"] = transformMoneyString(budg[11]);
|
|
war['endBudgetOpfor'] = transformMoneyString(budg[14]);
|
|
} else if (line.includes("Startbudget")) {
|
|
war["budgetBlufor"] = transformMoneyString(budg[11]);
|
|
war["budgetOpfor"] = transformMoneyString(budg[14]);
|
|
} else {
|
|
budget.push(getBudgetEntry(budg));
|
|
}
|
|
}
|
|
|
|
if (line.includes("Fahne")) {
|
|
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';
|
|
const capture = !!line.includes('Flagge erobert');
|
|
|
|
flag.push({
|
|
warId: 'sdf89uiz786',
|
|
time: getDateTime(line.split(" ")[5]),
|
|
player: playerName,
|
|
flagFraction: flagFraction,
|
|
capture: capture
|
|
});
|
|
addPlayerIfNotExists(playerName);
|
|
}
|
|
|
|
if (line.includes("Punkte")) {
|
|
clean.push(line);
|
|
const pt = line.split(" ");
|
|
|
|
if (line.includes("Endpunktestand")) {
|
|
war['ptBlufor'] = parseInt(pt[11]);
|
|
war['ptOpfor'] = parseInt(pt[14].slice(0, -1));
|
|
} else {
|
|
points.push(getPointsEntry(pt))
|
|
}
|
|
}
|
|
|
|
if (line.includes("Respawn")) {
|
|
clean.push(line);
|
|
const resp = line.split(" ");
|
|
const playerName = line.substring(line.lastIndexOf("Spieler:") + 9, line.lastIndexOf("-") - 1);
|
|
|
|
respawn.push(getRespawnEntry(resp, playerName));
|
|
addPlayerIfNotExists(playerName);
|
|
}
|
|
|
|
if (line.includes("Revive")) {
|
|
clean.push(line);
|
|
|
|
const stabilized = !!line.includes('stabilisiert');
|
|
|
|
const medicName = line.substring(line.lastIndexOf("wurde von ") + 10, line.lastIndexOf(stabilized ? ' stabilisiert' : ' wiederbelebt'));
|
|
const medicNameArray = medicName.split(" ");
|
|
const medicFraction = medicNameArray[medicNameArray.length - 1] === "(WEST)" ? "BLUFOR" : "OPFOR";
|
|
const sanitizedMedicName = medicName.substring(0, medicName.indexOf(medicNameArray[medicNameArray.length - 1]) - 1);
|
|
|
|
const patientName = line.substring(line.lastIndexOf("|| ") + 3, line.lastIndexOf(" wurde von"));
|
|
const patientNameArray = patientName.split(" ");
|
|
const patientFraction = patientNameArray[patientNameArray.length - 1] === "(WEST)" ? "BLUFOR" : "OPFOR";
|
|
const sanitizedPatientName = patientName.substring(0, patientName.indexOf(patientNameArray[patientNameArray.length - 1]) - 1);
|
|
|
|
revive.push({
|
|
warId: 'asfddf',
|
|
time: getDateTime(line.split(" ")[5]),
|
|
stabilized: stabilized,
|
|
medic: sanitizedMedicName,
|
|
patient: sanitizedPatientName
|
|
});
|
|
|
|
addPlayerIfNotExists(sanitizedMedicName);
|
|
addPlayerIfNotExists(sanitizedPatientName);
|
|
}
|
|
|
|
if (line.includes("Transport ||")) {
|
|
clean.push(line);
|
|
const driverName = line.substring(line.lastIndexOf("wurde von ") + 10, line.lastIndexOf(" eingeflogen"));
|
|
const driverNameArray = driverName.split(" ");
|
|
const driverFraction = driverNameArray[driverNameArray.length - 1] === "(WEST)" ? "BLUFOR" : "OPFOR";
|
|
const sanitizedDriverName = driverName.substring(0, driverName.indexOf(driverNameArray[driverNameArray.length - 1]) - 1);
|
|
|
|
const passengerName = line.substring(line.lastIndexOf("|| ") + 3, line.lastIndexOf(" wurde von"));
|
|
const passengerNameArray = passengerName.split(" ");
|
|
const passengerFraction = passengerNameArray[passengerNameArray.length - 1] === "(WEST)" ? "BLUFOR" : "OPFOR";
|
|
const sanitizedPassengerName = passengerName.substring(0, passengerName.indexOf(passengerNameArray[passengerNameArray.length - 1]) - 1);
|
|
const distance = parseInt(line.substring(line.lastIndexOf("eingeflogen (") + 13, line.lastIndexOf("m)") - 1));
|
|
|
|
transport.push({
|
|
war: "blablub7z8",
|
|
time: getDateTime(line.split(" ")[5]),
|
|
driver: sanitizedDriverName,
|
|
passenger: sanitizedPassengerName,
|
|
distance: distance
|
|
});
|
|
|
|
addPlayerIfNotExists(sanitizedDriverName);
|
|
addPlayerIfNotExists(sanitizedPassengerName);
|
|
}
|
|
});
|
|
//
|
|
// revive.forEach(budg => console.log(budg));
|
|
// console.log(revive.length)
|
|
};
|
|
|
|
function getRespawnEntry(respawn, playerName) {
|
|
return {
|
|
war: "1234567",
|
|
time: getDateTime(respawn[5]),
|
|
player: playerName
|
|
}
|
|
}
|
|
|
|
function getPointsEntry(pt) {
|
|
return {
|
|
warId: "123-xyz-123",
|
|
time: getDateTime(pt[5]),
|
|
ptBlufor: parseInt(pt[12]),
|
|
ptOpfor: parseInt(pt[15].slice(0, -1))
|
|
}
|
|
}
|
|
|
|
function getBudgetEntry(budg) {
|
|
return {
|
|
warId: "123-xyz-123",
|
|
time: getDateTime(budg[5]),
|
|
fraction: budg[9] === "NATO" ? "BLUFOR" : "OPFOR",
|
|
oldBudget: transformMoneyString(budg[11]),
|
|
newBudget: transformMoneyString(budg[14])
|
|
}
|
|
}
|
|
|
|
const transformMoneyString = (budgetString) => {
|
|
if (!budgetString.includes("e+")) {
|
|
return parseInt(budgetString);
|
|
}
|
|
const budget = budgetString.split("e+");
|
|
return Math.round(parseFloat(budget[0]) * Math.pow(10, parseInt(budget[1])));
|
|
|
|
};
|
|
|
|
function getDateTime(timeString) {
|
|
const timeZone = 'Z';
|
|
return new Date("1999-01-01T0" + timeString + timeZone);
|
|
}
|
|
|
|
module.exports = parseWarLog;
|