@flayerlabs/gamemode-gate
v0.2.0
Published
Server-authoritative rooms, economy, admission and registry for Flaunch Game Modes
Readme
@flayerlabs/gamemode-gate
Run authoritative Game Mode rooms, spending allowance, admission and game discovery. You can run SDK rules or accept point awards from an existing authoritative game server.
Requirements
You need:
- Node.js 20 or later
- PostgreSQL
@flayerlabs/gamemode-specat the matching SDK version
Install the package and direct database dependency:
pnpm add @flayerlabs/gamemode-gate @flayerlabs/gamemode-spec pgStart a local gate without a chain
createDemoGate starts the real gate flow with a stand-in wallet and no chain access. It expects
PostgreSQL at postgres://postgres:[email protected]:55439/gamemode unless you set DATABASE_URL.
import { createDemoGate } from '@flayerlabs/gamemode-gate'
import { rules, type Config } from './game/rules.js'
const config: Config = {
rounds: 3,
ceiling: 10,
points: 500,
roundMs: 10_000,
}
const demo = await createDemoGate({
game: rules,
config,
gateOrigin: 'http://127.0.0.1:4000',
})
await demo.app.listen({ host: '127.0.0.1', port: 4000 })This path uses the real room, database, socket and signed spend authorisations. It records purchases
instead of submitting them to a chain. Do not use createDemoGate in production.
Build a production gate
Run migrate(pool) before the gate accepts traffic.
If you already ran the pre-release schema, run migrate(pool) again. An empty setup upgrades in
place. Delete any pre-release test rounds first because their game ID and point limit are unknown.
A createGate setup needs:
Sessionsconfigured with the page domain and the gate's exact public originClaims,LedgerandPayloadSignerfor spending authorisationspointsPerDollar,usdPerEthand the allowed game origins
Add the chain services used by your deployment:
Discoveryverifies each launch before the gate adopts itSettlementupdates recorded spending from the chain
Run one gate process for each game. The current room writer does not support multiple replicas.
Use createTurnstileAdmit if the trusted parent supplies Cloudflare Turnstile evidence. The policy
checks session creation. Game action and claim policy remain the gate operator's responsibility.
Read the production gate guide before deploying a gate.
Connect an existing game server
Use createGameServerGate() when your server already owns gameplay and scoring:
import { createGameServerGate } from '@flayerlabs/gamemode-gate'
const awardToken = process.env.AWARD_TOKEN
if (!awardToken || awardToken.length < 32) {
throw new Error('AWARD_TOKEN must contain at least 32 characters')
}
const app = createGameServerGate({
pool,
sessions,
claims,
discovery,
settlement,
gameId: 'my-game',
maxPointsPerPlayer: 10_000,
awardToken,
pointsPerDollar: 500,
usdPerEth: 3_000,
allowedOrigins: ['https://game.example'],
})The award token must contain at least 32 characters. Keep it on your game server. Never send it to the browser.
Use a stable, distinct gameId for each game. It scopes durable rounds and awards when games share
a PostgreSQL database.
Your server adds points with POST /internal/rounds/:id/awards. The gate checks the token, event
ID, wallet, round window and per-player limit before it changes the ledger. It also makes identical
retries safe.
Use the external game-server steps for the request format, responses and deployment checks. Do not call the ledger or signer directly.
Run the central game registry
createGameRegistry provides:
- public
GET /games/:chainId/:coinlookups for trusted Flaunch pages - authenticated internal routes for the Flaunch launch backend to pin or disable a registration
The registry is a central Flaunch service. Do not run it inside a creator gate. Its
writerToken must contain at least 32 characters and stay on the launch backend.
Read the current request and response behaviour in the game registry source.
