10#include <unordered_map>
22 _router(std::make_unique<
CommandRouter>(policy, translations))
24 _router->Attach(&host);
36 InstallConsoleCommand(*added);
44 _consoleCommands.clear();
61 std::vector<std::string> tokens;
62 tokens.reserve(
static_cast<size_t>(args.ArgC()));
63 for (
int i = 1; i < args.ArgC(); ++i)
65 tokens.emplace_back(args.Arg(i));
70 if (Player* player = _players.Get(slot))
73 [
this, slot](
const std::string& line) { ReplyToPlayer(slot, line); });
84 [](
const std::string& line) {
Log::Info(
"{}", line); });
88 _consoleCommands.try_emplace(name, name, help, std::move(run), playersCanRun);
91void CommandManager::ReplyToPlayer(
int slot,
const std::string& line)
95 _policy.Reply(slot, line);
99 _messages.Send(slot, line);
128 const std::span<const std::string> tokens{parts.begin() + 1, parts.end()};
129 const int slot = caller->
Slot();
130 _router->Dispatch(*def, caller, tokens,
Origin::Chat, *_binder,
131 [
this, slot](
const std::string& line) { ReplyToPlayer(slot, line); });
145 return !parts.empty() && _router->IsForeign(parts.front());
150 return _router->Count();
How a chat line is spelled: the prefix, and splitting one into tokens.
Fluent command registration, returned by CommandManager::Add.
CommandManager(Policy &policy, Translations &translations, PlayerManager &players, EntitySystem &entities, Messages &messages, IPluginContext &host)
bool HandleChatMessage(Player *caller, std::string_view message)
CommandBuilder Add(std::string_view name)
bool IsForeign(std::string_view message) const
The registered commands, their usage lines, and the dispatch that runs one.
runtime.Entities: finds and creates entities. Everything it returns is valid for this frame only; see...
Send chat, center print, center HTML, and alert messages.
The roster: every connected player, and the signals for the connection lifecycle.
One connected player, owned by PlayerManager for the length of the connection.
int Slot() const noexcept
The one permission and targeting gate, plus the plugin's reply callback.
std::function< void(const CCommand &args, int slot)> Handler
static std::string ToLower(std::string_view str)
Localization system. Loads one JSON file per language; nested objects flatten into dotted keys (categ...
std::optional< std::string_view > StripPrefix(std::string_view message)
std::vector< std::string > Tokenize(std::string_view text)
void Info(std::format_string< Args... > fmt, Args &&... args)
One command as the builder assembled it.