'INSERT INTO Session (SessionName) VALUES (\"'+spielname+'\");',
'INSERT INTO Session (SessionName) VALUES (\"'+spielname+'\");',
(error)=>{
error=>{
if(error){
if(error){
console.error(error);
console.error(error);
res.status(500).json({status:'false'});
res.status(500).json({status:'false'});
}else{
res.status(200).json({status:'true'});
}
}
}
}
);
);
//Init new Gamestatus
db.query(
'INSERT INTO Gamestatus (SessionID, Red, Blue, RedTurn, ActiveExplainer, ActiveWatchdog) VALUES ((SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\"), 0, 0, 1, 0, 0);',
error=>{
if(error){
console.error(error);
res.status(500).json({status:'false'});
}else{
res.status(200).json({status:'true'});
}
});
}else{
}else{
res.status(500).json({status:'error'});
res.status(500).json({status:'error'});
}
}
});
});
//Check if Session exist
router.post('/isSession',(req,res)=>{
router.post('/isSession',(req,res)=>{
varspielname=req.body.spielname;
constspielname=req.body.spielname;
if(spielname.match(/^[0-9a-zA-Z]+$/)!=null){
if(spielname.match(/^[0-9a-zA-Z]+$/)!=null){
db.query(
db.query(
'SELECT SessionName FROM Session WHERE SessionName = \''+spielname+'\';',
'SELECT SessionName FROM Session WHERE SessionName = \''+spielname+'\';',
...
@@ -46,6 +58,7 @@ function createRouter(db) {
...
@@ -46,6 +58,7 @@ function createRouter(db) {
}
}
});
});
//Return all Sessions (Not neccesary)
router.get('/Session',function(req,res){
router.get('/Session',function(req,res){
db.query(
db.query(
'SELECT * FROM Session',
'SELECT * FROM Session',
...
@@ -60,6 +73,36 @@ function createRouter(db) {
...
@@ -60,6 +73,36 @@ function createRouter(db) {
);
);
});
});
//Return GameStatus
router.post('/getGamestatus',(req,res)=>{
constspielname=req.body.spielname;
if(spielname.match(/^[0-9a-zA-Z]+$/)!=null){
db.query(
'SELECT SessionID, Red, Blue, RedTurn, ActiveExplainer, ActiveWatchdog FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")',