![]() |
Cockatrice 2026-10-19-Development-3.1.2-beta.2
A virtual tabletop for multiplayer card games
|
#include <servatrice.h>
Public Types | |
| enum | AuthenticationMethod { AuthenticationNone , AuthenticationSql , AuthenticationPassword } |
| enum | AuthenticationStrictness { AuthenticationLegacy , AuthenticationMixed , AuthenticationStrict } |
Public Slots | |
| void | scheduleShutdown (const QString &reason, int minutes) |
| void | updateLoginMessage () |
| void | setRequiredFeatures (const QString &featureList) |
| void | onEmailDelivered (const QString &userName, EmailType type, const QString &token, qint64 rowId) |
| void | onEmailPermanentlyFailed (const QString &userName, EmailType type, FailureReason reason, const QString &token, qint64 rowId) |
Public Member Functions | |
| Servatrice (QObject *parent=nullptr) | |
| ~Servatrice () override | |
| bool | initServer () |
| QMap< QString, bool > | getServerRequiredFeatureList () const override |
| bool | requiresChallengeResponseAuth () const override |
| True when only challenge-response logins are accepted (strict mode). | |
| QByteArray | getLegacyBackupKey () const |
| Key sealing legacy password backups, or empty when they are disabled. | |
| int | getLegacyBackupTtlDays () const |
| Days a legacy password backup may go unused before it is purged. | |
| QString | getServerName () const |
| QString | getLoginMessage () const override |
| SessionEvent * | getLoginSessionEvent () const override |
| SessionEvent * | makeShutdownEvent () const |
| QString | getRequiredFeatures () const override |
| QString | getAuthenticationMethodString () const |
| QString | getDBTypeString () const |
| QString | getDbPrefix () const |
| QString | getEmailBlackList () const |
| QString | getEmailWhiteList () const |
| AuthenticationMethod | getAuthenticationMethod () const |
| AuthenticationStrictness | getAuthenticationStrictness () const |
| bool | permitUnregisteredUsers () const override |
| bool | getGameShouldPing () const override |
| bool | getClientIDRequiredEnabled () const override |
| bool | getRegOnlyServerEnabled () const override |
| bool | getMaxUserLimitEnabled () const override |
| bool | getStoreReplaysEnabled () const override |
| bool | getRegistrationEnabled () const |
| bool | getRequireEmailForRegistrationEnabled () const |
| bool | getRequireEmailActivationEnabled () const |
| bool | getEnableLogQuery () const override |
| bool | getEnableForgotPassword () const |
| bool | getEnableForgotPasswordChallenge () const |
| bool | getEnableAudit () const |
| bool | getEnableRegistrationAudit () const |
| bool | getEnableForgotPasswordAudit () const |
| int | getMinPasswordLength () const |
| int | getIdleClientTimeout () const override |
| int | getServerID () const override |
| int | getMaxGameInactivityTime () const override |
| int | getMaxPlayerInactivityTime () const override |
| int | getClientKeepAlive () const override |
| int | getDeckShareExpiryDays () const |
| int | getDeckShareCleanupInterval () const |
| int | getDeckShareMaxDecksPerShare () const |
| int | getDeckShareMaxSharesPerDay () const |
| int | getMaxUsersPerAddress () const |
| QString | getTrustedSources () const |
| Raw security/trusted_sources list; match addresses against it with isTrustedSource(). | |
| int | getMessageCountingInterval () const override |
| int | getMaxMessageCountPerInterval () const override |
| int | getMaxMessageSizePerInterval () const override |
| int | getMaxGamesPerUser () const override |
| int | getCommandCountingInterval () const override |
| int | getMaxCommandCountPerInterval () const override |
| int | getMaxUserTotal () const override |
| bool | permitCreateGameAsJudge () const override |
| int | getMaxTcpUserLimit () const |
| int | getMaxWebSocketUserLimit () const |
| int | getUsersWithAddress (const QHostAddress &address) const |
| int | getMaxAccountsPerEmail () const |
| int | getForgotPasswordTokenLife () const |
| QList< AbstractServerSocketInterface * > | getUsersWithAddressAsList (const QHostAddress &address) const |
| void | incTxBytes (quint64 num) |
| void | incRxBytes (quint64 num) |
| void | addDatabaseInterface (QThread *thread, Servatrice_DatabaseInterface *databaseInterface) |
| MetricsRegistry & | getMetricsRegistry () |
| qint64 | getCardsInGamesTotal () const |
| int | getMetricsSlowCommandMs () const |
| int | getMetricsStallWarnMs () const |
| Heartbeat overshoot that counts as a stall. A value of 0 disables the watchdogs. | |
| void | observeGameStartDurationMs (qint64 elapsedMs) override |
| qint64 | getEventLoopStallsTotal () const |
| qint64 | getEventLoopLastStallMs () const |
| qint64 | getEventLoopMaxStallMs () const |
| void | observeEventLoopStall (const QString &threadName, qint64 overshootMs) |
| Records one heartbeat overshoot and logs a single warning for it. | |
| void | watchWorkerThread (QThread *thread) |
| RateLimiter * | getRateLimiter () |
| bool | recordFailedLogin (const QString &ipAddress, const QString &userName) override |
| Record a failed login attempt for the (address, username) pair; returns true if now locked out. | |
| bool | isLoginRateLimited (const QString &ipAddress, const QString &userName) override |
| True if the (address, username) pair is already locked out of logging in. | |
| int | loginRateLimitRemainingSeconds (const QString &ipAddress, const QString &userName) override |
| Seconds remaining before the login rate limit for the (address, username) pair lifts. Returns 0 if not limited. | |
| void | clearFailedLogins (const QString &ipAddress, const QString &userName) override |
| Clear any failed-login lockout for the (address, username) pair, e.g. after a successful login. | |
| bool | recordRegistrationAttempt (const QString &ipAddress) |
| bool | recordForgotPasswordAttempt (const QString &ipAddress) |
| bool | isRateLimitExempt (const QString &ipAddress) const |
| True when the address is in security/trusted_sources and therefore exempt from per-address limits. | |
| int | getMaxLoginAttemptsPerIp () const |
| int | getLoginAttemptWindowSeconds () const |
| int | getMaxRegistrationsPerIp () const |
| int | getRegistrationWindowSeconds () const |
| int | getMaxForgotPasswordRequestsPerIp () const |
| int | getForgotPasswordWindowSeconds () const |
| bool | islConnectionExists (int _serverId) const |
| void | addIslInterface (int _serverId, IslInterface *interface) |
| void | removeIslInterface (int _serverId) |
| std::shared_ptr< const Response_ReportStats > | getCachedReportStats () const |
| void | cacheReportStats (const Response_ReportStats &stats) |
| QList< ServerProperties > | getServerList () const |
| Public Member Functions inherited from Server | |
| Server (QObject *parent=nullptr) | |
| ~Server () override=default | |
| AuthenticationResult | loginUser (Server_ProtocolHandler *session, QString &name, const QString &password, bool passwordNeedsHash, QString &reason, int &secondsLeft, QString &clientid, QString &clientVersion, QString &connectionType) |
| void | broadcastUserInfoUpdate (Server_ProtocolHandler *source) |
| const QMap< int, Server_Room * > & | getRooms () |
| Server_AbstractUserInterface * | findUser (const QString &userName) const |
| const QMap< QString, Server_ProtocolHandler * > & | getUsers () const |
| const QMap< qint64, Server_ProtocolHandler * > & | getUsersBySessionId () const |
| void | addClient (Server_ProtocolHandler *player) |
| void | removeClient (Server_ProtocolHandler *player) |
| QList< QString > | getOnlineModeratorList () const |
| Server_DatabaseInterface * | getDatabaseInterface () const |
| int | getNextLocalGameId () |
| void | sendIsl_Response (const Response &item, int serverId=-1, qint64 sessionId=-1) |
| void | sendIsl_SessionEvent (const SessionEvent &item, int serverId=-1, qint64 sessionId=-1) |
| void | sendIsl_GameEventContainer (const GameEventContainer &item, int serverId=-1, qint64 sessionId=-1) |
| void | sendIsl_RoomEvent (const RoomEvent &item, int serverId=-1, qint64 sessionId=-1) |
| void | sendIsl_GameCommand (const CommandContainer &item, int serverId, qint64 sessionId, int roomId, int playerId) |
| void | sendIsl_RoomCommand (const CommandContainer &item, int serverId, qint64 sessionId, int roomId) |
| const QMap< QString, Server_AbstractUserInterface * > & | getExternalUsers () const |
| void | addPersistentPlayer (const QString &userName, int roomId, int gameId, int playerId) |
| void | removePersistentPlayer (const QString &userName, int roomId, int gameId, int playerId) |
| QList< PlayerReference > | getPersistentPlayerReferences (const QString &userName) const |
| int | getUsersCount () const |
| int | getGamesCount () const |
| int | getTCPUserCount () const |
| int | getWebSocketUserCount () const |
Public Attributes | |
| QReadWriteLock | islLock |
| Public Attributes inherited from Server | |
| QReadWriteLock | clientsLock |
| QReadWriteLock | roomsLock |
Protected Member Functions | |
| void | doSendIslMessage (const IslMessage &msg, int _serverId) override |
| Protected Member Functions inherited from Server | |
| void | prepareDestroy () |
| void | setDatabaseInterface (Server_DatabaseInterface *_databaseInterface) |
| void | addRoom (Server_Room *newRoom) |
Private Types | |
| enum | DatabaseType { DatabaseNone , DatabaseMySql } |
Private Slots | |
| void | statusUpdate () |
| void | sweepLegacyBackups () |
| void | shutdownTimeout () |
| void | cleanupExpiredDeckShares () |
Private Member Functions | |
| bool | cleanupDatabaseForEmail (const QString &userName, EmailType type, const QString &token, qint64 rowId) |
| void | updateServerList () |
| QString | getDBPrefixString () const |
| QString | getDBHostNameString () const |
| QString | getDBDatabaseNameString () const |
| QString | getDBUserNameString () const |
| QString | getDBPasswordString () const |
| QString | getRoomsMethodString () const |
| QString | getISLNetworkSSLCertFile () const |
| QString | getISLNetworkSSLKeyFile () const |
| int | getServerStatusUpdateTime () const |
| int | getNumberOfTCPPools () const |
| int | getServerTCPPort () const |
| int | getNumberOfWebSocketPools () const |
| int | getServerWebSocketPort () const |
| int | getISLNetworkPort () const |
| bool | getISLNetworkEnabled () const |
| bool | getEnableInternalSMTPClient () const |
| QHostAddress | getServerTCPHost () const |
| QHostAddress | getServerWebSocketHost () const |
Static Private Attributes | |
| static constexpr int | reportStatsCacheTtlSeconds = 60 |
Additional Inherited Members | |
| Signals inherited from Server | |
| void | pingClockTimeout () |
| void | sigSendIslMessage (const IslMessage &message, int serverId) |
| void | endSession (qint64 sessionId) |
| Protected Slots inherited from Server | |
| void | externalUserJoined (const ServerInfo_User &userInfo) |
| void | externalUserLeft (const QString &userName) |
| void | externalRoomUserJoined (int roomId, const ServerInfo_User &userInfo) |
| void | externalRoomUserLeft (int roomId, const QString &userName) |
| void | externalRoomSay (int roomId, const QString &userName, const QString &message, const QString &channelId) |
| void | externalRoomRemoveMessages (int roomId, const QString &userName, int amount) |
| void | externalRoomGameListChanged (int roomId, const ServerInfo_Game &gameInfo) |
| void | externalJoinGameCommandReceived (const Command_JoinGame &cmd, int cmdId, int roomId, int serverId, qint64 sessionId) |
| void | externalGameCommandContainerReceived (const CommandContainer &cont, int playerId, int serverId, qint64 sessionId) |
| void | externalGameEventContainerReceived (const GameEventContainer &cont, qint64 sessionId) |
| void | externalResponseReceived (const Response &resp, qint64 sessionId) |
| Protected Attributes inherited from Server | |
| QList< Server_ProtocolHandler * > | clients |
| QMap< qint64, Server_ProtocolHandler * > | usersBySessionId |
| QMap< QString, Server_ProtocolHandler * > | users |
| QMap< qint64, Server_AbstractUserInterface * > | externalUsersBySessionId |
| QMap< QString, Server_AbstractUserInterface * > | externalUsers |
| QMap< int, Server_Room * > | rooms |
| QMap< QThread *, Server_DatabaseInterface * > | databaseInterfaces |
|
private |
|
explicit |
|
override |
| void Servatrice::addDatabaseInterface | ( | QThread * | thread, |
| Servatrice_DatabaseInterface * | databaseInterface ) |
| void Servatrice::addIslInterface | ( | int | _serverId, |
| IslInterface * | interface ) |
| void Servatrice::cacheReportStats | ( | const Response_ReportStats & | stats | ) |
|
private |
|
privateslot |
|
overridevirtual |
Clear any failed-login lockout for the (address, username) pair, e.g. after a successful login.
Reimplemented from Server.
|
overrideprotectedvirtual |
Reimplemented from Server.
|
inline |
| QString Servatrice::getAuthenticationMethodString | ( | ) | const |
| Servatrice::AuthenticationStrictness Servatrice::getAuthenticationStrictness | ( | ) | const |
| std::shared_ptr< const Response_ReportStats > Servatrice::getCachedReportStats | ( | ) | const |
| qint64 Servatrice::getCardsInGamesTotal | ( | ) | const |
Sums cards across all zones of all running games. Each game takes its own gameMutex – the hot per-game lock every game action contends on – and then iterates every player's zones, so the scrape cost is really O(total cards in play) plus one mutex acquisition per live game. Keep scrapes infrequent in big multiplayer rooms.
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
Reimplemented from Server.
|
private |
|
private |
|
private |
|
inline |
|
private |
| QString Servatrice::getDBTypeString | ( | ) | const |
|
private |
| int Servatrice::getDeckShareCleanupInterval | ( | ) | const |
| int Servatrice::getDeckShareExpiryDays | ( | ) | const |
| int Servatrice::getDeckShareMaxDecksPerShare | ( | ) | const |
| int Servatrice::getDeckShareMaxSharesPerDay | ( | ) | const |
| QString Servatrice::getEmailBlackList | ( | ) | const |
| QString Servatrice::getEmailWhiteList | ( | ) | const |
| bool Servatrice::getEnableAudit | ( | ) | const |
| bool Servatrice::getEnableForgotPassword | ( | ) | const |
| bool Servatrice::getEnableForgotPasswordAudit | ( | ) | const |
| bool Servatrice::getEnableForgotPasswordChallenge | ( | ) | const |
|
private |
|
overridevirtual |
| bool Servatrice::getEnableRegistrationAudit | ( | ) | const |
|
inline |
|
inline |
|
inline |
| int Servatrice::getForgotPasswordTokenLife | ( | ) | const |
| int Servatrice::getForgotPasswordWindowSeconds | ( | ) | const |
|
inlineoverridevirtual |
Reimplemented from Server.
|
overridevirtual |
|
private |
|
private |
|
private |
|
private |
| QByteArray Servatrice::getLegacyBackupKey | ( | ) | const |
Key sealing legacy password backups, or empty when they are disabled.
| int Servatrice::getLegacyBackupTtlDays | ( | ) | const |
Days a legacy password backup may go unused before it is purged.
| int Servatrice::getLoginAttemptWindowSeconds | ( | ) | const |
|
inlineoverridevirtual |
Reimplemented from Server.
|
overridevirtual |
| int Servatrice::getMaxAccountsPerEmail | ( | ) | const |
|
overridevirtual |
Reimplemented from Server.
| int Servatrice::getMaxForgotPasswordRequestsPerIp | ( | ) | const |
|
overridevirtual |
Reimplemented from Server.
|
overridevirtual |
Reimplemented from Server.
| int Servatrice::getMaxLoginAttemptsPerIp | ( | ) | const |
|
overridevirtual |
Reimplemented from Server.
|
overridevirtual |
Reimplemented from Server.
|
overridevirtual |
Reimplemented from Server.
| int Servatrice::getMaxRegistrationsPerIp | ( | ) | const |
| int Servatrice::getMaxTcpUserLimit | ( | ) | const |
|
overridevirtual |
| int Servatrice::getMaxUsersPerAddress | ( | ) | const |
|
overridevirtual |
| int Servatrice::getMaxWebSocketUserLimit | ( | ) | const |
|
overridevirtual |
Reimplemented from Server.
|
inline |
|
inline |
|
inline |
Heartbeat overshoot that counts as a stall. A value of 0 disables the watchdogs.
| int Servatrice::getMinPasswordLength | ( | ) | const |
|
private |
|
private |
|
inline |
| bool Servatrice::getRegistrationEnabled | ( | ) | const |
| int Servatrice::getRegistrationWindowSeconds | ( | ) | const |
|
overridevirtual |
|
overridevirtual |
| bool Servatrice::getRequireEmailActivationEnabled | ( | ) | const |
| bool Servatrice::getRequireEmailForRegistrationEnabled | ( | ) | const |
|
private |
|
overridevirtual |
| QList< ServerProperties > Servatrice::getServerList | ( | ) | const |
| QString Servatrice::getServerName | ( | ) | const |
|
inlineoverridevirtual |
Reimplemented from Server.
|
private |
|
private |
|
private |
|
private |
|
private |
|
overridevirtual |
| QString Servatrice::getTrustedSources | ( | ) | const |
Raw security/trusted_sources list; match addresses against it with isTrustedSource().
| int Servatrice::getUsersWithAddress | ( | const QHostAddress & | address | ) | const |
| QList< AbstractServerSocketInterface * > Servatrice::getUsersWithAddressAsList | ( | const QHostAddress & | address | ) | const |
| void Servatrice::incRxBytes | ( | quint64 | num | ) |
| void Servatrice::incTxBytes | ( | quint64 | num | ) |
| bool Servatrice::initServer | ( | ) |
| bool Servatrice::islConnectionExists | ( | int | _serverId | ) | const |
|
overridevirtual |
True if the (address, username) pair is already locked out of logging in.
Consulted before any authentication work (database round trip, password verification) so a blocked pair cannot burn server CPU per attempt.
Reimplemented from Server.
| bool Servatrice::isRateLimitExempt | ( | const QString & | ipAddress | ) | const |
True when the address is in security/trusted_sources and therefore exempt from per-address limits.
|
overridevirtual |
Seconds remaining before the login rate limit for the (address, username) pair lifts. Returns 0 if not limited.
Reimplemented from Server.
| SessionEvent * Servatrice::makeShutdownEvent | ( | ) | const |
| void Servatrice::observeEventLoopStall | ( | const QString & | threadName, |
| qint64 | overshootMs ) |
Records one heartbeat overshoot and logs a single warning for it.
|
overridevirtual |
Called once per actual game start with how long bringing every player's zones online took, so servers can spot deck sizes that wedge threads.
Reimplemented from Server.
|
slot |
|
slot |
|
overridevirtual |
Reimplemented from Server.
|
inlineoverridevirtual |
Reimplemented from Server.
|
overridevirtual |
Record a failed login attempt for the (address, username) pair; returns true if now locked out.
Keyed by pair so a successful login as one user cannot wipe out another user's failure history from the same address (e.g. a guest login or the attacker's own account clearing the way for further guessing).
Reimplemented from Server.
| bool Servatrice::recordForgotPasswordAttempt | ( | const QString & | ipAddress | ) |
| bool Servatrice::recordRegistrationAttempt | ( | const QString & | ipAddress | ) |
| void Servatrice::removeIslInterface | ( | int | _serverId | ) |
|
inlineoverridevirtual |
True when only challenge-response logins are accepted (strict mode).
Reimplemented from Server.
|
slot |
|
slot |
|
privateslot |
|
privateslot |
|
privateslot |
|
slot |
|
private |
| void Servatrice::watchWorkerThread | ( | QThread * | thread | ) |
Installs an EventLoopWatchdog in thread. Called once per socket pool thread right after it starts.
|
private |
|
private |
|
private |
|
private |
|
private |
overshoot of the most recent stall
|
private |
worst overshoot seen since process start
|
private |
heartbeat overshoots past the warn threshold
|
private |
|
private |
| QReadWriteLock Servatrice::islLock |
|
private |
|
private |
|
private |
|
mutableprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticconstexprprivate |
|
mutableprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
mutableprivate |
|
private |
|
private |
|
private |
|
mutableprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |