Skip to content

five-on-it / apps/server/src/game-server / GameServer

Class: GameServer ​

Defined in: apps/server/src/game-server.ts:760

One city instance.

Constructors ​

Constructor ​

new GameServer(level, options?): GameServer

Defined in: apps/server/src/game-server.ts:842

Parameters ​

level ​

Level

options? ​

GameServerOptions = {}

Returns ​

GameServer

Properties ​

ai ​

readonly ai: AiWorld

Defined in: apps/server/src/game-server.ts:773

The NPC brains.


bytesOut ​

bytesOut: number = 0

Defined in: apps/server/src/game-server.ts:789

Bytes sent in snapshots since start (for the metrics endpoint).


debug ​

readonly debug: boolean

Defined in: apps/server/src/game-server.ts:777

Whether the clients' debug commands are honoured.


level ​

readonly level: Level

Defined in: apps/server/src/game-server.ts:764

The level the world was built from, as every client receives it.


missions ​

readonly missions: MissionHost | undefined

Defined in: apps/server/src/game-server.ts:775

The game's missions, when the server runs a game.


roads ​

readonly roads: RoadGraph

Defined in: apps/server/src/game-server.ts:771

The level's roads as a graph of lanes: what the AI drives on.


run ​

readonly run: RunHost | undefined

Defined in: apps/server/src/game-server.ts:832

The run, in a run's room.


sim ​

readonly sim: SimWorld

Defined in: apps/server/src/game-server.ts:762

The authoritative world.


social ​

readonly social: RoomSocial

Defined in: apps/server/src/game-server.ts:820

The room's roster, chat and votes to kick.


substepTicks ​

readonly substepTicks: number[]

Defined in: apps/server/src/game-server.ts:791

How many ticks took one, two, three and four physics steps (substeps.ts), for /health.

Accessors ​

aiStatus ​

Get Signature ​

get aiStatus(): AiStatus

Defined in: apps/server/src/game-server.ts:1462

The AI's numbers for the health endpoint.

Returns ​

AiStatus


clientCount ​

Get Signature ​

get clientCount(): number

Defined in: apps/server/src/game-server.ts:1535

Number of connected clients.

Returns ​

number


frozen ​

Get Signature ​

get frozen(): boolean

Defined in: apps/server/src/game-server.ts:1545

Whether the room waits: its one player has the pause menu open. A room of several never waits for one of them (the city goes on); the room host skips the ticks of a frozen room. A run's room never waits, even for its one player: the run's clocks (its countdown, its time, its idling) are the wall clock's, so a pause would be counted as played.

Returns ​

boolean


netStatus ​

Get Signature ​

get netStatus(): object

Defined in: apps/server/src/game-server.ts:2061

The room's snapshots as the metrics read them: whether they are deltas and tiered, how long a round takes to build and encode (ms, on average), the bytes sent, the snapshots skipped on backed-up connections, the keyframes clients asked for, how many entities a client holds on average, and the clients' inputs that came after their tick was run on a guess (late: each a tick the server drove on the last input held, which the client's prediction ran on its own).

Returns ​

object

aoiTiers ​

aoiTiers: boolean

bytesOut ​

bytesOut: number

delta ​

delta: boolean

entitiesPerClient ​

entitiesPerClient: number

late ​

late: number

resyncs ​

resyncs: number

skipped ​

skipped: number

snapshotMs ​

snapshotMs: number

Methods ​

acknowledged() ​

acknowledged(clientId): number

Defined in: apps/server/src/game-server.ts:2108

The client's last tick the server has run: what its snapshots acknowledge (0 before its first input).

Parameters ​

clientId ​

number

Returns ​

number


addClient() ​

addClient(transport, who?): number

Defined in: apps/server/src/game-server.ts:1568

Registers a connection, who its join token says it is (an account, a name, a party): spawns the player's car and character (seated as the driver, in their party), sends the welcome (with the level, or a big level's hash to a client that asked for it), puts them on the room's roster and starts accepting inputs. Returns the client id. A join is handled on the loop between two steps, so it is kept under a few milliseconds on the city that ships (join.integration.test.ts): nothing of the level is made here.

Parameters ​

transport ​

Transport

who? ​

Joiner = {}

Returns ​

number


addSeat() ​

addSeat(seat): { seat: number; } | { refused: string; }

Defined in: apps/server/src/game-server.ts:1779

A seat added to the run under way for a player the platform placed (POST /rooms/:id/seats): on the roster of the run and of its missions, its player's join token naming its index. Why not, when the run has no seat open on that team (or is no run).

Parameters ​

seat ​
account ​

