@chrischall/warapp-mcp 0.22.0 → 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 (73) 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/guard-off.js +7 -0
  6. package/dist/analysis/headroom.js +1 -0
  7. package/dist/analysis/outlook.js +42 -2
  8. package/dist/analysis/plan/captures.js +2 -0
  9. package/dist/analysis/plan/holds.js +25 -8
  10. package/dist/analysis/plan/report.js +2 -2
  11. package/dist/analysis/plan/targets.js +15 -5
  12. package/dist/analysis/plan/threats.js +55 -2
  13. package/dist/analysis/planner.js +12 -1
  14. package/dist/bundle.js +10245 -3743
  15. package/dist/chat.js +93 -3
  16. package/dist/clans.js +308 -0
  17. package/dist/forums.js +70 -0
  18. package/dist/friends.js +83 -0
  19. package/dist/index.js +1 -1
  20. package/dist/invite-code.js +46 -0
  21. package/dist/join-color.js +23 -13
  22. package/dist/ladders.js +360 -0
  23. package/dist/lessons-store.js +2 -2
  24. package/dist/mail.js +295 -0
  25. package/dist/my-games.js +18 -1
  26. package/dist/notifications.js +22 -4
  27. package/dist/open-games.js +29 -2
  28. package/dist/outlook-log.js +1 -0
  29. package/dist/protocol/bundle.js +4 -4
  30. package/dist/protocol/codec.js +1 -1
  31. package/dist/protocol/methods.js +690 -8
  32. package/dist/protocol/rpc.js +28 -3
  33. package/dist/push/socketio.js +2 -2
  34. package/dist/quickmatch.js +264 -0
  35. package/dist/surrender-pending.js +62 -2
  36. package/dist/templates.js +451 -0
  37. package/dist/tools/bait.js +6 -2
  38. package/dist/tools/boot-player.js +165 -0
  39. package/dist/tools/chat.js +19 -0
  40. package/dist/tools/check-plan.js +5 -3
  41. package/dist/tools/clan-writes.js +208 -0
  42. package/dist/tools/clans.js +181 -0
  43. package/dist/tools/end-game-common.js +49 -0
  44. package/dist/tools/forums.js +535 -0
  45. package/dist/tools/friends.js +50 -0
  46. package/dist/tools/game.js +21 -3
  47. package/dist/tools/index.js +39 -0
  48. package/dist/tools/invites.js +347 -0
  49. package/dist/tools/join-game.js +4 -4
  50. package/dist/tools/ladders.js +418 -0
  51. package/dist/tools/leave-game.js +85 -27
  52. package/dist/tools/live-context.js +2 -2
  53. package/dist/tools/mail.js +600 -0
  54. package/dist/tools/my-games.js +50 -6
  55. package/dist/tools/notifications.js +12 -3
  56. package/dist/tools/nudge.js +178 -0
  57. package/dist/tools/past-games.js +23 -0
  58. package/dist/tools/quickmatch.js +481 -0
  59. package/dist/tools/react.js +177 -0
  60. package/dist/tools/session.js +6 -2
  61. package/dist/tools/team-surrender.js +206 -0
  62. package/dist/tools/templates.js +342 -0
  63. package/dist/tools/tournaments.js +495 -0
  64. package/dist/tools/turn.js +18 -8
  65. package/dist/tools/vote-to-end.js +142 -0
  66. package/dist/tools/write-kit.js +22 -1
  67. package/dist/tournaments.js +321 -0
  68. package/dist/version.js +1 -1
  69. package/manifest.json +190 -2
  70. package/mint.yaml +3 -4
  71. package/package.json +1 -1
  72. package/server.json +2 -2
  73. package/skills/warapp-mcp/SKILL.md +39 -6
package/dist/chat.js CHANGED
@@ -16,6 +16,14 @@ import { parseFeedTime } from './normalize.js';
16
16
  import { asInt } from './scalars.js';
17
17
  export const GAME_DETAILS_AND_CHAT = 'warlight.shared.GameDetailsAndChat';
18
18
  export const GAME_MESSAGE = 'warlight.shared.GameMessage';
