QtCraft API C++ classes QML types Handbook

QcAccessList Class

Who may join a world and who is an operator (decision E-244): operators, banned names and the whitelist, kept in access.json in the world directory and written at once with every change. More...

Header: #include <server/login/QcAccessList.h>

Public Types

struct Ban
struct Entry
enum class List { Operators, Bans, Whitelist }

Public Functions

QcResult<bool> addBan(const QcAccessList::Ban &ban)
const QcAccessList::Ban *ban(const QString &name) const
QList<QcAccessList::Ban> bans() const
QcResult<bool> bind(const QString &name, const QString &fingerprint)
const QString &damagedCopy() const
bool isFullFor(QcAccessList::List list, const QString &name) const
bool isOperator(const QString &name, const QString &fingerprint) const
bool isWhitelisted(const QString &name, const QString &fingerprint) const
QStringList open(const QString &directory, const QStringList &initialOperators)
QStringList operators() const
std::optional<QcMsg::Disconnect> refusal(const QString &name, const QString &fingerprint, bool local) const
QcResult<bool> removeBan(const QString &name)
QcResult<bool> setOperator(const QString &name, bool isOperator, const QString &fingerprint = {})
QcResult<bool> setWhitelistEnabled(bool enabled)
QcResult<bool> setWhitelisted(const QString &name, bool listed, const QString &fingerprint = {})
bool wasDamaged() const
QStringList whitelist() const
bool whitelistEnabled() const

Static Public Members

const QStringView fileName
const int formatVersion
QString key(const QString &name)
const qsizetype maxEntries
const qint64 maxFileBytes
const qsizetype maxReasonLength

Detailed Description

Names are cleaned like player names (QcProfileValidation) and compared without case. Entries are bound to the fingerprint of a player's identity (decision E-253): an entry with a fingerprint counts only for that identity, a ban with one also under other names; an entry without one counts by name and takes the fingerprint of the first player of that name who logs in. A damaged file is copied aside and the world opens with empty lists but a switched-on whitelist, so nobody banned slips in until an operator has looked at it; when no copy could be made, nothing is written over the damaged file. Without a world directory the lists live in memory only.

Member Type Documentation

enum class QcAccessList::List

The three lists.

ConstantValueDescription
QcAccessList::List::Operators0The operators.
QcAccessList::List::Bans1The banned names.
QcAccessList::List::Whitelist2The names on the whitelist.

Member Function Documentation

QcResult<bool> QcAccessList::addBan(const QcAccessList::Ban &ban)

Bans the name of ban, or gives a banned name the new reason. Returns whether the list changed (false also when the list is full, isFullFor()); an error when it changed but could not be written.

const QcAccessList::Ban *QcAccessList::ban(const QString &name) const

Returns the ban of name; nullptr when it is not banned by name.

QList<QcAccessList::Ban> QcAccessList::bans() const

Returns every ban.

QcResult<bool> QcAccessList::bind(const QString &name, const QString &fingerprint)

The player name logged in with the identity fingerprint: entries of his name without a fingerprint get it. Returns whether a list changed; an error when it could not be written.

const QString &QcAccessList::damagedCopy() const

Returns the copy of the damaged file (empty when none could be made, then changes are not written).

bool QcAccessList::isFullFor(QcAccessList::List list, const QString &name) const

Returns whether adding name to list would go beyond maxEntries (a listed name always fits).

bool QcAccessList::isOperator(const QString &name, const QString &fingerprint) const

Returns whether name with the identity fingerprint is an operator. Operators of the server configuration count for the identity of their first login, which bind() keeps in the file (configOperators), and by name until then.

bool QcAccessList::isWhitelisted(const QString &name, const QString &fingerprint) const

Returns whether name with the identity fingerprint is on the whitelist.

[static] QString QcAccessList::key(const QString &name)

Returns the comparison key of name: cleaned and case-folded.

QStringList QcAccessList::open(const QString &directory, const QStringList &initialOperators)

Reads access.json in directory (an empty directory keeps the lists in memory). Never fails: the problems are the warnings it returns. initialOperators (server configuration) are operators too; invalid names among them are left out with a warning. Runs once, on a fresh list, when the server starts (QcServer).

QStringList QcAccessList::operators() const

Returns the names of the operators.

std::optional<QcMsg::Disconnect> QcAccessList::refusal(const QString &name, const QString &fingerprint, bool local) const

Returns why the player name with the identity fingerprint may not join: banned by name or fingerprint (operators too), or not on the switched-on whitelist (operators pass it); the local player (local) always may. The reason is a translatable disconnect (QcChatText); std::nullopt when he may.

QcResult<bool> QcAccessList::removeBan(const QString &name)

Lifts the ban of name. Returns whether the list changed; an error when it changed but could not be written.

QcResult<bool> QcAccessList::setOperator(const QString &name, bool isOperator, const QString &fingerprint = {})

Makes name an operator or no longer one (isOperator); a known fingerprint binds the entry to that identity. Returns whether the list changed; an error when it changed but could not be written.

See also isOperator().

QcResult<bool> QcAccessList::setWhitelistEnabled(bool enabled)

Switches the whitelist on or off (enabled). Returns whether that changed; an error when it changed but could not be written.

See also whitelistEnabled().

QcResult<bool> QcAccessList::setWhitelisted(const QString &name, bool listed, const QString &fingerprint = {})

Puts name on the whitelist or takes it off (listed); a known fingerprint binds the entry to that identity. Returns whether the list changed; an error when it changed but could not be written.

See also isWhitelisted().

bool QcAccessList::wasDamaged() const

Returns whether the file was damaged when the world opened.

QStringList QcAccessList::whitelist() const

Returns the names on the whitelist.

bool QcAccessList::whitelistEnabled() const

Returns whether the whitelist is switched on.

See also setWhitelistEnabled().

Member Variable Documentation

const QStringView QcAccessList::fileName

The name of the file in the world directory.

const int QcAccessList::formatVersion

Format 2 has the fingerprints; files of other formats count as damaged (decision E-356: no migration before the first release).

const qsizetype QcAccessList::maxEntries

Per list; further entries of a file are left out with a warning.

const qint64 QcAccessList::maxFileBytes

The largest file read (a larger one counts as damaged).

const qsizetype QcAccessList::maxReasonLength

The longest reason and banning name kept for a ban.