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,51 +458,46 @@ function createRouter(db) { ...@@ -458,51 +458,46 @@ 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(
sql,
(error) => {
if (error) {
console.log(error);
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} else {
res.header('Access-Control-Allow-Origin', "*").status(200).json(
{
status: 'true',
red: JSON.parse(req.body.red)+1,
blue: req.body.blue
}
);
} }
if (team === 'blue') {
teamname = 'Blue';
pointsBlue = pointsBlue + 1;
} }
); 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;';
} else if (team === 'blue') { console.log('addPoint check 1: ', sql);
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( db.query(
sql, sql,
(error) => { (error, results) => {
if (error) { if (error) {
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 {
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: req.body.red, red: pointsRed,
blue: JSON.parse(req.body.blue)+1 blue: pointsBlue
} }
); );
} else {
console.log('Check Update Failed: ', checkUpdate, error);
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false', reason: 'checkUpdate Failed with '+checkUpdate});
} }
} }
);
} }
} else { );
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} }
}; };
...@@ -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);
db.query(
sql,
(error) => {
if (error) {
console.log(error);
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} else {
next()
} }
if (team === 'blue') {
teamname = 'Blue';
} }
); 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;';
} else if (team === 'blue') { console.log('removePoint check 1: ', sql);
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 = 4 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\") AND CardID = '+cardID+';';
console.log('removePoint Blue: ', sql);
db.query( db.query(
sql, sql,
(error) => { (error, results) => {
if (error) { if (error) {
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 { }
const checkUpdate = results[0].affectedRows;
console.log('removePoint 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('removePoint: ', sqlUpdate);
db.query(sqlUpdate);
next() next()
} else {
console.log('Check Update Failed: ', checkUpdate, error);
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false', reason: 'checkUpdate Failed with '+checkUpdate});
setTimeout(setIsTaboohTo0, 1500, req, res);
} }
} }
); );
}
} 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