From 45eef9ef5c9bdd366d138db0d25e53185b909527 Mon Sep 17 00:00:00 2001 From: Frederik Spirgi Date: Wed, 9 Sep 2026 11:02:31 +0200 Subject: [PATCH] try to fix this spaghetti of a code --- gambling.js | 5 +++-- lib/lobbies.js | 2 +- public/client.js | 4 ++-- public/frontend_poker.js | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/gambling.js b/gambling.js index dbd41f4..d65444c 100644 --- a/gambling.js +++ b/gambling.js @@ -1,4 +1,4 @@ -const http = require('node:http'); +const http = require('node:http'); const {configuration} = require('./lib/config'); const {createRepository} = require('./lib/repository'); const {createSessionService} = require('./lib/sessions'); @@ -33,7 +33,8 @@ async function createApplication(options = {}) { if (require.main === module) { require('dotenv').config(); createApplication().then(async application => { - const address = await application.listen(); + let address; + try {address = await application.listen();} catch (error) {await application.close(); throw error;} console.log(`Server listening at http://${address.address}:${address.port}`); for (const signal of ['SIGINT', 'SIGTERM']) process.once(signal, () => application.close().catch(error => {console.error(error); process.exitCode = 1;})); }).catch(error => {console.error(error.message); process.exitCode = 1;}); diff --git a/lib/lobbies.js b/lib/lobbies.js index 4e50c52..f4e49fa 100644 --- a/lib/lobbies.js +++ b/lib/lobbies.js @@ -37,7 +37,7 @@ function createLobbyService(repository, config) { const membershipMutation = ['lobby:create', 'lobby:join', 'lobby:leave'].includes(message.type); return queue.run([...(membershipMutation ? ['membership'] : []), ...(username ? [`account:${username}`] : []), ...(message.lobbyId ? [`lobby:${message.lobbyId}`] : [])], async () => { - const id = `${username || 'system'}:${message.requestId}`; + const id = `${username ? `user:${username}` : 'system'}:${message.requestId}`; const fingerprint = hash(JSON.stringify(canonical(message))); const prior = await repository.command(id); if (prior) { diff --git a/public/client.js b/public/client.js index 6133001..00f75c3 100644 --- a/public/client.js +++ b/public/client.js @@ -45,11 +45,11 @@ window.RealtimeClient = class extends EventTarget { } this.dispatchEvent(new CustomEvent('message', {detail: message})); }); - socket.addEventListener('error', () => this.status('Connection interrupted. Reconnecting…')); + socket.addEventListener('error', () => this.status('Connection interrupted. Reconnecting...')); socket.addEventListener('close', async event => { clearTimeout(timeout); this.ready = false; if (this.stopped) return; - this.status('Connection interrupted. Reconnecting…'); + this.status('Connection interrupted. Reconnecting...'); if (event.code === 1008 && /Session/.test(event.reason)) { this.close(); localStorage.removeItem('activeLobbyId'); location.assign('/login'); return; } diff --git a/public/frontend_poker.js b/public/frontend_poker.js index d29c69d..46989a6 100644 --- a/public/frontend_poker.js +++ b/public/frontend_poker.js @@ -101,7 +101,7 @@ document.addEventListener("DOMContentLoaded", () => { if (winner) { const heading = document.createElement("h2"); - heading.textContent = `Winner: ${winner}`; + heading.textContent = `Payout recipients: ${winner}`; showdownPanel.appendChild(heading); }