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
This commit is contained in:
parent
b56b13880e
commit
249818a7aa
111 changed files with 17472 additions and 13 deletions
41
server/commands/allianceInviteAnswer.js
Normal file
41
server/commands/allianceInviteAnswer.js
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
'use strict';
|
||||
/* POST /alliance-invites/:id/accept | /decline. Only the invited operator's user. Accepting needs Peering office >= 1,
|
||||
* no current alliance, and room (cap re-evaluated). Answering an already answered invite the same way is a no-op. */
|
||||
const { GameError } = require('../errors');
|
||||
const A = require('../alliances');
|
||||
|
||||
module.exports = function allianceInviteAnswer(ctx, { userId, inviteId, accept }) {
|
||||
const { db, now } = ctx;
|
||||
const S = A.S;
|
||||
const inv = db.get(`SELECT i.*, o.user_id AS uid, o.name AS oname FROM alliance_invites i JOIN operators o ON o.id = i.operator_id WHERE i.id = ?`, inviteId);
|
||||
if (!inv || inv.uid !== userId) throw new GameError('not_found', { what: 'invite' });
|
||||
|
||||
if (inv.status !== 'pending') {
|
||||
if ((accept && inv.status === 'accepted') || (!accept && inv.status === 'declined')) return { changed: false, allianceId: inv.alliance_id };
|
||||
throw new GameError(inv.status === 'expired' ? 'invite_expired' : 'conflict', { what: 'invite is ' + inv.status });
|
||||
}
|
||||
if (inv.expires_at <= now) {
|
||||
// The refusal rolls this transaction back; the invite is simply treated as expired whenever it is looked at.
|
||||
throw new GameError('invite_expired', { expiresAt: inv.expires_at });
|
||||
}
|
||||
const alliance = A.getAlliance(db, inv.alliance_id);
|
||||
if (!alliance) throw new GameError('not_found', { what: 'alliance' });
|
||||
|
||||
if (!accept) {
|
||||
db.run("UPDATE alliance_invites SET status = 'declined', answered_at = ? WHERE id = ?", now, inv.id);
|
||||
A.notifyOperator(ctx, inv.invited_by, 'alliance_invite_declined', { inviteId: inv.id, allianceId: alliance.id, by: inv.oname });
|
||||
return { changed: true, allianceId: alliance.id };
|
||||
}
|
||||
|
||||
const cur = A.membership(db, inv.operator_id);
|
||||
if (cur) throw new GameError('already_in_alliance', { allianceId: cur.alliance_id });
|
||||
const lvl = A.peeringLevel(db, inv.operator_id);
|
||||
if (lvl < S.minPeeringLevel) throw new GameError('peering_office_required', { have: lvl, need: S.minPeeringLevel });
|
||||
const cap = A.refreshCap(db, alliance);
|
||||
if (A.memberCount(db, alliance.id) >= cap) throw new GameError('alliance_full', { cap });
|
||||
|
||||
A.addMember(db, alliance.id, inv.operator_id, 'member', now);
|
||||
db.run("UPDATE alliance_invites SET status = 'accepted', answered_at = ? WHERE id = ?", now, inv.id);
|
||||
A.notifyAlliance(ctx, alliance.id, 'alliance_member_joined', { allianceId: alliance.id, operatorId: inv.operator_id, name: inv.oname }, { except: inv.operator_id });
|
||||
return { changed: true, allianceId: alliance.id, role: 'member' };
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue