Skip to main content

SDK Quickstart

Integrate your dedicated server with GameFlow in a handful of steps. Pick your language once; the selection follows you across every step and across the rest of the docs.

The flow is the same everywhere: connect → ready → track players → shut down. Health reporting starts on its own once you call ready(); you never ping anything yourself.

1. Install

npm install @gameflow.gg/gameserver-sdk

Requires Node 18.17+. Zero runtime dependencies.

2. Connect and signal readiness

Connect on startup, start listening on the assigned port, then call ready() only when your server can actually accept connections. Until then the platform will not send players to it.

import { GameFlow } from '@gameflow.gg/gameserver-sdk';

const gf = await GameFlow.connect();

// Listen on the platform-assigned port, then signal readiness.
myServer.listen(gf.ports.default ?? 7777);
await gf.ready(); // health reporting starts automatically

3. Track players

Register a session when a player joins and unregister it when they leave. Use any stable unique id (session id, account id).

This matters beyond dashboards: GameFlow shuts down servers that report zero players past your organization's idle timeout, so a server that never reports players will be reaped.

import { ServerFullError } from '@gameflow.gg/gameserver-sdk';

// when a player joins
try {
await gf.players.connect(client.sessionId);
} catch (err) {
if (err instanceof ServerFullError) client.reject('server full');
}

// when a player leaves
await gf.players.disconnect(client.sessionId);

gf.players.count(); // current player count (synchronous)
gf.players.list(); // connected session ids
gf.players.capacity(); // max players configured for your game

4. Use the launch payload (optional)

Servers can be launched with an opaque payload (match config, team rosters, anything). The SDK treats it as a string, so parse it however you produced it.

const payload = await gf.payload(); // string | undefined
const match = payload ? JSON.parse(payload) : null;

gf.onPayloadChange((next) => {
// fires when the platform assigns this server to a new match
});

5. Shut down cleanly

When a server is stopped, the platform sends SIGTERM and force-kills the container about 45 seconds later. Drain and call shutdown() well within that budget. Also call it yourself when a match ends and the server is done.

process.on('SIGTERM', async () => {
myServer.close();
await gf.shutdown();
process.exit(0);
});

6. Ship it

Package your server with a Dockerfile at the build root (run as UID 1000, expose your port) and upload it through the GameFlow dashboard or CLI. See Creating a Game.

Before you upload, test everything on your machine first; the same binary runs unchanged off-platform. See Local development.