Compare commits
5 Commits
Rechten
...
plaatsen-r
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e42966e618 | ||
|
|
e4976e51fa | ||
|
|
65070688ec | ||
|
|
e54c870f05 | ||
| f5aabafcc5 |
2
.env
2
.env
@@ -57,7 +57,7 @@ MERCURE_URL=http://mercure/.well-known/mercure
|
||||
# Public hub URL used by browsers
|
||||
MERCURE_PUBLIC_URL=http://localhost:8090/.well-known/mercure
|
||||
# Shared secret for signing JWTs (dev only). In prod, set via real env/secrets.
|
||||
MERCURE_JWT_SECRET=!ChangeThisMercureJWT!
|
||||
MERCURE_JWT_SECRET=!ChangeThisMercureJWTSignedBySymfonySecretKey!
|
||||
# Base URL for Mercure topics. Use .dev in development; override to .com in prod via .env.prod or real env.
|
||||
MERCURE_TOPIC_BASE=https://escapepage.dev
|
||||
###< mercure ###
|
||||
|
||||
@@ -4,7 +4,7 @@ import './styles/game1.css';
|
||||
let sequenceFinished = false;
|
||||
let stillPlayingSound = true;
|
||||
|
||||
function subscribeToMercure(mercurePublicUrl, topic) {
|
||||
function subscribeToMercure(mercurePublicUrl, topic, myScreen) {
|
||||
try {
|
||||
const url = mercurePublicUrl + '?topic=' + encodeURIComponent(topic);
|
||||
const es = new EventSource(url);
|
||||
@@ -16,6 +16,13 @@ function subscribeToMercure(mercurePublicUrl, topic) {
|
||||
|
||||
// data is [sendTo, message]
|
||||
if (Array.isArray(data) && data.length >= 2) {
|
||||
const sendTo = parseInt(data[0]);
|
||||
// Filter: 0 means everyone, otherwise must match myScreen
|
||||
if (sendTo !== 0 && sendTo !== parseInt(myScreen)) {
|
||||
console.log('[Mercure][game1] Message not for this player, skipping.');
|
||||
return;
|
||||
}
|
||||
|
||||
const messageContainer = document.getElementById('message-container');
|
||||
if (messageContainer) {
|
||||
const msgEl = document.createElement('div');
|
||||
@@ -24,6 +31,7 @@ function subscribeToMercure(mercurePublicUrl, topic) {
|
||||
msgEl.style.color = '#0F0'; // Green for incoming messages
|
||||
msgEl.style.marginBottom = '10px';
|
||||
messageContainer.appendChild(msgEl);
|
||||
window.scrollTo(0, document.body.scrollHeight);
|
||||
if(stillPlayingSound)
|
||||
playSound();
|
||||
console.log('[Mercure][game1] sequenceFinished status:', sequenceFinished);
|
||||
@@ -120,11 +128,12 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||
|
||||
const mercurePublicUrl = cfgEl.dataset.mercurePublicUrl;
|
||||
const topic = cfgEl.dataset.topic;
|
||||
const screen = cfgEl.dataset.screen;
|
||||
const apiPingUrl = cfgEl.dataset.apiPingUrl;
|
||||
const apiEchoUrl = cfgEl.dataset.apiEchoUrl;
|
||||
|
||||
if (mercurePublicUrl && topic) {
|
||||
subscribeToMercure(mercurePublicUrl, topic);
|
||||
subscribeToMercure(mercurePublicUrl, topic, screen);
|
||||
} else {
|
||||
console.warn('[Mercure][game1] Missing data attributes on #mercure-config');
|
||||
}
|
||||
@@ -181,6 +190,7 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||
msgEl.textContent = msg[0];
|
||||
msgEl.style.marginBottom = '10px';
|
||||
messageContainer.appendChild(msgEl);
|
||||
window.scrollTo(0, document.body.scrollHeight);
|
||||
|
||||
playSound();
|
||||
|
||||
@@ -203,6 +213,13 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||
stillPlayingSound = false;
|
||||
sequenceFinished = false;
|
||||
const message = inputField.value.trim();
|
||||
|
||||
const msgEl = document.createElement('div');
|
||||
msgEl.className = 'message';
|
||||
msgEl.textContent = message;
|
||||
msgEl.style.marginBottom = '10px';
|
||||
messageContainer.appendChild(msgEl);
|
||||
|
||||
if (message && apiEchoUrl) {
|
||||
inputField.value = '';
|
||||
try {
|
||||
@@ -211,6 +228,16 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||
body: { message, ts: new Date().toISOString() },
|
||||
});
|
||||
console.log('[API][game1] message sent →', response);
|
||||
if (response && response.result && Array.isArray(response.result.result)) {
|
||||
response.result.result.forEach(text => {
|
||||
const msgEl = document.createElement('div');
|
||||
msgEl.className = 'message';
|
||||
msgEl.textContent = text;
|
||||
msgEl.style.marginBottom = '10px';
|
||||
messageContainer.appendChild(msgEl);
|
||||
});
|
||||
window.scrollTo(0, document.body.scrollHeight);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[API][game1] Failed to send message:', err);
|
||||
}
|
||||
|
||||
@@ -29,8 +29,11 @@ body {
|
||||
|
||||
div#game-timer {
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
left: 20px;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
padding: 20px;
|
||||
background-color: #000;
|
||||
color: #F00;
|
||||
font-size: 28px;
|
||||
z-index: 100;
|
||||
@@ -38,7 +41,7 @@ div#game-timer {
|
||||
|
||||
div#message-container {
|
||||
padding: 20px;
|
||||
padding-top: 60px; /* Space for fixed timer */
|
||||
padding-top: 80px; /* Space for fixed timer */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: flex-end;
|
||||
@@ -49,6 +52,7 @@ div#message-container {
|
||||
|
||||
div.message {
|
||||
color: #C0C0C0;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
div#input {
|
||||
|
||||
@@ -7,11 +7,11 @@ services:
|
||||
environment:
|
||||
# Uncomment the following line to disable HTTPS,
|
||||
#SERVER_NAME: ':80'
|
||||
MERCURE_PUBLISHER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!'
|
||||
MERCURE_SUBSCRIBER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!'
|
||||
MERCURE_PUBLISHER_JWT_KEY: '!ChangeThisMercureJWTSignedBySymfonySecretKey!'
|
||||
MERCURE_SUBSCRIBER_JWT_KEY: '!ChangeThisMercureJWTSignedBySymfonySecretKey!'
|
||||
# Set the URL of your Symfony project (without trailing slash!) as value of the cors_origins directive
|
||||
MERCURE_EXTRA_DIRECTIVES: |
|
||||
cors_origins http://127.0.0.1:8000
|
||||
cors_origins http://localhost:8080
|
||||
# Comment the following line to disable the development mode
|
||||
command: /usr/bin/caddy run --config /etc/caddy/dev.Caddyfile
|
||||
healthcheck:
|
||||
|
||||
@@ -3,4 +3,6 @@ mercure:
|
||||
default:
|
||||
url: '%env(MERCURE_URL)%'
|
||||
public_url: '%env(MERCURE_PUBLIC_URL)%'
|
||||
jwt: '%env(MERCURE_JWT_SECRET)%'
|
||||
jwt:
|
||||
secret: '%env(MERCURE_JWT_SECRET)%'
|
||||
publish: ['*']
|
||||
|
||||
@@ -63,8 +63,8 @@ services:
|
||||
container_name: escapepage-mercure
|
||||
environment:
|
||||
SERVER_NAME: ":80"
|
||||
MERCURE_PUBLISHER_JWT_KEY: ${MERCURE_JWT_SECRET:-!ChangeThisMercureJWT!}
|
||||
MERCURE_SUBSCRIBER_JWT_KEY: ${MERCURE_JWT_SECRET:-!ChangeThisMercureJWT!}
|
||||
MERCURE_PUBLISHER_JWT_KEY: '!ChangeThisMercureJWTSignedBySymfonySecretKey!'
|
||||
MERCURE_SUBSCRIBER_JWT_KEY: '!ChangeThisMercureJWTSignedBySymfonySecretKey!'
|
||||
MERCURE_CORS_ALLOWED_ORIGINS: http://localhost:8080
|
||||
MERCURE_PUBLISH_ALLOWED_ORIGINS: http://localhost:8080
|
||||
MERCURE_EXTRA_DIRECTIVES: |
|
||||
|
||||
@@ -85,8 +85,18 @@ final class GameController extends AbstractController
|
||||
#[IsGranted(new Expression("is_granted('ROLE_PLAYER') or is_granted('ROLE_ADMIN')"))]
|
||||
#[IsGranted('SESSION_VIEW', subject: 'session')]
|
||||
public function index(
|
||||
Session $session): Response
|
||||
Session $session,
|
||||
Security $security,
|
||||
\App\Game\Repository\PlayerRepository $playerRepository
|
||||
): Response
|
||||
{
|
||||
return $this->render('game/index.html.twig', ['session' => $session]);
|
||||
$user = $security->getUser();
|
||||
$player = $playerRepository->findOneBy(['session' => $session, 'user' => $user]);
|
||||
$screen = $player ? $player->getScreen() : 0;
|
||||
|
||||
return $this->render('game/index.html.twig', [
|
||||
'session' => $session,
|
||||
'screen' => $screen,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,4 +21,5 @@ enum SessionSettingType: string
|
||||
case VERIFICATION_PROGRESS_FOR_PLAYER1 = 'VerificationProgressForPlayer1';
|
||||
case VERIFICATION_PROGRESS_FOR_PLAYER2 = 'VerificationProgressForPlayer2';
|
||||
case VERIFICATION_PROGRESS_FOR_PLAYER3 = 'VerificationProgressForPlayer3';
|
||||
case EVERYONE_VERIFIED = 'EveryoneVerified';
|
||||
}
|
||||
|
||||
@@ -189,6 +189,7 @@ class GameResponseService
|
||||
$messages[] = ' If you want to send a message specifically to one other agent, use the id of the agent after /chat, like /chat 6 {message}';
|
||||
$messages[] = ' This will send the message only to agent with id 6.';
|
||||
$messages[] = ' USAGE: /chat {message}';
|
||||
$messages[] = ' USAGE: /chat 6 {message}';
|
||||
$messages[] = '';
|
||||
break;
|
||||
case 'help':
|
||||
@@ -584,6 +585,52 @@ class GameResponseService
|
||||
$setting->setValue(json_encode($rights));
|
||||
$this->entityManager->persist($setting);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->checkIfAllPlayersVerified($player);
|
||||
}
|
||||
}
|
||||
|
||||
private function checkIfAllPlayersVerified(Player $player): void
|
||||
{
|
||||
$session = $player->getSession();
|
||||
$everyoneVerifiedSetting = $this->sessionSettingRepository->getSetting($session, SessionSettingType::EVERYONE_VERIFIED, $player);
|
||||
|
||||
if ($everyoneVerifiedSetting && $everyoneVerifiedSetting->getValue() === 'true') {
|
||||
return;
|
||||
}
|
||||
|
||||
$allVerified = true;
|
||||
foreach ([1, 2, 3] as $screen) {
|
||||
$progressSettingName = match ($screen) {
|
||||
1 => SessionSettingType::VERIFICATION_PROGRESS_FOR_PLAYER1,
|
||||
2 => SessionSettingType::VERIFICATION_PROGRESS_FOR_PLAYER2,
|
||||
3 => SessionSettingType::VERIFICATION_PROGRESS_FOR_PLAYER3,
|
||||
default => null,
|
||||
};
|
||||
|
||||
$progressSetting = $this->sessionSettingRepository->getSetting($session, $progressSettingName, $player);
|
||||
$progress = json_decode($progressSetting?->getValue() ?? '[]', true) ?? [];
|
||||
|
||||
if (count($progress) < 2) {
|
||||
$allVerified = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($allVerified) {
|
||||
if (!$everyoneVerifiedSetting) {
|
||||
$everyoneVerifiedSetting = new SessionSetting();
|
||||
$everyoneVerifiedSetting->setSession($session);
|
||||
$everyoneVerifiedSetting->setPlayer($player);
|
||||
$everyoneVerifiedSetting->setName(SessionSettingType::EVERYONE_VERIFIED);
|
||||
}
|
||||
$everyoneVerifiedSetting->setValue('true');
|
||||
$this->entityManager->persist($everyoneVerifiedSetting);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$topic = $_ENV['MERCURE_TOPIC_BASE'] . '/game/hub-' . $session->getId();
|
||||
$message = "Mainframe Help Modus: Agents Doyle, Vega and Lennox rapports have been updated with coded messages.";
|
||||
$this->hub->publish(new Update($topic, json_encode([0, $message])));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
data-topic="{{ (mercure_topic_base ~ '/game/hub-' ~ session.id)|e('html_attr') }}"
|
||||
data-api-ping-url="{{ path('game_api_ping')|e('html_attr') }}"
|
||||
data-api-echo-url="{{ path('game_api_message')|e('html_attr') }}"
|
||||
data-screen="{{ screen|e('html_attr') }}"
|
||||
style="display:none">
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user