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

Who invoked the command, and how to answer them. More...

#include <CommandBuilder.hpp>

Public Member Functions

bool IsServer () const
 
std::string Text (std::string_view key, Tokens tokens={}) const
 
Result< Reply > Ok (std::string_view key, Tokens tokens={}) const
 
Result< Reply > Fail (std::string_view key, Tokens tokens={}) const
 
void Say (std::string_view key, Tokens tokens={}) const
 
void SayRaw (std::string_view line) const
 

Public Attributes

VoltMod::Player * Player = nullptr
 
int Slot = -1
 
VoltMod::Translations & Translations
 
std::function< void(const std::string &)> Send
 

Detailed Description

Who invoked the command, and how to answer them.

A handler's first parameter. Player is null and Slot is -1 for console commands; reply helpers use the caller's language.

Definition at line 39 of file CommandBuilder.hpp.

Member Function Documentation

◆ Fail()

Result< Reply > VoltMod::Caller::Fail ( std::string_view  key,
Tokens  tokens = {} 
) const

Fail, replying with key localized for this caller.

The error keeps key in Key and the localized line in Text. Errors from other services carry only a key and are localized by dispatch.

Definition at line 18 of file CommandBuilder.cpp.

References VoltMod::Error::Code, VoltMod::Failed, VoltMod::ReadFile(), and VoltMod::Text.

◆ IsServer()

bool VoltMod::Caller::IsServer ( ) const
inline

True when the server ran the command: the server console, rcon or a cfg file.

Definition at line 51 of file CommandBuilder.hpp.

◆ Ok()

Result< Reply > VoltMod::Caller::Ok ( std::string_view  key,
Tokens  tokens = {} 
) const

Succeed, replying with key localized for this caller.

Definition at line 13 of file CommandBuilder.cpp.

References VoltMod::ReadFile(), and VoltMod::Text.

◆ Say()

void VoltMod::Caller::Say ( std::string_view  key,
Tokens  tokens = {} 
) const

Send one extra localized line; finish a multi-line reply with Ok or Reply::Silent.

Definition at line 25 of file CommandBuilder.cpp.

References VoltMod::ReadFile(), SayRaw(), and VoltMod::Text.

◆ SayRaw()

void VoltMod::Caller::SayRaw ( std::string_view  line) const

Send line verbatim: an already-formatted row that has no translation of its own.

Definition at line 30 of file CommandBuilder.cpp.

References VoltMod::ReadFile(), and Send.

Referenced by Say().

◆ Text()

std::string VoltMod::Caller::Text ( std::string_view  key,
Tokens  tokens = {} 
) const

Return localized key with {token} substitution.

Definition at line 8 of file CommandBuilder.cpp.

References VoltMod::Translations::Get(), VoltMod::ReadFile(), and Slot.

Member Data Documentation

◆ Player

VoltMod::Player* VoltMod::Caller::Player = nullptr

The player who typed the command, or null for console commands.

Definition at line 42 of file CommandBuilder.hpp.

Referenced by VoltMod::CommandRouter::Dispatch().

◆ Send

std::function<void(const std::string&)> VoltMod::Caller::Send

Sends a reply to chat or the console for the duration of the handler call.

Definition at line 48 of file CommandBuilder.hpp.

Referenced by SayRaw().

◆ Slot

int VoltMod::Caller::Slot = -1

Player's slot, or -1 for the console - which is also the server-language slot.

Definition at line 44 of file CommandBuilder.hpp.

Referenced by Text().

◆ Translations

VoltMod::Translations& VoltMod::Caller::Translations

The plugin's translations. Get(key) with no slot resolves the server language.

Definition at line 46 of file CommandBuilder.hpp.


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