7Status Policy::CheckPermission(
const Player& caller, std::string_view permission)
const
9 if (permission.empty())
18 if (!_missingPermissionWarned)
20 _missingPermissionWarned =
true;
22 "Denying '{}': no HasPermission policy is installed. "
23 "Set Runtime::Policy.HasPermission in Load.",
37Status Policy::CheckImmunity(
const Player& caller, int64_t targetSteamId)
const
39 if (targetSteamId == caller.SteamId() || !
CanTarget)
44 if (!
CanTarget(caller.SteamId(), targetSteamId))
53 std::string_view permission)
const
55 Player* callerPlayer = _players.Get(caller);
61 Player* targetPlayer =
nullptr;
64 targetPlayer = _players.Get(*target);
71 if (
auto allowed = CheckPermission(*callerPlayer, permission); !allowed)
73 return std::unexpected(allowed.error());
78 if (
auto allowed = CheckImmunity(*callerPlayer, targetPlayer->
SteamId()); !allowed)
80 return std::unexpected(allowed.error());
84 return Authorized{.Caller = *callerPlayer, .Target = targetPlayer};
89 Player* callerPlayer = _players.Get(caller);
95 if (
auto allowed = CheckPermission(*callerPlayer, permission); !allowed)
97 return std::unexpected(allowed.error());
100 return CheckImmunity(*callerPlayer, targetSteamId);
One connected player, owned by PlayerManager for the length of the connection.
int64_t SteamId() const noexcept
Status AuthorizeSteamId(PlayerRef caller, int64_t targetSteamId, std::string_view permission) const
Authorize for a target that may be offline, addressed by SteamID.
std::function< bool(int64_t steamId, std::string_view permission)> HasPermission
std::function< bool(int64_t callerSteamId, int64_t targetSteamId)> CanTarget
Result< Authorized > Authorize(PlayerRef caller, std::optional< PlayerRef > target, std::string_view permission) const
The single gate. Commands, target resolution and menu rows call exactly this.
void Error(std::format_string< Args... > fmt, Args &&... args)
std::expected< void, Error > Status
@ NotFound
The named thing does not exist (no such player, convar, row).
std::expected< T, Error > Result
A caller/target pair that cleared Policy::Authorize.
One failure: a code to branch on, text for the log, and an optional translation key.
static Error Denied(std::string key)
static Error Immune(std::string key)
static Error NotFound(std::string detail)
A storable reference to a player: the slot plus the SteamID that occupied it.