19
+ export const MESSAGE_REACTION = 'warlight.shared.MessageReaction';
20
+ /**
21
+ * `warlight.shared.ReactionType`, one byte, by its value (#634): the client's reaction menu lists exactly these five
22
+ * (its labels "Thumbs up", "Thumbs down", "Heart", "Laugh", "Angry").
23
+ */
24
+ export const REACTION_TYPES = ['thumbs-up', 'thumbs-down', 'heart', 'laugh', 'angry'];
25
+ /** GameDetailsAndChat's reactions (243): a dict of message id → that message's reactions, read by position. */
26
+ const GDC_REACTIONS = 5;
19
27
  /**
20
28
  * GameMessage field positions in read order, and its whole field count (protocol 243: the shared images,
21
29
  * an optional list of strings, at 5, and the reactions, an optional list of records, at 7).
@@ -27,6 +35,44 @@ export const PUBLIC_CHANNEL = -1;
27
35
  export const CHAT_CHANNELS = ['public', 'team', 'private', 'unknown'];
28
36
  const isInt = (v) => typeof v === 'number' && Number.isInteger(v);
29
37
  const optInt = (v) => v === null || isInt(v);
38
+ /** One decoded MessageReaction; `undefined` when it is not one. */
39
+ function reactionOf(r) {
40
+ if (!isObj(r) || r.$type !== MESSAGE_REACTION)
41
+ return undefined;
42
+ const f = fields(r);
43
+ if (f.length !== 3)
44
+ return undefined;
45
+ const [by, name, kind] = f;
46
+ if (!isInt(by) || !(name === null || typeof name === 'string') || !isInt(kind))
47
+ return undefined;
48
+ const type = REACTION_TYPES[kind];
49
+ return type ? { by, name, type } : { by, name, type: 'unknown', code: kind };
50
+ }
51
+ /** A decoded reaction list (`null` items skipped): the reactions, or `undefined` when any is not one. */
52
+ function reactionsOf(list) {
53
+ const out = [];
54
+ for (const r of list) {
55
+ if (r === null)
56
+ continue;
57
+ const reaction = reactionOf(r);
58
+ if (!reaction)
59
+ return undefined;
60
+ out.push(reaction);
61
+ }
62
+ return out;
63
+ }
64
+ /** Set a line's reactions from a decoded list: none is no field, an unreadable list is `reactionsUnread`. */
65
+ function setReactions(line, list) {
66
+ delete line.reactions;
67
+ delete line.reactionsUnread;
68
+ if (list === null)
69
+ return;
70
+ const reactions = reactionsOf(list);
71
+ if (!reactions)
72
+ line.reactionsUnread = true;
73
+ else if (reactions.length)
74
+ line.reactions = reactions;
75
+ }
30
76
  /** One decoded GameMessage as a line; `undefined` when a field is not what it should be. */
