Skip to content

Commit 5a1e004

Browse files
Add AntiFlood plug-in (#243)
* add antifllod plugin * add antiflood to plugins.ini * add antifllod dictionary * add antifllod config * translate config * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Sergey Shorokhov <[email protected]>
1 parent 791aadb commit 5a1e004

File tree

4 files changed

+154
-0
lines changed

4 files changed

+154
-0
lines changed

cstrike/addons/amxmodx/configs/plugins-ChatAdditions.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CA_Storage_SQLite.amxx debug ; SQLite storage provider
88
; CA_Storage_GameCMS.amxx debug ; GameCMS (MySQL) storage provider
99

1010
; Extensions
11+
CA_AntiFlood.amxx debug ; Antiflood for chat
1112
CA_Mute.amxx debug ; Players can choose who they can hear.
1213
CA_Addon_DeathMute.amxx debug ; Alive players don't hear dead players after 5 secs
1314
CA_Addon_RankRestrictions.amxx debug ; Restrict chat until you reach the rank of a statistic.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Time between messages
2+
// 0.0 - no limit
3+
// -
4+
// Default: "0.75"
5+
// Minimum: "0.000000"
6+
ca_anti_flood_time "0.75"
7+
8+
// How many identical messages can be written in a row
9+
// 0 - no limit
10+
// -
11+
// Default: "2"
12+
// Minimum: "0.000000"
13+
ca_equal_messages "2"
14+
15+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[en]
2+
CA_ANTIFLOOD_CHAT_PREFIX = ^1[^4AntiFlood^1]
3+
4+
CA_ANTIFLOOD_CHAT_STOP_FLOODING = ^1Stop ^3flooding.
5+
CA_ANTIFLOOD_CHAT_EQUAL_MESSAGE = ^1Your message ^3is repeated! ^4Exercise your imagination.
6+
7+
CA_ANTIFLOOD_CVAR_TIME = Time between messages^n0.0 - no limit
8+
CA_ANTIFLOOD_CVAR_EQUAL_MESSAGES = How many identical messages can be written in a row^n0 - no limit
9+
10+
[ru]
11+
CA_ANTIFLOOD_CHAT_PREFIX = ^1[^4AntiFlood^1]
12+
13+
CA_ANTIFLOOD_CHAT_STOP_FLOODING = ^1Прекратите ^3флудить.
14+
CA_ANTIFLOOD_CHAT_EQUAL_MESSAGE = ^1Сообщение ^3повторяется! ^4Проявите фантазию.
15+
16+
CA_ANTIFLOOD_CVAR_TIME = Время между сообщениями^n0.0 - без ограничений
17+
CA_ANTIFLOOD_CVAR_EQUAL_MESSAGES = Сколько одинаковых сообщений можно написать подряд^n0 - без ограничений
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#include <amxmodx>
2+
#include <ChatAdditions>
3+
4+
#define GetCvarDesc(%0) fmt("%L", LANG_SERVER, %0)
5+
6+
new g_szOldMessage[MAX_PLAYERS + 1][CA_MAX_MESSAGE_SIZE];
7+
8+
enum _:Cvars
9+
{
10+
Float:ca_anti_flood_time,
11+
ca_equal_messages
12+
};
13+
14+
new g_pCvarValue[Cvars];
15+
16+
public stock const PluginName[] = "CA: Anti Flood";
17+
public stock const PluginVersion[] = CA_VERSION;
18+
public stock const PluginAuthor[] = "Nordic Warrior";
19+
public stock const PluginURL[] = "https://github.com/ChatAdditions";
20+
public stock const PluginDescription[] = "Antiflood for chat";
21+
22+
public plugin_init()
23+
{
24+
register_plugin(PluginName, PluginVersion, PluginAuthor);
25+
26+
register_dictionary("CA_AntiFlood.txt");
27+
28+
CreateCvars();
29+
AutoExecConfig(true, "CA_AntiFlood", "ChatAdditions");
30+
}
31+
32+
public plugin_cfg()
33+
{
34+
if(find_plugin_byfile("antiflood.amxx") != INVALID_PLUGIN_ID)
35+
{
36+
log_amx("Default plugin <antiflood.amxx> was found. Stopped.");
37+
pause("acd", "antiflood.amxx");
38+
}
39+
}
40+
41+
public CA_Client_Say(id, const szMessage[])
42+
{
43+
return CheckMessage(id, szMessage);
44+
}
45+
46+
public CA_Client_SayTeam(id, const szMessage[])
47+
{
48+
return CheckMessage(id, szMessage);
49+
}
50+
51+
CheckMessage(id, const szMessage[])
52+
{
53+
if(szMessage[0] == '/')
54+
{
55+
return CA_CONTINUE;
56+
}
57+
58+
static Float:flNextMessage[MAX_PLAYERS + 1];
59+
static iEqualMessage[MAX_PLAYERS + 1];
60+
61+
new Float:flNextSay = get_gametime();
62+
63+
if(flNextMessage[id] > flNextSay)
64+
{
65+
client_print_color(id, print_team_red, "%L %L", id, "CA_ANTIFLOOD_CHAT_PREFIX", id, "CA_ANTIFLOOD_CHAT_STOP_FLOODING");
66+
flNextMessage[id] = flNextSay + g_pCvarValue[ca_anti_flood_time];
67+
68+
return CA_SUPERCEDE;
69+
}
70+
71+
if(strcmp(szMessage, g_szOldMessage[id], true) == 0)
72+
{
73+
if(++iEqualMessage[id] >= g_pCvarValue[ca_equal_messages])
74+
{
75+
client_print_color(id, print_team_red, "%L %L", id, "CA_ANTIFLOOD_CHAT_PREFIX", id, "CA_ANTIFLOOD_CHAT_EQUAL_MESSAGE");
76+
77+
return CA_SUPERCEDE;
78+
}
79+
}
80+
else
81+
{
82+
iEqualMessage[id] = 0;
83+
}
84+
85+
flNextMessage[id] = flNextSay + g_pCvarValue[ca_anti_flood_time];
86+
copy(g_szOldMessage[id], charsmax(g_szOldMessage[]), szMessage);
87+
88+
return CA_CONTINUE;
89+
}
90+
91+
public client_disconnected(id)
92+
{
93+
g_szOldMessage[id][0] = EOS;
94+
}
95+
96+
CreateCvars()
97+
{
98+
bind_pcvar_float(
99+
create_cvar(
100+
.name = "ca_anti_flood_time",
101+
.string = "0.75",
102+
.description = GetCvarDesc("CA_ANTIFLOOD_CVAR_TIME"),
103+
.has_min = true,
104+
.min_val = 0.0
105+
),
106+
107+
g_pCvarValue[ca_anti_flood_time]
108+
);
109+
110+
bind_pcvar_num(
111+
create_cvar(
112+
.name = "ca_equal_messages",
113+
.string = "2",
114+
.description = GetCvarDesc("CA_ANTIFLOOD_CVAR_EQUAL_MESSAGES"),
115+
.has_min = true,
116+
.min_val = 0.0
117+
),
118+
119+
g_pCvarValue[ca_equal_messages]
120+
);
121+
}

0 commit comments

Comments
 (0)