18#ifndef TRINITY_CHATCOMMAND_H
19#define TRINITY_CHATCOMMAND_H
48 struct ChatCommandBuilder;
58 template <
typename Tuple,
size_t offset>
61 template <
typename Tuple,
typename NextType,
size_t offset>
68 return ConsumeFromOffset<Tuple, offset + 1>(tuple, handler, *next);
74 template <
typename Tuple,
typename NestedNextType,
size_t offset>
80 auto& myArg = std::get<offset>(tuple);
85 if ((result1 = ConsumeFromOffset<Tuple, offset + 1>(tuple, handler, *result1)))
89 ChatCommandResult result2 = ConsumeFromOffset<Tuple, offset + 1>(tuple, handler, args);
105 template <
typename Tuple,
size_t offset>
108 if constexpr (offset < std::tuple_size_v<Tuple>)
109 return MultiConsumer<Tuple, std::tuple_element_t<offset, Tuple>, offset>::TryConsumeTo(tuple, handler, args);
110 else if (!args.empty())
116 template <
typename T>
struct HandlerToTuple {
static_assert(Trinity::dependant_false_v<T>,
"Invalid command handler signature"); };
123 template <
typename TypedHandler>
131 std::get<0>(arguments) = chatHandler;
132 ChatCommandResult result = ConsumeFromOffset<Tuple, 1>(arguments, chatHandler, argsStr);
134 return std::apply(
reinterpret_cast<TypedHandler*
>(handler), std::move(arguments));
142 _handler =
reinterpret_cast<void*
>(handler);
150 std::string argsStrCopy(argsStr);
151 return reinterpret_cast<bool(*)(
ChatHandler*,
char const*)
>(handler)(chatHandler, argsStrCopy.c_str());
153 _handler =
reinterpret_cast<void*
>(handler);
156 explicit operator bool()
const {
return (
_wrapper !=
nullptr); }
192 static std::map<std::string_view, ChatCommandNode, StringCompareLessI_T>
const&
GetTopLevelMap();
208 std::variant<std::monostate, TrinityStrings, std::string>
_help;
209 std::map<std::string_view, ChatCommandNode, StringCompareLessI_T>
_subCommands;
220 template <
typename T>
231 using SubCommandEntry = std::reference_wrapper<std::vector<ChatCommandBuilder>
const>;
236 template <
typename TypedHandler>
241 template <
typename TypedHandler>
249 [[deprecated(
"char const* parameters to command handlers are deprecated; convert this to a typed argument handler instead")]]
254 template <
typename TypedHandler>
255 [[deprecated(
"you are using the old-style command format; convert this to the new format ({ name, handler (not a pointer!), permission, Console::(Yes/No) })")]]
260 [[deprecated(
"you are using the old-style command format; convert this to the new format ({ name, subCommands })")]]
267 std::variant<InvokerEntry, SubCommandEntry>
_data;
#define ASSERT_NOTNULL(pointer)
std::optional< T > Optional
Optional helper class to wrap optional values within.
Role Based Access Control related classes definition.
void SendCommandHelp(ChatHandler &handler) const
std::map< std::string_view, ChatCommandNode, StringCompareLessI_T > _subCommands
std::variant< std::monostate, TrinityStrings, std::string > _help
ChatCommandNode(ChatCommandNode &&other)=default
static void LoadCommandMap()
bool HasVisibleSubCommands(ChatHandler const &who) const
static void SendCommandHelpFor(ChatHandler &handler, std::string_view cmd)
static void InvalidateCommandMap()
void LoadFromBuilder(ChatCommandBuilder const &builder)
Trinity::ChatCommands::ChatCommandBuilder ChatCommandBuilder
static std::map< std::string_view, ChatCommandNode, StringCompareLessI_T > const & GetTopLevelMap()
static void LoadCommandsIntoMap(ChatCommandNode *blank, std::map< std::string_view, ChatCommandNode, StringCompareLessI_T > &map, Trinity::ChatCommands::ChatCommandTable const &commands)
bool IsVisible(ChatHandler const &who) const
void ResolveNames(std::string name)
CommandPermissions _permission
bool IsInvokerVisible(ChatHandler const &who) const
static std::vector< std::string > GetAutoCompletionsFor(ChatHandler const &handler, std::string_view cmd)
static bool TryExecuteCommand(ChatHandler &handler, std::string_view cmd)
TC_GAME_API std::vector< std::string > GetAutoCompletionsFor(ChatHandler const &handler, std::string_view cmd)
TC_GAME_API void SendCommandHelpFor(ChatHandler &handler, std::string_view cmd)
std::vector< ChatCommandBuilder > ChatCommandTable
TC_GAME_API bool TryExecuteCommand(ChatHandler &handler, std::string_view cmd)
TC_GAME_API void InvalidateCommandMap()
TC_GAME_API void LoadCommandMap()
typename HandlerToTuple< T >::type TupleType
TC_GAME_API char const * GetTrinityString(ChatHandler const *handler, TrinityStrings which)
ChatCommandResult ConsumeFromOffset(Tuple &, ChatHandler const *handler, std::string_view args)
TC_GAME_API void SendErrorMessageToHandler(ChatHandler *handler, std::string_view str)
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default TC string format function.
InvokerEntry(T &handler, TrinityStrings help, rbac::RBACPermissions permission, Trinity::ChatCommands::Console allowConsole)
InvokerEntry(InvokerEntry &&)=default
InvokerEntry(InvokerEntry const &)=default
Trinity::Impl::ChatCommands::CommandInvoker _invoker
Trinity::Impl::ChatCommands::CommandPermissions _permissions
std::variant< InvokerEntry, SubCommandEntry > _data
std::reference_wrapper< std::vector< ChatCommandBuilder > const > SubCommandEntry
ChatCommandBuilder(char const *name, std::vector< ChatCommandBuilder > const &subCommands)
ChatCommandBuilder(char const *name, rbac::RBACPermissions permission, bool console, TypedHandler *handler, char const *)
ChatCommandBuilder(ChatCommandBuilder const &)=default
ChatCommandBuilder(char const *name, TypedHandler &handler, TrinityStrings help, rbac::RBACPermissions permission, Trinity::ChatCommands::Console allowConsole)
ChatCommandBuilder(ChatCommandBuilder &&)=default
ChatCommandBuilder(char const *name, rbac::RBACPermissions, bool, std::nullptr_t, char const *, std::vector< ChatCommandBuilder > const &sub)
ChatCommandBuilder(char const *name, TypedHandler &handler, rbac::RBACPermissions permission, Trinity::ChatCommands::Console allowConsole)
ChatCommandBuilder(char const *name, bool(&handler)(ChatHandler *, char const *), rbac::RBACPermissions permission, Trinity::ChatCommands::Console allowConsole)
bool HasErrorMessage() const
std::string const & GetErrorMessage() const
bool operator()(ChatHandler *chatHandler, std::string_view args) const
CommandInvoker(TypedHandler &handler)
bool(void *, ChatHandler *, std::string_view) wrapper_func
CommandInvoker(bool(&handler)(ChatHandler *, char const *))
Trinity::ChatCommands::Console AllowConsole
CommandPermissions(rbac::RBACPermissions perm, Trinity::ChatCommands::Console console)
rbac::RBACPermissions RequiredPermission
std::tuple< ChatHandler *, std::remove_cvref_t< Ts >... > type
static ChatCommandResult TryConsumeTo(Tuple &tuple, ChatHandler const *handler, std::string_view args)
static ChatCommandResult TryConsumeTo(Tuple &tuple, ChatHandler const *handler, std::string_view args)