@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
package/dist/tools/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { StatsCollector } from '../stats.js';
|
|
|
6
6
|
import { registerBeginTurnTool } from './begin-turn.js';
|
|
7
7
|
import { registerBoardTool } from './board.js';
|
|
8
8
|
import { registerChatTools } from './chat.js';
|
|
9
|
+
import { registerReactTool } from './react.js';
|
|
9
10
|
import { registerChatInboxTool } from './chat-inbox.js';
|
|
10
11
|
import { registerMarkChatReadTool } from './chat-read-mark.js';
|
|
11
12
|
import { registerCheckPlanTool } from './check-plan.js';
|
|
@@ -18,6 +19,16 @@ import { registerMapTool } from './map.js';
|
|
|
18
19
|
import { registerMapStatsTool } from './map-stats.js';
|
|
19
20
|
import { fetchMyGames, registerMyGamesTool } from './my-games.js';
|
|
20
21
|
import { registerNotificationTools } from './notifications.js';
|
|
22
|
+
import { registerFriendsTool } from './friends.js';
|
|
23
|
+
import { registerNudgeTool } from './nudge.js';
|
|
24
|
+
import { registerMailTools } from './mail.js';
|
|
25
|
+
import { registerLadderTools } from './ladders.js';
|
|
26
|
+
import { registerClanTools } from './clans.js';
|
|
27
|
+
import { registerClanWriteTools } from './clan-writes.js';
|
|
28
|
+
import { registerQuickmatchTools } from './quickmatch.js';
|
|
29
|
+
import { registerForumTools } from './forums.js';
|
|
30
|
+
import { registerTournamentTools } from './tournaments.js';
|
|
31
|
+
import { mailSignal } from '../mail.js';
|
|
21
32
|
import { registerOpenGamesTool } from './open-games.js';
|
|
22
33
|
import { registerOpponentsTool } from './opponents.js';
|
|
23
34
|
import { registerPickTools } from './picks.js';
|
|
@@ -32,12 +43,17 @@ import { paceStatus } from './pace.js';
|
|
|
32
43
|
import { registerStrategyTool } from './strategy.js';
|
|
33
44
|
import { registerSurrenderTool } from './surrender.js';
|
|
34
45
|
import { registerAcceptSurrenderTool } from './accept-surrender.js';
|
|
46
|
+
import { registerTeamSurrenderTool } from './team-surrender.js';
|
|
47
|
+
import { registerVoteToEndTool } from './vote-to-end.js';
|
|
48
|
+
import { registerBootPlayerTool } from './boot-player.js';
|
|
35
49
|
import { registerTeamTool } from './team.js';
|
|
36
50
|
import { registerTeamBriefTool } from './team-brief.js';
|
|
37
51
|
import { registerTurnTools } from './turn.js';
|
|
38
52
|
import { registerMyOrdersTool } from './my-orders.js';
|
|
39
53
|
import { registerUncommitTool } from './uncommit.js';
|
|
40
54
|
import { registerLeaveGameTool } from './leave-game.js';
|
|
55
|
+
import { registerAcceptInviteTool, registerInviteCodeTool } from './invites.js';
|
|
56
|
+
import { registerTemplateTools } from './templates.js';
|
|
41
57
|
import { registerCloseFinishedGameTool } from './close-finished-game.js';
|
|
42
58
|
import { registerWhereTool } from './where.js';
|
|
43
59
|
import { registerStateTools } from './state.js';
|
|
@@ -119,9 +135,15 @@ function registerEveryTool(server, deps) {
|
|
|
119
135
|
registerOpenGamesTool(server, live);
|
|
120
136
|
registerJoinGameTool(server, live);
|
|
121
137
|
registerLeaveGameTool(server, live);
|
|
138
|
+
registerAcceptInviteTool(server, live);
|
|
139
|
+
registerInviteCodeTool(server, live);
|
|
140
|
+
registerTemplateTools(server, live);
|
|
122
141
|
registerCloseFinishedGameTool(server, live);
|
|
123
142
|
registerSurrenderTool(server, live);
|
|
124
143
|
registerAcceptSurrenderTool(server, live);
|
|
144
|
+
registerTeamSurrenderTool(server, live);
|
|
145
|
+
registerVoteToEndTool(server, live);
|
|
146
|
+
registerBootPlayerTool(server, live);
|
|
125
147
|
registerBeginTurnTool(server, live);
|
|
126
148
|
registerScoutTool(server, live, deps.env ? { env: deps.env } : {});
|
|
127
149
|
registerTurnTools(server, live, deps.env ? { env: deps.env } : {});
|
|
@@ -136,10 +158,26 @@ function registerEveryTool(server, deps) {
|
|
|
136
158
|
registerMyOrdersTool(server, live);
|
|
137
159
|
registerChatTools(server, live, deps.env ? { env: deps.env } : {});
|
|
138
160
|
registerChatInboxTool(server, live);
|
|
161
|
+
// Local and hosted: a reaction on a chat message, confirm-gated (#634).
|
|
162
|
+
registerReactTool(server, live, deps.env ? { env: deps.env } : {});
|
|
139
163
|
// Local and hosted: war.app's own chat read mark, confirm-gated (#311).
|
|
140
164
|
registerMarkChatReadTool(server, live);
|
|
141
165
|
// Local and hosted: the account's own notifications, through its war.app tab.
|
|
142
166
|
registerNotificationTools(server, live, deps.env ? { env: deps.env } : {});
|
|
167
|
+
// #641: the friends and block list (read-only), and nudging a player who holds a game up (confirm-gated).
|
|
168
|
+
registerFriendsTool(server, live);
|
|
169
|
+
registerNudgeTool(server, live);
|
|
170
|
+
registerMailTools(server, live, deps.env ? { env: deps.env } : {});
|
|
171
|
+
// #637: ladders — seasons, standings and players (read-only), joining and leaving (confirm-gated).
|
|
172
|
+
registerLadderTools(server, live);
|
|
173
|
+
// #639: clans and clan wars (read-only), and answering an invite, joining an open clan, leaving (confirm-gated).
|
|
174
|
+
registerClanTools(server, live);
|
|
175
|
+
registerClanWriteTools(server, live);
|
|
176
|
+
registerQuickmatchTools(server, live);
|
|
177
|
+
// #640: the forums — forum and thread lists, a thread's posts (read-only); new threads, replies, votes, watching (confirm-gated).
|
|
178
|
+
registerForumTools(server, live, deps.env ? { env: deps.env } : {});
|
|
179
|
+
// #636: tournaments — lists, details and chat (read-only); join, decline and profile favourites (confirm-gated).
|
|
180
|
+
registerTournamentTools(server, live);
|
|
143
181
|
registerTeamTool(server, live);
|
|
144
182
|
// C4: the team brief, read-only — the facts for a team-chat message, never sent.
|
|
145
183
|
registerTeamBriefTool(server, live);
|
|
@@ -183,6 +221,7 @@ function registerEveryTool(server, deps) {
|
|
|
183
221
|
}
|
|
184
222
|
return paceStatus(live, Date.now());
|
|
185
223
|
},
|
|
224
|
+
mail: () => mailSignal(live.rpc.unreadMail),
|
|
186
225
|
identityChanged: () => live.forgetIdentity(),
|
|
187
226
|
hosted,
|
|
188
227
|
...(env ? { env } : {}),
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
// Invitations (#633). `warapp_accept_invite` accepts a game the signed-in account is invited to with the web
|
|
2
|
+
// client's AcceptGame (61), gated on the user's confirmation; `warapp_get_game_by_invite_code` reads a game by its
|
|
3
|
+
// invite code with GetGameByInviteCode (295), read-only. Both read from the client bundle, UNVERIFIED live
|
|
4
|
+
// (docs/WEB-PROTOCOL.md "Invitations and invite codes").
|
|
5
|
+
//
|
|
6
|
+
// An invited game is in GetMyGames' list (my seat `Invited`), as a GameInfo — the record the open-games page
|
|
7
|
+
// carries — so it is read the way warapp_list_open_games reads a lobby (src/open-games.ts `openGameOf`) and checked
|
|
8
|
+
// against the same joining policy warapp_join_game applies. An invitation is the owner's choice, so a break is
|
|
9
|
+
// reported in the preview, never refused. Declining an invitation is warapp_leave_game (DeclineGame, #652): the
|
|
10
|
+
// client's lobby sends the same call from the same Decline button for an invited seat as for a seated one.
|
|
11
|
+
//
|
|
12
|
+
// Joining a game through its invite code is not built: the client joins such a game from its lobby with
|
|
13
|
+
// AcceptOpenSeat and team -1, but only after reading the lobby (its players' colours, its settings, a scenario
|
|
14
|
+
// slot), which neither the code's reply nor any read this server has for a game it is not in carries.
|
|
15
|
+
import { CONFIRM_INJECTION_RULE, toolAnnotations } from '@chrischall/mcp-utils';
|
|
16
|
+
import { z } from 'zod';
|
|
17
|
+
import { parseGameId } from '../client.js';
|
|
18
|
+
import { INVITE_CODE_NOT_FOUND, readGameInviteCode } from '../invite-code.js';
|
|
19
|
+
import { chooseJoinColor, readAccountColors, STANDARD_COLORS } from '../join-color.js';
|
|
20
|
+
import { attendedGames, gameOf, readMyGameInfos } from '../my-games.js';
|
|
21
|
+
import { joiningPolicy, openGameOf, parseOpenGamesPage, seatIn, } from '../open-games.js';
|
|
22
|
+
import { GAME_COLOR_COUNT, MAX_INVITE_CODE_LENGTH, Method, readAcceptGameReturn, writeAcceptGameParams, writeGetGameByInviteCodeParams, writeGetMyGamesParams, } from '../protocol/methods.js';
|
|
23
|
+
import { WarappServerError } from '../protocol/rpc.js';
|
|
24
|
+
import { holdsSeat } from '../player-states.js';
|
|
25
|
+
import { gameIdArg, readAnnotations, respond, UNTRUSTED_PREVIEW_NOTE, untrustedDescription, untrustedText } from './common.js';
|
|
26
|
+
import { captureJoin, joinContextLog } from './decision-capture.js';
|
|
27
|
+
import { lookupMeta, mintMeta } from './hints.js';
|
|
28
|
+
import { ALREADY_JOINED, confirmSeated, joinErrorWording, lobbyScreen } from './join-game.js';
|
|
29
|
+
import { requireApprovedAccount, writeAccount } from './live-context.js';
|
|
30
|
+
import { listMyGames } from './my-games.js';
|
|
31
|
+
import { markLotteries, openGamesPage } from './open-games.js';
|
|
32
|
+
import { noBrowserNote } from './session.js';
|
|
33
|
+
import { accountUnknown, defineGatedWrite, refuse, sendAndVerify } from './write-kit.js';
|
|
34
|
+
/** Every GameInfo record GetMyGames lists (the whole list, widened as warapp_my_games widens it). */
|
|
35
|
+
async function myGameInfos(ctx) {
|
|
36
|
+
const { games } = await listMyGames(async (filters) => {
|
|
37
|
+
const env = await ctx.rpc.call('GetMyGames', Method.GetMyGames, (w) => writeGetMyGamesParams(w, filters));
|
|
38
|
+
return readMyGameInfos(await ctx.bundle(), env.body);
|
|
39
|
+
});
|
|
40
|
+
return games;
|
|
41
|
+
}
|
|
42
|
+
/** The record of game `gameId` in `infos`, or undefined. */
|
|
43
|
+
function infoOf(infos, gameId) {
|
|
44
|
+
return infos.find((r) => openGameOf(r)?.game.id === gameId);
|
|
45
|
+
}
|
|
46
|
+
/** The account's colours from a war.app page carrying the client's startup parameters; undefined when unread. */
|
|
47
|
+
async function accountColors(ctx) {
|
|
48
|
+
try {
|
|
49
|
+
return readAccountColors(await openGamesPage(ctx), await ctx.bundle());
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The colour to accept with, as the lobby does (read from the bundle): none when the host locked my colour in; else
|
|
57
|
+
* the one asked for (refused when another player has it), else my preferred, else my secondary — each only when no
|
|
58
|
+
* player in the game has it — else the first standard colour still free (where the client would ask).
|
|
59
|
+
*/
|
|
60
|
+
async function inviteColor(ctx, requested, locked, lobby, gameId) {
|
|
61
|
+
if (locked) {
|
|
62
|
+
if (requested !== undefined) {
|
|
63
|
+
refuse(`The host locked in your colour in game ${gameId}, so none can be chosen.`, 'Leave color out.');
|
|
64
|
+
}
|
|
65
|
+
return { color: null, source: 'locked' };
|
|
66
|
+
}
|
|
67
|
+
const taken = lobby.colorsTaken;
|
|
68
|
+
if (requested !== undefined) {
|
|
69
|
+
if (taken.includes(requested)) {
|
|
70
|
+
refuse(`Colour ${requested} is taken by a player in game ${gameId}.`, 'Pass another color, or leave it out to let this tool pick one.');
|
|
71
|
+
}
|
|
72
|
+
return { color: requested, source: 'requested' };
|
|
73
|
+
}
|
|
74
|
+
const chosen = chooseJoinColor(await accountColors(ctx), taken);
|
|
75
|
+
if (!chosen) {
|
|
76
|
+
refuse(`Every standard colour is taken in game ${gameId}.`, `Pass color: a war.app colour index (${STANDARD_COLORS}–${GAME_COLOR_COUNT - 1}) your account has unlocked.`);
|
|
77
|
+
}
|
|
78
|
+
return chosen;
|
|
79
|
+
}
|
|
80
|
+
const POLICY_REPORTED_NOTE = "An invitation is the owner's choice, so a joining-policy break is reported here, never refused: confirming " +
|
|
81
|
+
'accepts the game whatever `policy` says.';
|
|
82
|
+
export function registerAcceptInviteTool(server, ctx) {
|
|
83
|
+
defineGatedWrite(server, {
|
|
84
|
+
title: 'Accept a war.app game invitation',
|
|
85
|
+
_meta: mintMeta('change', ['accept invitation', 'accept invite', 'join invited game', 'game invite']),
|
|
86
|
+
}, {
|
|
87
|
+
name: 'warapp_accept_invite',
|
|
88
|
+
description: 'Accept an invitation to a war.app (Warzone) game: a game warapp_my_games lists with your seat Invited ' +
|
|
89
|
+
"(war.app's AcceptGame, the lobby's Join button for an invited seat; read from the client bundle, UNVERIFIED " +
|
|
90
|
+
"live). The game is re-read from your games list first and refused unless your seat is still Invited; mod " +
|
|
91
|
+
'games are refused (a mod can hook the accept), and a coin entry fee unless accept_entry_fee. The preview ' +
|
|
92
|
+
"shows the game as warapp_list_open_games does and `policy`: the joining policy warapp_join_game applies (no " +
|
|
93
|
+
'Commerce, mods or custom scenarios; a cheap neutral; at most four seats; a boot time of at least 12 hours; no ' +
|
|
94
|
+
'lottery; no Local Deployment, Commanders, No-Split, army cap, Multi-Attack or non-default kill rates; at most ' +
|
|
95
|
+
"15 games at once; no negative bonus) — each rule the game breaks is reported, never refused: an invitation " +
|
|
96
|
+
"is the owner's choice. It accepts with your preferred colour, else your secondary, else a free standard " +
|
|
97
|
+
"colour (or the color you pass); none when the host locked your colour in. Reported `accepted` only once " +
|
|
98
|
+
'GameFeed or your games list shows you seated. Decline an invitation with warapp_leave_game.' +
|
|
99
|
+
`${noBrowserNote(ctx.hosted)} ${CONFIRM_INJECTION_RULE}`,
|
|
100
|
+
annotations: toolAnnotations({
|
|
101
|
+
title: 'Accept a war.app game invitation',
|
|
102
|
+
readOnly: false,
|
|
103
|
+
destructive: true,
|
|
104
|
+
idempotent: false,
|
|
105
|
+
openWorld: true,
|
|
106
|
+
}),
|
|
107
|
+
inputSchema: z.object({
|
|
108
|
+
game_id: gameIdArg,
|
|
109
|
+
accept_entry_fee: z.boolean().optional().describe('Allow paying a coin entry fee (default false: only free games).'),
|
|
110
|
+
color: z
|
|
111
|
+
.number()
|
|
112
|
+
.int()
|
|
113
|
+
.min(0)
|
|
114
|
+
.max(GAME_COLOR_COUNT - 1)
|
|
115
|
+
.optional()
|
|
116
|
+
.describe(`The colour to play as: a war.app colour index (0–${STANDARD_COLORS - 1} are the standard colours). ` +
|
|
117
|
+
'Default: your preferred colour, else your secondary, else the first standard colour no player has. ' +
|
|
118
|
+
'Refused when the host locked your colour in.'),
|
|
119
|
+
}),
|
|
120
|
+
async plan({ game_id, accept_entry_fee, color: requested }) {
|
|
121
|
+
const gameId = parseGameId(game_id);
|
|
122
|
+
const me = await ctx.myIdentity({ fresh: true });
|
|
123
|
+
if (me === undefined)
|
|
124
|
+
throw accountUnknown(ctx);
|
|
125
|
+
const { token, inGameId: myId } = me;
|
|
126
|
+
const infos = await myGameInfos(ctx);
|
|
127
|
+
const record = infoOf(infos, gameId);
|
|
128
|
+
const read = record ? openGameOf(record) : undefined;
|
|
129
|
+
if (!record || !read) {
|
|
130
|
+
refuse(`Game ${gameId} is not in your war.app games list, so there is no invitation to accept.`, 'warapp_my_games lists the games you are invited to (your seat Invited).');
|
|
131
|
+
}
|
|
132
|
+
const seat = seatIn(record, myId);
|
|
133
|
+
if (!seat)
|
|
134
|
+
refuse(`You are not a player in game ${gameId}, so there is no invitation to accept.`, 'Check the game id with warapp_my_games.');
|
|
135
|
+
if (seat.state !== 'Invited') {
|
|
136
|
+
refuse(holdsSeat(seat.state)
|
|
137
|
+
? `You have already accepted game ${gameId} (your seat is ${seat.state}).`
|
|
138
|
+
: `Your invitation to game ${gameId} is no longer open (your seat is ${seat.state}).`, 'warapp_my_games shows your seat in each game.');
|
|
139
|
+
}
|
|
140
|
+
if (read.game.rules.includes('Mods')) {
|
|
141
|
+
refuse(`Game ${gameId} uses mods, which can hook the accept in ways this tool cannot reproduce.`, 'Accept it from war.app instead.');
|
|
142
|
+
}
|
|
143
|
+
if (read.game.entryFeeCoins > 0 && accept_entry_fee !== true) {
|
|
144
|
+
refuse(`Game ${gameId} costs ${read.game.entryFeeCoins} coins to join.`, 'Pass accept_entry_fee: true to pay it.');
|
|
145
|
+
}
|
|
146
|
+
const { color, source } = await inviteColor(ctx, requested, seat.colorLocked === true, read.lobby, gameId);
|
|
147
|
+
const screened = await lobbyScreen(ctx, gameId);
|
|
148
|
+
const [game] = (await markLotteries(ctx, [read.game]));
|
|
149
|
+
let attended;
|
|
150
|
+
try {
|
|
151
|
+
attended = attendedGames(infos.map(gameOf), myId);
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
attended = undefined;
|
|
155
|
+
}
|
|
156
|
+
const account = { attendedGames: attended, negativeBonus: screened.negativeBonus };
|
|
157
|
+
const policy = joiningPolicy(game, screened.screen, account);
|
|
158
|
+
return {
|
|
159
|
+
gate: {
|
|
160
|
+
action: 'warapp.accept_invite',
|
|
161
|
+
summary: `Accept the invitation to war.app game ${gameId} (${game.pace}, ${game.seats} seats)`,
|
|
162
|
+
account: writeAccount(token),
|
|
163
|
+
target: gameId,
|
|
164
|
+
payload: { method: 'AcceptGame', gameId, color },
|
|
165
|
+
willSend: { game: gameId, color: color ?? 'locked by the host' },
|
|
166
|
+
preview: {
|
|
167
|
+
game: {
|
|
168
|
+
id: game.id,
|
|
169
|
+
name: untrustedText(game.name),
|
|
170
|
+
url: game.url,
|
|
171
|
+
pace: game.pace,
|
|
172
|
+
...(game.bootTime ? { bootTime: game.bootTime } : {}),
|
|
173
|
+
players: game.players,
|
|
174
|
+
openSeats: game.openSeats,
|
|
175
|
+
seats: game.seats,
|
|
176
|
+
teamGame: game.teamGame,
|
|
177
|
+
entryFeeCoins: game.entryFeeCoins,
|
|
178
|
+
prizeCoins: game.prizeCoins,
|
|
179
|
+
rules: game.rules,
|
|
180
|
+
...(game.lottery !== undefined ? { lottery: game.lottery, lotteryBasis: game.lotteryBasis } : {}),
|
|
181
|
+
plannerGaps: [...game.plannerGaps, ...screened.gaps],
|
|
182
|
+
},
|
|
183
|
+
screen: screened.screen,
|
|
184
|
+
...(screened.note ? { screenNote: screened.note } : {}),
|
|
185
|
+
policy,
|
|
186
|
+
...(policy.passes === false ? { policyBreaks: policy.breaks } : {}),
|
|
187
|
+
policyNote: POLICY_REPORTED_NOTE,
|
|
188
|
+
...(attended !== undefined ? { attendedGames: attended } : {}),
|
|
189
|
+
color: { index: color, source },
|
|
190
|
+
account: String(token),
|
|
191
|
+
note: 'Accepting makes you a player who must take turns until the game ends. AcceptGame is UNVERIFIED live.',
|
|
192
|
+
untrusted: UNTRUSTED_PREVIEW_NOTE,
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
state: {
|
|
196
|
+
gameId,
|
|
197
|
+
name: game.name,
|
|
198
|
+
url: game.url,
|
|
199
|
+
color,
|
|
200
|
+
account: String(token),
|
|
201
|
+
join: joinContextLog(game, screened.game, screened.screen, undefined, account),
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
},
|
|
205
|
+
async execute({ gameId, name, url, color, account, join }) {
|
|
206
|
+
await requireApprovedAccount(ctx, account);
|
|
207
|
+
const game = { id: gameId, name: untrustedText(name), url };
|
|
208
|
+
let vacationEnded = false;
|
|
209
|
+
const extra = () => (vacationEnded ? { vacationEnded: true } : {});
|
|
210
|
+
const notShown = () => ({
|
|
211
|
+
status: 'unconfirmed',
|
|
212
|
+
outcome: 'unconfirmed',
|
|
213
|
+
game,
|
|
214
|
+
...extra(),
|
|
215
|
+
warning: 'war.app took the accept, but neither GameFeed nor your games list shows you seated yet, so this could ' +
|
|
216
|
+
'not confirm it. Check warapp_my_games shortly.',
|
|
217
|
+
});
|
|
218
|
+
const result = await sendAndVerify({
|
|
219
|
+
send: async () => {
|
|
220
|
+
const env = await ctx.rpc.call('AcceptGame', Method.AcceptGame, (w) => writeAcceptGameParams(w, { gameId, color }));
|
|
221
|
+
vacationEnded = readAcceptGameReturn(env.body) ?? false;
|
|
222
|
+
},
|
|
223
|
+
// "Already in the game": the client treats it as a successful join.
|
|
224
|
+
refused: (e) => {
|
|
225
|
+
if (e.code === ALREADY_JOINED)
|
|
226
|
+
return 'ignore';
|
|
227
|
+
const wording = joinErrorWording(e);
|
|
228
|
+
return wording ? new WarappServerError(e.code, `${wording} (war.app error ${e.code})`) : undefined;
|
|
229
|
+
},
|
|
230
|
+
unanswered: (failure) => ({
|
|
231
|
+
status: 'unknown',
|
|
232
|
+
outcome: 'unknown',
|
|
233
|
+
game,
|
|
234
|
+
warning: `war.app did not confirm the accept (${failure}), so you may already be seated. Check warapp_my_games before trying again.`,
|
|
235
|
+
}),
|
|
236
|
+
readBack: () => confirmSeated(ctx, gameId),
|
|
237
|
+
unreadable: () => notShown(),
|
|
238
|
+
classify: (seated) => (seated ? { status: 'accepted', outcome: 'confirmed', game, ...extra() } : notShown()),
|
|
239
|
+
});
|
|
240
|
+
if (result.outcome === 'confirmed' && join)
|
|
241
|
+
await captureJoin(ctx, gameId, Number(account), join);
|
|
242
|
+
return result;
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
/** The game `gameId` as the open-games list shows it, from that list, else my games list; undefined when neither has it. */
|
|
247
|
+
async function findGame(ctx, gameId) {
|
|
248
|
+
const bundle = await ctx.bundle();
|
|
249
|
+
let listed;
|
|
250
|
+
let source = 'open-games';
|
|
251
|
+
let seat;
|
|
252
|
+
const myId = await ctx.myInGameId().catch(() => undefined);
|
|
253
|
+
try {
|
|
254
|
+
listed = parseOpenGamesPage(await openGamesPage(ctx), bundle).games.find((g) => g.id === gameId);
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
listed = undefined;
|
|
258
|
+
}
|
|
259
|
+
if (!listed && myId !== undefined) {
|
|
260
|
+
try {
|
|
261
|
+
const record = infoOf(await myGameInfos(ctx), gameId);
|
|
262
|
+
if (record) {
|
|
263
|
+
listed = openGameOf(record)?.game;
|
|
264
|
+
seat = seatIn(record, myId)?.state;
|
|
265
|
+
source = 'my-games';
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
catch {
|
|
269
|
+
listed = undefined;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (!listed)
|
|
273
|
+
return undefined;
|
|
274
|
+
const [marked] = (await markLotteries(ctx, [listed]));
|
|
275
|
+
const { breaks, warnings } = joiningPolicy(marked, null);
|
|
276
|
+
return {
|
|
277
|
+
game: {
|
|
278
|
+
...marked,
|
|
279
|
+
...(breaks.length ? { policyBreaks: breaks } : {}),
|
|
280
|
+
...(warnings ? { policyWarnings: warnings } : {}),
|
|
281
|
+
...(seat ? { mySeat: seat } : {}),
|
|
282
|
+
},
|
|
283
|
+
source,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
const CODE_NOTE = "Read with war.app's GetGameByInviteCode (read from the client bundle, UNVERIFIED live). The game is shown as " +
|
|
287
|
+
"warapp_list_open_games shows it when war.app's open-games list or your games list carries it; policyBreaks is " +
|
|
288
|
+
'advisory, and the neutral cost is not checked here. Joining through an invite code is not built: join a listed ' +
|
|
289
|
+
'game with warapp_join_game, accept an invitation with warapp_accept_invite, or open the url in war.app.';
|
|
290
|
+
export function registerInviteCodeTool(server, ctx) {
|
|
291
|
+
server.registerTool('warapp_get_game_by_invite_code', {
|
|
292
|
+
title: 'Read a war.app game by invite code',
|
|
293
|
+
description: untrustedDescription("Read the war.app (Warzone) game an invite code names (war.app's GetGameByInviteCode, the client's Game " +
|
|
294
|
+
'Invite Code screen; read from the client bundle, UNVERIFIED live). Returns `found: false` for a code ' +
|
|
295
|
+
"war.app does not know; `gameId: null` while the code's creator has not made the game yet (war.app's " +
|
|
296
|
+
'waiting screen); else the game id, its url, the code\'s player cap (`maxPlayers`) and, when war.app\'s ' +
|
|
297
|
+
'open-games list or your games list carries the game, `game` as warapp_list_open_games shows it (pace, boot ' +
|
|
298
|
+
'time, seats, team game, entry fee, cards, rules, plannerGaps, lottery, policyBreaks, policyWarnings) with ' +
|
|
299
|
+
'`source` saying which list, and `mySeat` when you are in it (Invited: accept with warapp_accept_invite). ' +
|
|
300
|
+
`Joining through a code is not built.${noBrowserNote(ctx.hosted)} Read-only.`),
|
|
301
|
+
_meta: lookupMeta(['invite code', 'game code', 'game invite code', 'join by code']),
|
|
302
|
+
annotations: readAnnotations('Read a war.app game by invite code'),
|
|
303
|
+
inputSchema: z.object({
|
|
304
|
+
code: z
|
|
305
|
+
.string()
|
|
306
|
+
.trim()
|
|
307
|
+
.min(1)
|
|
308
|
+
.max(MAX_INVITE_CODE_LENGTH)
|
|
309
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: refusing control characters is the point.
|
|
310
|
+
.regex(/^[^\u0000-\u001f\u007f]+$/, 'no control characters')
|
|
311
|
+
.describe('The invite code, as war.app gave it.'),
|
|
312
|
+
}),
|
|
313
|
+
}, async ({ code }) => {
|
|
314
|
+
let read;
|
|
315
|
+
try {
|
|
316
|
+
const env = await ctx.rpc.call('GetGameByInviteCode', Method.GetGameByInviteCode, (w) => writeGetGameByInviteCodeParams(w, code));
|
|
317
|
+
read = readGameInviteCode(await ctx.bundle(), env.body);
|
|
318
|
+
}
|
|
319
|
+
catch (e) {
|
|
320
|
+
if (e instanceof WarappServerError && e.code === INVITE_CODE_NOT_FOUND) {
|
|
321
|
+
return respond(undefined, ['compact'], () => ({ found: false, reason: 'war.app does not know this invite code ("Invalid code!").' }));
|
|
322
|
+
}
|
|
323
|
+
throw e;
|
|
324
|
+
}
|
|
325
|
+
if (!read) {
|
|
326
|
+
return respond(undefined, ['compact'], () => ({ found: false, reason: 'war.app answered with no invite-code record.' }));
|
|
327
|
+
}
|
|
328
|
+
const base = { found: true, code: untrustedText(read.code ?? code), gameId: read.gameId, maxPlayers: read.maxPlayers };
|
|
329
|
+
if (read.gameId === null) {
|
|
330
|
+
return respond(undefined, ['compact'], () => ({
|
|
331
|
+
...base,
|
|
332
|
+
game: null,
|
|
333
|
+
waiting: "The code's creator has not made its game yet (war.app shows a waiting screen); read it again later.",
|
|
334
|
+
}));
|
|
335
|
+
}
|
|
336
|
+
const url = `https://war.app/MultiPlayer?GameID=${read.gameId}`;
|
|
337
|
+
const found = await findGame(ctx, read.gameId);
|
|
338
|
+
return respond(undefined, ['compact'], () => ({
|
|
339
|
+
...base,
|
|
340
|
+
url,
|
|
341
|
+
...(found
|
|
342
|
+
? { game: found.game, source: found.source }
|
|
343
|
+
: { game: null, gameNote: "Neither war.app's open-games list nor your games list carries this game, so its settings were not read." }),
|
|
344
|
+
codeNote: CODE_NOTE,
|
|
345
|
+
}));
|
|
346
|
+
});
|
|
347
|
+
}
|
package/dist/tools/join-game.js
CHANGED
|
@@ -26,7 +26,7 @@ import { holdsSeat, playerStateName } from '../player-states.js';
|
|
|
26
26
|
import { NO_TEAM } from '../teams.js';
|
|
27
27
|
import { accountUnknown, defineGatedWrite, refuse, sendAndVerify } from './write-kit.js';
|
|
28
28
|
/** war.app's "already in the game" code: the client treats it as a successful join. */
|
|
29
|
-
const ALREADY_JOINED = 121;
|
|
29
|
+
export const ALREADY_JOINED = 121;
|
|
30
30
|
/** war.app's generic assertion failure; with "color is null" it is a join sent without a colour. */
|
|
31
31
|
const ASSERT_FAILED = 1;
|
|
32
32
|
const COLOR_UNAVAILABLE = 'That color is not available. Please pick a different color (pass color: a war.app colour index ' +
|
|
@@ -49,7 +49,7 @@ const JOIN_ERRORS = {
|
|
|
49
49
|
390: COLOR_UNAVAILABLE,
|
|
50
50
|
};
|
|
51
51
|
/** The wording for a join refusal this tool names itself, or undefined. */
|
|
52
|
-
function joinErrorWording(e) {
|
|
52
|
+
export function joinErrorWording(e) {
|
|
53
53
|
if (e.code === ASSERT_FAILED && /color is null/i.test(e.message)) {
|
|
54
54
|
return 'war.app refused the join because it was sent with no colour ("color is null").';
|
|
55
55
|
}
|
|
@@ -138,7 +138,7 @@ function joinColor(requested, html, bundle, lobby, gameId) {
|
|
|
138
138
|
* The lobby's screen from its GameFeed settings (#132): the open-games record carries no neutral
|
|
139
139
|
* sizes or fog, GameFeed does. Best effort — a failed read leaves the preview without a screen.
|
|
140
140
|
*/
|
|
141
|
-
async function lobbyScreen(ctx, gameId) {
|
|
141
|
+
export async function lobbyScreen(ctx, gameId) {
|
|
142
142
|
try {
|
|
143
143
|
// #423: the map too, for the negative-bonus check (the join reads one lobby; the map store keeps it).
|
|
144
144
|
const game = await ctx.client.getGame(gameId, { settings: true, map: true });
|
|
@@ -163,7 +163,7 @@ async function lobbyScreen(ctx, gameId) {
|
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
/** Whether GameFeed, else GetMyGames, shows the signed-in account in the game. */
|
|
166
|
-
async function confirmSeated(ctx, gameId) {
|
|
166
|
+
export async function confirmSeated(ctx, gameId) {
|
|
167
167
|
const token = await ctx.myInviteToken();
|
|
168
168
|
if (token !== undefined) {
|
|
169
169
|
try {
|