GameServer beta
Class of @v12-engine/engine/server
export declare class GameServerA 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
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
get bytesSent(): number;Bytes sent to those connected now, as they went over the wire: compressed, where they are
close
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
get connections(): number;How many are connected to it, playing or watching: none, for a room that may be closed
draining
draining: boolean;It takes no new games: it is stopping once the running one is over (close({ drain }))
endGame
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
get host(): SessionHost | undefined;What sends the game to its players, while there is one
kick
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
listing(room: string): GameListing;What a list of games says of it (GET /games, GameListing), as the room it is reached at
logger
readonly logger: Logger;What the server and its games say: see GameServerOptions.log
metrics
metrics(): ServerMetrics;Its numbers now: what /metrics says (see ServerMetrics)
options
readonly options: GameServerOptions;What the server was made with
pause
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
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
phase: 'lobby' | 'game' | 'ended';Where the server is: lobby before the game, game while it is on, ended once it is over
port
get port(): number;The port the server listens on, the real one where 0 was asked for
settings
get settings(): Record<string, string>;The game's settings (ServerHooks.settings), as chosen in the lobby
start
static start(options: GameServerOptions): Promise<GameServer>;Starts a server, and resolves once it listens
startGame
startGame(): Promise<void>;Makes the world, seats everyone at it, and runs it
world
get world(): World | undefined;The world of the game on, or of the one that ended while its players are still on its screen