14. Server features register themselves
14. Server features register themselves (#326, part 2 of #317)
Section titled “14. Server features register themselves (#326, part 2 of #317)”-
[E] Decided by the owner (2026-11-19, #317): the action table of
src/server/game/dispatch.tsand the state ofsrc/server/game/state.tsstop being edited by every feature; a feature registers itself like a round setting (#310) and a client feature (#322). No change of the game, of a text, of an action name or of the JSON the client receives. -
[V] Contract (main agent’s proposal, the owner decided only that the pattern comes): a server module that adds actions or a part of the state exports under the fixed name
serverFeature,export const serverFeature = { actions, adminActions, state, enabled, off } satisfies ServerFeature;, all members optional (offis required withenabled).ServerFeatureandStatePartare insrc/server/game/feature.ts. The module lives next to the server code of the feature (src/server/game/<feature>.ts, as the round settings live insrc/core), not in a new folder.actionsmaps an action name to itsAction;adminActionsthe same for the actions of the admin, which are audited asadmin.writeand not asgame. A name is in exactly one of the two.- [E] A feature says whether it is on in the round (#374; owner,
2026-11-22, #351: a refactor of the v3 foundation without a change of
behaviour). [V]
enabled(round)with its refusaloff: while it is off,runActionrefuses each of its actions withoffand every key of itsstatepart is null (assembleStatewraps itsbuild). Guilds, their ranks and their chat (guilds,guild-ranks,guild-chat) sayenabled: (round) => round.guilds, off: GUILDS_OFFinstead of the former groupguildActions(#191); the marketplace keeps its own switch in its own code.GUILD_ACTIONSofdispatch.tsis read from the switches (the actions refused withGUILDS_OFF). The admin’s guild chat (adminGuildChat, an HTTP route, not an action) keepsrequireGuilds, and the Schnellwahl leaves the guild targets out byround.guilds(#292): neither refuses an action or leaves out a state part. The group cases ofregistry.test.tsbecame cases of the switch, at least as strict (coordinator, 2026-11-24, [V]). stateis oneStatePart:order(a number, the next free ten above the highest; it fixes the place of the keys in the JSON object, so every snapshot stays),keys(the keys it adds, so a key defined twice is found at the start) andbuild(ctx, user, view), which returns an object with exactly these keys.viewholds whatstateForcomputes once for all parts (the round rules, the main planet, the shown planet, the points, the activity limits).
-
[V] The list is generated:
scripts/gen-features.tswritessrc/server/features.gen.ts(SERVER_FEATURES,[name, serverFeature]pairs sorted by path), not checked in (.gitignore), from every file ofsrc/serverthat exportsserverFeature(same detection as forroundSettings). It is not insrc/server/game/becausesrc/server/push-options.tsregisters too. Onlysrc/serverimports it:client-not-server,core-stays-pureandfeature-stays-pureforbid every other part of the code to reachsrc/server, so the browser bundle cannot contain it. Knip takes it as an entry; Vitest coverage and Stryker leave it out. -
[V]
dispatch.tsandstate.tskeep their frame: the general gates ofrunAction(vacation, the switch of a feature, admin audit category, achievements) and the actions and state keys of the core game. The functions ofsrc/server/game/assemble.tsbuildACTIONS, the switches of the actions andADMIN_ACTIONSfrom the frame and the list and the ordered parts of the state; a name, a key or an order number that exists twice stops the start with both files named. The guard testsrc/server/game/registry.test.tschecks the rules for every listed module. -
[V] Built: these modules register
actionsoradminActions(demolition,endzeit,admin,phalanx,missiles,jump-gate,main-planet,vacation,abandon,market,fleet-actions,push-options,friends,achievements,guilds,guild-ranks,guild-chat) and these a part of the state (main-planet60,jump-gate80,guilds110,friends120,achievements130,abandon170 for the locks,market180, andadmin-state190, a module of its own because the Endzeit importsadmin.ts, thenquick-targets200 for the Schnellwahl of the fleet form, #292). The frame keys ofstate.tshave numbers too (10 to 160, ten apart, with the gaps the features use), so the JSON keys stay in their old order; a new part takes the next free ten above the highest. Left in the frame on purpose: the actionsbuild,cancelBuild,research,cancelResearch,order,pct,rename,options,read,delrepanddelallofactions.ts(the core game and the account;actions.test.tscalls them directly), the general gates ofrunAction,lockedState(the lock screen of the vacation mode has its own, shorter shape),meOf(the account, with its push kinds and its vacation) and the keysround,now,cfg,me,planet,labs,fleets,reports,players,galaxyanddebris.src/server/game/registry-pin.test.tswrote out every action with its group and the key order of the state once for the refactoring; it is deleted (#317), the guardregistry.test.tskeeps the rules and no list has to be edited when an action or a key is added. -
[E] Decided by the owner (2026-11-20, #317, #118, „jetzt komplett“): the boundary between the browser and the server is checked by the compiler, for the actions and for the state. No game rule, text, value or wire format changes; the validation of the server stays as it is (types do not replace it: the input arrives as JSON and every handler still checks what it reads).
-
[V] The actions:
src/core/actions/<feature>.tsdeclares the input of each action,export const actionInputs = { name: input<{ ... }>() }(inputandAttr, the type of adata-*attribute, are insrc/core/action-input.ts). The files are listed in the git-ignoredsrc/core/actions.gen.ts(scripts/gen-features.ts, the same detection as forroundSettings), so a new action edits no shared list;src/core/ actions.tsmerges them into the typeActionMapand offersActionNameandWire<K>, the input plus theplanetthe browser’s transport adds to every call. A field the browser reads from adata-*attribute isAttr(a text or nothing); a field the server accepts leaves out (cargo,pctofsend) is optional, because the map says what the server accepts and the browser’s form is a subtype of it. -
[V] The server side: a handler is declared
Handler<'name'>(src/server/game/actions.ts), so itsdis the input of the map, and the membersactionsandadminActionsofServerFeatureareHandlers, a mapped type over the names of the map: a name the map does not know, or a handler of another action, is a compile error. The table ofdispatch.tserases the type inassembleActions(one cast, there). The guardsrc/server/game/action-contract.test.tschecks at run time that the names the server registers are exactly the names the map declares, each once, and at compile time that every handler declares exactly the input of its name (a handler typed with the wideDatafails there). Tests that send junk on purpose useloose<'name'>(...)oftest-helpers.ts. -
[V] The state:
src/core/state/<part>.tsexportstype StateShape, the keys one part holds and their types (the frame ofstate.tsinframe.ts); the files are listed insrc/core/state.gen.ts(FullState, the intersection), andsrc/core/state.tsderivesGameStatefrom it: the keys of the lock screen of the vacation mode (LockedState) always, every key of a feature as optional, as the lock screen does not send them. A feature declaresstate: { ... } satisfies StatePart<StateShape>, a key of the frame goes throughkeyedofstate.ts, which takes the type fromframe.ts; so what the server builds is checked against the type the browser reads, andsrc/server/game/state-contract.test.tschecks that every key of a feature has a shape and every shape a sender.client/logic/types.tsonly re-exports. -
[V] Where the hand-written
GameStatediffered from what the server sends:GuildChatMessage.arrivalisnumber | null(the column is nullable; only an attack carries it), the browser treated it asnumber | undefinedand would have shown 1970 for an attack row without a time;logic/guilds.tsnow treatsnulllike a missing time.AdminState.specsisreadonly. Nothing else differed. -
[E] Changed for #542, not built yet (owner, 2026-11-30): every feature gets one folder
src/features/<feature>/with its rules and checks, its action inputs and state shape, its Lexicanum page, its server part (*.server.ts) and its client part (*.client.ts), and its tests;src/corekeeps only what two or more features share. This replaces, once #542 is built, the place of the checks insrc/core(pattern 7), the ban of client code in a feature folder (pattern 11) and the separate places of pattern 13 and 14. Names are readable (#543), and each rule exists once and is checked by the server (#544).