1
mirror of https://github.com/thepeacockproject/Peacock synced 2024-11-22 22:12:45 +01:00

Added fallback for loadSession in case someone might have disconnected. (#191)

This commit is contained in:
Lennard Fonteijn 2023-04-06 22:46:28 +02:00 committed by GitHub
parent 21b3663c50
commit b8a68820d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -829,8 +829,21 @@ async function loadSession(
sessionData?: ContractSession, sessionData?: ContractSession,
): Promise<void> { ): Promise<void> {
if (!sessionData) { if (!sessionData) {
try {
//First, try the loading the session from the filesystem.
sessionData = await getContractSession(token + "_" + sessionId) 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 // Update challenge progression with the user's latest progression data
for (const cid in sessionData.challengeContexts) { for (const cid in sessionData.challengeContexts) {
// Make sure the ChallengeProgression is available, otherwise loading might fail! // Make sure the ChallengeProgression is available, otherwise loading might fail!