Public: anyone can read this; the crew can change it.
forked from trevato/cs
A member of a room is the engine's: the socket, the clock and the four sentences stop being the shooter's #370
Check · Review · Land · Live done — Landed and live in production.
Closes #334: the page's side of a room moves into the engine as `createMember` in `src/engine/member.ts`. The page's side is the socket and its open, errored and closed states, how long since the last snapshot arrived, the tick counter, the reused input buffer, and the rule for which of four sentences the page shows. `src/client/session.ts` now keeps only what belongs to Counter-Strike, and #319's…
shipped production is serving it deploy ae07c2d
Sign in to join this conversation.
new above
offline
Closes #334: the page's side of a room moves into the engine as
createMemberinsrc/engine/member.ts. The page's side is the socket and its open, errored and closed states, how long since the last snapshot arrived, the tick counter, the reused input buffer, and the rule for which of four sentences the page shows.src/client/session.tsnow keeps only what belongs to Counter-Strike, and #319'ssession.test.tspasses without a single change.readText,readSnapshotandwriteInput. Next to the codec it passeshear(message, world) → world, which is what a text message does to its world (ahellobuilds one; the rest keep the one they had). It can also passlanded(got, world). The engine never namesWorld,Hello,applySnapshotorSNAPSHOT_FRAME. WhatapplySnapshotreturns about your own body goes tolandedunchanged, and the shooter writes it ontomethere, so the split #316's prediction relies on is kept.SentencesandbehindMshave no default, for the same reason the hub's caps have none. The docstring says so, andmember.test.tschecks the rule with a fake game's words, including that exactlybehindMsstill counts as playing and one millisecond more is behind.member.test.tsplays a whole room of a counter game made of plain objects: a hello, names, snapshots (asUint8Arrayand asArrayBuffer), input, and a drop. It tests every existing refusal separately:- a text frame that doesn't parse - a binary frame whose first byte isn't the snapshot kind - a frame before
hello, or while the game has no world - a snapshot the codec refuses, which also leaves the clock where it was - data of any other type -presswhile the socket isn't open, which isn't counted as a tickindex.tsexportscreateMember,Member,MemberCodec,MemberOptions,MemberSocketandSentences.surface.jsonmoves to 0.10.0 because names were added.GUIDE.mdhas a### membersection afterrooms, with its measured weight (0.9 kB raw, 0.6 kB gzipped).session.tsstill exportsSocket, now as an alias ofMemberSocket, along withStanding,Session, the sentences andBEHIND_MS.main.tsneeded no change.Two small refusals are new; neither is reachable with a real browser socket. The member ignores anything the socket delivers after it closed, and an
openevent after a close doesn't make it live again.session.test.tspasses either way, andmember.test.tstests both, because its fake socket keeps delivering after a close.Not done: #316 (prediction) and interpolation are left alone, and I didn't write a second codec for the example game (#326).
To try it: run
bun run test(typecheck and 1494 tests, all passing), then join a room in the preview. The connection line should read "Joining the room…", then "In the room", and should say the connection is behind if snapshots stop arriving for more than half a second.🤖 Generated with Claude Code
Closes #334