@chrischall/warapp-mcp 0.22.1 → 0.23.1
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 +3 -3
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +49 -3
- package/dist/analysis/coalition.js +3 -2
- package/dist/analysis/outlook.js +42 -2
- package/dist/analysis/plan/captures.js +3 -1
- package/dist/analysis/plan/relations.js +1 -1
- package/dist/analysis/plan/report.js +2 -2
- package/dist/analysis/plan/targets.js +48 -12
- package/dist/analysis/plan/threats.js +55 -2
- package/dist/analysis/planner.js +2 -1
- package/dist/analysis/relations.js +40 -7
- package/dist/bundle.js +10250 -3744
- package/dist/chat.js +93 -3
- package/dist/clans.js +308 -0
- package/dist/forums.js +70 -0
- package/dist/friends.js +83 -0
- package/dist/index.js +1 -1
- package/dist/invite-code.js +46 -0
- package/dist/join-color.js +23 -13
- package/dist/ladders.js +360 -0
- package/dist/mail.js +295 -0
- package/dist/my-games.js +18 -1
- package/dist/notifications.js +22 -4
- package/dist/open-games.js +29 -2
- package/dist/outlook-log.js +1 -0
- package/dist/protocol/bundle.js +4 -4
- package/dist/protocol/codec.js +1 -1
- package/dist/protocol/methods.js +690 -8
- package/dist/protocol/rpc.js +28 -3
- package/dist/push/socketio.js +2 -2
- package/dist/quickmatch.js +264 -0
- package/dist/surrender-pending.js +62 -2
- package/dist/templates.js +451 -0
- package/dist/tools/boot-player.js +165 -0
- package/dist/tools/calibration-harness.js +8 -1
- package/dist/tools/calibration.js +14 -2
- package/dist/tools/chat.js +19 -0
- package/dist/tools/clan-writes.js +208 -0
- package/dist/tools/clans.js +181 -0
- package/dist/tools/end-game-common.js +49 -0
- package/dist/tools/forums.js +535 -0
- package/dist/tools/friends.js +50 -0
- package/dist/tools/game.js +21 -3
- package/dist/tools/index.js +39 -0
- package/dist/tools/invites.js +347 -0
- package/dist/tools/join-game.js +4 -4
- package/dist/tools/ladders.js +418 -0
- package/dist/tools/leave-game.js +85 -27
- package/dist/tools/live-context.js +2 -2
- package/dist/tools/mail.js +600 -0
- package/dist/tools/my-games.js +50 -6
- package/dist/tools/notifications.js +12 -3
- package/dist/tools/nudge.js +178 -0
- package/dist/tools/quickmatch.js +481 -0
- package/dist/tools/react.js +177 -0
- package/dist/tools/relations.js +3 -2
- package/dist/tools/session.js +6 -2
- package/dist/tools/team-surrender.js +206 -0
- package/dist/tools/templates.js +342 -0
- package/dist/tools/tournaments.js +495 -0
- package/dist/tools/turn.js +4 -1
- package/dist/tools/vote-to-end.js +142 -0
- package/dist/tools/write-kit.js +22 -1
- package/dist/tournaments.js +321 -0
- package/dist/trend.js +1 -0
- package/dist/version.js +1 -1
- package/manifest.json +190 -2
- package/mint.yaml +3 -4
- package/package.json +1 -1
- package/server.json +2 -2
- package/skills/warapp-mcp/SKILL.md +39 -6
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
// Quickmatch (#638): read my quickmatch settings, the templates and their votes, and the leaderboards; change which
|
|
2
|
+
// templates I play and how many multi-day games war.app may start for me, and vote for templates — the last two
|
|
3
|
+
// confirm-gated. Read from the 6.09 client bundle, UNVERIFIED live (docs/WEB-PROTOCOL.md, "Quickmatch").
|
|
4
|
+
//
|
|
5
|
+
// The real-time queue (QuickmatchRTRequest 275, StillWaiting 278, Cancel 279) is left out: the owner plays
|
|
6
|
+
// multi-day only. CheckQuickmatchMD (270) has no writer in the client, so it is never sent.
|
|
7
|
+
//
|
|
8
|
+
// Multi-day quickmatch is a standing commitment: with a game count above 0, war.app starts multi-day games for me
|
|
9
|
+
// on its own, on the templates I marked, with no further confirmation. The settings write's preview says how many
|
|
10
|
+
// games that is and where it is turned off.
|
|
11
|
+
import { CONFIRM_INJECTION_RULE, toolAnnotations } from '@chrischall/mcp-utils';
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
import { Method, QUICKMATCH_LEADERBOARD_PAGE, QUICKMATCH_TEMPLATE_SETTINGS, writeGetQuickmatchLeaderboardsParams, writeGetQuickmatchTemplatesParams, writeGetQuickmatchTemplateVotesParams, writeGetTemplateLengthsParams, writeSetQuickmatchSettingsParams, writeSetQuickmatchTemplateVotesParams, } from '../protocol/methods.js';
|
|
14
|
+
import { QUICKMATCH_SPEEDS, readLeaderboard, readQuickmatchSettings, readQuickmatchTemplates, readTemplateLengths, readTemplateVoters, settingName, settingPlays, } from '../quickmatch.js';
|
|
15
|
+
import { inGameId } from '../live.js';
|
|
16
|
+
import { readAnnotations, respond, shownAccount, UNTRUSTED_PREVIEW_NOTE, untrustedDescription, untrustedText } from './common.js';
|
|
17
|
+
import { mintMeta } from './hints.js';
|
|
18
|
+
import { failureText, requireApprovedAccount, writeAccount } from './live-context.js';
|
|
19
|
+
import { BRIDGE_NOTE } from './live.js';
|
|
20
|
+
import { defineGatedWrite, refuse, requireMe, sendAndVerify, worded } from './write-kit.js';
|
|
21
|
+
/** Every answer says so: nothing here has been checked against a real reply. */
|
|
22
|
+
export const QUICKMATCH_UNVERIFIED = "Read from war.app's client code, UNVERIFIED live: the quickmatch calls and their layouts have not been checked against " +
|
|
23
|
+
'a real reply yet.';
|
|
24
|
+
/** Where multi-day quickmatch is turned off. */
|
|
25
|
+
export const QUICKMATCH_OFF = 'Turn it off with warapp_set_quickmatch_settings and multi_day_games: 0, or on war.app under Multiplayer → Quickmatch ' +
|
|
26
|
+
'(https://war.app/MultiPlayer?Quickmatch=1) by unticking "Invite me to games".';
|
|
27
|
+
/** The most multi-day games the client lets the count reach. */
|
|
28
|
+
export const MAX_MULTI_DAY_GAMES = 10;
|
|
29
|
+
/** The client's refusals for quickmatch calls, worded from the codes' names (read from the bundle, UNVERIFIED live). */
|
|
30
|
+
const QUICKMATCH_ERRORS = {
|
|
31
|
+
603: "war.app has no quickmatch settings for this account yet (QuickmatchPlayerSettingsKeyNotFound): open war.app's Quickmatch page once.",
|
|
32
|
+
606: 'war.app found no vote of yours on that template (QuickmatchTemplateVoteKeyNotFound).',
|
|
33
|
+
607: 'war.app has no quickmatch template with that id (QuickmatchTemplateKeyNotFound).',
|
|
34
|
+
608: 'war.app says that quickmatch template is locked or no longer valid (QuickmatchTemplateLockedOrInvalid).',
|
|
35
|
+
614: "You don't have enough quickmatch votes available for that (NotEnoughQuickmatchVotes): nothing changed.",
|
|
36
|
+
};
|
|
37
|
+
const SETTING_KEYS = Object.keys(QUICKMATCH_TEMPLATE_SETTINGS);
|
|
38
|
+
async function readSettings(ctx) {
|
|
39
|
+
const env = await ctx.rpc.call('GetQuickmatchSettings', Method.GetQuickmatchSettings);
|
|
40
|
+
return readQuickmatchSettings(await ctx.bundle(), env.body);
|
|
41
|
+
}
|
|
42
|
+
async function readTemplates(ctx) {
|
|
43
|
+
const env = await ctx.rpc.call('GetQuickmatchTemplates', Method.GetQuickmatchTemplates, (w) => writeGetQuickmatchTemplatesParams(w));
|
|
44
|
+
return readQuickmatchTemplates(await ctx.bundle(), env.body);
|
|
45
|
+
}
|
|
46
|
+
/** The settings must be the signed-in account's own, or nothing is changed. */
|
|
47
|
+
function requireOwnSettings(settings, me) {
|
|
48
|
+
const mine = inGameId({ id: me });
|
|
49
|
+
if (settings.playerId !== mine) {
|
|
50
|
+
refuse(`war.app answered with quickmatch settings for in-game player ${settings.playerId}, not the signed-in account (in-game ` +
|
|
51
|
+
`player ${mine}, GameFeed id ${me}), so nothing was sent.`, 'Check which account the war.app tab or session is signed in to.');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const shownName = (name) => (name === null || name === undefined ? null : untrustedText(name));
|
|
55
|
+
/** A template's setting as reported: the setting, and whether it plays real-time and multi-day games. */
|
|
56
|
+
function templateView(setting) {
|
|
57
|
+
return { setting: settingName(setting) ?? 'off', realTime: settingPlays(setting, true), multiDay: settingPlays(setting, false) };
|
|
58
|
+
}
|
|
59
|
+
function settingsView(s) {
|
|
60
|
+
return {
|
|
61
|
+
wins: s.wins,
|
|
62
|
+
templateRank: s.templateRank,
|
|
63
|
+
votesUnlocked: s.votesUnlocked,
|
|
64
|
+
multiDay: { games: s.multiDayGames, on: s.multiDayGames > 0 },
|
|
65
|
+
coins: s.coins,
|
|
66
|
+
newTemplatesOnByDefault: s.newTemplatesOnByDefault,
|
|
67
|
+
speed: QUICKMATCH_SPEEDS[s.speed] ?? s.speed,
|
|
68
|
+
ratings: s.ratings,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function registerSettingsRead(server, ctx) {
|
|
72
|
+
server.registerTool('warapp_quickmatch_settings', {
|
|
73
|
+
title: 'Read my war.app quickmatch settings',
|
|
74
|
+
description: untrustedDescription("Your war.app (Warzone) quickmatch settings (war.app's GetQuickmatchSettings): quickmatch wins, templates and votes " +
|
|
75
|
+
'unlocked, `multiDay.games` — how many multi-day quickmatch games war.app may start for you on its own (0: off) — the ' +
|
|
76
|
+
'coin wager range, the real-time speed and your ratings (global, real-time, multi-day, 1v1, team, free-for-all and per ' +
|
|
77
|
+
'template; never the per-country one). `templates` lists the templates you have unlocked by id, name (delimited) and ' +
|
|
78
|
+
'map id, each with its `setting` (`on`, `off`, `real_time_only`, `multi_day_only`); `lengths: true` adds each one\'s ' +
|
|
79
|
+
`average game length in minutes (war.app's GetTemplateLengths). ${BRIDGE_NOTE} Read-only. ${QUICKMATCH_UNVERIFIED}`),
|
|
80
|
+
_meta: mintMeta('lookup', ['quickmatch settings', 'my quickmatch templates', 'multi-day quickmatch', 'quickmatch rating']),
|
|
81
|
+
annotations: readAnnotations('Read war.app quickmatch settings'),
|
|
82
|
+
inputSchema: z.object({
|
|
83
|
+
lengths: z.boolean().optional().describe("true to add each template's average game length (one more request); default false."),
|
|
84
|
+
}),
|
|
85
|
+
}, async ({ lengths }) => {
|
|
86
|
+
const { settings, unlocked } = await readSettings(ctx);
|
|
87
|
+
let minutes;
|
|
88
|
+
let lengthsNote;
|
|
89
|
+
if (lengths === true && unlocked.length > 0) {
|
|
90
|
+
try {
|
|
91
|
+
const env = await ctx.rpc.call('GetTemplateLengths', Method.GetTemplateLengths, (w) => writeGetTemplateLengthsParams(w, unlocked.map((t) => t.id)));
|
|
92
|
+
minutes = readTemplateLengths(env.body);
|
|
93
|
+
}
|
|
94
|
+
catch (e) {
|
|
95
|
+
lengthsNote = `The template lengths could not be read (${failureText(e)}).`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const templates = unlocked.map((t) => ({
|
|
99
|
+
id: t.id,
|
|
100
|
+
name: shownName(t.name),
|
|
101
|
+
mapId: t.mapId,
|
|
102
|
+
...templateView(settings.templates.get(t.id) ?? QUICKMATCH_TEMPLATE_SETTINGS.off),
|
|
103
|
+
...(minutes ? { averageMinutes: minutes.has(t.id) ? Math.round(minutes.get(t.id)) : null } : {}),
|
|
104
|
+
}));
|
|
105
|
+
return respond(undefined, ['compact'], () => ({
|
|
106
|
+
...settingsView(settings),
|
|
107
|
+
templates,
|
|
108
|
+
...(lengthsNote ? { lengthsNote } : {}),
|
|
109
|
+
multiDayNote: settings.multiDayGames > 0
|
|
110
|
+
? `war.app may start up to ${settings.multiDayGames} multi-day quickmatch game(s) for you on its own. ${QUICKMATCH_OFF}`
|
|
111
|
+
: 'Multi-day quickmatch is off: war.app starts no quickmatch games for you.',
|
|
112
|
+
unverified: QUICKMATCH_UNVERIFIED,
|
|
113
|
+
}));
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
const SORTS = ['rank', 'votes', 'newest'];
|
|
117
|
+
function registerTemplatesRead(server, ctx) {
|
|
118
|
+
server.registerTool('warapp_quickmatch_templates', {
|
|
119
|
+
title: 'List war.app quickmatch templates and votes',
|
|
120
|
+
description: untrustedDescription("The war.app (Warzone) quickmatch templates players vote on (war.app's GetQuickmatchTemplates): each template's id, " +
|
|
121
|
+
'name (delimited), map id, votes, rank (`fixedRank` when war.app set it, which votes do not move) and `myVotes`; and ' +
|
|
122
|
+
'your votes unlocked, used and available. `sort`: `rank` (default: ranked first, then by votes), `votes` or `newest`; ' +
|
|
123
|
+
"`limit` (default 25, max 100) and `offset` page the list. `template_id` also lists who voted for that template " +
|
|
124
|
+
"(war.app's GetQuickmatchTemplateVotes: player ids, names delimited, votes). " +
|
|
125
|
+
`${BRIDGE_NOTE} Read-only. ${QUICKMATCH_UNVERIFIED}`),
|
|
126
|
+
_meta: mintMeta('lookup', ['quickmatch templates', 'quickmatch votes', 'vote for template', 'who voted']),
|
|
127
|
+
annotations: readAnnotations('List war.app quickmatch templates'),
|
|
128
|
+
inputSchema: z.object({
|
|
129
|
+
sort: z.enum(SORTS).optional().describe('`rank` (default), `votes` or `newest`.'),
|
|
130
|
+
limit: z.number().int().min(1).max(100).optional().describe('Templates per page (default 25, max 100).'),
|
|
131
|
+
offset: z.number().int().min(0).optional().describe('Templates to skip (default 0).'),
|
|
132
|
+
template_id: z.number().int().positive().optional().describe('A template id: also list who voted for it.'),
|
|
133
|
+
}),
|
|
134
|
+
}, async ({ sort, limit, offset, template_id }) => {
|
|
135
|
+
const read = await readTemplates(ctx);
|
|
136
|
+
const mine = new Map(read.myVotes.map((v) => [v.templateId, v.votes]));
|
|
137
|
+
const used = read.myVotes.reduce((n, v) => n + v.votes, 0);
|
|
138
|
+
const order = sort ?? 'rank';
|
|
139
|
+
const list = [...read.templates].sort((a, b) => order === 'newest'
|
|
140
|
+
? b.templateId - a.templateId
|
|
141
|
+
: order === 'votes'
|
|
142
|
+
? b.votes - a.votes
|
|
143
|
+
: a.rank !== null && b.rank !== null
|
|
144
|
+
? a.rank - b.rank
|
|
145
|
+
: a.rank !== null || b.rank !== null
|
|
146
|
+
? a.rank !== null
|
|
147
|
+
? -1
|
|
148
|
+
: 1
|
|
149
|
+
: b.votes - a.votes);
|
|
150
|
+
const start = offset ?? 0;
|
|
151
|
+
const page = list.slice(start, start + (limit ?? 25)).map((t) => {
|
|
152
|
+
const info = read.info.get(t.templateId);
|
|
153
|
+
return {
|
|
154
|
+
id: t.templateId,
|
|
155
|
+
name: shownName(info?.name),
|
|
156
|
+
mapId: info?.mapId ?? null,
|
|
157
|
+
votes: t.votes,
|
|
158
|
+
rank: t.rank,
|
|
159
|
+
fixedRank: t.fixedRank,
|
|
160
|
+
myVotes: mine.get(t.templateId) ?? 0,
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
let voters;
|
|
164
|
+
if (template_id !== undefined) {
|
|
165
|
+
const env = await ctx.rpc.call('GetQuickmatchTemplateVotes', Method.GetQuickmatchTemplateVotes, (w) => writeGetQuickmatchTemplateVotesParams(w, template_id));
|
|
166
|
+
voters = {
|
|
167
|
+
templateId: template_id,
|
|
168
|
+
players: readTemplateVoters(await ctx.bundle(), env.body).map((v) => ({ ...v, name: shownName(v.name) })),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
const unlocked = read.settings?.votesUnlocked ?? null;
|
|
172
|
+
return respond(undefined, ['compact'], () => ({
|
|
173
|
+
templates: page,
|
|
174
|
+
count: page.length,
|
|
175
|
+
total: list.length,
|
|
176
|
+
...(start + page.length < list.length ? { next: start + page.length } : {}),
|
|
177
|
+
votes: { unlocked, used, available: unlocked === null ? null : Math.max(0, unlocked - used) },
|
|
178
|
+
...(voters ? { voters } : {}),
|
|
179
|
+
unverified: QUICKMATCH_UNVERIFIED,
|
|
180
|
+
}));
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
const CATEGORIES = { global: 'Global', real_time: 'RT', multi_day: 'MD', '1v1': '1v1', team: 'Team', ffa: 'FFA' };
|
|
184
|
+
const CATEGORY_KEYS = Object.keys(CATEGORIES);
|
|
185
|
+
function registerLeaderboardRead(server, ctx) {
|
|
186
|
+
server.registerTool('warapp_quickmatch_leaderboard', {
|
|
187
|
+
title: 'Read a war.app quickmatch leaderboard',
|
|
188
|
+
description: untrustedDescription("A war.app (Warzone) quickmatch leaderboard (war.app's GetQuickmatchLeaderboards), 50 players a page: each row's " +
|
|
189
|
+
'rank, player id, name (delimited) and rating, nothing else about them, and `total`. `category`: `global` (default), ' +
|
|
190
|
+
'`real_time`, `multi_day`, `1v1`, `team` or `ffa`; or `template_id` for one template\'s board. `start` is the ' +
|
|
191
|
+
`0-based rank to start from (\`next\` gives the next page). ${BRIDGE_NOTE} Read-only. ${QUICKMATCH_UNVERIFIED}`),
|
|
192
|
+
_meta: mintMeta('lookup', ['quickmatch leaderboard', 'quickmatch ranking', 'top quickmatch players']),
|
|
193
|
+
annotations: readAnnotations('Read a war.app quickmatch leaderboard'),
|
|
194
|
+
inputSchema: z.object({
|
|
195
|
+
category: z.enum(CATEGORY_KEYS).optional().describe('The board: `global` (default), `real_time`, `multi_day`, `1v1`, `team`, `ffa`.'),
|
|
196
|
+
template_id: z.number().int().positive().optional().describe("A template id: that template's board (instead of `category`)."),
|
|
197
|
+
start: z.number().int().min(0).optional().describe('The 0-based rank to start from (default 0).'),
|
|
198
|
+
}),
|
|
199
|
+
}, async ({ category, template_id, start }) => {
|
|
200
|
+
const name = template_id !== undefined ? `Template ${template_id}` : CATEGORIES[category ?? 'global'];
|
|
201
|
+
const from = start ?? 0;
|
|
202
|
+
const env = await ctx.rpc.call('GetQuickmatchLeaderboards', Method.GetQuickmatchLeaderboards, (w) => writeGetQuickmatchLeaderboardsParams(w, name, from));
|
|
203
|
+
const board = readLeaderboard(await ctx.bundle(), env.body);
|
|
204
|
+
const rows = board.rows.map((r) => ({ ...r, name: shownName(r.name) }));
|
|
205
|
+
return respond(undefined, ['compact'], () => ({
|
|
206
|
+
category: template_id !== undefined ? { templateId: template_id } : (category ?? 'global'),
|
|
207
|
+
rows,
|
|
208
|
+
total: board.total,
|
|
209
|
+
...(from + QUICKMATCH_LEADERBOARD_PAGE < board.total && rows.length > 0 ? { next: from + QUICKMATCH_LEADERBOARD_PAGE } : {}),
|
|
210
|
+
unverified: QUICKMATCH_UNVERIFIED,
|
|
211
|
+
}));
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
function registerSettingsWrite(server, ctx) {
|
|
215
|
+
defineGatedWrite(server, {
|
|
216
|
+
title: 'Change my war.app quickmatch settings',
|
|
217
|
+
_meta: mintMeta('change', ['quickmatch settings', 'turn on multi-day quickmatch', 'turn off quickmatch', 'quickmatch templates']),
|
|
218
|
+
}, {
|
|
219
|
+
name: 'warapp_set_quickmatch_settings',
|
|
220
|
+
description: "Change your war.app (Warzone) quickmatch settings (war.app's SetQuickmatchSettings): `multi_day_games` (0–10) is how " +
|
|
221
|
+
'many multi-day quickmatch games war.app may start for you ON ITS OWN, joined with no further confirmation (0 turns ' +
|
|
222
|
+
'multi-day quickmatch off), and `templates` sets the templates you play by id (`on`, `off`, `real_time_only`, ' +
|
|
223
|
+
'`multi_day_only`; only templates warapp_quickmatch_settings lists as unlocked). Everything else (coin wager, ' +
|
|
224
|
+
"speed, new-templates default) is re-sent as war.app has it. As the client does, it refuses settings that leave no " +
|
|
225
|
+
'template on, none for real-time or none for multi-day. The preview says how many games could start and where to ' +
|
|
226
|
+
'turn them off. Always as the signed-in war.app account; read back with GetQuickmatchSettings (`saved` → ' +
|
|
227
|
+
"`confirmed`); no answer is `unknown` — never resend blindly. Read from war.app's client code, UNVERIFIED live. " +
|
|
228
|
+
`${BRIDGE_NOTE} ${CONFIRM_INJECTION_RULE}`,
|
|
229
|
+
annotations: toolAnnotations({
|
|
230
|
+
title: 'Change war.app quickmatch settings',
|
|
231
|
+
readOnly: false,
|
|
232
|
+
destructive: true,
|
|
233
|
+
idempotent: true,
|
|
234
|
+
openWorld: true,
|
|
235
|
+
}),
|
|
236
|
+
inputSchema: z.object({
|
|
237
|
+
multi_day_games: z
|
|
238
|
+
.number()
|
|
239
|
+
.int()
|
|
240
|
+
.min(0)
|
|
241
|
+
.max(MAX_MULTI_DAY_GAMES)
|
|
242
|
+
.optional()
|
|
243
|
+
.describe('How many multi-day quickmatch games war.app may start for you on its own (0: off; at most 10).'),
|
|
244
|
+
templates: z
|
|
245
|
+
.array(z.object({
|
|
246
|
+
template_id: z.number().int().positive().describe('An unlocked template id (warapp_quickmatch_settings).'),
|
|
247
|
+
setting: z.enum(SETTING_KEYS).describe('`on` (real-time and multi-day), `off`, `real_time_only` or `multi_day_only`.'),
|
|
248
|
+
}))
|
|
249
|
+
.max(200)
|
|
250
|
+
.optional()
|
|
251
|
+
.describe('The templates to change; templates not named keep their setting.'),
|
|
252
|
+
}),
|
|
253
|
+
async plan({ multi_day_games, templates }) {
|
|
254
|
+
if (multi_day_games === undefined && (templates === undefined || templates.length === 0)) {
|
|
255
|
+
refuse('Nothing to change: give `multi_day_games`, `templates`, or both. Nothing was sent.', 'Read the current settings with warapp_quickmatch_settings.');
|
|
256
|
+
}
|
|
257
|
+
const me = await requireMe(ctx);
|
|
258
|
+
const { settings, unlocked } = await readSettings(ctx);
|
|
259
|
+
requireOwnSettings(settings, me);
|
|
260
|
+
const known = new Map(unlocked.map((t) => [t.id, t]));
|
|
261
|
+
const next = new Map(settings.templates);
|
|
262
|
+
const changes = [];
|
|
263
|
+
for (const t of templates ?? []) {
|
|
264
|
+
if (!known.has(t.template_id)) {
|
|
265
|
+
refuse(`Template ${t.template_id} is not one of the quickmatch templates you have unlocked, so nothing was sent.`, 'List them with warapp_quickmatch_settings.');
|
|
266
|
+
}
|
|
267
|
+
const from = next.get(t.template_id) ?? QUICKMATCH_TEMPLATE_SETTINGS.off;
|
|
268
|
+
const to = QUICKMATCH_TEMPLATE_SETTINGS[t.setting];
|
|
269
|
+
next.set(t.template_id, to);
|
|
270
|
+
if (from !== to) {
|
|
271
|
+
changes.push({ templateId: t.template_id, name: shownName(known.get(t.template_id)?.name), from: settingName(from) ?? 'off', to: t.setting });
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const sent = [...next].filter(([, v]) => v !== QUICKMATCH_TEMPLATE_SETTINGS.off).sort((a, b) => a[0] - b[0]);
|
|
275
|
+
// The client's own checks before it saves (QuickmatchScene).
|
|
276
|
+
if (sent.length === 0)
|
|
277
|
+
refuse('war.app needs at least one quickmatch template on, so nothing was sent.', 'Set at least one template `on`.');
|
|
278
|
+
if (!sent.some(([, v]) => settingPlays(v, true))) {
|
|
279
|
+
refuse('war.app needs at least one template on for real-time (the client refuses to save without one), so nothing was sent.', 'Set one template `on` or `real_time_only`; real-time games start only when you press Play Now on war.app.');
|
|
280
|
+
}
|
|
281
|
+
if (!sent.some(([, v]) => settingPlays(v, false))) {
|
|
282
|
+
refuse('war.app needs at least one template on for multi-day (the client refuses to save without one), so nothing was sent.', 'Set one template `on` or `multi_day_only`.');
|
|
283
|
+
}
|
|
284
|
+
const games = multi_day_games ?? settings.multiDayGames;
|
|
285
|
+
const multiDayTemplates = sent.filter(([, v]) => settingPlays(v, false)).map(([id]) => id);
|
|
286
|
+
const commitment = games > 0
|
|
287
|
+
? `war.app may then start up to ${games} multi-day quickmatch game(s) for you at a time on its own, on template(s) ` +
|
|
288
|
+
`${multiDayTemplates.join(', ')}, each joined with no further confirmation and played to the end or surrendered. ` +
|
|
289
|
+
QUICKMATCH_OFF
|
|
290
|
+
: 'Multi-day quickmatch will be off: war.app starts no quickmatch games for you.';
|
|
291
|
+
const state = {
|
|
292
|
+
me,
|
|
293
|
+
multiDayGames: games,
|
|
294
|
+
templates: sent,
|
|
295
|
+
coins: { min: settings.coins.min, max: Math.max(settings.coins.max, settings.coins.min) },
|
|
296
|
+
newTemplatesOnByDefault: settings.newTemplatesOnByDefault,
|
|
297
|
+
speed: settings.speed,
|
|
298
|
+
};
|
|
299
|
+
return {
|
|
300
|
+
gate: {
|
|
301
|
+
action: 'warapp.set_quickmatch_settings',
|
|
302
|
+
// By id only: template names are their makers' words and go, delimited, in labelled fields.
|
|
303
|
+
summary: `Set war.app quickmatch to ${games} multi-day game(s) and ${sent.length} template(s) on`,
|
|
304
|
+
account: writeAccount(me),
|
|
305
|
+
target: `quickmatch:${me}`,
|
|
306
|
+
payload: {
|
|
307
|
+
method: 'SetQuickmatchSettings',
|
|
308
|
+
multiDayGames: state.multiDayGames,
|
|
309
|
+
templates: state.templates,
|
|
310
|
+
coins: state.coins,
|
|
311
|
+
newTemplatesOnByDefault: state.newTemplatesOnByDefault,
|
|
312
|
+
speed: state.speed,
|
|
313
|
+
},
|
|
314
|
+
willSend: { multiDayGames: games, templates: Object.fromEntries(sent.map(([id, v]) => [id, settingName(v)])) },
|
|
315
|
+
preview: {
|
|
316
|
+
warning: commitment,
|
|
317
|
+
account: shownAccount(undefined, me),
|
|
318
|
+
multiDay: {
|
|
319
|
+
gamesBefore: settings.multiDayGames,
|
|
320
|
+
gamesAfter: games,
|
|
321
|
+
couldStartAtOnce: games,
|
|
322
|
+
templates: multiDayTemplates,
|
|
323
|
+
turnOff: QUICKMATCH_OFF,
|
|
324
|
+
},
|
|
325
|
+
templateChanges: changes,
|
|
326
|
+
unchanged: 'The coin wager, the real-time speed and the new-templates default are re-sent as war.app has them.',
|
|
327
|
+
note: 'Quickmatch games are set up by war.app from the templates: this server\'s joining policy does not check them.',
|
|
328
|
+
untrusted: UNTRUSTED_PREVIEW_NOTE,
|
|
329
|
+
},
|
|
330
|
+
},
|
|
331
|
+
state,
|
|
332
|
+
};
|
|
333
|
+
},
|
|
334
|
+
async execute(state) {
|
|
335
|
+
await requireApprovedAccount(ctx, writeAccount(state.me));
|
|
336
|
+
const base = {
|
|
337
|
+
multiDayGames: state.multiDayGames,
|
|
338
|
+
templates: Object.fromEntries(state.templates.map(([id, v]) => [id, settingName(v)])),
|
|
339
|
+
};
|
|
340
|
+
return sendAndVerify({
|
|
341
|
+
send: async () => {
|
|
342
|
+
await ctx.rpc.call('SetQuickmatchSettings', Method.SetQuickmatchSettings, (w) => writeSetQuickmatchSettingsParams(w, {
|
|
343
|
+
multiDayGames: state.multiDayGames,
|
|
344
|
+
minCoins: state.coins.min,
|
|
345
|
+
maxCoins: state.coins.max,
|
|
346
|
+
templates: state.templates,
|
|
347
|
+
newTemplatesOnByDefault: state.newTemplatesOnByDefault,
|
|
348
|
+
speed: state.speed,
|
|
349
|
+
}));
|
|
350
|
+
},
|
|
351
|
+
refused: worded(QUICKMATCH_ERRORS),
|
|
352
|
+
unanswered: (failure) => ({
|
|
353
|
+
status: 'unknown',
|
|
354
|
+
outcome: 'unknown',
|
|
355
|
+
...base,
|
|
356
|
+
warning: `war.app did not confirm the change (${failure}), so it may have been saved. Read it with warapp_quickmatch_settings before changing again.`,
|
|
357
|
+
}),
|
|
358
|
+
readBack: async () => (await readSettings(ctx)).settings,
|
|
359
|
+
unreadable: (failure) => ({ status: 'unconfirmed', outcome: 'unconfirmed', ...base, warning: failure }),
|
|
360
|
+
classify: (after) => {
|
|
361
|
+
const mismatches = [];
|
|
362
|
+
if (after.multiDayGames !== state.multiDayGames)
|
|
363
|
+
mismatches.push(`multi-day games read ${after.multiDayGames}`);
|
|
364
|
+
const want = new Map(state.templates);
|
|
365
|
+
for (const id of new Set([...want.keys(), ...after.templates.keys()])) {
|
|
366
|
+
const a = after.templates.get(id) ?? QUICKMATCH_TEMPLATE_SETTINGS.off;
|
|
367
|
+
const b = want.get(id) ?? QUICKMATCH_TEMPLATE_SETTINGS.off;
|
|
368
|
+
if (a !== b)
|
|
369
|
+
mismatches.push(`template ${id} reads ${settingName(a) ?? a}`);
|
|
370
|
+
}
|
|
371
|
+
return mismatches.length === 0
|
|
372
|
+
? {
|
|
373
|
+
status: 'saved',
|
|
374
|
+
outcome: 'confirmed',
|
|
375
|
+
...base,
|
|
376
|
+
detail: state.multiDayGames > 0
|
|
377
|
+
? `Saved: war.app may start up to ${state.multiDayGames} multi-day quickmatch game(s) for you. ${QUICKMATCH_OFF}`
|
|
378
|
+
: 'Saved: multi-day quickmatch is off.',
|
|
379
|
+
}
|
|
380
|
+
: { status: 'unconfirmed', outcome: 'unconfirmed', ...base, mismatches, warning: 'war.app accepted the change, but the settings read back differ.' };
|
|
381
|
+
},
|
|
382
|
+
});
|
|
383
|
+
},
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
function registerVoteWrite(server, ctx) {
|
|
387
|
+
defineGatedWrite(server, {
|
|
388
|
+
title: 'Vote for a war.app quickmatch template',
|
|
389
|
+
_meta: mintMeta('change', ['vote for quickmatch template', 'quickmatch votes', 'remove my vote']),
|
|
390
|
+
}, {
|
|
391
|
+
name: 'warapp_vote_quickmatch_template',
|
|
392
|
+
description: "Set how many of your quickmatch votes go to one war.app (Warzone) template (war.app's SetQuickmatchTemplateVotes): " +
|
|
393
|
+
'`votes` 0–3 (0 takes your votes back). Refuses a template not on the voting list, one whose rank war.app fixed, no ' +
|
|
394
|
+
'change, and more votes than you have available (warapp_quickmatch_templates shows them). Your votes show by name in ' +
|
|
395
|
+
"the template's voter list. Always as the signed-in war.app account; read back with GetQuickmatchTemplates (`voted` " +
|
|
396
|
+
"→ `confirmed`); no answer is `unknown` — never resend blindly. Read from war.app's client code, UNVERIFIED live. " +
|
|
397
|
+
`${BRIDGE_NOTE} ${CONFIRM_INJECTION_RULE}`,
|
|
398
|
+
annotations: toolAnnotations({
|
|
399
|
+
title: 'Vote for a war.app quickmatch template',
|
|
400
|
+
readOnly: false,
|
|
401
|
+
destructive: false,
|
|
402
|
+
idempotent: true,
|
|
403
|
+
openWorld: true,
|
|
404
|
+
}),
|
|
405
|
+
inputSchema: z.object({
|
|
406
|
+
template_id: z.number().int().positive().describe('The template id (warapp_quickmatch_templates).'),
|
|
407
|
+
votes: z.number().int().min(0).max(3).describe('Your votes on it afterwards: 0 (none) to 3.'),
|
|
408
|
+
}),
|
|
409
|
+
async plan({ template_id, votes }) {
|
|
410
|
+
const me = await requireMe(ctx);
|
|
411
|
+
const read = await readTemplates(ctx);
|
|
412
|
+
if (read.settings)
|
|
413
|
+
requireOwnSettings(read.settings, me);
|
|
414
|
+
const template = read.templates.find((t) => t.templateId === template_id);
|
|
415
|
+
if (!template) {
|
|
416
|
+
refuse(`Template ${template_id} is not on the quickmatch voting list, so nothing was sent.`, 'List the templates with warapp_quickmatch_templates.');
|
|
417
|
+
}
|
|
418
|
+
if (template.fixedRank) {
|
|
419
|
+
refuse(`Template ${template_id}'s rank is set by war.app, and the client offers no vote on it: nothing was sent.`, 'Vote for another template.');
|
|
420
|
+
}
|
|
421
|
+
const before = read.myVotes.find((v) => v.templateId === template_id)?.votes ?? 0;
|
|
422
|
+
if (before === votes)
|
|
423
|
+
refuse(`You already have ${votes} vote(s) on template ${template_id}: nothing to change.`, 'Nothing to do.');
|
|
424
|
+
const used = read.myVotes.reduce((n, v) => n + v.votes, 0);
|
|
425
|
+
const unlocked = read.settings?.votesUnlocked;
|
|
426
|
+
const available = unlocked === undefined ? null : Math.max(0, unlocked - used);
|
|
427
|
+
if (available !== null && votes - before > available) {
|
|
428
|
+
refuse(`That needs ${votes - before} more vote(s), and you have ${available} available, so nothing was sent.`, 'Take votes back from another template first (votes: 0), or win more quickmatch games to unlock votes.');
|
|
429
|
+
}
|
|
430
|
+
const info = read.info.get(template_id);
|
|
431
|
+
return {
|
|
432
|
+
gate: {
|
|
433
|
+
action: 'warapp.vote_quickmatch_template',
|
|
434
|
+
summary: `Set your quickmatch votes on template ${template_id} from ${before} to ${votes}`,
|
|
435
|
+
account: writeAccount(me),
|
|
436
|
+
target: `quickmatch-vote:${template_id}`,
|
|
437
|
+
payload: { method: 'SetQuickmatchTemplateVotes', templateId: template_id, votes },
|
|
438
|
+
willSend: { templateId: template_id, votes },
|
|
439
|
+
preview: {
|
|
440
|
+
warning: `This sets your votes on quickmatch template ${template_id} to ${votes}; they show by name in its voter list.`,
|
|
441
|
+
account: shownAccount(undefined, me),
|
|
442
|
+
template: { id: template_id, name: shownName(info?.name), votes: template.votes, rank: template.rank },
|
|
443
|
+
myVotes: { before, after: votes },
|
|
444
|
+
available: available === null ? null : { before: available, after: available - (votes - before) },
|
|
445
|
+
untrusted: UNTRUSTED_PREVIEW_NOTE,
|
|
446
|
+
},
|
|
447
|
+
},
|
|
448
|
+
state: { me, templateId: template_id, votes, before },
|
|
449
|
+
};
|
|
450
|
+
},
|
|
451
|
+
async execute({ me, templateId, votes, before }) {
|
|
452
|
+
await requireApprovedAccount(ctx, writeAccount(me));
|
|
453
|
+
const base = { templateId, votes, before };
|
|
454
|
+
return sendAndVerify({
|
|
455
|
+
send: async () => {
|
|
456
|
+
await ctx.rpc.call('SetQuickmatchTemplateVotes', Method.SetQuickmatchTemplateVotes, (w) => writeSetQuickmatchTemplateVotesParams(w, templateId, votes));
|
|
457
|
+
},
|
|
458
|
+
refused: worded(QUICKMATCH_ERRORS),
|
|
459
|
+
unanswered: (failure) => ({
|
|
460
|
+
status: 'unknown',
|
|
461
|
+
outcome: 'unknown',
|
|
462
|
+
...base,
|
|
463
|
+
warning: `war.app did not confirm the vote (${failure}), so it may have been saved. Read it with warapp_quickmatch_templates before voting again.`,
|
|
464
|
+
}),
|
|
465
|
+
readBack: async () => (await readTemplates(ctx)).myVotes.find((v) => v.templateId === templateId)?.votes ?? 0,
|
|
466
|
+
unreadable: (failure) => ({ status: 'unconfirmed', outcome: 'unconfirmed', ...base, warning: failure }),
|
|
467
|
+
classify: (after) => after === votes
|
|
468
|
+
? { status: 'voted', outcome: 'confirmed', ...base }
|
|
469
|
+
: { status: 'unconfirmed', outcome: 'unconfirmed', ...base, readBack: after, warning: 'war.app accepted the vote, but your votes on the template read back differ.' },
|
|
470
|
+
});
|
|
471
|
+
},
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
/** The quickmatch tools (#638): three reads and two confirm-gated writes. */
|
|
475
|
+
export function registerQuickmatchTools(server, ctx) {
|
|
476
|
+
registerSettingsRead(server, ctx);
|
|
477
|
+
registerTemplatesRead(server, ctx);
|
|
478
|
+
registerLeaderboardRead(server, ctx);
|
|
479
|
+
registerSettingsWrite(server, ctx);
|
|
480
|
+
registerVoteWrite(server, ctx);
|
|
481
|
+
}
|