Skip to content

GameServer beta ​

Class of @v12-engine/engine/server

ts
export declare class GameServer

A server of a game: its connections, who joins and where they go (Doorman), its lobby (Lobby: the seats, the settings, when a game starts) and its game while one is on (Match)

Members ​

attach ​

ts
static attach(source: ConnectionSource, options: Omit<GameServerOptions, 'port'>): Promise<GameServer>;

A server whose connections come from elsewhere (ConnectionSource): a room of GameRooms, those a port it shares hands it. Closing it closes those, and leaves where they come from to whoever owns it

bytesSent ​

ts
get bytesSent(): number;

Bytes sent to those connected now, as they went over the wire: compressed, where they are

close ​

ts
close(options?: {
        drain?: number;
    }): Promise<void>;

Stops the server: every connection closed. With drain, it first takes no new games (its health says so, for a load balancer to send nobody new) and waits for the running one to end, up to so many seconds: then it is ended (no winner, the players told the server stopped) and the server closes

connections ​

ts
get connections(): number;

How many are connected to it, playing or watching: none, for a room that may be closed

draining ​

ts
draining: boolean;

It takes no new games: it is stopping once the running one is over (close({ drain }))

endGame ​

ts
endGame(): Promise<GameResult | undefined>;

The game is over: the result told to everyone and kept. The game goes on being shown until everyone has left

host ​

ts
get host(): SessionHost | undefined;

What sends the game to its players, while there is one

kick ​

ts
kick(player: PlayerId, reason: string): void;

Lets a player go for good: told why, their connection closed, and their token and id no good any more

listing ​

ts
listing(room: string): GameListing;

What a list of games says of it (GET /games, GameListing), as the room it is reached at

logger ​

ts
readonly logger: Logger;

What the server and its games say: see GameServerOptions.log

metrics ​

ts
metrics(): ServerMetrics;

Its numbers now: what /metrics says (see ServerMetrics)

options ​

ts
readonly options: GameServerOptions;

What the server was made with

pause ​

ts
pause(paused: boolean, by?: {
        player: PlayerId;
        seconds: number;
    }): void;

Pauses the game for everyone, or lets it go on. A player's pause (by, from the pause command) ends by itself after its seconds, or when a seated player says resume; an admin's, when the admin says so

pausedBy ​

ts
get pausedBy(): PlayerId | 'admin' | undefined;

Who paused the game: an admin, or a player (with a pause of theirs, for so long at most). Nobody while it runs

phase ​

ts
phase: 'lobby' | 'game' | 'ended';

Where the server is: lobby before the game, game while it is on, ended once it is over

port ​

ts
get port(): number;

The port the server listens on, the real one where 0 was asked for

settings ​

ts
get settings(): Record<string, string>;

The game's settings (ServerHooks.settings), as chosen in the lobby

start ​

ts
static start(options: GameServerOptions): Promise<GameServer>;

Starts a server, and resolves once it listens

startGame ​

ts
startGame(): Promise<void>;

Makes the world, seats everyone at it, and runs it

world ​

ts
get world(): World | undefined;

The world of the game on, or of the one that ended while its players are still on its screen