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
17 lines
1.2 KiB
JavaScript
17 lines
1.2 KiB
JavaScript
'use strict';
|
|
/* POST /alliances/:id/role. Needs `setRole` (leader). Roles diplomat | officer | member; use transfer for leadership. */
|
|
const { GameError } = require('../errors');
|
|
const A = require('../alliances');
|
|
|
|
module.exports = function allianceRole(ctx, { userId, allianceId, operatorId, role }) {
|
|
const { db } = ctx;
|
|
const { op, alliance } = A.requireRole(db, userId, allianceId, 'setRole');
|
|
if (A.S.roles.indexOf(role) < 0 || role === 'leader') throw new GameError('validation_failed', { errors: [{ path: 'role', message: 'must be diplomat, officer or member' }] });
|
|
if (operatorId === op.id) throw new GameError('validation_failed', { errors: [{ path: 'operatorId', message: 'the leader cannot change their own role; transfer leadership' }] });
|
|
const t = A.membership(db, operatorId);
|
|
if (!t || t.alliance_id !== alliance.id) throw new GameError('not_found', { what: 'member' });
|
|
if (t.role === role) return { changed: false, role };
|
|
db.run('UPDATE alliance_members SET role = ? WHERE operator_id = ?', role, operatorId);
|
|
A.notifyOperator(ctx, operatorId, 'alliance_role', { allianceId: alliance.id, tag: alliance.tag, from: t.role, role });
|
|
return { changed: true, role };
|
|
};
|