imposter get
This commit is contained in:
20
backend.js
20
backend.js
@ -81,9 +81,27 @@ app.get("/api/:sessionId/:username/createImposter", (req, res) => {
|
||||
|
||||
function createImposter(sessionId, userQty) {
|
||||
const ImposterId = Math.floor(Math.random() * userQty) + 1;
|
||||
db.run(`UPDATE "${sessionId}" state = 1 WHERE id = ? `[ImposterId]);
|
||||
console.log(sessionId, ImposterId);
|
||||
db.run(`UPDATE "${sessionId}" SET state = 1 WHERE id = ? `, [ImposterId]);
|
||||
}
|
||||
|
||||
app.get("/api/:sessionId/:username/getImposter", (req, res) => {
|
||||
const { sessionId, username } = req.params;
|
||||
|
||||
db.get(
|
||||
`SELECT state FROM "${sessionId}" WHERE user = ?`,
|
||||
[username],
|
||||
(err, rows) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
res.status(500).send("DB-Fehler");
|
||||
return;
|
||||
}
|
||||
res.json(rows);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
//liste an user zurückgeben
|
||||
app.get("/api/user/:sessionId", (req, res) => {
|
||||
const { sessionId } = req.params;
|
||||
|
||||
16
game/game.js
16
game/game.js
@ -12,10 +12,20 @@ async function show_user() {
|
||||
const users = await res.json();
|
||||
const allUsers = users.map((u) => u.state);
|
||||
if (allUsers.every((v) => v === 0)) {
|
||||
console.log("test");
|
||||
async function createImposter() {
|
||||
const res = await fetch(`/api/${sessionId}/${username}/createImposter`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function createImposter() {
|
||||
const res = await fetch(`/api/${sessionId}/${username}/createImposter`);
|
||||
async function getImposter() {
|
||||
const res = await fetch(`/api/${sessionId}/${username}/getImposter`);
|
||||
const stateObj = await res.json();
|
||||
state = stateObj.state;
|
||||
|
||||
if (state == 1) {
|
||||
console.log("du bist imposter");
|
||||
} else {
|
||||
console.log("du bist kein imposter");
|
||||
}
|
||||
}
|
||||
|
||||
BIN
imposter.db
BIN
imposter.db
Binary file not shown.
Reference in New Issue
Block a user