@chrischall/warapp-mcp 0.22.1 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +2 -0
- package/dist/analysis/plan/report.js +2 -2
- package/dist/analysis/plan/targets.js +15 -5
- package/dist/analysis/plan/threats.js +55 -2
- package/dist/analysis/planner.js +2 -1
- package/dist/bundle.js +10186 -3727
- 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/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/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 +1 -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/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/protocol/methods.js
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
// war.app web-client method ids (the int32 in every frame header) and the
|
|
2
|
-
// parameter writers this server uses. The ids are protocol
|
|
3
|
-
// (
|
|
4
|
-
//
|
|
2
|
+
// parameter writers this server uses. The ids are protocol 244's: 244 inserted two methods
|
|
3
|
+
// (AddPlayersToPrivateDiscussion 192, GetFreeModGameStatus 266), which moved Subscribe, GameUpdated and the
|
|
4
|
+
// notification calls (#626); 243 had inserted six (ChangeCommitConfirmation 26, TeamSurrender 70,
|
|
5
|
+
// TournamentGroup 94, UploadSharedImage 129, ChatRoomReactionsChanged 247, SetReaction 285) and renumbered
|
|
6
|
+
// everything after each. The name is also the `m=` query value of
|
|
5
7
|
// https://war.app/Services?m=<name>&js=1.
|
|
6
8
|
export const Method = {
|
|
9
|
+
/** #641: the signed-in account's friends list (auth only; reply GetFriendsReturn). Bundle-read, UNVERIFIED live. */
|
|
10
|
+
GetFriends: 0,
|
|
11
|
+
/** #641: nudge a player who is holding a game up (`writeNudgeParams`). Bundle-read, UNVERIFIED live. */
|
|
12
|
+
Nudge: 8,
|
|
7
13
|
/** Exists in the client's method table, but the web client never calls it (open games come from a page). */
|
|
8
14
|
GetOpenGames: 10,
|
|
15
|
+
/** #635: create a game (the bundle's writer; UNVERIFIED live). */
|
|
16
|
+
CreateGame: 33,
|
|
9
17
|
GetGameDetails: 39,
|
|
10
18
|
GameRefresh: 40,
|
|
11
19
|
GetLatestGameInfo: 41,
|
|
@@ -22,6 +30,12 @@ export const Method = {
|
|
|
22
30
|
DeclineGame: 65,
|
|
23
31
|
Surrender: 68,
|
|
24
32
|
AcceptSurrender: 69,
|
|
33
|
+
/** #630: propose, accept, decline or withdraw a team surrender (read from the bundle's writer, UNVERIFIED live). */
|
|
34
|
+
TeamSurrender: 70,
|
|
35
|
+
/** #631: vote to end the game, or take the vote back (read from the bundle's writer, UNVERIFIED live). */
|
|
36
|
+
VoteToEndGame: 71,
|
|
37
|
+
/** #632: boot a player who has run past the direct-boot time (read from the bundle's writer, UNVERIFIED live). */
|
|
38
|
+
BootPlayer: 72,
|
|
25
39
|
GetMapDetails: 75,
|
|
26
40
|
SendOrders: 76,
|
|
27
41
|
SendInProgressOrders: 77,
|
|
@@ -37,11 +51,93 @@ export const Method = {
|
|
|
37
51
|
* Parameters as UnCommit's (auth, int32 game id), read from the bundle's writer; UNVERIFIED live.
|
|
38
52
|
*/
|
|
39
53
|
GetEndGameWindowData: 85,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
54
|
+
/**
|
|
55
|
+
* #637, ladders: read from the 6.09 bundle's writers and readers, UNVERIFIED live. GetLadderSeasons, GetLadderPlayers
|
|
56
|
+
* and GetLadderGames take no auth block (`methodTakesAuth`); the rest do.
|
|
57
|
+
*/
|
|
58
|
+
JoinLadder: 160,
|
|
59
|
+
LeaveLadder: 161,
|
|
60
|
+
GetLadderSeasons: 162,
|
|
61
|
+
GetLadderSeason: 163,
|
|
62
|
+
GetLadderPlayers: 164,
|
|
63
|
+
GetLadderGames: 165,
|
|
64
|
+
GetLadderPlayer: 166,
|
|
65
|
+
/** #636, tournaments: read from the 6.09 bundle's writers, UNVERIFIED live. */
|
|
66
|
+
GetMyTournaments: 90,
|
|
67
|
+
GetOpenTournaments: 95,
|
|
68
|
+
JoinTournament: 97,
|
|
69
|
+
GetTournamentChat: 99,
|
|
70
|
+
DeclineTournament: 100,
|
|
71
|
+
GetTournamentDetails: 104,
|
|
72
|
+
/** #629, private mail (Discussions): read from the 6.09 bundle's writers, UNVERIFIED live. */
|
|
73
|
+
CreatePrivateDiscussion: 191,
|
|
74
|
+
AddPlayersToPrivateDiscussion: 192,
|
|
75
|
+
DeletePrivateDiscussion: 193,
|
|
76
|
+
SearchPrivateDiscussions: 194,
|
|
77
|
+
/** A post to a thread: a mail reply is one (the client's Reply button on a mail thread). */
|
|
78
|
+
CreatePost: 196,
|
|
79
|
+
GetDiscussion: 198,
|
|
80
|
+
/** #635: the account's own saved templates (the bundle's writer; UNVERIFIED live). */
|
|
81
|
+
GetTemplates: 134,
|
|
82
|
+
/** #635: templates by id (the bundle's writer; UNVERIFIED live). */
|
|
83
|
+
GetTemplatesByID: 135,
|
|
84
|
+
/** #635: one template with its settings; takes no auth block (the bundle's writer; UNVERIFIED live). */
|
|
85
|
+
GetTemplate: 138,
|
|
86
|
+
/**
|
|
87
|
+
* #639, clans: read from the 6.09 bundle's writers, UNVERIFIED live. GetClans and GetOpenClans take no auth
|
|
88
|
+
* block (the client writes nothing after the header); the rest take auth, then the int32s `writeClanIdParams`
|
|
89
|
+
* and `writeRemoveFromClanParams` write. RemoveFromClan with my own id is the client's Leave button.
|
|
90
|
+
*/
|
|
91
|
+
GetClans: 208,
|
|
92
|
+
GetClan: 211,
|
|
93
|
+
AcceptClanInvite: 216,
|
|
94
|
+
RejectClanInvite: 217,
|
|
95
|
+
RemoveFromClan: 219,
|
|
96
|
+
GetOpenClans: 226,
|
|
97
|
+
JoinOpenClan: 227,
|
|
98
|
+
/** #640, forums (Discussions of the forum types): read from the 6.09 bundle's writers, UNVERIFIED live. */
|
|
99
|
+
GetForums: 189,
|
|
100
|
+
CreateForumThread: 190,
|
|
101
|
+
GetForumThreads: 199,
|
|
102
|
+
SearchForum: 201,
|
|
103
|
+
ForumVote: 204,
|
|
104
|
+
WatchForumThread: 328,
|
|
105
|
+
GetGroupForumThreads: 354,
|
|
106
|
+
Subscribe: 243,
|
|
107
|
+
/** #633: the client's "Game Invite Code" screen (`GameInviteCode` reply); read from the bundle, UNVERIFIED live. */
|
|
108
|
+
GetGameByInviteCode: 295,
|
|
109
|
+
/** #635, new in protocol 244: the member free-mod-game status (the bundle's writer; UNVERIFIED live). */
|
|
110
|
+
GetFreeModGameStatus: 266,
|
|
111
|
+
/** #635: a code a game can be joined by (the bundle's writer; UNVERIFIED live). */
|
|
112
|
+
CreateGameInviteCode: 294,
|
|
113
|
+
GameUpdated: 246,
|
|
114
|
+
/** #639, clan wars: GetClanWars takes no auth block; GetClanWar and GetClanWarGames do. UNVERIFIED live. */
|
|
115
|
+
GetClanWar: 313,
|
|
116
|
+
GetClanWarGames: 316,
|
|
117
|
+
GetClanWars: 324,
|
|
118
|
+
/**
|
|
119
|
+
* #638, quickmatch: read from the 6.09 bundle's writers, UNVERIFIED live. 270 (CheckQuickmatchMD) has no writer
|
|
120
|
+
* in the client and is never sent; the real-time queue (275, 278, 279) is out of scope.
|
|
121
|
+
*/
|
|
122
|
+
GetQuickmatchSettings: 268,
|
|
123
|
+
SetQuickmatchSettings: 269,
|
|
124
|
+
GetQuickmatchTemplates: 271,
|
|
125
|
+
GetQuickmatchTemplateVotes: 272,
|
|
126
|
+
SetQuickmatchTemplateVotes: 274,
|
|
127
|
+
/** No auth block: a list of template ids. */
|
|
128
|
+
GetTemplateLengths: 276,
|
|
129
|
+
/** No auth block: a category, a start index and a count. */
|
|
130
|
+
GetQuickmatchLeaderboards: 280,
|
|
131
|
+
GetInAppNotifications: 325,
|
|
132
|
+
DeleteInAppNotification: 326,
|
|
133
|
+
AcknowledgeInAppNotifications: 327,
|
|
134
|
+
/** #634: add or remove my reaction on a message (the bundle's writer; UNVERIFIED live). */
|
|
135
|
+
SetReaction: 287,
|
|
136
|
+
/** #637: the signed-in account's standing on each ladder it has played (auth only; a list of LadderStat). */
|
|
137
|
+
GetLadderStats: 333,
|
|
138
|
+
/** #636: the tournaments I may show on my profile, and which I do (auth only). */
|
|
139
|
+
GetFavoriteTournaments: 331,
|
|
140
|
+
SetFavoriteTournament: 332,
|
|
45
141
|
};
|
|
46
142
|
const NAMES = new Map(Object.entries(Method).map(([name, id]) => [id, name]));
|
|
47
143
|
/** The method's name for a known id, or undefined. */
|
|
@@ -52,6 +148,44 @@ export function methodName(id) {
|
|
|
52
148
|
export function writeGetMapDetailsParams(w, mapId) {
|
|
53
149
|
w.int32(mapId);
|
|
54
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* GetClan, AcceptClanInvite, RejectClanInvite and JoinOpenClan(auth, …) — #639. READ FROM THE CLIENT BUNDLE's
|
|
153
|
+
* writers, NOT VERIFIED LIVE: after the auth block, the int32 clan id (an invite is answered by the inviting
|
|
154
|
+
* clan's id; the client has no invite id).
|
|
155
|
+
*/
|
|
156
|
+
export function writeClanIdParams(w, clanId) {
|
|
157
|
+
w.int32(clanId);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* RemoveFromClan(auth, …) — #639, bundle-read, UNVERIFIED live: the int32 in-game id of the player removed. The
|
|
161
|
+
* client's Leave button sends the signed-in account's own id; removing anyone else is clan management, which
|
|
162
|
+
* this server does not do.
|
|
163
|
+
*/
|
|
164
|
+
export function writeRemoveFromClanParams(w, playerId) {
|
|
165
|
+
w.int32(playerId);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* GetClanWar(auth, …) — #639, bundle-read, UNVERIFIED live: an optional int32 war id (a present flag, then the
|
|
169
|
+
* id); absent asks for the current war.
|
|
170
|
+
*/
|
|
171
|
+
export function writeGetClanWarParams(w, warId) {
|
|
172
|
+
if (warId === undefined)
|
|
173
|
+
w.bool(false);
|
|
174
|
+
else
|
|
175
|
+
w.bool(true).int32(warId);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* GetClanWarGames(auth, …) — #639, bundle-read, UNVERIFIED live: the int32 war id, an optional int32 clan id
|
|
179
|
+
* (present flag, then the id), the int32 offset of the first game, then the int32 page size.
|
|
180
|
+
*/
|
|
181
|
+
export function writeGetClanWarGamesParams(w, p) {
|
|
182
|
+
w.int32(p.warId);
|
|
183
|
+
if (p.clanId === undefined)
|
|
184
|
+
w.bool(false);
|
|
185
|
+
else
|
|
186
|
+
w.bool(true).int32(p.clanId);
|
|
187
|
+
w.int32(p.offset).int32(p.count);
|
|
188
|
+
}
|
|
55
189
|
/** GetTerritoryPicks(auth, gameId, playerId) — the parameters after the auth block. */
|
|
56
190
|
export function writeGetTerritoryPicksParams(w, gameId, playerId) {
|
|
57
191
|
w.int32(gameId).int32(playerId);
|
|
@@ -122,6 +256,44 @@ export function readAcceptOpenSeatReturn(body) {
|
|
|
122
256
|
const vacationEnded = body.bool();
|
|
123
257
|
return body.bool() ? { vacationEnded, otherGameId: body.int32() } : { vacationEnded };
|
|
124
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* AcceptGame(auth, …) — accept an invitation (#633), the lobby's Join button for an invited seat. READ FROM THE
|
|
261
|
+
* CLIENT BUNDLE's writer, NOT VERIFIED LIVE: the int32 game id, an optional GameColor (a present flag, then the
|
|
262
|
+
* colour index; the client sends it absent when my seat's colour is locked in), then the "a mod hooks this method"
|
|
263
|
+
* bool, sent false (mod games are refused).
|
|
264
|
+
*/
|
|
265
|
+
export function writeAcceptGameParams(w, p) {
|
|
266
|
+
if (p.color !== null && (!Number.isInteger(p.color) || p.color < 0 || p.color >= GAME_COLOR_COUNT)) {
|
|
267
|
+
throw new RangeError(`war.app colour index out of range: ${p.color} (0..${GAME_COLOR_COUNT - 1})`);
|
|
268
|
+
}
|
|
269
|
+
w.int32(p.gameId);
|
|
270
|
+
if (p.color === null)
|
|
271
|
+
w.bool(false);
|
|
272
|
+
else
|
|
273
|
+
w.bool(true).int32(p.color);
|
|
274
|
+
w.bool(false); // a mod hooks this join
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* An AcceptGame reply: one bool (no present flag), the client's "this action has ended your vacation". `undefined`
|
|
278
|
+
* when the reply carries nothing. Never a success signal: the accept is read back from game state.
|
|
279
|
+
*/
|
|
280
|
+
export function readAcceptGameReturn(body) {
|
|
281
|
+
return body.remaining > 0 ? body.bool() : undefined;
|
|
282
|
+
}
|
|
283
|
+
/** The longest invite code this server sends (war.app's codes are short; a bound on what a caller passes). */
|
|
284
|
+
export const MAX_INVITE_CODE_LENGTH = 64;
|
|
285
|
+
/**
|
|
286
|
+
* GetGameByInviteCode(auth, code) — the client's "Game Invite Code" screen (#633). READ FROM THE CLIENT BUNDLE's
|
|
287
|
+
* writer, NOT VERIFIED LIVE: after the auth block one nullable string, the code as typed. The reply is a present
|
|
288
|
+
* flag, then a `warlight.shared.GameInviteCode` (src/invite-code.ts); server error 651 is "Invalid code!".
|
|
289
|
+
*/
|
|
290
|
+
export function writeGetGameByInviteCodeParams(w, code) {
|
|
291
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: refusing control characters is the point.
|
|
292
|
+
if (code.length === 0 || code.length > MAX_INVITE_CODE_LENGTH || /[\u0000-\u001f\u007f]/.test(code)) {
|
|
293
|
+
throw new RangeError(`not an invite code: 1–${MAX_INVITE_CODE_LENGTH} characters, no control characters`);
|
|
294
|
+
}
|
|
295
|
+
w.string(code);
|
|
296
|
+
}
|
|
125
297
|
/**
|
|
126
298
|
* Surrender(auth, …) — VERIFIED live 2026-11-12 (issue #30): the game id, the
|
|
127
299
|
* surrender flag (false takes back a pending surrender), then the per-method
|
|
@@ -139,6 +311,102 @@ export function writeSurrenderParams(w, p) {
|
|
|
139
311
|
export function writeAcceptSurrenderParams(w, p) {
|
|
140
312
|
w.int32(p.gameId).int32(p.playerId).bool(p.accept).bool(false);
|
|
141
313
|
}
|
|
314
|
+
/** The client's `TeamSurrenderAction` enum (#630), sent as one byte. */
|
|
315
|
+
export const TeamSurrenderAction = { propose: 0, accept: 1, decline: 2, withdraw: 3 };
|
|
316
|
+
/**
|
|
317
|
+
* TeamSurrender(auth, …) — #630. READ FROM THE CLIENT BUNDLE's writer, NOT VERIFIED LIVE: after the
|
|
318
|
+
* auth block the int32 game id, then the action as a one-byte enum, and nothing after it. No result payload.
|
|
319
|
+
*/
|
|
320
|
+
export function writeTeamSurrenderParams(w, p) {
|
|
321
|
+
w.int32(p.gameId).u8(TeamSurrenderAction[p.action]);
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* VoteToEndGame(auth, …) — #631. READ FROM THE CLIENT BUNDLE's writer, NOT VERIFIED LIVE: after the auth
|
|
325
|
+
* block the int32 game id, then the vote flag (false takes the vote back), and nothing after it. No result payload.
|
|
326
|
+
*/
|
|
327
|
+
export function writeVoteToEndGameParams(w, p) {
|
|
328
|
+
w.int32(p.gameId).bool(p.vote);
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* BootPlayer(auth, …) — #632. READ FROM THE CLIENT BUNDLE's writer, NOT VERIFIED LIVE: after the auth block
|
|
332
|
+
* the int32 game id, the int32 in-game id of the player booted, then the per-method "a mod hooks this
|
|
333
|
+
* method" bool, sent false. No result payload.
|
|
334
|
+
*/
|
|
335
|
+
export function writeBootPlayerParams(w, p) {
|
|
336
|
+
w.int32(p.gameId).int32(p.playerId).bool(false);
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* The preset reminders a nudge carries, by the index Nudge sends (#641). war.app has four and sends the
|
|
340
|
+
* text itself; the names are ours, describing each in our own words.
|
|
341
|
+
*/
|
|
342
|
+
export const NUDGE_MESSAGES = {
|
|
343
|
+
/** Tells the player it is their turn. */
|
|
344
|
+
turn: 0,
|
|
345
|
+
/** A blunt hurry-up. */
|
|
346
|
+
hurry: 1,
|
|
347
|
+
/** Asks politely that they take their turn when they can (the one the client's lobby nudge sends). */
|
|
348
|
+
polite: 2,
|
|
349
|
+
/** Says they are holding the game up. */
|
|
350
|
+
holding_up: 3,
|
|
351
|
+
};
|
|
352
|
+
/**
|
|
353
|
+
* Nudge(auth, …) — remind a player who is holding a game up (#641). READ FROM THE CLIENT BUNDLE's writer,
|
|
354
|
+
* NOT VERIFIED LIVE: after the auth block the int32 in-game id of the player nudged, the int32 game id,
|
|
355
|
+
* then the int32 index of the preset reminder. No result payload.
|
|
356
|
+
*/
|
|
357
|
+
export function writeNudgeParams(w, p) {
|
|
358
|
+
if (!Number.isInteger(p.message) || p.message < 0 || p.message > 3) {
|
|
359
|
+
throw new RangeError(`A nudge message index is 0..3, not ${p.message}.`);
|
|
360
|
+
}
|
|
361
|
+
w.int32(p.playerId).int32(p.gameId).int32(p.message);
|
|
362
|
+
}
|
|
363
|
+
/** The page size the client asks GetLadderPlayers and GetLadderGames for (#637). */
|
|
364
|
+
export const LADDER_PAGE = 50;
|
|
365
|
+
const ladderStart = (start) => {
|
|
366
|
+
if (!Number.isInteger(start) || start < 0)
|
|
367
|
+
throw new RangeError(`A ladder page start is a whole number from 0, not ${start}.`);
|
|
368
|
+
return start;
|
|
369
|
+
};
|
|
370
|
+
/**
|
|
371
|
+
* JoinLadder(auth, …) — join a ladder (#637). READ FROM THE CLIENT BUNDLE's writer, NOT VERIFIED LIVE: after the auth
|
|
372
|
+
* block the int32 ladder (`LadderEnum`: 0 1v1, 1 2v2, 2 seasonal, 4 3v3), then the int32 number of ladder games to
|
|
373
|
+
* hold at once. The result is one bool: whether joining ended the account's vacation.
|
|
374
|
+
*/
|
|
375
|
+
export function writeJoinLadderParams(w, p) {
|
|
376
|
+
w.int32(p.ladder).int32(p.gamesAtOnce);
|
|
377
|
+
}
|
|
378
|
+
/** LeaveLadder(auth, ladder) — leave a ladder (#637; bundle-read, UNVERIFIED live): the int32 ladder. No result. */
|
|
379
|
+
export function writeLeaveLadderParams(w, p) {
|
|
380
|
+
w.int32(p.ladder);
|
|
381
|
+
}
|
|
382
|
+
/** GetLadderSeason(auth, seasonId) — one ladder season's page (#637; bundle-read, UNVERIFIED live). */
|
|
383
|
+
export function writeGetLadderSeasonParams(w, p) {
|
|
384
|
+
w.int32(p.seasonId);
|
|
385
|
+
}
|
|
386
|
+
/** GetLadderPlayers(seasonId, start, 50) — a page of a season's standings, no auth (#637; bundle-read, UNVERIFIED live). */
|
|
387
|
+
export function writeGetLadderPlayersParams(w, p) {
|
|
388
|
+
w.int32(p.seasonId).int32(ladderStart(p.start)).int32(LADDER_PAGE);
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* GetLadderGames(seasonId, playerId?, start, 50) — a page of a season's games, optionally one player's, no auth (#637;
|
|
392
|
+
* bundle-read, UNVERIFIED live): the int32 season, an optional int32 in-game player id (present flag, then the id),
|
|
393
|
+
* the int32 start and the int32 page size.
|
|
394
|
+
*/
|
|
395
|
+
export function writeGetLadderGamesParams(w, p) {
|
|
396
|
+
w.int32(p.seasonId);
|
|
397
|
+
if (p.playerId === undefined)
|
|
398
|
+
w.bool(false);
|
|
399
|
+
else
|
|
400
|
+
w.bool(true).int32(p.playerId);
|
|
401
|
+
w.int32(ladderStart(p.start)).int32(LADDER_PAGE);
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* GetLadderPlayer(auth, seasonId, playerId, true) — one player's ladder page (#637; bundle-read, UNVERIFIED live): the
|
|
405
|
+
* int32 season, the int32 in-game player id, then a bool the client always sends true.
|
|
406
|
+
*/
|
|
407
|
+
export function writeGetLadderPlayerParams(w, p) {
|
|
408
|
+
w.int32(p.seasonId).int32(p.playerId).bool(true);
|
|
409
|
+
}
|
|
142
410
|
/**
|
|
143
411
|
* BeginFirstTurn(auth, gameId) — the web client's Begin button in a game whose
|
|
144
412
|
* first turn is a speed race (MoveOrder `NoLuckCycle`): war.app withholds the
|
|
@@ -202,6 +470,217 @@ export function writeDeleteInAppNotificationParams(w, id) {
|
|
|
202
470
|
}
|
|
203
471
|
/** The server error DeleteInAppNotification answers for an id it does not hold: already deleted. */
|
|
204
472
|
export const NOTIFICATION_NOT_FOUND = 699;
|
|
473
|
+
// ---------------------------------------------------------------------------
|
|
474
|
+
// Private mail (#629: war.app's "Discussions" of type PrivateDiscussion). Every writer below is READ FROM THE
|
|
475
|
+
// 6.09 CLIENT BUNDLE's request writers (protocol 244), NOT VERIFIED LIVE. Player ids are war.app's in-game ids
|
|
476
|
+
// (a GameFeed id less its two check digits each end), the id space the client's own account id is in.
|
|
477
|
+
/** The most players a mail thread holds (the client's own limit, "at most 21 players"). */
|
|
478
|
+
export const MAIL_MAX_PLAYERS = 21;
|
|
479
|
+
/** The page size the client's thread view asks GetDiscussion for. */
|
|
480
|
+
export const MAIL_PAGE_SIZE = 20;
|
|
481
|
+
function checkIds(ids, what) {
|
|
482
|
+
for (const id of ids)
|
|
483
|
+
if (!Number.isInteger(id) || id <= 0 || id > 0x7fffffff)
|
|
484
|
+
throw new RangeError(`not a ${what}: ${id}`);
|
|
485
|
+
}
|
|
486
|
+
function writeOptionalIntList(w, ids) {
|
|
487
|
+
w.bool(true).list(ids, (ww, id) => ww.int32(id));
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* CreatePrivateDiscussion(auth, …) — the client's "Send mail": the subject (string), a present list (int32 count) of
|
|
491
|
+
* the recipients' int32 ids, the body (string), an optional list of shared-image strings (sent absent), then the
|
|
492
|
+
* 6.09 "allow adding players" bool. Reply: one int32 with no present flag (the new thread's id, as the client reads it).
|
|
493
|
+
*/
|
|
494
|
+
export function writeCreatePrivateDiscussionParams(w, p) {
|
|
495
|
+
if (p.recipients.length === 0)
|
|
496
|
+
throw new RangeError('no recipients');
|
|
497
|
+
checkIds(p.recipients, 'player id');
|
|
498
|
+
w.string(p.subject);
|
|
499
|
+
writeOptionalIntList(w, p.recipients);
|
|
500
|
+
w.string(p.body).bool(false).bool(p.allowAdditions);
|
|
501
|
+
}
|
|
502
|
+
/** A CreatePrivateDiscussion reply's int32 (the new thread's id), or undefined when the reply carries none. */
|
|
503
|
+
export function readCreatePrivateDiscussionReturn(body) {
|
|
504
|
+
return body.remaining >= 4 ? body.int32() : undefined;
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* AddPlayersToPrivateDiscussion(auth, …) — new in 6.09: the int32 thread id, then a present list (int32 count) of the
|
|
508
|
+
* players' int32 ids. No result payload.
|
|
509
|
+
*/
|
|
510
|
+
export function writeAddPlayersToPrivateDiscussionParams(w, discussionId, players) {
|
|
511
|
+
if (players.length === 0)
|
|
512
|
+
throw new RangeError('no players');
|
|
513
|
+
checkIds([discussionId], 'thread id');
|
|
514
|
+
checkIds(players, 'player id');
|
|
515
|
+
w.int32(discussionId);
|
|
516
|
+
writeOptionalIntList(w, players);
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* DeletePrivateDiscussion(auth, …) — the int32 thread id, then one bool: true when a later reply should bring the
|
|
520
|
+
* thread back to the inbox (the client's "Yes, I want to see replies"), false to leave it for good ("No, permanently
|
|
521
|
+
* remove me from this discussion"). No result payload.
|
|
522
|
+
*/
|
|
523
|
+
export function writeDeletePrivateDiscussionParams(w, discussionId, restoreOnReply) {
|
|
524
|
+
checkIds([discussionId], 'thread id');
|
|
525
|
+
w.int32(discussionId).bool(restoreOnReply);
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* SearchPrivateDiscussions(auth, …) — the client's "Search Private Mail" with one player: that player's int32 id.
|
|
529
|
+
* Reply: a present flag, then a list (int32 count) of optional `DiscussionInfo`.
|
|
530
|
+
*/
|
|
531
|
+
export function writeSearchPrivateDiscussionsParams(w, playerId) {
|
|
532
|
+
checkIds([playerId], 'player id');
|
|
533
|
+
w.int32(playerId);
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* CreatePost(auth, …) — a reply to a thread: the int32 thread id, the text (string), an optional list of shared-image
|
|
537
|
+
* strings (sent absent). No result payload: the reply is read back from the thread.
|
|
538
|
+
*/
|
|
539
|
+
export function writeCreatePostParams(w, discussionId, text) {
|
|
540
|
+
checkIds([discussionId], 'thread id');
|
|
541
|
+
w.int32(discussionId).string(text).bool(false);
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* GetDiscussion(auth, …) — the int32 thread id, the int32 first post, the int32 count, one bool (see
|
|
545
|
+
* {@link GetDiscussionParams.headerOnly}). Reply: a present flag, then `DiscussionForClient`.
|
|
546
|
+
*/
|
|
547
|
+
export function writeGetDiscussionParams(w, p) {
|
|
548
|
+
checkIds([p.discussionId], 'thread id');
|
|
549
|
+
if (!Number.isInteger(p.start) || p.start < 0)
|
|
550
|
+
throw new RangeError(`bad first post: ${p.start}`);
|
|
551
|
+
if (!Number.isInteger(p.count) || p.count < 0 || p.count > 100)
|
|
552
|
+
throw new RangeError(`bad post count: ${p.count}`);
|
|
553
|
+
w.int32(p.discussionId).int32(p.start).int32(p.count).bool(p.headerOnly);
|
|
554
|
+
}
|
|
555
|
+
// ---------------------------------------------------------------------------
|
|
556
|
+
// Forums (#640: war.app's public, group and other forum "Discussions"). Every writer below is READ FROM THE 6.09
|
|
557
|
+
// CLIENT BUNDLE's request writers (protocol 244), NOT VERIFIED LIVE. A forum thread is a Discussion like a mail
|
|
558
|
+
// thread: it is read with GetDiscussion and replied to with CreatePost (both above).
|
|
559
|
+
/** The page size the client's thread lists ask for (GetForumThreads, SearchForum, GetGroupForumThreads). */
|
|
560
|
+
export const FORUM_THREAD_PAGE_SIZE = 50;
|
|
561
|
+
/** `DiscussionVote` as ForumVote sends it: the client's up and down buttons, and 0 to take a vote back. */
|
|
562
|
+
export const FORUM_VOTE = { clear: 0, up: 1, down: 2 };
|
|
563
|
+
function checkPage(start, count) {
|
|
564
|
+
if (!Number.isInteger(start) || start < 0)
|
|
565
|
+
throw new RangeError(`bad first thread: ${start}`);
|
|
566
|
+
if (!Number.isInteger(count) || count < 1 || count > 100)
|
|
567
|
+
throw new RangeError(`bad thread count: ${count}`);
|
|
568
|
+
}
|
|
569
|
+
function writeOptionalForum(w, forumId) {
|
|
570
|
+
if (forumId === null)
|
|
571
|
+
w.bool(false);
|
|
572
|
+
else {
|
|
573
|
+
checkIds([forumId], 'forum id');
|
|
574
|
+
w.bool(true).int32(forumId);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* GetForumThreads(auth, …) — an optional int32 forum id (present flag, then the id; absent for every forum), the int32
|
|
579
|
+
* first thread, the int32 count. Reply: a present flag, then `DiscussionInfos` (a list of optional DiscussionInfo and
|
|
580
|
+
* an int32 total).
|
|
581
|
+
*/
|
|
582
|
+
export function writeGetForumThreadsParams(w, p) {
|
|
583
|
+
checkPage(p.start, p.count);
|
|
584
|
+
writeOptionalForum(w, p.forumId);
|
|
585
|
+
w.int32(p.start).int32(p.count);
|
|
586
|
+
}
|
|
587
|
+
/** SearchForum(auth, …) — as GetForumThreads with the search text (string) after the forum id. Reply as GetForumThreads'. */
|
|
588
|
+
export function writeSearchForumParams(w, p) {
|
|
589
|
+
checkPage(p.start, p.count);
|
|
590
|
+
writeOptionalForum(w, p.forumId);
|
|
591
|
+
w.string(p.query).int32(p.start).int32(p.count);
|
|
592
|
+
}
|
|
593
|
+
/** GetGroupForumThreads(auth, …) — the int32 group id, the int32 first thread, the int32 count. Reply as GetForumThreads'. */
|
|
594
|
+
export function writeGetGroupForumThreadsParams(w, p) {
|
|
595
|
+
checkIds([p.groupId], 'group id');
|
|
596
|
+
checkPage(p.start, p.count);
|
|
597
|
+
w.int32(p.groupId).int32(p.start).int32(p.count);
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* CreateForumThread(auth, …) — the int32 forum id, the subject (string), the body (string), an optional list of
|
|
601
|
+
* shared-image strings (sent absent). Reply: one int32, the new thread's id (read as CreatePrivateDiscussion's).
|
|
602
|
+
*/
|
|
603
|
+
export function writeCreateForumThreadParams(w, p) {
|
|
604
|
+
checkIds([p.forumId], 'forum id');
|
|
605
|
+
w.int32(p.forumId).string(p.subject).string(p.body).bool(false);
|
|
606
|
+
}
|
|
607
|
+
/** ForumVote(auth, …) — the int32 thread id, the int32 post id, the vote as an int32 ({@link FORUM_VOTE}). No result payload. */
|
|
608
|
+
export function writeForumVoteParams(w, discussionId, postId, vote) {
|
|
609
|
+
checkIds([discussionId], 'thread id');
|
|
610
|
+
checkIds([postId], 'post id');
|
|
611
|
+
if (vote !== 0 && vote !== 1 && vote !== 2)
|
|
612
|
+
throw new RangeError(`bad vote: ${vote}`);
|
|
613
|
+
w.int32(discussionId).int32(postId).int32(vote);
|
|
614
|
+
}
|
|
615
|
+
/** WatchForumThread(auth, …) — the int32 thread id, then one bool: true to watch it, false to stop. No result payload. */
|
|
616
|
+
export function writeWatchForumThreadParams(w, discussionId, watch) {
|
|
617
|
+
checkIds([discussionId], 'thread id');
|
|
618
|
+
w.int32(discussionId).bool(watch);
|
|
619
|
+
}
|
|
620
|
+
const checkTournamentId = (id) => {
|
|
621
|
+
if (!Number.isInteger(id) || id <= 0 || id > 0x7fffffff)
|
|
622
|
+
throw new RangeError(`bad tournament id: ${id}`);
|
|
623
|
+
};
|
|
624
|
+
/** What the client's Tournaments screen asks for "your tournaments": active, not declined, default sort, all of them. */
|
|
625
|
+
export const MY_TOURNAMENTS_ACTIVE = { filterType: 8, count: 0x7fffffff, sort: 2, start: 0 };
|
|
626
|
+
/**
|
|
627
|
+
* GetMyTournaments(auth, …) — a present MyTournamentsFilter (int32 filter type, int32 count, int32 sort), then the int32
|
|
628
|
+
* start index. Reply: a present flag, then `MyTournamentsReturn`. READ FROM THE CLIENT BUNDLE, NOT VERIFIED LIVE.
|
|
629
|
+
*/
|
|
630
|
+
export function writeGetMyTournamentsParams(w, p) {
|
|
631
|
+
for (const n of [p.filterType, p.count, p.sort, p.start]) {
|
|
632
|
+
if (!Number.isInteger(n) || n < 0 || n > 0x7fffffff)
|
|
633
|
+
throw new RangeError(`bad tournament filter value: ${n}`);
|
|
634
|
+
}
|
|
635
|
+
w.bool(true).int32(p.filterType).int32(p.count).int32(p.sort).int32(p.start);
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* JoinTournament(auth, …) — the int32 tournament id, the int32 team (-1 when the tournament is not a team one), then a
|
|
639
|
+
* bool the client sets when one of the tournament's mods hooks the join (sent false: tournaments with mods are refused).
|
|
640
|
+
* No result payload. READ FROM THE CLIENT BUNDLE, NOT VERIFIED LIVE.
|
|
641
|
+
*/
|
|
642
|
+
export function writeJoinTournamentParams(w, p) {
|
|
643
|
+
checkTournamentId(p.tournamentId);
|
|
644
|
+
if (!Number.isInteger(p.team) || p.team < -1)
|
|
645
|
+
throw new RangeError(`bad tournament team: ${p.team}`);
|
|
646
|
+
w.int32(p.tournamentId).int32(p.team).bool(p.modHook);
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* GetTournamentChat(auth, …) — the int32 tournament id, a present string holding a message id in decimal (the messages
|
|
650
|
+
* after it: the client sends its last-read id or 0), then the int32 most messages to return (the client asks 21 on
|
|
651
|
+
* opening, 2,000,000,000 for all). Reply: a present flag, then a list of optional `GameMessage`. READ FROM THE CLIENT
|
|
652
|
+
* BUNDLE, NOT VERIFIED LIVE.
|
|
653
|
+
*/
|
|
654
|
+
export function writeGetTournamentChatParams(w, p) {
|
|
655
|
+
checkTournamentId(p.tournamentId);
|
|
656
|
+
if (!/^\d{1,20}$/.test(p.after))
|
|
657
|
+
throw new RangeError(`bad tournament chat marker: ${p.after}`);
|
|
658
|
+
if (!Number.isInteger(p.count) || p.count <= 0 || p.count > 2_000_000_000)
|
|
659
|
+
throw new RangeError(`bad tournament chat count: ${p.count}`);
|
|
660
|
+
w.int32(p.tournamentId).string(p.after).int32(p.count);
|
|
661
|
+
}
|
|
662
|
+
/** DeclineTournament(auth, …) — the int32 tournament id. No result payload. READ FROM THE CLIENT BUNDLE, NOT VERIFIED LIVE. */
|
|
663
|
+
export function writeDeclineTournamentParams(w, tournamentId) {
|
|
664
|
+
checkTournamentId(tournamentId);
|
|
665
|
+
w.int32(tournamentId);
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* GetTournamentDetails(auth, …) — the int32 tournament id, then an optional value the client always sends absent (a
|
|
669
|
+
* nullable written as a present flag and text). Reply: a present flag, then `GetTournamentDetailsReturn`. READ FROM THE
|
|
670
|
+
* CLIENT BUNDLE, NOT VERIFIED LIVE.
|
|
671
|
+
*/
|
|
672
|
+
export function writeGetTournamentDetailsParams(w, tournamentId) {
|
|
673
|
+
checkTournamentId(tournamentId);
|
|
674
|
+
w.int32(tournamentId).bool(false);
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* SetFavoriteTournament(auth, …) — the int32 tournament id and a bool (true: show it among my favourites). No result
|
|
678
|
+
* payload. READ FROM THE CLIENT BUNDLE, NOT VERIFIED LIVE.
|
|
679
|
+
*/
|
|
680
|
+
export function writeSetFavoriteTournamentParams(w, p) {
|
|
681
|
+
checkTournamentId(p.tournamentId);
|
|
682
|
+
w.int32(p.tournamentId).bool(p.favorite);
|
|
683
|
+
}
|
|
205
684
|
/**
|
|
206
685
|
* DeclineGame(auth, gameId, modHook) — the lobby's Decline button, which is also how a seated
|
|
207
686
|
* player leaves a game still `WaitingForPlayers` (#217). READ FROM THE CLIENT BUNDLE's writer,
|
|
@@ -370,6 +849,27 @@ export function writeSendChatParams(w, p) {
|
|
|
370
849
|
// Protocol 243 added a last, optional list of strings (the shared images a message carries): absent.
|
|
371
850
|
.bool(false);
|
|
372
851
|
}
|
|
852
|
+
/**
|
|
853
|
+
* `warlight.shared.ReactionTarget`, one byte: what a SetReaction reacts to. The client sends 0 from a game's chat,
|
|
854
|
+
* 1 from a chat room and 2 from a forum post (its three callers); only a game message is sent here.
|
|
855
|
+
*/
|
|
856
|
+
export const ReactionTarget = { GameMessage: 0 };
|
|
857
|
+
/** The SetReaction refusals the client words (its reaction helper): 639 timed out, the rest "can't react". */
|
|
858
|
+
export const REACTION_TIMED_OUT = 639;
|
|
859
|
+
export const REACTION_REFUSED = [773, 774, 17, 333, 5, 421, 430, 425, 443, 424, 428];
|
|
860
|
+
/**
|
|
861
|
+
* SetReaction(auth, …) — a game chat message's react menu (#634). READ FROM THE CLIENT BUNDLE's writer, NOT VERIFIED
|
|
862
|
+
* LIVE: the target (a byte, {@link ReactionTarget}), the message id (a string of decimal text), an int32 the game chat
|
|
863
|
+
* sends as 0 (a forum post sends its thread there), the reaction kind (a byte), then the add flag (false removes).
|
|
864
|
+
* Reply: a present flag, then the message's reactions now (a list of optional `MessageReaction`).
|
|
865
|
+
*/
|
|
866
|
+
export function writeSetReactionParams(w, p) {
|
|
867
|
+
if (!MESSAGE_ID_TEXT.test(p.messageId))
|
|
868
|
+
throw new RangeError(`not a message id: ${JSON.stringify(p.messageId)}`);
|
|
869
|
+
if (!Number.isInteger(p.type) || p.type < 0 || p.type > 4)
|
|
870
|
+
throw new RangeError(`not a reaction kind: ${p.type}`);
|
|
871
|
+
w.u8(ReactionTarget.GameMessage).string(p.messageId).int32(0).u8(p.type).bool(p.add);
|
|
872
|
+
}
|
|
373
873
|
// ---------------------------------------------------------------------------
|
|
374
874
|
// Orders (SendOrders, method 74).
|
|
375
875
|
//
|
|
@@ -688,3 +1188,185 @@ export function writeSendOrdersParams(w, gameId, playerId, orders, turnNumber) {
|
|
|
688
1188
|
}
|
|
689
1189
|
w.int32(turnNumber).bool(false).bool(false);
|
|
690
1190
|
}
|
|
1191
|
+
// ---------------------------------------------------------------------------
|
|
1192
|
+
// Templates and creating games (#635). Every layout here is READ FROM THE CLIENT BUNDLE's writer (protocol 244,
|
|
1193
|
+
// client 6.09), golden-pinned, UNVERIFIED live (docs/WEB-PROTOCOL.md "Templates and creating games").
|
|
1194
|
+
/**
|
|
1195
|
+
* `warlight.shared.GetTemplatesType` as the client sends it: 2, the account's own saved templates (the client's
|
|
1196
|
+
* "My Templates" list and its template picker). The enum's other values are unnamed in the bundle and never sent.
|
|
1197
|
+
*/
|
|
1198
|
+
export const MY_TEMPLATES = 2;
|
|
1199
|
+
/** GetTemplates(auth, type) — the type as one byte (the client always sends {@link MY_TEMPLATES}). */
|
|
1200
|
+
export function writeGetTemplatesParams(w, type = MY_TEMPLATES) {
|
|
1201
|
+
w.u8(type);
|
|
1202
|
+
}
|
|
1203
|
+
/** The most template ids one GetTemplatesByID asks for here. */
|
|
1204
|
+
export const MAX_TEMPLATE_IDS = 50;
|
|
1205
|
+
/** GetTemplatesByID(auth, ids) — a present list (int32 count) of int32 template ids. */
|
|
1206
|
+
export function writeGetTemplatesByIdParams(w, ids) {
|
|
1207
|
+
if (ids.length === 0)
|
|
1208
|
+
throw new RangeError('no template ids');
|
|
1209
|
+
if (ids.length > MAX_TEMPLATE_IDS)
|
|
1210
|
+
throw new RangeError(`at most ${MAX_TEMPLATE_IDS} template ids`);
|
|
1211
|
+
for (const id of ids)
|
|
1212
|
+
if (!Number.isInteger(id) || id <= 0)
|
|
1213
|
+
throw new RangeError(`not a template id: ${id}`);
|
|
1214
|
+
w.bool(true).list(ids, (ww, id) => ww.int32(id));
|
|
1215
|
+
}
|
|
1216
|
+
/**
|
|
1217
|
+
* GetTemplate(templateId, level) — NO auth block: the int32 template id, then a bool the client sets when it asks
|
|
1218
|
+
* for a single-player level rather than a template (sent false). Reply: a present flag, then a GameTemplate.
|
|
1219
|
+
* war.app answers 264 or 540 for a template that does not exist (the client: "It may have been deleted").
|
|
1220
|
+
*/
|
|
1221
|
+
export function writeGetTemplateParams(w, templateId) {
|
|
1222
|
+
if (!Number.isInteger(templateId) || templateId <= 0)
|
|
1223
|
+
throw new RangeError(`not a template id: ${templateId}`);
|
|
1224
|
+
w.int32(templateId).bool(false);
|
|
1225
|
+
}
|
|
1226
|
+
/** The server errors GetTemplate answers for a template that does not exist. */
|
|
1227
|
+
export const TEMPLATE_NOT_FOUND = new Set([264, 540]);
|
|
1228
|
+
/** `warlight.shared.coins.FreeModGameState`, by value (the client's own names). */
|
|
1229
|
+
export const FREE_MOD_GAME_STATE = { 1: 'Available', 2: 'Reserved', 3: 'Used' };
|
|
1230
|
+
/**
|
|
1231
|
+
* GetFreeModGameStatus(auth) takes nothing after the auth block. Its result: the present flag, then an optional
|
|
1232
|
+
* date (a present flag, then the date), an int32 (coins per player), an optional int32 game id, a string (the
|
|
1233
|
+
* game's name) and the int32 state. Absent is `undefined`.
|
|
1234
|
+
*/
|
|
1235
|
+
export function readFreeModGameStatus(body) {
|
|
1236
|
+
if (!body.bool())
|
|
1237
|
+
return undefined;
|
|
1238
|
+
const availableAgain = body.bool() ? body.date() : null;
|
|
1239
|
+
const coinsPerPlayer = body.int32();
|
|
1240
|
+
const gameId = body.bool() ? body.int32() : null;
|
|
1241
|
+
const gameName = body.string();
|
|
1242
|
+
const state = body.int32();
|
|
1243
|
+
return { availableAgain, coinsPerPlayer, gameId, gameName, state };
|
|
1244
|
+
}
|
|
1245
|
+
/**
|
|
1246
|
+
* CreateGameInviteCode(auth, seats) — an optional int32 (a present flag, then the value): the client sends the
|
|
1247
|
+
* template's invite count when it creates a game from a template's "Invite a friend", and nothing from its
|
|
1248
|
+
* create-game screen. Reply: a present flag, then a GameInviteCode.
|
|
1249
|
+
*/
|
|
1250
|
+
export function writeCreateGameInviteCodeParams(w, seats) {
|
|
1251
|
+
if (seats === undefined) {
|
|
1252
|
+
w.bool(false);
|
|
1253
|
+
return;
|
|
1254
|
+
}
|
|
1255
|
+
if (!Number.isInteger(seats) || seats < 1 || seats > 1000)
|
|
1256
|
+
throw new RangeError(`not a seat count: ${seats}`);
|
|
1257
|
+
w.bool(true).int32(seats);
|
|
1258
|
+
}
|
|
1259
|
+
/** A CreateGameInviteCode result: the present flag, then a string, a date, an optional int32 and two int32s. */
|
|
1260
|
+
export function readGameInviteCode(body) {
|
|
1261
|
+
if (!body.bool())
|
|
1262
|
+
return undefined;
|
|
1263
|
+
const code = body.string();
|
|
1264
|
+
const date = body.date();
|
|
1265
|
+
const gameId = body.bool() ? body.int32() : null;
|
|
1266
|
+
return { code, date, gameId, n3: body.int32(), n4: body.int32() };
|
|
1267
|
+
}
|
|
1268
|
+
/** An invite code as this server accepts one back: letters, digits, `-` and `_`, 4–64 characters. */
|
|
1269
|
+
export const INVITE_CODE = /^[A-Za-z0-9_-]{4,64}$/;
|
|
1270
|
+
/** The client's marker for an open seat. */
|
|
1271
|
+
export const OPEN_SEAT_INVITE = 'OpenSeat@warlight.net';
|
|
1272
|
+
/** The client's marker for an AI seat. */
|
|
1273
|
+
export const AI_INVITE = 'AI@warlight.net';
|
|
1274
|
+
const INVITE_TEXT = /^(\d{1,12}|OpenSeat@warlight\.net|AI@warlight\.net)$/;
|
|
1275
|
+
/**
|
|
1276
|
+
* CreateGame(auth, players, teamsOf, settings) — a present list (int32 count) of present `PlayerInvite` records
|
|
1277
|
+
* (the invite as a string, an optional int32 slot, the int32 team), the int32 AtStartDivideIntoTeamsOf, then a
|
|
1278
|
+
* present GameStartSettings record. Reply: a present flag, then CreateGameReturn.
|
|
1279
|
+
*/
|
|
1280
|
+
export function writeCreateGameParams(w, p) {
|
|
1281
|
+
for (const pl of p.players) {
|
|
1282
|
+
if (!INVITE_TEXT.test(pl.invite))
|
|
1283
|
+
throw new RangeError(`not an invite: ${JSON.stringify(pl.invite)}`);
|
|
1284
|
+
if (!Number.isInteger(pl.team) || pl.team < -1)
|
|
1285
|
+
throw new RangeError(`not a team: ${pl.team}`);
|
|
1286
|
+
}
|
|
1287
|
+
if (!Number.isInteger(p.teamsOf) || p.teamsOf < 0)
|
|
1288
|
+
throw new RangeError(`not a team size: ${p.teamsOf}`);
|
|
1289
|
+
if (p.settings[0] !== 2)
|
|
1290
|
+
throw new RangeError('the settings are not a GameStartSettings record');
|
|
1291
|
+
w.bool(true).list(p.players, (ww, pl) => {
|
|
1292
|
+
ww.bool(true).string(pl.invite);
|
|
1293
|
+
if (pl.slot === undefined)
|
|
1294
|
+
ww.bool(false);
|
|
1295
|
+
else
|
|
1296
|
+
ww.bool(true).int32(pl.slot);
|
|
1297
|
+
ww.int32(pl.team);
|
|
1298
|
+
});
|
|
1299
|
+
w.int32(p.teamsOf).bool(true).raw(p.settings);
|
|
1300
|
+
}
|
|
1301
|
+
/** A CreateGame result: the present flag, then an int32 game id and a bool. Absent is `undefined`. */
|
|
1302
|
+
export function readCreateGameReturn(body) {
|
|
1303
|
+
if (!body.bool())
|
|
1304
|
+
return undefined;
|
|
1305
|
+
return { gameId: body.int32(), vacationEnded: body.bool() };
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* A quickmatch template's setting (`warlight.shared.quickmatch.QuickmatchPlayerTemplateSetting`, #638): which
|
|
1309
|
+
* kinds of quickmatch game it is played in. Read from the client bundle; the names are the client's.
|
|
1310
|
+
*/
|
|
1311
|
+
export const QUICKMATCH_TEMPLATE_SETTINGS = {
|
|
1312
|
+
on: 1,
|
|
1313
|
+
off: 2,
|
|
1314
|
+
real_time_only: 3,
|
|
1315
|
+
multi_day_only: 4,
|
|
1316
|
+
};
|
|
1317
|
+
/**
|
|
1318
|
+
* SetQuickmatchSettings(auth, …) — #638. READ FROM THE CLIENT BUNDLE's writer, NOT VERIFIED LIVE: after the auth
|
|
1319
|
+
* block the int32 multi-day game count, the int32 minimum and maximum coin wager, the template dict (present flag,
|
|
1320
|
+
* int32 count, then per template an int32 id and its setting as one byte), the "new templates on by default"
|
|
1321
|
+
* bool, then the real-time speed as one byte. No result payload.
|
|
1322
|
+
*/
|
|
1323
|
+
export function writeSetQuickmatchSettingsParams(w, p) {
|
|
1324
|
+
w.int32(p.multiDayGames).int32(p.minCoins).int32(p.maxCoins);
|
|
1325
|
+
if (p.templates === null)
|
|
1326
|
+
w.bool(false);
|
|
1327
|
+
else {
|
|
1328
|
+
w.bool(true).int32(p.templates.length);
|
|
1329
|
+
for (const [id, setting] of p.templates) {
|
|
1330
|
+
if (![1, 2, 3, 4].includes(setting))
|
|
1331
|
+
throw new RangeError(`A quickmatch template setting is 1..4, not ${setting}.`);
|
|
1332
|
+
w.int32(id).u8(setting);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
w.bool(p.newTemplatesOnByDefault).u8(p.speed);
|
|
1336
|
+
}
|
|
1337
|
+
/**
|
|
1338
|
+
* GetQuickmatchTemplates(auth, flag) — #638. The client's voting screen sends the flag false (its create-game and
|
|
1339
|
+
* tournament template pickers send true); this server sends what the voting screen sends.
|
|
1340
|
+
*/
|
|
1341
|
+
export function writeGetQuickmatchTemplatesParams(w) {
|
|
1342
|
+
w.bool(false);
|
|
1343
|
+
}
|
|
1344
|
+
/** GetQuickmatchTemplateVotes(auth, templateId) — #638: who voted for one template. */
|
|
1345
|
+
export function writeGetQuickmatchTemplateVotesParams(w, templateId) {
|
|
1346
|
+
w.int32(templateId);
|
|
1347
|
+
}
|
|
1348
|
+
/**
|
|
1349
|
+
* SetQuickmatchTemplateVotes(auth, templateId, votes) — #638. READ FROM THE CLIENT BUNDLE's writer, NOT VERIFIED
|
|
1350
|
+
* LIVE: the int32 template id, then the int32 number of my votes on it (the client offers 0..3). No result payload.
|
|
1351
|
+
*/
|
|
1352
|
+
export function writeSetQuickmatchTemplateVotesParams(w, templateId, votes) {
|
|
1353
|
+
if (!Number.isInteger(votes) || votes < 0 || votes > 3)
|
|
1354
|
+
throw new RangeError(`Quickmatch votes are 0..3, not ${votes}.`);
|
|
1355
|
+
w.int32(templateId).int32(votes);
|
|
1356
|
+
}
|
|
1357
|
+
/** GetTemplateLengths(templateIds) — #638, no auth block: the int list (present flag, int32 count, int32 ids). */
|
|
1358
|
+
export function writeGetTemplateLengthsParams(w, templateIds) {
|
|
1359
|
+
w.bool(true).int32(templateIds.length);
|
|
1360
|
+
for (const id of templateIds)
|
|
1361
|
+
w.int32(id);
|
|
1362
|
+
}
|
|
1363
|
+
/** The page size the client asks a quickmatch leaderboard in. */
|
|
1364
|
+
export const QUICKMATCH_LEADERBOARD_PAGE = 50;
|
|
1365
|
+
/**
|
|
1366
|
+
* GetQuickmatchLeaderboards(category, start, count) — #638, no auth block: the category as a nullable string
|
|
1367
|
+
* ("Global", "MD", "RT", "1v1", "Team", "FFA" or "Template <id>"), the int32 start index, then the int32 count
|
|
1368
|
+
* (the client sends 50).
|
|
1369
|
+
*/
|
|
1370
|
+
export function writeGetQuickmatchLeaderboardsParams(w, category, start, count = QUICKMATCH_LEADERBOARD_PAGE) {
|
|
1371
|
+
w.string(category).int32(start).int32(count);
|
|
1372
|
+
}
|