Commit 8e4cbe2b authored by Dennis Willers's avatar Dennis Willers 🏀

Just one time can a new Round be startet

parent f8d27eec
Pipeline #328 passed with stages
in 3 minutes and 5 seconds
const express = require('express'); const express = require('express');
const io = require("socket.io-client"); const io = require("socket.io-client");
const socket = io('ws://tabu-server.willers.digital'); //const socket = io('ws://tabu-server.willers.digital');
//const socket = io('ws://localhost:80'); const socket = io('ws://localhost:3000');
function createRouter(db) { function createRouter(db) {
const router = express.Router(); const router = express.Router();
...@@ -184,6 +184,31 @@ function createRouter(db) { ...@@ -184,6 +184,31 @@ function createRouter(db) {
} }
}; };
const isActiveExplainer = function isActiveExplainer(req, res, next) {
const spielname = req.body.spielname;
if (spielname.match(/^[0-9a-zA-Z]+$/) != null) {
const sql = 'SELECT ActiveExplainer FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")';
console.log('isActiveExplainer: ',sql)
db.query(
sql,
(error, results) => {
console.log('Result: ', results);
if (error) {
console.log(error);
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false', reason: 'Round is active'});
} else {
const activeExplainer = JSON.parse(results[0].ActiveExplainer);
if (activeExplainer === 0) {
next();
} else {
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false', reason: 'Round is active'});
}
}
}
);
}
};
const newRound = function newRound(req, res) { const newRound = function newRound(req, res) {
const spielname = req.body.spielname; const spielname = req.body.spielname;
if (spielname.match(/^[0-9a-zA-Z]+$/) != null) { if (spielname.match(/^[0-9a-zA-Z]+$/) != null) {
...@@ -206,7 +231,7 @@ function createRouter(db) { ...@@ -206,7 +231,7 @@ function createRouter(db) {
} }
); );
} else { } else {
res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'}); res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false', reason: 'Already Active Game'});
} }
}; };
...@@ -234,7 +259,7 @@ function createRouter(db) { ...@@ -234,7 +259,7 @@ function createRouter(db) {
} else { } else {
//res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'}); //res.header('Access-Control-Allow-Origin', "*").status(500).json({status: 'false'});
} }
}; }
const newGame = function newGame(req, res) { const newGame = function newGame(req, res) {
const spielname = req.body.spielname; const spielname = req.body.spielname;
...@@ -408,13 +433,13 @@ function createRouter(db) { ...@@ -408,13 +433,13 @@ function createRouter(db) {
router.post('/getS2C', [getS2C]); router.post('/getS2C', [getS2C]);
//Start a new Round and lock the game positions //Start a new Round and lock the game positions
router.post('/newRound', [newRound]); router.post('/newRound', [isActiveExplainer, newRound]);
//End a Round and unlock the game positions and invert RedTurn //End a Round and unlock the game positions and invert RedTurn
router.post('/endRound', [endRound]); router.post('/endRound', [endRound]);
//Starts a new Game and resets red and blue and chooses a random value for RedTurn //Starts a new Game and resets red and blue and chooses a random value for RedTurn
router.post('/newGame', [newGame]); router.post('/newGame', [isActiveExplainer, newGame]);
//Add Point //Add Point
router.post('/addPoint', [addPoint]); router.post('/addPoint', [addPoint]);
......
...@@ -6,7 +6,7 @@ const Socketio = require("socket.io")(Http, { ...@@ -6,7 +6,7 @@ const Socketio = require("socket.io")(Http, {
} }
}); });
Http.listen(80, () => { Http.listen(3000, () => {
console.log("Listening at :3000..."); console.log("Listening at :3000...");
}); });
......
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