Phase 2: client military/social screens, WebSocket push, trade + endgame, review findings pending
Built: units/movements/reports/send/expansion screens, alliance/messages/rankings screens, ws client + server /ws push (docs/PROTOCOL.md), Internet exchange trade, backbone endgame + world end, shared reports, buildDone relative levels. Tested: npm test 175/175. Two adversarial reviews found issues (trade-leg recall exploit, __proto__ via validate.js, rankings DoS, static headers, ...): fixes follow in the next commit. NOT done: bots/balance, e2e suite, real-device checks. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
This commit is contained in:
parent
249818a7aa
commit
b18645dca1
87 changed files with 10201 additions and 71 deletions
|
|
@ -22,6 +22,8 @@ const routes = require('./routes');
|
|||
const eventHandlers = require('./events');
|
||||
const { createStaticHandler, applySecurityHeaders } = require('./static');
|
||||
const { parseTrustProxy, parseTrustedProxies, listenDual, listUrls } = require('./net');
|
||||
const { createPush } = require('./push');
|
||||
const { bindGame, pushDeps } = require('./pushHooks');
|
||||
|
||||
function defaultLog(msg) { console.log(new Date().toISOString() + ' ' + msg); }
|
||||
|
||||
|
|
@ -55,6 +57,11 @@ async function createServer(userOpts) {
|
|||
routes.register(api.router, services);
|
||||
api.services = services;
|
||||
|
||||
// WebSocket push on /ws (docs/PROTOCOL.md): hints only, the REST API stays the source of truth and works without it
|
||||
const push = createPush(Object.assign({ clock, authenticate: auth.authenticate, opts: o, log }, pushDeps(db)));
|
||||
bindGame({ push, db, scheduler, commands });
|
||||
services.push = push;
|
||||
|
||||
const serveStatic = createStaticHandler(o.publicDir);
|
||||
const server = http.createServer((req, res) => {
|
||||
const url = req.url || '/';
|
||||
|
|
@ -66,6 +73,7 @@ async function createServer(userOpts) {
|
|||
if (url.startsWith('/api/')) return api.handle(req, res);
|
||||
return serveStatic(req, res).catch((err) => { log('static error: ' + (err && err.message)); if (!res.headersSent) res.writeHead(500); res.end(); });
|
||||
});
|
||||
server.on('upgrade', push.onUpgrade);
|
||||
server.headersTimeout = 20000; server.requestTimeout = 30000; server.keepAliveTimeout = 5000;
|
||||
const sockets = new Set();
|
||||
server.on('connection', (s) => { sockets.add(s); s.on('close', () => sockets.delete(s)); });
|
||||
|
|
@ -81,6 +89,7 @@ async function createServer(userOpts) {
|
|||
if (closePromise) return closePromise;
|
||||
closePromise = (async () => {
|
||||
scheduler.stop(); clearInterval(idemTimer);
|
||||
await push.close(); // 1001 to every socket, so server.close() below is not held up
|
||||
await new Promise((r) => { server.close(() => r()); if (server.closeIdleConnections) server.closeIdleConnections(); setTimeout(() => { for (const s of sockets) s.destroy(); }, 1000).unref(); });
|
||||
db.close();
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue