Auto-trigger locked-files restoration exactly at the 60s deadline
Previously the restore check only ran lazily on a player's next message, so files could stay wrongly-removed for an arbitrary amount of time after the window expired. The frontend now schedules a setTimeout (using the server-provided deadline, mirroring the terminal lock's reveal timer) that pings the backend right at the deadline so the check runs promptly regardless of player activity. Restored via data-files-removal-deadline on page load too, so a refresh mid-window doesn't lose the timer.
This commit is contained in:
@@ -160,12 +160,14 @@ final class GameController extends AbstractController
|
||||
$screen = $player ? $player->getScreen() : 0;
|
||||
$session_id = $session->getId();
|
||||
$lock = $player ? $gameResponseService->getPublicLockState($player) : null;
|
||||
$filesRemovalDeadline = $gameResponseService->getPublicLockedFilesDeadline($session);
|
||||
|
||||
return $this->render('game/index.html.twig', [
|
||||
'session' => $session,
|
||||
'screen' => $screen,
|
||||
'session_id' => $session_id,
|
||||
'lock' => $lock,
|
||||
'filesRemovalDeadline' => $filesRemovalDeadline,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -230,7 +230,7 @@ class GameResponseService
|
||||
return ['result' => ['You are not allowed to remove this file.']];
|
||||
|
||||
$this->playerService->addDeletedFileToSession($player, $fullPath);
|
||||
$this->startLockedFilesRemovalDeadline($player->getSession(), $fullPath);
|
||||
$filesRemovalDeadline = $this->startLockedFilesRemovalDeadline($player->getSession(), $fullPath);
|
||||
$lock = $this->triggerLock($player);
|
||||
|
||||
return [
|
||||
@@ -243,6 +243,7 @@ class GameResponseService
|
||||
'lockedAt' => $lock['lockedAt'],
|
||||
'revealAt' => $lock['revealAt'],
|
||||
'unlockAt' => $lock['unlockAt'],
|
||||
'filesRemovalDeadline' => $filesRemovalDeadline,
|
||||
];
|
||||
case 'sudo':
|
||||
if(!in_array('sudo', $rechten))
|
||||
@@ -1031,17 +1032,19 @@ class GameResponseService
|
||||
|
||||
/**
|
||||
* Starts (if not already running) the 60-second window within which all locked files
|
||||
* must be removed, or the ones already removed get restored by the virus.
|
||||
* must be removed, or the ones already removed get restored by the virus. Returns the
|
||||
* (new or already-running) deadline as a unix timestamp, or null if the removed file
|
||||
* wasn't a locked one.
|
||||
*/
|
||||
private function startLockedFilesRemovalDeadline(Session $session, string $removedFile): void
|
||||
private function startLockedFilesRemovalDeadline(Session $session, string $removedFile): ?int
|
||||
{
|
||||
if (!in_array($removedFile, $this->getLockedFiles())) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
$setting = $this->sessionSettingRepository->getSetting($session, SessionSettingType::LOCKED_FILES_REMOVAL_DEADLINE);
|
||||
if ($setting && $setting->getValue()) {
|
||||
return; // Window already running
|
||||
return (int)$setting->getValue(); // Window already running
|
||||
}
|
||||
|
||||
if (!$setting) {
|
||||
@@ -1050,9 +1053,28 @@ class GameResponseService
|
||||
$setting->setName(SessionSettingType::LOCKED_FILES_REMOVAL_DEADLINE);
|
||||
}
|
||||
|
||||
$setting->setValue((string)(time() + 60));
|
||||
$deadline = time() + 60;
|
||||
$setting->setValue((string)$deadline);
|
||||
$this->entityManager->persist($setting);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $deadline;
|
||||
}
|
||||
|
||||
/**
|
||||
* Public, session-wide view of the active locked-files removal deadline (if any), safe
|
||||
* to expose on page load so the UI can schedule its auto-check timer after a refresh.
|
||||
*/
|
||||
public function getPublicLockedFilesDeadline(Session $session): ?int
|
||||
{
|
||||
$setting = $this->sessionSettingRepository->getSetting($session, SessionSettingType::LOCKED_FILES_REMOVAL_DEADLINE);
|
||||
if (!$setting || !$setting->getValue()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$deadline = (int)$setting->getValue();
|
||||
|
||||
return $deadline > time() ? $deadline : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user