@chrischall/warapp-mcp 0.22.1 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/.claude-plugin/marketplace.json +3 -3
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +49 -3
  4. package/dist/analysis/coalition.js +3 -2
  5. package/dist/analysis/outlook.js +42 -2
  6. package/dist/analysis/plan/captures.js +2 -0
  7. package/dist/analysis/plan/report.js +2 -2
  8. package/dist/analysis/plan/targets.js +15 -5
  9. package/dist/analysis/plan/threats.js +55 -2
  10. package/dist/analysis/planner.js +2 -1
  11. package/dist/bundle.js +10186 -3727
  12. package/dist/chat.js +93 -3
  13. package/dist/clans.js +308 -0
  14. package/dist/forums.js +70 -0
  15. package/dist/friends.js +83 -0
  16. package/dist/index.js +1 -1
  17. package/dist/invite-code.js +46 -0
  18. package/dist/join-color.js +23 -13
  19. package/dist/ladders.js +360 -0
  20. package/dist/mail.js +295 -0
  21. package/dist/my-games.js +18 -1
  22. package/dist/notifications.js +22 -4
  23. package/dist/open-games.js +29 -2
  24. package/dist/outlook-log.js +1 -0
  25. package/dist/protocol/bundle.js +4 -4
  26. package/dist/protocol/codec.js +1 -1
  27. package/dist/protocol/methods.js +690 -8
  28. package/dist/protocol/rpc.js +28 -3
  29. package/dist/push/socketio.js +2 -2
  30. package/dist/quickmatch.js +264 -0
  31. package/dist/surrender-pending.js +62 -2
  32. package/dist/templates.js +451 -0
  33. package/dist/tools/boot-player.js +165 -0
  34. package/dist/tools/chat.js +19 -0
  35. package/dist/tools/clan-writes.js +208 -0
  36. package/dist/tools/clans.js +181 -0
  37. package/dist/tools/end-game-common.js +49 -0
  38. package/dist/tools/forums.js +535 -0
  39. package/dist/tools/friends.js +50 -0
  40. package/dist/tools/game.js +21 -3
  41. package/dist/tools/index.js +39 -0
  42. package/dist/tools/invites.js +347 -0
  43. package/dist/tools/join-game.js +4 -4
  44. package/dist/tools/ladders.js +418 -0
  45. package/dist/tools/leave-game.js +85 -27
  46. package/dist/tools/live-context.js +2 -2
  47. package/dist/tools/mail.js +600 -0
  48. package/dist/tools/my-games.js +50 -6
  49. package/dist/tools/notifications.js +12 -3
  50. package/dist/tools/nudge.js +178 -0
  51. package/dist/tools/quickmatch.js +481 -0
  52. package/dist/tools/react.js +177 -0
  53. package/dist/tools/session.js +6 -2
  54. package/dist/tools/team-surrender.js +206 -0
  55. package/dist/tools/templates.js +342 -0
  56. package/dist/tools/tournaments.js +495 -0
  57. package/dist/tools/turn.js +1 -1
  58. package/dist/tools/vote-to-end.js +142 -0
  59. package/dist/tools/write-kit.js +22 -1
  60. package/dist/tournaments.js +321 -0
  61. package/dist/version.js +1 -1
  62. package/manifest.json +190 -2
  63. package/mint.yaml +3 -4
  64. package/package.json +1 -1
  65. package/server.json +2 -2
  66. package/skills/warapp-mcp/SKILL.md +39 -6
