VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
TargetResolver.cpp
Go to the documentation of this file.
3
6
7namespace VoltMod
8{
9
10std::expected<std::vector<Player*>, TargetFailure> EngineArgBinder::Resolve(std::string_view token, Player* caller,
11 const TargetRules& rules)
12{
13 if (token.empty())
14 {
15 return std::unexpected(TargetFailure{TargetError::NoMatch});
16 }
17
18 std::vector<PlayerView> candidates;
19 candidates.reserve(_players.All().size());
20 for (Player* player : _players.All())
21 {
22 const Pawn pawn = _entities.Pawn(player->Slot());
23 candidates.push_back({
24 .Slot = player->Slot(),
25 .SteamId = player->SteamId(),
26 .Name = player->Name(),
27 .Team = pawn.TeamNum(),
28 .Alive = pawn.IsAlive(),
29 .Bot = player->IsBot(),
30 // The command permission was already checked; this only asks whether the target may be acted on.
31 .Targetable = !caller || _policy.Authorize(caller->Ref(), player->Ref(), {}).has_value(),
32 });
33 }
34
35 const int callerSlot = caller ? caller->Slot() : -1;
37 if (!slots)
38 {
39 return std::unexpected(slots.error());
40 }
41
42 std::vector<Player*> targets;
43 targets.reserve(slots->size());
44 for (int slot : *slots)
45 {
46 if (Player* player = _players.Get(slot))
47 {
48 targets.push_back(player);
49 }
50 }
51 return targets;
52}
53
54} // namespace VoltMod
std::expected< std::vector< Player * >, TargetFailure > Resolve(std::string_view token, Player *caller, const TargetRules &rules) override
VoltMod::Pawn Pawn(int slot)
A player's body: health, armor, movement, aim, weapons. The engine replaces it on every spawn; the Co...
Definition Pawn.hpp:19
int Slot() const
Definition Pawn.cpp:218
Player * Get(int slot)
std::span< Player *const > All() const
One connected player, owned by PlayerManager for the length of the connection.
Definition Player.hpp:23
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.
Definition Policy.cpp:52
std::size_t RandomIndex(std::size_t count)
Definition Random.cpp:7
TargetQuery ParseTargetToken(std::string_view token)
Definition Targeting.cpp:11
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
std::expected< std::vector< int >, TargetFailure > FilterPlayers(std::span< const PlayerView > players, const TargetQuery &query, const TargetRules &rules, int callerSlot, const std::function< std::size_t(std::size_t)> &randomIndex)