Built: units/research/training, movements (scan, raid, attack, takeover, reinforce, settle, transport), deterministic combat resolved in the event queue, reports, power/offline units, founding + conquest + incumbent sites; alliances, roles, diplomacy (24h pact cancel via events), messages, rankings; vanilla-JS phone-first client (auth, POP, map, alerts, settings, en/nb); systemd units, backup timer, DEPLOY.md, tools/admin.js. Tested: npm test 96/96 (fake clock, in-memory db, a few real-HTTP tests); client checked with headless Chromium screenshots only. NOT done: marketplace/transport trade, client screens for military/social, WebSocket push, bots/balance, e2e suite. All unit stats and costs are unbalanced first guesses. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
31 lines
1.7 KiB
JavaScript
31 lines
1.7 KiB
JavaScript
'use strict';
|
|
/* POST /messages/blocks { operatorId } and DELETE /messages/blocks/:operatorId. Blocked senders' messages are not
|
|
* delivered (the sender is not told). Both idempotent. Registered as messageBlock and messageUnblock. */
|
|
const { GameError } = require('../errors');
|
|
const A = require('../alliances');
|
|
|
|
function resolve(db, userId, operatorId) {
|
|
const target = db.get('SELECT * FROM operators WHERE id = ?', operatorId);
|
|
if (!target) throw new GameError('not_found', { what: 'operator' });
|
|
const me = db.get('SELECT * FROM operators WHERE user_id = ? AND world_id = ?', userId, target.world_id);
|
|
if (!me) throw new GameError('not_found', { what: 'operator' });
|
|
if (me.id === target.id) throw new GameError('validation_failed', { errors: [{ path: 'operatorId', message: 'you cannot block yourself' }] });
|
|
return { me, target };
|
|
}
|
|
|
|
function messageBlock(ctx, { userId, operatorId }) {
|
|
const { db, now } = ctx;
|
|
const { me, target } = resolve(db, userId, operatorId);
|
|
if (db.get('SELECT 1 AS x FROM message_blocks WHERE operator_id = ? AND blocked_id = ?', me.id, target.id)) return { changed: false };
|
|
if (db.get('SELECT COUNT(*) AS n FROM message_blocks WHERE operator_id = ?', me.id).n >= A.S.maxBlocks) throw new GameError('conflict', { what: 'block list full', max: A.S.maxBlocks });
|
|
db.run('INSERT INTO message_blocks (operator_id, blocked_id, created_at) VALUES (?, ?, ?)', me.id, target.id, now);
|
|
return { changed: true };
|
|
}
|
|
|
|
function messageUnblock(ctx, { userId, operatorId }) {
|
|
const { db } = ctx;
|
|
const { me, target } = resolve(db, userId, operatorId);
|
|
return { changed: db.run('DELETE FROM message_blocks WHERE operator_id = ? AND blocked_id = ?', me.id, target.id).changes > 0 };
|
|
}
|
|
|
|
module.exports = { messageBlock, messageUnblock };
|