Commit 942762da authored by Joshua's avatar Joshua

C:/Program Files/Git/newRound, /endRound, /newGame

parent b8d44a03
......@@ -103,6 +103,66 @@ function createRouter(db) {
}
});
//Start a new Round and lock the game positions
router.post('/newRound', (req, res) => {
const spielname = req.body.spielname;
if (spielname.match(/^[0-9a-zA-Z]+$/) != null) {
db.query(
'UPDATE Gamestatus SET ActiveExplainer = 1, ActiveWatchdog=1 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")',
(error, results) => {
if (error) {
console.log(error);
res.status(500).json({status: 'false'});
} else {
res.status(200).json({status: 'true'});
}
}
);
} else {
res.status(500).json({status: 'false'});
}
});
//End a Round and unlock the game positions and invert RedTurn
router.post('/endRound', (req, res) => {
const spielname = req.body.spielname;
if (spielname.match(/^[0-9a-zA-Z]+$/) != null) {
db.query(
'UPDATE Gamestatus SET RedTurn = (SELECT 1-Gamestatus.RedTurn FROM Gamestatus INNER JOIN Session ON Session.SessionID=Gamestatus.SessionID WHERE Session.SessionName = \"'+spielname+'\"), ActiveExplainer = 0, ActiveWatchdog=0 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")',
(error, results) => {
if (error) {
console.log(error);
res.status(500).json({status: 'false'});
} else {
res.status(200).json({status: 'true'});
}
}
);
} else {
res.status(500).json({status: 'false'});
}
});
//Starts a new Game and resets red and blue and chooses a random value for RedTurn
router.post('/newGame', (req, res) => {
const spielname = req.body.spielname;
if (spielname.match(/^[0-9a-zA-Z]+$/) != null) {
db.query(
'UPDATE Gamestatus SET Red = 0, Blue = 0, RedTurn = '+Math.round(Math.random())+' WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")',
(error, results) => {
if (error) {
console.log(error);
res.status(500).json({status: 'false'});
} else {
res.status(200).json({status: 'true'});
}
}
);
} else {
res.status(500).json({status: 'false'});
}
});
return router;
}
......
{
"name": "timeline-server",
"name": "Tabu-Middleware",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
......
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