mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-10 12:03:25 -08:00
[Refactor] Clarify the restriction checks in Server_Game::checkJoin (#7876)
This commit is contained in:
parent
c1549ed7f5
commit
9dc6483f1c
1 changed files with 24 additions and 12 deletions
|
|
@ -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()))) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue