2017-10-21 12:11:32 +02:00
|
|
|
'use strict';
|
2017-10-20 23:42:41 +02:00
|
|
|
|
2017-10-28 12:58:40 +02:00
|
|
|
const playerArrayContains = require('./util').playerArrayContains;
|
2017-10-20 23:42:41 +02:00
|
|
|
|
2018-02-03 11:34:46 +01:00
|
|
|
const WHITESPACE = ' ';
|
|
|
|
|
2018-04-14 13:20:10 +02:00
|
|
|
const VehicleClasses = Object.freeze({
|
2018-04-15 13:47:48 +02:00
|
|
|
LIGHT: 'Leicht',
|
|
|
|
HEAVY: 'Schwer',
|
|
|
|
AIR: 'Flug',
|
|
|
|
UNKNOWN: 'Unbekannt',
|
2018-04-14 13:20:10 +02:00
|
|
|
});
|
|
|
|
|
2018-06-09 19:17:38 +02:00
|
|
|
const playerNameRegex = /(^|,\s)(.*?)\s\(/g;
|
2018-06-04 21:46:07 +02:00
|
|
|
|
2018-06-06 18:45:25 +02:00
|
|
|
const vehicleNameEndRegex = /\s\(\w+:/;
|
|
|
|
|
2018-06-04 21:46:07 +02:00
|
|
|
const sideRegex = /(side:\s(.*?)\))/;
|
|
|
|
|
2018-06-17 11:52:43 +02:00
|
|
|
const magazineRegex = /(magazine:\s(.*?)\))/;
|
2018-06-06 18:45:25 +02:00
|
|
|
|
2018-06-17 11:52:43 +02:00
|
|
|
const vehicleRegex = /(vehicle:\s(.*?)\))/;
|
2018-06-04 21:46:07 +02:00
|
|
|
|
2018-06-06 18:45:25 +02:00
|
|
|
const categoryRegex = /(category:\s(.*?)\))/;
|
2018-06-04 21:46:07 +02:00
|
|
|
|
2019-02-09 11:54:16 +01:00
|
|
|
const bluforPlayerCountRegex = /NATO\s(\d*)/;
|
|
|
|
|
|
|
|
const opforPlayerCountRegex = /CSAT\s(\d*)/;
|
|
|
|
|
2019-02-09 20:42:24 +01:00
|
|
|
const timestampRegex = /LOG:\s(\d*:\d*:\d*)\s---/;
|
|
|
|
|
|
|
|
const singleMinFpsRegex = /Single min\. FPS for (.*):\s(\d*.\d*)"/; // group1 = entity name, group2 = value
|
|
|
|
|
|
|
|
const singleAvgFpsRegex = /Single avg\. FPS for (.*):\s(\d*.\d*)"/; // group1 = entity name, group2 = value
|
|
|
|
|
|
|
|
const minFpsRegex = /Min\. FPS for (.*):\s\[(.*)\]"/; // group1 = entity name, group2 = comma separated values
|
|
|
|
|
|
|
|
const avgFpsRegex = /Avg\. FPS for (.*):\s\[(.*)\]"/; // group1 = entity name, group2 = comma separated values
|
2019-02-09 11:54:16 +01:00
|
|
|
|
2017-10-20 23:42:41 +02:00
|
|
|
const parseWarLog = (lineArray, war) => {
|
2018-10-18 20:23:29 +02:00
|
|
|
let flagBlufor = true;
|
|
|
|
let flagOpfor = true;
|
|
|
|
|
2018-02-03 11:34:46 +01:00
|
|
|
const NAME_TOO_LONG_ERROR = 'Error: ENAMETOOLONG: name too long, open \'';
|
|
|
|
|
2017-10-21 12:11:32 +02:00
|
|
|
const stats = {
|
|
|
|
war: war,
|
|
|
|
clean: [],
|
|
|
|
budget: [],
|
|
|
|
points: [],
|
|
|
|
kills: [],
|
2018-03-03 12:26:24 +01:00
|
|
|
vehicles: [],
|
2017-10-21 12:11:32 +02:00
|
|
|
respawn: [],
|
|
|
|
revive: [],
|
|
|
|
flag: [],
|
|
|
|
transport: [],
|
2018-03-12 09:26:44 +01:00
|
|
|
players: [],
|
2019-02-09 11:54:16 +01:00
|
|
|
playerCount: [],
|
2019-02-09 20:42:24 +01:00
|
|
|
serverFps: [],
|
2017-10-21 12:11:32 +02:00
|
|
|
};
|
|
|
|
|
2018-04-14 13:20:10 +02:00
|
|
|
const VEHICLE_BLACKLIST = [
|
2018-03-04 19:59:54 +01:00
|
|
|
'Prowler (Unbewaffnet)', 'Prowler (Bewaffnet)', 'Hunter',
|
2018-10-01 07:42:07 +02:00
|
|
|
'HEMTT Transporter', 'HEMTT Transporter (abgedeckt)', 'HEMTT Sanitätsfahrzeug',
|
2018-03-04 19:59:54 +01:00
|
|
|
'Remote Designator [NATO]', 'UGV Stomper',
|
|
|
|
'Qilin (Unbewaffnet)', 'Qilin (Bewaffnet)', 'Ifrit',
|
2018-10-01 07:42:07 +02:00
|
|
|
'Tempest-Transporter', 'Tempest-Transporter (abgedeckt)', 'Tempest Sanitätsfahrzeug',
|
2018-03-04 19:59:54 +01:00
|
|
|
'Remote Designator [CSAT]', 'UBF Saif',
|
2018-03-12 09:26:44 +01:00
|
|
|
'Quad Bike', 'HuntIR',
|
2018-03-04 19:59:54 +01:00
|
|
|
];
|
2018-03-03 12:57:31 +01:00
|
|
|
|
2018-02-26 09:33:28 +01:00
|
|
|
const addPlayerIfNotExists = (inputPlayer, steamUUID) => {
|
2018-06-17 11:52:43 +02:00
|
|
|
const player = getPlayerInfoFromString(inputPlayer);
|
2017-11-06 14:22:18 +01:00
|
|
|
if (player && player.name && player.fraction && !playerArrayContains(stats.players, player)) {
|
2018-06-06 18:45:25 +02:00
|
|
|
player['warId'] = war._id;
|
|
|
|
player['steamUUID'] = steamUUID;
|
2017-11-06 14:22:18 +01:00
|
|
|
stats.players.push(player);
|
|
|
|
}
|
2017-10-20 23:42:41 +02:00
|
|
|
};
|
|
|
|
|
2018-03-12 09:26:44 +01:00
|
|
|
lineArray.some((line) => {
|
2017-10-22 14:13:58 +02:00
|
|
|
/**
|
2017-11-02 11:17:16 +01:00
|
|
|
* sanitize nameTooLongError coming up in first line
|
2017-10-22 14:13:58 +02:00
|
|
|
*/
|
2018-02-03 11:34:46 +01:00
|
|
|
if (line.includes(NAME_TOO_LONG_ERROR)) {
|
|
|
|
line = line.substring(line.indexOf(NAME_TOO_LONG_ERROR) + NAME_TOO_LONG_ERROR.length);
|
2017-10-22 14:13:58 +02:00
|
|
|
}
|
|
|
|
|
2018-03-03 12:26:24 +01:00
|
|
|
if (line.includes('(Abschuss)')) {
|
2018-03-12 10:39:56 +01:00
|
|
|
/**
|
|
|
|
* KILLS & VEHICLE KILLS
|
|
|
|
*/
|
2017-10-21 12:11:32 +02:00
|
|
|
stats.clean.push(line);
|
2018-03-03 12:26:24 +01:00
|
|
|
|
2018-06-04 21:46:07 +02:00
|
|
|
const shooterString = line.substring(line.lastIndexOf(' von: ') + 6, line.search(/$/) - 1);
|
2018-06-17 11:52:43 +02:00
|
|
|
const shooter = getPlayerInfoFromString(shooterString);
|
2017-10-21 11:32:25 +02:00
|
|
|
|
2018-03-03 12:57:31 +01:00
|
|
|
if (line.includes('Fahrzeug:')) {
|
|
|
|
const targetString = line.substring(line.lastIndexOf(' --- Fahrzeug: ') + 15, line.lastIndexOf(' von:'));
|
2018-03-03 12:26:24 +01:00
|
|
|
const target = getVehicleAndFractionFromString(targetString);
|
|
|
|
if (target && shooter && target.fraction !== shooter.fraction) {
|
2018-06-09 19:31:22 +02:00
|
|
|
const vehicleKill = {
|
2018-03-03 12:26:24 +01:00
|
|
|
war: war._id,
|
2018-06-06 18:45:25 +02:00
|
|
|
time: getFullTimeDate(war.date, line.split(WHITESPACE)[5]),
|
2018-03-03 12:26:24 +01:00
|
|
|
target: target ? target.name : null,
|
2018-03-12 09:26:44 +01:00
|
|
|
fraction: shooter ? shooter.fraction : 'NONE',
|
2018-04-14 13:44:50 +02:00
|
|
|
vehicleClass: target.vehicleClass,
|
2018-06-09 19:31:22 +02:00
|
|
|
};
|
|
|
|
if (shooter && shooter.name instanceof Array) {
|
|
|
|
vehicleKill.shooter = shooter.name[0];
|
|
|
|
vehicleKill.additionalShooter = shooter.name.slice(1, shooter.name.length);
|
|
|
|
} else {
|
2018-06-09 22:06:18 +02:00
|
|
|
vehicleKill.shooter = shooter ? shooter.name : null;
|
2018-06-09 19:31:22 +02:00
|
|
|
}
|
2018-06-17 11:52:43 +02:00
|
|
|
if (shooter.magazine) {
|
|
|
|
vehicleKill.magazine = shooter.magazine;
|
|
|
|
}
|
|
|
|
if (shooter.vehicle) {
|
|
|
|
vehicleKill.shooterVehicle = shooter.vehicle;
|
|
|
|
}
|
|
|
|
|
2018-06-09 19:31:22 +02:00
|
|
|
stats.vehicles.push(vehicleKill);
|
2018-03-03 12:26:24 +01:00
|
|
|
}
|
|
|
|
} else {
|
2018-06-04 20:34:17 +02:00
|
|
|
const targetString = line.substring(line.lastIndexOf(' --- Einheit: ') + 14, line.lastIndexOf(' von:'));
|
2018-06-17 11:52:43 +02:00
|
|
|
const target = getPlayerInfoFromString(targetString);
|
|
|
|
const kill = {
|
2018-03-03 12:26:24 +01:00
|
|
|
war: war._id,
|
2018-09-30 14:44:59 +02:00
|
|
|
time: getFullTimeDate(war.date, line.split(WHITESPACE)[5]),
|
2019-02-10 01:04:19 +01:00
|
|
|
friendlyFire: false,
|
2018-06-17 11:52:43 +02:00
|
|
|
};
|
2018-09-30 14:43:01 +02:00
|
|
|
if (shooter) {
|
|
|
|
kill.shooter = shooter.name;
|
|
|
|
kill.fraction = shooter.fraction;
|
|
|
|
if (target) {
|
|
|
|
kill.friendlyFire = (target.fraction === shooter.fraction);
|
|
|
|
}
|
|
|
|
if (shooter.magazine) {
|
|
|
|
kill.magazine = shooter.magazine;
|
|
|
|
}
|
|
|
|
if (shooter.vehicle) {
|
|
|
|
kill.shooterVehicle = shooter.vehicle;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
kill.fraction = 'NONE';
|
2018-06-17 11:52:43 +02:00
|
|
|
}
|
2018-09-30 14:43:01 +02:00
|
|
|
|
|
|
|
if (target) {
|
|
|
|
kill.target = target.name;
|
|
|
|
if (target.vehicle) {
|
|
|
|
kill.targetVehicle = target.vehicle;
|
|
|
|
}
|
2018-06-17 11:52:43 +02:00
|
|
|
}
|
|
|
|
stats.kills.push(kill);
|
2018-03-03 12:26:24 +01:00
|
|
|
}
|
2018-03-12 10:39:56 +01:00
|
|
|
} else if (line.includes('(Budget)')) {
|
|
|
|
/**
|
|
|
|
* BUDGET
|
|
|
|
*/
|
2017-10-21 12:11:32 +02:00
|
|
|
stats.clean.push(line);
|
2018-02-03 11:34:46 +01:00
|
|
|
const budg = line.split(WHITESPACE);
|
2017-12-10 15:43:30 +01:00
|
|
|
if (line.includes('Startbudget')) {
|
2018-06-06 18:45:25 +02:00
|
|
|
stats.war['budgetBlufor'] = transformMoneyString(budg[9]);
|
|
|
|
stats.war['budgetOpfor'] = transformMoneyString(budg[12].slice(0, -1));
|
2018-02-25 17:46:18 +01:00
|
|
|
|
2017-11-02 18:54:26 +01:00
|
|
|
// this date needs to be assigned in first place !important
|
2018-06-06 18:45:25 +02:00
|
|
|
const dateString = budg[0].slice(0, -1).split('/').map((s) => parseInt(s));
|
|
|
|
stats.war.date = new Date(dateString[0], dateString[1] - 1, dateString[2]);
|
2017-12-10 15:43:30 +01:00
|
|
|
} else if (line.includes('Endbudget')) {
|
2018-06-06 18:45:25 +02:00
|
|
|
stats.war['endBudgetBlufor'] = transformMoneyString(budg[9]);
|
|
|
|
stats.war['endBudgetOpfor'] = transformMoneyString(budg[12].slice(0, -2));
|
|
|
|
stats.war.endDate = getFullTimeDate(war.date, budg[5]);
|
2017-10-20 23:42:41 +02:00
|
|
|
} else {
|
2018-05-05 12:59:26 +02:00
|
|
|
if (line.includes('Respawn von ')) {
|
|
|
|
/**
|
|
|
|
* RESPAWN
|
|
|
|
*/
|
|
|
|
const playerName = line.substring(line.lastIndexOf('Respawn von ') + 12, line.lastIndexOf('"'));
|
|
|
|
stats.respawn.push(getRespawnEntry(budg, playerName, war._id, war.date));
|
|
|
|
}
|
2017-10-29 17:36:55 +01:00
|
|
|
stats.budget.push(getBudgetEntry(budg, war._id, war.date));
|
2017-10-20 23:42:41 +02:00
|
|
|
}
|
2018-03-12 10:39:56 +01:00
|
|
|
} else if (line.includes('(Fahne)') && !line.includes('Dominator')) {
|
|
|
|
/**
|
|
|
|
* FLAG
|
|
|
|
*/
|
2017-10-21 10:41:49 +02:00
|
|
|
const flagFraction = line.includes('NATO Flagge') ? 'BLUFOR' : 'OPFOR';
|
|
|
|
const capture = !!line.includes('Flagge erobert');
|
|
|
|
|
2018-10-18 20:23:29 +02:00
|
|
|
if ((flagFraction === 'BLUFOR' && ((capture && flagBlufor) || (!capture && !flagBlufor))) ||
|
|
|
|
(flagFraction === 'OPFOR' && ((capture && flagOpfor) || (!capture && !flagOpfor)))) {
|
|
|
|
stats.clean.push(line);
|
|
|
|
|
|
|
|
const playerName = line.substring(line.lastIndexOf('rt von ') + 7).slice(0, -1);
|
|
|
|
|
|
|
|
if (flagFraction === 'BLUFOR') {
|
|
|
|
flagBlufor = !capture;
|
|
|
|
} else if (flagFraction === 'OPFOR') {
|
|
|
|
flagOpfor = !capture;
|
|
|
|
}
|
|
|
|
|
|
|
|
stats.flag.push({
|
|
|
|
war: war._id,
|
|
|
|
time: getFullTimeDate(war.date, line.split(WHITESPACE)[5]),
|
|
|
|
player: playerName,
|
|
|
|
flagFraction: flagFraction,
|
|
|
|
capture: capture,
|
|
|
|
});
|
|
|
|
}
|
2018-03-12 10:39:56 +01:00
|
|
|
} else if (line.includes('(Punkte)')) {
|
|
|
|
/**
|
|
|
|
* POINTS
|
|
|
|
*/
|
2017-10-21 12:11:32 +02:00
|
|
|
stats.clean.push(line);
|
2018-08-13 19:07:23 +02:00
|
|
|
|
2018-02-03 11:34:46 +01:00
|
|
|
const pt = line.split(WHITESPACE);
|
2017-10-20 23:42:41 +02:00
|
|
|
|
2017-10-21 12:11:32 +02:00
|
|
|
if (line.includes('Endpunktestand')) {
|
2018-06-06 18:45:25 +02:00
|
|
|
stats.war['ptBlufor'] = parseInt(pt[9]);
|
|
|
|
stats.war['ptOpfor'] = parseInt(pt[12].slice(0, -1));
|
2017-11-02 18:54:26 +01:00
|
|
|
// EXIT LOOP
|
2017-10-22 14:13:58 +02:00
|
|
|
return true;
|
2017-10-20 23:42:41 +02:00
|
|
|
} else {
|
2018-03-12 09:26:44 +01:00
|
|
|
stats.points.push(getPointsEntry(pt, line, war._id, war.date));
|
2017-10-20 23:42:41 +02:00
|
|
|
}
|
2018-03-12 10:39:56 +01:00
|
|
|
} else if (line.includes('(Revive)')) {
|
|
|
|
/**
|
|
|
|
* REVIVE
|
|
|
|
*/
|
2017-10-21 12:11:32 +02:00
|
|
|
stats.clean.push(line);
|
2018-01-16 19:46:28 +01:00
|
|
|
const stabilized = !!line.includes('stabilisiert."');
|
2017-10-21 14:54:58 +02:00
|
|
|
const medicName = line.substring(line.lastIndexOf('wurde von ') + 10,
|
|
|
|
line.lastIndexOf(stabilized ? ' stabilisiert' : ' wiederbelebt'));
|
2018-06-17 11:52:43 +02:00
|
|
|
const medic = getPlayerInfoFromString(medicName);
|
2018-01-16 19:46:28 +01:00
|
|
|
const patientName = line.substring(line.lastIndexOf('--- ') + 4, line.lastIndexOf(' wurde von'));
|
2018-06-17 11:52:43 +02:00
|
|
|
const patient = getPlayerInfoFromString(patientName);
|
2017-10-21 10:41:49 +02:00
|
|
|
|
2017-10-21 12:11:32 +02:00
|
|
|
stats.revive.push({
|
|
|
|
war: war._id,
|
2018-06-06 18:45:25 +02:00
|
|
|
time: getFullTimeDate(war.date, line.split(WHITESPACE)[5]),
|
2017-10-21 10:41:49 +02:00
|
|
|
stabilized: stabilized,
|
2017-10-21 11:32:25 +02:00
|
|
|
medic: medic.name,
|
2017-10-21 19:49:24 +02:00
|
|
|
patient: patient.name,
|
2018-03-12 09:26:44 +01:00
|
|
|
fraction: medic.fraction,
|
2017-10-21 10:41:49 +02:00
|
|
|
});
|
2018-03-12 10:39:56 +01:00
|
|
|
} else if (line.includes('(Transport)')) {
|
|
|
|
/**
|
|
|
|
* TRANSPORT
|
|
|
|
*/
|
2018-02-01 07:06:26 +01:00
|
|
|
stats.clean.push(line);
|
|
|
|
const driverString = line.substring(line.lastIndexOf('wurde von ') + 10, line.lastIndexOf(' eingeflogen'));
|
2018-06-17 11:52:43 +02:00
|
|
|
const driver = getPlayerInfoFromString(driverString);
|
2018-02-01 07:06:26 +01:00
|
|
|
const passengerString = line.substring(line.lastIndexOf('--- ') + 3, line.lastIndexOf(' wurde von'));
|
2018-06-17 11:52:43 +02:00
|
|
|
const passenger = getPlayerInfoFromString(passengerString);
|
2018-02-01 07:06:26 +01:00
|
|
|
const distance = parseInt(line.substring(line.lastIndexOf('eingeflogen (') + 13, line.lastIndexOf('m)') - 1));
|
|
|
|
|
|
|
|
stats.transport.push({
|
|
|
|
war: war._id,
|
2018-06-06 18:45:25 +02:00
|
|
|
time: getFullTimeDate(war.date, line.split(WHITESPACE)[5]),
|
2018-02-02 10:48:43 +01:00
|
|
|
driver: driver ? driver.name : null,
|
2018-02-01 07:06:26 +01:00
|
|
|
passenger: passenger ? passenger.name : null,
|
2018-02-02 10:48:43 +01:00
|
|
|
fraction: driver ? driver.fraction : 'NONE',
|
2018-03-12 09:26:44 +01:00
|
|
|
distance: distance,
|
2018-02-01 07:06:26 +01:00
|
|
|
});
|
2019-02-09 11:54:16 +01:00
|
|
|
} else if (line.includes('(Spieleranzahl)')) {
|
|
|
|
stats.clean.push(line);
|
|
|
|
|
|
|
|
const timestamp = (timestampRegex.exec(line))[1];
|
|
|
|
const countBlufor = (bluforPlayerCountRegex.exec(line))[1];
|
|
|
|
const countOpfor = (opforPlayerCountRegex.exec(line))[1];
|
|
|
|
|
|
|
|
stats.playerCount.push({
|
|
|
|
war: war.id,
|
|
|
|
time: getFullTimeDate(war.date, timestamp),
|
|
|
|
countBlufor: countBlufor,
|
|
|
|
countOpfor: countOpfor,
|
|
|
|
});
|
2019-02-09 20:42:24 +01:00
|
|
|
} else if (line.includes('(FPS)')) {
|
|
|
|
stats.clean.push(line);
|
|
|
|
|
|
|
|
const updateServerFpsLogEntry = (entityName, addKey, addValue) => {
|
|
|
|
const idx = stats.serverFps.findIndex((entry) => entry.entityName === entityName);
|
|
|
|
if (idx === -1) {
|
|
|
|
stats.serverFps.push({
|
|
|
|
war: war.id,
|
|
|
|
entityName: entityName,
|
|
|
|
[addKey]: addValue,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const entity = stats.serverFps[idx];
|
|
|
|
entity[addKey] = addValue;
|
|
|
|
stats.serverFps[idx] = entity;
|
|
|
|
};
|
|
|
|
|
|
|
|
const singleMinMatch = singleMinFpsRegex.exec(line);
|
|
|
|
if (singleMinMatch) {
|
|
|
|
updateServerFpsLogEntry(singleMinMatch[1], 'singleMinFps', singleMinMatch[2]);
|
|
|
|
} else {
|
|
|
|
const singleAvgMatch = singleAvgFpsRegex.exec(line);
|
|
|
|
if (singleAvgMatch) {
|
|
|
|
updateServerFpsLogEntry(singleAvgMatch[1], 'singleAvgFps', singleAvgMatch[2]);
|
|
|
|
} else {
|
|
|
|
const minCollectionMatch = minFpsRegex.exec(line);
|
|
|
|
if (minCollectionMatch) {
|
|
|
|
updateServerFpsLogEntry(minCollectionMatch[1], 'minFps', minCollectionMatch[2].split(','));
|
|
|
|
} else {
|
|
|
|
const avgCollectionMatch = avgFpsRegex.exec(line);
|
|
|
|
if (avgCollectionMatch) {
|
|
|
|
updateServerFpsLogEntry(avgCollectionMatch[1], 'avgFps', avgCollectionMatch[2].split(','));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-08-13 19:07:23 +02:00
|
|
|
} else if (line.includes('(Fraktionsuebersicht)') || line.includes('Fraktionsübersicht')) {
|
2018-03-12 10:39:56 +01:00
|
|
|
/**
|
|
|
|
* PLAYERS
|
|
|
|
*/
|
2018-01-16 19:46:28 +01:00
|
|
|
const playerString = line.substring(line.lastIndexOf('--- ') + 4, line.lastIndexOf(', PUID'));
|
2018-02-26 09:33:28 +01:00
|
|
|
const playerUUID = line.substring(line.lastIndexOf('PUID ') + 5, line.lastIndexOf('"'));
|
2018-03-12 09:26:44 +01:00
|
|
|
addPlayerIfNotExists(playerString, playerUUID);
|
2017-10-20 23:42:41 +02:00
|
|
|
}
|
|
|
|
});
|
2017-10-21 11:32:25 +02:00
|
|
|
|
2017-10-21 14:54:58 +02:00
|
|
|
for (let i = 0; i < stats.players.length; i++) {
|
2018-06-06 18:45:25 +02:00
|
|
|
const playerName = stats.players[i].name;
|
|
|
|
stats.players[i]['respawn'] = stats.respawn.filter((res) => res.player === playerName).length;
|
2018-04-14 17:46:01 +02:00
|
|
|
|
2018-06-06 18:45:25 +02:00
|
|
|
stats.players[i]['kill'] = stats.kills.filter(
|
2018-06-04 21:46:07 +02:00
|
|
|
(kill) => kill.shooter === playerName && !kill.friendlyFire).length;
|
2018-04-14 17:46:01 +02:00
|
|
|
|
2018-04-15 13:47:48 +02:00
|
|
|
// TODO: use vehicle class description from enum
|
2018-06-06 18:45:25 +02:00
|
|
|
stats.players[i]['vehicleLight'] = stats.vehicles.filter(
|
2018-06-10 19:58:37 +02:00
|
|
|
(vehicle) => (vehicle.shooter === playerName ||
|
|
|
|
(vehicle.additionalShooter && vehicle.additionalShooter.indexOf(playerName)) > -1) && vehicle.vehicleClass ===
|
|
|
|
'LIGHT' && VEHICLE_BLACKLIST.indexOf(vehicle.target) < 0).length;
|
2018-04-14 17:46:01 +02:00
|
|
|
|
2018-06-06 18:45:25 +02:00
|
|
|
stats.players[i]['vehicleHeavy'] = stats.vehicles.filter(
|
2018-06-10 19:58:37 +02:00
|
|
|
(vehicle) => (vehicle.shooter === playerName ||
|
|
|
|
(vehicle.additionalShooter && vehicle.additionalShooter.indexOf(playerName)) > -1) && vehicle.vehicleClass ===
|
|
|
|
'HEAVY' && VEHICLE_BLACKLIST.indexOf(vehicle.target) < 0).length;
|
2018-04-14 17:46:01 +02:00
|
|
|
|
2018-06-06 18:45:25 +02:00
|
|
|
stats.players[i]['vehicleAir'] = stats.vehicles.filter(
|
2018-06-10 19:58:37 +02:00
|
|
|
(vehicle) => (vehicle.shooter === playerName ||
|
|
|
|
(vehicle.additionalShooter && vehicle.additionalShooter.indexOf(playerName)) > -1) && vehicle.vehicleClass ===
|
|
|
|
'AIR' && VEHICLE_BLACKLIST.indexOf(vehicle.target) < 0).length;
|
2018-04-14 17:46:01 +02:00
|
|
|
|
2018-06-06 18:45:25 +02:00
|
|
|
stats.players[i]['friendlyFire'] = stats.kills.filter(
|
2018-03-12 09:59:43 +01:00
|
|
|
(kill) => kill.shooter === playerName && kill.friendlyFire).length;
|
2018-04-14 17:46:01 +02:00
|
|
|
|
2018-06-06 18:45:25 +02:00
|
|
|
stats.players[i]['death'] = stats.kills.filter((kill) => kill.target === playerName).length;
|
2018-04-14 17:46:01 +02:00
|
|
|
|
2018-06-06 18:45:25 +02:00
|
|
|
stats.players[i]['revive'] = stats.revive.filter((rev) => rev.medic === playerName && !rev.stabilized).length;
|
2018-04-14 17:46:01 +02:00
|
|
|
|
2018-06-06 18:45:25 +02:00
|
|
|
stats.players[i]['flagTouch'] = stats.flag.filter((flag) => flag.player === playerName).length;
|
2018-04-14 17:46:01 +02:00
|
|
|
|
2019-02-10 15:22:57 +01:00
|
|
|
let playerTravelDistance = stats.transport.filter((transport) => transport.passenger === playerName)
|
|
|
|
.map((transport) => transport.distance)
|
|
|
|
.reduce((total, num) => total + Math.round(num), 0);
|
|
|
|
if (playerTravelDistance > 0) {
|
|
|
|
stats.players[i]['travelDistance'] = playerTravelDistance;
|
|
|
|
}
|
|
|
|
|
|
|
|
let driverDistance = 0;
|
|
|
|
const driverTransports = stats.transport.filter((transport) => transport.driver === playerName);
|
|
|
|
for (let i = 0; i < driverTransports.length; i++) {
|
|
|
|
const curr = driverTransports[i];
|
|
|
|
if (i < driverTransports.length - 1) {
|
|
|
|
const next = driverTransports[i + 1];
|
|
|
|
if ((next.time.getTime() - curr.time.getTime()) < 2 * 60000) { // only track once in 2 min range
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
driverDistance += curr.distance;
|
|
|
|
} else {
|
|
|
|
driverDistance += curr.distance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (driverDistance > 0) {
|
|
|
|
stats.players[i]['driverDistance'] = driverDistance;
|
|
|
|
}
|
2017-10-21 14:54:58 +02:00
|
|
|
}
|
|
|
|
|
2018-03-12 09:26:44 +01:00
|
|
|
stats.war.playersBlufor = stats.players.filter((player) => player.fraction === 'BLUFOR').length;
|
|
|
|
stats.war.playersOpfor = stats.players.filter((player) => player.fraction === 'OPFOR').length;
|
2017-10-21 12:11:32 +02:00
|
|
|
|
|
|
|
return stats;
|
2017-10-20 23:42:41 +02:00
|
|
|
};
|
|
|
|
|
2017-10-29 17:36:55 +01:00
|
|
|
const getRespawnEntry = (respawn, playerName, warId, warDate) => {
|
2017-10-20 23:42:41 +02:00
|
|
|
return {
|
2017-10-21 12:11:32 +02:00
|
|
|
war: warId,
|
2018-06-06 18:45:25 +02:00
|
|
|
time: getFullTimeDate(warDate, respawn[5]),
|
2018-03-12 09:26:44 +01:00
|
|
|
player: playerName,
|
|
|
|
};
|
2017-10-21 12:11:32 +02:00
|
|
|
};
|
2017-10-20 23:42:41 +02:00
|
|
|
|
2017-10-29 17:36:55 +01:00
|
|
|
const getPointsEntry = (pt, line, warId, warDate) => {
|
2017-10-20 23:42:41 +02:00
|
|
|
return {
|
2017-10-21 18:23:04 +02:00
|
|
|
war: warId,
|
2018-06-06 18:45:25 +02:00
|
|
|
time: getFullTimeDate(warDate, pt[5]),
|
|
|
|
ptBlufor: parseInt(pt[10]),
|
2018-08-13 19:07:23 +02:00
|
|
|
ptOpfor: parseInt(pt[13].slice(0, -2)),
|
2018-03-12 09:26:44 +01:00
|
|
|
fraction: line.includes('Kein Dominator') ? 'NONE' : line.includes('NATO +1') ? 'BLUFOR' : 'OPFOR',
|
|
|
|
};
|
2017-10-21 12:11:32 +02:00
|
|
|
};
|
2017-10-20 23:42:41 +02:00
|
|
|
|
2017-10-29 17:36:55 +01:00
|
|
|
const getBudgetEntry = (budg, warId, warDate) => {
|
2017-10-20 23:42:41 +02:00
|
|
|
return {
|
2017-10-21 18:23:04 +02:00
|
|
|
war: warId,
|
2018-06-06 18:45:25 +02:00
|
|
|
time: getFullTimeDate(warDate, budg[5]),
|
|
|
|
fraction: budg[7] === 'NATO' ? 'BLUFOR' : 'OPFOR',
|
|
|
|
oldBudget: transformMoneyString(budg[9]),
|
|
|
|
newBudget: transformMoneyString(budg[12]),
|
2018-03-12 09:26:44 +01:00
|
|
|
};
|
2017-10-21 12:11:32 +02:00
|
|
|
};
|
2017-10-20 23:42:41 +02:00
|
|
|
|
2018-06-17 11:52:43 +02:00
|
|
|
const getPlayerInfoFromString = (inputString) => {
|
|
|
|
const resPlayer = {};
|
2019-02-14 20:46:22 +01:00
|
|
|
let playerNameRegexMatch = playerNameRegex.exec(inputString);
|
|
|
|
|
|
|
|
// https://stackoverflow.com/questions/18462784/why-is-javascript-regex-matching-every-second-time
|
|
|
|
if (!playerNameRegexMatch) {
|
|
|
|
playerNameRegexMatch = playerNameRegex.exec(inputString);
|
|
|
|
}
|
2018-06-04 21:46:07 +02:00
|
|
|
const sideMatch = sideRegex.exec(inputString);
|
|
|
|
|
2018-06-09 19:17:38 +02:00
|
|
|
// SINGLE PLAYER NAME
|
2018-06-04 21:46:07 +02:00
|
|
|
let name;
|
|
|
|
if (playerNameRegexMatch && playerNameRegexMatch.length >= 2) {
|
2018-06-09 19:17:38 +02:00
|
|
|
name = playerNameRegexMatch[2].trim();
|
2018-09-30 14:43:01 +02:00
|
|
|
// do not return player for 'unbekannt' or 'Error: No unit'
|
|
|
|
if (!name || name === 'unbekannt' || name === 'Error: No unit' || name === 'Selbstverschulden.') {
|
2019-02-14 20:46:22 +01:00
|
|
|
return {name: 'UNKNOWN', fraction: 'NONE'};
|
2018-06-17 11:52:43 +02:00
|
|
|
}
|
|
|
|
resPlayer.name = name;
|
2018-09-30 14:43:01 +02:00
|
|
|
} else {
|
2019-02-14 20:46:22 +01:00
|
|
|
return {name: 'UNKNOWN', fraction: 'NONE'};
|
2018-06-09 19:17:38 +02:00
|
|
|
}
|
2018-09-30 14:43:01 +02:00
|
|
|
|
2018-06-09 19:17:38 +02:00
|
|
|
// ADDITIONAL PLAYER NAMES
|
|
|
|
let additionalPlayerMatch;
|
|
|
|
while ((additionalPlayerMatch = playerNameRegex.exec(inputString)) !== null) {
|
|
|
|
const addPlayer = additionalPlayerMatch[0].replace(/^,\s/, '').replace(/\s\($/, '').trim();
|
|
|
|
if (name instanceof Array) {
|
2018-06-09 22:06:18 +02:00
|
|
|
name.push(addPlayer);
|
2018-06-09 19:17:38 +02:00
|
|
|
} else {
|
|
|
|
name = [name, addPlayer];
|
|
|
|
}
|
2018-06-04 21:46:07 +02:00
|
|
|
}
|
|
|
|
|
2018-06-09 19:17:38 +02:00
|
|
|
// PLAYER FRACTION
|
2018-06-06 18:45:25 +02:00
|
|
|
let side;
|
2018-06-04 21:46:07 +02:00
|
|
|
if (sideMatch && sideMatch.length >= 3) {
|
2018-06-06 18:45:25 +02:00
|
|
|
side = sideMatch[2];
|
2018-06-04 21:46:07 +02:00
|
|
|
} else {
|
2018-06-06 18:45:25 +02:00
|
|
|
const inputArray = inputString.split(WHITESPACE);
|
|
|
|
if (inputArray) {
|
|
|
|
side = inputArray[inputArray.length - 1].replace('(', '').replace(')', '');
|
2018-06-04 21:46:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-17 11:52:43 +02:00
|
|
|
if (side && side !== 'ENEMY') {
|
2018-09-30 14:43:01 +02:00
|
|
|
resPlayer.fraction = (side === 'WEST') ? 'BLUFOR' : 'OPFOR';
|
2018-06-17 11:52:43 +02:00
|
|
|
}
|
2018-06-09 19:17:38 +02:00
|
|
|
|
2018-06-06 18:45:25 +02:00
|
|
|
// MAGAZINE
|
2018-06-17 11:52:43 +02:00
|
|
|
const magazineMatch = magazineRegex.exec(inputString);
|
|
|
|
if (magazineMatch && magazineMatch.length >= 3) {
|
|
|
|
let magazine = magazineMatch[2];
|
|
|
|
if (new RegExp('\\(.*$').test(magazine)) {
|
|
|
|
magazine = magazine.concat(')');
|
|
|
|
}
|
|
|
|
resPlayer.magazine = magazine;
|
2018-06-04 21:46:07 +02:00
|
|
|
}
|
|
|
|
|
2018-06-17 11:52:43 +02:00
|
|
|
// VEHICLE
|
|
|
|
const vehicleMatch = vehicleRegex.exec(inputString);
|
|
|
|
if (vehicleMatch && vehicleMatch.length >= 3 && vehicleMatch[2]) {
|
|
|
|
let vehicle = vehicleMatch[2];
|
|
|
|
if (new RegExp('\\(.*$').test(vehicle)) {
|
|
|
|
vehicle = vehicle.concat(')');
|
|
|
|
}
|
|
|
|
resPlayer.vehicle = vehicle;
|
2017-10-21 11:32:25 +02:00
|
|
|
}
|
2018-06-17 11:52:43 +02:00
|
|
|
|
|
|
|
return resPlayer;
|
2017-10-21 12:11:32 +02:00
|
|
|
};
|
2017-10-21 11:32:25 +02:00
|
|
|
|
2018-04-14 13:20:10 +02:00
|
|
|
const getVehicleAndFractionFromString = (nameClassFractionString) => {
|
2018-06-06 18:45:25 +02:00
|
|
|
const sideMatch = sideRegex.exec(nameClassFractionString);
|
|
|
|
const categoryMatch = categoryRegex.exec(nameClassFractionString);
|
|
|
|
|
|
|
|
// NAME
|
|
|
|
const vehicleName = nameClassFractionString.substring(0,
|
|
|
|
nameClassFractionString.indexOf(vehicleNameEndRegex.exec(nameClassFractionString)));
|
|
|
|
|
|
|
|
let fraction;
|
|
|
|
if (sideMatch && sideMatch.length >= 3) {
|
|
|
|
// SIDE
|
|
|
|
const side = sideMatch[2];
|
|
|
|
fraction = side === 'OPT_NATO' || side === 'OPT_NATO_T' || side === 'WEST' ? 'BLUFOR' : 'OPFOR';
|
|
|
|
}
|
|
|
|
|
|
|
|
let vehicleClassString;
|
|
|
|
if (categoryMatch && categoryMatch.length >= 3) {
|
|
|
|
// CATEGORY
|
|
|
|
vehicleClassString = categoryMatch[2];
|
|
|
|
}
|
2018-03-03 12:26:24 +01:00
|
|
|
|
2018-04-14 13:44:50 +02:00
|
|
|
// skip logging here - this is some basic equipment identifier (i.e. parachute)
|
2018-06-06 18:45:25 +02:00
|
|
|
if (fraction === 'OPF_F' || fraction === 'BLU_F' || vehicleClassString === VehicleClasses.UNKNOWN) {
|
2018-03-03 12:26:24 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-14 13:44:50 +02:00
|
|
|
let vehicleClass;
|
|
|
|
for (const key in VehicleClasses) {
|
2018-06-06 18:45:25 +02:00
|
|
|
if (VehicleClasses.hasOwnProperty(key) && VehicleClasses[key] === vehicleClassString) {
|
2018-04-14 13:44:50 +02:00
|
|
|
vehicleClass = key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-06 18:45:25 +02:00
|
|
|
if (vehicleName && fraction && vehicleClass) {
|
|
|
|
return {
|
|
|
|
name: vehicleName,
|
|
|
|
fraction: fraction,
|
|
|
|
vehicleClass: vehicleClass,
|
|
|
|
};
|
|
|
|
}
|
2018-03-03 12:26:24 +01:00
|
|
|
};
|
|
|
|
|
2017-10-20 23:42:41 +02:00
|
|
|
const transformMoneyString = (budgetString) => {
|
2017-10-21 12:11:32 +02:00
|
|
|
if (!budgetString.includes('e+')) {
|
2017-10-20 23:42:41 +02:00
|
|
|
return parseInt(budgetString);
|
|
|
|
}
|
2017-10-21 12:11:32 +02:00
|
|
|
const budget = budgetString.split('e+');
|
2018-06-06 18:45:25 +02:00
|
|
|
return Math.round(parseFloat(budget[0]) * Math.pow(10, parseInt(budget[1])));
|
2017-10-29 17:36:55 +01:00
|
|
|
};
|
2017-10-20 23:42:41 +02:00
|
|
|
|
2017-10-29 17:36:55 +01:00
|
|
|
const getFullTimeDate = (date, timeString) => {
|
|
|
|
const returnDate = new Date(date);
|
|
|
|
const time = timeString.split(':');
|
2018-06-06 18:45:25 +02:00
|
|
|
returnDate.setHours(time[0]);
|
|
|
|
returnDate.setMinutes(time[1]);
|
2019-02-02 23:52:02 +01:00
|
|
|
returnDate.setSeconds(time[2]);
|
2017-10-29 17:36:55 +01:00
|
|
|
return returnDate;
|
2017-10-20 23:42:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = parseWarLog;
|