constsql='SELECT SessionID, Red, Blue, RedTurn, ActiveExplainer, ActiveCard FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")';
constsql='SELECT SessionID, Round, Red, Blue, RedTurn, ActiveExplainer, ActiveCard, isTabooh, lastPlay FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")';
constsql='INSERT INTO Gamestatus (SessionID, Red, Blue, RedTurn, ActiveExplainer, ActiveCard, isTabooh) VALUES ((SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\"), 0, 0, '+redTurn+', 0, 0, 0);';
constsql='INSERT INTO Gamestatus (SessionID, Round, Red, Blue, RedTurn, ActiveExplainer, ActiveCard, isTabooh, lastPlay) VALUES ((SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\"), 0, 0, 0, '+redTurn+', 0, 0, 0, now());';
console.log('addSession2: ',sql);
db.query(
sql,
...
...
@@ -175,7 +178,7 @@ function createRouter(db) {
db.query(sqlUpdate);
constsqlInsert='INSERT INTO S2C (SessionID, CardID) VALUES ((SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\"), '+card.CardID+');';
constsqlInsert='INSERT INTO S2C (SessionID, CardID, Round, RedTurn, CardResultID, ActiveGame) VALUES ((SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\"), '+card.CardID+', (SELECT Round FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")), (SELECT RedTurn FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")), 0, 1);';
constsql='UPDATE Gamestatus SET ActiveExplainer = 1 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")';
constsql='UPDATE Gamestatus SET ActiveExplainer = 1, lastPlay = now(), Round = Round + 1, isTabooh = 0 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")';
console.log('newRound: ',sql);
db.query(
sql,
...
...
@@ -258,7 +261,8 @@ function createRouter(db) {
functionendRound(req){
constspielname=req.body.spielname;
if(spielname.match(/^[0-9a-z]+$/)!=null){
constsql='UPDATE Gamestatus SET RedTurn = (SELECT 1-Gamestatus.RedTurn FROM Gamestatus INNER JOIN Session ON Session.SessionID=Gamestatus.SessionID WHERE Session.SessionName = \"'+spielname+'\"), ActiveExplainer = 0, ActiveCard =0 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")';
constsql='UPDATE S2C SET CardResultID = 1 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\") AND CardID = (SELECT ActiveCard FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\"));'+
'UPDATE Gamestatus SET RedTurn = (SELECT 1-Gamestatus.RedTurn FROM Gamestatus INNER JOIN Session ON Session.SessionID=Gamestatus.SessionID WHERE Session.SessionName = \"'+spielname+'\"), ActiveExplainer = 0, ActiveCard =0 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\");';
console.log('endRound: ',sql);
db.query(
sql,
...
...
@@ -284,7 +288,8 @@ function createRouter(db) {
constnewGame=functionnewGame(req,res){
constspielname=req.body.spielname;
if(spielname.match(/^[0-9a-z]+$/)!=null){
constsql='UPDATE Gamestatus SET Red = 0, Blue = 0, RedTurn = '+Math.round(Math.random())+' WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")';
constsql='UPDATE Gamestatus SET Round = 0, Red = 0, Blue = 0, RedTurn = '+Math.round(Math.random())+' WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\");'+
'UPDATE S2C SET ActiveGame = 0 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\");';
constsql='UPDATE Gamestatus SET Red = 1+(SELECT Red FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")) WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")';
constsql='UPDATE Gamestatus SET Red = 1+(SELECT Red FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")) WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\");'+
'UPDATE S2C SET CardResultID = 2 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\") AND CardID = '+cardID+';';
console.log('addPoint Red:',sql);
db.query(
sql,
...
...
@@ -444,7 +451,8 @@ function createRouter(db) {
}
);
}elseif(team==='blue'){
constsql='UPDATE Gamestatus SET Blue = 1+(SELECT Blue FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")) WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")';
constsql='UPDATE Gamestatus SET Blue = 1+(SELECT Blue FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")) WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\");'+
'UPDATE S2C SET CardResultID = 2 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\") AND CardID = '+cardID+';';
constsql='UPDATE Gamestatus SET Red = -1+(SELECT Red FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")) WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")';
constsql='UPDATE Gamestatus SET Red = -1+(SELECT Red FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")) WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\");'+
'UPDATE S2C SET CardResultID = 4 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\") AND CardID = '+cardID+';';
console.log('removePoint Red: ',sql);
db.query(
sql,
...
...
@@ -488,7 +498,8 @@ function createRouter(db) {
}
);
}elseif(team==='blue'){
constsql='UPDATE Gamestatus SET Blue = -1+(SELECT Blue FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")) WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")';
constsql='UPDATE Gamestatus SET Blue = -1+(SELECT Blue FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")) WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\");'+
'UPDATE S2C SET CardResultID = 4 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\") AND CardID = '+cardID+';';
constsql='UPDATE S2C SET CardResultID = 3 WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\") AND CardID = '+cardID+';';
constsql='UPDATE S2C SET CardResultID = '+cardResultID+' WHERE S2CID = '+s2cID+';'+
'UPDATE Gamestatus SET '+team+' = '+point+' +(SELECT '+team+' FROM Gamestatus WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\")) WHERE SessionID = (SELECT SessionID FROM Session WHERE SessionName = \"'+spielname+'\");';