Relaunch: Navy/Weiß-Design, Landingpage, Regeln, Chat-Overlay (Baseline)
Sichert den bisherigen Relaunch-Stand vor dem Gameplay/Community-Update: - Neues helles Design auf allen Seiten (Landing, Spiel, Login, Profil, Admin, Setup) - index.html = Landingpage, play.html = Spiel, regeln/datenschutz/impressum - Chat-Overlay mit Emoji + Giphy-GIF, Lobby Teilnehmen/Starten, App-Shell Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
188e8e52a2
commit
cb3e15ef85
21 changed files with 2596 additions and 1586 deletions
60
api.php
60
api.php
|
|
@ -41,12 +41,12 @@ function playerKey(string $name): string
|
|||
return substr(preg_replace('/[^a-z0-9]/', '_', strtolower($name)) ?? '', 0, 40);
|
||||
}
|
||||
|
||||
function loadRoom(PDO $pdo, string $code): ?array
|
||||
function loadRoom(PDO $pdo, string $code, bool $revealLiars = false): ?array
|
||||
{
|
||||
$stmt = $pdo->prepare(
|
||||
'SELECT code, revealed, liar_keys, normal_question, imposter_question,
|
||||
round_num, voted_out_keys, round_outcome, voting_open, active_emojis,
|
||||
reveal_index, revealed_keys, imposter_weights
|
||||
reveal_index, revealed_keys, imposter_weights, questions_revealed
|
||||
FROM gtl_rooms WHERE code = ?'
|
||||
);
|
||||
$stmt->execute([$code]);
|
||||
|
|
@ -58,7 +58,7 @@ function loadRoom(PDO $pdo, string $code): ?array
|
|||
|
||||
$ps = $pdo->prepare(
|
||||
'SELECT p.pkey, p.name, p.user_id, p.question, p.answer, p.answered, p.score,
|
||||
p.vote_for, p.vote_locked, p.vote_request, u.avatar
|
||||
p.vote_for, p.vote_locked, p.vote_request, u.avatar, u.color
|
||||
FROM gtl_players p
|
||||
LEFT JOIN gtl_users u ON u.id = p.user_id
|
||||
WHERE p.room_code = ? ORDER BY p.id ASC'
|
||||
|
|
@ -82,6 +82,7 @@ function loadRoom(PDO $pdo, string $code): ?array
|
|||
'name' => $row['name'],
|
||||
'userId' => $row['user_id'] ? (int) $row['user_id'] : null,
|
||||
'avatar' => $row['avatar'] ?? null,
|
||||
'color' => $row['color'] ?? null,
|
||||
'question' => $row['question'] ?? '',
|
||||
'answer' => $row['answer'] ?? '',
|
||||
'answered' => (bool) $row['answered'],
|
||||
|
|
@ -97,8 +98,9 @@ function loadRoom(PDO $pdo, string $code): ?array
|
|||
return [
|
||||
'code' => $room['code'],
|
||||
'revealed' => (bool) $room['revealed'],
|
||||
// liarKeys only sent after resolution — prevents clients from seeing imposters early
|
||||
'liarKeys' => $outcome ? $j($room['liar_keys']) : [],
|
||||
// liarKeys only sent after resolution — prevents clients from seeing imposters early.
|
||||
// Admin spectators ($revealLiars) get them immediately to mirror the host view.
|
||||
'liarKeys' => ($outcome || $revealLiars) ? $j($room['liar_keys']) : [],
|
||||
'normalQuestion' => $room['normal_question'] ?? '',
|
||||
'imposterQuestion' => $room['imposter_question'] ?? '',
|
||||
'roundNum' => (int) $room['round_num'],
|
||||
|
|
@ -107,6 +109,7 @@ function loadRoom(PDO $pdo, string $code): ?array
|
|||
'votingOpen' => (bool) ($room['voting_open'] ?? false),
|
||||
'revealIndex' => (int) ($room['reveal_index'] ?? -1),
|
||||
'revealedKeys' => $j($room['revealed_keys'] ?? ''),
|
||||
'questionsRevealed'=> (bool) ($room['questions_revealed'] ?? false),
|
||||
'imposterWeights' => $room['imposter_weights'] ?? null,
|
||||
'activeEmojis' => array_values(array_filter(
|
||||
$j($room['active_emojis'] ?? '[]'),
|
||||
|
|
@ -408,13 +411,31 @@ try {
|
|||
respond(['ok' => true, 'pkey' => $pkey, 'state' => loadRoom($pdo, $code)]);
|
||||
break;
|
||||
|
||||
case 'admin_spectate':
|
||||
if (!$authUserId) respond(['error' => 'Bitte erst einloggen.'], 401);
|
||||
$roleStmt = $pdo->prepare('SELECT role FROM gtl_users WHERE id = ?');
|
||||
$roleStmt->execute([$authUserId]);
|
||||
if ($roleStmt->fetchColumn() !== 'admin') respond(['error' => 'Keine Berechtigung.'], 403);
|
||||
|
||||
$body = input();
|
||||
$code = slugCode((string) ($body['code'] ?? ''));
|
||||
if ($code === '') respond(['error' => 'Raum-Code erforderlich.'], 400);
|
||||
$state = loadRoom($pdo, $code, true);
|
||||
if ($state === null) respond(['error' => 'Raum nicht gefunden.'], 404);
|
||||
// Remember this admin is spectating this room → state polls keep revealing imposters
|
||||
$_SESSION['spectate'][$code] = true;
|
||||
respond(['ok' => true, 'state' => $state]);
|
||||
break;
|
||||
|
||||
case 'state':
|
||||
$code = slugCode((string) ($_GET['code'] ?? ''));
|
||||
// Update activity timestamp so room stays alive while anyone polls
|
||||
$pdo->prepare('UPDATE gtl_rooms SET updated_at=? WHERE code=?')->execute([$now, $code]);
|
||||
// Lazy cleanup: delete rooms inactive for 12+ hours
|
||||
$pdo->exec('DELETE FROM gtl_rooms WHERE updated_at < ' . ($now - 43200));
|
||||
$state = loadRoom($pdo, $code);
|
||||
// Admin spectators keep seeing imposters while polling (flag set via admin_spectate)
|
||||
$spectating = !empty($_SESSION['spectate'][$code]);
|
||||
$state = loadRoom($pdo, $code, $spectating);
|
||||
if ($state === null) respond(['error' => 'Raum nicht gefunden.'], 404);
|
||||
respond(['ok' => true, 'state' => $state]);
|
||||
break;
|
||||
|
|
@ -458,7 +479,7 @@ try {
|
|||
'UPDATE gtl_rooms
|
||||
SET normal_question=?, imposter_question=?, liar_keys=?,
|
||||
voted_out_keys=NULL, round_outcome=NULL, voting_open=0,
|
||||
reveal_index=-1, revealed_keys=NULL, updated_at=?
|
||||
reveal_index=-1, revealed_keys=NULL, questions_revealed=0, updated_at=?
|
||||
WHERE code=?'
|
||||
)->execute([$normalQ, $imposterQ, json_encode($imposterKeys), $now, $code]);
|
||||
|
||||
|
|
@ -536,6 +557,15 @@ try {
|
|||
respond(['ok' => true, 'state' => loadRoom($pdo, $code)]);
|
||||
break;
|
||||
|
||||
case 'reveal_questions':
|
||||
// Leiter deckt die echte Frage für die Imposter auf (Knopfdruck)
|
||||
$body = input();
|
||||
$code = slugCode((string) ($body['code'] ?? ''));
|
||||
$pdo->prepare('UPDATE gtl_rooms SET questions_revealed=1, updated_at=? WHERE code=?')
|
||||
->execute([$now, $code]);
|
||||
respond(['ok' => true, 'state' => loadRoom($pdo, $code)]);
|
||||
break;
|
||||
|
||||
case 'reveal_next':
|
||||
// Legacy: Nächste Antwort sequenziell aufdecken (fallback)
|
||||
$body = input();
|
||||
|
|
@ -583,6 +613,20 @@ try {
|
|||
$body = input();
|
||||
$code = slugCode((string) ($body['code'] ?? ''));
|
||||
$pkey = (string) ($body['pkey'] ?? '');
|
||||
|
||||
// Antrag nur erlauben, wenn alle Antworten aufgedeckt sind
|
||||
$rvStmt = $pdo->prepare('SELECT reveal_index, revealed_keys FROM gtl_rooms WHERE code=?');
|
||||
$rvStmt->execute([$code]);
|
||||
$rvRoom = $rvStmt->fetch();
|
||||
if (!$rvRoom) respond(['error' => 'Raum nicht gefunden.'], 404);
|
||||
$playerCount = (int) $pdo->query('SELECT COUNT(*) FROM gtl_players WHERE room_code=' . $pdo->quote($code))->fetchColumn();
|
||||
$revealedKeys = (!empty($rvRoom['revealed_keys'])) ? (json_decode($rvRoom['revealed_keys'], true) ?: []) : [];
|
||||
$allRevealed = $playerCount > 0
|
||||
&& ((int) ($rvRoom['reveal_index'] ?? -1) >= 9999 || count($revealedKeys) >= $playerCount);
|
||||
if (!$allRevealed) {
|
||||
respond(['error' => 'Erst müssen alle Antworten aufgedeckt werden.'], 409);
|
||||
}
|
||||
|
||||
$pdo->prepare('UPDATE gtl_players SET vote_request=1, updated_at=? WHERE room_code=? AND pkey=?')
|
||||
->execute([$now, $code, $pkey]);
|
||||
$pdo->prepare('UPDATE gtl_rooms SET updated_at=? WHERE code=?')->execute([$now, $code]);
|
||||
|
|
@ -720,7 +764,7 @@ try {
|
|||
'UPDATE gtl_rooms
|
||||
SET revealed=0, liar_keys=NULL, voted_out_keys=NULL, round_outcome=NULL,
|
||||
normal_question=NULL, imposter_question=NULL, voting_open=0,
|
||||
reveal_index=-1, revealed_keys=NULL, active_emojis=NULL,
|
||||
reveal_index=-1, revealed_keys=NULL, questions_revealed=0, active_emojis=NULL,
|
||||
round_num=round_num+1, updated_at=?
|
||||
WHERE code=?'
|
||||
)->execute([$now, $code]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue