|
| | Scoreboard (std::filesystem::path file) |
| | Reads the board of a file.
|
| |
| bool | record (std::string_view name, std::uint32_t score) |
| | Adds a score, if it is among the best.
|
| |
| const std::vector< ScoreEntry > & | best () const noexcept |
| | The best scores.
|
| |
| const std::optional< std::string > & | load_error () const noexcept |
| | Why the file could not be read at start.
|
| |
| const std::filesystem::path & | file () const noexcept |
| | Where the board is kept.
|
| |
The max_entries best scores, best first, kept in a JSON file.
The file is {"scores": [{"name": "R9", "score": 1200}, ...]}. It is read once by the constructor: a missing file is an empty board; a file that cannot be read or is not a board (bad JSON, a field of the wrong type, a bad name) is reported by load_error() and logged, and the board starts empty, which never stops the server. Each record() that changes the board writes it at once, through a temporary file that then replaces the old one (core::Config::save()), so a crash never leaves half a file; a write that fails is logged and the board goes on in memory. Not thread-safe.