Commit a03122e2 authored by Dennis Willers's avatar Dennis Willers 🏀

Buggy Sockets

parent ba3b1630
Pipeline #318 failed with stages
in 2 minutes and 54 seconds
......@@ -9,6 +9,10 @@ function createRouter(db) {
res.status(200).json({status: 'true'});
};
const wait = function () {
setTimeout(null, 60000);
};
const isSession = function isSession(req, res, next) {
const spielname = req.body.spielname;
if (spielname.match(/^[0-9a-zA-Z]+$/) != null) {
......@@ -188,6 +192,11 @@ function createRouter(db) {
res.status(500).json({status: 'false'});
} else {
res.status(200).json({status: 'true'});
socket.emit('newRound', {
sessionName: spielname,
isOpen: true
});
setTimeout(endRound, 6000, req);
}
}
);
......@@ -196,7 +205,7 @@ function createRouter(db) {
}
};
const endRound = function endRound(req, res) {
function endRound(req) {
const spielname = req.body.spielname;
if (spielname.match(/^[0-9a-zA-Z]+$/) != null) {
const sql = '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+'\")';
......@@ -206,14 +215,19 @@ function createRouter(db) {
(error) => {
if (error) {
console.log(error);
res.status(500).json({status: 'false'});
return
//res.status(500).json({status: 'false'});
} else {
res.status(200).json({status: 'true'});
socket.emit('endRound', {
isOpen: true,
sessionName: spielname,
});
//res.status(200).json({status: 'true'});
}
}
);
} else {
res.status(500).json({status: 'false'});
//res.status(500).json({status: 'false'});
}
};
......
require('./socket');
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
......
......@@ -12,6 +12,8 @@ var position = {
};
var currentCard = {};
var newRound = {};
var endRound = {};
Socketio.on("connection", socket => {
console.log('new Socket connect');
......@@ -42,10 +44,34 @@ Socketio.on("connection", socket => {
for (var key in currentCard) {
socket.emit(key, currentCard[key])
}
/*for (var key in newRound) {
socket.emit(key, newRound[key])
}
for (var key in endRound) {
socket.emit(key, endRound[key])
}*/
socket.on("newCard", data => {
console.log('New Card From: ', data, ':newCard');
console.log('New Card from: ', data, ':newCard');
currentCard[data.sessionName+":newCard"] = data.cardID;
Socketio.emit(data.sessionName+":newCard", data.cardID)
})
});
socket.on("newRound", data => {
console.log('New Round from: ', data.isOpen);
endRound[data.sessionName+":endRound"] = false;
Socketio.emit(data.sessionName+":endRound", false);
socket.emit(data.sessionName+":endRound", false);
newRound[data.sessionName+":newRound"] = true;
Socketio.emit(data.sessionName+":newRound", true);
socket.emit(data.sessionName+":newRound", true);
});
socket.on("endRound", data => {
console.log('End Round from: ', data.isOpen);
newRound[data.sessionName+":newRound"] = false;
Socketio.emit(data.sessionName+":newRound", false);
socket.emit(data.sessionName+":newRound", false);
endRound[data.sessionName+":endRound"] = true;
Socketio.emit(data.sessionName+":endRound", true);
socket.emit(data.sessionName+":endRound", 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