Loading events.js +55 −1 Original line number Diff line number Diff line Loading @@ -19,8 +19,10 @@ function createRouter(db) { } ); //Init new Gamestatus var redTurn = Math.random(); redTurn = Math.round(redTurn); db.query( 'INSERT INTO Gamestatus (SessionID, Red, Blue, RedTurn, ActiveExplainer, ActiveWatchdog) VALUES ((SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\"), 0, 0, 1, 0, 0);', 'INSERT INTO Gamestatus (SessionID, Red, Blue, RedTurn, ActiveExplainer, ActiveWatchdog) VALUES ((SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\"), 0, 0, '+redTurn+', 0, 0);', error => { if (error) { console.error(error); Loading Loading @@ -103,6 +105,58 @@ function createRouter(db) { } }); //Return S2C router.post('/getS2C', (req,res) => { const spielname = req.body.spielname; if (spielname.match(/^[0-9a-zA-Z]+$/) != null) { let card; db.query( 'SELECT Card.CardID, Solution, Tabu1, Tabu2, Tabu3, Tabu4, Tabu5 \n' + 'FROM Card \n' + 'WHERE Card.CardID NOT IN \n' + '(\n' + ' SELECT S2C.CardID\n' + ' FROM S2C\n' + ' WHERE S2C.CardID IS NOT NULL AND S2C.SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")\n' + ');', (error, results) => { if (error) { console.log(error); res.status(500).json({status: 'false'}); } else { console.log(results); let random = Math.random() * (results.length-1); random = Math.round(random) card = results[random]; console.log(card); db.query( 'INSERT INTO S2C (SessionID, CardID) VALUES ((SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\"), '+card.CardID+');', (error, results) => { if (error) { res.status(500).json({status: 'false'}); } else { res.status(200).json( { status: 'true', cardID: card.CardID, solution: card.Solution, tabu1: card.Tabu1, tabu2: card.Tabu2, tabu3: card.Tabu3, tabu4: card.Tabu4, tabu5: card.Tabu5, } ); } } ); } }); } else { res.status(500).json({status: 'error'}); } }); //Start a new Round and lock the game positions router.post('/newRound', (req, res) => { const spielname = req.body.spielname; Loading Loading
events.js +55 −1 Original line number Diff line number Diff line Loading @@ -19,8 +19,10 @@ function createRouter(db) { } ); //Init new Gamestatus var redTurn = Math.random(); redTurn = Math.round(redTurn); db.query( 'INSERT INTO Gamestatus (SessionID, Red, Blue, RedTurn, ActiveExplainer, ActiveWatchdog) VALUES ((SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\"), 0, 0, 1, 0, 0);', 'INSERT INTO Gamestatus (SessionID, Red, Blue, RedTurn, ActiveExplainer, ActiveWatchdog) VALUES ((SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\"), 0, 0, '+redTurn+', 0, 0);', error => { if (error) { console.error(error); Loading Loading @@ -103,6 +105,58 @@ function createRouter(db) { } }); //Return S2C router.post('/getS2C', (req,res) => { const spielname = req.body.spielname; if (spielname.match(/^[0-9a-zA-Z]+$/) != null) { let card; db.query( 'SELECT Card.CardID, Solution, Tabu1, Tabu2, Tabu3, Tabu4, Tabu5 \n' + 'FROM Card \n' + 'WHERE Card.CardID NOT IN \n' + '(\n' + ' SELECT S2C.CardID\n' + ' FROM S2C\n' + ' WHERE S2C.CardID IS NOT NULL AND S2C.SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")\n' + ');', (error, results) => { if (error) { console.log(error); res.status(500).json({status: 'false'}); } else { console.log(results); let random = Math.random() * (results.length-1); random = Math.round(random) card = results[random]; console.log(card); db.query( 'INSERT INTO S2C (SessionID, CardID) VALUES ((SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\"), '+card.CardID+');', (error, results) => { if (error) { res.status(500).json({status: 'false'}); } else { res.status(200).json( { status: 'true', cardID: card.CardID, solution: card.Solution, tabu1: card.Tabu1, tabu2: card.Tabu2, tabu3: card.Tabu3, tabu4: card.Tabu4, tabu5: card.Tabu5, } ); } } ); } }); } else { res.status(500).json({status: 'error'}); } }); //Start a new Round and lock the game positions router.post('/newRound', (req, res) => { const spielname = req.body.spielname; Loading