Upstream/server/commands/allianceKick.js
jvanvik 249818a7aa Stage 3-5 server (military, expansion, social), web client for stages 1-2, ops/deploy
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
2026-10-11 18:32:36 +02:00

19 lines
1.2 KiB
JavaScript

'use strict';
/* POST /alliances/:id/kick. Needs `kick` and the actor must outrank the target. Target not in the alliance: no-op. */
const R = require('../../public/js/rules.js');
const { GameError } = require('../errors');
const A = require('../alliances');
module.exports = function allianceKick(ctx, { userId, allianceId, operatorId }) {
const { db } = ctx;
const { op, alliance, member } = A.requireRole(db, userId, allianceId, 'kick');
if (operatorId === op.id) throw new GameError('validation_failed', { errors: [{ path: 'operatorId', message: 'use leave to leave an alliance' }] });
const t = A.membership(db, operatorId);
if (!t || t.alliance_id !== alliance.id) return { changed: false };
if (!R.outranks(member.role, t.role)) throw new GameError('forbidden', { need: 'outrank', role: member.role, targetRole: t.role });
const target = db.get('SELECT id, name FROM operators WHERE id = ?', operatorId);
A.removeMember(db, operatorId);
A.notifyOperator(ctx, operatorId, 'alliance_kicked', { allianceId: alliance.id, tag: alliance.tag, name: alliance.name });
A.notifyAlliance(ctx, alliance.id, 'alliance_member_left', { allianceId: alliance.id, operatorId, name: target.name, kicked: true });
return { changed: true };
};