@chrischall/warapp-mcp 0.0.0 → 0.2.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.
- package/.claude-plugin/marketplace.json +4 -4
- package/.claude-plugin/plugin.json +2 -2
- package/README.md +211 -9
- package/dist/analysis/accept-surrender.js +56 -0
- package/dist/analysis/award.js +159 -0
- package/dist/analysis/bonuses.js +98 -0
- package/dist/analysis/breach.js +62 -0
- package/dist/analysis/calibrate.js +239 -0
- package/dist/analysis/card-support.js +329 -0
- package/dist/analysis/card-threats.js +234 -0
- package/dist/analysis/cards-in-effect.js +130 -0
- package/dist/analysis/chains.js +59 -0
- package/dist/analysis/chokepoints.js +140 -0
- package/dist/analysis/combat.js +231 -0
- package/dist/analysis/commander-safety.js +149 -0
- package/dist/analysis/commitments.js +338 -0
- package/dist/analysis/exchange.js +155 -0
- package/dist/analysis/finished-game.js +136 -0
- package/dist/analysis/game-lessons.js +217 -0
- package/dist/analysis/graph.js +82 -0
- package/dist/analysis/guard-off.js +54 -0
- package/dist/analysis/guess.js +351 -0
- package/dist/analysis/headroom.js +241 -0
- package/dist/analysis/hold-diff.js +64 -0
- package/dist/analysis/how-lost.js +130 -0
- package/dist/analysis/index.js +14 -0
- package/dist/analysis/local-deploy.js +179 -0
- package/dist/analysis/lookahead.js +108 -0
- package/dist/analysis/opponent-profile.js +552 -0
- package/dist/analysis/opponents.js +1253 -0
- package/dist/analysis/outlook.js +695 -0
- package/dist/analysis/overrides.js +60 -0
- package/dist/analysis/picks.js +1879 -0
- package/dist/analysis/plan/after-leftover.js +140 -0
- package/dist/analysis/plan/cap-spend.js +242 -0
- package/dist/analysis/plan/captures.js +1195 -0
- package/dist/analysis/plan/commander.js +236 -0
- package/dist/analysis/plan/completed.js +29 -0
- package/dist/analysis/plan/conceded-out.js +131 -0
- package/dist/analysis/plan/estimates.js +715 -0
- package/dist/analysis/plan/guard-off.js +232 -0
- package/dist/analysis/plan/holds.js +1631 -0
- package/dist/analysis/plan/leftover.js +760 -0
- package/dist/analysis/plan/move-order.js +319 -0
- package/dist/analysis/plan/orders.js +317 -0
- package/dist/analysis/plan/relations.js +702 -0
- package/dist/analysis/plan/report.js +672 -0
- package/dist/analysis/plan/shared.js +1405 -0
- package/dist/analysis/plan/stand-still.js +823 -0
- package/dist/analysis/plan/state.js +44 -0
- package/dist/analysis/plan/strike.js +1416 -0
- package/dist/analysis/plan/targets.js +651 -0
- package/dist/analysis/plan/team.js +299 -0
- package/dist/analysis/plan/threats.js +1001 -0
- package/dist/analysis/plan/transfers.js +328 -0
- package/dist/analysis/plan/util.js +5 -0
- package/dist/analysis/plan/vacated.js +285 -0
- package/dist/analysis/planner.js +2927 -0
- package/dist/analysis/player-record.js +144 -0
- package/dist/analysis/player.js +268 -0
- package/dist/analysis/profile.js +347 -0
- package/dist/analysis/relations.js +1030 -0
- package/dist/analysis/schedule.js +88 -0
- package/dist/analysis/since-last.js +50 -0
- package/dist/analysis/static-seats.js +71 -0
- package/dist/analysis/stress.js +584 -0
- package/dist/analysis/team-brief.js +151 -0
- package/dist/analysis/tripwire.js +644 -0
- package/dist/analysis/turn-sim.js +259 -0
- package/dist/analysis/whereabouts.js +1112 -0
- package/dist/board.js +105 -0
- package/dist/bundle.js +121082 -36148
- package/dist/calibration-source.js +75 -0
- package/dist/cards.js +435 -0
- package/dist/chat-cursor.js +135 -0
- package/dist/chat.js +265 -0
- package/dist/client.js +439 -0
- package/dist/config.js +62 -0
- package/dist/direct/link.js +102 -0
- package/dist/direct/session.js +267 -0
- package/dist/direct/transport.js +424 -0
- package/dist/finished-store.js +357 -0
- package/dist/guess-salt.js +65 -0
- package/dist/hosted.js +24 -0
- package/dist/index.js +33 -0
- package/dist/join-color.js +140 -0
- package/dist/lessons-store.js +356 -0
- package/dist/live.js +287 -0
- package/dist/map-details.js +127 -0
- package/dist/map-stats.js +160 -0
- package/dist/map-store.js +242 -0
- package/dist/move-order.js +141 -0
- package/dist/my-games.js +218 -0
- package/dist/normalize.js +443 -0
- package/dist/notifications.js +143 -0
- package/dist/open-games.js +537 -0
- package/dist/outlook-log.js +165 -0
- package/dist/path-lock.js +22 -0
- package/dist/pick-list.js +193 -0
- package/dist/player-record-store.js +231 -0
- package/dist/player-states.js +31 -0
- package/dist/profile-store.js +727 -0
- package/dist/protocol/bundle.js +375 -0
- package/dist/protocol/codec.js +556 -0
- package/dist/protocol/decoded.js +12 -0
- package/dist/protocol/interp.js +1904 -0
- package/dist/protocol/methods.js +615 -0
- package/dist/protocol/rpc.js +202 -0
- package/dist/push/listener.js +393 -0
- package/dist/push/packets.js +66 -0
- package/dist/push/socketio.js +333 -0
- package/dist/push/websocket.js +179 -0
- package/dist/redact.js +62 -0
- package/dist/relations-store.js +242 -0
- package/dist/replay.js +227 -0
- package/dist/scalars.js +28 -0
- package/dist/scout.js +346 -0
- package/dist/stats.js +291 -0
- package/dist/strategy/card-clock.js +185 -0
- package/dist/strategy/map-notes.js +128 -0
- package/dist/strategy/notes.js +2223 -0
- package/dist/surrender-pending.js +126 -0
- package/dist/team-cards.js +84 -0
- package/dist/team-orders.js +150 -0
- package/dist/teams.js +19 -0
- package/dist/tools/accept-surrender.js +311 -0
- package/dist/tools/award.js +206 -0
- package/dist/tools/begin-turn.js +162 -0
- package/dist/tools/board.js +77 -0
- package/dist/tools/card-advice.js +256 -0
- package/dist/tools/card-effects.js +49 -0
- package/dist/tools/card-plays.js +434 -0
- package/dist/tools/card-support-advice.js +140 -0
- package/dist/tools/chat-inbox.js +158 -0
- package/dist/tools/chat-read-mark.js +179 -0
- package/dist/tools/chat.js +525 -0
- package/dist/tools/check-plan.js +689 -0
- package/dist/tools/commander-check.js +103 -0
- package/dist/tools/commitments.js +216 -0
- package/dist/tools/common.js +143 -0
- package/dist/tools/diplomacy.js +342 -0
- package/dist/tools/end-of-game.js +384 -0
- package/dist/tools/game.js +151 -0
- package/dist/tools/guess-view.js +56 -0
- package/dist/tools/healthcheck.js +90 -0
- package/dist/tools/hints.js +34 -0
- package/dist/tools/how-lost.js +154 -0
- package/dist/tools/index.js +152 -0
- package/dist/tools/join-game.js +327 -0
- package/dist/tools/leave-game.js +181 -0
- package/dist/tools/live-context.js +339 -0
- package/dist/tools/live.js +404 -0
- package/dist/tools/map-details.js +88 -0
- package/dist/tools/map-stats.js +130 -0
- package/dist/tools/map.js +141 -0
- package/dist/tools/my-games.js +193 -0
- package/dist/tools/notifications.js +484 -0
- package/dist/tools/open-games.js +104 -0
- package/dist/tools/opponents.js +163 -0
- package/dist/tools/order-options.js +135 -0
- package/dist/tools/past-games.js +94 -0
- package/dist/tools/picks.js +305 -0
- package/dist/tools/profile-hook.js +156 -0
- package/dist/tools/profile-opponents.js +121 -0
- package/dist/tools/profile-reads.js +99 -0
- package/dist/tools/push.js +445 -0
- package/dist/tools/relations.js +611 -0
- package/dist/tools/resolve.js +45 -0
- package/dist/tools/route.js +36 -0
- package/dist/tools/scout.js +87 -0
- package/dist/tools/session.js +163 -0
- package/dist/tools/strategy.js +257 -0
- package/dist/tools/stress-opponents.js +83 -0
- package/dist/tools/surrender-pending.js +74 -0
- package/dist/tools/surrender.js +247 -0
- package/dist/tools/survival.js +189 -0
- package/dist/tools/team-brief.js +266 -0
- package/dist/tools/team-source.js +222 -0
- package/dist/tools/team.js +178 -0
- package/dist/tools/turn.js +2825 -0
- package/dist/tools/uncommit.js +160 -0
- package/dist/tools/where.js +300 -0
- package/dist/tools/write-kit.js +164 -0
- package/dist/transport-bridge.js +33 -0
- package/dist/trend.js +577 -0
- package/dist/version.js +4 -0
- package/manifest.json +194 -4
- package/mint.yaml +106 -14
- package/package.json +11 -6
- package/server.json +40 -3
- package/skills/warapp-api/SKILL.md +95 -4
- package/skills/warapp-api/references/scout.mjs +348 -0
- package/skills/warapp-api/scripts/warapp.sh +69 -8
- package/skills/warapp-mcp/SKILL.md +1096 -21
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
// warapp_get_notifications, warapp_dismiss_notification and warapp_delete_notification (#311): war.app's
|
|
2
|
+
// in-app notifications (the client's "In App Notifications" screen), read with GetInAppNotifications (317),
|
|
3
|
+
// marked read with AcknowledgeInAppNotifications (319) and deleted with DeleteInAppNotification (318, the
|
|
4
|
+
// client's Delete button). All read from the client bundle, UNVERIFIED live (docs/WEB-PROTOCOL.md,
|
|
5
|
+
// Notifications and read marks).
|
|
6
|
+
//
|
|
7
|
+
// The list is name-free beyond ids: a notification's title and data are war.app's text with other
|
|
8
|
+
// players' names in it, read only to classify the notification and find the game its link names.
|
|
9
|
+
// A game-ended notification runs the end-of-game pass on that game (#312, src/tools/end-of-game.ts:
|
|
10
|
+
// idempotent, one history read per game, at most END_OF_GAME_PER_CALL per call), which folds its live
|
|
11
|
+
// profile too; then any kept opponent profile still unfolded is folded (B2, `foldFinishedGame`) — one
|
|
12
|
+
// GameFeed read (no map) only when one is kept unfolded, none otherwise.
|
|
13
|
+
//
|
|
14
|
+
// Dismissing marks read and never deletes; deleting is its own tool, one 318 per id, error 699 read as
|
|
15
|
+
// already gone. Neither sends anything to any player. Automated chat stays off (D2): neither is a send.
|
|
16
|
+
import { CONFIRM_INJECTION_RULE, toolAnnotations } from '@chrischall/mcp-utils';
|
|
17
|
+
import { z } from 'zod';
|
|
18
|
+
import { classifyNotification, readInAppNotifications } from '../notifications.js';
|
|
19
|
+
import { foldFinishedGame, hasUnfoldedProfile, profileEnabled } from '../profile-store.js';
|
|
20
|
+
import { END_OF_GAME_PER_CALL, endOfGame, finishedAccount, needsEndOfGame } from './end-of-game.js';
|
|
21
|
+
import { Method, NOTIFICATION_ID, NOTIFICATION_NOT_FOUND, NOTIFICATIONS_PAGE_SIZE, writeAcknowledgeInAppNotificationsParams, writeDeleteInAppNotificationParams, writeGetInAppNotificationsParams, } from '../protocol/methods.js';
|
|
22
|
+
import { notSent, WarappServerError } from '../protocol/rpc.js';
|
|
23
|
+
import { readAnnotations, respond, untrustedDescription } from './common.js';
|
|
24
|
+
import { mintMeta } from './hints.js';
|
|
25
|
+
import { requireApprovedAccount, writeAccount } from './live-context.js';
|
|
26
|
+
import { BRIDGE_NOTE } from './live.js';
|
|
27
|
+
import { defineGatedWrite, refuse, requireMe, sendAndVerify } from './write-kit.js';
|
|
28
|
+
/** Every answer says so: nothing here has been checked against a real reply. */
|
|
29
|
+
export const NOTIFICATIONS_UNVERIFIED = "Read from war.app's client code, UNVERIFIED live: the notification list, its fields and how a game-ended " +
|
|
30
|
+
'notification is recognised have not been checked against a real reply yet.';
|
|
31
|
+
/** The most games one list call reads from GameFeed to fold a kept profile. */
|
|
32
|
+
export const FOLD_LOOKUPS = 5;
|
|
33
|
+
/** The most pages a dismissal reads to find its ids (and to read them back). */
|
|
34
|
+
export const MAX_FIND_PAGES = 5;
|
|
35
|
+
/** The most ids one dismissal (or deletion) takes. */
|
|
36
|
+
export const MAX_DISMISS_IDS = NOTIFICATIONS_PAGE_SIZE;
|
|
37
|
+
/** One page of the account's notifications, from `start`. */
|
|
38
|
+
async function listPage(ctx, start) {
|
|
39
|
+
const env = await ctx.rpc.call('GetInAppNotifications', Method.GetInAppNotifications, (w) => writeGetInAppNotificationsParams(w, start));
|
|
40
|
+
return readInAppNotifications(await ctx.bundle(), env.body);
|
|
41
|
+
}
|
|
42
|
+
/** The notifications among `ids` the list holds, read page by page until all are found (at most MAX_FIND_PAGES). */
|
|
43
|
+
async function findNotifications(ctx, ids) {
|
|
44
|
+
const want = new Set(ids);
|
|
45
|
+
const found = new Map();
|
|
46
|
+
const positions = new Map();
|
|
47
|
+
let start = 0;
|
|
48
|
+
let total = 0;
|
|
49
|
+
let complete = false;
|
|
50
|
+
for (let page = 0; page < MAX_FIND_PAGES; page++) {
|
|
51
|
+
const listed = await listPage(ctx, start);
|
|
52
|
+
total = listed.total;
|
|
53
|
+
listed.items.forEach((n, i) => {
|
|
54
|
+
if (want.has(n.id) && !found.has(n.id)) {
|
|
55
|
+
found.set(n.id, n);
|
|
56
|
+
positions.set(n.id, start + i);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
start += listed.items.length;
|
|
60
|
+
if (listed.items.length === 0 || start >= total) {
|
|
61
|
+
complete = true;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
if (found.size === want.size)
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
return { found, positions, readTo: start, total, complete };
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* An id the read-back did not find is seen gone only when the pages read cover the whole list, or
|
|
71
|
+
* reach past where it stood when planned by as many notifications as the list has grown since (new
|
|
72
|
+
* ones arrive at the top and push it down). Otherwise it is simply not seen: never confirmed.
|
|
73
|
+
*/
|
|
74
|
+
export function seenGone(after, position, totalBefore) {
|
|
75
|
+
if (after.complete)
|
|
76
|
+
return true;
|
|
77
|
+
if (position === undefined)
|
|
78
|
+
return false;
|
|
79
|
+
return after.readTo > position + Math.max(0, after.total - totalBefore);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The end-of-game pass on each game a game-ended notification names (#312: the fourth trigger, beside
|
|
83
|
+
* warapp_get_game, warapp_wait_for_turn's read and the warapp_my_games sweep), through the same idempotent
|
|
84
|
+
* `endOfGame`: a game with a record or a processed mark costs nothing; at most `END_OF_GAME_PER_CALL` games
|
|
85
|
+
* that still need it per call, in the list's order (the rest are `pending`, for a later list call), each
|
|
86
|
+
* ONE history read (P2), folding its live profile too. The account is the board cache's, else the
|
|
87
|
+
* signed-in one (read at most once per call). Never throws.
|
|
88
|
+
*/
|
|
89
|
+
async function passEndedGames(ctx, env, games) {
|
|
90
|
+
const dir = ctx.dataDir;
|
|
91
|
+
const processed = [];
|
|
92
|
+
let pending = 0;
|
|
93
|
+
if (!dir || !profileEnabled(env))
|
|
94
|
+
return { processed, pending };
|
|
95
|
+
let token;
|
|
96
|
+
const identity = () => (token ??= ctx.myInviteToken().catch(() => undefined));
|
|
97
|
+
for (const gameId of games) {
|
|
98
|
+
const me = await finishedAccount(dir, env, gameId, identity);
|
|
99
|
+
if (me === undefined || !(await needsEndOfGame(dir, env, gameId, me)))
|
|
100
|
+
continue;
|
|
101
|
+
if (processed.length >= END_OF_GAME_PER_CALL) {
|
|
102
|
+
pending++;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const r = await endOfGame({ client: ctx.client, dataDir: dir, env }, gameId, me, undefined, { fold: true });
|
|
106
|
+
processed.push({ gameId, status: r.status, ...(r.turns !== undefined ? { turns: r.turns } : {}), ...(r.profileFold ? { profileFold: r.profileFold.status } : {}) });
|
|
107
|
+
}
|
|
108
|
+
return { processed, pending };
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Fold the kept opponent profile of each game a game-ended notification names (B2): only where a
|
|
112
|
+
* per-game file is kept unfolded, one GameFeed read (no map) per such game, at most FOLD_LOOKUPS.
|
|
113
|
+
* Runs after the end-of-game pass, which folds a game it reads itself (so that game costs no read here).
|
|
114
|
+
* Best effort: a failed read folds nothing and is never an error.
|
|
115
|
+
*/
|
|
116
|
+
async function foldEndedGames(ctx, env, games) {
|
|
117
|
+
const dir = ctx.dataDir;
|
|
118
|
+
if (!dir || !profileEnabled(env))
|
|
119
|
+
return [];
|
|
120
|
+
const out = [];
|
|
121
|
+
let lookups = 0;
|
|
122
|
+
for (const gameId of games) {
|
|
123
|
+
if (lookups >= FOLD_LOOKUPS)
|
|
124
|
+
break;
|
|
125
|
+
if (!(await hasUnfoldedProfile(dir, gameId)))
|
|
126
|
+
continue;
|
|
127
|
+
lookups++;
|
|
128
|
+
try {
|
|
129
|
+
const game = await ctx.client.getGame(gameId, { map: false });
|
|
130
|
+
const files = game.state === 'Finished' ? await foldFinishedGame(dir, game, env) : 0;
|
|
131
|
+
if (files > 0)
|
|
132
|
+
out.push({ gameId, files });
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
// Best effort: the next read that shows the game finished folds it.
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return out;
|
|
139
|
+
}
|
|
140
|
+
/** The games the game-ended notifications name, once each, in the list's order. */
|
|
141
|
+
const endedGames = (notes) => [
|
|
142
|
+
...new Set(notes.filter((n) => n.kind === 'game-ended' && n.gameId !== null).map((n) => n.gameId)),
|
|
143
|
+
];
|
|
144
|
+
const idArg = z.union([z.string(), z.number().int().nonnegative()]);
|
|
145
|
+
/** Clean, validated notification ids, or a refusal naming the bad ones. */
|
|
146
|
+
function askedIds(ids) {
|
|
147
|
+
const asked = [...new Set(ids.map((id) => String(id).trim()))];
|
|
148
|
+
const bad = asked.filter((id) => !NOTIFICATION_ID.test(id));
|
|
149
|
+
if (bad.length) {
|
|
150
|
+
refuse(`Not a notification id: ${bad.slice(0, 5).join(', ')}. Nothing was sent.`, 'Use the ids warapp_get_notifications lists.');
|
|
151
|
+
}
|
|
152
|
+
return asked;
|
|
153
|
+
}
|
|
154
|
+
export function registerNotificationTools(server, ctx, opts = {}) {
|
|
155
|
+
const env = opts.env ?? process.env;
|
|
156
|
+
server.registerTool('warapp_get_notifications', {
|
|
157
|
+
title: 'List my war.app notifications',
|
|
158
|
+
description: untrustedDescription("Your war.app (Warzone) in-app notifications (the client's notifications screen, war.app's " +
|
|
159
|
+
'GetInAppNotifications), 30 per page, by id only: each with `id` (what warapp_dismiss_notification takes), ' +
|
|
160
|
+
'`kind` (`game-ended` when the title is war.app\'s "Game … has ended." line, else `other`), `gameId` (the ' +
|
|
161
|
+
'game its link names, or null), `time` and `unread`. The title and body are never shown (they carry other ' +
|
|
162
|
+
"players' names). " +
|
|
163
|
+
'`total` is how many notifications war.app holds; pass `next` back as `start` for the next page; ' +
|
|
164
|
+
'`unread_only` keeps the unread ones of the page. A game-ended notification runs the end-of-game pass on ' +
|
|
165
|
+
'that game once (`endOfGame`: its history read once from GameFeed and kept name-free for later games, at most ' +
|
|
166
|
+
'two games per call, `pending` counting the rest; a game already processed costs nothing) and folds the ' +
|
|
167
|
+
'opponent profile kept for it (`profilesFolded`, or the pass entry\'s `profileFold`). Chat is not here: warapp_chat_inbox reads it. ' +
|
|
168
|
+
`${BRIDGE_NOTE} Read-only. ${NOTIFICATIONS_UNVERIFIED}`),
|
|
169
|
+
_meta: mintMeta('whats-new', ['notifications', 'war.app notifications', 'my alerts', 'did a game end']),
|
|
170
|
+
annotations: readAnnotations('List war.app notifications'),
|
|
171
|
+
inputSchema: z.object({
|
|
172
|
+
start: z.number().int().min(0).max(1_000_000).optional().describe('The paging offset (default 0, the newest page): `next` from the last answer.'),
|
|
173
|
+
unread_only: z.boolean().optional().describe('Show only the unread notifications of the page (default false).'),
|
|
174
|
+
}),
|
|
175
|
+
}, async ({ start, unread_only }) => {
|
|
176
|
+
const from = start ?? 0;
|
|
177
|
+
const { items, total } = await listPage(ctx, from);
|
|
178
|
+
const all = items.map(classifyNotification);
|
|
179
|
+
const notifications = unread_only ? all.filter((n) => n.unread) : all;
|
|
180
|
+
// #312: the end-of-game pass first (it folds the games it reads), then the fold of any kept profile left.
|
|
181
|
+
const ended = endedGames(all);
|
|
182
|
+
const passes = await passEndedGames(ctx, env, ended);
|
|
183
|
+
const profilesFolded = await foldEndedGames(ctx, env, ended);
|
|
184
|
+
const next = from + items.length < total && items.length > 0 ? from + items.length : undefined;
|
|
185
|
+
return respond(undefined, ['compact'], () => ({
|
|
186
|
+
notifications,
|
|
187
|
+
count: notifications.length,
|
|
188
|
+
unread: all.filter((n) => n.unread).length,
|
|
189
|
+
total,
|
|
190
|
+
...(next !== undefined ? { next } : {}),
|
|
191
|
+
...(profilesFolded.length ? { profilesFolded } : {}),
|
|
192
|
+
...(passes.processed.length || passes.pending ? { endOfGame: passes } : {}),
|
|
193
|
+
unverified: NOTIFICATIONS_UNVERIFIED,
|
|
194
|
+
}));
|
|
195
|
+
});
|
|
196
|
+
defineGatedWrite(server, {
|
|
197
|
+
title: 'Mark war.app notifications read',
|
|
198
|
+
_meta: mintMeta('change', ['dismiss notification', 'mark notification read', 'clear my notifications']),
|
|
199
|
+
}, {
|
|
200
|
+
name: 'warapp_dismiss_notification',
|
|
201
|
+
description: 'Mark one or several war.app (Warzone) in-app notifications read (war.app\'s AcknowledgeInAppNotifications), ' +
|
|
202
|
+
'by the ids warapp_get_notifications lists. It never deletes a notification (warapp_delete_notification does) ' +
|
|
203
|
+
'and sends nothing to any player. ' +
|
|
204
|
+
'Refuses ids war.app does not list and ids already read. Always as the signed-in war.app account; the outcome ' +
|
|
205
|
+
'is read back by listing again (`dismissed`; `unconfirmed` while one still reads unread or was not seen in the ' +
|
|
206
|
+
'pages read back; or `unknown` when ' +
|
|
207
|
+
`war.app did not answer — never resend blindly). ${NOTIFICATIONS_UNVERIFIED} ${BRIDGE_NOTE} ${CONFIRM_INJECTION_RULE}`,
|
|
208
|
+
annotations: toolAnnotations({
|
|
209
|
+
title: 'Mark war.app notifications read',
|
|
210
|
+
readOnly: false,
|
|
211
|
+
destructive: false,
|
|
212
|
+
idempotent: true,
|
|
213
|
+
openWorld: true,
|
|
214
|
+
}),
|
|
215
|
+
inputSchema: z.object({
|
|
216
|
+
ids: z
|
|
217
|
+
.array(idArg)
|
|
218
|
+
.min(1)
|
|
219
|
+
.max(MAX_DISMISS_IDS)
|
|
220
|
+
.describe('Notification ids from warapp_get_notifications (decimal text).'),
|
|
221
|
+
}),
|
|
222
|
+
async plan({ ids }) {
|
|
223
|
+
const asked = askedIds(ids);
|
|
224
|
+
const me = await requireMe(ctx);
|
|
225
|
+
const { found, positions, total } = await findNotifications(ctx, asked);
|
|
226
|
+
const missing = asked.filter((id) => !found.has(id));
|
|
227
|
+
if (missing.length) {
|
|
228
|
+
refuse(`war.app does not list notification ${missing.join(', ')}, so nothing was sent.`, 'List them again with warapp_get_notifications: it may already be deleted.');
|
|
229
|
+
}
|
|
230
|
+
const unread = asked.filter((id) => found.get(id).unread);
|
|
231
|
+
const alreadyRead = asked.filter((id) => !found.get(id).unread);
|
|
232
|
+
if (!unread.length) {
|
|
233
|
+
refuse(`Notification ${alreadyRead.join(', ')} is already read, so there is nothing to send.`, 'Check warapp_get_notifications.');
|
|
234
|
+
}
|
|
235
|
+
const shown = unread.map((id) => {
|
|
236
|
+
const n = classifyNotification(found.get(id));
|
|
237
|
+
return { id: n.id, kind: n.kind, gameId: n.gameId, time: n.time };
|
|
238
|
+
});
|
|
239
|
+
const label = unread.length === 1 ? `notification ${unread[0]}` : `${unread.length} notifications (${unread.join(', ')})`;
|
|
240
|
+
return {
|
|
241
|
+
gate: {
|
|
242
|
+
action: 'warapp.dismiss_notification',
|
|
243
|
+
// By id only: a notification's title and body are war.app's text with other players' names.
|
|
244
|
+
summary: `Mark war.app ${label} read`,
|
|
245
|
+
account: writeAccount(me),
|
|
246
|
+
target: unread.join(','),
|
|
247
|
+
payload: { method: 'AcknowledgeInAppNotifications', ids: unread },
|
|
248
|
+
willSend: { ids: unread },
|
|
249
|
+
preview: {
|
|
250
|
+
warning: `This marks ${label} read on war.app. Nothing is deleted and nothing reaches another player.`,
|
|
251
|
+
account: `war.app account ${me}`,
|
|
252
|
+
notifications: shown,
|
|
253
|
+
...(alreadyRead.length ? { alreadyRead } : {}),
|
|
254
|
+
unverified: NOTIFICATIONS_UNVERIFIED,
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
state: {
|
|
258
|
+
me,
|
|
259
|
+
ids: unread,
|
|
260
|
+
alreadyRead,
|
|
261
|
+
positions: Object.fromEntries(unread.map((id) => [id, positions.get(id)])),
|
|
262
|
+
totalBefore: total,
|
|
263
|
+
},
|
|
264
|
+
};
|
|
265
|
+
},
|
|
266
|
+
async execute({ me, ids, alreadyRead, positions, totalBefore }) {
|
|
267
|
+
await requireApprovedAccount(ctx, writeAccount(me));
|
|
268
|
+
const base = { ids, ...(alreadyRead.length ? { alreadyRead } : {}) };
|
|
269
|
+
const check = 'Check warapp_get_notifications before doing anything else.';
|
|
270
|
+
return sendAndVerify({
|
|
271
|
+
send: async () => {
|
|
272
|
+
await ctx.rpc.call('AcknowledgeInAppNotifications', Method.AcknowledgeInAppNotifications, (w) => writeAcknowledgeInAppNotificationsParams(w, ids));
|
|
273
|
+
},
|
|
274
|
+
unanswered: (failure) => ({
|
|
275
|
+
status: 'unknown',
|
|
276
|
+
outcome: 'unknown',
|
|
277
|
+
...base,
|
|
278
|
+
warning: `war.app did not confirm (${failure}), so the notifications may already be marked read. ${check}`,
|
|
279
|
+
}),
|
|
280
|
+
readBack: () => findNotifications(ctx, ids),
|
|
281
|
+
unreadable: (failure) => ({
|
|
282
|
+
status: 'unconfirmed',
|
|
283
|
+
outcome: 'unconfirmed',
|
|
284
|
+
...base,
|
|
285
|
+
warning: `war.app accepted the request, but the list could not be read back (${failure}). ${check}`,
|
|
286
|
+
}),
|
|
287
|
+
classify: (after) => {
|
|
288
|
+
// Read on the list, or seen gone from it (deleted): no longer unread. Not found where the pages
|
|
289
|
+
// read could not tell: not seen, so never confirmed.
|
|
290
|
+
const stillUnread = ids.filter((id) => after.found.get(id)?.unread === true);
|
|
291
|
+
const dismissed = ids.filter((id) => after.found.get(id)?.unread === false);
|
|
292
|
+
const missing = ids.filter((id) => !after.found.has(id));
|
|
293
|
+
const gone = missing.filter((id) => seenGone(after, positions[id], totalBefore));
|
|
294
|
+
const notSeen = missing.filter((id) => !gone.includes(id));
|
|
295
|
+
const parts = {
|
|
296
|
+
...(dismissed.length ? { dismissed } : {}),
|
|
297
|
+
...(gone.length ? { gone } : {}),
|
|
298
|
+
};
|
|
299
|
+
if (!stillUnread.length && !notSeen.length) {
|
|
300
|
+
return { status: 'dismissed', outcome: 'confirmed', ...base, ...parts };
|
|
301
|
+
}
|
|
302
|
+
const problems = [
|
|
303
|
+
...(stillUnread.length ? [`the list still shows ${stillUnread.join(', ')} unread`] : []),
|
|
304
|
+
...(notSeen.length
|
|
305
|
+
? [`${notSeen.join(', ')} ${notSeen.length === 1 ? 'was' : 'were'} not seen in the pages read (${after.readTo} of ${after.total})`]
|
|
306
|
+
: []),
|
|
307
|
+
];
|
|
308
|
+
return {
|
|
309
|
+
status: 'unconfirmed',
|
|
310
|
+
outcome: 'unconfirmed',
|
|
311
|
+
...base,
|
|
312
|
+
...parts,
|
|
313
|
+
...(stillUnread.length ? { stillUnread } : {}),
|
|
314
|
+
...(notSeen.length ? { notSeen } : {}),
|
|
315
|
+
warning: `war.app accepted the request, but ${problems.join(', and ')}. ${check}`,
|
|
316
|
+
};
|
|
317
|
+
},
|
|
318
|
+
});
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
defineGatedWrite(server, {
|
|
322
|
+
title: 'Delete war.app notifications',
|
|
323
|
+
_meta: mintMeta('change', ['delete notification', 'remove notification', 'clear old notifications']),
|
|
324
|
+
}, {
|
|
325
|
+
name: 'warapp_delete_notification',
|
|
326
|
+
description: "Delete one or several war.app (Warzone) in-app notifications (war.app's DeleteInAppNotification, the client's " +
|
|
327
|
+
'Delete button), by the ids warapp_get_notifications lists, read or unread: one request per id, in order. A ' +
|
|
328
|
+
'deleted notification is gone from war.app for good; it sends nothing to any player (to keep it and only clear ' +
|
|
329
|
+
'its unread mark, use warapp_dismiss_notification). Refuses ids war.app does not list. Always as the signed-in ' +
|
|
330
|
+
'war.app account; an id war.app no longer holds when sent (its error 699) counts as already gone (`alreadyGone`). ' +
|
|
331
|
+
'The outcome is read back by listing again (`deleted`; `unconfirmed` while one is still listed, was not seen in ' +
|
|
332
|
+
'the pages read back, or war.app refused one — the ids after a refusal are not sent; or `unknown` when war.app ' +
|
|
333
|
+
`did not answer — never resend blindly). ${NOTIFICATIONS_UNVERIFIED} ${BRIDGE_NOTE} ${CONFIRM_INJECTION_RULE}`,
|
|
334
|
+
annotations: toolAnnotations({
|
|
335
|
+
title: 'Delete war.app notifications',
|
|
336
|
+
readOnly: false,
|
|
337
|
+
destructive: true,
|
|
338
|
+
idempotent: true,
|
|
339
|
+
openWorld: true,
|
|
340
|
+
}),
|
|
341
|
+
inputSchema: z.object({
|
|
342
|
+
ids: z
|
|
343
|
+
.array(idArg)
|
|
344
|
+
.min(1)
|
|
345
|
+
.max(MAX_DISMISS_IDS)
|
|
346
|
+
.describe('Notification ids from warapp_get_notifications (decimal text).'),
|
|
347
|
+
}),
|
|
348
|
+
async plan({ ids }) {
|
|
349
|
+
const asked = askedIds(ids);
|
|
350
|
+
const me = await requireMe(ctx);
|
|
351
|
+
const { found, positions, total } = await findNotifications(ctx, asked);
|
|
352
|
+
const missing = asked.filter((id) => !found.has(id));
|
|
353
|
+
if (missing.length) {
|
|
354
|
+
refuse(`war.app does not list notification ${missing.join(', ')}, so nothing was sent.`, 'List them again with warapp_get_notifications: it may already be deleted.');
|
|
355
|
+
}
|
|
356
|
+
const shown = asked.map((id) => {
|
|
357
|
+
const n = classifyNotification(found.get(id));
|
|
358
|
+
return { id: n.id, kind: n.kind, gameId: n.gameId, time: n.time, unread: n.unread };
|
|
359
|
+
});
|
|
360
|
+
const label = asked.length === 1 ? `notification ${asked[0]}` : `${asked.length} notifications (${asked.join(', ')})`;
|
|
361
|
+
return {
|
|
362
|
+
gate: {
|
|
363
|
+
action: 'warapp.delete_notification',
|
|
364
|
+
// By id only: a notification's title and body are war.app's text with other players' names.
|
|
365
|
+
summary: `Delete war.app ${label}`,
|
|
366
|
+
account: writeAccount(me),
|
|
367
|
+
target: asked.join(','),
|
|
368
|
+
payload: { method: 'DeleteInAppNotification', ids: asked },
|
|
369
|
+
willSend: { ids: asked },
|
|
370
|
+
preview: {
|
|
371
|
+
warning: `This deletes ${label} from your war.app notifications; it cannot be undone. Nothing reaches another player.`,
|
|
372
|
+
account: `war.app account ${me}`,
|
|
373
|
+
notifications: shown,
|
|
374
|
+
unverified: NOTIFICATIONS_UNVERIFIED,
|
|
375
|
+
},
|
|
376
|
+
},
|
|
377
|
+
state: {
|
|
378
|
+
me,
|
|
379
|
+
ids: asked,
|
|
380
|
+
positions: Object.fromEntries(asked.map((id) => [id, positions.get(id)])),
|
|
381
|
+
totalBefore: total,
|
|
382
|
+
},
|
|
383
|
+
};
|
|
384
|
+
},
|
|
385
|
+
async execute({ me, ids, positions, totalBefore }) {
|
|
386
|
+
await requireApprovedAccount(ctx, writeAccount(me));
|
|
387
|
+
const check = 'Check warapp_get_notifications before doing anything else.';
|
|
388
|
+
const sends = { sent: [], alreadyGone: [], notSent: [] };
|
|
389
|
+
const progress = () => ({
|
|
390
|
+
...(sends.alreadyGone.length ? { alreadyGone: sends.alreadyGone } : {}),
|
|
391
|
+
...(sends.refused ? { refused: sends.refused } : {}),
|
|
392
|
+
...(sends.notSent.length ? { notSent: sends.notSent } : {}),
|
|
393
|
+
});
|
|
394
|
+
return sendAndVerify({
|
|
395
|
+
// One request per id, in order, never retried. A refusal (other than 699), no answer or a request that
|
|
396
|
+
// could not be sent stops there: the ids after it are not sent. A refusal or an unsent request before
|
|
397
|
+
// anything changed is an error; after, it is reported and the read-back judges what did change.
|
|
398
|
+
send: async () => {
|
|
399
|
+
for (const [i, id] of ids.entries()) {
|
|
400
|
+
try {
|
|
401
|
+
await ctx.rpc.call('DeleteInAppNotification', Method.DeleteInAppNotification, (w) => writeDeleteInAppNotificationParams(w, id));
|
|
402
|
+
sends.sent.push(id);
|
|
403
|
+
}
|
|
404
|
+
catch (e) {
|
|
405
|
+
if (e instanceof WarappServerError && e.code === NOTIFICATION_NOT_FOUND) {
|
|
406
|
+
sends.alreadyGone.push(id);
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
sends.notSent = ids.slice(i + 1);
|
|
410
|
+
const changed = sends.sent.length + sends.alreadyGone.length > 0;
|
|
411
|
+
if (changed && notSent(e)) {
|
|
412
|
+
// Never "nothing changed": earlier ids went. This one never left, so it is not sent either.
|
|
413
|
+
sends.unsent = id;
|
|
414
|
+
sends.notSent = ids.slice(i);
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
if (e instanceof WarappServerError) {
|
|
418
|
+
if (!changed)
|
|
419
|
+
throw e;
|
|
420
|
+
sends.refused = { id, code: e.code };
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
sends.unanswered = id;
|
|
424
|
+
throw e;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
},
|
|
428
|
+
unanswered: (failure) => ({
|
|
429
|
+
status: 'unknown',
|
|
430
|
+
outcome: 'unknown',
|
|
431
|
+
ids,
|
|
432
|
+
...(sends.sent.length ? { sent: sends.sent } : {}),
|
|
433
|
+
...(sends.unanswered ? { unanswered: sends.unanswered } : {}),
|
|
434
|
+
...progress(),
|
|
435
|
+
warning: `war.app did not confirm (${failure}), so notification ${sends.unanswered ?? ids[0]} may already be deleted` +
|
|
436
|
+
`${sends.notSent.length ? `; ${sends.notSent.join(', ')} ${sends.notSent.length === 1 ? 'was' : 'were'} not sent` : ''}. ${check}`,
|
|
437
|
+
}),
|
|
438
|
+
readBack: () => findNotifications(ctx, ids),
|
|
439
|
+
unreadable: (failure) => ({
|
|
440
|
+
status: 'unconfirmed',
|
|
441
|
+
outcome: 'unconfirmed',
|
|
442
|
+
ids,
|
|
443
|
+
...(sends.sent.length ? { sent: sends.sent } : {}),
|
|
444
|
+
...progress(),
|
|
445
|
+
warning: `war.app accepted the request, but the list could not be read back (${failure}). ${check}`,
|
|
446
|
+
}),
|
|
447
|
+
classify: (after) => {
|
|
448
|
+
// Each id sent (or already gone) is deleted only once seen gone; one still listed, or not found where
|
|
449
|
+
// the pages read could not tell, is not confirmed.
|
|
450
|
+
const tried = [...sends.sent, ...sends.alreadyGone];
|
|
451
|
+
const stillListed = tried.filter((id) => after.found.has(id));
|
|
452
|
+
const missing = tried.filter((id) => !after.found.has(id));
|
|
453
|
+
const gone = missing.filter((id) => seenGone(after, positions[id], totalBefore));
|
|
454
|
+
const notSeen = missing.filter((id) => !gone.includes(id));
|
|
455
|
+
const deleted = gone.filter((id) => sends.sent.includes(id));
|
|
456
|
+
const parts = { ids, ...(deleted.length ? { deleted } : {}), ...progress() };
|
|
457
|
+
if (!stillListed.length && !notSeen.length && !sends.refused && !sends.unsent) {
|
|
458
|
+
return { status: 'deleted', outcome: 'confirmed', ...parts };
|
|
459
|
+
}
|
|
460
|
+
const problems = [
|
|
461
|
+
...(sends.refused
|
|
462
|
+
? [`war.app refused ${sends.refused.id} (error ${sends.refused.code})${sends.notSent.length ? `, so ${sends.notSent.join(', ')} ${sends.notSent.length === 1 ? 'was' : 'were'} not sent` : ''}`]
|
|
463
|
+
: []),
|
|
464
|
+
...(sends.unsent
|
|
465
|
+
? [sends.notSent.length > 1 ? `${sends.unsent} could not be sent, so ${sends.notSent.slice(1).join(', ')} ${sends.notSent.length === 2 ? 'was' : 'were'} not sent either` : `${sends.unsent} could not be sent`]
|
|
466
|
+
: []),
|
|
467
|
+
...(stillListed.length ? [`the list still holds ${stillListed.join(', ')}`] : []),
|
|
468
|
+
...(notSeen.length
|
|
469
|
+
? [`${notSeen.join(', ')} ${notSeen.length === 1 ? 'was' : 'were'} not seen in the pages read (${after.readTo} of ${after.total})`]
|
|
470
|
+
: []),
|
|
471
|
+
];
|
|
472
|
+
return {
|
|
473
|
+
status: 'unconfirmed',
|
|
474
|
+
outcome: 'unconfirmed',
|
|
475
|
+
...parts,
|
|
476
|
+
...(stillListed.length ? { stillListed } : {}),
|
|
477
|
+
...(notSeen.length ? { notSeen } : {}),
|
|
478
|
+
warning: `${problems.join(', and ')}. ${check}`,
|
|
479
|
+
};
|
|
480
|
+
},
|
|
481
|
+
});
|
|
482
|
+
},
|
|
483
|
+
});
|
|
484
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// warapp_list_open_games: the open games war.app's OpenGames page lists, decoded
|
|
2
|
+
// from the page's embedded payload (src/open-games.ts) — a page GET, so it works
|
|
3
|
+
// over the direct transport with no browser. Read-only.
|
|
4
|
+
import { McpToolError } from '@chrischall/mcp-utils';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { filterOpenGames, joiningPolicy, lotteryOf, lotteryShape, markJoined, withLottery, OPEN_GAMES_URL, parseOpenGamesPage, } from '../open-games.js';
|
|
7
|
+
import { readAnnotations, respond, untrustedDescription } from './common.js';
|
|
8
|
+
import { noBrowserNote } from './session.js';
|
|
9
|
+
import { lookupMeta } from './hints.js';
|
|
10
|
+
/** The OpenGames page as text, or a tool error with a hint. */
|
|
11
|
+
export async function openGamesPage(ctx) {
|
|
12
|
+
try {
|
|
13
|
+
return await ctx.fetchPage(OPEN_GAMES_URL);
|
|
14
|
+
}
|
|
15
|
+
catch (e) {
|
|
16
|
+
throw new McpToolError(`Could not read war.app's open games page: ${e instanceof Error ? e.message : String(e)}`, {
|
|
17
|
+
kind: 'unknown',
|
|
18
|
+
hint: (ctx.hosted ? 'Make sure' : 'Link a session with warapp_link_session to read it without a browser, or make sure') +
|
|
19
|
+
' a signed-in war.app tab is open and paired (reload or focus it if it is frozen), then retry.',
|
|
20
|
+
cause: e,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** At most this many lobbies' maps are fetched from GameFeed per call to tell a lottery (#217). */
|
|
25
|
+
export const LOTTERY_LOOKUPS = 5;
|
|
26
|
+
/** A lobby's map size: the cached map, else (when `fetch`) GameFeed's; undefined when unread. */
|
|
27
|
+
async function territoryCount(ctx, game, fetch) {
|
|
28
|
+
const cached = ctx.client.cachedMap(game.mapId);
|
|
29
|
+
if (cached)
|
|
30
|
+
return cached.territories.length;
|
|
31
|
+
if (!fetch)
|
|
32
|
+
return undefined;
|
|
33
|
+
try {
|
|
34
|
+
return (await ctx.client.getGame(game.id))?.map?.territories.length;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* `games` with `lottery` / `lotteryBasis` set where the data says so (#217, {@link lotteryOf}): a
|
|
42
|
+
* cached map is used for every game; GameFeed is asked (map included) only for lobbies whose
|
|
43
|
+
* settings fit the lottery shape, at most {@link LOTTERY_LOOKUPS} per call. Never throws.
|
|
44
|
+
*/
|
|
45
|
+
export async function markLotteries(ctx, games) {
|
|
46
|
+
let lookups = 0;
|
|
47
|
+
const fetchFor = games.map((g) => lotteryShape(g) && !ctx.client.cachedMap(g.mapId) && lookups++ < LOTTERY_LOOKUPS);
|
|
48
|
+
return Promise.all(games.map(async (g, i) => {
|
|
49
|
+
const verdict = lotteryOf(g, await territoryCount(ctx, g, fetchFor[i]));
|
|
50
|
+
return verdict ? withLottery(g, verdict) : g;
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
export function registerOpenGamesTool(server, ctx) {
|
|
54
|
+
server.registerTool('warapp_list_open_games', {
|
|
55
|
+
title: 'List open war.app games to join',
|
|
56
|
+
description: untrustedDescription('Open war.app (Warzone) games you could join, from war.app\'s Open Games page: each with its id, name, url, ' +
|
|
57
|
+
'pace (multi-day or real-time), boot time, players seated, open seats, seats in all, team game or not, ' +
|
|
58
|
+
'map id, entry fee and prize in coins, cards, rules (the settings flags the game carries, in war.app\'s ' +
|
|
59
|
+
'wording) and plannerGaps — rules the turn planner does not model yet. joined: true marks a game you ' +
|
|
60
|
+
'already hold a seat in (when the signed-in account can be told). By default only free, multi-day, ' +
|
|
61
|
+
'no-team games. policyBreaks lists the joining-policy rules a game breaks (Commerce, mods, custom ' +
|
|
62
|
+
'scenarios, more than four seats, a boot time under 12 hours, a lottery (a likely one too)); the neutral cost is checked by ' +
|
|
63
|
+
'warapp_join_game\'s preview. lottery: true marks a lottery from the data, never the name — a map of at ' +
|
|
64
|
+
'most four territories (its size read from GameFeed for lobbies with base income 0 and overridden ' +
|
|
65
|
+
'bonuses, or from a map already cached); lottery: null is that settings shape with the map size unread; ' +
|
|
66
|
+
'lotteryBasis says which. hiddenByPrerequisites counts games war.app hides from this account.' +
|
|
67
|
+
`${noBrowserNote(ctx.hosted)} Read-only.`),
|
|
68
|
+
_meta: lookupMeta(['open games', 'find a game', 'join a game', 'new warzone game', 'games to join']),
|
|
69
|
+
annotations: readAnnotations('List open war.app games'),
|
|
70
|
+
inputSchema: z.object({
|
|
71
|
+
pace: z
|
|
72
|
+
.enum(['multi-day', 'real-time', 'both'])
|
|
73
|
+
.optional()
|
|
74
|
+
.describe('Game pace (default multi-day).'),
|
|
75
|
+
max_players: z.number().int().positive().optional().describe('At most this many seats in the game.'),
|
|
76
|
+
free_only: z.boolean().optional().describe('Only games without a coin entry fee (default true).'),
|
|
77
|
+
exclude_teams: z.boolean().optional().describe('Leave out team games (default true).'),
|
|
78
|
+
limit: z.number().int().positive().max(200).optional().describe('At most this many games (default 25).'),
|
|
79
|
+
}),
|
|
80
|
+
}, async ({ pace, max_players, free_only, exclude_teams, limit }) => {
|
|
81
|
+
const [html, myId] = await Promise.all([openGamesPage(ctx), ctx.myInGameId()]);
|
|
82
|
+
const parsed = parseOpenGamesPage(html, await ctx.bundle());
|
|
83
|
+
const marked = myId === undefined ? parsed.games : markJoined(parsed.games, parsed.lobbies, myId);
|
|
84
|
+
const filtered = filterOpenGames(marked, {
|
|
85
|
+
...(pace ? { pace } : {}),
|
|
86
|
+
...(max_players !== undefined ? { max_players } : {}),
|
|
87
|
+
...(free_only !== undefined ? { free_only } : {}),
|
|
88
|
+
...(exclude_teams !== undefined ? { exclude_teams } : {}),
|
|
89
|
+
limit: limit ?? 25,
|
|
90
|
+
});
|
|
91
|
+
// #134: advisory — the neutral-cost part needs each lobby's GameFeed settings, so only the join preview has it.
|
|
92
|
+
const games = (await markLotteries(ctx, filtered)).map((g) => {
|
|
93
|
+
const { breaks } = joiningPolicy(g, null);
|
|
94
|
+
return breaks.length ? { ...g, policyBreaks: breaks } : g;
|
|
95
|
+
});
|
|
96
|
+
return respond(undefined, ['compact'], () => ({
|
|
97
|
+
games,
|
|
98
|
+
count: games.length,
|
|
99
|
+
listed: parsed.games.length,
|
|
100
|
+
...(parsed.hiddenByPrerequisites !== undefined ? { hiddenByPrerequisites: parsed.hiddenByPrerequisites } : {}),
|
|
101
|
+
...(parsed.note ? { warning: parsed.note } : {}),
|
|
102
|
+
}));
|
|
103
|
+
});
|
|
104
|
+
}
|