Add chess games over channel data
Play and watch chess on a channel via the Chess games entry in the channel overflow menu. Moves travel as GRP_DATA packets (type 0x0100) carrying the full position and a hash-chain value for authentication. Includes translations for all locales.
This commit is contained in:
1 parent
9ac915bdf2
commit
185b026a0d
66 files changed
+15314
-25
No files matched your search
@@ -34,6 +34,7 @@ MeshCore Open is an open-source Flutter client for MeshCore LoRa mesh networking
|
||||
21. [UI Design Reference](design.md) - Contributor reference: theme, typography, spacing, shared widgets, sheets vs dialogs vs pages, states, and localization rules for UI changes
|
||||
22. [Offline Mode](offline-mode.md) - Read-only view of the last radio's contacts, channels and messages while no radio is connected, and the Connect sheet
|
||||
23. [Performance Profiling](performance-profiling.md) - Contributor reference: frame and memory baselines, HTTP capture retention, and resetting diagnostic recordings
|
||||
24. [Chess](games.md) - Play and watch chess games on a channel: invites, challenges, time per move, and how moves are sent and checked
|
||||
|
||||
## App Overview
|
||||
|
||||
@@ -49,6 +50,7 @@ MeshCore Open connects to MeshCore LoRa mesh radios over BLE, USB, or TCP. Once
|
||||
- **Configure radio settings** including frequency, power, bandwidth, and spreading factor
|
||||
- **Cache offline maps** for use without internet connectivity
|
||||
- **Analyze line-of-sight** between nodes with terrain elevation profiles
|
||||
- **Play chess** on a channel, or watch other people's games
|
||||
- **Filter spam** in channels with your own rules and automatic on-device checks
|
||||
- **Use Android Auto** to hear new messages and reply by voice while driving (Android)
|
||||
|
||||
|
||||
@@ -282,3 +282,5 @@ Reactions use `r:<four-hex message hash>:<two-hex emoji index>`. Channel replies
|
||||
Transport-routed raw packets include four transport-code bytes before packed path metadata. For transport floods, the app matches the first two code bytes against locally known region candidates using HMAC-SHA256 over `[payloadType][payload]`. Region scope keys are the first 16 bytes of SHA256 of `#<region>`. The radio's default flood scope is also a candidate, matched on the key the radio reports (it may have been set by another client). The name itself is not carried as plain text. Unknown or ambiguous matches remain null; see [regions](regions.md).
|
||||
|
||||
Image chunks use `CMD_SEND_CHANNEL_DATA` (62), `RESP_CODE_CHANNEL_DATA_RECV` (27), and application data type `0xAE1C`. The framing, capacities, metadata byte, and XOR recovery algorithm are defined in [image_chunk_transport.dart](../lib/services/image_chunk_transport.dart), which is the source of truth. See [image messages](image-messages.md) for user requirements and limitations.
|
||||
|
||||
Chess games use the same command and response with data type `0x0100`, which is registered to MeshCore Open in the firmware's `docs/number_allocations.md`. The high nibble of the first payload byte names the app feature (`1` = chess v1), so other games can share the data type. The packet layouts are in [chess_packets.dart](../lib/games/chess/chess_packets.dart) and [games](games.md#how-moves-are-sent).
|
||||
@@ -191,6 +191,17 @@ One model is one row inside the existing `MeshCard` (or `SettingsReveal`), rows
|
||||
|
||||
A dialog that offers several missing models (backup restore) uses the same rows for name, size, status and progress, and keeps its own confirm button.
|
||||
|
||||
### Chess board
|
||||
|
||||
`ChessBoardView` (`lib/games/chess/ui/chess_board.dart`) is board content, not chrome, so its squares keep the same classic colours in every theme (`ChessBoardPalette`). Both have strong contrast with the white and black piece vectors (`chess_vectors_flutter`).
|
||||
|
||||
- Last move: both squares get a translucent yellow wash. Check: a red radial glow behind the king. Selected piece: a 3px `primary` border.
|
||||
- Legal targets: a dark dot on an empty square and a dark ring around a capturable piece, so they differ in shape and not only colour.
|
||||
- Rank and file labels sit in the corners of the edge squares, in the opposite square colour, at 12–14px.
|
||||
- The board fills the width (up to 560) and the page scrolls, so it fits a 320dp phone at 2.0× text.
|
||||
|
||||
The channel's games list is a `showMeshSheet` with a `DraggableScrollableSheet`, the same layout as the Add channel sheet. Starting a game closes it and opens a second sheet, so sheets are never stacked.
|
||||
|
||||
## 6. Sheets, dialogs and pages
|
||||
|
||||
What the code does:
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
# Chess
|
||||
|
||||
Play chess with someone on a channel, or watch other people's games. Moves go over the mesh as small channel data packets, so games suit a slow network: each move can take its time, and anyone on the channel can follow along.
|
||||
|
||||
## Requirements
|
||||
|
||||
- Companion firmware v1.15 or newer, on every radio that plays or watches. Older firmware can't send or receive channel data, and the games sheet says so.
|
||||
- Everyone involved must be on the same channel (same key). Other MeshCore apps don't show the games, and the moves never appear as chat messages.
|
||||
|
||||
## Start a game
|
||||
|
||||
Open a channel, tap **⋮**, then **Chess games**. The menu shows how many games and invites are open on that channel.
|
||||
|
||||
- **Challenge someone**: pick a person recently heard on this channel. Only they can accept. Their phone shows a notification.
|
||||
- **Post an open invite**: anyone on the channel can accept. If two people accept at the same time, the inviter's phone picks the first one it heard and tells everyone; the other person keeps watching.
|
||||
|
||||
Choose the **time per move** (no limit, 15 minutes, 1 hour (default), 6 hours, 1 day or 3 days) and **your colour** (random, white or black). Unanswered invites expire after a day. Tap your own invite to cancel it.
|
||||
|
||||
## Play
|
||||
|
||||
The board turns so that your pieces are at the bottom. Tap one of your pieces, then one of the marked squares. A promotion asks which piece you want.
|
||||
|
||||
- **Offer draw** / **Accept draw**. Making a move instead declines an offer.
|
||||
- **Resign** asks first.
|
||||
- **Claim win on time** appears when your opponent has gone more than 10 minutes past the time per move. Your phone times it from when it sent your last move; the 10 minutes allow for slow delivery.
|
||||
- **Ask for update** asks the players to send the latest move again. Use it when a game looks stuck. A player answers within a few seconds, at most once a minute per game.
|
||||
|
||||
Checkmate, stalemate, not enough pieces to mate, the 50-move rule and repetition end the game on their own.
|
||||
|
||||
You get a notification when you're challenged, when it's your move, and when a game ends, unless the channel is muted. Notifications open the channel.
|
||||
|
||||
## Watch
|
||||
|
||||
Every game on the channel shows up under **Live games**. If you joined late, the board appears with the next move, because each move carries the whole position. Moves from before you joined show as "(missed)". Until you've heard how the game started, the players are marked as not confirmed; **Ask for update** fetches that.
|
||||
|
||||
Finished games stay in the list for a week. Tap **✕** to remove one sooner.
|
||||
|
||||
## How moves are sent
|
||||
|
||||
Each packet starts with a 4-byte header: app and packet kind, a random 2-byte game ID, and the half-move number. Kinds are invite, accept, decline, move, resign, draw offer, draw accept, cancel, timeout claim, game info and request.
|
||||
|
||||
A move is 49 bytes or less, which fills four 16-byte encrypted blocks on air:
|
||||
|
||||
| Field | Bytes |
|
||||
|---|---|
|
||||
| Header | 4 |
|
||||
| Minutes since the game started | 2 |
|
||||
| Move, as its index in the sorted list of legal moves | 1 |
|
||||
| Chain value (see below) | 16 |
|
||||
| Position after the move | ≤26 |
|
||||
|
||||
The position is an 8-byte map of occupied squares, 2 bytes for side to move, castling, en passant and the 50-move counter, then half a byte per piece.
|
||||
|
||||
**Checking who moved.** Each player's phone makes a secret value and hashes it 512 times. Only the last hash is sent, in the invite or accept. Each later action reveals the hash one step back, which anyone can check with a single hash but nobody else can produce. A packet with a value that doesn't fit the player's chain is ignored. If two different packets arrive with the same value, the first one heard counts. Player names are not checked; the chain is.
|
||||
|
||||
Players also check that the move gives the position in the packet. Spectators who missed moves take the position as it is.
|
||||
|
||||
Your secret values stay on your phone, stored per radio with the rest of the game.
|
||||
Reference in new issue
Block a user