@@ -0,0 +1,208 @@
1
+ // The clan writes (#639), each confirm-gated: warapp_answer_clan_invite (AcceptClanInvite 216 / RejectClanInvite
2
+ // 217), warapp_join_open_clan (JoinOpenClan 227) and warapp_leave_clan (RemoveFromClan 219 with my own id: the
3
+ // client's Leave button). Read from the 6.09 client bundle, UNVERIFIED live (docs/WEB-PROTOCOL.md, "Clans").
4
+ //
5
+ // Each plan reads the clan's page (GetClan) and the signed-in account, and refuses what the client would not offer:
6
+ // an invite I do not hold, a clan I am already in, a closed clan, leaving a clan I am not in. The preview names the
7
+ // clan and the account by id (the clan's name goes delimited in a labelled field). Joining or accepting moves the
8
+ // account out of any clan it is in (the client warns so). The outcome is read back from the clan's page: my id among
9
+ // its members (accepted, joined), off its invited list (declined), off its members (left) → `confirmed`; else
10
+ // `unconfirmed`; no answer is `unknown`, never resent. No text reaches another player: not a chat send.
11
+ import { CONFIRM_INJECTION_RULE, toolAnnotations } from '@chrischall/mcp-utils';
12
+ import { z } from 'zod';
13
+ import { Method, writeClanIdParams, writeRemoveFromClanParams } from '../protocol/methods.js';
14
+ import { CLANS_UNVERIFIED, fetchClan, myClanStanding } from './clans.js';
15
+ import { shownAccount, UNTRUSTED_PREVIEW_NOTE, untrustedText } from './common.js';
16
+ import { mintMeta } from './hints.js';
17
+ import { requireApprovedAccount, writeAccount } from './live-context.js';
18
+ import { BRIDGE_NOTE } from './live.js';
19
+ import { defineGatedWrite, refuse, requireMe, sendAndVerify, worded } from './write-kit.js';
20
+ /** The clan refusals the client handles, worded from the client's own messages (read from the bundle, UNVERIFIED live). */
21
+ const CLAN_ERRORS = {
22
+ 440: 'The invite to this clan was revoked, so war.app refused: you did not join.',
23
+ 688: 'This clan is full (50 members), so war.app refused: you did not join.',
24
+ 690: 'This clan is now full or no longer open, so war.app refused: you did not join.',
25
+ 227: "The clan's creator has blocked you, so war.app refused: you did not join.",
26
+ 442: "You are the clan's only manager, so war.app will not let you leave (the clan would be left with none): promote another member to manager first.",
27
+ };
28
+ const clanIdArg = z.number().int().positive().describe('The clan id (the number after ID= in war.app/Clans/?ID=<n>).');
29
+ // Idempotent in effect: a repeat finds the change made and is refused before anything is sent.
30
+ const annotations = (title, destructive) => toolAnnotations({ title, readOnly: false, destructive, idempotent: true, openWorld: true });
31
+ /** The clan's page and where I stand in it, refused when the account or the clan cannot be read. */
32
+ async function clanAndMe(ctx, clanId) {
33
+ const me = await requireMe(ctx);
34
+ const clan = await fetchClan(ctx, clanId);
35
+ if (clan === null)
36
+ refuse(`war.app has no clan ${clanId}, so nothing was sent.`, 'Check the id with warapp_list_clans.');
37
+ const standing = myClanStanding(clan, me);
38
+ if (standing.inGameId === null)
39
+ refuse('The signed-in account id is not a war.app player id, so nothing was sent.', 'Check warapp_session_status.');
40
+ return { me, clan, standing: { ...standing, inGameId: standing.inGameId } };
41
+ }
42
+ const shownClan = (clan) => ({ id: clan.clanId, name: clan.name === null ? null : untrustedText(clan.name), members: clan.members.length });
43
+ /** The read-back: the clan's page again, judged by `done`. */
44
+ function readBack(ctx, s, done, ok, notYet) {
45
+ const base = { clan: { id: s.clanId }, account: s.me };
46
+ return {
47
+ unanswered: (failure) => ({
48
+ status: 'unknown',
49
+ outcome: 'unknown',
50
+ ...base,
51
+ warning: `war.app did not confirm it (${failure}), so it may have gone through. Read the clan with warapp_get_clan before trying again.`,
52
+ }),
53
+ readBack: () => fetchClan(ctx, s.clanId),
54
+ unreadable: (failure) => ({ status: 'unconfirmed', outcome: 'unconfirmed', ...base, warning: `It was sent, but the clan could not be read back (${failure}).` }),
55
+ classify: (after) => done(after)
56
+ ? { status: ok, outcome: 'confirmed', ...base }
57
+ : { status: 'unconfirmed', outcome: 'unconfirmed', ...base, warning: notYet },
58
+ };
59
+ }
60
+ const isMember = (clan, id) => clan?.members.some((m) => m.playerId === id) === true;
61
+ export function registerClanWriteTools(server, ctx) {
62
+ defineGatedWrite(server, { title: 'Accept or decline a war.app clan invite', _meta: mintMeta('change', ['accept clan invite', 'decline clan invite', 'join clan']) }, {
63
+ name: 'warapp_answer_clan_invite',
64
+ description: "Accept (`accept: true`) or decline (`accept: false`) the signed-in account's invite to a war.app (Warzone) clan " +
65
+ "(war.app's AcceptClanInvite / RejectClanInvite, by the clan's id). Refuses when the clan's page (warapp_get_clan) " +
66
+ 'shows no invite for you, or you are already a member. Accepting moves you out of any clan you are in. war.app ' +
67
+ "refuses a revoked invite (said plainly) and a full clan. Read back from the clan's page: `accepted` (you are a " +
68
+ 'member) or `declined` (the invite is gone), both `confirmed`; else `unconfirmed`; no answer is `unknown` — never ' +
69
+ `resend blindly. ${CLANS_UNVERIFIED} ${BRIDGE_NOTE} ${CONFIRM_INJECTION_RULE}`,
70
+ annotations: annotations('Answer a war.app clan invite', false),
71
+ inputSchema: z.object({
72
+ clan_id: clanIdArg,
73
+ accept: z.boolean().describe('true to join the clan, false to decline the invite.'),
74
+ }),
75
+ async plan({ clan_id, accept }) {
76
+ const { me, clan, standing } = await clanAndMe(ctx, clan_id);
77
+ if (standing.member)
78
+ refuse(`You are already a member of clan ${clan_id}, so nothing was sent.`, 'Read the clan with warapp_get_clan.');
79
+ if (!standing.invited)
80
+ refuse(`Clan ${clan_id} shows no invite for you, so nothing was sent.`, 'The invite may have been revoked; read the clan with warapp_get_clan.');
81
+ const verb = accept ? 'Accept' : 'Decline';
82
+ return {
83
+ gate: {
84
+ action: accept ? 'warapp.accept_clan_invite' : 'warapp.reject_clan_invite',
85
+ summary: `${verb} the invite to war.app clan ${clan_id}`,
86
+ account: writeAccount(me),
87
+ target: `clan:${clan_id}`,
88
+ payload: { method: accept ? 'AcceptClanInvite' : 'RejectClanInvite', clanId: clan_id },
89
+ willSend: { clan: clan_id, accept },
90
+ preview: {
91
+ warning: accept
92
+ ? `This joins clan ${clan_id} as account ${me}; it moves you out of any clan you are in now.`
93
+ : `This declines account ${me}'s invite to clan ${clan_id}; only the clan can invite you again.`,
94
+ account: shownAccount(undefined, me),
95
+ clan: shownClan(clan),
96
+ untrusted: UNTRUSTED_PREVIEW_NOTE,
97
+ },
98
+ },
99
+ state: { clanId: clan_id, me, inGameId: standing.inGameId, accept },
100
+ };
101
+ },
102
+ async execute(s) {
103
+ await requireApprovedAccount(ctx, writeAccount(s.me));
104
+ const back = s.accept
105
+ ? readBack(ctx, s, (c) => isMember(c, s.inGameId), 'accepted', 'The clan does not list you as a member yet.')
106
+ : readBack(ctx, s, (c) => c !== null && !c.invited.includes(s.inGameId), 'declined', 'The clan still lists your invite.');
107
+ return sendAndVerify({
108
+ send: async () => {
109
+ await ctx.rpc.call(s.accept ? 'AcceptClanInvite' : 'RejectClanInvite', s.accept ? Method.AcceptClanInvite : Method.RejectClanInvite, (w) => writeClanIdParams(w, s.clanId));
110
+ },
111
+ // The client takes a revoked invite (440) as declined already: read back, not refused.
112
+ refused: (e) => (!s.accept && e.code === 440 ? 'ignore' : worded(CLAN_ERRORS)(e)),
113
+ ...back,
114
+ });
115
+ },
116
+ });
117
+ defineGatedWrite(server, { title: 'Join an open war.app clan', _meta: mintMeta('change', ['join open clan', 'join a clan']) }, {
118
+ name: 'warapp_join_open_clan',
119
+ description: "Join a war.app (Warzone) clan that is open to anyone (war.app's JoinOpenClan; warapp_list_clans with " +
120
+ '`open: true` lists them). Refuses a clan whose page shows it closed, or one you are already in. Joining moves you ' +
121
+ "out of any clan you are in. war.app refuses a full or closed clan and one whose creator has blocked you (said " +
122
+ "plainly). Read back from the clan's page: `joined` (`confirmed`) once you are a member; else `unconfirmed`; no " +
123
+ `answer is \`unknown\` — never resend blindly. ${CLANS_UNVERIFIED} ${BRIDGE_NOTE} ${CONFIRM_INJECTION_RULE}`,
124
+ annotations: annotations('Join an open war.app clan', false),
125
+ inputSchema: z.object({ clan_id: clanIdArg }),
126
+ async plan({ clan_id }) {
127
+ const { me, clan, standing } = await clanAndMe(ctx, clan_id);
128
+ if (standing.member)
129
+ refuse(`You are already a member of clan ${clan_id}, so nothing was sent.`, 'Read the clan with warapp_get_clan.');
130
+ if (clan.openUntil === null) {
131
+ refuse(`Clan ${clan_id} is not open to join, so nothing was sent.`, standing.invited ? 'It has invited you: answer with warapp_answer_clan_invite.' : 'A closed clan takes members by invite only.');
132
+ }
133
+ return {
134
+ gate: {
135
+ action: 'warapp.join_open_clan',
136
+ summary: `Join war.app clan ${clan_id}`,
137
+ account: writeAccount(me),
138
+ target: `clan:${clan_id}`,
139
+ payload: { method: 'JoinOpenClan', clanId: clan_id },
140
+ willSend: { clan: clan_id },
141
+ preview: {
142
+ warning: `This joins clan ${clan_id} as account ${me}; it moves you out of any clan you are in now.`,
143
+ account: shownAccount(undefined, me),
144
+ clan: { ...shownClan(clan), openUntil: clan.openUntil },
145
+ untrusted: UNTRUSTED_PREVIEW_NOTE,
146
+ },
147
+ },
148
+ state: { clanId: clan_id, me, inGameId: standing.inGameId },
149
+ };
150
+ },
151
+ async execute(s) {
152
+ await requireApprovedAccount(ctx, writeAccount(s.me));
153
+ return sendAndVerify({
154
+ send: async () => {
155
+ await ctx.rpc.call('JoinOpenClan', Method.JoinOpenClan, (w) => writeClanIdParams(w, s.clanId));
156
+ },
157
+ refused: worded(CLAN_ERRORS),
158
+ ...readBack(ctx, s, (c) => isMember(c, s.inGameId), 'joined', 'The clan does not list you as a member yet.'),
159
+ });
160
+ },
161
+ });
162
+ defineGatedWrite(server, { title: 'Leave a war.app clan', _meta: mintMeta('change', ['leave clan', 'quit clan']) }, {
163
+ name: 'warapp_leave_clan',
164
+ description: "Leave the war.app (Warzone) clan the signed-in account is in (war.app's RemoveFromClan with your own id: the " +
165
+ "clan page's Leave button). Destructive: only the clan (or, for an open clan, joining again) can take you back, " +
166
+ "and any title or manager role is lost. Refuses when the clan's page does not list you. war.app refuses its only " +
167
+ "manager (said plainly). Read back from the clan's page: `left` (`confirmed`) once you are not a member; else " +
168
+ `\`unconfirmed\`; no answer is \`unknown\` — never resend blindly. ${CLANS_UNVERIFIED} ${BRIDGE_NOTE} ${CONFIRM_INJECTION_RULE}`,
169
+ annotations: annotations('Leave a war.app clan', true),
170
+ inputSchema: z.object({ clan_id: clanIdArg }),
171
+ async plan({ clan_id }) {
172
+ const { me, clan, standing } = await clanAndMe(ctx, clan_id);
173
+ if (!standing.member)
174
+ refuse(`Clan ${clan_id} does not list you as a member, so nothing was sent.`, 'Read the clan with warapp_get_clan.');
175
+ const soleManager = standing.manager && clan.managers.length === 1;
176
+ return {
177
+ gate: {
178
+ action: 'warapp.leave_clan',
179
+ summary: `Leave war.app clan ${clan_id}`,
180
+ account: writeAccount(me),
181
+ target: `clan:${clan_id}`,
182
+ payload: { method: 'RemoveFromClan', clanId: clan_id, playerId: standing.inGameId },
183
+ willSend: { clan: clan_id, player: standing.inGameId },
184
+ preview: {
185
+ warning: `This takes account ${me} out of clan ${clan_id}. Only the clan can take you back (or you rejoin, if it is open).`,
186
+ account: shownAccount(undefined, me),
187
+ clan: shownClan(clan),
188
+ ...(standing.manager ? { manager: true } : {}),
189
+ ...(soleManager ? { soleManagerNote: 'You are its only manager: war.app refuses to let the only manager leave.' } : {}),
190
+ untrusted: UNTRUSTED_PREVIEW_NOTE,
191
+ },
192
+ },
193
+ state: { clanId: clan_id, me, inGameId: standing.inGameId },
194
+ };
195
+ },
196
+ async execute(s) {
197
+ await requireApprovedAccount(ctx, writeAccount(s.me));
198
+ return sendAndVerify({
199
+ send: async () => {
200
+ await ctx.rpc.call('RemoveFromClan', Method.RemoveFromClan, (w) => writeRemoveFromClanParams(w, s.inGameId));
201
+ },
202
+ // 443 is the client's "not in the clan": already left, so read back rather than refuse.
203
+ refused: (e) => (e.code === 443 ? 'ignore' : worded(CLAN_ERRORS)(e)),
204
+ ...readBack(ctx, s, (c) => !isMember(c, s.inGameId), 'left', 'The clan still lists you as a member.'),
205
+ });
206
+ },
207
+ });
208
+ }
@@ -0,0 +1,181 @@
1
+ import { z } from 'zod';
2
+ import { readClan, readClans, readClanWar, readClanWarGames, readClanWars, readOpenClans } from '../clans.js';
3
+ import { inGameOf } from '../live.js';
4
+ import { Method, writeClanIdParams, writeGetClanWarGamesParams, writeGetClanWarParams } from '../protocol/methods.js';
5
+ import { readAnnotations, respond, untrustedBody, untrustedDescription, untrustedText } from './common.js';
6
+ import { mintMeta } from './hints.js';
7
+ import { BRIDGE_NOTE } from './live.js';
8
+ /** Every answer says so: nothing here has been checked against a real reply. */
9
+ export const CLANS_UNVERIFIED = "Read from war.app's client code, UNVERIFIED live: the clan and clan-war requests and replies have not been checked " +
10
+ 'against war.app yet.';
11
+ const DEFAULT_CLANS = 50;
12
+ const MAX_CLANS = 200;
13
+ const DEFAULT_WAR_GAMES = 25;
14
+ const MAX_WAR_GAMES = 100;
15
+ const clanIdArg = z.number().int().positive().describe('The clan id (the number after ID= in war.app/Clans/?ID=<n>).');
16
+ const name = (v) => (v === null ? null : untrustedText(v));
17
+ const text = (v) => (v === null || v === '' ? null : untrustedBody(v));
18
+ const shownClan = (c) => ({
19
+ clanId: c.clanId,
20
+ name: name(c.name),
21
+ createdBy: c.createdBy,
22
+ createdAt: c.createdAt,
23
+ open: c.openUntil !== null,
24
+ openUntil: c.openUntil,
25
+ });
26
+ /** Read one clan's page (GetClan); `null` when war.app sent none. */
27
+ export async function fetchClan(ctx, clanId) {
28
+ const env = await ctx.rpc.call('GetClan', Method.GetClan, (w) => writeClanIdParams(w, clanId));
29
+ return readClan(await ctx.bundle(), env.body);
30
+ }
31
+ /** Where the signed-in account (GameFeed id `me`) stands in a clan: a member, a manager, invited. */
32
+ export function myClanStanding(clan, me) {
33
+ const inGameId = inGameOf({ id: me }) ?? null;
34
+ if (inGameId === null)
35
+ return { inGameId, member: false, manager: false, invited: false };
36
+ return {
37
+ inGameId,
38
+ member: clan.members.some((m) => m.playerId === inGameId),
39
+ manager: clan.managers.includes(inGameId),
40
+ invited: clan.invited.includes(inGameId),
41
+ };
42
+ }
43
+ export function registerClanTools(server, ctx) {
44
+ server.registerTool('warapp_list_clans', {
45
+ title: 'List war.app clans',
46
+ description: untrustedDescription("war.app (Warzone) clans: every clan (war.app's GetClans), or with `open: true` only the clans open for anyone " +
47
+ 'to join (GetOpenClans, with each one\'s member count; war.app caps a clan at 50). Each is `clanId`, `name` ' +
48
+ '(delimited), `createdBy` (a player id), `createdAt`, `open` and `openUntil`. `query` keeps the clans whose ' +
49
+ 'name contains it (any case); `offset`/`limit` page the list (default 50, at most 200), `total` counts the ' +
50
+ `matches. ${BRIDGE_NOTE} Read-only. ${CLANS_UNVERIFIED}`),
51
+ _meta: mintMeta('lookup', ['war.app clans', 'list clans', 'open clans', 'find a clan']),
52
+ annotations: readAnnotations('List war.app clans'),
53
+ inputSchema: z.object({
54
+ open: z.boolean().optional().describe('true for only the clans open to join (default false: every clan).'),
55
+ query: z.string().max(100).optional().describe('Keep the clans whose name contains this text (any case).'),
56
+ offset: z.number().int().min(0).optional().describe('Skip this many matches (default 0).'),
57
+ limit: z.number().int().min(1).max(MAX_CLANS).optional().describe(`How many to return (default ${DEFAULT_CLANS}).`),
58
+ }),
59
+ }, async ({ open, query, offset, limit }) => {
60
+ const bundle = await ctx.bundle();
61
+ const all = open
62
+ ? readOpenClans(bundle, (await ctx.rpc.call('GetOpenClans', Method.GetOpenClans)).body)
63
+ : readClans(bundle, (await ctx.rpc.call('GetClans', Method.GetClans)).body);
64
+ const q = query?.trim().toLowerCase();
65
+ const matched = q ? all.filter((c) => (c.name ?? '').toLowerCase().includes(q)) : all;
66
+ const from = offset ?? 0;
67
+ const page = matched.slice(from, from + (limit ?? DEFAULT_CLANS));
68
+ return respond(undefined, ['compact'], () => ({
69
+ source: open ? 'open' : 'all',
70
+ total: matched.length,
71
+ offset: from,
72
+ clans: page.map((c) => ({ ...shownClan(c), ...('members' in c ? { members: c.members } : {}) })),
73
+ ...(from + page.length < matched.length ? { next: from + page.length } : {}),
74
+ unverified: CLANS_UNVERIFIED,
75
+ }));
76
+ });
77
+ server.registerTool('warapp_get_clan', {
78
+ title: "Read a war.app clan's page",
79
+ description: untrustedDescription("One war.app (Warzone) clan's page (war.app's GetClan): its name, creator, creation time, whether it is open to " +
80
+ 'join, its tagline, bio and link (the clan\'s own words, delimited), its members — each `playerId` (the in-game ' +
81
+ 'id), `name`, `level`, `title` (the clan\'s title for them) and `manager`, nothing else about them — its final ' +
82
+ 'rank per clan-war season, and `me` (whether the signed-in account is a member, a manager or invited: answer an ' +
83
+ `invite with warapp_answer_clan_invite). ${BRIDGE_NOTE} Read-only. ${CLANS_UNVERIFIED}`),
84
+ _meta: mintMeta('lookup', ['war.app clan', 'clan members', 'my clan', 'clan invite']),
85
+ annotations: readAnnotations("Read a war.app clan's page"),
86
+ inputSchema: z.object({ clan_id: clanIdArg }),
87
+ }, async ({ clan_id }) => {
88
+ const clan = await fetchClan(ctx, clan_id);
89
+ if (clan === null) {
90
+ return respond(undefined, ['compact'], () => ({ clanId: clan_id, found: false, unverified: CLANS_UNVERIFIED }));
91
+ }
92
+ const me = await ctx.myInviteToken({ fresh: false }).catch(() => undefined);
93
+ const standing = me === undefined ? null : myClanStanding(clan, me);
94
+ return respond(undefined, ['compact'], () => ({
95
+ found: true,
96
+ ...shownClan(clan),
97
+ tagline: text(clan.tagline),
98
+ bio: text(clan.bio),
99
+ link: text(clan.link),
100
+ memberCount: clan.members.length,
101
+ members: clan.members.map((m) => ({ playerId: m.playerId, name: name(m.name), level: m.level, title: m.title === null ? null : untrustedText(m.title), manager: m.manager })),
102
+ warRanks: clan.warRanks,
103
+ me: standing && { member: standing.member, manager: standing.manager, invited: standing.invited },
104
+ ...(standing ? {} : { meNote: 'The signed-in war.app account could not be read, so `me` is unknown.' }),
105
+ unverified: CLANS_UNVERIFIED,
106
+ }));
107
+ });
108
+ server.registerTool('warapp_get_clan_wars', {
109
+ title: 'Read war.app clan wars',
110
+ description: untrustedDescription("war.app (Warzone) clan wars. With no `war_id` and no `current`: every season (war.app's GetClanWars), newest " +
111
+ 'first, each `warId`, `inProgress` and the `winner` (clan id and name). With `war_id`, or `current: true` for ' +
112
+ "the season running now: that war (GetClanWar) — `finished`, `ended` and the `standings` (rank, clan id and " +
113
+ 'name, points, and the points, wins and participants of the day so far, final rank once it has ended), at most `limit` (default 50). ' +
114
+ `Its games are warapp_get_clan_war_games. ${BRIDGE_NOTE} Read-only. ${CLANS_UNVERIFIED}`),
115
+ _meta: mintMeta('lookup', ['clan war', 'clan war standings', 'clan war seasons']),
116
+ annotations: readAnnotations('Read war.app clan wars'),
117
+ inputSchema: z.object({
118
+ war_id: z.number().int().positive().optional().describe('The war (season) id; omit for the list of seasons.'),
119
+ current: z.boolean().optional().describe('true for the war running now (ignored with `war_id`).'),
120
+ limit: z.number().int().min(1).max(MAX_CLANS).optional().describe(`How many standings to return (default ${DEFAULT_CLANS}).`),
121
+ }),
122
+ }, async ({ war_id, current, limit }) => {
123
+ const bundle = await ctx.bundle();
124
+ if (war_id === undefined && !current) {
125
+ const seasons = readClanWars(bundle, (await ctx.rpc.call('GetClanWars', Method.GetClanWars)).body);
126
+ return respond(undefined, ['compact'], () => ({
127
+ seasons: seasons.map((s) => ({ ...s, winner: s.winner && { clanId: s.winner.clanId, name: name(s.winner.name) } })),
128
+ count: seasons.length,
129
+ unverified: CLANS_UNVERIFIED,
130
+ }));
131
+ }
132
+ const env = await ctx.rpc.call('GetClanWar', Method.GetClanWar, (w) => writeGetClanWarParams(w, war_id));
133
+ const war = readClanWar(bundle, env.body);
134
+ if (war === null) {
135
+ return respond(undefined, ['compact'], () => ({ warId: war_id ?? null, found: false, unverified: CLANS_UNVERIFIED }));
136
+ }
137
+ const shown = war.standings.slice(0, limit ?? DEFAULT_CLANS);
138
+ return respond(undefined, ['compact'], () => ({
139
+ found: true,
140
+ warId: war.warId,
141
+ finished: war.finished,
142
+ ended: war.ended,
143
+ clans: war.standings.length,
144
+ standings: shown.map((s, i) => ({ rank: i + 1, ...s, name: name(s.name) })),
145
+ unverified: CLANS_UNVERIFIED,
146
+ }));
147
+ });
148
+ server.registerTool('warapp_get_clan_war_games', {
149
+ title: "Read a war.app clan war's games",
150
+ description: untrustedDescription("The games of a war.app (Warzone) clan war (war.app's GetClanWarGames), every clan's or one clan's (`clan_id`), " +
151
+ 'paged (`offset`, `limit`: default 25, at most 100; `total` counts them all). Each game: `gameId` (the war.app ' +
152
+ 'game, `null` for a free win), `day`, `template` (id and name), `sides` (per clan, its players by id and name) ' +
153
+ `and \`winnerClanId\`. ${BRIDGE_NOTE} Read-only. ${CLANS_UNVERIFIED}`),
154
+ _meta: mintMeta('lookup', ['clan war games', 'clan war results']),
155
+ annotations: readAnnotations("Read a war.app clan war's games"),
156
+ inputSchema: z.object({
157
+ war_id: z.number().int().positive().describe('The war (season) id, from warapp_get_clan_wars.'),
158
+ clan_id: clanIdArg.optional().describe("Only this clan's games (default: every clan's)."),
159
+ offset: z.number().int().min(0).optional().describe('The first game to return, 0-based (default 0).'),
160
+ limit: z.number().int().min(1).max(MAX_WAR_GAMES).optional().describe(`How many games (default ${DEFAULT_WAR_GAMES}).`),
161
+ }),
162
+ }, async ({ war_id, clan_id, offset, limit }) => {
163
+ const from = offset ?? 0;
164
+ const count = limit ?? DEFAULT_WAR_GAMES;
165
+ const env = await ctx.rpc.call('GetClanWarGames', Method.GetClanWarGames, (w) => writeGetClanWarGamesParams(w, { warId: war_id, clanId: clan_id, offset: from, count }));
166
+ const page = readClanWarGames(await ctx.bundle(), env.body);
167
+ return respond(undefined, ['compact'], () => ({
168
+ warId: war_id,
169
+ clanId: clan_id ?? null,
170
+ total: page.total,
171
+ offset: from,
172
+ games: page.games.map((g) => ({
173
+ ...g,
174
+ template: { id: g.template.id, name: name(g.template.name) },
175
+ sides: g.sides.map((s) => ({ clanId: s.clanId, players: s.players.map((p) => ({ playerId: p.playerId, name: name(p.name) })) })),
176
+ })),
177
+ ...(page.total !== null && from + page.games.length < page.total && page.games.length > 0 ? { next: from + page.games.length } : {}),
178
+ unverified: CLANS_UNVERIFIED,
179
+ }));
180
+ });
181
+ }
@@ -0,0 +1,49 @@
1
+ // What the team surrender (#630), the vote to end (#631) and the boot (#632) share: the game read and
2
+ // refused the same way before anything is sent, and the game details read for the votes.
3
+ import { parseGameId } from '../client.js';
4
+ import { inGameOf, playersByInGameId } from '../live.js';
5
+ import { untrustedText } from './common.js';
6
+ import { readDetailsSeats } from './surrender-pending.js';
7
+ import { mySeat, refuse, requireMe, requirePlaying } from './write-kit.js';
8
+ /** The game, my GameFeed id and my seat, refused unless the game is being played (or picked) and my seat plays as a human. */
9
+ export async function gameInPlay(ctx, gameIdInput, what, opts = {}) {
10
+ const gameId = parseGameId(gameIdInput);
11
+ const me = await requireMe(ctx);
12
+ const game = await ctx.client.getGame(gameId, { map: false, settings: true });
13
+ if (game.state === 'Finished')
14
+ refuse(`Game ${gameId} is already over, so ${what} is not possible and nothing was sent.`, 'Check warapp_get_game.');
15
+ const states = opts.picking === false ? ['Playing'] : ['Playing', 'DistributingTerritories'];
16
+ if (!states.includes(game.state)) {
17
+ refuse(`Game ${gameId} is not being played (game state: ${game.state}), so ${what} is not possible and nothing was sent.`, 'Check warapp_get_game.');
18
+ }
19
+ const seat = mySeat(game, me);
20
+ requirePlaying(game, seat);
21
+ if (seat.humanTurnedIntoAI) {
22
+ refuse(`Your seat in game ${gameId} is played by an AI now, so ${what} is not possible and nothing was sent.`, 'Check warapp_get_game.');
23
+ }
24
+ const meInGame = inGameOf(seat);
25
+ if (meInGame === undefined)
26
+ refuse(`Your in-game id in game ${gameId} could not be read, so nothing was sent.`, 'Check warapp_get_game.');
27
+ return { gameId, me, game, seat, meInGame };
28
+ }
29
+ /** The game details' seats, refused when they cannot be read (the votes live only there). */
30
+ export async function requireDetailsSeats(ctx, gameId, what) {
31
+ const seats = await readDetailsSeats(ctx, gameId);
32
+ if (!seats) {
33
+ refuse(`Could not read game ${gameId}'s details, so ${what} cannot be told and nothing was sent.`, 'Make sure a war.app tab signed in to your account is open and paired (reload or focus it if it is frozen), then retry.');
34
+ }
35
+ return seats;
36
+ }
37
+ /** In-game ids as players: the GameFeed id (`null` when none maps), the in-game id and the name (untrusted). */
38
+ export function seatsView(game, ids) {
39
+ const byInGame = playersByInGameId(game.players);
40
+ return ids.map((id) => {
41
+ const p = byInGame.get(id);
42
+ return { player: p?.id ?? null, inGameId: id, name: p ? untrustedText(p.name) : null };
43
+ });
44
+ }
45
+ /** One in-game id by its GameFeed id when known, for a preview's sentences (ids only, never names). */
46
+ export function seatLabel(game, id) {
47
+ const p = playersByInGameId(game.players).get(id);
48
+ return p ? `player ${p.id}` : `in-game ${id}`;
49
+ }