[Refactor] Clarify the restriction checks in Server_Game::checkJoin (#7876)

This commit is contained in:
AI-scor 2026-11-10 16:21:50 +01:00 • committed by GitHub
parent c1549ed7f5
commit 9dc6483f1c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -641,30 +641,42 @@ Response::ResponseCode Server_Game::checkJoin(ServerInfo_User *user,
} }
} }
// join_as_judge grants referee tools, so it requires the judge flag itself; the staff
// override below deliberately does not grant it.
if (roleInfo.isJudge && !(user->user_level() & ServerInfo_User::IsJudge)) { if (roleInfo.isJudge && !(user->user_level() & ServerInfo_User::IsJudge)) {
return Response::RespUserLevelTooLow; return Response::RespUserLevelTooLow;
} }
if (!(overrideRestrictions && (user->user_level() & (ServerInfo_User::IsModerator | ServerInfo_User::IsJudge)))) {
if ((_password != password) && !(roleInfo.isSpectator && !spectatorsNeedPassword)) { // Moderators and judges may skip the game's entry restrictions, but only when the
// request opts in. Seat limits below are never overridden.
const bool isStaff = user->user_level() & (ServerInfo_User::IsModerator | ServerInfo_User::IsJudge);
const bool staffOverridesRestrictions = overrideRestrictions && isStaff;
if (!staffOverridesRestrictions) {
const bool passwordNotRequired = roleInfo.isSpectator && !spectatorsNeedPassword;
if (_password != password && !passwordNotRequired) {
return Response::RespWrongPassword; return Response::RespWrongPassword;
} }
if (!(user->user_level() & ServerInfo_User::IsRegistered) && onlyRegistered) {
const bool isRegistered = user->user_level() & ServerInfo_User::IsRegistered;
if (onlyRegistered && !isRegistered) {
return Response::RespUserLevelTooLow; return Response::RespUserLevelTooLow;
} }
if (onlyBuddies && (user->name() != creatorInfo->name())) {
if (!databaseInterface->isInBuddyList(QString::fromStdString(creatorInfo->name()), const bool isCreator = user->name() == creatorInfo->name();
QString::fromStdString(user->name()))) { if (onlyBuddies && !isCreator &&
return Response::RespOnlyBuddies; !databaseInterface->isInBuddyList(QString::fromStdString(creatorInfo->name()),
} QString::fromStdString(user->name()))) {
return Response::RespOnlyBuddies;
} }
if (databaseInterface->isInIgnoreList(QString::fromStdString(creatorInfo->name()), if (databaseInterface->isInIgnoreList(QString::fromStdString(creatorInfo->name()),
QString::fromStdString(user->name()))) { QString::fromStdString(user->name()))) {
return Response::RespInIgnoreList; return Response::RespInIgnoreList;
} }
if (roleInfo.isSpectator) {
if (!spectatorsAllowed) { if (roleInfo.isSpectator && !spectatorsAllowed) {
return Response::RespSpectatorsNotAllowed; return Response::RespSpectatorsNotAllowed;
}
} }
} }
if (!roleInfo.isSpectator && (gameStarted || (getPlayerCount() >= getMaxPlayers()))) { if (!roleInfo.isSpectator && (gameStarted || (getPlayerCount() >= getMaxPlayers()))) {