Remove expired rejoin sessions
This commit is contained in:
@@ -17,7 +17,9 @@ export async function apiRequest(endpoint, method = 'GET', data = null) {
|
||||
if (errBody.error) msg = errBody.error;
|
||||
else if (errBody.detail) msg = errBody.detail;
|
||||
} catch(e) {}
|
||||
throw new Error(msg);
|
||||
const error = new Error(msg);
|
||||
error.status = res.status;
|
||||
throw error;
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
@@ -6,10 +6,17 @@
|
||||
// - Add a CHANGELOG entry only when a commit changes something players can
|
||||
// see. Skip refactors, tests, and tooling. Keep wording player-facing.
|
||||
|
||||
export const VERSION = 17;
|
||||
export const VERSION = 18;
|
||||
|
||||
// Newest first. Each entry: { version, date: 'YYYY-MM-DD', changes: [string, ...] }.
|
||||
export const CHANGELOG = [
|
||||
{
|
||||
version: 18,
|
||||
date: '2026-07-10',
|
||||
changes: [
|
||||
'Expired rejoin entries are now removed automatically when a game has ended or a player is no longer in the crew, with a clear explanation.',
|
||||
],
|
||||
},
|
||||
{
|
||||
version: 17,
|
||||
date: '2026-07-10',
|
||||
|
||||
@@ -31,14 +31,35 @@
|
||||
let reconnectTimer = null;
|
||||
let reconnectDelay = 1000;
|
||||
let destroyed = false;
|
||||
let staleSession = false;
|
||||
|
||||
function discardStaleSession(message) {
|
||||
staleSession = true;
|
||||
removeSession(gameId, playerId);
|
||||
state = null;
|
||||
error = message;
|
||||
if (reconnectTimer) clearTimeout(reconnectTimer);
|
||||
if (ws) ws.close();
|
||||
}
|
||||
|
||||
async function fetchState() {
|
||||
if (staleSession) return;
|
||||
try {
|
||||
const data = await apiRequest(`/game/${gameId}/player/${playerId}/state`);
|
||||
// Preserve the Game Over screen for players who were already present
|
||||
// when play ended, but discard stale home-screen rejoin attempts.
|
||||
if (!state && data.game.phase === 'ended') {
|
||||
discardStaleSession('This game has ended and can no longer be rejoined.');
|
||||
return;
|
||||
}
|
||||
state = data;
|
||||
error = '';
|
||||
} catch (err) {
|
||||
error = err.message;
|
||||
if (!state && err.status === 404) {
|
||||
discardStaleSession('This saved game can no longer be rejoined. You may have been removed from the crew.');
|
||||
} else {
|
||||
error = err.message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +74,7 @@
|
||||
};
|
||||
ws.onmessage = () => fetchState();
|
||||
ws.onclose = () => {
|
||||
if (destroyed) return;
|
||||
if (destroyed || staleSession) return;
|
||||
reconnectTimer = setTimeout(connectSocket, reconnectDelay);
|
||||
reconnectDelay = Math.min(reconnectDelay * 2, 10000);
|
||||
};
|
||||
@@ -188,6 +209,11 @@
|
||||
{#if error}
|
||||
<div class="alert alert-danger" style="margin: 20px;">
|
||||
Error connecting to game: {error}
|
||||
{#if staleSession}
|
||||
<div class="mt-4">
|
||||
<a href="#/" class="btn btn-secondary btn-small">Back to Home</a>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user