diff --git a/backend.js b/backend.js index 293b95c..f188200 100644 --- a/backend.js +++ b/backend.js @@ -145,7 +145,7 @@ app.get("/api/reset/:sessionId", (req, res) => { const { sessionId } = req.params; db.run(`UPDATE "${sessionId}" SET state = 0 WHERE state = 1`); - db.run(`UPDATE "${sessionId}" SET ready = 0 WHERE ready = 1`); + //db.run(`UPDATE "${sessionId}" SET ready = 0 WHERE ready = 1`); db.run(`UPDATE words SET inUse = 0 WHERE inUse = 1`); return res.status(201).json({ success: true }); }); diff --git a/game/game.js b/game/game.js index c75ca1c..88445f3 100644 --- a/game/game.js +++ b/game/game.js @@ -6,20 +6,20 @@ show_user() async function show_user() { const res = await fetch(`/api/user/${sessionId}`); const users = await res.json(); + //todo: der check ob es schon einen imposter gibt sollte auf dem Server stattfinden! const allUsers = users.map((u) => u.state); if (allUsers.every((v) => v === 0)) { createImposter(); async function createImposter() { const res = await fetch(`/api/${sessionId}/${username}/createImposter`); - var imposterStatus = getImposter(); //var für globale variable, muss in dieser funktion sein wegen komischer race condition bug + getImposter(); } }else { - var imposterStatus = getImposter(); //var für globale variable, muss in dieser funktion sein wegen komischer race condition bug + getImposter(); + } } -//const imposterStatus = getImposter(); - async function getImposter() { const res = await fetch(`/api/${sessionId}/${username}/getImposter`); const stateObj = await res.json(); @@ -30,20 +30,14 @@ async function getImposter() { if (state == 1) { console.log("du bist imposter"); ImposterStateDiv.textContent = "Du bist der Imposter!"; - return true; + getWords(true); } else { console.log("du bist kein imposter"); ImposterStateDiv.textContent = "Du bist kein Imposter!"; - return false; + getWords(false); } } -// Initialisierung: await getImposter(), dann getWords aufrufen -async function init() { - const imposterStatus = await getImposter(); - await getWords(imposterStatus); -} -init(); async function getWords(imposterStatus) { const res = await fetch(`/api/getWords`); diff --git a/imposter.db b/imposter.db index ba50367..d087239 100644 Binary files a/imposter.db and b/imposter.db differ diff --git a/index.html b/index.html index 04be76f..3de6f9e 100644 --- a/index.html +++ b/index.html @@ -6,17 +6,18 @@