string = ...

name ​

string = ...

party? ​

string = ...

team ​

string = ...

tier? ​

number = ...

Returns ​

{ seat: number; } | { refused: string; }


announceRestart() ​

announceRestart(seconds): void

Defined in: apps/server/src/game-server.ts:2089

Tells the room's players the server restarts for maintenance in so many seconds (a line of its chat).

Parameters ​

seconds ​

number

Returns ​

void


disconnectAll() ​

disconnectAll(code, reason): void

Defined in: apps/server/src/game-server.ts:2097

Closes every player's connection with a code (a refusal's, which the client explains: restarting when the server stops for maintenance).

Parameters ​

code ​

number

reason ​

string

Returns ​

void


dispose() ​

dispose(): void

Defined in: apps/server/src/game-server.ts:1893

Closes every connection and frees the world; the server is unusable afterwards.

Returns ​

void


isKicked() ​

isKicked(account): boolean

Defined in: apps/server/src/game-server.ts:1705

Whether an account was voted out of the room: it may not join again.

Parameters ​

account ​

string | undefined

Returns ​

boolean


pollRun() ​

pollRun(): void

Defined in: apps/server/src/game-server.ts:2266

A run's room, on every pass of the loop whether anybody is in it or not (rooms.ts): the run moved on by the clock (the gathering, the countdown, a dropped seat's minute running out: the missions let its player go); its players are told with the snapshots.

Returns ​

void


removeClient() ​

removeClient(id): void

Defined in: apps/server/src/game-server.ts:1906

Drops a client, its character and its car, unless someone is still in it (who carjacked it, or rides along): then the car goes when the last of them leaves the game, as does any such car the client sat in. Safe to call twice.

Parameters ​

id ​

number

Returns ​

void


resetLevel() ​

resetLevel(): void

Defined in: apps/server/src/game-server.ts:1489

Resets the whole level: every player back in a fresh car of the first class at the spawn they came in at, the pedestrians and the range dummies anew, every projectile gone, every light piece planted again, every other car gone (a chaser's a player had carjacked, the ambient traffic, which comes back out of sight), every item on the ground and container gone and the level's laid out anew, every door shut and locked as the level has it, every stored car and every player's Cash forgotten, the signals back to their plan and the clock to its start, and the level's parked cars put back; then tells every player it is done (a reset frame with the count). Asked for by any player's resetLevel input.

Returns ​

void


tick() ​

tick(): void

Defined in: apps/server/src/game-server.ts:2113

Advances the world by one tick and sends snapshots when due.

Returns ​

void


warmUp() ​

warmUp(options?): object

Defined in: apps/server/src/game-server.ts:1841

Warms the world up before its first player, as a room opens (rooms.ts): the physics' first step and the ticks the traffic and the crowd take to come run now (ordinary ticks, the whole step warmed: the AI, the missions, the snapshots' building), with a stand-in for the players at their first spawn point (where the first player comes in), instead of in that player's first second. It ticks until the streets are full (the traffic at its number and the crowd at the hour's, or neither grown for WARM_UP.stallTicks) and the last WARM_UP.quietSteps steps each took under WARM_UP.budgetMs, judged on multiples of WARM_UP.round ticks so every periodic job keeps its phase, and at most WARM_UP.maxTicks, logged as cut short. The warm-up is before the room's time: the room clock then starts at the game's time, as after a level reset, anchored on the tick reached (the welcome's tick: a tick count never starts at zero in a room). Logs "warmed in N ticks, M ms" with what came; returns both numbers. A clock and a cap may be injected (the tests'). What the first player's own join still costs over a later one's (4 ms against 1 on Riverbend, measured part by part) is not the world's: the process runs the join's code for the first time (every part of addClient five to ten times its warm cost) and Rapier's convex hull of the car's class costs 1.5 to 2 ms the first time after the warm-up (in createCollider, the same for a class the traffic has spawned, wherever the car is made, no collection of the garbage in it; the cause on the WASM side is not identified), 0.3 ms after that.

The snapshots of the warm-up go through an encoder of nobody's too, as the stand-in would get them (what lies within AOI_RADIUS of it, at its tiers; the bytes dropped): a keyframe, then deltas, so the first player's first frames are encoded by code the process has run, as every later player's are. Cold, the first delta after a keyframe took twice its warm time on Riverbend (1.2 to 2.7 ms against 0.9, the more cars changed since the keyframe the more), in a step the first player's join had already made slow.

Parameters ​

options? ​
maxTicks? ​

number

now? ​

() => number

Returns ​

object

ms ​

ms: number

ticks ​

ticks: number