From 3b4a343274286b31a9b3cf33c64f7ef6c6a5234f Mon Sep 17 00:00:00 2001 From: Corey D Date: Fri, 2 Dec 2022 23:55:32 +1100 Subject: [PATCH] Add natives to get chat triggers (#1816) --- core/ChatTriggers.cpp | 20 ++++++++++++++++++++ core/ChatTriggers.h | 2 ++ core/smn_console.cpp | 22 ++++++++++++++++++++++ plugins/include/console.inc | 18 ++++++++++++++++++ 4 files changed, 62 insertions(+) diff --git a/core/ChatTriggers.cpp b/core/ChatTriggers.cpp index 71a67740..787a5d34 100644 --- a/core/ChatTriggers.cpp +++ b/core/ChatTriggers.cpp @@ -461,3 +461,23 @@ bool ChatTriggers::WasFloodedMessage() { return m_bWasFloodedMessage; } + +const char *ChatTriggers::GetPublicChatTrigger() +{ + if (!m_PubTrigger.length()) + { + return NULL; + } + + return m_PubTrigger.c_str(); +} + +const char *ChatTriggers::GetPrivateChatTrigger() +{ + if (!m_PrivTrigger.length()) + { + return NULL; + } + + return m_PrivTrigger.c_str(); +} diff --git a/core/ChatTriggers.h b/core/ChatTriggers.h index de9620f9..b52946da 100644 --- a/core/ChatTriggers.h +++ b/core/ChatTriggers.h @@ -63,6 +63,8 @@ public: unsigned int SetReplyTo(unsigned int reply); bool IsChatTrigger(); bool WasFloodedMessage(); + const char *GetPublicChatTrigger(); + const char *GetPrivateChatTrigger(); private: enum ChatTriggerType { ChatTrigger_Public, diff --git a/core/smn_console.cpp b/core/smn_console.cpp index 25da56ba..c95ebbd3 100644 --- a/core/smn_console.cpp +++ b/core/smn_console.cpp @@ -1091,6 +1091,26 @@ static cell_t IsChatTrigger(IPluginContext *pContext, const cell_t *params) return g_ChatTriggers.IsChatTrigger() ? 1 : 0; } +static cell_t GetPublicChatTriggers(IPluginContext *pContext, const cell_t *params) +{ + size_t length; + + const char *triggers = g_ChatTriggers.GetPublicChatTrigger(); + pContext->StringToLocalUTF8(params[1], params[2], triggers ? triggers : "", &length); + + return static_cast(length); +} + +static cell_t GetSilentChatTriggers(IPluginContext *pContext, const cell_t *params) +{ + size_t length; + + const char *triggers = g_ChatTriggers.GetPrivateChatTrigger(); + pContext->StringToLocalUTF8(params[1], params[2], triggers ? triggers : "", &length); + + return static_cast(length); +} + static cell_t SetCommandFlags(IPluginContext *pContext, const cell_t *params) { char *name; @@ -1514,6 +1534,8 @@ REGISTER_NATIVES(consoleNatives) {"ReadCommandIterator", ReadCommandIterator}, {"FakeClientCommandEx", FakeClientCommandEx}, {"IsChatTrigger", IsChatTrigger}, + {"GetPublicChatTriggers", GetPublicChatTriggers}, + {"GetSilentChatTriggers", GetSilentChatTriggers}, {"SetCommandFlags", SetCommandFlags}, {"GetCommandFlags", GetCommandFlags}, {"FindFirstConCommand", FindFirstConCommand}, diff --git a/plugins/include/console.inc b/plugins/include/console.inc index ee2db555..dd7a0a42 100644 --- a/plugins/include/console.inc +++ b/plugins/include/console.inc @@ -273,6 +273,24 @@ native ReplySource SetCmdReplySource(ReplySource source); */ native bool IsChatTrigger(); +/** + * Get the list of characters used for public chat triggers. + * + * @param buffer Buffer to use for storing the string. + * @param maxlength Maximum length of the buffer. + * @return Length of string written to buffer. + */ +native int GetPublicChatTriggers(char[] buffer, int maxlength); + +/** + * Get the list of characters used for silent chat triggers. + * + * @param buffer Buffer to use for storing the string. + * @param maxlength Maximum length of the buffer. + * @return Length of string written to buffer. + */ +native int GetSilentChatTriggers(char[] buffer, int maxlength); + /** * Displays usage of an admin command to users depending on the * setting of the sm_show_activity cvar. All users receive a message