Skip to content

five-on-it / apps/server/src

apps/server/src ​

Process entrypoint of the authoritative game server: one HTTP listener for the endpoints and the WebSocket upgrades of http.ts, and one fixed 60 Hz loop that ticks every room (rooms.ts).

The default room plays the level FOI_LEVEL names (a bundled name or a .json level file; main-riverbend by default, else the first main-* level in name order, else the first test-*) with the game FOI_GAME names (a game file; by default the level's bundled game, if it has one, else free roam); a connection to the server's root joins it, which is how a standalone server, the desktop app and the end-to-end tests play. FOI_DEFAULT_ROOM=0 leaves it out. FOI_PEDESTRIANS sets how many pedestrians it keeps around the players (40 on a main-* level, 24 on a test-* one by default), FOI_CHASERS_FOOT and FOI_CHASERS_CAR how many chasers start on foot and in cars, FOI_CHASER_PROFILE their profile, FOI_CHASER_CLASS their cars' class and FOI_CHASER_CREW how many ride in each car, FOI_DEBUG (1 or 0) whether its clients' debug commands are honoured (on a test-* level they are by default; npm run dev turns them on whatever the level), FOI_POLICE (1 or 0) whether it has police (the game's rules.police by default, on in free roam). FOI_TRAFFIC how many ambient cars drive its roads (by default the game's rules.traffic, else a few dozen on a main-* level and none on a test-* one). FOI_DELTA=0 sends every snapshot whole instead of what changed since the last one a client was sent; FOI_AOI_TIERS=0 sends the far entities as often as the near ones; FOI_WS_DEFLATE=0 stops compressing the frames (permessage-deflate, on by default: see performance.md). FOI_WEATHER is the rooms' weather: on (the level's climate changing on its own, the night shortening sight; the default but on a test-* level), off (always clear; the default on a test-* level) or a climate by name (alpine, coast…); a game's rules.weather and its missions script it either way.

A connection asking for a level that ships (/game?level=main-riverbend, the main menu's level selection) gets a room of its own for that level, opened on demand with its bundled game and the same switches (level-rooms.ts); FOI_LEVEL_ROOMS=0 turns that off.

FOI_RTC=1 offers the clients a WebRTC data channel for the inputs and the snapshots beside their WebSocket (rtc-transport.ts, run in a worker thread: rtc-host.ts), on the UDP ports FOI_RTC_PORTS, gathering on FOI_RTC_ADDRESSES, announcing FOI_RTC_PUBLIC_IP, FOI_RTC_MAX_PEERS channels at most (rtc-settings.ts); off by default.

FOI_ROOM_SECRET lets the platform API open rooms for its games here and lets players join them with the join tokens it signs; FOI_JOIN=token (a platform for the game's owners) asks one of every connection, the default room's and the levels' too (http.ts), and needs the secret. A room that stands empty for FOI_ROOM_IDLE_S seconds (300) closes. PORT selects the port (7777), LOG_LEVEL the logging.