Commit 79550d8f authored by Dennis Willers's avatar Dennis Willers 🏀

Punkte werden jetzt richtig gezählt. Auch beim parallelen drücken.

parent db313be0
Pipeline #391 passed with stages
in 3 minutes and 25 seconds
...@@ -458,52 +458,47 @@ function createRouter(db) { ...@@ -458,52 +458,47 @@ function createRouter(db) {
const cardID = req.body.cardID; const cardID = req.body.cardID;
const team = req.body.team; const team = req.body.team;
if (spielname.match(/^[0-9a-z]+$/) != null && team.match(/^[0-9a-z]+$/) != null && !isNaN(cardID)) { if (spielname.match(/^[0-9a-z]+$/) != null && team.match(/^[0-9a-z]+$/) != null && !isNaN(cardID)) {
let teamname = '';
let pointsRed = JSON.parse(req.body.red);
let pointsBlue = JSON.parse(req.body.blue);
if (team === 'red') { if (team === 'red') {
const sql = 'UPDATE Gamestatus SET Red = 1+(SELECT Red FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")) WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\");' + teamname = 'Red';
'UPDATE S2C SET CardResultID = 2 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\") AND CardID = '+cardID+';'; pointsRed = pointsRed + 1;
console.log('addPoint Red:', sql); }
db.query( if (team === 'blue') {
sql, teamname = 'Blue';
(error) => { pointsBlue = pointsBlue + 1;
if (error) { }
console.log(error); const sql = 'UPDATE S2C SET CardResultID = 2 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\") AND CardID = '+cardID+' AND (((SELECT ActiveExplainer FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")) = 1 AND CardResultID = 0) OR (SELECT ActiveExplainer FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")) = 0);SELECT ROW_COUNT() AS CheckUpdate;';
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'}); console.log('addPoint check 1: ', sql);
} else { db.query(
sql,
(error, results) => {
if (error) {
console.log(error);
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} else {
const checkUpdate = results[0].affectedRows;
console.log('addPoint check 2: ', results[0].affectedRows);
if (checkUpdate === 1) {
const sqlUpdate = 'UPDATE Gamestatus SET '+teamname+' = 1+(SELECT '+teamname+' FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")) WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\");';
console.log('addPoint: ', sqlUpdate);
db.query(sqlUpdate);
res.header('Access-Control-Allow-Origin', "*").status(200).json( res.header('Access-Control-Allow-Origin', "*").status(200).json(
{ {
status: 'true', status: 'true',
red: JSON.parse(req.body.red)+1, red: pointsRed,
blue: req.body.blue blue: pointsBlue
} }
); );
}
}
);
} else if (team === 'blue') {
const sql = 'UPDATE Gamestatus SET Blue = 1+(SELECT Blue FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")) WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\");' +
'UPDATE S2C SET CardResultID = 2 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\") AND CardID = '+cardID+';';
console.log('addPoint Blue:', sql);
db.query(
sql,
(error) => {
if (error) {
console.log(error);
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} else { } else {
res.header('Access-Control-Allow-Origin', "*").status(200).json( console.log('Check Update Failed: ', checkUpdate, error);
{ res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false', reason: 'checkUpdate Failed with '+checkUpdate});
status: 'true',
red: req.body.red,
blue: JSON.parse(req.body.blue)+1
}
);
} }
} }
); }
);
} }
} else {
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
}
}; };
const removePoint = function removePoint(req, res, next) { const removePoint = function removePoint(req, res, next) {
...@@ -511,37 +506,36 @@ function createRouter(db) { ...@@ -511,37 +506,36 @@ function createRouter(db) {
const cardID = req.body.cardID; const cardID = req.body.cardID;
const team = req.body.team; const team = req.body.team;
if (spielname.match(/^[0-9a-z]+$/) != null && team.match(/^[0-9a-z]+$/) != null && !isNaN(cardID)) { if (spielname.match(/^[0-9a-z]+$/) != null && team.match(/^[0-9a-z]+$/) != null && !isNaN(cardID)) {
let teamname = '';
if (team === 'red') { if (team === 'red') {
const sql = 'UPDATE Gamestatus SET Red = -1+(SELECT Red FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")) WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\");' + teamname = 'Red';
'UPDATE S2C SET CardResultID = 4 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\") AND CardID = '+cardID+';'; }
console.log('removePoint Red: ', sql); if (team === 'blue') {
db.query( teamname = 'Blue';
sql, }
(error) => { const sql = 'UPDATE S2C SET CardResultID = 4 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\") AND CardID = '+cardID+' AND (((SELECT ActiveExplainer FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")) = 1 AND CardResultID = 0) OR (SELECT ActiveExplainer FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")) = 0);SELECT ROW_COUNT() AS CheckUpdate;';
if (error) { console.log('removePoint check 1: ', sql);
console.log(error); db.query(
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'}); sql,
} else { (error, results) => {
next() if (error) {
} console.log(error);
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} }
); const checkUpdate = results[0].affectedRows;
} else if (team === 'blue') { console.log('removePoint check 2: ', results[0].affectedRows);
const sql = 'UPDATE Gamestatus SET Blue = -1+(SELECT Blue FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")) WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\");' + if (checkUpdate === 1) {
'UPDATE S2C SET CardResultID = 4 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\") AND CardID = '+cardID+';'; const sqlUpdate = 'UPDATE Gamestatus SET '+teamname+' = -1+(SELECT '+teamname+' FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")) WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\");';
console.log('removePoint Blue: ', sql); console.log('removePoint: ', sqlUpdate);
db.query( db.query(sqlUpdate);
sql, next()
(error) => { } else {
if (error) { console.log('Check Update Failed: ', checkUpdate, error);
console.log(error); res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false', reason: 'checkUpdate Failed with '+checkUpdate});
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'}); setTimeout(setIsTaboohTo0, 1500, req, res);
} else {
next()
}
} }
); }
} );
} else { } else {
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'}); res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} }
...@@ -551,12 +545,13 @@ function createRouter(db) { ...@@ -551,12 +545,13 @@ function createRouter(db) {
const spielname = req.body.spielname; const spielname = req.body.spielname;
const cardID = req.body.cardID; const cardID = req.body.cardID;
if (spielname.match(/^[0-9a-z]+$/) != null && !isNaN(cardID)) { if (spielname.match(/^[0-9a-z]+$/) != null && !isNaN(cardID)) {
const sql = 'UPDATE S2C SET CardResultID = 3 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\") AND CardID = '+cardID+';'; const sql = 'UPDATE S2C SET CardResultID = 3 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\") AND CardID = '+cardID+' AND (((SELECT ActiveExplainer FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")) = 1 AND CardResultID = 0) OR (SELECT ActiveExplainer FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")) = 0);SELECT ROW_COUNT() AS CheckUpdate;';
console.log('skipCard: ', sql); console.log('skipCard: ', sql);
db.query( db.query(
sql, sql,
(error) => { (error, results) => {
if (error) { if (error) {
console.log('skipCard check: ', results[0].affectedRows);
console.log(error); console.log(error);
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'}); res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment