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