Skip to content

ServerHooks beta ​

Interface of @v12-engine/engine

ts
export interface ServerHooks

What a game does on a server (Rules.server). Only ever run there: a player's screen has none of it. The lobby's settings come to onGameStart as the lobby left them

Members ​

onGameEnd ​

ts
onGameEnd?(world: World, result: GameResult): void;

The game ended: who won, as plain data, before it is kept (saveResult)

onGameStart ​

ts
onGameStart?(world: World, seats: readonly ServerSeat[], settings: Record<string, string>): void;

The game starts, with the world made and the lobby's settings

onPlayerJoin ​

ts
onPlayerJoin?(seat: ServerSeat, world?: World): void;

Someone took a seat in the lobby, or came back to theirs in a game (world then)

onPlayerLeave ​

ts
onPlayerLeave?(seat: ServerSeat, world?: World): void;

Someone left their seat: in the lobby, or in a game (world then), where they may come back

saveResult ​

ts
saveResult?(result: GameResult): void | Promise<void>;

Keeps a game's result: in a file, a database, a ranking. A server writes it to a file of its own without

seatSettings ​

ts
seatSettings?: Record<string, LobbySetting>;

Settings of each seat, by name: a race, a difficulty, a colour. Chosen in the lobby by who sits there, and for a seat the computer plays or nobody holds, by any player seated; each seat's (ServerSeat.settings) are handed to its computer player (GameMode.ai) and to the start (onGameStart)

settings ​

ts
settings?: Record<string, LobbySetting>;

Settings of the lobby, by name: what can be chosen, and what is chosen until someone does