forked from WikiDeck/wikideck
Modes: reject non-hostable keywords (obscure) in mode rules; document card-input boundary
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -153,7 +153,8 @@ A mode is rejected at node startup, never handed to the engine half-checked, if:
|
||||
- the merged ruleset fails the engine's strict `parseRuleset`, or
|
||||
- it fails the host-side checks in `server/game/engine-binding.ts`: `distinctStats` requires
|
||||
`topicCount` 3; every `portalReveal` turn ≤ `turns`; `energyByTurn` has an entry per turn;
|
||||
`turns × turnSeconds ≤ 240`; `powerByCost` has 7 entries; or
|
||||
`turns × turnSeconds ≤ 240`; `powerByCost` has 7 entries; no keyword whose hidden information
|
||||
`viewFor` doesn't mask yet (`obscure`) is enabled; or
|
||||
- its deck policy can't produce legal decks (starter decks illegal under its rules, or a draft
|
||||
pool smaller than 2 × `deckSize`).
|
||||
|
||||
@@ -184,6 +185,8 @@ requests in any request or match path**:
|
||||
- **Sybils and win-trading:** anyone can make a new player id, and two ids controlled by the same
|
||||
person can feed each other wins. Tonight's leaderboards are for fun. Accounts (#7) or
|
||||
wallet-signed identities would raise the cost.
|
||||
- **Card input.** The host builds every deck from shipped engine data (starter decks and the
|
||||
loaner pool). It never accepts cards, `check` values or pinned stats from client JSON.
|
||||
- **Card stats.** Card numbers come from the engine's card mapping. Minted stats are self-reported
|
||||
by the minter (see council-critic in #3); a mode can only pick a mapping preset, not supply numbers.
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ export function previewPool(rules: Ruleset, seed: string, size: number): GameCar
|
||||
* The engine's strict parseRuleset, plus host-side checks that keep a hosted mode playable
|
||||
* (requested in review on #6). Anything that fails is rejected at startup, never passed on.
|
||||
*/
|
||||
export const UNSAFE_KEYWORDS: readonly string[] = ['obscure'];
|
||||
|
||||
export function parseModeRuleset(value: unknown): Ruleset {
|
||||
const rules = parseRuleset(value);
|
||||
const problems: string[] = [];
|
||||
@@ -29,6 +31,8 @@ export function parseModeRuleset(value: unknown): Ruleset {
|
||||
if (rules.energyByTurn.length < rules.turns) problems.push('energyByTurn needs one entry per turn');
|
||||
if (rules.turns * rules.turnSeconds > 240) problems.push('turns × turnSeconds must be ≤ 240');
|
||||
if (rules.powerByCost.length !== 7) problems.push('powerByCost needs 7 entries');
|
||||
// Keywords whose hidden information viewFor doesn't mask yet would leak cards to the opponent (#6, #27).
|
||||
for (const id of UNSAFE_KEYWORDS) if ((rules.keywordsEnabled as readonly string[]).includes(id)) problems.push(`keyword "${id}" is not hostable yet (viewFor does not mask it)`);
|
||||
if (problems.length) throw new Error(`Invalid mode rules: ${problems.join('; ')}`);
|
||||
return rules;
|
||||
}
|
||||
|
||||
@@ -200,7 +200,10 @@ test('modes api: mode rules are checked beyond the engine schema and rejected, n
|
||||
{ powerByCost: [0, 1, 2] },
|
||||
{ mulligan: true },
|
||||
{ keywordParams: { notAKeyword: { amount: 1 } } },
|
||||
{ keywordsEnabled: [...DEFAULT_RULESET.keywordsEnabled, 'obscure'] },
|
||||
];
|
||||
for (const rules of bad) assert.throws(() => resolveRuleset(DEFAULT_RULESET, rules as any, parseModeRuleset), JSON.stringify(rules));
|
||||
assert.throws(() => resolveRuleset(DEFAULT_RULESET, { keywordsEnabled: ['viral', 'obscure'] }, parseModeRuleset), /not hostable/);
|
||||
assert.doesNotThrow(() => resolveRuleset(DEFAULT_RULESET, { keywordsEnabled: ['viral', 'edition', 'wildcard'] }, parseModeRuleset));
|
||||
assert.doesNotThrow(() => resolveRuleset(DEFAULT_RULESET, {}, parseModeRuleset));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user