@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
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
// Game templates and creating a game from one (#635): the GetTemplate reply's layout, a byte-exact walk
|
|
2
|
+
// of it, and the GameStartSettings a CreateGame sends, built from the template's own bytes.
|
|
3
|
+
//
|
|
4
|
+
// READ FROM THE CLIENT BUNDLE (protocol 244, client 6.09), UNVERIFIED live (docs/WEB-PROTOCOL.md "Templates
|
|
5
|
+
// and creating games"). A `warlight.shared.GameTemplate` and a `warlight.shared.GameStartSettings` are both
|
|
6
|
+
// a `GameSettingsBase`: a type byte (3 a template, 2 start settings), the subclass's own fields, then the
|
|
7
|
+
// base's 59 settings fields in one shared order (the client sorts them by name; its writer and reader
|
|
8
|
+
// agree field for field). So the settings a template carries are already the bytes a CreateGame sends:
|
|
9
|
+
// this server never re-encodes a setting. It copies the template's settings run as it is, with only the
|
|
10
|
+
// game name (a plain string inside it) replaced, and refuses rather than guess:
|
|
11
|
+
// - the template's own fields and the settings are walked field by field here, every nested record
|
|
12
|
+
// (cards, mods, a custom scenario, open-seat rules, invites, the owner) read by the bundle's own reader
|
|
13
|
+
// by type name, so the walk knows where the name sits and where the settings end;
|
|
14
|
+
// - the walk must agree with the bundle's own GameTemplate reader (same field count, same values), and
|
|
15
|
+
// - the built GameStartSettings is decoded again by the bundle's own reader: it must read to the last
|
|
16
|
+
// byte, every setting equal to the template's, the name the new one.
|
|
17
|
+
// Custom settings (anything but the name) are not offered: each would need its own writer, and a setting
|
|
18
|
+
// written wrong is a game created wrong. A template whose settings need what this server does not send
|
|
19
|
+
// (a custom scenario's start slots, a coin entry fee, a single-player level) is refused.
|
|
20
|
+
import { McpToolError } from '@chrischall/mcp-utils';
|
|
21
|
+
import { cardTypeName } from './cards.js';
|
|
22
|
+
import { normalizeSettings } from './normalize.js';
|
|
23
|
+
import { Reader, Writer } from './protocol/codec.js';
|
|
24
|
+
import { fields, isObj } from './protocol/decoded.js';
|
|
25
|
+
export const GAME_TEMPLATE = 'warlight.shared.GameTemplate';
|
|
26
|
+
export const GAME_START_SETTINGS = 'warlight.shared.GameStartSettings';
|
|
27
|
+
export const GAME_TEMPLATE_INFO = 'warlight.shared.GameTemplateInfo';
|
|
28
|
+
const PLAYER_INVITE = 'warlight.shared.PlayerInvite';
|
|
29
|
+
const PLAYER_INFO = 'warlight.shared.PlayerInfo2';
|
|
30
|
+
const SINGLE_PLAYER_LEVEL = 'warlight.shared.SinglePlayerLevelData';
|
|
31
|
+
const CARD_GAME = 'warlight.shared.CardGame';
|
|
32
|
+
const CUSTOM_SCENARIO = 'warlight.shared.CustomScenario';
|
|
33
|
+
const MOD_GAME = 'warlight.shared.mods.ModGame';
|
|
34
|
+
const OPEN_SEAT_PREREQUISITE = 'warlight.shared.OpenSeatPrerequisite';
|
|
35
|
+
/** The GameSettingsBase type byte of each subclass (the base reader switches on it). */
|
|
36
|
+
export const SETTINGS_TAG = { GameStartSettings: 2, GameTemplate: 3 };
|
|
37
|
+
/** A GameTemplate's own fields after its type byte, in read order (the bundle's reader). */
|
|
38
|
+
export const TEMPLATE_FIELDS = [
|
|
39
|
+
{ name: 'flag0', kind: 'bool' },
|
|
40
|
+
{ name: 'AtStartDivideIntoTeamsOf', kind: 'int32' },
|
|
41
|
+
{ name: 'flag2', kind: 'bool' },
|
|
42
|
+
{ name: 'text3', kind: 'string' },
|
|
43
|
+
{ name: 'date4', kind: 'date' },
|
|
44
|
+
{ name: 'ID', kind: 'int32' },
|
|
45
|
+
{ name: 'InvitedPlayers', kind: { listOf: PLAYER_INVITE } },
|
|
46
|
+
{ name: 'date7', kind: 'date' },
|
|
47
|
+
{ name: 'int8', kind: 'int32' },
|
|
48
|
+
{ name: 'MapVersion', kind: 'int32' },
|
|
49
|
+
{ name: 'date10', kind: 'date' },
|
|
50
|
+
{ name: 'NumberOfFixedTeams', kind: 'int32' },
|
|
51
|
+
{ name: 'SinglePlayerLevelData', kind: { record: SINGLE_PLAYER_LEVEL } },
|
|
52
|
+
{ name: 'TemplateCategory', kind: 'u8' },
|
|
53
|
+
{ name: 'TemplateDescription', kind: 'string' },
|
|
54
|
+
{ name: 'TemplateName', kind: 'string' },
|
|
55
|
+
{ name: 'TemplateOwner', kind: 'optInt32' },
|
|
56
|
+
{ name: 'TemplateOwnerInfo', kind: { record: PLAYER_INFO } },
|
|
57
|
+
];
|
|
58
|
+
/** The 59 GameSettingsBase fields, in the one order both the client's writer and its reader use. */
|
|
59
|
+
export const SETTINGS_FIELDS = [
|
|
60
|
+
{ name: 'AIsSurrenderWhenOneHumanRemains', kind: 'bool' },
|
|
61
|
+
{ name: 'AllowAttackOnly', kind: 'bool' },
|
|
62
|
+
{ name: 'AllowPercentageAttacks', kind: 'bool' },
|
|
63
|
+
{ name: 'AllowTransferOnly', kind: 'bool' },
|
|
64
|
+
{ name: 'AllowVacations', kind: 'bool' },
|
|
65
|
+
{ name: 'ArmyCap', kind: 'optFloat64' },
|
|
66
|
+
{ name: 'AutoBootTime', kind: 'float64' },
|
|
67
|
+
{ name: 'AutomaticTerritoryDistribution', kind: 'bool' },
|
|
68
|
+
{ name: 'BankingBootTimes', kind: 'optInt32' },
|
|
69
|
+
{ name: 'BonusArmyPer', kind: 'int32' },
|
|
70
|
+
{ name: 'BootedPlayersTurnIntoAIs', kind: 'bool' },
|
|
71
|
+
{ name: 'CardHoldingsAndReceivesFogged', kind: 'bool' },
|
|
72
|
+
{ name: 'CardPlayingsFogged', kind: 'bool' },
|
|
73
|
+
{ name: 'Cards', kind: { dictOf: CARD_GAME } },
|
|
74
|
+
{ name: 'CityIncome', kind: 'int32' },
|
|
75
|
+
{ name: 'CoinEntryFee', kind: 'int32' },
|
|
76
|
+
{ name: 'Commanders', kind: 'bool' },
|
|
77
|
+
{ name: 'CommerceArmyCostMultiplier', kind: 'optInt32' },
|
|
78
|
+
{ name: 'CommerceCityBaseCost', kind: 'optInt32' },
|
|
79
|
+
{ name: 'CustomScenario', kind: { record: CUSTOM_SCENARIO } },
|
|
80
|
+
{ name: 'DefenseKillRate', kind: 'float64' },
|
|
81
|
+
{ name: 'DirectBootTime', kind: 'float64' },
|
|
82
|
+
{ name: 'DistributionModeID', kind: 'int32' },
|
|
83
|
+
{ name: 'ExtraCoins', kind: 'int32' },
|
|
84
|
+
{ name: 'FogLevel', kind: 'u8' },
|
|
85
|
+
{ name: 'GlobalCityCostIncrease', kind: 'int32' },
|
|
86
|
+
{ name: 'InitialBank', kind: 'float64' },
|
|
87
|
+
{ name: 'InitialNeutralsInDistribution', kind: 'int32' },
|
|
88
|
+
{ name: 'InitialNonDistributionArmies', kind: 'int32' },
|
|
89
|
+
{ name: 'InitialPlayerArmiesPerTerritory', kind: 'int32' },
|
|
90
|
+
{ name: 'InstantSurrender', kind: 'bool' },
|
|
91
|
+
{ name: 'LimitDistributionTerritories', kind: 'int32' },
|
|
92
|
+
{ name: 'LocalDeployments', kind: 'bool' },
|
|
93
|
+
{ name: 'LuckModifier', kind: 'float64' },
|
|
94
|
+
{ name: 'MapID', kind: 'int32' },
|
|
95
|
+
{ name: 'MaxCardsHold', kind: 'int32' },
|
|
96
|
+
{ name: 'MinimumArmyBonus', kind: 'int32' },
|
|
97
|
+
{ name: 'Mods', kind: { dictOf: MOD_GAME } },
|
|
98
|
+
{ name: 'MoveOrder', kind: 'u8' },
|
|
99
|
+
{ name: 'MultiAttack', kind: 'bool' },
|
|
100
|
+
{ name: 'Name', kind: 'string' },
|
|
101
|
+
{ name: 'NonMembersCanUseMods', kind: 'optInt32' },
|
|
102
|
+
{ name: 'NoSplit', kind: 'bool' },
|
|
103
|
+
{ name: 'NumberOfCardsToReceiveEachTurn', kind: 'int32' },
|
|
104
|
+
{ name: 'NumberOfWastelands', kind: 'int32' },
|
|
105
|
+
{ name: 'OffenseKillRate', kind: 'float64' },
|
|
106
|
+
{ name: 'OneArmyStandsGuard', kind: 'bool' },
|
|
107
|
+
{ name: 'OpenSeatPrerequisites', kind: { listOf: OPEN_SEAT_PREREQUISITE } },
|
|
108
|
+
{ name: 'OverriddenBonuses', kind: 'dictIntInt' },
|
|
109
|
+
{ name: 'PersonalMessage', kind: 'string' },
|
|
110
|
+
{ name: 'PrivateMessaging', kind: 'bool' },
|
|
111
|
+
{ name: 'RandomSlots', kind: 'bool' },
|
|
112
|
+
{ name: 'RankedGame', kind: 'bool' },
|
|
113
|
+
{ name: 'RealTimeGame', kind: 'bool' },
|
|
114
|
+
{ name: 'RoundingMode', kind: 'u8' },
|
|
115
|
+
{ name: 'SurrenderedPlayersTurnIntoAIs', kind: 'bool' },
|
|
116
|
+
{ name: 'TerritoryCityCostIncrease', kind: 'int32' },
|
|
117
|
+
{ name: 'TimesCanComeBackFromAI', kind: 'int32' },
|
|
118
|
+
{ name: 'WastelandSize', kind: 'int32' },
|
|
119
|
+
];
|
|
120
|
+
const NAME_FIELD = SETTINGS_FIELDS.findIndex((f) => f.name === 'Name');
|
|
121
|
+
/** The template is not one this server can create a game from, or its reply did not read as one. */
|
|
122
|
+
export class TemplateFormatError extends McpToolError {
|
|
123
|
+
constructor(detail) {
|
|
124
|
+
super(`war.app's template arrived in an unexpected shape (${detail}), so nothing was sent.`, {
|
|
125
|
+
kind: 'unknown',
|
|
126
|
+
hint: 'The war.app client may have changed; the template can still be used to create a game in war.app.',
|
|
127
|
+
});
|
|
128
|
+
this.name = 'TemplateFormatError';
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function readField(r, kind, bundle, budget) {
|
|
132
|
+
const record = (type) => (r.bool() ? bundle.readClass(type, r, budget) : null);
|
|
133
|
+
switch (kind) {
|
|
134
|
+
case 'bool':
|
|
135
|
+
return r.bool();
|
|
136
|
+
case 'int32':
|
|
137
|
+
return r.int32();
|
|
138
|
+
case 'string':
|
|
139
|
+
return r.string();
|
|
140
|
+
case 'date':
|
|
141
|
+
return r.date();
|
|
142
|
+
case 'u8':
|
|
143
|
+
return r.u8();
|
|
144
|
+
case 'float64':
|
|
145
|
+
return r.float64();
|
|
146
|
+
case 'optInt32':
|
|
147
|
+
return r.bool() ? r.int32() : null;
|
|
148
|
+
case 'optFloat64':
|
|
149
|
+
return r.bool() ? r.float64() : null;
|
|
150
|
+
case 'dictIntInt':
|
|
151
|
+
return r.bool() ? r.list((rr) => [rr.int32(), rr.int32()]) : null;
|
|
152
|
+
default:
|
|
153
|
+
if ('dictOf' in kind)
|
|
154
|
+
return r.bool() ? r.list((rr) => [rr.int32(), record(kind.dictOf)]) : null;
|
|
155
|
+
if ('listOf' in kind)
|
|
156
|
+
return r.bool() ? r.list(() => record(kind.listOf)) : null;
|
|
157
|
+
return record(kind.record);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Walk a GetTemplate reply (`body` positioned at its result-present flag): `null` when it carries no template.
|
|
162
|
+
* Every nested record is read by the bundle's own reader; the walk is then checked against the bundle's own
|
|
163
|
+
* GameTemplate reader (the same fields, the same values) and must end on the reply's last byte.
|
|
164
|
+
*/
|
|
165
|
+
export function walkTemplate(bundle, body, budget = { spent: 0 }) {
|
|
166
|
+
if (!body.bool())
|
|
167
|
+
return null;
|
|
168
|
+
const bytes = body.raw(body.remaining);
|
|
169
|
+
const r = new Reader(bytes);
|
|
170
|
+
const tag = r.u8();
|
|
171
|
+
if (tag !== SETTINGS_TAG.GameTemplate)
|
|
172
|
+
throw new TemplateFormatError(`settings type ${tag}, not a template (${SETTINGS_TAG.GameTemplate})`);
|
|
173
|
+
const template = {};
|
|
174
|
+
const settings = {};
|
|
175
|
+
try {
|
|
176
|
+
for (const f of TEMPLATE_FIELDS)
|
|
177
|
+
template[f.name] = readField(r, f.kind, bundle, budget);
|
|
178
|
+
const settingsStart = r.position;
|
|
179
|
+
let name = { offset: 0, length: 0 };
|
|
180
|
+
SETTINGS_FIELDS.forEach((f, i) => {
|
|
181
|
+
const at = r.position;
|
|
182
|
+
settings[f.name] = readField(r, f.kind, bundle, budget);
|
|
183
|
+
if (i === NAME_FIELD)
|
|
184
|
+
name = { offset: at - settingsStart, length: r.position - at };
|
|
185
|
+
});
|
|
186
|
+
if (r.remaining !== 0)
|
|
187
|
+
throw new TemplateFormatError(`${r.remaining} byte(s) left after the settings`);
|
|
188
|
+
const settingsBytes = bytes.slice(settingsStart, r.position);
|
|
189
|
+
// The bundle's own reader, over the same bytes, must see exactly what the walk saw.
|
|
190
|
+
const own = bundle.readClass(GAME_TEMPLATE, new Reader(bytes), budget);
|
|
191
|
+
if (!isObj(own))
|
|
192
|
+
throw new TemplateFormatError('the bundle did not read a template record');
|
|
193
|
+
const ownFields = fields(own);
|
|
194
|
+
const walked = [...Object.values(template), ...Object.values(settings)];
|
|
195
|
+
if (ownFields.length !== walked.length) {
|
|
196
|
+
throw new TemplateFormatError(`the bundle reads ${ownFields.length} template fields, this server ${walked.length}`);
|
|
197
|
+
}
|
|
198
|
+
ownFields.forEach((v, i) => {
|
|
199
|
+
if (!sameValue(v, walked[i]))
|
|
200
|
+
throw new TemplateFormatError(`template field ${i} reads differently from the bundle's reader`);
|
|
201
|
+
});
|
|
202
|
+
return { template, settings, settingsBytes, name };
|
|
203
|
+
}
|
|
204
|
+
catch (e) {
|
|
205
|
+
if (e instanceof TemplateFormatError)
|
|
206
|
+
throw e;
|
|
207
|
+
throw new TemplateFormatError(e instanceof Error ? e.message : String(e));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/** Two decoded values are the same (records by their fields, dates by time, NaN as NaN). */
|
|
211
|
+
export function sameValue(a, b) {
|
|
212
|
+
if (a === b)
|
|
213
|
+
return true;
|
|
214
|
+
if (typeof a === 'number' && typeof b === 'number')
|
|
215
|
+
return Number.isNaN(a) && Number.isNaN(b);
|
|
216
|
+
if (a instanceof Date && b instanceof Date)
|
|
217
|
+
return a.getTime() === b.getTime();
|
|
218
|
+
if (a instanceof Uint8Array && b instanceof Uint8Array)
|
|
219
|
+
return a.length === b.length && a.every((x, i) => x === b[i]);
|
|
220
|
+
if (a instanceof Map && b instanceof Map)
|
|
221
|
+
return sameValue([...a], [...b]);
|
|
222
|
+
if (Array.isArray(a) && Array.isArray(b))
|
|
223
|
+
return a.length === b.length && a.every((x, i) => sameValue(x, b[i]));
|
|
224
|
+
if (isObj(a) && isObj(b)) {
|
|
225
|
+
const ka = Object.keys(a);
|
|
226
|
+
const kb = Object.keys(b);
|
|
227
|
+
return ka.length === kb.length && ka.every((k) => Object.hasOwn(b, k) && sameValue(a[k], b[k]));
|
|
228
|
+
}
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
/** The longest game name war.app's client writes (it cuts a rematch's name to 50 characters). */
|
|
232
|
+
export const MAX_GAME_NAME = 50;
|
|
233
|
+
/** A game name war.app can take: 1–50 characters after trimming, no control characters. */
|
|
234
|
+
export function checkGameName(name) {
|
|
235
|
+
const trimmed = name.trim();
|
|
236
|
+
if (trimmed.length === 0)
|
|
237
|
+
throw new RangeError('The game name is empty.');
|
|
238
|
+
if ([...trimmed].length > MAX_GAME_NAME)
|
|
239
|
+
throw new RangeError(`The game name is longer than ${MAX_GAME_NAME} characters.`);
|
|
240
|
+
if (/[\p{Cc}\p{Cf}]/u.test(trimmed))
|
|
241
|
+
throw new RangeError('The game name holds a control character.');
|
|
242
|
+
return trimmed;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* The GameStartSettings record a CreateGame sends, with no present flag (the caller writes it): the type byte
|
|
246
|
+
* (2), the invite code (a string, null for none), the creator's player info (absent, as the client sends it),
|
|
247
|
+
* the template id (present), the template name (null, as the client sends it), then the template's settings run
|
|
248
|
+
* with only its Name replaced.
|
|
249
|
+
*/
|
|
250
|
+
export function buildStartSettings(walked, input) {
|
|
251
|
+
const name = checkGameName(input.name);
|
|
252
|
+
const head = new Writer()
|
|
253
|
+
.u8(SETTINGS_TAG.GameStartSettings)
|
|
254
|
+
.string(input.inviteCode ?? null)
|
|
255
|
+
.bool(false)
|
|
256
|
+
.bool(true)
|
|
257
|
+
.int32(input.templateId)
|
|
258
|
+
.string(null)
|
|
259
|
+
.bytes();
|
|
260
|
+
const nameBytes = new Writer().string(name).bytes();
|
|
261
|
+
const s = walked.settingsBytes;
|
|
262
|
+
const { offset, length } = walked.name;
|
|
263
|
+
const out = new Uint8Array(head.length + s.length - length + nameBytes.length);
|
|
264
|
+
out.set(head, 0);
|
|
265
|
+
out.set(s.subarray(0, offset), head.length);
|
|
266
|
+
out.set(nameBytes, head.length + offset);
|
|
267
|
+
out.set(s.subarray(offset + length), head.length + offset + nameBytes.length);
|
|
268
|
+
return out;
|
|
269
|
+
}
|
|
270
|
+
/** The GameStartSettings' own fields before the settings (the invite code, the player info, the template id and name). */
|
|
271
|
+
const START_SETTINGS_OWN_FIELDS = 4;
|
|
272
|
+
/**
|
|
273
|
+
* Decode built start settings with the bundle's own reader: it must read to the last byte, carry every setting
|
|
274
|
+
* the template carries (the same values), the name the new one, and the template id and invite code given.
|
|
275
|
+
* Throws {@link TemplateFormatError} otherwise: nothing is then sent.
|
|
276
|
+
*/
|
|
277
|
+
export function verifyStartSettings(bundle, built, walked, input, budget = { spent: 0 }) {
|
|
278
|
+
const r = new Reader(built);
|
|
279
|
+
let own;
|
|
280
|
+
try {
|
|
281
|
+
own = bundle.readClass(GAME_START_SETTINGS, r, budget);
|
|
282
|
+
}
|
|
283
|
+
catch (e) {
|
|
284
|
+
throw new TemplateFormatError(`the start settings do not read back (${e instanceof Error ? e.message : String(e)})`);
|
|
285
|
+
}
|
|
286
|
+
if (r.remaining !== 0)
|
|
287
|
+
throw new TemplateFormatError(`${r.remaining} byte(s) of the start settings were not read back`);
|
|
288
|
+
if (!isObj(own))
|
|
289
|
+
throw new TemplateFormatError('the start settings did not read back as a record');
|
|
290
|
+
const got = fields(own);
|
|
291
|
+
const want = [input.inviteCode ?? null, null, input.templateId, null, ...Object.values(walked.settings)];
|
|
292
|
+
want[START_SETTINGS_OWN_FIELDS + NAME_FIELD] = checkGameName(input.name);
|
|
293
|
+
if (got.length !== want.length)
|
|
294
|
+
throw new TemplateFormatError(`the start settings read back ${got.length} fields, not ${want.length}`);
|
|
295
|
+
got.forEach((v, i) => {
|
|
296
|
+
if (!sameValue(v, want[i]))
|
|
297
|
+
throw new TemplateFormatError(`start settings field ${i} reads back differently`);
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
// ---------------------------------------------------------------------------
|
|
301
|
+
// What a template shows.
|
|
302
|
+
const FOG = ['', 'NoFog', 'LightFog', 'ModerateFog', 'Foggy', 'VeryFoggy', 'ExtremeFog'];
|
|
303
|
+
const MOVE_ORDER = ['Random', 'Cycle', 'NoLuckCycle'];
|
|
304
|
+
const ROUNDING = ['WeightedRandom', 'StraightRound'];
|
|
305
|
+
const CATEGORY = ['', 'BuiltInMP', 'BuiltInSPE', 'PlayerOwnedMP', 'PlayerOwnedSPE', 'SinglePlayerLevel'];
|
|
306
|
+
/** A `warlight.shared.GameFogLevel` name (1 NoFog … 6 ExtremeFog), or the number when unknown. */
|
|
307
|
+
export const fogName = (n) => (typeof n === 'number' && FOG[n] ? FOG[n] : String(n));
|
|
308
|
+
/** A `warlight.shared.TemplateCategoryType` name, or the number when unknown. */
|
|
309
|
+
export const categoryName = (n) => (typeof n === 'number' && CATEGORY[n] ? CATEGORY[n] : String(n));
|
|
310
|
+
const nameOf = (names, n) => (typeof n === 'number' && names[n] ? names[n] : String(n));
|
|
311
|
+
const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : undefined);
|
|
312
|
+
const len = (v) => (Array.isArray(v) ? v.length : 0);
|
|
313
|
+
const minutes = (ms) => {
|
|
314
|
+
const n = num(ms);
|
|
315
|
+
return n === undefined ? undefined : Math.round(n / 60_000);
|
|
316
|
+
};
|
|
317
|
+
/** The card types a template's Cards dict turns on (keys are the card type ids). */
|
|
318
|
+
function cardsOf(cards) {
|
|
319
|
+
if (!Array.isArray(cards))
|
|
320
|
+
return [];
|
|
321
|
+
return cards
|
|
322
|
+
.map((e) => (Array.isArray(e) ? num(e[0]) : undefined))
|
|
323
|
+
.filter((t) => t !== undefined)
|
|
324
|
+
.sort((a, b) => a - b)
|
|
325
|
+
.map(cardTypeName);
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* The template's settings in GameFeed's spelling, so the settings normalizer (`normalizeSettings`) reads them
|
|
329
|
+
* as it reads a game's: kill rates as percents, fog, move order and rounding by name, the cards as `<Name>Card`
|
|
330
|
+
* keys (their own settings are not read), overrides in GameFeed's `{ bonusID, value }` shape, the mods by id.
|
|
331
|
+
*/
|
|
332
|
+
export function feedShapedSettings(s) {
|
|
333
|
+
const pct = (v) => (num(v) === undefined ? undefined : Math.round(num(v) * 1000) / 10);
|
|
334
|
+
const out = {
|
|
335
|
+
Map: s.MapID,
|
|
336
|
+
MinimumArmyBonus: s.MinimumArmyBonus,
|
|
337
|
+
BonusArmyPer: s.BonusArmyPer,
|
|
338
|
+
DistributionMode: s.DistributionModeID,
|
|
339
|
+
TerritoryLimit: s.LimitDistributionTerritories,
|
|
340
|
+
InitialPlayerArmiesPerTerritory: s.InitialPlayerArmiesPerTerritory,
|
|
341
|
+
InitialNonDistributionArmies: s.InitialNonDistributionArmies,
|
|
342
|
+
InitialNeutralsInDistribution: s.InitialNeutralsInDistribution,
|
|
343
|
+
OneArmyStandsGuard: s.OneArmyStandsGuard,
|
|
344
|
+
MultiAttack: s.MultiAttack,
|
|
345
|
+
LocalDeployments: s.LocalDeployments,
|
|
346
|
+
NoSplit: s.NoSplit,
|
|
347
|
+
Commanders: s.Commanders,
|
|
348
|
+
AllowTransferOnly: s.AllowTransferOnly,
|
|
349
|
+
AllowAttackOnly: s.AllowAttackOnly,
|
|
350
|
+
AllowPercentageAttacks: s.AllowPercentageAttacks,
|
|
351
|
+
PrivateMessaging: s.PrivateMessaging,
|
|
352
|
+
Pace: s.RealTimeGame === true ? 'RealTime' : 'MultiDay',
|
|
353
|
+
Fog: fogName(s.FogLevel),
|
|
354
|
+
MoveOrder: nameOf(MOVE_ORDER, s.MoveOrder),
|
|
355
|
+
RoundingMode: nameOf(ROUNDING, s.RoundingMode),
|
|
356
|
+
OffensiveKillRate: pct(s.OffenseKillRate),
|
|
357
|
+
DefensiveKillRate: pct(s.DefenseKillRate),
|
|
358
|
+
LuckModifier: s.LuckModifier,
|
|
359
|
+
ArmyCap: s.ArmyCap,
|
|
360
|
+
Wastelands: { NumberOfWastelands: s.NumberOfWastelands, WastelandSize: s.WastelandSize },
|
|
361
|
+
Mods: Array.isArray(s.Mods) ? s.Mods.map((e) => ({ ModID: Array.isArray(e) ? e[0] : undefined })) : [],
|
|
362
|
+
OverriddenBonuses: Array.isArray(s.OverriddenBonuses)
|
|
363
|
+
? s.OverriddenBonuses.map((e) => (Array.isArray(e) ? { bonusID: e[0], value: e[1] } : e))
|
|
364
|
+
: [],
|
|
365
|
+
Commerce: s.CommerceArmyCostMultiplier === null || s.CommerceArmyCostMultiplier === undefined
|
|
366
|
+
? {}
|
|
367
|
+
: {
|
|
368
|
+
ArmyCostMultiplier: s.CommerceArmyCostMultiplier,
|
|
369
|
+
...(num(s.CommerceCityBaseCost) !== undefined ? { CityBaseCost: s.CommerceCityBaseCost } : {}),
|
|
370
|
+
TerritoryCityCostIncrease: s.TerritoryCityCostIncrease,
|
|
371
|
+
GlobalCityCostIncrease: s.GlobalCityCostIncrease,
|
|
372
|
+
CityIncome: s.CityIncome,
|
|
373
|
+
},
|
|
374
|
+
};
|
|
375
|
+
for (const card of cardsOf(s.Cards))
|
|
376
|
+
out[`${card.replace(/\s+/g, '')}Card`] = {};
|
|
377
|
+
return out;
|
|
378
|
+
}
|
|
379
|
+
/** Why this server will not create a game from a template (empty: it can). */
|
|
380
|
+
export function createRefusals(w) {
|
|
381
|
+
const out = [];
|
|
382
|
+
const s = w.settings;
|
|
383
|
+
const t = w.template;
|
|
384
|
+
if (t.SinglePlayerLevelData !== null || [2, 4, 5].includes(num(t.TemplateCategory) ?? -1))
|
|
385
|
+
out.push('a single-player template or level');
|
|
386
|
+
if (s.CustomScenario !== null)
|
|
387
|
+
out.push('a custom scenario (its start slots are not sent by this server)');
|
|
388
|
+
if ((num(s.CoinEntryFee) ?? 0) > 0 || (num(s.ExtraCoins) ?? 0) > 0)
|
|
389
|
+
out.push('a coin entry fee or prize');
|
|
390
|
+
return out;
|
|
391
|
+
}
|
|
392
|
+
export function templateView(w) {
|
|
393
|
+
const s = w.settings;
|
|
394
|
+
const t = w.template;
|
|
395
|
+
const { raw: _raw, overriddenBonuses, ...settings } = normalizeSettings(feedShapedSettings(s));
|
|
396
|
+
return {
|
|
397
|
+
id: num(t.ID),
|
|
398
|
+
templateName: typeof t.TemplateName === 'string' ? t.TemplateName : null,
|
|
399
|
+
description: typeof t.TemplateDescription === 'string' ? t.TemplateDescription : null,
|
|
400
|
+
gameName: typeof s.Name === 'string' ? s.Name : null,
|
|
401
|
+
category: categoryName(t.TemplateCategory),
|
|
402
|
+
mapId: num(s.MapID),
|
|
403
|
+
invitedSeats: len(t.InvitedPlayers),
|
|
404
|
+
teamsOf: num(t.AtStartDivideIntoTeamsOf),
|
|
405
|
+
fixedTeams: num(t.NumberOfFixedTeams),
|
|
406
|
+
settings: { ...settings, overriddenBonuses: overriddenBonuses?.size ?? 0 },
|
|
407
|
+
boot: { directMinutes: minutes(s.DirectBootTime), autoMinutes: minutes(s.AutoBootTime), bankMinutes: minutes(s.InitialBank) },
|
|
408
|
+
realTime: s.RealTimeGame === true,
|
|
409
|
+
ranked: s.RankedGame === true,
|
|
410
|
+
coinEntryFee: num(s.CoinEntryFee),
|
|
411
|
+
customScenario: s.CustomScenario !== null,
|
|
412
|
+
openSeatRules: len(s.OpenSeatPrerequisites),
|
|
413
|
+
cannotCreate: createRefusals(w),
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
/** GameTemplateInfo positions in read order (the template lists' records), and its field count. */
|
|
417
|
+
const TI = { category: 0, description: 1, fog: 2, id: 4, mapId: 6, name: 8 };
|
|
418
|
+
export const GAME_TEMPLATE_INFO_FIELDS = 14;
|
|
419
|
+
/**
|
|
420
|
+
* Read a GetTemplates or GetTemplatesByID result (`body` at its result-present flag): a present list of optional
|
|
421
|
+
* `GameTemplateInfo`, each read by the bundle's reader, fields by read order. Absent is an empty list.
|
|
422
|
+
*/
|
|
423
|
+
export function readTemplateInfos(bundle, body) {
|
|
424
|
+
if (!body.bool())
|
|
425
|
+
return [];
|
|
426
|
+
const budget = { spent: 0 };
|
|
427
|
+
const items = body.list((r) => (r.bool() ? bundle.readClass(GAME_TEMPLATE_INFO, r, budget) : null)) ?? [];
|
|
428
|
+
const out = [];
|
|
429
|
+
for (const item of items) {
|
|
430
|
+
if (item === null)
|
|
431
|
+
continue;
|
|
432
|
+
if (!isObj(item) || item.$type !== GAME_TEMPLATE_INFO)
|
|
433
|
+
throw new TemplateFormatError('a listed template is not a GameTemplateInfo');
|
|
434
|
+
const f = fields(item);
|
|
435
|
+
if (f.length !== GAME_TEMPLATE_INFO_FIELDS)
|
|
436
|
+
throw new TemplateFormatError(`a GameTemplateInfo has ${f.length} fields, not ${GAME_TEMPLATE_INFO_FIELDS}`);
|
|
437
|
+
const id = num(f[TI.id]);
|
|
438
|
+
if (id === undefined)
|
|
439
|
+
throw new TemplateFormatError('a listed template has no id');
|
|
440
|
+
const str = (v) => (typeof v === 'string' ? v : null);
|
|
441
|
+
out.push({
|
|
442
|
+
id,
|
|
443
|
+
name: str(f[TI.name]),
|
|
444
|
+
description: str(f[TI.description]),
|
|
445
|
+
mapId: num(f[TI.mapId]) ?? null,
|
|
446
|
+
category: categoryName(f[TI.category]),
|
|
447
|
+
fog: fogName(f[TI.fog]),
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
return out;
|
|
451
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// warapp_boot_player (#632): boot a player who has run past the game's direct-boot time with the web
|
|
2
|
+
// client's BootPlayer (72), gated on the user's confirmation. The encoder is read from the client bundle
|
|
3
|
+
// and golden-pinned, UNVERIFIED live (docs/WEB-PROTOCOL.md "Booting a player").
|
|
4
|
+
//
|
|
5
|
+
// The plan refuses until the boot time has passed: GameFeed's `DirectBoot` minutes against how long the
|
|
6
|
+
// turn has run (`lastTurnTime`, read as the turn's start — UNVERIFIED — as `leavers` reads it). The client
|
|
7
|
+
// adds the player's banked boot time, and a vacation can hold it off; GameFeed carries neither per player,
|
|
8
|
+
// so war.app may still refuse (error 38), which changes nothing. A player who has committed, an AI, a
|
|
9
|
+
// player out of the game and my own seat are refused too. The outcome is read back from GameFeed.
|
|
10
|
+
import { CONFIRM_INJECTION_RULE, toolAnnotations } from '@chrischall/mcp-utils';
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
import { inGameOf } from '../live.js';
|
|
13
|
+
import { leavers, parseFeedTime } from '../normalize.js';
|
|
14
|
+
import { Method, writeBootPlayerParams } from '../protocol/methods.js';
|
|
15
|
+
import { gameIdArg, shownAccount, UNTRUSTED_PREVIEW_NOTE, untrustedText } from './common.js';
|
|
16
|
+
import { gameInPlay } from './end-game-common.js';
|
|
17
|
+
import { mintMeta } from './hints.js';
|
|
18
|
+
import { requireApprovedAccount, writeAccount } from './live-context.js';
|
|
19
|
+
import { resolvePlayer } from './resolve.js';
|
|
20
|
+
import { noBrowserNote } from './session.js';
|
|
21
|
+
import { defineGatedWrite, refuse, sendAndVerify, worded } from './write-kit.js';
|
|
22
|
+
/** A boot time this long or longer is the game having none (GameFeed may send the TimeSpan maximum). */
|
|
23
|
+
export const NO_BOOT_MINUTES = 10 * 365 * 24 * 60;
|
|
24
|
+
/** The client's message for 445: the player was booted and turned into an AI — a boot, read back as one. */
|
|
25
|
+
const BOOTED_INTO_AI = 445;
|
|
26
|
+
/** The BootPlayer refusals, worded from the client's own messages (read from the bundle, UNVERIFIED live). */
|
|
27
|
+
const BOOT_ERRORS = {
|
|
28
|
+
4: 'Cannot boot because the game is over.',
|
|
29
|
+
7: 'Cannot boot because either you or that player are no longer active in the game.',
|
|
30
|
+
230: 'Cannot boot because you are no longer active in the game.',
|
|
31
|
+
38: 'This player cannot be booted yet (its banked time or a vacation may still hold it, or the turn just advanced).',
|
|
32
|
+
39: 'This player just took their turn, so they cannot be booted.',
|
|
33
|
+
};
|
|
34
|
+
/** Why the boot is not open yet, or `undefined` when the direct-boot time has passed (as GameFeed reads it). */
|
|
35
|
+
export function directBootBlock(directBootMinutes, leftMinutes) {
|
|
36
|
+
if (directBootMinutes === undefined)
|
|
37
|
+
return 'the game\'s DirectBoot setting could not be read';
|
|
38
|
+
if (!(directBootMinutes > 0) || directBootMinutes >= NO_BOOT_MINUTES)
|
|
39
|
+
return 'direct booting is off in this game';
|
|
40
|
+
if (leftMinutes === undefined)
|
|
41
|
+
return 'how long this turn has run could not be read (no lastTurnTime)';
|
|
42
|
+
if (leftMinutes > 0)
|
|
43
|
+
return `the direct-boot time has not passed: ${leftMinutes} minute(s) to go`;
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
export function registerBootPlayerTool(server, ctx) {
|
|
47
|
+
defineGatedWrite(server, {
|
|
48
|
+
title: 'Boot a stalled player from a war.app game',
|
|
49
|
+
_meta: mintMeta('change', ['boot player', 'kick stalled player warzone', 'boot slow player']),
|
|
50
|
+
}, {
|
|
51
|
+
name: 'warapp_boot_player',
|
|
52
|
+
description: 'Boot a player who has run past the game\'s direct-boot time in a war.app (Warzone) game, as the signed-in account ' +
|
|
53
|
+
"(the client's Boot button): they are kicked out of the game at once and their seat becomes an AI or neutral land " +
|
|
54
|
+
'(the game\'s BootedPlayersTurnIntoAIs). Refused until the boot time has passed — GameFeed\'s DirectBoot minutes against ' +
|
|
55
|
+
'how long the turn has run (lastTurnTime, read as the turn\'s start, unverified) — and for a player who has committed, ' +
|
|
56
|
+
'an AI, a player out of the game, yourself, finished games and games you are not playing. Banked boot time and ' +
|
|
57
|
+
'vacations can still hold a boot off, and GameFeed does not carry them, so war.app may refuse (nothing changes). ' +
|
|
58
|
+
'warapp_get_game says when a player can be booted (`leavers`, `canBootNow`). The outcome is read back from GameFeed ' +
|
|
59
|
+
'(`booted`; `unconfirmed`, `unknown`). The encoding is read from the client bundle, UNVERIFIED live.' +
|
|
60
|
+
`${noBrowserNote(ctx.hosted)} ${CONFIRM_INJECTION_RULE}`,
|
|
61
|
+
annotations: toolAnnotations({
|
|
62
|
+
title: 'Boot a stalled player from a war.app game',
|
|
63
|
+
readOnly: false,
|
|
64
|
+
destructive: true,
|
|
65
|
+
idempotent: false,
|
|
66
|
+
openWorld: true,
|
|
67
|
+
}),
|
|
68
|
+
inputSchema: z.object({
|
|
69
|
+
game_id: gameIdArg,
|
|
70
|
+
player: z.union([z.number(), z.string()]).describe('The player to boot, by name or GameFeed id.'),
|
|
71
|
+
}),
|
|
72
|
+
async plan({ game_id, player }) {
|
|
73
|
+
const { gameId, me, game, seat } = await gameInPlay(ctx, game_id, 'a boot', { picking: false });
|
|
74
|
+
const target = resolvePlayer(game.players, player);
|
|
75
|
+
const who = `player ${target.id}`;
|
|
76
|
+
if (target.id === me)
|
|
77
|
+
refuse('You cannot boot yourself; nothing was sent.', 'Name another player.');
|
|
78
|
+
if ((target.state ?? 'Playing') !== 'Playing')
|
|
79
|
+
refuse(`${who} is no longer playing in game ${gameId} (state: ${target.state}); nothing was sent.`, 'Check warapp_get_game.');
|
|
80
|
+
if (target.isAI || target.humanTurnedIntoAI)
|
|
81
|
+
refuse(`${who} is played by an AI in game ${gameId}, so there is no one to boot; nothing was sent.`, 'Check warapp_get_game.');
|
|
82
|
+
if (target.hasCommittedOrders)
|
|
83
|
+
refuse(`${who} has committed this turn in game ${gameId}, so it cannot be booted; nothing was sent.`, 'Check warapp_get_game.');
|
|
84
|
+
const inGameId = inGameOf(target);
|
|
85
|
+
if (inGameId === undefined)
|
|
86
|
+
refuse(`${who}'s in-game id could not be read, so nothing was sent.`, 'Check warapp_get_game.');
|
|
87
|
+
const now = Date.now();
|
|
88
|
+
const rules = game.endRules ?? {};
|
|
89
|
+
const entry = leavers(game, now).players.find((l) => l.playerId === target.id);
|
|
90
|
+
const block = directBootBlock(rules.directBootMinutes, entry?.directBootInMinutes);
|
|
91
|
+
if (block)
|
|
92
|
+
refuse(`${who} cannot be booted from game ${gameId} yet: ${block}. Nothing was sent.`, 'warapp_get_game shows each player\'s time to a boot (`leavers`).');
|
|
93
|
+
const becomes = rules.bootedTurnIntoAI === undefined ? null : rules.bootedTurnIntoAI ? 'AI' : 'neutral';
|
|
94
|
+
const start = parseFeedTime(game.lastTurnTime);
|
|
95
|
+
return {
|
|
96
|
+
gate: {
|
|
97
|
+
action: 'warapp.boot_player',
|
|
98
|
+
summary: `Boot ${who} from war.app game ${gameId}`,
|
|
99
|
+
account: writeAccount(me),
|
|
100
|
+
target: gameId,
|
|
101
|
+
payload: { method: 'BootPlayer', gameId, playerId: inGameId },
|
|
102
|
+
willSend: { game: gameId, player: target.id, inGameId },
|
|
103
|
+
preview: {
|
|
104
|
+
warning: `This BOOTS ${who} from game ${gameId}: they are kicked out at once and cannot take this seat back as themselves; ` +
|
|
105
|
+
`their seat becomes ${becomes === 'AI' ? 'an AI' : becomes === 'neutral' ? 'neutral land' : 'an AI or neutral land (the setting was not read)'}.`,
|
|
106
|
+
account: shownAccount(seat.name, me),
|
|
107
|
+
game: { id: gameId, name: game.name === undefined ? null : untrustedText(game.name), state: game.state },
|
|
108
|
+
player: { player: target.id, inGameId, name: untrustedText(target.name) },
|
|
109
|
+
waitingMinutes: entry?.waitingMinutes ?? null,
|
|
110
|
+
turnStartedAt: start === undefined ? null : new Date(start).toISOString(),
|
|
111
|
+
directBootMinutes: rules.directBootMinutes ?? null,
|
|
112
|
+
becomes,
|
|
113
|
+
unverified: 'BootPlayer is read from the client bundle and not yet verified live. The wait is read from lastTurnTime (unverified as the ' +
|
|
114
|
+
"turn's start); banked boot time and vacations are not counted, so war.app may still refuse. The outcome is read back from GameFeed.",
|
|
115
|
+
untrusted: UNTRUSTED_PREVIEW_NOTE,
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
state: { gameId, me, player: target.id, inGameId },
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
async execute({ gameId, me, player, inGameId }) {
|
|
122
|
+
await requireApprovedAccount(ctx, writeAccount(me));
|
|
123
|
+
const game = { id: gameId };
|
|
124
|
+
const who = { player, inGameId };
|
|
125
|
+
const words = worded(BOOT_ERRORS);
|
|
126
|
+
return sendAndVerify({
|
|
127
|
+
send: async () => {
|
|
128
|
+
await ctx.rpc.call('BootPlayer', Method.BootPlayer, (w) => writeBootPlayerParams(w, { gameId, playerId: inGameId }));
|
|
129
|
+
},
|
|
130
|
+
// 445: the client's "This player was just booted and turned into an AI": a boot, read back as one.
|
|
131
|
+
refused: (e) => (e.code === BOOTED_INTO_AI ? 'ignore' : words(e)),
|
|
132
|
+
unanswered: (failure) => ({
|
|
133
|
+
status: 'unknown',
|
|
134
|
+
outcome: 'unknown',
|
|
135
|
+
game,
|
|
136
|
+
...who,
|
|
137
|
+
warning: `war.app did not confirm the boot (${failure}), so it may already have gone through. Check warapp_get_game before doing anything else.`,
|
|
138
|
+
}),
|
|
139
|
+
readBack: () => ctx.client.getGame(gameId, { map: false }),
|
|
140
|
+
unreadable: (failure) => ({
|
|
141
|
+
status: 'unconfirmed',
|
|
142
|
+
outcome: 'unconfirmed',
|
|
143
|
+
game,
|
|
144
|
+
...who,
|
|
145
|
+
warning: `war.app took the request, but GameFeed could not be read back (${failure}). Check warapp_get_game.`,
|
|
146
|
+
}),
|
|
147
|
+
classify: (after) => {
|
|
148
|
+
const theirs = after.players.find((p) => p.id === player);
|
|
149
|
+
const state = { theirState: theirs?.state ?? null, gameState: after.state };
|
|
150
|
+
if (theirs?.state === 'Booted' || theirs?.humanTurnedIntoAI === true) {
|
|
151
|
+
return { status: 'booted', outcome: 'confirmed', game, ...who, ...state };
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
status: 'unconfirmed',
|
|
155
|
+
outcome: 'unconfirmed',
|
|
156
|
+
game,
|
|
157
|
+
...who,
|
|
158
|
+
...state,
|
|
159
|
+
warning: 'war.app took the request, but GameFeed does not show the player booted yet. Check warapp_get_game shortly; do not send it again blindly.',
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
}
|
package/dist/tools/chat.js
CHANGED
|
@@ -273,6 +273,21 @@ export async function markChatSeen(ctx, gameId, me, read, cursor, channels) {
|
|
|
273
273
|
: undefined;
|
|
274
274
|
}
|
|
275
275
|
const playerOf = (players, byInGame, id) => byInGame.get(id) ?? players.find((p) => p.id === id);
|
|
276
|
+
/**
|
|
277
|
+
* One reaction as the tools show it: its kind, who reacted (the game's player when the in-game id is one, by
|
|
278
|
+
* GameFeed id, else the name war.app sent beside it; delimited either way) and whether it is mine.
|
|
279
|
+
*/
|
|
280
|
+
function shownReaction(r, byInGame, me) {
|
|
281
|
+
const p = byInGame.get(r.by);
|
|
282
|
+
const name = p?.name ?? r.name;
|
|
283
|
+
return {
|
|
284
|
+
type: r.type,
|
|
285
|
+
...(r.code !== undefined ? { code: r.code } : {}),
|
|
286
|
+
from: name === null ? null : untrustedText(name),
|
|
287
|
+
fromId: p?.id ?? null,
|
|
288
|
+
mine: me !== undefined && r.by === me.inGameId,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
276
291
|
/** A line as the tool shows it: players by GameFeed id, names and the text delimited. */
|
|
277
292
|
export function shown(line, isNew, players, byInGame, me, map) {
|
|
278
293
|
let from = null;
|
|
@@ -304,6 +319,10 @@ export function shown(line, isNew, players, byInGame, me, map) {
|
|
|
304
319
|
...(to ? { to } : {}),
|
|
305
320
|
// #387: a private message addressed to me, so a watcher can flag diplomacy the moment it arrives.
|
|
306
321
|
...(line.channel === 'private' && me !== undefined && line.to === me.inGameId ? { toMe: true } : {}),
|
|
322
|
+
// #634: what the sender shared and who reacted, all their own words (delimited).
|
|
323
|
+
...(line.images?.length ? { images: line.images.map((k) => untrustedText(k)) } : {}),
|
|
324
|
+
...(line.reactions?.length ? { reactions: line.reactions.map((r) => shownReaction(r, byInGame, me)) } : {}),
|
|
325
|
+
...(line.reactionsUnread ? { reactionsUnread: true } : {}),
|
|
307
326
|
mine: isMine(line, me),
|
|
308
327
|
new: isNew,
|
|
309
328
|
};
|