Add natives to get chat triggers (#1816)

This commit is contained in:
Corey D 2022-12-02 23:55:32 +11:00 committed by GitHub
parent f90b7ade76
commit 3b4a343274
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 0 deletions

View File

@ -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();
}

View File

@ -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,

View File

@ -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<cell_t>(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<cell_t>(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},

View File

@ -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