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) {
const cardID = req.body.cardID;
const team = req.body.team;
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') {
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+'\");' +
'UPDATE S2C SET CardResultID = 2 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\") AND CardID = '+cardID+';';
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
}
);
teamname = 'Red';
pointsRed = pointsRed + 1;
}
if (team === 'blue') {
teamname = 'Blue';
pointsBlue = pointsBlue + 1;
}
);
} 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);
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;';
console.log('addPoint check 1: ', sql);
db.query(
sql,
(error) => {
(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(
{
status: 'true',
red: req.body.red,
blue: JSON.parse(req.body.blue)+1
red: pointsRed,
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) {
const cardID = req.body.cardID;
const team = req.body.team;
if (spielname.match(/^[0-9a-z]+$/) != null && team.match(/^[0-9a-z]+$/) != null && !isNaN(cardID)) {
let teamname = '';
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+'\");' +
'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()
teamname = 'Red';
}
if (team === 'blue') {
teamname = 'Blue';
}
);
} 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 = 4 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\") AND CardID = '+cardID+';';
console.log('removePoint Blue: ', sql);
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;';
console.log('removePoint check 1: ', sql);
db.query(
sql,
(error) => {
(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('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()
} 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 {
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
}
......@@ -551,12 +545,13 @@ function createRouter(db) {
const spielname = req.body.spielname;
const cardID = req.body.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);
db.query(
sql,
(error) => {
(error, results) => {
if (error) {
console.log('skipCard check: ', results[0].affectedRows);
console.log(error);
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} 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