From 826f54183578a75b0df5bd40c26d4edc73d44888 Mon Sep 17 00:00:00 2001 From: Lennard Fonteijn Date: Wed, 5 Apr 2023 00:57:45 +0200 Subject: [PATCH] Added fallback for loadSession in case someone might have disconnected. --- components/profileHandler.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/components/profileHandler.ts b/components/profileHandler.ts index 6cf4b40e..3ab92c09 100644 --- a/components/profileHandler.ts +++ b/components/profileHandler.ts @@ -829,8 +829,21 @@ async function loadSession( sessionData?: ContractSession, ): Promise { if (!sessionData) { - sessionData = await getContractSession(token + "_" + sessionId) + try { + //First, try the loading the session from the filesystem. + sessionData = await getContractSession(token + "_" + sessionId) + } catch (e) { + //Otherwise, see if we still have this session in memory. + //This may be the currently active session, but we need a fallback of some sorts in case a player disconnected. + if (contractSessions.has(sessionId)) { + sessionData = contractSessions.get(sessionId) + } else { + //Rethrow the error + throw e + } + } } + // Update challenge progression with the user's latest progression data for (const cid in sessionData.challengeContexts) { // Make sure the ChallengeProgression is available, otherwise loading might fail!