@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,142 @@
|
|
|
1
|
+
// warapp_vote_to_end (#631): vote to end a war.app game, or take the vote back, with the web client's
|
|
2
|
+
// VoteToEndGame (71), gated on the user's confirmation. The encoder is read from the client bundle and
|
|
3
|
+
// golden-pinned, UNVERIFIED live (docs/WEB-PROTOCOL.md "Votes to end the game").
|
|
4
|
+
//
|
|
5
|
+
// The votes live only in the game details: GameWL's last field, a dict of in-game id → the time each voted.
|
|
6
|
+
// When every player still playing has voted the game ends by vote (each seat's state EndedByVote), with no
|
|
7
|
+
// winner. The plan refuses a vote already cast, a vote to take back that was never cast, unreadable details,
|
|
8
|
+
// a finished game and a game I am not playing. The outcome is read back from the details and GameFeed.
|
|
9
|
+
import { CONFIRM_INJECTION_RULE, toolAnnotations } from '@chrischall/mcp-utils';
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import { Method, writeVoteToEndGameParams } from '../protocol/methods.js';
|
|
12
|
+
import { endVotesOf } from '../surrender-pending.js';
|
|
13
|
+
import { gameIdArg, shownAccount, UNTRUSTED_PREVIEW_NOTE, untrustedText } from './common.js';
|
|
14
|
+
import { gameInPlay, requireDetailsSeats, seatsView } from './end-game-common.js';
|
|
15
|
+
import { mintMeta } from './hints.js';
|
|
16
|
+
import { requireApprovedAccount, writeAccount } from './live-context.js';
|
|
17
|
+
import { noBrowserNote } from './session.js';
|
|
18
|
+
import { readDetailsSeats } from './surrender-pending.js';
|
|
19
|
+
import { defineGatedWrite, refuse, sendAndVerify, worded } from './write-kit.js';
|
|
20
|
+
/** The VoteToEndGame refusals, worded from the client's own messages (read from the bundle, UNVERIFIED live). */
|
|
21
|
+
const VOTE_ERRORS = {
|
|
22
|
+
4: 'Could not vote because the game is already over.',
|
|
23
|
+
7: 'Could not vote because you are no longer in the game.',
|
|
24
|
+
230: 'Could not vote because you are no longer in the game.',
|
|
25
|
+
88: 'The game has been deleted.',
|
|
26
|
+
};
|
|
27
|
+
/** The votes as a preview or result shows them: each seat by both ids, the names untrusted. */
|
|
28
|
+
export function endVotesView(game, v) {
|
|
29
|
+
return { voted: seatsView(game, v.voted), notYet: seatsView(game, v.notYet), myVote: v.myVote };
|
|
30
|
+
}
|
|
31
|
+
export function registerVoteToEndTool(server, ctx) {
|
|
32
|
+
defineGatedWrite(server, {
|
|
33
|
+
title: 'Vote to end a war.app game',
|
|
34
|
+
_meta: mintMeta('change', ['vote to end game', 'end game by vote warzone', 'draw game']),
|
|
35
|
+
}, {
|
|
36
|
+
name: 'warapp_vote_to_end',
|
|
37
|
+
description: "Vote to end a war.app (Warzone) game as the signed-in account (the client's Vote to End), or take your vote back " +
|
|
38
|
+
'(`withdraw: true`). Once every player still playing has voted, the game ends by vote at once with no winner ' +
|
|
39
|
+
'(every seat EndedByVote) and cannot be resumed. The plan reads the current votes from the game details and refuses ' +
|
|
40
|
+
'a vote you already cast, a vote to take back you never cast, unreadable details, finished games and games you are ' +
|
|
41
|
+
'not playing; war.app refuses it in tournament games. The preview lists who voted and who has not (by GameFeed and ' +
|
|
42
|
+
'in-game id) and whether yours is the last vote. The outcome is read back from the details and GameFeed (`voted`, ' +
|
|
43
|
+
'`withdrawn`, `ended`; `unconfirmed`, `unknown`). The encoding is read from the client bundle, UNVERIFIED live.' +
|
|
44
|
+
`${noBrowserNote(ctx.hosted)} ${CONFIRM_INJECTION_RULE}`,
|
|
45
|
+
annotations: toolAnnotations({
|
|
46
|
+
title: 'Vote to end a war.app game',
|
|
47
|
+
readOnly: false,
|
|
48
|
+
destructive: true,
|
|
49
|
+
idempotent: false,
|
|
50
|
+
openWorld: true,
|
|
51
|
+
}),
|
|
52
|
+
inputSchema: z.object({
|
|
53
|
+
game_id: gameIdArg,
|
|
54
|
+
withdraw: z.boolean().optional().describe('Take back your vote to end the game instead of casting it (default false).'),
|
|
55
|
+
}),
|
|
56
|
+
async plan({ game_id, withdraw }) {
|
|
57
|
+
const vote = !(withdraw ?? false);
|
|
58
|
+
const { gameId, me, game, seat, meInGame } = await gameInPlay(ctx, game_id, 'a vote to end the game');
|
|
59
|
+
const seats = await requireDetailsSeats(ctx, gameId, 'the votes to end the game');
|
|
60
|
+
const votes = endVotesOf(seats, meInGame);
|
|
61
|
+
if (!votes || votes.myVote === null)
|
|
62
|
+
refuse(`The votes to end game ${gameId} could not be read from the game details, so nothing was sent.`, 'Retry shortly.');
|
|
63
|
+
if (vote && votes.myVote)
|
|
64
|
+
refuse(`You have already voted to end game ${gameId}; nothing was sent.`, 'Pass `withdraw: true` to take the vote back.');
|
|
65
|
+
if (!vote && !votes.myVote)
|
|
66
|
+
refuse(`You have not voted to end game ${gameId}, so there is no vote to take back; nothing was sent.`, 'Check warapp_my_games (`endVotes`).');
|
|
67
|
+
const last = vote && votes.notYet.every((id) => id === meInGame);
|
|
68
|
+
const warning = !vote
|
|
69
|
+
? `This takes back your vote to end game ${gameId}: the game goes on.`
|
|
70
|
+
: last
|
|
71
|
+
? `This ENDS game ${gameId}: yours is the last vote, so the game ends by vote at once with no winner, and cannot be resumed.`
|
|
72
|
+
: `This votes to end game ${gameId}. ${votes.notYet.filter((id) => id !== meInGame).length} player(s) still playing have not voted; once ` +
|
|
73
|
+
'every one has, the game ends by vote at once with no winner, and cannot be resumed.';
|
|
74
|
+
return {
|
|
75
|
+
gate: {
|
|
76
|
+
action: vote ? 'warapp.vote_to_end' : 'warapp.withdraw_vote_to_end',
|
|
77
|
+
summary: vote ? `Vote to end war.app game ${gameId}` : `Take back your vote to end war.app game ${gameId}`,
|
|
78
|
+
account: writeAccount(me),
|
|
79
|
+
target: gameId,
|
|
80
|
+
payload: { method: 'VoteToEndGame', gameId, vote },
|
|
81
|
+
willSend: { game: gameId, vote },
|
|
82
|
+
preview: {
|
|
83
|
+
warning,
|
|
84
|
+
account: shownAccount(seat.name, me),
|
|
85
|
+
game: { id: gameId, name: game.name === undefined ? null : untrustedText(game.name), state: game.state },
|
|
86
|
+
votes: endVotesView(game, votes),
|
|
87
|
+
endsGameNow: last,
|
|
88
|
+
unverified: 'VoteToEndGame is read from the client bundle and not yet verified live; the outcome is read back from game state.',
|
|
89
|
+
untrusted: UNTRUSTED_PREVIEW_NOTE,
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
state: { gameId, me, meInGame, vote },
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
async execute({ gameId, me, meInGame, vote }) {
|
|
96
|
+
await requireApprovedAccount(ctx, writeAccount(me));
|
|
97
|
+
const game = { id: gameId };
|
|
98
|
+
return sendAndVerify({
|
|
99
|
+
send: async () => {
|
|
100
|
+
await ctx.rpc.call('VoteToEndGame', Method.VoteToEndGame, (w) => writeVoteToEndGameParams(w, { gameId, vote }));
|
|
101
|
+
},
|
|
102
|
+
refused: worded(VOTE_ERRORS),
|
|
103
|
+
unanswered: (failure) => ({
|
|
104
|
+
status: 'unknown',
|
|
105
|
+
outcome: 'unknown',
|
|
106
|
+
game,
|
|
107
|
+
vote,
|
|
108
|
+
warning: `war.app did not confirm the ${vote ? 'vote' : 'take-back'} (${failure}), so it may already have gone through. Check warapp_my_games before doing anything else.`,
|
|
109
|
+
}),
|
|
110
|
+
readBack: async () => ({ after: await ctx.client.getGame(gameId, { map: false }), seats: await readDetailsSeats(ctx, gameId) }),
|
|
111
|
+
unreadable: (failure) => ({
|
|
112
|
+
status: 'unconfirmed',
|
|
113
|
+
outcome: 'unconfirmed',
|
|
114
|
+
game,
|
|
115
|
+
vote,
|
|
116
|
+
warning: `war.app took the request, but GameFeed could not be read back (${failure}). Check warapp_my_games.`,
|
|
117
|
+
}),
|
|
118
|
+
classify: ({ after, seats }) => {
|
|
119
|
+
const mine = after.players.find((p) => p.id === me);
|
|
120
|
+
const state = { yourState: mine?.state ?? null, gameState: after.state };
|
|
121
|
+
// #645: an ended game is evidence for a vote only; taking a vote back never ends it.
|
|
122
|
+
if (vote && (mine?.state === 'EndedByVote' || after.state === 'Finished')) {
|
|
123
|
+
return { status: 'ended', outcome: 'confirmed', game, vote, ...state };
|
|
124
|
+
}
|
|
125
|
+
const votes = seats ? endVotesOf(seats, meInGame) : undefined;
|
|
126
|
+
if (votes && votes.myVote === vote) {
|
|
127
|
+
return { status: vote ? 'voted' : 'withdrawn', outcome: 'confirmed', game, vote, ...state, votes: endVotesView(after, votes) };
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
status: 'unconfirmed',
|
|
131
|
+
outcome: 'unconfirmed',
|
|
132
|
+
game,
|
|
133
|
+
vote,
|
|
134
|
+
...state,
|
|
135
|
+
warning: (votes ? 'war.app took the request, but the game details do not show your vote changed yet. ' : 'war.app took the request, but the votes could not be read back. ') +
|
|
136
|
+
'Check warapp_my_games shortly; do not send it again blindly.',
|
|
137
|
+
};
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
}
|
package/dist/tools/write-kit.js
CHANGED
|
@@ -19,12 +19,16 @@
|
|
|
19
19
|
// callers read them:
|
|
20
20
|
// warapp_begin_turn begun → confirmed; not_begun → not_applied; unconfirmed; unknown
|
|
21
21
|
// warapp_join_game joined → confirmed; unconfirmed; unknown
|
|
22
|
-
// warapp_leave_game left → confirmed; unconfirmed; unknown
|
|
22
|
+
// warapp_leave_game left, declined (an invitation, #652) → confirmed; unconfirmed; unknown
|
|
23
23
|
// warapp_close_finished_game closed → confirmed; unconfirmed; unknown
|
|
24
24
|
// warapp_surrender surrendered → confirmed; pending, still_playing → accepted;
|
|
25
25
|
// unchanged → unconfirmed; unknown
|
|
26
26
|
// warapp_accept_surrender accepted, pending (my acceptance read back, others still owe
|
|
27
27
|
// theirs) → confirmed; unconfirmed; unknown
|
|
28
|
+
// warapp_team_surrender proposed, accepted, declined, withdrawn, surrendered → confirmed;
|
|
29
|
+
// unconfirmed; unknown
|
|
30
|
+
// warapp_vote_to_end voted, withdrawn, ended → confirmed; unconfirmed; unknown
|
|
31
|
+
// warapp_boot_player booted → confirmed; unconfirmed; unknown
|
|
28
32
|
// warapp_uncommit_turn uncommitted → confirmed; unconfirmed; unknown
|
|
29
33
|
// warapp_submit_turn resolved, committed → confirmed; unknown after a send war.app
|
|
30
34
|
// accepted (read-back failed or shows nothing yet) → unconfirmed;
|
|
@@ -35,6 +39,23 @@
|
|
|
35
39
|
// warapp_delete_notification deleted → confirmed; unconfirmed (also after a refusal past the
|
|
36
40
|
// first id); unknown
|
|
37
41
|
// warapp_mark_chat_read read → confirmed; unconfirmed; unknown
|
|
42
|
+
// warapp_nudge_player nudged → accepted (nothing to read back); unknown
|
|
43
|
+
// warapp_join_ladder joined → confirmed; unconfirmed; unknown
|
|
44
|
+
// warapp_leave_ladder left → confirmed (287 read back as alreadyOff); unconfirmed; unknown
|
|
45
|
+
// warapp_answer_clan_invite / warapp_join_open_clan / warapp_leave_clan
|
|
46
|
+
// accepted / declined / joined / left → confirmed; unconfirmed; unknown
|
|
47
|
+
// warapp_set_quickmatch_settings saved → confirmed; unconfirmed; unknown
|
|
48
|
+
// warapp_vote_quickmatch_template voted → confirmed; unconfirmed; unknown
|
|
49
|
+
// warapp_join_tournament joined → confirmed; unconfirmed; unknown
|
|
50
|
+
// warapp_decline_tournament declined → confirmed; not_applied (started meanwhile); unconfirmed; unknown
|
|
51
|
+
// warapp_set_favorite_tournament set → confirmed; unconfirmed; unknown
|
|
52
|
+
// warapp_create_game created → confirmed; unconfirmed; unknown
|
|
53
|
+
// warapp_accept_invite accepted → confirmed; unconfirmed; unknown
|
|
54
|
+
// warapp_create_forum_thread created → confirmed; unconfirmed; unknown
|
|
55
|
+
// warapp_reply_forum_thread sent → confirmed; unconfirmed; unknown
|
|
56
|
+
// warapp_vote_forum_post voted → confirmed; unconfirmed; unknown
|
|
57
|
+
// warapp_watch_forum_thread watching / not-watching → confirmed, or accepted when the thread's
|
|
58
|
+
// watchers do not read; unconfirmed; unknown
|
|
38
59
|
// warapp_link_session linked → confirmed
|
|
39
60
|
import { defineWrite, McpToolError, registerWrite, } from '@chrischall/mcp-utils';
|
|
40
61
|
import { notSent, WarappServerError } from '../protocol/rpc.js';
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
// War.app tournaments (#636), through the web-client protocol: the replies of GetOpenTournaments (95), GetMyTournaments
|
|
2
|
+
// (90), GetTournamentDetails (104) and GetFavoriteTournaments (331), decoded by the client bundle's own readers by
|
|
3
|
+
// registered type name, fields by read order and checked by type and count — never by their minified names
|
|
4
|
+
// (docs/WEB-PROTOCOL.md, "Tournaments"). Every layout is read from the 6.09 bundle, UNVERIFIED live.
|
|
5
|
+
//
|
|
6
|
+
// Allowlists only: of a player only the account id, the name and the tournament state leave this file (a PlayerInfo2
|
|
7
|
+
// also carries a clan and a colour; a TournamentPlayer chat marks and who invited them). Names, the tournament's name,
|
|
8
|
+
// the host's description and a cancel reason are other players' words: returned raw here, cleaned by the tools.
|
|
9
|
+
import { McpToolError } from '@chrischall/mcp-utils';
|
|
10
|
+
import { cardTypeName } from './cards.js';
|
|
11
|
+
import { formatDuration, readSettings } from './open-games.js';
|
|
12
|
+
import { fields, isObj } from './protocol/decoded.js';
|
|
13
|
+
export const TOURNAMENT_INFO = 'warlight.shared.TournamentInfo';
|
|
14
|
+
export const MY_TOURNAMENTS_RETURN = 'warlight.shared.MyTournamentsReturn';
|
|
15
|
+
export const TOURNAMENT_DETAILS_RETURN = 'warlight.shared.GetTournamentDetailsReturn';
|
|
16
|
+
export const TOURNAMENT = 'warlight.shared.Tournament';
|
|
17
|
+
export const TOURNAMENT_PLAYER = 'warlight.shared.TournamentPlayer';
|
|
18
|
+
export const TOURNAMENT_GAME = 'warlight.shared.TournamentGame';
|
|
19
|
+
export const TOURNAMENT_GAME_INFO = 'warlight.shared.TournamentGameInfo';
|
|
20
|
+
export const TOURNAMENT_SETTINGS = 'warlight.shared.TournamentSettings';
|
|
21
|
+
export const TOURNAMENT_COINS = 'warlight.shared.TournamentCoinStructure';
|
|
22
|
+
export const FAVORITES_RETURN = 'warlight.shared.GetFavoriteTournamentsReturn';
|
|
23
|
+
const PLAYER_INFO2 = 'warlight.shared.PlayerInfo2';
|
|
24
|
+
/** Field positions in read order, and each record's whole field count (6.09). */
|
|
25
|
+
const TI = {
|
|
26
|
+
autoBoot: 0, unreadChat: 1, coins: 2, creator: 4, directBoot: 5, mapId: 8, name: 10, joined: 11, perGame: 12,
|
|
27
|
+
myState: 13, realTime: 14, startsAt: 15, settings: 16, state: 17, teamSize: 18, rounds: 19, id: 20, type: 21,
|
|
28
|
+
};
|
|
29
|
+
const TI_FIELDS = 22;
|
|
30
|
+
const TC = { creationCost: 0, entryFee: 1, prizes: 3 };
|
|
31
|
+
const TC_FIELDS = 5;
|
|
32
|
+
const TN = {
|
|
33
|
+
cancelReason: 1, games: 4, groups: 5, id: 7, perGame: 10, players: 11, settings: 16, startsAt: 17, state: 18,
|
|
34
|
+
teamSize: 19, rounds: 20, type: 21,
|
|
35
|
+
};
|
|
36
|
+
const TN_FIELDS = 24;
|
|
37
|
+
const TP = { info: 4, id: 5, state: 8, team: 9 };
|
|
38
|
+
const TP_FIELDS = 12;
|
|
39
|
+
const TG = { bye: 0, gameId: 1, info: 2, id: 3 };
|
|
40
|
+
const TG_FIELDS = 8;
|
|
41
|
+
const TGI_FIELDS = 2;
|
|
42
|
+
/**
|
|
43
|
+
* TournamentSettings: its own six fields (a date, the host, a string, the creator, the template id, the template name),
|
|
44
|
+
* then the 59 of the settings base (GameSettingsBase), so the base's positions are offset by 6.
|
|
45
|
+
*/
|
|
46
|
+
const TS = {
|
|
47
|
+
host: 1, creator: 3, templateId: 4, templateName: 5, autoBoot: 12, banking: 14, cards: 19, entryFee: 21, commanders: 22,
|
|
48
|
+
directBoot: 27, localDeployments: 38, luck: 39, mapId: 40, mods: 43, multiAttack: 45, name: 46, description: 55,
|
|
49
|
+
privateMessaging: 56, ranked: 58, realTime: 59,
|
|
50
|
+
};
|
|
51
|
+
const TS_FIELDS = 65;
|
|
52
|
+
const PI2 = { name: 4 };
|
|
53
|
+
const PI2_FIELDS = 8;
|
|
54
|
+
/** TimeSpans at or beyond this many ms are war.app's "never". */
|
|
55
|
+
const NEVER_MS = 922_336_666_814_565;
|
|
56
|
+
export const TOURNAMENT_TYPES = ['single-elimination', 'double-elimination', 'round-robin', 'cup'];
|
|
57
|
+
/** TournamentState, as the client's own status lines name it. */
|
|
58
|
+
export const TOURNAMENT_STATES = ['not-started', 'in-progress', 'finished', 'cancelled'];
|
|
59
|
+
/** TournamentPlayerState, as the client's own status lines name it. */
|
|
60
|
+
export const TOURNAMENT_PLAYER_STATES = ['invited', 'joined', 'declined', 'removed'];
|
|
61
|
+
const isInt = (v) => typeof v === 'number' && Number.isInteger(v);
|
|
62
|
+
const isNum = (v) => typeof v === 'number' && Number.isFinite(v);
|
|
63
|
+
const optStr = (v) => v === null || typeof v === 'string';
|
|
64
|
+
const optInt = (v) => v === null || isInt(v);
|
|
65
|
+
/** A reply in a shape this server does not understand. */
|
|
66
|
+
export class TournamentFormatError extends McpToolError {
|
|
67
|
+
constructor(detail) {
|
|
68
|
+
super(`war.app's tournament data arrived in an unexpected shape (${detail}).`, {
|
|
69
|
+
kind: 'unknown',
|
|
70
|
+
hint: 'The war.app client may have changed; the tournament can still be read in the war.app tab.',
|
|
71
|
+
});
|
|
72
|
+
this.name = 'TournamentFormatError';
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function record(v, type, count) {
|
|
76
|
+
if (!isObj(v) || v.$type !== type)
|
|
77
|
+
throw new TournamentFormatError(`expected a ${type.split('.').pop()}`);
|
|
78
|
+
const f = fields(v);
|
|
79
|
+
if (f.length !== count)
|
|
80
|
+
throw new TournamentFormatError(`a ${type.split('.').pop()} has ${f.length} fields, not ${count}`);
|
|
81
|
+
return f;
|
|
82
|
+
}
|
|
83
|
+
const named = (list, code) => (isInt(code) ? (list[code] ?? null) : null);
|
|
84
|
+
function bootOf(v) {
|
|
85
|
+
if (!isNum(v) || v <= 0 || v >= NEVER_MS)
|
|
86
|
+
return null;
|
|
87
|
+
return { minutes: Math.round(v / 60_000), shown: formatDuration(v) };
|
|
88
|
+
}
|
|
89
|
+
const dateOf = (v) => (v instanceof Date && Number.isFinite(v.getTime()) ? v.toISOString() : null);
|
|
90
|
+
/** A PlayerInfo2's name, nothing else of it. */
|
|
91
|
+
function nameOf(v) {
|
|
92
|
+
if (v === null || v === undefined)
|
|
93
|
+
return null;
|
|
94
|
+
const f = record(v, PLAYER_INFO2, PI2_FIELDS);
|
|
95
|
+
return typeof f[PI2.name] === 'string' ? f[PI2.name] : null;
|
|
96
|
+
}
|
|
97
|
+
function bracketSize(type, perGame, rounds, teamSize) {
|
|
98
|
+
if ((type !== 'single-elimination' && type !== 'double-elimination') || rounds === null || perGame < 1 || rounds < 0)
|
|
99
|
+
return null;
|
|
100
|
+
return perGame ** rounds * teamSize;
|
|
101
|
+
}
|
|
102
|
+
/** One TournamentInfo record. */
|
|
103
|
+
export function readTournamentInfo(v) {
|
|
104
|
+
const f = record(v, TOURNAMENT_INFO, TI_FIELDS);
|
|
105
|
+
const id = f[TI.id];
|
|
106
|
+
const name = f[TI.name];
|
|
107
|
+
const teamSize = f[TI.teamSize];
|
|
108
|
+
const perGame = f[TI.perGame];
|
|
109
|
+
const joined = f[TI.joined];
|
|
110
|
+
const rounds = f[TI.rounds];
|
|
111
|
+
const myState = f[TI.myState];
|
|
112
|
+
if (!isInt(id) || !optStr(name) || !isInt(teamSize) || !isInt(perGame) || !isInt(joined) || !optInt(rounds) || !optInt(myState)) {
|
|
113
|
+
throw new TournamentFormatError('a TournamentInfo lacks its id, name or sizes');
|
|
114
|
+
}
|
|
115
|
+
const type = named(TOURNAMENT_TYPES, f[TI.type]);
|
|
116
|
+
const settings = readSettings(f[TI.settings]);
|
|
117
|
+
let entryFee = 0;
|
|
118
|
+
const coins = f[TI.coins];
|
|
119
|
+
if (coins !== null) {
|
|
120
|
+
const c = record(coins, TOURNAMENT_COINS, TC_FIELDS);
|
|
121
|
+
if (isInt(c[TC.entryFee]))
|
|
122
|
+
entryFee = c[TC.entryFee];
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
id,
|
|
126
|
+
name,
|
|
127
|
+
type,
|
|
128
|
+
state: named(TOURNAMENT_STATES, f[TI.state]),
|
|
129
|
+
creator: nameOf(f[TI.creator]),
|
|
130
|
+
myState: myState === null ? null : named(TOURNAMENT_PLAYER_STATES, myState),
|
|
131
|
+
realTime: f[TI.realTime] === true,
|
|
132
|
+
directBoot: bootOf(f[TI.directBoot]),
|
|
133
|
+
autoBoot: bootOf(f[TI.autoBoot]),
|
|
134
|
+
mapId: isInt(f[TI.mapId]) ? f[TI.mapId] : null,
|
|
135
|
+
teamSize,
|
|
136
|
+
perGame,
|
|
137
|
+
rounds,
|
|
138
|
+
joined,
|
|
139
|
+
size: bracketSize(type, perGame, rounds, teamSize),
|
|
140
|
+
startsAt: dateOf(f[TI.startsAt]),
|
|
141
|
+
unreadChat: f[TI.unreadChat] === true,
|
|
142
|
+
entryFeeCoins: entryFee,
|
|
143
|
+
rules: settings?.rules ?? [],
|
|
144
|
+
...(settings?.cards ? { cards: settings.cards } : {}),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function infoList(v) {
|
|
148
|
+
if (v === null)
|
|
149
|
+
return [];
|
|
150
|
+
if (!Array.isArray(v))
|
|
151
|
+
throw new TournamentFormatError('no tournament list');
|
|
152
|
+
return v.filter((x) => x !== null).map(readTournamentInfo);
|
|
153
|
+
}
|
|
154
|
+
/** GetOpenTournaments' result (the body at the result-present flag): a list of TournamentInfo. */
|
|
155
|
+
export function readOpenTournaments(bundle, body) {
|
|
156
|
+
if (!body.bool())
|
|
157
|
+
return [];
|
|
158
|
+
const list = body.list((r) => (r.bool() ? bundle.readClass(TOURNAMENT_INFO, r) : null));
|
|
159
|
+
return infoList(list);
|
|
160
|
+
}
|
|
161
|
+
/** GetMyTournaments' result: my tournaments, and the open ones the reply carries beside them. */
|
|
162
|
+
export function readMyTournaments(bundle, body) {
|
|
163
|
+
if (!body.bool())
|
|
164
|
+
return { mine: [], open: [], total: 0 };
|
|
165
|
+
const f = record(bundle.readClass(MY_TOURNAMENTS_RETURN, body), MY_TOURNAMENTS_RETURN, 4);
|
|
166
|
+
return { total: isInt(f[0]) ? f[0] : 0, open: infoList(f[1]), mine: infoList(f[3]) };
|
|
167
|
+
}
|
|
168
|
+
const dictKeys = (v) => Array.isArray(v) ? v.map((e) => (Array.isArray(e) ? e[0] : undefined)).filter(isInt) : [];
|
|
169
|
+
function readTemplate(v) {
|
|
170
|
+
if (v === null)
|
|
171
|
+
return null;
|
|
172
|
+
const f = record(v, TOURNAMENT_SETTINGS, TS_FIELDS);
|
|
173
|
+
const bool = (k) => (typeof f[TS[k]] === 'boolean' ? f[TS[k]] : null);
|
|
174
|
+
const str = (k) => (typeof f[TS[k]] === 'string' && f[TS[k]] !== '' ? f[TS[k]] : null);
|
|
175
|
+
const int = (k) => (isInt(f[TS[k]]) ? f[TS[k]] : null);
|
|
176
|
+
const banking = int('banking');
|
|
177
|
+
return {
|
|
178
|
+
templateId: int('templateId'),
|
|
179
|
+
templateName: str('templateName'),
|
|
180
|
+
host: int('host'),
|
|
181
|
+
creator: nameOf(f[TS.creator]),
|
|
182
|
+
name: str('name'),
|
|
183
|
+
description: str('description'),
|
|
184
|
+
realTime: bool('realTime'),
|
|
185
|
+
directBoot: bootOf(f[TS.directBoot]),
|
|
186
|
+
autoBoot: bootOf(f[TS.autoBoot]),
|
|
187
|
+
bankingBootTimes: banking,
|
|
188
|
+
mapId: int('mapId'),
|
|
189
|
+
entryFeeCoins: int('entryFee') ?? 0,
|
|
190
|
+
cards: dictKeys(f[TS.cards]).map(cardTypeName),
|
|
191
|
+
modIds: dictKeys(f[TS.mods]),
|
|
192
|
+
commanders: bool('commanders'),
|
|
193
|
+
localDeployments: bool('localDeployments'),
|
|
194
|
+
multiAttack: bool('multiAttack'),
|
|
195
|
+
luck: isNum(f[TS.luck]) ? f[TS.luck] : null,
|
|
196
|
+
ranked: bool('ranked'),
|
|
197
|
+
privateMessaging: bool('privateMessaging'),
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function readPlayer(v) {
|
|
201
|
+
const f = record(v, TOURNAMENT_PLAYER, TP_FIELDS);
|
|
202
|
+
const id = f[TP.id];
|
|
203
|
+
if (!isInt(id))
|
|
204
|
+
throw new TournamentFormatError('a TournamentPlayer lacks its id');
|
|
205
|
+
// The allowlist: only these leave the parser.
|
|
206
|
+
return {
|
|
207
|
+
playerId: id,
|
|
208
|
+
name: nameOf(f[TP.info]),
|
|
209
|
+
state: named(TOURNAMENT_PLAYER_STATES, f[TP.state]),
|
|
210
|
+
team: isInt(f[TP.team]) ? f[TP.team] : -1,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function readGame(v) {
|
|
214
|
+
const f = record(v, TOURNAMENT_GAME, TG_FIELDS);
|
|
215
|
+
const id = f[TG.id];
|
|
216
|
+
const gameId = f[TG.gameId];
|
|
217
|
+
if (!isInt(id) || !optInt(gameId))
|
|
218
|
+
throw new TournamentFormatError('a TournamentGame lacks its id');
|
|
219
|
+
let players = null;
|
|
220
|
+
let stateCode = null;
|
|
221
|
+
if (f[TG.info] !== null) {
|
|
222
|
+
const g = record(f[TG.info], TOURNAMENT_GAME_INFO, TGI_FIELDS);
|
|
223
|
+
players = g[0] === null ? null : dictKeys(g[0]);
|
|
224
|
+
stateCode = isInt(g[1]) ? g[1] : null;
|
|
225
|
+
}
|
|
226
|
+
return { id, gameId, bye: f[TG.bye] !== null, players, stateCode };
|
|
227
|
+
}
|
|
228
|
+
/** GetTournamentDetails' result: the tournament, or `null` when the reply carries none. */
|
|
229
|
+
export function readTournamentDetails(bundle, body) {
|
|
230
|
+
if (!body.bool())
|
|
231
|
+
return null;
|
|
232
|
+
const ret = record(bundle.readClass(TOURNAMENT_DETAILS_RETURN, body), TOURNAMENT_DETAILS_RETURN, 3);
|
|
233
|
+
const t = ret[2];
|
|
234
|
+
if (t === null)
|
|
235
|
+
return null;
|
|
236
|
+
const f = record(t, TOURNAMENT, TN_FIELDS);
|
|
237
|
+
const id = f[TN.id];
|
|
238
|
+
const teamSize = f[TN.teamSize];
|
|
239
|
+
const perGame = f[TN.perGame];
|
|
240
|
+
const rounds = f[TN.rounds];
|
|
241
|
+
const reason = f[TN.cancelReason];
|
|
242
|
+
if (!isInt(id) || !isInt(teamSize) || !isInt(perGame) || !optInt(rounds) || !optStr(reason)) {
|
|
243
|
+
throw new TournamentFormatError('a Tournament lacks its id or sizes');
|
|
244
|
+
}
|
|
245
|
+
const playersDict = f[TN.players];
|
|
246
|
+
if (!(playersDict === null || Array.isArray(playersDict)))
|
|
247
|
+
throw new TournamentFormatError('no player dict');
|
|
248
|
+
const players = (playersDict ?? []).map((e) => (Array.isArray(e) ? e[1] : null)).filter((p) => p !== null).map(readPlayer);
|
|
249
|
+
const gameList = f[TN.games];
|
|
250
|
+
if (!(gameList === null || Array.isArray(gameList)))
|
|
251
|
+
throw new TournamentFormatError('no game list');
|
|
252
|
+
return {
|
|
253
|
+
id,
|
|
254
|
+
type: named(TOURNAMENT_TYPES, f[TN.type]),
|
|
255
|
+
state: named(TOURNAMENT_STATES, f[TN.state]),
|
|
256
|
+
teamSize,
|
|
257
|
+
perGame,
|
|
258
|
+
rounds,
|
|
259
|
+
groups: isInt(f[TN.groups]) ? f[TN.groups] : 0,
|
|
260
|
+
startsAt: dateOf(f[TN.startsAt]),
|
|
261
|
+
cancelReason: reason === '' ? null : reason,
|
|
262
|
+
players,
|
|
263
|
+
games: gameList === null ? null : gameList.filter((g) => g !== null).map(readGame),
|
|
264
|
+
settings: readTemplate(f[TN.settings]),
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
export function readFavoriteTournaments(bundle, body) {
|
|
268
|
+
if (!body.bool())
|
|
269
|
+
return [];
|
|
270
|
+
const f = record(bundle.readClass(FAVORITES_RETURN, body), FAVORITES_RETURN, 3);
|
|
271
|
+
const names = f[0];
|
|
272
|
+
const favs = f[1];
|
|
273
|
+
const placed = f[2];
|
|
274
|
+
if (!(names === null || Array.isArray(names)) || !(favs === null || Array.isArray(favs)) || !(placed === null || Array.isArray(placed))) {
|
|
275
|
+
throw new TournamentFormatError('no favourites lists');
|
|
276
|
+
}
|
|
277
|
+
const favSet = new Set((favs ?? []).filter(isInt));
|
|
278
|
+
const placeOf = new Map();
|
|
279
|
+
for (const e of placed ?? [])
|
|
280
|
+
if (Array.isArray(e) && isInt(e[0]) && isInt(e[1]))
|
|
281
|
+
placeOf.set(e[0], e[1]);
|
|
282
|
+
const out = [];
|
|
283
|
+
for (const e of names ?? []) {
|
|
284
|
+
if (!Array.isArray(e) || !isInt(e[0]))
|
|
285
|
+
continue;
|
|
286
|
+
out.push({ id: e[0], name: typeof e[1] === 'string' ? e[1] : null, favorite: favSet.has(e[0]), placed: placeOf.get(e[0]) ?? null });
|
|
287
|
+
}
|
|
288
|
+
// A favourite the reply names without a name still shows.
|
|
289
|
+
for (const id of favSet)
|
|
290
|
+
if (!out.some((t) => t.id === id))
|
|
291
|
+
out.push({ id, name: null, favorite: true, placed: placeOf.get(id) ?? null });
|
|
292
|
+
return out;
|
|
293
|
+
}
|
|
294
|
+
export function gamesCommitment(t) {
|
|
295
|
+
const r = t.rounds;
|
|
296
|
+
switch (t.type) {
|
|
297
|
+
case 'single-elimination':
|
|
298
|
+
return r === null
|
|
299
|
+
? { min: 1, max: null, basis: 'Single elimination: one game a round until you lose; the round count was not read.' }
|
|
300
|
+
: { min: 1, max: r, basis: `Single elimination over ${r} rounds: one game a round until you lose (a bye skips one).` };
|
|
301
|
+
case 'double-elimination':
|
|
302
|
+
return r === null
|
|
303
|
+
? { min: 2, max: null, basis: 'Double elimination: out after two losses; the round count was not read.' }
|
|
304
|
+
: { min: 2, max: 2 * r + 1, basis: `Double elimination over ${r} rounds: out after two losses, so at least 2 games and about ${2 * r + 1} at most (winners' and losers' brackets and the final; our estimate).` };
|
|
305
|
+
case 'round-robin':
|
|
306
|
+
return t.perGame > 1
|
|
307
|
+
? { min: t.perGame - 1, max: t.perGame - 1, basis: `Round robin among ${t.perGame} teams: one game against each other team.` }
|
|
308
|
+
: { min: null, max: null, basis: 'Round robin: one game against each other entrant; the entrant count was not read.' };
|
|
309
|
+
case 'cup': {
|
|
310
|
+
const group = t.perGame > 1 ? t.perGame - 1 : null;
|
|
311
|
+
const knockout = t.groups > 0 ? Math.ceil(Math.log2(2 * t.groups)) : null;
|
|
312
|
+
return {
|
|
313
|
+
min: group,
|
|
314
|
+
max: group !== null && knockout !== null ? group + knockout : null,
|
|
315
|
+
basis: `Cup: one game against each other team in a group of ${t.perGame}${t.groups > 0 ? `, then up to ${knockout} knockout rounds for the top two of ${t.groups} groups` : ''} (our estimate).`,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
default:
|
|
319
|
+
return { min: null, max: null, basis: 'The tournament type was not read.' };
|
|
320
|
+
}
|
|
321
|
+
}
|
package/dist/trend.js
CHANGED
package/dist/version.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// Single source of truth for the server version. release-please bumps the
|
|
2
2
|
// literal on the marked line (registered in release-please-config.json
|
|
3
3
|
// extra-files); every other module imports VERSION from here.
|
|
4
|
-
export const VERSION = '0.
|
|
4
|
+
export const VERSION = '0.23.1'; // x-release-please-version
|