|
VoltMod
C++23 framework for CS2 server plugins
|
The registered commands, their usage lines, and the dispatch that runs one. More...
#include <CommandRouter.hpp>
Public Member Functions | |
| CommandRouter (const Policy &policy, Translations &translations) | |
| void | Attach (IPluginContext *host) |
| const CommandDefinition * | Add (CommandDefinition def) |
| void | Clear () |
| const CommandDefinition * | Find (std::string_view name) const |
| bool | IsForeign (std::string_view name) const |
| size_t | Count () const |
| std::string | Usage (const CommandDefinition &def, int slot, Origin origin) const |
| void | Dispatch (const CommandDefinition &def, Player *caller, std::span< const std::string > tokens, Origin origin, ArgBinder &binder, const std::function< void(const std::string &)> &say) const |
The registered commands, their usage lines, and the dispatch that runs one.
Engine-free by construction: it holds a Policy and a Translations, both of which are plain logic, and reaches the server only through the ArgBinder handed to Dispatch. Chat syntax lives in CommandSyntax and argument binding in BindArgs; neither needs the registry, so neither is here.
Definition at line 36 of file CommandRouter.hpp.
|
inline |
Definition at line 39 of file CommandRouter.hpp.
| const CommandDefinition * VoltMod::CommandRouter::Add | ( | CommandDefinition | def | ) |
Register def under its lowercased name plus its aliases. With a host attached, each of those names is registered there first, so two plugins cannot answer the same command.
Definition at line 42 of file CommandRouter.cpp.
References VoltMod::Log::Error(), VoltMod::ReadFile(), VoltMod::IPluginContext::RegisterCommand(), and VoltMod::Strings::ToLower().
|
inline |
Attach to host, which owns the process-wide command names. Null leaves registration as it is without a host: names are the plugin's own business.
Definition at line 43 of file CommandRouter.hpp.
| void VoltMod::CommandRouter::Clear | ( | ) |
Drop every registration. The router is emptied as a whole or not at all: a command lives exactly as long as the manager that owns it.
Definition at line 96 of file CommandRouter.cpp.
|
inline |
Definition at line 61 of file CommandRouter.hpp.
| void VoltMod::CommandRouter::Dispatch | ( | const CommandDefinition & | def, |
| Player * | caller, | ||
| std::span< const std::string > | tokens, | ||
| Origin | origin, | ||
| ArgBinder & | binder, | ||
| const std::function< void(const std::string &)> & | say | ||
| ) | const |
Authorize, bind and run def, sending every line to say.
caller is null for Origin::Console, which is the server itself: no permission is checked and caller-relative selectors match nobody.
Definition at line 174 of file CommandRouter.cpp.
References VoltMod::Policy::Authorize(), VoltMod::BindArgs(), VoltMod::FailureLine(), VoltMod::Translations::Get(), VoltMod::Caller::Player, VoltMod::ReadFile(), VoltMod::Player::Slot(), and Usage().
| const CommandDefinition * VoltMod::CommandRouter::Find | ( | std::string_view | name | ) | const |
Look name up as a command name, then as an alias.
Definition at line 102 of file CommandRouter.cpp.
References VoltMod::ReadFile(), and VoltMod::Strings::ToLower().
Referenced by IsForeign().
| bool VoltMod::CommandRouter::IsForeign | ( | std::string_view | name | ) | const |
True when name is not this router's but the host has it registered for someone else.
Definition at line 122 of file CommandRouter.cpp.
References Find(), VoltMod::IPluginContext::IsCommandRegistered(), and VoltMod::Strings::ToLower().
| std::string VoltMod::CommandRouter::Usage | ( | const CommandDefinition & | def, |
| int | slot, | ||
| Origin | origin | ||
| ) | const |
The usage line for def, in slot's language.
Definition at line 165 of file CommandRouter.cpp.
References VoltMod::Translations::Get(), and VoltMod::ReadFile().
Referenced by Dispatch().