Route every Mercure publish through an event, log pushes per-player
Every $hub->publish() call site (chat, hints, security alerts, virus alerts, game_finished, and the pre-game lobby events) now dispatches a PushMercureMessageEvent instead of publishing directly. Two listeners handle it: PublishMercureMessageListener does the actual Mercure publish exactly as before (same wire format, no client changes needed), and LogMercureMessageListener appends it to the activity log of whichever player(s) it was actually delivered to. A private /chat to one agent only gets logged for that agent, never broadcast into everyone's transcript - the event carries an explicit targetScreen (null = everyone) rather than leaving listeners to guess from the payload shape. The per-player log format moved from flat text to JSON Lines (one timestamped, structured entry per line) via a new shared SessionActivityLogger service, since a flat string can't carry an event's type or exact payload - both needed for a future feature to replay a player's full session history, not just their own commands, on page reload. The admin session log viewer now parses and formats these entries back into readable lines. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,14 +11,14 @@ use App\Game\Entity\SessionSetting;
|
||||
use App\Game\Enum\GameStatus;
|
||||
use App\Game\Enum\SessionSettingType;
|
||||
use App\Game\Enum\SessionStatus;
|
||||
use App\Game\Event\PushMercureMessageEvent;
|
||||
use App\Game\Repository\GameRepository;
|
||||
use App\Game\Repository\LobbyMessageRepository;
|
||||
use App\Game\Repository\SessionRepository;
|
||||
use App\Tech\Entity\User;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Symfony\Component\Mercure\HubInterface;
|
||||
use Symfony\Component\Mercure\Update;
|
||||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
final class GameDashboardService
|
||||
{
|
||||
@@ -31,7 +31,7 @@ final class GameDashboardService
|
||||
private readonly SessionRepository $sessionRepository,
|
||||
private readonly LobbyMessageRepository $lobbyMessageRepository,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly HubInterface $hub,
|
||||
private readonly EventDispatcherInterface $eventDispatcher,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -480,12 +480,11 @@ final class GameDashboardService
|
||||
|
||||
private function publishLobbyEvent(Session $session, string $type, array $extra = []): void
|
||||
{
|
||||
try {
|
||||
$topic = '/game/hub/' . $session->getId();
|
||||
$this->hub->publish(new Update($topic, json_encode(array_merge(['type' => $type], $extra))));
|
||||
} catch (\Exception $e) {
|
||||
// Mercure might be down, but we don't want to crash the game
|
||||
}
|
||||
$this->eventDispatcher->dispatch(new PushMercureMessageEvent(
|
||||
$session,
|
||||
array_merge(['type' => $type], $extra),
|
||||
$type,
|
||||
));
|
||||
}
|
||||
|
||||
public function checkAllPlayersReady(Session $session): void
|
||||
@@ -559,12 +558,7 @@ final class GameDashboardService
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
try {
|
||||
$topic = '/game/hub/' . $session->getId();
|
||||
$this->hub->publish(new Update($topic, json_encode(['type' => 'all_ready'])));
|
||||
} catch (\Exception $e) {
|
||||
// Mercure might be down, but we don't want to crash the game
|
||||
}
|
||||
$this->eventDispatcher->dispatch(new PushMercureMessageEvent($session, ['type' => 'all_ready'], 'all_ready'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user