VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
CommandNames.cpp
Go to the documentation of this file.
2
3#include <algorithm>
4
5namespace VoltMod
6{
7
8bool CommandNames::Register(OwnerId owner, std::string_view ownerName, std::string_view name)
9{
10 if (name.empty())
11 {
12 return false;
13 }
14
15 const auto found = std::ranges::find(_entries, name, &Entry::Name);
16 if (found != _entries.end())
17 {
18 return found->Owner == owner;
19 }
20
21 _entries.push_back({.Name = std::string(name), .Owner = owner, .OwnerName = std::string(ownerName)});
22 return true;
23}
24
25void CommandNames::Reserve(std::string_view name)
26{
27 if (!name.empty() && std::ranges::find(_entries, name, &Entry::Name) == _entries.end())
28 {
29 _entries.push_back({.Name = std::string(name), .Owner = nullptr, .OwnerName = "the host"});
30 }
31}
32
33std::string_view CommandNames::OwnerOf(std::string_view name) const
34{
35 const auto found = std::ranges::find(_entries, name, &Entry::Name);
36 return found != _entries.end() ? std::string_view(found->OwnerName) : std::string_view();
37}
38
40{
41 std::erase_if(_entries, [owner](const Entry& entry) { return entry.Owner == owner; });
42}
43
44} // namespace VoltMod
void RemoveAll(OwnerId owner)
bool Register(OwnerId owner, std::string_view ownerName, std::string_view name)
void Reserve(std::string_view name)
std::string_view OwnerOf(std::string_view name) const
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56