Full-stack multiplayer Blackjack — raw WebSocket server, real-time game state, betting economy, and a persistent SQLite leaderboard tied to cookie-based player identities.
Architecture
asyncio.start_server handles concurrent connections; _ws_decode_frames manually parses the length-prefixed binary frame format including masking, while _ws_encode handles server→client framing.GameRoom instance manages a state machine across five phases: waiting → betting → playing → dealer_turn → finished. Turn sequencing uses await _advance_turn() with cooperative yielding — the dealer draw loop uses await asyncio.sleep() between cards to pace reveals without blocking other connections.create/join message. The server maps this UUID to a players table in leaderboard.db, tracking total_wins, total_losses, and best_balance using MAX(best_balance, ?) so high scores are preserved across sessions.math.floor(bet * 1.5), push returns the stake, bust/lose deducts the bet. For split hands, the bet is divided equally between both sub-hands. Balances persist to the DB at game end.All-Time Rankings
Players ranked by peak balance — the W/L record shown is from the session when that high score was first achieved. Your identity is tied to a cookie so your best score persists across sessions without an account.
Live Demo