Commit a88af9b2 authored by Dennis Willers's avatar Dennis Willers 🏀

Remove Point set a Timer until a Tabooh Button can be pressed again. Need to...

Remove Point set a Timer until a Tabooh Button can be pressed again. Need to be implemented in the frontend as well
parent 1d7fd718
...@@ -317,7 +317,7 @@ function createRouter(db) { ...@@ -317,7 +317,7 @@ function createRouter(db) {
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 {
resultCardID = results[0].ActiveCard; let resultCardID = results[0].ActiveCard;
if (JSON.parse(resultCardID) === JSON.parse(cardID)) { if (JSON.parse(resultCardID) === JSON.parse(cardID)) {
next(); next();
} else { } else {
...@@ -332,6 +332,93 @@ function createRouter(db) { ...@@ -332,6 +332,93 @@ function createRouter(db) {
} }
}; };
const canPressTabooh = function canPressTabooh(req, res, next) {
const spielname = req.body.spielname;
const sql = 'SELECT isTabooh FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\");';
console.log('canPressTabooh: ', sql);
if (spielname.match(/^[0-9a-z]+$/) != null) {
db.query(sql,
(error, results) => {
if (error) {
console.log(error);
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} else {
let resultCardID = results[0].isTabooh;
if (JSON.parse(resultCardID) === 0) {
next();
} else {
res.header('Access-Control-Allow-Origin', "*").status(200).json({status: 'false'});
}
}
});
}
};
const setIsTaboohTo1 = function setIsTaboohTo1(req, res, next) {
const spielname = req.body.spielname;
const sql = 'UPDATE Gamestatus SET isTabooh = 1 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")';
console.log('setIsTaboohTo1:', sql);
if (spielname.match(/^[0-9a-z]+$/) != null) {
db.query(sql,
(error) => {
if (error) {
console.log(error);
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} else {
socket.emit('canPressTabooh', {
canPressTabooh: false,
sessionName: spielname,
});
next();
}
});
}
};
const setIsTaboohTo0 = function setIsTaboohTo0(req, res) {
const spielname = req.body.spielname;
const sql = 'UPDATE Gamestatus SET isTabooh = 0 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")';
console.log('setIsTaboohTo0:', sql);
if (spielname.match(/^[0-9a-z]+$/) != null) {
db.query(sql,
(error) => {
if (error) {
console.log(error);
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} else {
socket.emit('canPressTabooh', {
canPressTabooh: true,
sessionName: spielname,
});
}
});
}
};
const acceptRemovePoint = function acceptRemovePoint(req, res) {
const spielname = req.body.spielname;
const sql = 'SELECT Red, Blue FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")';
console.log('acceptRemovePoint:', sql);
if (spielname.match(/^[0-9a-z]+$/) != null) {
db.query(sql,
(error, results) => {
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: results[0].Red,
blue: results[0].Blue
}
);
setTimeout(setIsTaboohTo0, 2500, req, res);
}
});
}
};
const addPoint = function addPoint(req, res) { const addPoint = function addPoint(req, res) {
const spielname = req.body.spielname; const spielname = req.body.spielname;
const team = req.body.team; const team = req.body.team;
...@@ -382,7 +469,7 @@ function createRouter(db) { ...@@ -382,7 +469,7 @@ function createRouter(db) {
} }
}; };
const removePoint = function removePoint(req, res) { const removePoint = function removePoint(req, res, next) {
const spielname = req.body.spielname; const spielname = req.body.spielname;
const team = req.body.team; const team = req.body.team;
if (spielname.match(/^[0-9a-z]+$/) != null && team.match(/^[0-9a-z]+$/) != null) { if (spielname.match(/^[0-9a-z]+$/) != null && team.match(/^[0-9a-z]+$/) != null) {
...@@ -396,13 +483,7 @@ function createRouter(db) { ...@@ -396,13 +483,7 @@ function createRouter(db) {
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 {
res.header('Access-Control-Allow-Origin', "*").status(200).json( next()
{
status: 'true',
red: JSON.parse(req.body.red)-1,
blue: req.body.blue
}
);
} }
} }
); );
...@@ -416,13 +497,7 @@ function createRouter(db) { ...@@ -416,13 +497,7 @@ function createRouter(db) {
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 {
res.header('Access-Control-Allow-Origin', "*").status(200).json( next()
{
status: 'true',
red: req.body.red,
blue: JSON.parse(req.body.blue)-1
}
);
} }
} }
); );
...@@ -493,7 +568,7 @@ function createRouter(db) { ...@@ -493,7 +568,7 @@ function createRouter(db) {
router.post('/addPoint', [isPoint4Card, addPoint]); router.post('/addPoint', [isPoint4Card, addPoint]);
//Remove Point //Remove Point
router.post('/removePoint', [isPoint4Card, removePoint]); router.post('/removePoint', [isPoint4Card, canPressTabooh, setIsTaboohTo1, removePoint, acceptRemovePoint]);
//Get ActiveCard //Get ActiveCard
router.post('/getActiveCard', [isSession, getActiveCard]); router.post('/getActiveCard', [isSession, getActiveCard]);
......
...@@ -44,5 +44,10 @@ Socketio.on("connection", socket => { ...@@ -44,5 +44,10 @@ Socketio.on("connection", socket => {
Socketio.emit(data.sessionName+":endRound", true); Socketio.emit(data.sessionName+":endRound", true);
socket.emit(data.sessionName+":endRound", true); socket.emit(data.sessionName+":endRound", true);
}); });
socket.on("canPressTabooh", data => {
console.log('CanPressTabooh from: ', data.sessionName, data.canPressTabooh);
Socketio.emit(data.sessionName+":canPressTabooh", data.canPressTabooh);
socket.emit(data.sessionName+":canPressTabooh", data.canPressTabooh);
});
}); });
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