Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Module/AntiAD): add support separate check channels #129

Merged
merged 3 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions modules/mod-anti-ad/conf/AntiAD.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,26 @@
# Description: Enable mute at writing forbidden word.
# Default: 1
#
# AntiAD.MuteGM.Enable
# AntiAD.MuteGM.Enable
# Description: Enable mute for GMs.
# Default: 0
#
# AntiAD.Mute.Time
# AntiAD.Mute.Time
# Description: Mute time in minutes.
# Default: 5
#
# AntiAD.CheckChannels
# Description: A mask that describes which channels checks
#
# Following flags are available
# ANTIAD_CHANNEL_SAY = 0 // Say
# ANTIAD_CHANNEL_WHISPER = 1 // Whisper
# ANTIAD_CHANNEL_GROUP = 2 // Group
# ANTIAD_CHANNEL_GUILD = 4 // Guild
# ANTIAD_CHANNEL_CHANNEL = 8 // Channels (lfg and etc)
#
# Default: 8
#

AntiAD.Enable = 0
AntiAD.MessageGMsInWorld.Enable = 1
Expand All @@ -56,3 +68,4 @@ AntiAD.SelfMessage.Enable = 1
AntiAD.Mute.Enable = 1
AntiAD.MuteGM.Enable = 1
AntiAD.Mute.Time = 1
AntiAD.CheckChannels = 8
32 changes: 32 additions & 0 deletions modules/mod-anti-ad/src/AntiAD_SC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
#include "MuteManager.h"
#include <vector>

enum AntiADChannelsType : uint8
{
ANTIAD_CHANNEL_SAY,
ANTIAD_CHANNEL_WHISPER = 1,
ANTIAD_CHANNEL_GROUP = 2,
ANTIAD_CHANNEL_GUILD = 4,
ANTIAD_CHANNEL_CHANNEL = 8,
};

enum StringLocales : uint8
{
ANTIAD_LOCALE_SEND_GM_TEXT = 1,
Expand Down Expand Up @@ -84,6 +93,14 @@ class AntiAD
LOG_INFO("modules.antiad", "");
}

bool IsNeedCheckChannel(uint8 channelType)
{
if (!CONF_GET_BOOL("AntiAD.Enable"))
return false;

return (CONF_GET_INT("AntiAD.CheckChannels") & channelType) ? true : false;
}

bool IsBadMessage(std::string& msg)
{
if (messages.empty())
Expand Down Expand Up @@ -117,26 +134,41 @@ class AntiAD_Player : public PlayerScript

void OnChat(Player* player, uint32 /*type*/, uint32 /*lang*/, std::string& msg) override
{
if (!sAD->IsNeedCheckChannel(ANTIAD_CHANNEL_SAY))
return;

CheckMessage(player, msg);
}

void OnChat(Player* player, uint32 /*type*/, uint32 /*lang*/, std::string& msg, Player* /*receiver*/) override
{
if (!sAD->IsNeedCheckChannel(ANTIAD_CHANNEL_WHISPER))
return;

CheckMessage(player, msg);
}

void OnChat(Player* player, uint32 /*type*/, uint32 /*lang*/, std::string& msg, Group* /*group*/) override
{
if (!sAD->IsNeedCheckChannel(ANTIAD_CHANNEL_GROUP))
return;

CheckMessage(player, msg);
}

void OnChat(Player* player, uint32 /*type*/, uint32 /*lang*/, std::string& msg, Guild* /*guild*/) override
{
if (!sAD->IsNeedCheckChannel(ANTIAD_CHANNEL_GUILD))
return;

CheckMessage(player, msg);
}

void OnChat(Player* player, uint32 /*type*/, uint32 /*lang*/, std::string& msg, Channel* /*channel*/) override
{
if (!sAD->IsNeedCheckChannel(ANTIAD_CHANNEL_CHANNEL))
return;

CheckMessage(player, msg);
}

Expand Down