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

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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ CommandRouter()

VoltMod::CommandRouter::CommandRouter ( const Policy &  policy,
Translations &  translations 
)
inline

Definition at line 39 of file CommandRouter.hpp.

Member Function Documentation

◆ Add()

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.

Returns
the stored definition, or null when the name or the registration was refused (already logged). Valid until Clear.

Definition at line 42 of file CommandRouter.cpp.

References VoltMod::Log::Error(), VoltMod::ReadFile(), VoltMod::IPluginContext::RegisterCommand(), and VoltMod::Strings::ToLower().

◆ Attach()

void VoltMod::CommandRouter::Attach ( IPluginContext *  host)
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.

◆ Clear()

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.

◆ Count()

size_t VoltMod::CommandRouter::Count ( ) const
inline

Definition at line 61 of file CommandRouter.hpp.

◆ Dispatch()

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().

◆ Find()

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().

◆ 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().

◆ Usage()

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().


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