· 8 years ago · Jan 27, 2018, 01:14 AM
1
2
3
4#include <amxmodx>
5#include <amxmisc>
6#include <engine>
7#include <regex>
8
9#define PLUGIN_NAME "Bans Avancados TTJogos"
10#define PLUGIN_VERSION "1.0.1"
11#define PLUGIN_AUTHOR "thales"
12
13#pragma semicolon 1
14
15
16
17// ===============================================
18// CUSTOMIZATION STARTS HERE
19// ===============================================
20
21
22// uncomment the line below if you want this plugin to
23// load old bans from the banned.cfg and listip.cfg files
24//#define KEEP_DEFAULT_BANS
25
26
27// uncomment the line below if you want the history to be in one file
28//#define HISTORY_ONE_FILE
29
30
31// if you must have a maximum amount of bans to be compatible with AMXX versions before 1.8.0
32// change this number to your maximum amount
33// if you would rather have unlimited (requires AMXX 1.8.0 or higher) then set it to 0
34#define MAX_BANS 0
35
36
37
38// if you want to use SQL for your server, then uncomment the line below
39//#define USING_SQL
40
41
42// ===============================================
43// CUSTOMIZATION ENDS HERE
44// ===============================================
45
46
47
48#if defined USING_SQL
49#include <sqlx>
50
51#define TABLE_NAME "bans_ttjogos"
52#define KEY_NAME "name"
53#define KEY_STEAMID "steamid"
54#define KEY_BANLENGTH "banlength"
55#define KEY_UNBANTIME "unbantime"
56#define KEY_REASON "reason"
57#define KEY_ADMIN_NAME "admin_name"
58#define KEY_ADMIN_STEAMID "admin_steamid"
59
60#define RELOAD_BANS_INTERVAL 60.0
61#endif
62
63#define REGEX_IP_PATTERN "\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"
64#define REGEX_STEAMID_PATTERN "^^STEAM_0:(0|1):\d+$"
65
66new Regex:g_IP_pattern;
67new Regex:g_SteamID_pattern;
68new g_regex_return;
69
70/*bool:IsValidIP(const ip[])
71{
72 return regex_match_c(ip, g_IP_pattern, g_regex_return) > 0;
73}*/
74
75#define IsValidIP(%1) (regex_match_c(%1, g_IP_pattern, g_regex_return) > 0)
76
77/*bool:IsValidAuthid(const authid[])
78{
79 return regex_match_c(authid, g_SteamID_pattern, g_regex_return) > 0;
80}*/
81
82#define IsValidAuthid(%1) (regex_match_c(%1, g_SteamID_pattern, g_regex_return) > 0)
83
84
85enum // for name displaying
86{
87 ACTIVITY_NONE, // nothing is shown
88 ACTIVITY_HIDE, // admin name is hidden
89 ACTIVITY_SHOW // admin name is shown
90};
91new const g_admin_activity[] =
92{
93 ACTIVITY_NONE, // amx_show_activity 0 = show nothing to everyone
94 ACTIVITY_HIDE, // amx_show_activity 1 = hide admin name from everyone
95 ACTIVITY_SHOW, // amx_show_activity 2 = show admin name to everyone
96 ACTIVITY_SHOW, // amx_show_activity 3 = show name to admins but hide it from normal users
97 ACTIVITY_SHOW, // amx_show_activity 4 = show name to admins but show nothing to normal users
98 ACTIVITY_HIDE // amx_show_activity 5 = hide name from admins but show nothing to normal users
99};
100new const g_normal_activity[] =
101{
102 ACTIVITY_NONE, // amx_show_activity 0 = show nothing to everyone
103 ACTIVITY_HIDE, // amx_show_activity 1 = hide admin name from everyone
104 ACTIVITY_SHOW, // amx_show_activity 2 = show admin name to everyone
105 ACTIVITY_HIDE, // amx_show_activity 3 = show name to admins but hide it from normal users
106 ACTIVITY_NONE, // amx_show_activity 4 = show name to admins but show nothing to normal users
107 ACTIVITY_NONE // amx_show_activity 5 = hide name from admins but show nothing to normal users
108};
109
110
111#if MAX_BANS <= 0
112enum _:BannedData
113{
114 bd_name[32],
115 bd_steamid[35],
116 bd_banlength,
117 bd_unbantime[32],
118 bd_reason[128],
119 bd_admin_name[64],
120 bd_admin_steamid[35]
121};
122
123new Trie:g_trie;
124new Array:g_array;
125#else
126new g_names[MAX_BANS][32];
127new g_steamids[MAX_BANS][35];
128new g_banlengths[MAX_BANS];
129new g_unbantimes[MAX_BANS][32];
130new g_reasons[MAX_BANS][128];
131new g_admin_names[MAX_BANS][64];
132new g_admin_steamids[MAX_BANS][35];
133#endif
134new g_total_bans;
135
136#if !defined USING_SQL
137new g_ban_file[64];
138#else
139new Handle:g_sql_tuple;
140new bool:g_loading_bans = true;
141#endif
142
143new ab_website;
144new ab_immunity;
145new ab_bandelay;
146new ab_unbancheck;
147
148new amx_show_activity;
149
150#if MAX_BANS <= 0
151new Array:g_maxban_times;
152new Array:g_maxban_flags;
153#else
154#define MAX_BANLIMITS 30
155new g_maxban_times[MAX_BANLIMITS];
156new g_maxban_flags[MAX_BANLIMITS];
157#endif
158new g_total_maxban_times;
159
160new g_unban_entity;
161
162new g_max_clients;
163
164new g_msgid_SayText;
165
166public plugin_init()
167{
168 register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
169 register_cvar("bans_ttjogos", PLUGIN_VERSION, FCVAR_SPONLY);
170
171 register_dictionary("bans_ttjogos.txt");
172
173 register_concmd("amx_ban", "CmdBan", ADMIN_BAN, "<nick, #userid, authid> <time in minutes> <reason>");
174 register_concmd("amx_banip", "CmdBanIp", ADMIN_BAN, "<nick, #userid, authid> <time in minutes> <reason>");
175 register_concmd("amx_addban", "CmdAddBan", ADMIN_BAN, "<name> <authid or ip> <time in minutes> <reason>");
176 register_concmd("amx_unban", "CmdUnban", ADMIN_BAN, "<authid or ip>");
177 register_concmd("amx_banlist", "CmdBanList", ADMIN_BAN, "[start] -- shows everyone who is banned");
178 register_srvcmd("amx_addbanlimit", "CmdAddBanLimit", -1, "<flag> <time in minutes>");
179
180 ab_website = register_cvar("tt_website", "");
181 ab_immunity = register_cvar("tt_immunity", "1");
182 ab_bandelay = register_cvar("tt_bandelay", "1.0");
183 ab_unbancheck = register_cvar("tt_unbancheck", "5.0");
184
185 amx_show_activity = register_cvar("amx_show_activity", "2");
186
187 #if MAX_BANS <= 0
188 g_trie = TrieCreate();
189 g_array = ArrayCreate(BannedData);
190 #endif
191
192 #if !defined MAX_BANLIMITS
193 g_maxban_times = ArrayCreate(1);
194 g_maxban_flags = ArrayCreate(1);
195 #endif
196
197 #if !defined USING_SQL
198 get_datadir(g_ban_file, sizeof(g_ban_file) - 1);
199 add(g_ban_file, sizeof(g_ban_file) - 1, "/bans_ttjogos.txt");
200
201 LoadBans();
202 #else
203 g_sql_tuple = SQL_MakeStdTuple();
204 PrepareTable();
205 #endif
206
207 new error[2];
208 g_IP_pattern = regex_compile(REGEX_IP_PATTERN, g_regex_return, error, sizeof(error) - 1);
209 g_SteamID_pattern = regex_compile(REGEX_STEAMID_PATTERN, g_regex_return, error, sizeof(error) - 1);
210
211 g_max_clients = get_maxplayers();
212
213 g_msgid_SayText = get_user_msgid("SayText");
214}
215
216#if defined USING_SQL
217PrepareTable()
218{
219 new query[128];
220 formatex(query, sizeof(query) - 1,\
221 "CREATE TABLE IF NOT EXISTS `%s` (`%s` varchar(32) NOT NULL, `%s` varchar(35) NOT NULL, `%s` int(10) NOT NULL, `%s` varchar(32) NOT NULL, `%s` varchar(128) NOT NULL, `%s` varchar(64) NOT NULL, `%s` varchar(35) NOT NULL);",\
222 TABLE_NAME, KEY_NAME, KEY_STEAMID, KEY_BANLENGTH, KEY_UNBANTIME, KEY_REASON, KEY_ADMIN_NAME, KEY_ADMIN_STEAMID
223 );
224
225 SQL_ThreadQuery(g_sql_tuple, "QueryCreateTable", query);
226}
227
228public QueryCreateTable(failstate, Handle:query, error[], errcode, data[], datasize, Float:queuetime)
229{
230 if( failstate == TQUERY_CONNECT_FAILED )
231 {
232 set_fail_state("Could not connect to database.");
233 }
234 else if( failstate == TQUERY_QUERY_FAILED )
235 {
236 set_fail_state("Query failed.");
237 }
238 else if( errcode )
239 {
240 log_amx("Error on query: %s", error);
241 }
242 else
243 {
244 LoadBans();
245 }
246}
247#endif
248
249public plugin_cfg()
250{
251 CreateUnbanEntity();
252}
253
254public CreateUnbanEntity()
255{
256 static failtimes;
257
258 g_unban_entity = create_entity("info_target");
259
260 if( !is_valid_ent(g_unban_entity) )
261 {
262 ++failtimes;
263
264 log_amx("[ERROR] Failed to create unban entity (%i/10)", failtimes);
265
266 if( failtimes < 10 )
267 {
268 set_task(1.0, "CreateUnbanEntity");
269 }
270 else
271 {
272 log_amx("[ERROR] Could not create unban entity!");
273 }
274
275 return;
276 }
277
278 entity_set_string(g_unban_entity, EV_SZ_classname, "unban_entity");
279 entity_set_float(g_unban_entity, EV_FL_nextthink, get_gametime() + 1.0);
280
281 register_think("unban_entity", "FwdThink");
282}
283
284public client_authorized(client)
285{
286 static authid[35];
287 get_user_authid(client, authid, sizeof(authid) - 1);
288
289 static ip[35];
290 get_user_ip(client, ip, sizeof(ip) - 1, 1);
291
292 #if MAX_BANS > 0
293 static banned_authid[35], bool:is_ip;
294 for( new i = 0; i < g_total_bans; i++ )
295 {
296 copy(banned_authid, sizeof(banned_authid) - 1, g_steamids[i]);
297
298 is_ip = bool:(containi(banned_authid, ".") != -1);
299
300 if( is_ip && equal(ip, banned_authid) || !is_ip && equal(authid, banned_authid) )
301 {
302 static name[32], reason[128], unbantime[32], admin_name[32], admin_steamid[64];
303 copy(name, sizeof(name) - 1, g_names[i]);
304 copy(reason, sizeof(reason) - 1, g_reasons[i]);
305 new banlength = g_banlengths[i];
306 copy(unbantime, sizeof(unbantime) - 1, g_unbantimes[i]);
307 copy(admin_name, sizeof(admin_name) - 1, g_admin_names[i]);
308 copy(admin_steamid, sizeof(admin_steamid) - 1, g_admin_steamids[i]);
309
310 PrintBanInformation(client, name, banned_authid, reason, banlength, unbantime, admin_name, admin_steamid, true, true);
311
312 set_task(get_pcvar_float(ab_bandelay), "TaskDisconnectPlayer", client);
313 break;
314 }
315 }
316 #else
317 static array_pos;
318
319 if( TrieGetCell(g_trie, authid, array_pos) || TrieGetCell(g_trie, ip, array_pos) )
320 {
321 static data[BannedData];
322 ArrayGetArray(g_array, array_pos, data);
323
324 PrintBanInformation(client, data[bd_name], data[bd_steamid], data[bd_reason], data[bd_banlength], data[bd_unbantime], data[bd_admin_name], data[bd_admin_steamid], true, true);
325
326 set_task(get_pcvar_float(ab_bandelay), "TaskDisconnectPlayer", client);
327 }
328 #endif
329}
330
331public CmdBan(client, level, cid)
332{
333 if( !cmd_access(client, level, cid, 4) ) return PLUGIN_HANDLED;
334
335 static arg[128];
336 read_argv(1, arg, sizeof(arg) - 1);
337
338 new target = cmd_target(client, arg, GetTargetFlags(client));
339 if( !target ) return PLUGIN_HANDLED;
340
341 static target_authid[35];
342 get_user_authid(target, target_authid, sizeof(target_authid) - 1);
343
344 if( !IsValidAuthid(target_authid) )
345 {
346 console_print(client, "[TTJogos] %L", client, "AB_NOT_AUTHORIZED");
347 return PLUGIN_HANDLED;
348 }
349
350 #if MAX_BANS <= 0
351 if( TrieKeyExists(g_trie, target_authid) )
352 {
353 console_print(client, "[TTJogos] %L", client, "AB_ALREADY_BANNED_STEAMID");
354 return PLUGIN_HANDLED;
355 }
356 #else
357 for( new i = 0; i < g_total_bans; i++ )
358 {
359 if( !strcmp(target_authid, g_steamids[i], 1) )
360 {
361 console_print(client, "[TTJogos] %L", client, "AB_ALREADY_BANNED_STEAMID");
362 return PLUGIN_HANDLED;
363 }
364 }
365 #endif
366
367 read_argv(2, arg, sizeof(arg) - 1);
368
369 new length = str_to_num(arg);
370 new maxlength = GetMaxBanTime(client);
371
372 if( maxlength && (!length || length > maxlength) )
373 {
374 console_print(client, "[TTJogos] %L", client, "AB_MAX_BAN_TIME", maxlength);
375 return PLUGIN_HANDLED;
376 }
377
378 static unban_time[64];
379 if( length == 0 )
380 {
381 formatex(unban_time, sizeof(unban_time) - 1, "%L", client, "AB_PERMANENT_BAN");
382 }
383 else
384 {
385 GenerateUnbanTime(length, unban_time, sizeof(unban_time) - 1);
386 }
387
388 read_argv(3, arg, sizeof(arg) - 1);
389
390 static admin_name[64], target_name[32];
391 get_user_name(client, admin_name, sizeof(admin_name) - 1);
392 get_user_name(target, target_name, sizeof(target_name) - 1);
393
394 static admin_authid[35];
395 get_user_authid(client, admin_authid, sizeof(admin_authid) - 1);
396
397 AddBan(target_name, target_authid, arg, length, unban_time, admin_name, admin_authid);
398
399 PrintBanInformation(target, target_name, target_authid, arg, length, unban_time, admin_name, admin_authid, true, true);
400 PrintBanInformation(client, target_name, target_authid, arg, length, unban_time, admin_name, admin_authid, false, false);
401
402 set_task(get_pcvar_float(ab_bandelay), "TaskDisconnectPlayer", target);
403
404 GetBanTime(length, unban_time, sizeof(unban_time) - 1);
405
406 PrintActivity(admin_name, "^x04[TTJogos] $name^x01 :^x03 banned %s. Reason: %s. Ban Length: %s", target_name, arg, unban_time);
407
408 Log("%s <%s> banned %s <%s> || Reason: ^"%s^" || Ban Length: %s", admin_name, admin_authid, target_name, target_authid, arg, unban_time);
409
410 return PLUGIN_HANDLED;
411}
412
413public CmdBanIp(client, level, cid)
414{
415 if( !cmd_access(client, level, cid, 4) ) return PLUGIN_HANDLED;
416
417 static arg[128];
418 read_argv(1, arg, sizeof(arg) - 1);
419
420 new target = cmd_target(client, arg, GetTargetFlags(client));
421 if( !target ) return PLUGIN_HANDLED;
422
423 static target_ip[35];
424 get_user_ip(target, target_ip, sizeof(target_ip) - 1, 1);
425
426 #if MAX_BANS <= 0
427 if( TrieKeyExists(g_trie, target_ip) )
428 {
429 console_print(client, "[TTJogos] %L", client, "AB_ALREADY_BANNED_IP");
430 return PLUGIN_HANDLED;
431 }
432 #else
433 for( new i = 0; i < g_total_bans; i++ )
434 {
435 if( !strcmp(target_ip, g_steamids[i], 1) )
436 {
437 console_print(client, "[TTJogos] %L", client, "AB_ALREADY_BANNED_IP");
438 return PLUGIN_HANDLED;
439 }
440 }
441 #endif
442
443 read_argv(2, arg, sizeof(arg) - 1);
444
445 new length = str_to_num(arg);
446 new maxlength = GetMaxBanTime(client);
447
448 if( maxlength && (!length || length > maxlength) )
449 {
450 console_print(client, "[TTJogos] %L", client, "AB_MAX_BAN_TIME", maxlength);
451 return PLUGIN_HANDLED;
452 }
453
454 static unban_time[32];
455
456 if( length == 0 )
457 {
458 formatex(unban_time, sizeof(unban_time) - 1, "%L", client, "AB_PERMANENT_BAN");
459 }
460 else
461 {
462 GenerateUnbanTime(length, unban_time, sizeof(unban_time) - 1);
463 }
464
465 read_argv(3, arg, sizeof(arg) - 1);
466
467 static admin_name[64], target_name[32];
468 get_user_name(client, admin_name, sizeof(admin_name) - 1);
469 get_user_name(target, target_name, sizeof(target_name) - 1);
470
471 static admin_authid[35];
472 get_user_authid(client, admin_authid, sizeof(admin_authid) - 1);
473
474 AddBan(target_name, target_ip, arg, length, unban_time, admin_name, admin_authid);
475
476 PrintBanInformation(target, target_name, target_ip, arg, length, unban_time, admin_name, admin_authid, true, true);
477 PrintBanInformation(client, target_name, target_ip, arg, length, unban_time, admin_name, admin_authid, false, false);
478
479 set_task(get_pcvar_float(ab_bandelay), "TaskDisconnectPlayer", target);
480
481 GetBanTime(length, unban_time, sizeof(unban_time) - 1);
482
483 PrintActivity(admin_name, "^x04[TTJogos] $name^x01 :^x03 banned %s. Reason: %s. Ban Length: %s", target_name, arg, unban_time);
484
485 Log("%s <%s> banned %s <%s> || Reason: ^"%s^" || Ban Length: %s", admin_name, admin_authid, target_name, target_ip, arg, unban_time);
486
487 return PLUGIN_HANDLED;
488}
489
490public CmdAddBan(client, level, cid)
491{
492 if( !cmd_access(client, level, cid, 5) ) return PLUGIN_HANDLED;
493
494 static target_name[32], target_authid[35], bantime[10], reason[128];
495 read_argv(1, target_name, sizeof(target_name) - 1);
496 read_argv(2, target_authid, sizeof(target_authid) - 1);
497 read_argv(3, bantime, sizeof(bantime) - 1);
498 read_argv(4, reason, sizeof(reason) - 1);
499
500 new bool:is_ip = bool:(containi(target_authid, ".") != -1);
501
502 if( !is_ip && !IsValidAuthid(target_authid) )
503 {
504 console_print(client, "[TTJogos] %L", client, "AB_INVALID_STEAMID");
505 console_print(client, "[TTJogos] %L", client, "AB_VALID_STEAMID_FORMAT");
506
507 return PLUGIN_HANDLED;
508 }
509 else if( is_ip )
510 {
511 new pos = contain(target_authid, ":");
512 if( pos > 0 )
513 {
514 target_authid[pos] = 0;
515 }
516
517 if( !IsValidIP(target_authid) )
518 {
519 console_print(client, "[TTJogos] %L", client, "AB_INVALID_IP");
520
521 return PLUGIN_HANDLED;
522 }
523 }
524
525 #if MAX_BANS <= 0
526 if( TrieKeyExists(g_trie, target_authid) )
527 {
528 console_print(client, "[TTJogos] %L", client, is_ip ? "AB_ALREADY_BANNED_IP" : "AB_ALREADY_BANNED_STEAMID");
529 return PLUGIN_HANDLED;
530 }
531 #else
532 for( new i = 0; i < g_total_bans; i++ )
533 {
534 if( !strcmp(target_authid, g_steamids[i], 1) )
535 {
536 console_print(client, "[TTJogos] %L", client, is_ip ? "AB_ALREADY_BANNED_IP" : "AB_ALREADY_BANNED_STEAMID");
537 return PLUGIN_HANDLED;
538 }
539 }
540 #endif
541
542 new length = str_to_num(bantime);
543 new maxlength = GetMaxBanTime(client);
544
545 if( maxlength && (!length || length > maxlength) )
546 {
547 console_print(client, "[TTJogos] %L", client, "AB_MAX_BAN_TIME", maxlength);
548 return PLUGIN_HANDLED;
549 }
550
551 if( is_user_connected(find_player(is_ip ? "d" : "c", target_authid)) )
552 {
553 client_cmd(client, "amx_ban ^"%s^" %i ^"%s^"", target_authid, length, reason);
554 return PLUGIN_HANDLED;
555 }
556
557 static unban_time[32];
558 if( length == 0 )
559 {
560 formatex(unban_time, sizeof(unban_time) - 1, "%L", client, "AB_PERMANENT_BAN");
561 }
562 else
563 {
564 GenerateUnbanTime(length, unban_time, sizeof(unban_time) - 1);
565 }
566
567 static admin_name[64], admin_authid[35];
568 get_user_name(client, admin_name, sizeof(admin_name) - 1);
569 get_user_authid(client, admin_authid, sizeof(admin_authid) - 1);
570
571 AddBan(target_name, target_authid, reason, length, unban_time, admin_name, admin_authid);
572
573 PrintBanInformation(client, target_name, target_authid, reason, length, unban_time, "", "", false, false);
574
575 GetBanTime(length, unban_time, sizeof(unban_time) - 1);
576
577 PrintActivity(admin_name, "^x04[TTJogos] $name^x01 :^x03 banned %s %s. Reason: %s. Ban Length: %s", is_ip ? "IP" : "SteamID", target_authid, reason, unban_time);
578
579 Log("%s <%s> banned %s <%s> || Reason: ^"%s^" || Ban Length: %s", admin_name, admin_authid, target_name, target_authid, reason, unban_time);
580
581 return PLUGIN_HANDLED;
582}
583
584public CmdUnban(client, level, cid)
585{
586 if( !cmd_access(client, level, cid, 2) ) return PLUGIN_HANDLED;
587
588 static arg[35];
589 read_argv(1, arg, sizeof(arg) - 1);
590
591 #if MAX_BANS > 0
592 static banned_authid[35];
593 for( new i = 0; i < g_total_bans; i++ )
594 {
595 copy(banned_authid, sizeof(banned_authid) - 1, g_steamids[i]);
596
597 if( equal(arg, banned_authid) )
598 {
599 static admin_name[64];
600 get_user_name(client, admin_name, sizeof(admin_name) - 1);
601
602 static name[32], reason[128];
603 copy(name, sizeof(name) - 1, g_names[i]);
604 copy(reason, sizeof(reason) - 1, g_reasons[i]);
605
606 PrintActivity(admin_name, "^x04[TTJogos] $name^x01 :^x03 unbanned %s^x01 [%s] [Ban Reason: %s]", name, arg, reason);
607
608 static authid[35];
609 get_user_authid(client, authid, sizeof(authid) - 1);
610
611 Log("%s <%s> unbanned %s <%s> || Ban Reason: ^"%s^"", admin_name, authid, name, arg, reason);
612
613 RemoveBan(i);
614
615 return PLUGIN_HANDLED;
616 }
617 }
618 #else
619 if( TrieKeyExists(g_trie, arg) )
620 {
621 static array_pos;
622 TrieGetCell(g_trie, arg, array_pos);
623
624 static data[BannedData];
625 ArrayGetArray(g_array, array_pos, data);
626
627 static unban_name[32];
628 get_user_name(client, unban_name, sizeof(unban_name) - 1);
629
630 PrintActivity(unban_name, "^x04[TTJogos] $name^x01 :^x03 unbanned %s^x01 [%s] [Ban Reason: %s]", data[bd_name], data[bd_steamid], data[bd_reason]);
631
632 static admin_name[64];
633 get_user_name(client, admin_name, sizeof(admin_name) - 1);
634
635 static authid[35];
636 get_user_authid(client, authid, sizeof(authid) - 1);
637
638 Log("%s <%s> unbanned %s <%s> || Ban Reason: ^"%s^"", admin_name, authid, data[bd_name], data[bd_steamid], data[bd_reason]);
639
640 RemoveBan(array_pos, data[bd_steamid]);
641
642 return PLUGIN_HANDLED;
643 }
644 #endif
645
646 console_print(client, "[TTJogos] %L", client, "AB_NOT_IN_BAN_LIST", arg);
647
648 return PLUGIN_HANDLED;
649}
650
651public CmdBanList(client, level, cid)
652{
653 if( !cmd_access(client, level, cid, 1) ) return PLUGIN_HANDLED;
654
655 if( !g_total_bans )
656 {
657 console_print(client, "[TTJogos] %L", client, "AB_NO_BANS");
658 return PLUGIN_HANDLED;
659 }
660
661 static start;
662
663 if( read_argc() > 1 )
664 {
665 static arg[5];
666 read_argv(1, arg, sizeof(arg) - 1);
667
668 start = min(str_to_num(arg), g_total_bans) - 1;
669 }
670 else
671 {
672 start = 0;
673 }
674
675 new last = min(start + 10, g_total_bans);
676
677 if( client == 0 )
678 {
679 server_cmd("echo ^"%L^"", client, "AB_BAN_LIST_NUM", start + 1, last);
680 }
681 else
682 {
683 client_cmd(client, "echo ^"%L^"", client, "AB_BAN_LIST_NUM", start + 1, last);
684 }
685
686 for( new i = start; i < last; i++ )
687 {
688 #if MAX_BANS <= 0
689 static data[BannedData];
690 ArrayGetArray(g_array, i, data);
691
692 PrintBanInformation(client, data[bd_name], data[bd_steamid], data[bd_reason], data[bd_banlength], data[bd_unbantime], data[bd_admin_name], data[bd_admin_steamid], true, false);
693 #else
694 static name[32], steamid[35], reason[128], banlength, unbantime[32], admin_name[32], admin_steamid[35];
695
696 copy(name, sizeof(name) - 1, g_names[i]);
697 copy(steamid, sizeof(steamid) - 1, g_steamids[i]);
698 copy(reason, sizeof(reason) - 1, g_reasons[i]);
699 banlength = g_banlengths[i];
700 copy(unbantime, sizeof(unbantime) - 1, g_unbantimes[i]);
701 copy(admin_name, sizeof(admin_name) - 1, g_admin_names[i]);
702 copy(admin_steamid, sizeof(admin_steamid) - 1, g_admin_steamids[i]);
703
704 PrintBanInformation(client, name, steamid, reason, banlength, unbantime, admin_name, admin_steamid, true, false);
705 #endif
706 }
707
708 if( ++last < g_total_bans )
709 {
710 if( client == 0 )
711 {
712 server_cmd("echo ^"%L^"", client, "AB_BAN_LIST_NEXT", last);
713 }
714 else
715 {
716 client_cmd(client, "echo ^"%L^"", client, "AB_BAN_LIST_NEXT", last);
717 }
718 }
719
720 return PLUGIN_HANDLED;
721}
722
723public CmdAddBanLimit()
724{
725 if( read_argc() != 3 )
726 {
727 log_amx("amx_addbanlimit was used with incorrect parameters!");
728 log_amx("Usage: amx_addbanlimit <flags> <time in minutes>");
729 return PLUGIN_HANDLED;
730 }
731
732 static arg[16];
733
734 read_argv(1, arg, sizeof(arg) - 1);
735 new flags = read_flags(arg);
736
737 read_argv(2, arg, sizeof(arg) - 1);
738 new minutes = str_to_num(arg);
739
740 #if !defined MAX_BANLIMITS
741 ArrayPushCell(g_maxban_flags, flags);
742 ArrayPushCell(g_maxban_times, minutes);
743 #else
744 if( g_total_maxban_times >= MAX_BANLIMITS )
745 {
746 static notified;
747 if( !notified )
748 {
749 log_amx("The amx_addbanlimit has reached its maximum!");
750 notified = 1;
751 }
752 return PLUGIN_HANDLED;
753 }
754
755 g_maxban_flags[g_total_maxban_times] = flags;
756 g_maxban_times[g_total_maxban_times] = minutes;
757 #endif
758 g_total_maxban_times++;
759
760 return PLUGIN_HANDLED;
761}
762
763public FwdThink(entity)
764{
765 if( entity != g_unban_entity ) return;
766
767 #if defined USING_SQL
768 if( g_total_bans > 0 && !g_loading_bans )
769 #else
770 if( g_total_bans > 0 )
771 #endif
772 {
773 static _hours[5], _minutes[5], _seconds[5], _month[5], _day[5], _year[7];
774 format_time(_hours, sizeof(_hours) - 1, "%H");
775 format_time(_minutes, sizeof(_minutes) - 1, "%M");
776 format_time(_seconds, sizeof(_seconds) - 1, "%S");
777 format_time(_month, sizeof(_month) - 1, "%m");
778 format_time(_day, sizeof(_day) - 1, "%d");
779 format_time(_year, sizeof(_year) - 1, "%Y");
780
781 // c = current
782 // u = unban
783
784 new c_hours = str_to_num(_hours);
785 new c_minutes = str_to_num(_minutes);
786 new c_seconds = str_to_num(_seconds);
787 new c_month = str_to_num(_month);
788 new c_day = str_to_num(_day);
789 new c_year = str_to_num(_year);
790
791 static unban_time[32];
792 static u_hours, u_minutes, u_seconds, u_month, u_day, u_year;
793
794 for( new i = 0; i < g_total_bans; i++ )
795 {
796 #if MAX_BANS <= 0
797 static data[BannedData];
798 ArrayGetArray(g_array, i, data);
799
800 if( data[bd_banlength] == 0 ) continue;
801 #else
802 if( g_banlengths[i] == 0 ) continue;
803 #endif
804
805 #if MAX_BANS <= 0
806 copy(unban_time, sizeof(unban_time) - 1, data[bd_unbantime]);
807 #else
808 copy(unban_time, sizeof(unban_time) - 1, g_unbantimes[i]);
809 #endif
810 replace_all(unban_time, sizeof(unban_time) - 1, ":", " ");
811 replace_all(unban_time, sizeof(unban_time) - 1, "/", " ");
812
813 parse(unban_time,\
814 _hours, sizeof(_hours) - 1,\
815 _minutes, sizeof(_minutes) - 1,\
816 _seconds, sizeof(_seconds) - 1,\
817 _month, sizeof(_month) - 1,\
818 _day, sizeof(_day) - 1,\
819 _year, sizeof(_year) - 1
820 );
821
822 u_hours = str_to_num(_hours);
823 u_minutes = str_to_num(_minutes);
824 u_seconds = str_to_num(_seconds);
825 u_month = str_to_num(_month);
826 u_day = str_to_num(_day);
827 u_year = str_to_num(_year);
828
829 if( u_year < c_year
830 || u_year == c_year && u_month < c_month
831 || u_year == c_year && u_month == c_month && u_day < c_day
832 || u_year == c_year && u_month == c_month && u_day == c_day && u_hours < c_hours
833 || u_year == c_year && u_month == c_month && u_day == c_day && u_hours == c_hours && u_minutes < c_minutes
834 || u_year == c_year && u_month == c_month && u_day == c_day && u_hours == c_hours && u_minutes == c_minutes && u_seconds <= c_seconds )
835 {
836 #if MAX_BANS <= 0
837 Log("Ban time is up for: %s [%s]", data[bd_name], data[bd_steamid]);
838
839 Print("^x04[TTJogos]^x03 %s^x01[^x04%s^x01]^x03 ban time is up!^x01 [Ban Reason: %s]", data[bd_name], data[bd_steamid], data[bd_reason]);
840
841 RemoveBan(i, data[bd_steamid]);
842 #else
843 Log("Ban time is up for: %s [%s]", g_names[i], g_steamids[i]);
844
845 Print("^x04[TTJogos]^x03 %s^x01[^x04%s^x01]^x03 ban time is up!^x01 [Ban Reason: %s]", g_names[i], g_steamids[i], g_reasons[i]);
846
847 RemoveBan(i);
848 #endif
849
850 i--; // current pos was replaced with another ban, so we need to check it again.
851 }
852 }
853 }
854
855 entity_set_float(g_unban_entity, EV_FL_nextthink, get_gametime() + get_pcvar_float(ab_unbancheck));
856}
857
858public TaskDisconnectPlayer(client)
859{
860 server_cmd("kick #%i ^"Voce Foi BANIDO, Motivo no console.^"", get_user_userid(client));
861}
862
863AddBan(const target_name[], const target_steamid[], const reason[], const length, const unban_time[], const admin_name[], const admin_steamid[])
864{
865 #if MAX_BANS > 0
866 if( g_total_bans == MAX_BANS )
867 {
868 log_amx("Ban list is full! (%i)", g_total_bans);
869 return;
870 }
871 #endif
872
873 #if defined USING_SQL
874 static target_name2[32], reason2[128], admin_name2[32];
875 MakeStringSQLSafe(target_name, target_name2, sizeof(target_name2) - 1);
876 MakeStringSQLSafe(reason, reason2, sizeof(reason2) - 1);
877 MakeStringSQLSafe(admin_name, admin_name2, sizeof(admin_name2) - 1);
878
879 static query[512];
880 formatex(query, sizeof(query) - 1,\
881 "INSERT INTO `%s` (`%s`, `%s`, `%s`, `%s`, `%s`, `%s`, `%s`) VALUES ('%s', '%s', '%i', '%s', '%s', '%s', '%s');",\
882 TABLE_NAME, KEY_NAME, KEY_STEAMID, KEY_BANLENGTH, KEY_UNBANTIME, KEY_REASON, KEY_ADMIN_NAME, KEY_ADMIN_STEAMID,\
883 target_name2, target_steamid, length, unban_time, reason2, admin_name2, admin_steamid
884 );
885
886 SQL_ThreadQuery(g_sql_tuple, "QueryAddBan", query);
887 #else
888 new f = fopen(g_ban_file, "a+");
889
890 fprintf(f, "^"%s^" ^"%s^" %i ^"%s^" ^"%s^" ^"%s^" ^"%s^"^n",\
891 target_steamid,\
892 target_name,\
893 length,\
894 unban_time,\
895 reason,\
896 admin_name,\
897 admin_steamid
898 );
899
900 fclose(f);
901 #endif
902
903 #if MAX_BANS <= 0
904 static data[BannedData];
905 copy(data[bd_name], sizeof(data[bd_name]) - 1, target_name);
906 copy(data[bd_steamid], sizeof(data[bd_steamid]) - 1, target_steamid);
907 data[bd_banlength] = length;
908 copy(data[bd_unbantime], sizeof(data[bd_unbantime]) - 1, unban_time);
909 copy(data[bd_reason], sizeof(data[bd_reason]) - 1, reason);
910 copy(data[bd_admin_name], sizeof(data[bd_admin_name]) - 1, admin_name);
911 copy(data[bd_admin_steamid], sizeof(data[bd_admin_steamid]) - 1, admin_steamid);
912
913 TrieSetCell(g_trie, target_steamid, g_total_bans);
914 ArrayPushArray(g_array, data);
915 #else
916 copy(g_names[g_total_bans], sizeof(g_names[]) - 1, target_name);
917 copy(g_steamids[g_total_bans], sizeof(g_steamids[]) - 1, target_steamid);
918 g_banlengths[g_total_bans] = length;
919 copy(g_unbantimes[g_total_bans], sizeof(g_unbantimes[]) - 1, unban_time);
920 copy(g_reasons[g_total_bans], sizeof(g_reasons[]) - 1, reason);
921 copy(g_admin_names[g_total_bans], sizeof(g_admin_names[]) - 1, admin_name);
922 copy(g_admin_steamids[g_total_bans], sizeof(g_admin_steamids[]) - 1, admin_steamid);
923 #endif
924
925 g_total_bans++;
926
927 #if MAX_BANS > 0
928 if( g_total_bans == MAX_BANS )
929 {
930 log_amx("Ban list is full! (%i)", g_total_bans);
931 }
932 #endif
933}
934
935#if defined USING_SQL
936public QueryAddBan(failstate, Handle:query, error[], errcode, data[], datasize, Float:queuetime)
937{
938 if( failstate == TQUERY_CONNECT_FAILED )
939 {
940 set_fail_state("Could not connect to database.");
941 }
942 else if( failstate == TQUERY_QUERY_FAILED )
943 {
944 set_fail_state("Query failed.");
945 }
946 else if( errcode )
947 {
948 log_amx("Error on query: %s", error);
949 }
950 else
951 {
952 // Yay, ban was added! We can all rejoice!
953 }
954}
955
956public QueryDeleteBan(failstate, Handle:query, error[], errcode, data[], datasize, Float:queuetime)
957{
958 if( failstate == TQUERY_CONNECT_FAILED )
959 {
960 set_fail_state("Could not connect to database.");
961 }
962 else if( failstate == TQUERY_QUERY_FAILED )
963 {
964 set_fail_state("Query failed.");
965 }
966 else if( errcode )
967 {
968 log_amx("Error on query: %s", error);
969 }
970 else
971 {
972 // Yay, ban was deleted! We can all rejoice!
973 }
974}
975
976public QueryLoadBans(failstate, Handle:query, error[], errcode, data[], datasize, Float:queuetime)
977{
978 if( failstate == TQUERY_CONNECT_FAILED )
979 {
980 set_fail_state("Could not connect to database.");
981 }
982 else if( failstate == TQUERY_QUERY_FAILED )
983 {
984 set_fail_state("Query failed.");
985 }
986 else if( errcode )
987 {
988 log_amx("Error on query: %s", error);
989 }
990 else
991 {
992 if( SQL_NumResults(query) )
993 {
994 #if MAX_BANS <= 0
995 static data[BannedData];
996 while( SQL_MoreResults(query) )
997 #else
998 while( SQL_MoreResults(query) && g_total_bans < MAX_BANS )
999 #endif
1000 {
1001 #if MAX_BANS <= 0
1002 SQL_ReadResult(query, 0, data[bd_name], sizeof(data[bd_name]) - 1);
1003 SQL_ReadResult(query, 1, data[bd_steamid], sizeof(data[bd_steamid]) - 1);
1004 data[bd_banlength] = SQL_ReadResult(query, 2);
1005 SQL_ReadResult(query, 3, data[bd_unbantime], sizeof(data[bd_unbantime]) - 1);
1006 SQL_ReadResult(query, 4, data[bd_reason], sizeof(data[bd_reason]) - 1);
1007 SQL_ReadResult(query, 5, data[bd_admin_name], sizeof(data[bd_admin_name]) - 1);
1008 SQL_ReadResult(query, 6, data[bd_admin_steamid], sizeof(data[bd_admin_steamid]) - 1);
1009
1010 ArrayPushArray(g_array, data);
1011 TrieSetCell(g_trie, data[bd_steamid], g_total_bans);
1012 #else
1013 SQL_ReadResult(query, 0, g_names[g_total_bans], sizeof(g_names[]) - 1);
1014 SQL_ReadResult(query, 1, g_steamids[g_total_bans], sizeof(g_steamids[]) - 1);
1015 g_banlengths[g_total_bans] = SQL_ReadResult(query, 2);
1016 SQL_ReadResult(query, 3, g_unbantimes[g_total_bans], sizeof(g_unbantimes[]) - 1);
1017 SQL_ReadResult(query, 4, g_reasons[g_total_bans], sizeof(g_reasons[]) - 1);
1018 SQL_ReadResult(query, 5, g_admin_names[g_total_bans], sizeof(g_admin_names[]) - 1);
1019 SQL_ReadResult(query, 6, g_admin_steamids[g_total_bans], sizeof(g_admin_steamids[]) - 1);
1020 #endif
1021
1022 g_total_bans++;
1023
1024 SQL_NextRow(query);
1025 }
1026 }
1027
1028 set_task(RELOAD_BANS_INTERVAL, "LoadBans");
1029
1030 g_loading_bans = false;
1031 }
1032}
1033#endif
1034
1035#if MAX_BANS > 0
1036RemoveBan(remove)
1037{
1038 #if defined USING_SQL
1039 static query[128];
1040 formatex(query, sizeof(query) - 1,\
1041 "DELETE FROM `%s` WHERE `%s` = '%s';",\
1042 TABLE_NAME, KEY_STEAMID, g_steamids[remove]
1043 );
1044
1045 SQL_ThreadQuery(g_sql_tuple, "QueryDeleteBan", query);
1046 #endif
1047
1048 for( new i = remove; i < g_total_bans; i++ )
1049 {
1050 if( (i + 1) == g_total_bans )
1051 {
1052 copy(g_names[i], sizeof(g_names[]) - 1, "");
1053 copy(g_steamids[i], sizeof(g_steamids[]) - 1, "");
1054 g_banlengths[i] = 0;
1055 copy(g_unbantimes[i], sizeof(g_unbantimes[]) - 1, "");
1056 copy(g_reasons[i], sizeof(g_reasons[]) - 1, "");
1057 copy(g_admin_names[i], sizeof(g_admin_names[]) - 1, "");
1058 copy(g_admin_steamids[i], sizeof(g_admin_steamids[]) - 1, "");
1059 }
1060 else
1061 {
1062 copy(g_names[i], sizeof(g_names[]) - 1, g_names[i + 1]);
1063 copy(g_steamids[i], sizeof(g_steamids[]) - 1, g_steamids[i + 1]);
1064 g_banlengths[i] = g_banlengths[i + 1];
1065 copy(g_unbantimes[i], sizeof(g_unbantimes[]) - 1, g_unbantimes[i + 1]);
1066 copy(g_reasons[i], sizeof(g_reasons[]) - 1, g_reasons[i + 1]);
1067 copy(g_admin_names[i], sizeof(g_admin_names[]) - 1, g_admin_names[i + 1]);
1068 copy(g_admin_steamids[i], sizeof(g_admin_steamids[]) - 1, g_admin_steamids[i + 1]);
1069 }
1070 }
1071
1072 g_total_bans--;
1073
1074 #if !defined USING_SQL
1075 new f = fopen(g_ban_file, "wt");
1076
1077 static name[32], steamid[35], banlength, unbantime[32], reason[128], admin_name[32], admin_steamid[35];
1078 for( new i = 0; i < g_total_bans; i++ )
1079 {
1080 copy(name, sizeof(name) - 1, g_names[i]);
1081 copy(steamid, sizeof(steamid) - 1, g_steamids[i]);
1082 banlength = g_banlengths[i];
1083 copy(unbantime, sizeof(unbantime) - 1, g_unbantimes[i]);
1084 copy(reason, sizeof(reason) - 1, g_reasons[i]);
1085 copy(admin_name, sizeof(admin_name) - 1, g_admin_names[i]);
1086 copy(admin_steamid, sizeof(admin_steamid) - 1, g_admin_steamids[i]);
1087
1088 fprintf(f, "^"%s^" ^"%s^" %i ^"%s^" ^"%s^" ^"%s^" ^"%s^"^n",\
1089 steamid,\
1090 name,\
1091 banlength,\
1092 unbantime,\
1093 reason,\
1094 admin_name,\
1095 admin_steamid
1096 );
1097 }
1098
1099 fclose(f);
1100 #endif
1101}
1102#else
1103RemoveBan(pos, const authid[])
1104{
1105 TrieDeleteKey(g_trie, authid);
1106 ArrayDeleteItem(g_array, pos);
1107
1108 g_total_bans--;
1109
1110 #if defined USING_SQL
1111 static query[128];
1112 formatex(query, sizeof(query) - 1,\
1113 "DELETE FROM `%s` WHERE `%s` = '%s';",\
1114 TABLE_NAME, KEY_STEAMID, authid
1115 );
1116
1117 SQL_ThreadQuery(g_sql_tuple, "QueryDeleteBan", query);
1118
1119 new data[BannedData];
1120 for( new i = 0; i < g_total_bans; i++ )
1121 {
1122 ArrayGetArray(g_array, i, data);
1123 TrieSetCell(g_trie, data[bd_steamid], i);
1124 }
1125 #else
1126 new f = fopen(g_ban_file, "wt");
1127
1128 new data[BannedData];
1129 for( new i = 0; i < g_total_bans; i++ )
1130 {
1131 ArrayGetArray(g_array, i, data);
1132 TrieSetCell(g_trie, data[bd_steamid], i);
1133
1134 fprintf(f, "^"%s^" ^"%s^" %i ^"%s^" ^"%s^" ^"%s^" ^"%s^"^n",\
1135 data[bd_steamid],\
1136 data[bd_name],\
1137 data[bd_banlength],\
1138 data[bd_unbantime],\
1139 data[bd_reason],\
1140 data[bd_admin_name],\
1141 data[bd_admin_steamid]
1142 );
1143 }
1144
1145 fclose(f);
1146 #endif
1147}
1148#endif
1149
1150#if defined KEEP_DEFAULT_BANS
1151LoadOldBans(filename[])
1152{
1153 if( file_exists(filename) )
1154 {
1155 new f = fopen(filename, "rt");
1156
1157 static data[96];
1158 static command[10], minutes[10], steamid[35], length, unban_time[32];
1159
1160 while( !feof(f) )
1161 {
1162 fgets(f, data, sizeof(data) - 1);
1163 if( !data[0] ) continue;
1164
1165 parse(data, command, sizeof(command) - 1, minutes, sizeof(minutes) - 1, steamid, sizeof(steamid) - 1);
1166 if( filename[0] == 'b' && !equali(command, "banid") || filename[0] == 'l' && !equali(command, "addip") ) continue;
1167
1168 length = str_to_num(minutes);
1169 GenerateUnbanTime(length, unban_time, sizeof(unban_time) - 1);
1170
1171 AddBan("", steamid, "", length, unban_time, "", "");
1172 }
1173
1174 fclose(f);
1175
1176 static filename2[32];
1177
1178 // copy current
1179 copy(filename2, sizeof(filename2) - 1, filename);
1180
1181 // cut off at the "."
1182 // banned.cfg = banned
1183 // listip.cfg = listip
1184 filename2[containi(filename2, ".")] = 0;
1185
1186 // add 2.cfg
1187 // banned = banned2.cfg
1188 // listip = listip2.cfg
1189 add(filename2, sizeof(filename2) - 1, "2.cfg");
1190
1191 // rename file so that it isnt loaded again
1192 while( !rename_file(filename, filename2, 1) ) { }
1193 }
1194}
1195#endif
1196
1197public LoadBans()
1198{
1199 if( g_total_bans )
1200 {
1201 #if MAX_BANS <= 0
1202 TrieClear(g_trie);
1203 ArrayClear(g_array);
1204 #endif
1205
1206 g_total_bans = 0;
1207 }
1208
1209 #if defined USING_SQL
1210 static query[128];
1211 formatex(query, sizeof(query) - 1,\
1212 "SELECT * FROM `%s`;",\
1213 TABLE_NAME
1214 );
1215
1216 SQL_ThreadQuery(g_sql_tuple, "QueryLoadBans", query);
1217
1218 g_loading_bans = true;
1219 #else
1220 if( file_exists(g_ban_file) )
1221 {
1222 new f = fopen(g_ban_file, "rt");
1223
1224 static filedata[512], length[10];
1225
1226 #if MAX_BANS <= 0
1227 static data[BannedData];
1228 while( !feof(f) )
1229 #else
1230 while( !feof(f) && g_total_bans < MAX_BANS )
1231 #endif
1232 {
1233 fgets(f, filedata, sizeof(filedata) - 1);
1234
1235 if( !filedata[0] ) continue;
1236
1237 #if MAX_BANS <= 0
1238 parse(filedata,\
1239 data[bd_steamid], sizeof(data[bd_steamid]) - 1,\
1240 data[bd_name], sizeof(data[bd_name]) - 1,\
1241 length, sizeof(length) - 1,\
1242 data[bd_unbantime], sizeof(data[bd_unbantime]) - 1,\
1243 data[bd_reason], sizeof(data[bd_reason]) - 1,\
1244 data[bd_admin_name], sizeof(data[bd_admin_name]) - 1,\
1245 data[bd_admin_steamid], sizeof(data[bd_admin_steamid]) - 1
1246 );
1247
1248 data[bd_banlength] = str_to_num(length);
1249
1250 ArrayPushArray(g_array, data);
1251 TrieSetCell(g_trie, data[bd_steamid], g_total_bans);
1252 #else
1253 static steamid[35], name[32], unbantime[32], reason[128], admin_name[32], admin_steamid[35];
1254
1255 parse(filedata,\
1256 steamid, sizeof(steamid) - 1,\
1257 name, sizeof(name) - 1,\
1258 length, sizeof(length) - 1,\
1259 unbantime, sizeof(unbantime) - 1,\
1260 reason, sizeof(reason) - 1,\
1261 admin_name, sizeof(admin_name) - 1,\
1262 admin_steamid, sizeof(admin_steamid) - 1
1263 );
1264
1265 copy(g_names[g_total_bans], sizeof(g_names[]) - 1, name);
1266 copy(g_steamids[g_total_bans], sizeof(g_steamids[]) - 1, steamid);
1267 g_banlengths[g_total_bans] = str_to_num(length);
1268 copy(g_unbantimes[g_total_bans], sizeof(g_unbantimes[]) - 1, unbantime);
1269 copy(g_reasons[g_total_bans], sizeof(g_reasons[]) - 1, reason);
1270 copy(g_admin_names[g_total_bans], sizeof(g_admin_names[]) - 1, admin_name);
1271 copy(g_admin_steamids[g_total_bans], sizeof(g_admin_steamids[]) - 1, admin_steamid);
1272 #endif
1273
1274 g_total_bans++;
1275 }
1276
1277 fclose(f);
1278 }
1279 #endif
1280
1281 // load these after, so when they are added to the file with AddBan(), they aren't loaded again from above.
1282
1283 #if defined KEEP_DEFAULT_BANS
1284 LoadOldBans("banned.cfg");
1285 LoadOldBans("listip.cfg");
1286 #endif
1287}
1288
1289#if defined USING_SQL
1290MakeStringSQLSafe(const input[], output[], len)
1291{
1292 copy(output, len, input);
1293 replace_all(output, len, "'", "*");
1294 replace_all(output, len, "^"", "*");
1295 replace_all(output, len, "`", "*");
1296}
1297#endif
1298
1299GetBanTime(const bantime, length[], len)
1300{
1301 new minutes = bantime;
1302 new hours = 0;
1303 new days = 0;
1304
1305 while( minutes >= 60 )
1306 {
1307 minutes -= 60;
1308 hours++;
1309 }
1310
1311 while( hours >= 24 )
1312 {
1313 hours -= 24;
1314 days++;
1315 }
1316
1317 new bool:add_before;
1318 if( minutes )
1319 {
1320 formatex(length, len, "%i minute%s", minutes, minutes == 1 ? "" : "s");
1321
1322 add_before = true;
1323 }
1324 if( hours )
1325 {
1326 if( add_before )
1327 {
1328 format(length, len, "%i hour%s, %s", hours, hours == 1 ? "" : "s", length);
1329 }
1330 else
1331 {
1332 formatex(length, len, "%i hour%s", hours, hours == 1 ? "" : "s");
1333
1334 add_before = true;
1335 }
1336 }
1337 if( days )
1338 {
1339 if( add_before )
1340 {
1341 format(length, len, "%i day%s, %s", days, days == 1 ? "" : "s", length);
1342 }
1343 else
1344 {
1345 formatex(length, len, "%i day%s", days, days == 1 ? "" : "s");
1346
1347 add_before = true;
1348 }
1349 }
1350 if( !add_before )
1351 {
1352 // minutes, hours, and days = 0
1353 // assume permanent ban
1354 copy(length, len, "Permanent Ban");
1355 }
1356}
1357
1358GenerateUnbanTime(const bantime, unban_time[], len)
1359{
1360 static _hours[5], _minutes[5], _seconds[5], _month[5], _day[5], _year[7];
1361 format_time(_hours, sizeof(_hours) - 1, "%H");
1362 format_time(_minutes, sizeof(_minutes) - 1, "%M");
1363 format_time(_seconds, sizeof(_seconds) - 1, "%S");
1364 format_time(_month, sizeof(_month) - 1, "%m");
1365 format_time(_day, sizeof(_day) - 1, "%d");
1366 format_time(_year, sizeof(_year) - 1, "%Y");
1367
1368 new hours = str_to_num(_hours);
1369 new minutes = str_to_num(_minutes);
1370 new seconds = str_to_num(_seconds);
1371 new month = str_to_num(_month);
1372 new day = str_to_num(_day);
1373 new year = str_to_num(_year);
1374
1375 minutes += bantime;
1376
1377 while( minutes >= 60 )
1378 {
1379 minutes -= 60;
1380 hours++;
1381 }
1382
1383 while( hours >= 24 )
1384 {
1385 hours -= 24;
1386 day++;
1387 }
1388
1389 new max_days = GetDaysInMonth(month, year);
1390 while( day > max_days )
1391 {
1392 day -= max_days;
1393 month++;
1394 }
1395
1396 while( month > 12 )
1397 {
1398 month -= 12;
1399 year++;
1400 }
1401
1402 formatex(unban_time, len, "%i:%02i:%02i %i/%i/%i", hours, minutes, seconds, month, day, year);
1403}
1404
1405GetDaysInMonth(month, year=0)
1406{
1407 switch( month )
1408 {
1409 case 1: return 31; // january
1410 case 2: return ((year % 4) == 0) ? 29 : 28; // february
1411 case 3: return 31; // march
1412 case 4: return 30; // april
1413 case 5: return 31; // may
1414 case 6: return 30; // june
1415 case 7: return 31; // july
1416 case 8: return 31; // august
1417 case 9: return 30; // september
1418 case 10: return 31; // october
1419 case 11: return 30; // november
1420 case 12: return 31; // december
1421 }
1422
1423 return 30;
1424}
1425
1426GetTargetFlags(client)
1427{
1428 static const flags_no_immunity = (CMDTARGET_ALLOW_SELF|CMDTARGET_NO_BOTS);
1429 static const flags_immunity = (CMDTARGET_ALLOW_SELF|CMDTARGET_NO_BOTS|CMDTARGET_OBEY_IMMUNITY);
1430
1431 switch( get_pcvar_num(ab_immunity) )
1432 {
1433 case 1: return flags_immunity;
1434 case 2: return access(client, ADMIN_IMMUNITY) ? flags_no_immunity : flags_immunity;
1435 }
1436
1437 return flags_no_immunity;
1438}
1439
1440GetMaxBanTime(client)
1441{
1442 if( !g_total_maxban_times ) return 0;
1443
1444 new flags = get_user_flags(client);
1445
1446 for( new i = 0; i < g_total_maxban_times; i++ )
1447 {
1448 #if !defined MAX_BANLIMITS
1449 if( flags & ArrayGetCell(g_maxban_flags, i) )
1450 {
1451 return ArrayGetCell(g_maxban_times, i);
1452 }
1453 #else
1454 if( flags & g_maxban_flags[i] )
1455 {
1456 return g_maxban_times[i];
1457 }
1458 #endif
1459 }
1460
1461 return 0;
1462}
1463
1464PrintBanInformation(client, const target_name[], const target_authid[], const reason[], const length, const unban_time[], const admin_name[], const admin_authid[], bool:show_admin, bool:show_website)
1465{
1466 static website[64], ban_length[64];
1467 if( client == 0 )
1468 {
1469 server_print("************************************************");
1470 server_print("%L", client, "AB_BAN_INFORMATION");
1471 server_print("%L: %s", client, "AB_NAME", target_name);
1472 server_print("%L: %s", client, IsValidAuthid(target_authid) ? "AB_STEAMID" : "AB_IP", target_authid);
1473 server_print("%L: %s", client, "AB_REASON", reason);
1474 if( length > 0 )
1475 {
1476 GetBanTime(length, ban_length, sizeof(ban_length) - 1);
1477 server_print("%L: %s", client, "AB_BAN_LENGTH", ban_length);
1478 }
1479 server_print("%L: %s", client, "AB_UNBAN_TIME", unban_time);
1480 if( show_admin )
1481 {
1482 server_print("%L: %s", client, "AB_ADMIN_NAME", admin_name);
1483 server_print("%L: %s", client, "AB_ADMIN_STEAMID", admin_authid);
1484 }
1485 if( show_website )
1486 {
1487 get_pcvar_string(ab_website, website, sizeof(website) - 1);
1488 if( website[0] )
1489 {
1490 server_print("");
1491 server_print("%L", client, "AB_WEBSITE");
1492 server_print("%s", website);
1493 }
1494 }
1495 server_print("************************************************");
1496 }
1497 else
1498 {
1499 client_cmd(client, "echo ^"************************************************^"");
1500 client_cmd(client, "echo ^"%L^"", client, "AB_BAN_INFORMATION");
1501 client_cmd(client, "echo ^"%L: %s^"", client, "AB_NAME", target_name);
1502 client_cmd(client, "echo ^"%L: %s^"", client, IsValidAuthid(target_authid) ? "AB_STEAMID" : "AB_IP", target_authid);
1503 client_cmd(client, "echo ^"%L: %s^"", client, "AB_REASON", reason);
1504 if( length > 0 )
1505 {
1506 GetBanTime(length, ban_length, sizeof(ban_length) - 1);
1507 client_cmd(client, "echo ^"%L: %s^"", client, "AB_BAN_LENGTH", ban_length);
1508 }
1509 client_cmd(client, "echo ^"%L: %s^"", client, "AB_UNBAN_TIME", unban_time);
1510 if( show_admin )
1511 {
1512 client_cmd(client, "echo ^"%L: %s^"", client, "AB_ADMIN_NAME", admin_name);
1513 client_cmd(client, "echo ^"%L: %s^"", client, "AB_ADMIN_STEAMID", admin_authid);
1514 }
1515 if( show_website )
1516 {
1517 get_pcvar_string(ab_website, website, sizeof(website) - 1);
1518 if( website[0] )
1519 {
1520 client_cmd(client, "echo ^"^"");
1521 client_cmd(client, "echo ^"%L^"", client, "AB_WEBSITE");
1522 client_cmd(client, "echo ^"%s^"", website);
1523 }
1524 }
1525 client_cmd(client, "echo ^"************************************************^"");
1526 }
1527}
1528
1529PrintActivity(const admin_name[], const message_fmt[], any:...)
1530{
1531 if( !get_playersnum() ) return;
1532
1533 new activity = get_pcvar_num(amx_show_activity);
1534 if( !(0 <= activity <= 5) )
1535 {
1536 set_pcvar_num(amx_show_activity, (activity = 2));
1537 }
1538
1539 static message[192], temp[192];
1540 vformat(message, sizeof(message) - 1, message_fmt, 3);
1541
1542 for( new client = 1; client <= g_max_clients; client++ )
1543 {
1544 if( !is_user_connected(client) ) continue;
1545
1546 switch( is_user_admin(client) ? g_admin_activity[activity] : g_normal_activity[activity] )
1547 {
1548 case ACTIVITY_NONE:
1549 {
1550
1551 }
1552 case ACTIVITY_HIDE:
1553 {
1554 copy(temp, sizeof(temp) - 1, message);
1555 replace(temp, sizeof(temp) - 1, "$name", "ADMIN");
1556
1557 message_begin(MSG_ONE_UNRELIABLE, g_msgid_SayText, _, client);
1558 write_byte(client);
1559 write_string(temp);
1560 message_end();
1561 }
1562 case ACTIVITY_SHOW:
1563 {
1564 copy(temp, sizeof(temp) - 1, message);
1565 replace(temp, sizeof(temp) - 1, "$name", admin_name);
1566
1567 message_begin(MSG_ONE_UNRELIABLE, g_msgid_SayText, _, client);
1568 write_byte(client);
1569 write_string(temp);
1570 message_end();
1571 }
1572 }
1573 }
1574}
1575
1576Print(const message_fmt[], any:...)
1577{
1578 if( !get_playersnum() ) return;
1579
1580 static message[192];
1581 vformat(message, sizeof(message) - 1, message_fmt, 2);
1582
1583 for( new client = 1; client <= g_max_clients; client++ )
1584 {
1585 if( !is_user_connected(client) ) continue;
1586
1587 message_begin(MSG_ONE_UNRELIABLE, g_msgid_SayText, _, client);
1588 write_byte(client);
1589 write_string(message);
1590 message_end();
1591 }
1592}
1593
1594Log(const message_fmt[], any:...)
1595{
1596 static message[256];
1597 vformat(message, sizeof(message) - 1, message_fmt, 2);
1598
1599 static filename[96];
1600 #if defined HISTORY_ONE_FILE
1601 if( !filename[0] )
1602 {
1603 get_basedir(filename, sizeof(filename) - 1);
1604 add(filename, sizeof(filename) - 1, "/logs/ban_history.log");
1605 }
1606 #else
1607 static dir[64];
1608 if( !dir[0] )
1609 {
1610 get_basedir(dir, sizeof(dir) - 1);
1611 add(dir, sizeof(dir) - 1, "/logs");
1612 }
1613
1614 format_time(filename, sizeof(filename) - 1, "%m%d%Y");
1615 format(filename, sizeof(filename) - 1, "%s/BAN_HISTORY_%s.log", dir, filename);
1616 #endif
1617
1618 log_amx("%s", message);
1619 log_to_file(filename, "%s", message);
1620}