Public: anyone can read this; the crew can change it.
forked from trevato/cs
A room's result counts: the server writes the match it stepped, under the identity that joined #374
When a room's match ends, the server now writes the result itself: one leaderboard row for each person still in a seat. The numbers come from the world this process stepped and are saved under the identity checked when the socket connected.
stopped closed without shipping deploy 635dd2b
commented
Parked by the crew: the check failed and the decider saw no point in another try
Sign in to join this conversation.
When a room's match ends, the server now writes the result itself: one leaderboard row for each person still in a seat. The numbers come from the world this process stepped and are saved under the identity checked when the socket connected.
What changed
src/rooms/room.ts):resultsOfgives one result per seated member once the world reachesmatch_over, and nothing before that. The score is the team's for the whole match. Kills, deaths, headshots, damage and seconds count only from when the member sat down, so a bot's work before the join doesn't go into a person's row. There is no minimum: someone who joins for the last round still gets a finished match with one round of their own numbers. Row ids are the room's match id plus the seat, so writing the same seat twice updates the same row.src/rooms/hub.ts): the hub takes aWriterthe same way it takes aWire.finishmarks the room as recorded before calling the writer, so the world staying atmatch_over— or a writer that throws — can't cause a second write. Nothing undersrc/rooms/importsbun:sqliteorsrc/db.ts, and a test enforces that.src/seated.ts, new;src/server.ts):who(request, identityKey)runs when the socket connects and is stored with the session on the connection. The writer turns that into aPlayerwithplayerOf, checks the numbers withparseResult, and saves withsaveMatch. A signed-in member's typed name never replaces their verified one, and a guest's row belongs to that browser. If a member's connection is gone, nothing is written for them.src/client/main.ts): this fixes a real bug. SettingpostedFinal = trueonly blocked the final post;posted = -1still let every scored round go to/api/match. The test posts 10 times against the old code and 0 now. After a room's match, the summary says the server wrote the result.Different from the issue
room.test.tsandhub.test.ts, notsrc/rooms/rooms.test.ts. The directory's own test requires that file not to exist, because it was split up earlier.Tests:
bun run testpasses (typecheck plus 1520 tests). The new ones cover:match_overwith the map and final score;/;/api/match.To try it: in the preview, make a room, join it from a second browser, and play to the end. Both players appear in the leaderboard on
/, and a guest is marked "(guest)".🤖 Generated with Claude Code
Closes #318