The IP addresses that cannot log in, kept in a JSON file.
More...
#include </__w/project-rtype/project-rtype/server/include/rtype/ban_list.hpp>
|
| | BanList (std::filesystem::path file) |
| | Reads the bans of a file.
|
| |
| bool | ban (const aegis2d::net::Endpoint &address) |
| | Bans an address, its port ignored.
|
| |
| bool | banned (const aegis2d::net::Endpoint &address) const |
| | Tells whether an address is banned, whatever its port.
|
| |
| const std::vector< aegis2d::net::Endpoint > & | addresses () const noexcept |
| | The banned addresses, port 0.
|
| |
| const std::optional< std::string > & | load_error () const noexcept |
| | Why the file could not be read at start.
|
| |
The IP addresses that cannot log in, kept in a JSON file.
The file is {"bans": ["203.0.113.7", "::1"]}. It is read once by the constructor: a missing file is an empty list; a file that cannot be read or is not a list of addresses is reported by load_error() and logged, and the list starts empty, which never stops the server. Each ban is written at once, through a temporary file that then replaces the old one (core::Config::save()); a write that fails is logged and the ban holds until the server stops. Not thread-safe.
◆ BanList()
| rtype::BanList::BanList |
( |
std::filesystem::path |
file | ) |
|
|
explicit |
Reads the bans of a file.
- Parameters
-
| file | Where the bans are kept; created at the first ban. |
◆ addresses()
| const std::vector< aegis2d::net::Endpoint > & rtype::BanList::addresses |
( |
| ) |
const |
|
noexcept |
The banned addresses, port 0.
- Returns
- In the order they were banned.
◆ ban()
| bool rtype::BanList::ban |
( |
const aegis2d::net::Endpoint & |
address | ) |
|
Bans an address, its port ignored.
- Parameters
-
| address | Address of a client. |
- Returns
false if it was banned already: nothing changed.
◆ banned()
| bool rtype::BanList::banned |
( |
const aegis2d::net::Endpoint & |
address | ) |
const |
Tells whether an address is banned, whatever its port.
- Parameters
-
| address | Address of a client. |
- Returns
true if it may not log in.
◆ load_error()
| const std::optional< std::string > & rtype::BanList::load_error |
( |
| ) |
const |
|
noexcept |
Why the file could not be read at start.
- Returns
- The reason, or
std::nullopt if it was read or missing.
The documentation for this class was generated from the following file:
- /__w/project-rtype/project-rtype/server/include/rtype/ban_list.hpp