press5 Play protocol, version 2
Version 2 adds server rooms: rooms run by one of press5's engines (see "Server rooms" below). Everything in version 1 still works unchanged; send "v": 2 in hello to say you understand version 2 frames.
Connect a WebSocket to wss://play.press5.xyz/v1. Every text frame is one JSON object with a type t. A client frame may carry rid (a short string or number); the reply to it carries the same rid. Errors are {"t":"error","rid":..,"code":"...","message":"..."}. Close codes: 4001 game not allowed, 4002 no hello in 10 s, 4003 game full, 4008 rate limit, 4010 resumed elsewhere, 1012 server restart (reconnect and resume), 1009 frame too big.
Hello (first frame)
{"t":"hello","v":1,"name":"Ada","key":"p5g_...","resume":"<token>","sdk":"mylib/1.0"}
- In a browser, the page's address (https://<name>.on.press5.xyz) picks the game;
keyis for native builds. resume: the token from the lastjoinedframe, to take your seat back after a disconnect.- Reply: `{"t":"welcome","v":1,"id":"<player id>","name":"Ada","game":{"id","kind","title","maxPlayers","modes","tickRate"}, "serverTime":<ms>,"limits":{...},"resumed":true|false}
. After a successful resume ajoined` frame follows.
Lobby frames
{"t":"quick","mode"?,"maxPlayers"?,"filters"?,"meta"?}- join the fullest matching open room or make one.{"t":"create","private"?,"mode"?,"maxPlayers"?,"filters"?,"meta"?,"state"?}{"t":"join","code":"KXQRTW"}{"t":"list","mode"?,"filters"?}- reply{"t":"rooms","rooms":[{"code","mode","players","maxPlayers","meta","filters","locked","private","createdAt"}]}{"t":"name","name":"..."}- reply{"t":"ok","name":"..."}{"t":"ping","c":<anything>}- reply{"t":"pong","c":..,"s":<server ms>}
Joining replies {"t":"joined","you":"<id>","resume":"<token>","room":{"code","mode","private","locked","maxPlayers", "filters","meta","host","state","players":{"<id>":{"id","name","seat","state","away","joinedAt"}},"tickRate","createdAt"}}. Joining another room leaves the current one.
Room frames (client)
{"t":"set","me":{...},"room":{...}}- merge into your player state and (host only) the room state.nulldeletes a key.{"t":"send","data":<json>,"to"?:"<id>"|["<id>",...]}{"t":"leave"}- reply{"t":"left","reason":"left"}- Host only:
{"t":"lock","locked":true|false},{"t":"kick","id":".."},{"t":"host","id":".."},{"t":"meta","meta":{...}} - With a
rid,set/send/host frames are acknowledged with{"t":"ok"}; without one only errors are sent.
Room frames (server)
{"t":"patch","ts":<server ms>,"room"?:{key:value|null},"players"?:{"<id>":{key:value|null}}}- once a tick at most.{"t":"msg","from":"<id>","data":<json>}{"t":"player_join","player":{...}},{"t":"player_leave","id","reason"}(left, kicked, timeout),{"t":"player_away","id"},{"t":"player_back","id"},{"t":"player_name","id","name"}{"t":"host","id"},{"t":"room","locked","meta"},{"t":"left","code","reason"}(you were kicked){"t":"server_restart","reconnectMs":1000}- reconnect after that long and hello withresume.
Frames that change who is in the room, who is host, or messages are sent after any pending patch, so order is kept.
Binary frames
Client to server: byte 0 is the target seat (255 = everyone else), the rest is yours. The server replaces byte 0 with the sender's seat and forwards it. Counted against the same rate limits.
Server rooms (version 2)
A game whose press5.game.json has a "server" block gets one of press5's engines in every room. No game code runs on press5: the engine is press5's, the game only chooses it and sets it up. The joined frame then carries room.engine: {"name","version","tickRate","patchEvery","config"} (the full, checked settings, so a client can draw walls and predict movement). Relay set is refused (engine_room); send (chat) still works.
Client frames:
{"t":"input","s":<int>,"i":{...}}: one input a tick.scounts up from 1 and never repeats.ihas up to 16 fields of numbers, booleans or short strings; what they mean depends on the engine (arena below). The engine uses one input a tick and repeats the last one when none came, so sending faster gains nothing. No reply.{"t":"act","rid":..,"type":"<name>","data":..}: an engine action (turns:move; party:answer...). Replied withok(maybe"reply") orerror.
Server frames:
{"t":"state","s":<seq>,"a":<last input s applied>,"ts":<server ms>,"full":{...}}on joining (and when resent), then{"t":"state","s","a","ts","d":{...}}deltaspatchEveryticks apart. Withoutdnothing changed.{"t":"event","e":"<type>","d":{...}}: things that happen (arena: shot, gone, hit, ko, spawn, pickup, round).{"t":"left","reason":"room_error"|"room_over_budget"|"game_blocked"}when the room has to stop.
Deltas
d turns the previous snapshot into the new one, key by key: a key that is missing is unchanged; null means the key was removed; an object means "apply this inside"; anything else (a number, string, boolean or array) replaces the old value. Snapshots never contain null themselves.
apply(prev, d): for key, v in d:
if v is null: delete prev[key]
elif v is an object: prev[key] = apply(prev[key] or {}, v)
else: prev[key] = v
arena v1
- Input
i:mx,my(move, -1..1 each),jump(bool),ax,ay(aim direction, any length),fire(true= weapon 0, or a weapon number),v(the server time your screen was showing when the player fired: serverTime minus the interpolation delay; the server rewinds hitscan targets to it, at most 200 ms). - Snapshot:
{"ph":"play"|"end","n":<round>,"rt":<ms left, -1 = no limit>,"p":{<id>:[x,y,vx,vy,ax,ay,hp,dead,team,ground]},"k":{<pickup id>:[x,y,kind]},"sc":{<id>:score},"ts":[team scores]}. Withworld.viewRadiusset, only what is near you; withworld.lineOfSight, only players no wall hides (teammates always). A player who goes out of view is removed fromp(anullin the delta): stop drawing them. Withworld.decoys, a player Guard has flagged may also get made-up entries near the edge of the view radius: draw only what is on screen and the game looks the same. - Events:
shot {id,o,w,x,y,vx,vy,ms}(a projectile: fly it yourself forms) orshot {o,w,x,y,ax,ay,len,hit}(hitscan: a ray),gone {id}(a shot ended early),hit {t,by,dmg,hp},ko {t,by},spawn {id,team},pickup {p,k},round {phase,n,ranking,winner|team,teams}. With a view radius or line of sight, events go only to players who could see them: a projectileshotarrives when the shot first comes into your view (x,yare where it is now,mswhat it has left), so the same shot id may be new to you long after it was fired. - Prediction: run the movement core (
play/engines/arena/sim.js, ported exactly in every SDK and pinned byplay/engines/arena/vectors.json) on your own inputs attickRate. On each state, take your entry inpas the truth for inputa, then replay your inputs aftera. Draw everything else about 100 ms in the past, interpolating between snapshots.
turns v1
- Actions:
move(data for the rule pack:{x},{x,y},{from:[x,y],to:[x,y]},{play:"7h"},{draw:true},{pass:true}),resign,rematch. A move out of turn or against the rules gets an error naming why. - Snapshot: `{"ph":"wait"|"play"|"end","rules","seats":[ids],"turn","you":<your seat, -1 watching>,"deadline", "moves","result":{"winner"|"draw","why"},"rematch":[ids],"watching","game":{...the rule pack's view...}}`. In the card table only your own hand is in
game.hand; others are counts. - Events:
start,move {by,seat,data},timeout {seat},rematch {want},over {winner|draw,why}.
party v1
- Actions:
startandagain(the host),answer {choice}. - Snapshot: `{"ph":"lobby"|"question"|"reveal"|"end","mode","n","of","until","answered","players","sc":{id:score}, "q","choices","mine"}
, plus"answer","gained","counts"only during the reveal.room.engine.config.questions` is just how many there are. - Events:
question {n},reveal {n,answer,gained},over {ranking}. "mode": "guess"(typed answers):answer {text}replies{right, close?}(several tries,maxGuesses);guessed {id,name}when someone gets it; the snapshot'smineis{right,tries}andanswer(after the reveal) is the first accepted text."mode": "draw"(drawing and guessing): actionschoose {word},draw {s:[[x,y],...],c,w,new}(x, y from 0 to 1, up to 64 points),undo,clear(the drawer) andanswer {text}(everyone else). Snapshot `{"ph":"lobby"|"choose"|"draw"|"reveal"|"end","n","of","drawer","choices"(drawer, choosing),"word"(drawer, then all at the reveal),"hint","guessed","mine","until","sc","gained"}. Events:turn {drawer,n,of},drawing {drawer,hint,len},stroke {s,c,w,new}(not to the drawer),undo,clear,canvas {strokes}` (to a player joining mid-turn),guess {id,name,text}(wrong guesses),guessed {id,name},hint {hint},reveal {n,word,drawer,gained,why},over {ranking}.room.engine.config.wordsis just how many there are.
Leaderboards
hello may carry "guest":"g1...." (the token from an earlier welcome); welcome always has "guest", which a client keeps on the device. Results of server rooms with at least two players lasting 30 s go on the game's leaderboard: GET /v1/games/{name}/leaderboard?period=all|week|day. There is no way for a client to write one. The same two players' results against each other count in full ten times a day, then half as much each time.
Datagrams: UDP and WebTransport (version 2)
For fast games, state and inputs can also travel as unreliable datagrams. Everything else stays on the WebSocket, which is always open and is the fallback.
welcomecarries"udp":{"host","port","session":<u32>,"key":"<base64, 32 bytes>"}and, for browsers,"wt":{"url"}(WebTransport datagrams in the same format).- Layout (big-endian): byte 0 type (1 bind, 2 input, 3 state, 4 ping, 5 pong, 6 challenge, 7 confirm); bytes 1-4 session; 5-8 seq (each side counts its own); 9-12 ack (client: the last state
sit has; server: the last inputsapplied); then a payload (JSON, or raw bytes for confirm); then 8 bytes: the first 8 bytes of HMAC-SHA256(key, everything before them). - Bind: the client sends type 1 (empty payload) once a second until a state datagram arrives, and again if its address may have changed.
- Address check: a datagram from an address the server hasn't confirmed for this session gets only a challenge (type 6, 21 bytes): its seq and ack fields (bytes 5-12) are an 8-byte cookie. The client answers with confirm (type 7) whose payload is exactly those 8 bytes. Only then do pongs and state go to that address. Inputs from an unconfirmed address still count; nothing else is answered there. The server never answers a datagram whose tag does not check out, and never sends an unconfirmed address more bytes than it got from it, so it can't be used to flood someone else.
- Input (type 2):
{"i":[[s,{...}],...]}: the latest input plus the two before it, since packets get lost. - State (type 3):
{"s","b","ts","d"}or{"s","ts","full"}.dis against snapshotb, which the client has acknowledged. A client that does not havebkeeps acking what it has, and the server sendsfull. - While datagrams flow, the server stops sending state frames on the WebSocket; after 3 s without a valid datagram it goes back to the WebSocket. A snapshot that would not fit in 1200 bytes goes over the WebSocket that tick.