Skip to Content
Game ServerIntroduction

Agent8 Server SDK

Agent8 hosts a game server for you. You write one Server class; your game’s clients call its methods, and it reads and writes data that the platform stores and pushes back to every client in real time. This page is the map: how the pieces connect, how your code runs, and where each kind of data belongs.

Architecture

The client keeps one connection to the game server (connected) and, after joinRoom(roomId), a second one to that room’s Room Server (rsConnected). Both run the same Server class; code running for a room can also use $room. Every store below pushes its changes to subscribed clients, throttled to at most one update per 30 ms.

How Your Code Runs

  • Every method is a remote function — and a public endpoint. Clients call server.remoteFunction(name, args) (Remote Function), and any client can call any method with any arguments, so take identity from $sender and decide amounts on the server (Execution Model).
  • Nothing survives a call except the stores. Each request gets a fresh Server instance, and there are no timers — recurring work goes in $roomTick, which runs every 200 ms per active room.
  • Calls run concurrently. Two requests, or two room hooks, can interleave; make a read-modify-write exclusive with $lock.
  • Rooms have a lifecycle. A room exists while someone is in it, and onRoomCreate … onRoomDestroy fire as players join and leave, with a 30 s grace period for dropped connections (Room System).
  • Messages are not stored. Broadcasts and direct messages reach whoever is subscribed at that moment — anything a player must not miss belongs in a store.

Where Data Lives

StoreScopeLives untilDurabilityClient hookUse for
Global stateOne document for the verseForeverPersisted in the backgrounduseGlobalStateGame-wide settings, status, shared counters
User stateOne document per playerForeverPersisted in the backgrounduseGlobalMyStateProfile, progression, inventory
Global collectionQueryable list of itemsForeverCommitted after a ~2 s bufferuseGlobalCollection (first 100)History, logs, rankings
AssetBalances per playerForeverAtomic per call, persisted within ~5 suseAssetCurrencies, resources, consumables
Room stateOne document per roomThe last player leavesNever persisteduseRoomStateMatch phase, round timer
Room user stateOne document per player in a roomThe room endsNever persisteduseRoomMyStatePosition, HP, per-match score
Room collectionQueryable list per roomThe room endsNever persisteduseRoomCollectionPer-match events, room scoreboard

Anything a player must never lose — currency, items, rewards — goes in $asset or user state, never only in a collection or a room.

Start Building

Getting Started takes you from an empty Vite project to a tested server function, deployed and called from React.

These pages describe SDK 2.0. Moving an existing 1.x project across? Read Upgrading to 2.0 first.

Last updated on