|
1 | 1 | #include <amxmodx> |
2 | 2 | #include <ChatAdditions> |
3 | 3 |
|
4 | | -#define GetCvarDesc(%0) fmt("%L", LANG_SERVER, %0) |
| 4 | +#pragma ctrlchar '\' |
| 5 | +#pragma tabsize 2 |
5 | 6 |
|
6 | | -new g_szOldMessage[MAX_PLAYERS + 1][CA_MAX_MESSAGE_SIZE]; |
| 7 | +new g_OldMessage[MAX_PLAYERS + 1][CA_MAX_MESSAGE_SIZE] |
7 | 8 |
|
8 | | -enum _:Cvars |
9 | | -{ |
10 | | - Float:ca_anti_flood_time, |
11 | | - ca_equal_messages |
12 | | -}; |
13 | | - |
14 | | -new g_pCvarValue[Cvars]; |
| 9 | +new Float: ca_anti_flood_time, |
| 10 | + ca_equal_messages |
15 | 11 |
|
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"; |
| 12 | +public stock const PluginName[] = "CA: Anti Flood" |
| 13 | +public stock const PluginVersion[] = CA_VERSION |
| 14 | +public stock const PluginAuthor[] = "Nordic Warrior" |
| 15 | +public stock const PluginURL[] = "https://github.com/ChatAdditions" |
| 16 | +public stock const PluginDescription[] = "Antiflood for chat" |
21 | 17 |
|
22 | | -public plugin_init() |
23 | | -{ |
24 | | - register_plugin(PluginName, PluginVersion, PluginAuthor); |
| 18 | +public plugin_init() { |
| 19 | + register_plugin(PluginName, PluginVersion, PluginAuthor) |
25 | 20 |
|
26 | | - register_dictionary("CA_AntiFlood.txt"); |
| 21 | + register_dictionary("CA_AntiFlood.txt") |
27 | 22 |
|
28 | | - CreateCvars(); |
29 | | - AutoExecConfig(true, "CA_AntiFlood", "ChatAdditions"); |
| 23 | + CreateCVars() |
| 24 | + AutoExecConfig(true, "CA_AntiFlood", "ChatAdditions") |
30 | 25 | } |
31 | 26 |
|
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 | | - } |
| 27 | +public plugin_cfg() { |
| 28 | + if(find_plugin_byfile("antiflood.amxx") != INVALID_PLUGIN_ID) { |
| 29 | + log_amx("Default plugin <antiflood.amxx> was found. Stopped.") |
| 30 | + pause("acd", "antiflood.amxx") |
| 31 | + } |
39 | 32 | } |
40 | 33 |
|
41 | | -public CA_Client_Say(id, const szMessage[]) |
42 | | -{ |
43 | | - return CheckMessage(id, szMessage); |
| 34 | +public CA_Client_Say(id, const message[]) { |
| 35 | + return CheckMessage(id, message) |
44 | 36 | } |
45 | 37 |
|
46 | | -public CA_Client_SayTeam(id, const szMessage[]) |
47 | | -{ |
48 | | - return CheckMessage(id, szMessage); |
| 38 | +public CA_Client_SayTeam(id, const message[]) { |
| 39 | + return CheckMessage(id, message) |
49 | 40 | } |
50 | 41 |
|
51 | | -CheckMessage(id, const szMessage[]) |
52 | | -{ |
53 | | - if(szMessage[0] == '/') |
54 | | - { |
55 | | - return CA_CONTINUE; |
56 | | - } |
| 42 | +CheckMessage(id, const message[]) { |
| 43 | + if(message[0] == '/') { |
| 44 | + return CA_CONTINUE; |
| 45 | + } |
57 | 46 |
|
58 | | - static Float:flNextMessage[MAX_PLAYERS + 1]; |
59 | | - static iEqualMessage[MAX_PLAYERS + 1]; |
| 47 | + static Float:nextMessage[MAX_PLAYERS + 1] |
| 48 | + static equalMessage[MAX_PLAYERS + 1] |
60 | 49 |
|
61 | | - new Float:flNextSay = get_gametime(); |
| 50 | + new Float:nextSay = get_gametime() |
62 | 51 |
|
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]; |
| 52 | + if(nextMessage[id] > nextSay) { |
| 53 | + client_print_color(id, print_team_red, "%L %L", id, "CA_ANTIFLOOD_CHAT_PREFIX", id, "CA_ANTIFLOOD_CHAT_STOP_FLOODING") |
| 54 | + nextMessage[id] = nextSay + ca_anti_flood_time |
67 | 55 |
|
68 | | - return CA_SUPERCEDE; |
69 | | - } |
| 56 | + return CA_SUPERCEDE |
| 57 | + } |
70 | 58 |
|
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"); |
| 59 | + if(strcmp(message, g_OldMessage[id], true) == 0) { |
| 60 | + if(++equalMessage[id] >= ca_equal_messages) { |
| 61 | + client_print_color(id, print_team_red, "%L %L", id, "CA_ANTIFLOOD_CHAT_PREFIX", id, "CA_ANTIFLOOD_CHAT_EQUAL_MESSAGE") |
76 | 62 |
|
77 | | - return CA_SUPERCEDE; |
78 | | - } |
79 | | - } |
80 | | - else |
81 | | - { |
82 | | - iEqualMessage[id] = 0; |
| 63 | + return CA_SUPERCEDE |
83 | 64 | } |
| 65 | + } |
| 66 | + else { |
| 67 | + equalMessage[id] = 0 |
| 68 | + } |
84 | 69 |
|
85 | | - flNextMessage[id] = flNextSay + g_pCvarValue[ca_anti_flood_time]; |
86 | | - copy(g_szOldMessage[id], charsmax(g_szOldMessage[]), szMessage); |
| 70 | + nextMessage[id] = nextSay + ca_anti_flood_time |
| 71 | + copy(g_OldMessage[id], charsmax(g_OldMessage[]), message) |
87 | 72 |
|
88 | | - return CA_CONTINUE; |
| 73 | + return CA_CONTINUE |
89 | 74 | } |
90 | 75 |
|
91 | | -public client_disconnected(id) |
92 | | -{ |
93 | | - g_szOldMessage[id][0] = EOS; |
| 76 | +public client_disconnected(id) { |
| 77 | + g_OldMessage[id][0] = EOS |
94 | 78 | } |
95 | 79 |
|
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 | | - ); |
| 80 | +CreateCVars() { |
| 81 | + bind_pcvar_float( |
| 82 | + create_cvar( |
| 83 | + .name = "ca_anti_flood_time", |
| 84 | + .string = "0.75", |
| 85 | + .description = "Time between messages\n 0.0 - no limit", |
| 86 | + .has_min = true, |
| 87 | + .min_val = 0.0 |
| 88 | + ), |
| 89 | + |
| 90 | + ca_anti_flood_time |
| 91 | + ) |
| 92 | + |
| 93 | + bind_pcvar_num( |
| 94 | + create_cvar( |
| 95 | + .name = "ca_equal_messages", |
| 96 | + .string = "2", |
| 97 | + .description = "How many identical messages can be written in a row\n 0 - no limit", |
| 98 | + .has_min = true, |
| 99 | + .min_val = 0.0 |
| 100 | + ), |
| 101 | + |
| 102 | + ca_equal_messages |
| 103 | + ) |
121 | 104 | } |
0 commit comments