Skip to main content

Module play

Module play 

Source
Expand description

Playing a game: moves, resignations, draws, takebacks, aborts, claims, the end of a game (ratings, notifications) and the sweeper that flags clocks and lapses challenges.

Every action locks the game row (FOR UPDATE) in a transaction, works out the new state with chess-core, writes it and notifies in the same transaction. Postgres is the only clock (clock_timestamp()), so any replica can take any request and they all agree on time used.

Enums§

Api
Board API (people) or Bot API (bot accounts).

Functions§

abort
absent_secs
Seconds since player last had a stream open on this game (since the game started, if never).
claim_draw
claim_in
Seconds until the opponent may claim the win (None: player isn’t gone).
claim_victory
draw
finish
End a game: status and winner, ratings for a rated game, fair-play queueing, and the gameFinish events. row must be locked.
make_move
resign
start_game
Start the game for an accepted challenge (same id as the challenge).
sweep
One pass of the sweeper: lapsed challenges, flags and first moves that never came. Safe on every replica at once (rows are locked with SKIP LOCKED and conditions rechecked under the lock).
takeback
touch
Record that player has a stream open on a game.