VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
VoltMod::CommandBuilder Class Reference

Fluent command registration, returned by CommandManager::Add. More...

#include <CommandBuilder.hpp>

Public Types

using Installer = std::function<void(CommandDefinition)>

Public Member Functions

 CommandBuilder (Installer install, std::string_view name)
CommandBuilder & Alias (std::string_view alias)
CommandBuilder & Describe (std::string_view text)
CommandBuilder & Permission (std::string_view permission)
CommandBuilder & PlayersOnly ()
CommandBuilder & PlayersAndServer ()
CommandBuilder & ServerOnly ()
CommandBuilder & UsageKey (std::string_view key)
template<class F>
void Run (F &&handler)

Detailed Description

Fluent command registration, returned by CommandManager::Add.

commands.Add("ban")
.Describe("Ban a player.")
.Alias("b")
.Permission("admin.ban")
std::string name = t->Name(); // capture first: a ban drops the target
std::string reason = why.ValueOr(c.Translations.Get("reason.bannedByAdmin"));
if (!app.Ban(*c.Player, *t.Value, reason, d.Value))
return c.Fail("cmd.banFailed");
return c.Ok("cmd.banSuccess", {{"name", name}});
});
std::string Name() const
Definition Player.cpp:22
std::string Get(std::string_view key) const
std::chrono::seconds Value
Definition Args.hpp:86
decltype(U::Value) ValueOr(decltype(U::Value) fallback) const
Definition Args.hpp:147
Who invoked the command, and how to answer them.
Result< Reply > Ok(std::string_view key, Tokens tokens={}) const
VoltMod::Translations & Translations
Result< Reply > Fail(std::string_view key, Tokens tokens={}) const
VoltMod::Player * Player

Run installs the command. The manager owns it for the plugin load cycle.

Definition at line 193 of file CommandBuilder.hpp.

Member Typedef Documentation

◆ Installer

How Run hands the finished definition back to the manager that made this builder.

Definition at line 197 of file CommandBuilder.hpp.

Constructor & Destructor Documentation

◆ CommandBuilder()

VoltMod::CommandBuilder::CommandBuilder ( Installer install,
std::string_view name )
inline

Member Function Documentation

◆ Alias()

CommandBuilder & VoltMod::CommandBuilder::Alias ( std::string_view alias)
inline

Another name for the same command. Collisions are refused and logged at registration.

Definition at line 205 of file CommandBuilder.hpp.

References CommandBuilder().

◆ Describe()

CommandBuilder & VoltMod::CommandBuilder::Describe ( std::string_view text)
inline

Operator-facing description; also the console command's help text.

Definition at line 212 of file CommandBuilder.hpp.

References CommandBuilder().

◆ Permission()

CommandBuilder & VoltMod::CommandBuilder::Permission ( std::string_view permission)
inline

Gate on Policy::Authorize, which denies while no plugin publishes IPermissions.

Definition at line 219 of file CommandBuilder.hpp.

References CommandBuilder().

◆ PlayersAndServer()

CommandBuilder & VoltMod::CommandBuilder::PlayersAndServer ( )
inline

Also register a tier1 ConCommand, so players can type it in their console and the server can run it from its console, rcon, cfg files and ExecuteServerCommand.

Definition at line 235 of file CommandBuilder.hpp.

References CommandBuilder(), and VoltMod::PlayersAndServer.

◆ PlayersOnly()

CommandBuilder & VoltMod::CommandBuilder::PlayersOnly ( )
inline

Also register a tier1 ConCommand that only players can run, so they can type it in their console or bind it to a key. The server console, rcon and cfg files are refused.

Definition at line 227 of file CommandBuilder.hpp.

References CommandBuilder(), and VoltMod::Players.

◆ Run()

template<class F>
void VoltMod::CommandBuilder::Run ( F && handler)
inline

Install the command. The handler takes a Caller and one Args:: value per argument; that list defines arity, parsing, and usage. A handler that returns nothing succeeds silently.

The command is unregistered when CommandManager is destroyed.

Definition at line 263 of file CommandBuilder.hpp.

◆ ServerOnly()

CommandBuilder & VoltMod::CommandBuilder::ServerOnly ( )
inline

Register only the ConCommand, for an operator command players cannot run.

Definition at line 242 of file CommandBuilder.hpp.

References CommandBuilder(), and VoltMod::ServerOnly.

◆ UsageKey()

CommandBuilder & VoltMod::CommandBuilder::UsageKey ( std::string_view key)
inline

Translation key for the whole usage line, replacing the one derived from the argument types.

Definition at line 250 of file CommandBuilder.hpp.

References CommandBuilder(), and UsageKey().

Referenced by UsageKey().


The documentation for this class was generated from the following file: