finish basci backend implementation
parent
35f6ac04b3
commit
1acaba5a60
|
@ -63,25 +63,31 @@ wars.route('/')
|
|||
})
|
||||
|
||||
.post(apiAuthenticationMiddleware, checkMT, upload.single('log'), (req, res, next) => {
|
||||
let body = req.body;
|
||||
const bodyWar = new WarModel(body);
|
||||
const body = req.body;
|
||||
const warBody = new WarModel(body);
|
||||
|
||||
if (req.file) {
|
||||
// bodyWar.save((err, war) => {
|
||||
// if (err) {
|
||||
// return next(err);
|
||||
// }
|
||||
fs.readFile(req.file.buffer, (file, err) => {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
const lineArray = file.toString().split("\n");
|
||||
res.locals.items = parseWarLog(lineArray, bodyWar);
|
||||
res.locals.processed = true;
|
||||
const statsResult = parseWarLog(lineArray, warBody);
|
||||
statsResult.war.save((err, war) => {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
PlayerModel.create(statsResult.players, function (err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
res.status(codes.created);
|
||||
res.locals.items = war;
|
||||
next();
|
||||
});
|
||||
// })
|
||||
})
|
||||
});
|
||||
|
||||
} else {
|
||||
const err = new Error('no Logfile provided');
|
||||
err.status = codes.wrongmediasend;
|
||||
|
|
|
@ -18,7 +18,7 @@ const parseWarLog = (lineArray, war) => {
|
|||
|
||||
const addPlayersIfNotExists = (inputPlayers) => {
|
||||
inputPlayers.forEach(player => {
|
||||
if (player && !arrayContains(stats.players, player)) {
|
||||
if (player && player.name && player.fraction && !arrayContains(stats.players, player)) {
|
||||
player['warId'] = war._id;
|
||||
stats.players.push(player);
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ const parseWarLog = (lineArray, war) => {
|
|||
stats.clean.push(line);
|
||||
const shooterString = line.substring(line.lastIndexOf(' von: ') + 6, line.lastIndexOf('. :OPT LOG END'));
|
||||
const shooter = getPlayerAndFractionFromString(shooterString);
|
||||
|
||||
const targetString = line.substring(line.lastIndexOf(' || ') + 4, line.lastIndexOf(' von:'));
|
||||
const target = getPlayerAndFractionFromString(targetString);
|
||||
|
||||
|
@ -58,6 +57,7 @@ const parseWarLog = (lineArray, war) => {
|
|||
stats.war['endBudgetBlufor'] = transformMoneyString(budg[11]);
|
||||
stats.war['endBudgetOpfor'] = transformMoneyString(budg[14]);
|
||||
} else if (line.includes('Startbudget')) {
|
||||
stats.war.date = new Date(budg[0].substr(0, budg[0].length - 1).split('/').join('-') + 'T22:00:00.000+02:00');
|
||||
stats.war['budgetBlufor'] = transformMoneyString(budg[11]);
|
||||
stats.war['budgetOpfor'] = transformMoneyString(budg[14]);
|
||||
} else {
|
||||
|
@ -114,7 +114,8 @@ const parseWarLog = (lineArray, war) => {
|
|||
if (line.includes('Revive')) {
|
||||
stats.clean.push(line);
|
||||
const stabilized = !!line.includes('stabilisiert');
|
||||
const medicName = line.substring(line.lastIndexOf('wurde von ') + 10, line.lastIndexOf(stabilized ? ' stabilisiert' : ' wiederbelebt'));
|
||||
const medicName = line.substring(line.lastIndexOf('wurde von ') + 10,
|
||||
line.lastIndexOf(stabilized ? ' stabilisiert' : ' wiederbelebt'));
|
||||
const medic = getPlayerAndFractionFromString(medicName);
|
||||
const patientName = line.substring(line.lastIndexOf('|| ') + 3, line.lastIndexOf(' wurde von'));
|
||||
const patient = getPlayerAndFractionFromString(patientName);
|
||||
|
@ -153,11 +154,20 @@ const parseWarLog = (lineArray, war) => {
|
|||
}
|
||||
});
|
||||
|
||||
for (let i = 0; i < stats.players.length; i++) {
|
||||
const playerName = stats.players[i].name;
|
||||
stats.players[i]['respawn'] = stats.respawn.filter(res => res.player === playerName).length;
|
||||
stats.players[i]['kill'] = stats.kills.filter(kill => kill.shooter === playerName && !kill.friendlyFire).length;
|
||||
stats.players[i]['friendlyFire'] = stats.kills.filter(kill => kill.shooter === playerName && kill.friendlyFire).length;
|
||||
stats.players[i]['death'] = stats.kills.filter(kill => kill.target === playerName).length;
|
||||
stats.players[i]['revive'] = stats.revive.filter(rev => rev.medic === playerName && !rev.stabilized).length;
|
||||
stats.players[i]['flagTouch'] = stats.flag.filter(flag => flag.player === playerName).length;
|
||||
}
|
||||
|
||||
stats.war.playersBlufor = stats.players.filter(player => player.fraction === 'BLUFOR').length;
|
||||
stats.war.playersOpfor = stats.players.filter(player => player.fraction === 'OPFOR').length;
|
||||
|
||||
return stats;
|
||||
|
||||
};
|
||||
|
||||
const getRespawnEntry = (respawn, playerName, warId) => {
|
||||
|
@ -189,10 +199,10 @@ const getBudgetEntry = (budg, warId) => {
|
|||
|
||||
const getPlayerAndFractionFromString = (nameAndFractionString) => {
|
||||
const nameArray = nameAndFractionString.split(' ');
|
||||
const fraction = nameArray[nameArray.length - 1] === '(WEST)' ? 'BLUFOR' : 'OPFOR';
|
||||
const fraction = nameArray[nameArray.length - 1] !== '(ENEMY)' ? nameArray[nameArray.length - 1] === '(WEST)' ? 'BLUFOR' : 'OPFOR' : undefined;
|
||||
const name = nameAndFractionString.substring(0, nameAndFractionString.indexOf(nameArray[nameArray.length - 1]) - 1);
|
||||
// do not return player for 'Selbstverschulden'
|
||||
if (name || name === 'Error: No unit') {
|
||||
if (name && name !== 'Error: No unit') {
|
||||
return {name: name, fraction: fraction};
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "opt-cc",
|
||||
"version": "1.5.4",
|
||||
"version": "1.6.0",
|
||||
"license": "MIT",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
|
Loading…
Reference in New Issue