31
77
  function webLine(m) {
32
78
  if (!isObj(m) || m.$type !== GAME_MESSAGE)
@@ -46,7 +92,7 @@ function webLine(m) {
46
92
  const reactions = f[GM.reactions];
47
93
  if (!(date === null || date instanceof Date) || !optInt(sender) || !optInt(group) || !optInt(to) || !optInt(turn))
48
94
  return undefined;
49
- // Not reported, but checked: a field of another type here means the layout is not 243's.
95
+ // A field of another type here means the layout is not 243's.
50
96
  if (!(images === null || Array.isArray(images)) || !(reactions === null || Array.isArray(reactions)))
51
97
  return undefined;
52
98
  if (!(id === null || typeof id === 'string' || isInt(id)) || typeof text !== 'string' || !isInt(channel))
@@ -54,6 +100,9 @@ function webLine(m) {
54
100
  const line = { sender, text, turn, channel: 'unknown' };
55
101
  if (id !== null)
56
102
  line.id = String(id);
103
+ const shared = images === null ? [] : images.filter((s) => typeof s === 'string' && s !== '');
104
+ if (shared.length)
105
+ line.images = shared;
57
106
  if (date !== null && Number.isFinite(date.getTime())) {
58
107
  line.time = date.toISOString();
59
108
  line.timeMs = date.getTime();
@@ -75,6 +124,7 @@ function webLine(m) {
75
124
  line.channel = 'team';
76
125
  line.team = channel;
77
126
  }
127
+ setReactions(line, reactions);
78
128
  return line;
79
129
  }
80
130
  const numericId = (id) => {
@@ -113,13 +163,38 @@ export function readGameRefreshChat(bundle, body) {
113
163
  const ret = bundle.readClass(GAME_DETAILS_AND_CHAT, body);
114
164
  if (!isObj(ret) || ret.$type !== GAME_DETAILS_AND_CHAT)
115
165
  return undefined;
116
- const list = fields(ret)[0];
117
- return list === null ? undefined : webLines(list);
166
+ const rf = fields(ret);
167
+ const list = rf[0];
168
+ const lines = list === null ? undefined : webLines(list);
169
+ if (lines)
170
+ applyReactionsDict(lines, rf[GDC_REACTIONS]);
171
+ return lines;
118
172
  }
119
173
  catch {
120
174
  return undefined;
121
175
  }
122
176
  }
177
+ /**
178
+ * The details' reactions dict (message id → its reactions), when present and readable: as the client shows a
179
+ * message, an entry there replaces the message's own list. A dict in another shape is ignored.
180
+ */
181
+ function applyReactionsDict(lines, dict) {
182
+ if (!Array.isArray(dict))
183
+ return;
184
+ const byId = new Map();
185
+ for (const pair of dict) {
186
+ if (!Array.isArray(pair) || pair.length !== 2)
187
+ return;
188
+ const [key, list] = pair;
189
+ if (!(typeof key === 'string' || isInt(key)) || !(list === null || Array.isArray(list)))
190
+ return;
191
+ byId.set(String(key), list);
192
+ }
193
+ for (const line of lines) {
194
+ if (line.id !== undefined && byId.has(line.id))
195
+ setReactions(line, byId.get(line.id));
196
+ }
197
+ }
123
198
  /**
124
199
  * The SendChat reply: the updated message list, read straight after the result-present flag (each
125
200
  * message behind its own present flag), oldest first; `undefined` when it cannot be read. The replies of
@@ -136,6 +211,21 @@ export function readSendChatReply(bundle, body) {
136
211
  return undefined;
137
212
  }
138
213
  }
214
+ /**
215
+ * The SetReaction reply (#634): a present flag, then the message's reactions now (a list of optional
216
+ * `MessageReaction`; absent: none). `undefined` when it cannot be read. Never throws.
217
+ */
218
+ export function readSetReactionReply(bundle, body) {
219
+ try {
220
+ if (!body.bool())
221
+ return [];
222
+ const list = body.list((r) => (r.bool() ? bundle.readClass(MESSAGE_REACTION, r) : null));
223
+ return list === null ? [] : reactionsOf(list);
224
+ }
225
+ catch {
226
+ return undefined;
227
+ }
228
+ }
139
229
  /** RetrieveChat's and RetrievePrivateMessageHistory's reply: a message list as SendChat's. */
140
230
  export const readMessageHistoryReply = readSendChatReply;
141
231
  /**
package/dist/clans.js ADDED
@@ -0,0 +1,308 @@
1
+ // Clans and clan wars (#639). Read from the 6.09 client bundle, UNVERIFIED live (docs/WEB-PROTOCOL.md, "Clans").
2
+ //
3
+ // Every reply is decoded by the client bundle's own readers by stable type name, fields by read order (never their
4
+ // minified names). The parsers project an ALLOWLIST and nothing else leaves them:
5
+ // - a clan: its id, name, creator's id, creation time, whether (and until when) it is open to join, and from a
6
+ // clan's own page its tagline, bio and link (the clan's words: third-party text, cleaned by the tool);
7
+ // - a member: the player id, name, level, clan title (the clan's words) and whether a manager. A member's
8
+ // last-seen time, membership flag, colour and the record's other fields are never read out;
9
+ // - a clan war: its id, whether it has ended, the standings (clan id, name, points, wins and participants today,
10
+ // final rank) and its games (game id, day, template, the clans and players in it, the winning clan).
11
+ // The invited players' ids are read only to say whether the signed-in account is invited (a tool reports that flag,
12
+ // never the list: whom a clan invited is the clan's business).
13
+ import { McpToolError } from '@chrischall/mcp-utils';
14
+ import { fields, isObj } from './protocol/decoded.js';
15
+ export const CLAN = 'warlight.shared.Clan';
16
+ export const CLAN_DATA = 'warlight.shared.ClanData';
17
+ export const CLAN_FOR_CLIENT = 'warlight.shared.ClanForClient';
18
+ export const CLAN_INFO = 'warlight.shared.ClanInfo';
19
+ export const CLAN_MEMBER = 'warlight.shared.PlayerMetadataForClan';
20
+ export const CLAN_WAR = 'warlight.shared.clanwars.ClanWar';
21
+ export const CLAN_WAR_INFO = 'warlight.shared.clanwars.ClanWarInfo';
22
+ export const CLAN_WAR_CLAN = 'warlight.shared.clanwars.ClanWarClan';
23
+ export const CLAN_WAR_GAME = 'warlight.shared.clanwars.ClanWarGame';
24
+ export const GET_CLAN_WAR_RETURN = 'warlight.shared.clanwars.GetClanWarReturn';
25
+ export const GET_CLAN_WAR_GAMES_RETURN = 'warlight.shared.clanwars.GetClanWarGamesReturn';
26
+ const PLAYER_INFO_2 = 'warlight.shared.PlayerInfo2';
27
+ /** Each record's field count and the positions read (read order). */
28
+ const COUNT = {
29
+ clan: 11,
30
+ data: 7,
31
+ forClient: 6,
32
+ member: 7,
33
+ info: 2,
34
+ warInfo: 6,
35
+ warReturn: 8,
36
+ warClan: 12,
37
+ war: 8,
38
+ gamesReturn: 5,
39
+ game: 8,
40
+ playerInfo2: 8,
41
+ };
42
+ const C = { creator: 1, created: 2, id: 4, name: 7, openUntil: 8 };
43
+ const CD = { bio: 0, link: 3, managers: 4, titles: 5, tagline: 6 };
44
+ const CFC = { clan: 0, data: 1, warRanks: 2, invited: 3, members: 4, meta: 5 };
45
+ const PMC = { level: 3, name: 4 };
46
+ const CI = { clan: 0, members: 1 };
47
+ const CWI = { season: 2, winnerName: 4, winnerClan: 5 };
48
+ const CWR = { standings: 1, clans: 2, war: 7 };
49
+ const CWC = { clan: 0, participantsToday: 4, pointsToday: 5, winsToday: 6, finalRank: 8, pointsBefore: 11 };
50
+ const CW = { ended: 2, id: 3 };
51
+ const GCWG = { games: 1, players: 2, templates: 3, total: 4 };
52
+ const CWG = { game: 0, id: 1, players: 2, day: 3, template: 5, winner: 7 };
53
+ const PI2_NAME = 4;
54
+ /** A clan reply arrived in a shape this server does not understand. */
55
+ export class ClanFormatError extends McpToolError {
56
+ constructor(detail) {
57
+ super(`war.app's clan data arrived in an unexpected shape (${detail}).`, {
58
+ kind: 'unknown',
59
+ hint: 'The war.app client may have changed; clans can still be read in the war.app tab.',
60
+ });
61
+ this.name = 'ClanFormatError';
62
+ }
63
+ }
64
+ const isInt = (v) => typeof v === 'number' && Number.isInteger(v);
65
+ const isNum = (v) => typeof v === 'number' && Number.isFinite(v);
66
+ const strOf = (v) => (typeof v === 'string' ? v : null);
67
+ const dateOf = (v) => (v instanceof Date && Number.isFinite(v.getTime()) ? v.toISOString() : null);
68
+ const intOrNull = (v) => (isInt(v) ? v : null);
69
+ const arr = (v) => (Array.isArray(v) ? v : []);
70
+ const ints = (v) => (Array.isArray(v) ? v.filter(isInt) : []);
71
+ const shortType = (type) => type.split('.').pop();
72
+ function record(v, type, count) {
73
+ if (!isObj(v) || v.$type !== type)
74
+ throw new ClanFormatError(`expected a ${shortType(type)}`);
75
+ const f = fields(v);
76
+ if (f.length !== count)
77
+ throw new ClanFormatError(`a ${shortType(type)} has ${f.length} fields, not ${count}`);
78
+ return f;
79
+ }
80
+ /** A reply with bytes left over was not read as war.app wrote it. */
81
+ function leftover(body) {
82
+ if (body.remaining !== 0)
83
+ throw new ClanFormatError(`${body.remaining} bytes left unread`);
84
+ }
85
+ /** The decoded dict (`[key, value]` pairs) as a map; anything else reads as empty. */
86
+ function dict(v) {
87
+ const m = new Map();
88
+ if (!Array.isArray(v))
89
+ return m;
90
+ for (const e of v)
91
+ if (Array.isArray(e) && e.length === 2)
92
+ m.set(e[0], e[1]);
93
+ return m;
94
+ }
95
+ function clanOf(v) {
96
+ const f = record(v, CLAN, COUNT.clan);
97
+ const clanId = f[C.id];
98
+ if (!isInt(clanId))
99
+ throw new ClanFormatError('a Clan has no id');
100
+ return {
101
+ clanId,
102
+ name: strOf(f[C.name]),
103
+ createdBy: intOrNull(f[C.creator]),
104
+ createdAt: dateOf(f[C.created]),
105
+ openUntil: dateOf(f[C.openUntil]),
106
+ };
107
+ }
108
+ /** The most entries a list reply may carry (GetClans lists every clan war.app has). */
109
+ export const MAX_CLAN_LIST = 200_000;
110
+ /** The result-present flag, then an optional list of optional `type` records, each projected by `item`. */
111
+ function readList(bundle, body, type, item) {
112
+ if (!body.bool())
113
+ return [];
114
+ const n = body.int32();
115
+ if (n === -1)
116
+ return [];
117
+ if (n < 0 || n > MAX_CLAN_LIST)
118
+ throw new ClanFormatError(`a list of ${n} entries`);
119
+ const out = [];
120
+ for (let i = 0; i < n; i++) {
121
+ if (!body.bool())
122
+ continue;
123
+ out.push(item(bundle.readClass(type, body)));
124
+ }
125
+ leftover(body);
126
+ return out;
127
+ }
128
+ /** A GetClans result (method 208): every clan, by id and name. */
129
+ export function readClans(bundle, body) {
130
+ return readList(bundle, body, CLAN, clanOf);
131
+ }
132
+ /** A GetOpenClans result (method 226): the clans accepting new members. */
133
+ export function readOpenClans(bundle, body) {
134
+ return readList(bundle, body, CLAN_INFO, (v) => {
135
+ const f = record(v, CLAN_INFO, COUNT.info);
136
+ if (f[CI.clan] === null)
137
+ throw new ClanFormatError('a ClanInfo has no clan');
138
+ return { ...clanOf(f[CI.clan]), members: intOrNull(f[CI.members]) };
139
+ });
140
+ }
141
+ /** A GetClan result (method 211); `null` when war.app sent no clan. */
142
+ export function readClan(bundle, body) {
143
+ if (!body.bool())
144
+ return null;
145
+ const f = record(bundle.readClass(CLAN_FOR_CLIENT, body), CLAN_FOR_CLIENT, COUNT.forClient);
146
+ leftover(body);
147
+ if (f[CFC.clan] === null)
148
+ throw new ClanFormatError('a ClanForClient has no clan');
149
+ const clan = clanOf(f[CFC.clan]);
150
+ const data = f[CFC.data] === null ? null : record(f[CFC.data], CLAN_DATA, COUNT.data);
151
+ const managers = data ? ints(data[CD.managers]) : [];
152
+ const titles = data ? dict(data[CD.titles]) : new Map();
153
+ const meta = dict(f[CFC.meta]);
154
+ const members = ints(f[CFC.members]).map((playerId) => {
155
+ const m = meta.get(playerId);
156
+ const mf = m === null || m === undefined ? null : record(m, CLAN_MEMBER, COUNT.member);
157
+ // The allowlist: of a member's record only the name and level ever leave the parser.
158
+ return {
159
+ playerId,
160
+ name: mf ? strOf(mf[PMC.name]) : null,
161
+ level: mf ? intOrNull(mf[PMC.level]) : null,
162
+ title: strOf(titles.get(playerId)) || null,
163
+ manager: managers.includes(playerId),
164
+ };
165
+ });
166
+ const warRanks = [...dict(f[CFC.warRanks])]
167
+ .filter((e) => isInt(e[0]) && isInt(e[1]))
168
+ .map(([season, rank]) => ({ season, rank }))
169
+ .sort((a, b) => a.season - b.season);
170
+ return {
171
+ ...clan,
172
+ tagline: data ? strOf(data[CD.tagline]) : null,
173
+ bio: data ? strOf(data[CD.bio]) : null,
174
+ link: data ? strOf(data[CD.link]) : null,
175
+ members,
176
+ managers,
177
+ invited: ints(f[CFC.invited]),
178
+ warRanks,
179
+ };
180
+ }
181
+ /** A GetClanWars result (method 324): every season, newest first. */
182
+ export function readClanWars(bundle, body) {
183
+ return readList(bundle, body, CLAN_WAR_INFO, (v) => {
184
+ const f = record(v, CLAN_WAR_INFO, COUNT.warInfo);
185
+ const warId = f[CWI.season];
186
+ if (!isInt(warId))
187
+ throw new ClanFormatError('a ClanWarInfo has no id');
188
+ const name = strOf(f[CWI.winnerName]);
189
+ // The client reads a season with no winner's name as in progress.
190
+ return { warId, inProgress: name === null, winner: name === null ? null : { clanId: intOrNull(f[CWI.winnerClan]), name } };
191
+ }).sort((a, b) => b.warId - a.warId);
192
+ }
193
+ /** A GetClanWar result (method 313); `null` when war.app sent none (no such war). */
194
+ export function readClanWar(bundle, body) {
195
+ if (!body.bool())
196
+ return null;
197
+ const f = record(bundle.readClass(GET_CLAN_WAR_RETURN, body), GET_CLAN_WAR_RETURN, COUNT.warReturn);
198
+ leftover(body);
199
+ if (f[CWR.war] === null)
200
+ return null;
201
+ const war = record(f[CWR.war], CLAN_WAR, COUNT.war);
202
+ const warId = war[CW.id];
203
+ if (!isInt(warId))
204
+ throw new ClanFormatError('a ClanWar has no id');
205
+ const names = new Map();
206
+ for (const c of arr(f[CWR.clans])) {
207
+ if (c === null)
208
+ continue;
209
+ const s = clanOf(c);
210
+ names.set(s.clanId, s.name);
211
+ }
212
+ const standings = arr(f[CWR.standings])
213
+ .filter((v) => v !== null)
214
+ .map((v) => {
215
+ const s = record(v, CLAN_WAR_CLAN, COUNT.warClan);
216
+ const clanId = s[CWC.clan];
217
+ if (!isInt(clanId))
218
+ throw new ClanFormatError('a ClanWarClan has no clan id');
219
+ const before = s[CWC.pointsBefore];
220
+ const today = s[CWC.pointsToday];
221
+ return {
222
+ clanId,
223
+ name: names.get(clanId) ?? null,
224
+ points: isNum(before) && isNum(today) ? before + today : null,
225
+ pointsToday: isNum(today) ? today : null,
226
+ winsToday: intOrNull(s[CWC.winsToday]),
227
+ participantsToday: intOrNull(s[CWC.participantsToday]),
228
+ finalRank: intOrNull(s[CWC.finalRank]),
229
+ };
230
+ })
231
+ .sort((a, b) => {
232
+ if (a.finalRank !== null && b.finalRank !== null)
233
+ return a.finalRank - b.finalRank;
234
+ if ((a.points ?? 0) !== (b.points ?? 0))
235
+ return (b.points ?? 0) - (a.points ?? 0);
236
+ return a.clanId - b.clanId;
237
+ });
238
+ const ended = dateOf(war[CW.ended]);
239
+ return { warId, ended, finished: ended !== null, standings };
240
+ }
241
+ /** A clan-war game's players, from its JSON (clan id → `{ Players: [ids] }`); unreadable reads as none. */
242
+ function sidesOf(json) {
243
+ if (typeof json !== 'string')
244
+ return [];
245
+ let parsed;
246
+ try {
247
+ parsed = JSON.parse(json);
248
+ }
249
+ catch {
250
+ return [];
251
+ }
252
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
253
+ return [];
254
+ const out = [];
255
+ for (const [key, raw] of Object.entries(parsed)) {
256
+ const clanId = Number(key);
257
+ if (!Number.isInteger(clanId))
258
+ continue;
259
+ let value = raw;
260
+ if (typeof value === 'string') {
261
+ try {
262
+ value = JSON.parse(value);
263
+ }
264
+ catch {
265
+ continue;
266
+ }
267
+ }
268
+ const players = value && typeof value === 'object' ? value.Players : undefined;
269
+ out.push({ clanId, players: Array.isArray(players) ? players.map(Number).filter(Number.isInteger) : [] });
270
+ }
271
+ return out;
272
+ }
273
+ /** A GetClanWarGames result (method 316): the page of games, players named from the reply's own players. */
274
+ export function readClanWarGames(bundle, body) {
275
+ if (!body.bool())
276
+ return { total: null, games: [] };
277
+ const f = record(bundle.readClass(GET_CLAN_WAR_GAMES_RETURN, body), GET_CLAN_WAR_GAMES_RETURN, COUNT.gamesReturn);
278
+ leftover(body);
279
+ const players = new Map();
280
+ for (const [id, p] of dict(f[GCWG.players])) {
281
+ if (!isInt(id) || p === null || p === undefined)
282
+ continue;
283
+ // Of a PlayerInfo2 only the name is read.
284
+ players.set(id, strOf(record(p, PLAYER_INFO_2, COUNT.playerInfo2)[PI2_NAME]));
285
+ }
286
+ const templates = dict(f[GCWG.templates]);
287
+ const games = arr(f[GCWG.games])
288
+ .filter((v) => v !== null)
289
+ .map((v) => {
290
+ const g = record(v, CLAN_WAR_GAME, COUNT.game);
291
+ const id = g[CWG.id];
292
+ if (!isInt(id))
293
+ throw new ClanFormatError('a ClanWarGame has no id');
294
+ const templateId = intOrNull(g[CWG.template]);
295
+ return {
296
+ id,
297
+ gameId: intOrNull(g[CWG.game]),
298
+ day: intOrNull(g[CWG.day]),
299
+ template: { id: templateId, name: templateId === null ? null : strOf(templates.get(templateId)) },
300
+ sides: sidesOf(g[CWG.players]).map((s) => ({
301
+ clanId: s.clanId,
302
+ players: s.players.map((playerId) => ({ playerId, name: players.get(playerId) ?? null })),
303
+ })),
304
+ winnerClanId: intOrNull(g[CWG.winner]),
305
+ };
306
+ });
307
+ return { total: intOrNull(f[GCWG.total]), games };
308
+ }
package/dist/forums.js ADDED
@@ -0,0 +1,70 @@
1
+ // war.app forums (#640): the forum list (GetForums → PublicForum) and the thread pages (GetForumThreads, SearchForum,
2
+ // GetGroupForumThreads → DiscussionInfos → DiscussionInfo). A forum thread is a Discussion like a mail thread, so its
3
+ // posts are read by src/mail.ts's `readDiscussion` (GetDiscussion) and its listed threads by `infoOf`; this file adds
4
+ // only the two replies mail never gets. Decoded by the client bundle's own readers by stable type name, fields by read
5
+ // order (docs/WEB-PROTOCOL.md, "Forums"). UNVERIFIED live: read from the 6.09 bundle.
6
+ //
7
+ // Personal fields never leave here: of a forum only its id, name and posting rule are read (its other texts are not
8
+ // named by the client and never looked at); of a listed thread's PlayerInfo2 only the name (mail.ts). Subjects, post
9
+ // texts and names are other players' words: the tools pass them on only through untrustedText / untrustedBody.
10
+ import { DISCUSSION_INFOS, forumOf, infoOf, MailFormatError, PUBLIC_FORUM, record } from './mail.js';
11
+ /** `DiscussionType` values a forum thread can have (0 public forum, 3 clan forum, 5 group forum). */
12
+ export const FORUM_DISCUSSION_TYPES = new Set([0, 3, 5]);
13
+ /** The client's Feature Requests forum, where a thread never grows too old to post to. */
14
+ export const FEATURE_REQUEST_FORUM = 12;
15
+ /** `DiscussionVisibility` 2: a thread or post the client hides for its downvotes. */
16
+ export const HIDDEN_BY_DOWNVOTES = 2;
17
+ /** What a forum's posting rule (the permission it needs) means, in the client's own refusal words. */
18
+ export const FORUM_POST_RULE = {
19
+ 0: 'Needs a high enough war.app level to post (the client: "You are not high enough level to post to this forum").',
20
+ 1: 'Only players taking part in the ladders can post.',
21
+ };
22
+ /** Read a GetForums result (the body at the result-present flag): a list of optional PublicForum. */
23
+ export function readForums(bundle, body) {
24
+ if (!body.bool())
25
+ return [];
26
+ const n = body.int32();
27
+ const out = [];
28
+ if (n !== -1) {
29
+ if (n < 0 || n > 10_000)
30
+ throw new MailFormatError(`a list of ${n} forums`);
31
+ for (let i = 0; i < n; i++) {
32
+ if (!body.bool())
33
+ continue;
34
+ out.push(forumOf(bundle.readClass(PUBLIC_FORUM, body)));
35
+ }
36
+ }
37
+ if (body.remaining !== 0)
38
+ throw new MailFormatError(`${body.remaining} bytes left unread after the forum list`);
39
+ return out;
40
+ }
41
+ /** Read a GetForumThreads / SearchForum / GetGroupForumThreads result (the body at the result-present flag). */
42
+ export function readThreadPage(bundle, body) {
43
+ if (!body.bool())
44
+ return { threads: [], total: 0, hidden: 0 };
45
+ const f = record(bundle.readClass(DISCUSSION_INFOS, body), DISCUSSION_INFOS, 2);
46
+ if (body.remaining !== 0)
47
+ throw new MailFormatError(`${body.remaining} bytes left unread after the thread list`);
48
+ const total = f[1];
49
+ if (typeof total !== 'number' || !Number.isInteger(total))
50
+ throw new MailFormatError('a thread list lacks its total');
51
+ const all = Array.isArray(f[0]) ? f[0].filter((v) => v !== null).map(infoOf) : [];
52
+ const threads = all.filter((t) => t.visibility !== HIDDEN_BY_DOWNVOTES);
53
+ return { threads, total, hidden: all.length - threads.length };
54
+ }
55
+ /** A post's votes counted, and mine (`up`, `down`, or null when I have none). */
56
+ export function voteTally(post, me) {
57
+ let up = 0;
58
+ let down = 0;
59
+ let mine = null;
60
+ for (const v of post.votes ?? []) {
61
+ const kind = v.vote === 1 ? 'up' : v.vote === 2 ? 'down' : null;
62
+ if (kind === 'up')
63
+ up++;
64
+ if (kind === 'down')
65
+ down++;
66
+ if (v.player === me)
67
+ mine = kind;
68
+ }
69
+ return { up, down, mine };
70
+ }
@@ -0,0 +1,83 @@
1
+ // The signed-in account's friends and block list (#641). Read from the client bundle, UNVERIFIED live
2
+ // (docs/WEB-PROTOCOL.md, Friends and blocks).
3
+ //
4
+ // Friends: a GetFriends reply (method 0, auth only), `GetFriendsReturn` → a list of `PlayerInfo`,
5
+ // decoded by the client bundle's own readers by stable type name, fields by read order. A PlayerInfo
6
+ // also carries the friend's clan, colour, ladder flags, membership, last-online time, level, turn
7
+ // speeds and games played together: the parser projects an ALLOWLIST — the player id and the name —
8
+ // and nothing else ever leaves it.
9
+ //
10
+ // Blocks: GetFriendsReturn holds no block list. The client keeps it in the startup parameters every
11
+ // war.app page that runs the client carries (`InitParameters`, its second field: an optional list of
12
+ // the blocked players' ids; ids only, no names), read with src/join-color.ts' startup-string reader.
13
+ import { McpToolError } from '@chrischall/mcp-utils';
14
+ import { fromStartupParameters, signedInPlayerOf } from './join-color.js';
15
+ import { fields, isObj } from './protocol/decoded.js';
16
+ export const GET_FRIENDS_RETURN = 'warlight.shared.GetFriendsReturn';
17
+ export const PLAYER_INFO = 'warlight.shared.PlayerInfo';
18
+ const PRODUCT = 'warlight.shared.Product';
19
+ /** PlayerInfo's field count and the two positions read (read order). */
20
+ export const PLAYER_INFO_FIELDS = 16;
21
+ const PI = { name: 9, playerId: 11 };
22
+ /** InitParameters' block list position (read order): the field after the optional product. */
23
+ const IP = { product: 0, blocked: 1 };
24
+ /** The GetFriends reply arrived in a shape this server does not understand. */
25
+ export class FriendsFormatError extends McpToolError {
26
+ constructor(detail) {
27
+ super(`war.app's friends list arrived in an unexpected shape (${detail}).`, {
28
+ kind: 'unknown',
29
+ hint: 'The war.app client may have changed; the friends list can still be read in the war.app tab.',
30
+ });
31
+ this.name = 'FriendsFormatError';
32
+ }
33
+ }
34
+ const isInt = (v) => typeof v === 'number' && Number.isInteger(v);
35
+ function friendOf(p) {
36
+ if (!isObj(p) || p.$type !== PLAYER_INFO)
37
+ throw new FriendsFormatError('an entry is not a PlayerInfo');
38
+ const f = fields(p);
39
+ if (f.length !== PLAYER_INFO_FIELDS)
40
+ throw new FriendsFormatError(`a PlayerInfo has ${f.length} fields, not ${PLAYER_INFO_FIELDS}`);
41
+ const name = f[PI.name];
42
+ const playerId = f[PI.playerId];
43
+ if (!(name === null || typeof name === 'string') || !isInt(playerId))
44
+ throw new FriendsFormatError('a PlayerInfo lacks its id or name');
45
+ // The allowlist: only these two fields ever leave the parser.
46
+ return { playerId, name };
47
+ }
48
+ /** Read a GetFriends result (the body positioned at the result-present flag): ids and names only. */
49
+ export function readFriends(bundle, body) {
50
+ if (!body.bool())
51
+ return [];
52
+ const ret = bundle.readClass(GET_FRIENDS_RETURN, body);
53
+ if (!isObj(ret) || ret.$type !== GET_FRIENDS_RETURN)
54
+ throw new FriendsFormatError('no GetFriendsReturn');
55
+ const f = fields(ret);
56
+ if (f.length !== 2)
57
+ throw new FriendsFormatError(`a GetFriendsReturn has ${f.length} fields, not 2`);
58
+ const [list] = f;
59
+ if (!(list === null || Array.isArray(list)))
60
+ throw new FriendsFormatError('no friends list');
61
+ return (list ?? []).filter((p) => p !== null).map(friendOf);
62
+ }
63
+ /**
64
+ * The ids of the players the signed-in account has blocked, from the startup parameters a war.app page
65
+ * carries; `undefined` when the page has none that read as a signed-in account's (signed out, or the
66
+ * client changed). Never throws; never returns anything else the parameters carry.
67
+ */
68
+ export function readBlockedIds(html, bundle) {
69
+ return fromStartupParameters(html, bundle, (params) => {
70
+ if (!signedInPlayerOf(params))
71
+ return undefined;
72
+ const f = fields(params);
73
+ const product = f[IP.product];
74
+ const blocked = f[IP.blocked];
75
+ if (!(product === null || (isObj(product) && product.$type === PRODUCT)))
76
+ return undefined;
77
+ if (blocked === null)
78
+ return [];
79
+ if (!Array.isArray(blocked) || !blocked.every(isInt))
80
+ return undefined;
81
+ return [...new Set(blocked)];
82
+ });
83
+ }
package/dist/index.js CHANGED
@@ -36,6 +36,6 @@ await runMcp({
36
36
  version: VERSION,
37
37
  tools: [(server) => registerAllTools(server, { bridge })],
38
38
  shutdown: { onSignal: () => bridge.transport().close() },
39
- banner: `[warapp-mcp] v${VERSION} — war.app (Warzone) advisor; joining, leaving or surrendering a game, closing out a finished game, accepting a surrender, Begin, picks, turn orders, withdrawing them, chat, marking notifications and chat read, deleting notifications, importing local history and linking a session are confirm-gated. Set WARAPP_EMAIL and WARAPP_API_TOKEN. ` +
39
+ banner: `[warapp-mcp] v${VERSION} — war.app (Warzone) advisor; creating, joining, leaving or surrendering a game, accepting invitations, closing out a finished game, accepting a surrender, a team surrender, a vote to end, booting a stalled player, Begin, picks, turn orders, withdrawing them, chat, nudging a player, joining or leaving a ladder, answering a clan invite, joining or leaving a clan, changing quickmatch settings, voting on quickmatch templates, joining or declining a tournament, showing a tournament among your favourites, mail (new threads, replies, adding players, deleting threads), forum posts (new threads, replies, votes, watching a thread), chat reactions, marking notifications and chat read, deleting notifications, importing local history and linking a session are confirm-gated. Set WARAPP_EMAIL and WARAPP_API_TOKEN. ` +
40
40
  'This project was developed and is maintained by AI (Claude). Use at your own discretion.',
41
41
  });
@@ -0,0 +1,46 @@
1
+ // Game invite codes (#633): the reply of GetGameByInviteCode (295), a `warlight.shared.GameInviteCode`, decoded by
2
+ // the client bundle's own reader by type name and its fields by read order (docs/WEB-PROTOCOL.md "Invitations and
3
+ // invite codes"). READ FROM THE BUNDLE, UNVERIFIED live.
4
+ //
5
+ // The record's five fields: the code (a nullable string), a datetime, the game made with the code (an optional int32;
6
+ // absent while its creator has not made the game — the client then shows a "waiting" screen and asks again every few
7
+ // seconds), the most players a game made with the code may have (the create screen shows it as "Max players"), and an
8
+ // int32 the client never shows. Only the code, the game id and the cap are kept; the datetime and the last int32 are
9
+ // not reported (what they mean is not known).
10
+ import { McpToolError } from '@chrischall/mcp-utils';
11
+ import { fields, isObj } from './protocol/decoded.js';
12
+ export const GAME_INVITE_CODE = 'warlight.shared.GameInviteCode';
13
+ const GAME_INVITE_CODE_FIELDS = 5;
14
+ const GC = { code: 0, gameId: 2, maxPlayers: 3 };
15
+ /** war.app's answer for a code it does not know (`GameInviteCodeKeyNotFound`; the client says "Invalid code!"). */
16
+ export const INVITE_CODE_NOT_FOUND = 651;
17
+ /** The record arrived in a shape this server does not know (the client changed). */
18
+ export class InviteCodeFormatError extends McpToolError {
19
+ constructor(detail) {
20
+ super(`war.app's invite-code reply arrived in an unexpected shape (${detail}).`, {
21
+ kind: 'unknown',
22
+ hint: 'The war.app client may have changed.',
23
+ });
24
+ this.name = 'InviteCodeFormatError';
25
+ }
26
+ }
27
+ const isInt = (v) => typeof v === 'number' && Number.isInteger(v);
28
+ /** A GetGameByInviteCode result (the body at its result-present flag); `undefined` when absent. */
29
+ export function readGameInviteCode(bundle, body) {
30
+ if (!body.bool())
31
+ return undefined;
32
+ const rec = bundle.readClass(GAME_INVITE_CODE, body);
33
+ if (!isObj(rec) || rec.$type !== GAME_INVITE_CODE)
34
+ throw new InviteCodeFormatError('no GameInviteCode');
35
+ const f = fields(rec);
36
+ if (f.length !== GAME_INVITE_CODE_FIELDS) {
37
+ throw new InviteCodeFormatError(`a GameInviteCode has ${f.length} fields, not ${GAME_INVITE_CODE_FIELDS}`);
38
+ }
39
+ const code = f[GC.code];
40
+ const gameId = f[GC.gameId];
41
+ const max = f[GC.maxPlayers];
42
+ if (!(code === null || typeof code === 'string') || !(gameId === null || isInt(gameId))) {
43
+ throw new InviteCodeFormatError('a GameInviteCode lacks its fields');
44
+ }
45
+ return { code, gameId, maxPlayers: isInt(max) ? max : null };
46
+ }