· 6 years ago · May 12, 2019, 01:40 AM
1#include <amxmodx>
2#include <amxmisc>
3#include <engine>
4#include <regex>
5
6#define PLUGIN_NAME "Advanced Bans"
7#define PLUGIN_VERSION "0.8.1"
8#define PLUGIN_AUTHOR "Exolent"
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 "advanced_bans"
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 30
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> <time in minutes> <reason>");
170 register_concmd("amx_banip", "CmdBanIp", ADMIN_BAN, "<nick, #userid, authid> <time in minutes> <reason>");
171 register_concmd("amx_addban", "CmdAddBan", ADMIN_BAN, "<name> <authid or ip> <time in minutes> <reason>");
172 register_concmd("amx_unban", "CmdUnban", ADMIN_BAN, "<authid or ip>");
173 register_concmd("amx_banlist", "CmdBanList", ADMIN_BAN, "[start] -- shows everyone who is banned");
174 register_srvcmd("amx_addbanlimit", "CmdAddBanLimit", -1, "<flag> <time in minutes>");
175
176 ab_website = register_cvar("ab_website", "");
177 ab_immunity = register_cvar("ab_immunity", "1");
178 ab_bandelay = register_cvar("ab_bandelay", "5.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, "[AdvancedBans] %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, "[AdvancedBans] %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, "[AdvancedBans] %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, "[AdvancedBans] %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 set_hudmessage(0, 255, 0, 0.01, 0.18, 1, 6.0, 12.0)
403 show_hudmessage(0, "O Player %s foi banido por %s seu ban acaba em %s", target_name, arg, unban_time)
404
405 Log("%s <%s> banned %s <%s> || Reason: ^"%s^" || Ban Length: %s", admin_name, admin_authid, target_name, target_authid, arg, unban_time);
406
407 return PLUGIN_HANDLED;
408}
409
410public CmdBanIp(client, level, cid)
411{
412 if( !cmd_access(client, level, cid, 4) ) return PLUGIN_HANDLED;
413
414 static arg[128];
415 read_argv(1, arg, sizeof(arg) - 1);
416
417 new target = cmd_target(client, arg, GetTargetFlags(client));
418 if( !target ) return PLUGIN_HANDLED;
419
420 static target_ip[35];
421 get_user_ip(target, target_ip, sizeof(target_ip) - 1, 1);
422
423 #if MAX_BANS <= 0
424 if( TrieKeyExists(g_trie, target_ip) )
425 {
426 console_print(client, "[AdvancedBans] %L", client, "AB_ALREADY_BANNED_IP");
427 return PLUGIN_HANDLED;
428 }
429 #else
430 for( new i = 0; i < g_total_bans; i++ )
431 {
432 if( !strcmp(target_ip, g_steamids[i], 1) )
433 {
434 console_print(client, "[AdvancedBans] %L", client, "AB_ALREADY_BANNED_IP");
435 return PLUGIN_HANDLED;
436 }
437 }
438 #endif
439
440 read_argv(2, arg, sizeof(arg) - 1);
441
442 new length = str_to_num(arg);
443 new maxlength = GetMaxBanTime(client);
444
445 if( maxlength && (!length || length > maxlength) )
446 {
447 console_print(client, "[AdvancedBans] %L", client, "AB_MAX_BAN_TIME", maxlength);
448 return PLUGIN_HANDLED;
449 }
450
451 static unban_time[32];
452
453 if( length == 0 )
454 {
455 formatex(unban_time, sizeof(unban_time) - 1, "%L", client, "AB_PERMANENT_BAN");
456 }
457 else
458 {
459 GenerateUnbanTime(length, unban_time, sizeof(unban_time) - 1);
460 }
461
462 read_argv(3, arg, sizeof(arg) - 1);
463
464 static admin_name[64], target_name[32];
465 get_user_name(client, admin_name, sizeof(admin_name) - 1);
466 get_user_name(target, target_name, sizeof(target_name) - 1);
467
468 static admin_authid[35];
469 get_user_authid(client, admin_authid, sizeof(admin_authid) - 1);
470
471 AddBan(target_name, target_ip, arg, length, unban_time, admin_name, admin_authid);
472
473 PrintBanInformation(target, target_name, target_ip, arg, length, unban_time, admin_name, admin_authid, true, true);
474 PrintBanInformation(client, target_name, target_ip, arg, length, unban_time, admin_name, admin_authid, false, false);
475
476 set_task(get_pcvar_float(ab_bandelay), "TaskDisconnectPlayer", target);
477
478 GetBanTime(length, unban_time, sizeof(unban_time) - 1);
479
480 PrintActivity(admin_name, "^x04[ZPBR] $name^x01 :^x03 Baniu %s. Motivo: %s. Expira em: %s", target_name, arg, unban_time);
481
482 Log("%s <%s> banned %s <%s> || Reason: ^"%s^" || Ban Length: %s", admin_name, admin_authid, target_name, target_ip, arg, unban_time);
483
484 return PLUGIN_HANDLED;
485}
486
487public CmdAddBan(client, level, cid)
488{
489 if( !cmd_access(client, level, cid, 5) ) return PLUGIN_HANDLED;
490
491 static target_name[32], target_authid[35], bantime[10], reason[128];
492 read_argv(1, target_name, sizeof(target_name) - 1);
493 read_argv(2, target_authid, sizeof(target_authid) - 1);
494 read_argv(3, bantime, sizeof(bantime) - 1);
495 read_argv(4, reason, sizeof(reason) - 1);
496
497 new bool:is_ip = bool:(containi(target_authid, ".") != -1);
498
499 if( !is_ip && !IsValidAuthid(target_authid) )
500 {
501 console_print(client, "[AdvancedBans] %L", client, "AB_INVALID_STEAMID");
502 console_print(client, "[AdvancedBans] %L", client, "AB_VALID_STEAMID_FORMAT");
503
504 return PLUGIN_HANDLED;
505 }
506 else if( is_ip )
507 {
508 new pos = contain(target_authid, ":");
509 if( pos > 0 )
510 {
511 target_authid[pos] = 0;
512 }
513
514 if( !IsValidIP(target_authid) )
515 {
516 console_print(client, "[AdvancedBans] %L", client, "AB_INVALID_IP");
517
518 return PLUGIN_HANDLED;
519 }
520 }
521
522 #if MAX_BANS <= 0
523 if( TrieKeyExists(g_trie, target_authid) )
524 {
525 console_print(client, "[AdvancedBans] %L", client, is_ip ? "AB_ALREADY_BANNED_IP" : "AB_ALREADY_BANNED_STEAMID");
526 return PLUGIN_HANDLED;
527 }
528 #else
529 for( new i = 0; i < g_total_bans; i++ )
530 {
531 if( !strcmp(target_authid, g_steamids[i], 1) )
532 {
533 console_print(client, "[AdvancedBans] %L", client, is_ip ? "AB_ALREADY_BANNED_IP" : "AB_ALREADY_BANNED_STEAMID");
534 return PLUGIN_HANDLED;
535 }
536 }
537 #endif
538
539 new length = str_to_num(bantime);
540 new maxlength = GetMaxBanTime(client);
541
542 if( maxlength && (!length || length > maxlength) )
543 {
544 console_print(client, "[AdvancedBans] %L", client, "AB_MAX_BAN_TIME", maxlength);
545 return PLUGIN_HANDLED;
546 }
547
548 if( is_user_connected(find_player(is_ip ? "d" : "c", target_authid)) )
549 {
550 client_cmd(client, "amx_ban ^"%s^" %i ^"%s^"", target_authid, length, reason);
551 return PLUGIN_HANDLED;
552 }
553
554 static unban_time[32];
555 if( length == 0 )
556 {
557 formatex(unban_time, sizeof(unban_time) - 1, "%L", client, "AB_PERMANENT_BAN");
558 }
559 else
560 {
561 GenerateUnbanTime(length, unban_time, sizeof(unban_time) - 1);
562 }
563
564 static admin_name[64], admin_authid[35];
565 get_user_name(client, admin_name, sizeof(admin_name) - 1);
566 get_user_authid(client, admin_authid, sizeof(admin_authid) - 1);
567
568 AddBan(target_name, target_authid, reason, length, unban_time, admin_name, admin_authid);
569
570 PrintBanInformation(client, target_name, target_authid, reason, length, unban_time, "", "", false, false);
571
572 GetBanTime(length, unban_time, sizeof(unban_time) - 1);
573
574 PrintActivity(admin_name, "^x04[ZPBR] $name^x01 :^x03 Baniu %s %s. Motivo: %s. Expira em: %s", is_ip ? "IP" : "SteamID", target_authid, reason, unban_time);
575
576 Log("%s <%s> banned %s <%s> || Reason: ^"%s^" || Ban Length: %s", admin_name, admin_authid, target_name, target_authid, reason, unban_time);
577
578 return PLUGIN_HANDLED;
579}
580
581public CmdUnban(client, level, cid)
582{
583 if( !cmd_access(client, level, cid, 2) ) return PLUGIN_HANDLED;
584
585 static arg[35];
586 read_argv(1, arg, sizeof(arg) - 1);
587
588 #if MAX_BANS > 0
589 static banned_authid[35];
590 for( new i = 0; i < g_total_bans; i++ )
591 {
592 copy(banned_authid, sizeof(banned_authid) - 1, g_steamids[i]);
593
594 if( equal(arg, banned_authid) )
595 {
596 static admin_name[64];
597 get_user_name(client, admin_name, sizeof(admin_name) - 1);
598
599 static name[32], reason[128];
600 copy(name, sizeof(name) - 1, g_names[i]);
601 copy(reason, sizeof(reason) - 1, g_reasons[i]);
602
603 PrintActivity(admin_name, "^x04[ZPBR] $name^x01 :^x03 Desbaniu %s^x01 [%s] [Motivo: %s]", name, arg, reason);
604
605 static authid[35];
606 get_user_authid(client, authid, sizeof(authid) - 1);
607
608 Log("%s <%s> unbanned %s <%s> || Ban Reason: ^"%s^"", admin_name, authid, name, arg, reason);
609
610 RemoveBan(i);
611
612 return PLUGIN_HANDLED;
613 }
614 }
615 #else
616 if( TrieKeyExists(g_trie, arg) )
617 {
618 static array_pos;
619 TrieGetCell(g_trie, arg, array_pos);
620
621 static data[BannedData];
622 ArrayGetArray(g_array, array_pos, data);
623
624 static unban_name[32];
625 get_user_name(client, unban_name, sizeof(unban_name) - 1);
626
627 PrintActivity(unban_name, "^x04[ZPBR] $name^x01 :^x03 Desbaniu %s^x01 [%s] [Motivo: %s]", data[bd_name], data[bd_steamid], data[bd_reason]);
628
629 static admin_name[64];
630 get_user_name(client, admin_name, sizeof(admin_name) - 1);
631
632 static authid[35];
633 get_user_authid(client, authid, sizeof(authid) - 1);
634
635 Log("%s <%s> unbanned %s <%s> || Ban Reason: ^"%s^"", admin_name, authid, data[bd_name], data[bd_steamid], data[bd_reason]);
636
637 RemoveBan(array_pos, data[bd_steamid]);
638
639 return PLUGIN_HANDLED;
640 }
641 #endif
642
643 console_print(client, "[AdvancedBans] %L", client, "AB_NOT_IN_BAN_LIST", arg);
644
645 return PLUGIN_HANDLED;
646}
647
648public CmdBanList(client, level, cid)
649{
650 if( !cmd_access(client, level, cid, 1) ) return PLUGIN_HANDLED;
651
652 if( !g_total_bans )
653 {
654 console_print(client, "[AdvancedBans] %L", client, "AB_NO_BANS");
655 return PLUGIN_HANDLED;
656 }
657
658 static start;
659
660 if( read_argc() > 1 )
661 {
662 static arg[5];
663 read_argv(1, arg, sizeof(arg) - 1);
664
665 start = min(str_to_num(arg), g_total_bans) - 1;
666 }
667 else
668 {
669 start = 0;
670 }
671
672 new last = min(start + 10, g_total_bans);
673
674 if( client == 0 )
675 {
676 server_cmd("echo ^"%L^"", client, "AB_BAN_LIST_NUM", start + 1, last);
677 }
678 else
679 {
680 client_cmd(client, "echo ^"%L^"", client, "AB_BAN_LIST_NUM", start + 1, last);
681 }
682
683 for( new i = start; i < last; i++ )
684 {
685 #if MAX_BANS <= 0
686 static data[BannedData];
687 ArrayGetArray(g_array, i, data);
688
689 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);
690 #else
691 static name[32], steamid[35], reason[128], banlength, unbantime[32], admin_name[32], admin_steamid[35];
692
693 copy(name, sizeof(name) - 1, g_names[i]);
694 copy(steamid, sizeof(steamid) - 1, g_steamids[i]);
695 copy(reason, sizeof(reason) - 1, g_reasons[i]);
696 banlength = g_banlengths[i];
697 copy(unbantime, sizeof(unbantime) - 1, g_unbantimes[i]);
698 copy(admin_name, sizeof(admin_name) - 1, g_admin_names[i]);
699 copy(admin_steamid, sizeof(admin_steamid) - 1, g_admin_steamids[i]);
700
701 PrintBanInformation(client, name, steamid, reason, banlength, unbantime, admin_name, admin_steamid, true, false);
702 #endif
703 }
704
705 if( ++last < g_total_bans )
706 {
707 if( client == 0 )
708 {
709 server_cmd("echo ^"%L^"", client, "AB_BAN_LIST_NEXT", last);
710 }
711 else
712 {
713 client_cmd(client, "echo ^"%L^"", client, "AB_BAN_LIST_NEXT", last);
714 }
715 }
716
717 return PLUGIN_HANDLED;
718}
719
720public CmdAddBanLimit()
721{
722 if( read_argc() != 3 )
723 {
724 log_amx("amx_addbanlimit was used with incorrect parameters!");
725 log_amx("Usage: amx_addbanlimit <flags> <time in minutes>");
726 return PLUGIN_HANDLED;
727 }
728
729 static arg[16];
730
731 read_argv(1, arg, sizeof(arg) - 1);
732 new flags = read_flags(arg);
733
734 read_argv(2, arg, sizeof(arg) - 1);
735 new minutes = str_to_num(arg);
736
737 #if !defined MAX_BANLIMITS
738 ArrayPushCell(g_maxban_flags, flags);
739 ArrayPushCell(g_maxban_times, minutes);
740 #else
741 if( g_total_maxban_times >= MAX_BANLIMITS )
742 {
743 static notified;
744 if( !notified )
745 {
746 log_amx("The amx_addbanlimit has reached its maximum!");
747 notified = 1;
748 }
749 return PLUGIN_HANDLED;
750 }
751
752 g_maxban_flags[g_total_maxban_times] = flags;
753 g_maxban_times[g_total_maxban_times] = minutes;
754 #endif
755 g_total_maxban_times++;
756
757 return PLUGIN_HANDLED;
758}
759
760public FwdThink(entity)
761{
762 if( entity != g_unban_entity ) return;
763
764 #if defined USING_SQL
765 if( g_total_bans > 0 && !g_loading_bans )
766 #else
767 if( g_total_bans > 0 )
768 #endif
769 {
770 static _hours[5], _minutes[5], _seconds[5], _month[5], _day[5], _year[7];
771 format_time(_hours, sizeof(_hours) - 1, "%H");
772 format_time(_minutes, sizeof(_minutes) - 1, "%M");
773 format_time(_seconds, sizeof(_seconds) - 1, "%S");
774 format_time(_month, sizeof(_month) - 1, "%m");
775 format_time(_day, sizeof(_day) - 1, "%d");
776 format_time(_year, sizeof(_year) - 1, "%Y");
777
778 // c = current
779 // u = unban
780
781 new c_hours = str_to_num(_hours);
782 new c_minutes = str_to_num(_minutes);
783 new c_seconds = str_to_num(_seconds);
784 new c_month = str_to_num(_month);
785 new c_day = str_to_num(_day);
786 new c_year = str_to_num(_year);
787
788 static unban_time[32];
789 static u_hours, u_minutes, u_seconds, u_month, u_day, u_year;
790
791 for( new i = 0; i < g_total_bans; i++ )
792 {
793 #if MAX_BANS <= 0
794 static data[BannedData];
795 ArrayGetArray(g_array, i, data);
796
797 if( data[bd_banlength] == 0 ) continue;
798 #else
799 if( g_banlengths[i] == 0 ) continue;
800 #endif
801
802 #if MAX_BANS <= 0
803 copy(unban_time, sizeof(unban_time) - 1, data[bd_unbantime]);
804 #else
805 copy(unban_time, sizeof(unban_time) - 1, g_unbantimes[i]);
806 #endif
807 replace_all(unban_time, sizeof(unban_time) - 1, ":", " ");
808 replace_all(unban_time, sizeof(unban_time) - 1, "/", " ");
809
810 parse(unban_time,\
811 _hours, sizeof(_hours) - 1,\
812 _minutes, sizeof(_minutes) - 1,\
813 _seconds, sizeof(_seconds) - 1,\
814 _month, sizeof(_month) - 1,\
815 _day, sizeof(_day) - 1,\
816 _year, sizeof(_year) - 1
817 );
818
819 u_hours = str_to_num(_hours);
820 u_minutes = str_to_num(_minutes);
821 u_seconds = str_to_num(_seconds);
822 u_month = str_to_num(_month);
823 u_day = str_to_num(_day);
824 u_year = str_to_num(_year);
825
826 if( u_year < c_year
827 || u_year == c_year && u_month < c_month
828 || u_year == c_year && u_month == c_month && u_day < c_day
829 || u_year == c_year && u_month == c_month && u_day == c_day && u_hours < c_hours
830 || u_year == c_year && u_month == c_month && u_day == c_day && u_hours == c_hours && u_minutes < c_minutes
831 || u_year == c_year && u_month == c_month && u_day == c_day && u_hours == c_hours && u_minutes == c_minutes && u_seconds <= c_seconds )
832 {
833 #if MAX_BANS <= 0
834 Log("Ban time is up for: %s [%s]", data[bd_name], data[bd_steamid]);
835
836 Print("^x04[AdvancedBans]^x03 %s^x01[^x04%s^x01]^x03 ban time is up!^x01 [Ban Reason: %s]", data[bd_name], data[bd_steamid], data[bd_reason]);
837
838 RemoveBan(i, data[bd_steamid]);
839 #else
840 Log("Ban time is up for: %s [%s]", g_names[i], g_steamids[i]);
841
842 Print("^x04[AdvancedBans]^x03 %s^x01[^x04%s^x01]^x03 ban time is up!^x01 [Ban Reason: %s]", g_names[i], g_steamids[i], g_reasons[i]);
843
844 RemoveBan(i);
845 #endif
846
847 i--; // current pos was replaced with another ban, so we need to check it again.
848 }
849 }
850 }
851
852 entity_set_float(g_unban_entity, EV_FL_nextthink, get_gametime() + get_pcvar_float(ab_unbancheck));
853}
854
855public TaskDisconnectPlayer(client)
856{
857 server_cmd("kick #%i ^"You are banned from this server. Check your console^"", get_user_userid(client));
858}
859
860AddBan(const target_name[], const target_steamid[], const reason[], const length, const unban_time[], const admin_name[], const admin_steamid[])
861{
862 #if MAX_BANS > 0
863 if( g_total_bans == MAX_BANS )
864 {
865 log_amx("Ban list is full! (%i)", g_total_bans);
866 return;
867 }
868 #endif
869
870 #if defined USING_SQL
871 static target_name2[32], reason2[128], admin_name2[32];
872 MakeStringSQLSafe(target_name, target_name2, sizeof(target_name2) - 1);
873 MakeStringSQLSafe(reason, reason2, sizeof(reason2) - 1);
874 MakeStringSQLSafe(admin_name, admin_name2, sizeof(admin_name2) - 1);
875
876 static query[512];
877 formatex(query, sizeof(query) - 1,\
878 "INSERT INTO `%s` (`%s`, `%s`, `%s`, `%s`, `%s`, `%s`, `%s`) VALUES ('%s', '%s', '%i', '%s', '%s', '%s', '%s');",\
879 TABLE_NAME, KEY_NAME, KEY_STEAMID, KEY_BANLENGTH, KEY_UNBANTIME, KEY_REASON, KEY_ADMIN_NAME, KEY_ADMIN_STEAMID,\
880 target_name2, target_steamid, length, unban_time, reason2, admin_name2, admin_steamid
881 );
882
883 SQL_ThreadQuery(g_sql_tuple, "QueryAddBan", query);
884 #else
885 new f = fopen(g_ban_file, "a+");
886
887 fprintf(f, "^"%s^" ^"%s^" %i ^"%s^" ^"%s^" ^"%s^" ^"%s^"^n",\
888 target_steamid,\
889 target_name,\
890 length,\
891 unban_time,\
892 reason,\
893 admin_name,\
894 admin_steamid
895 );
896
897 fclose(f);
898 #endif
899
900 #if MAX_BANS <= 0
901 static data[BannedData];
902 copy(data[bd_name], sizeof(data[bd_name]) - 1, target_name);
903 copy(data[bd_steamid], sizeof(data[bd_steamid]) - 1, target_steamid);
904 data[bd_banlength] = length;
905 copy(data[bd_unbantime], sizeof(data[bd_unbantime]) - 1, unban_time);
906 copy(data[bd_reason], sizeof(data[bd_reason]) - 1, reason);
907 copy(data[bd_admin_name], sizeof(data[bd_admin_name]) - 1, admin_name);
908 copy(data[bd_admin_steamid], sizeof(data[bd_admin_steamid]) - 1, admin_steamid);
909
910 TrieSetCell(g_trie, target_steamid, g_total_bans);
911 ArrayPushArray(g_array, data);
912 #else
913 copy(g_names[g_total_bans], sizeof(g_names[]) - 1, target_name);
914 copy(g_steamids[g_total_bans], sizeof(g_steamids[]) - 1, target_steamid);
915 g_banlengths[g_total_bans] = length;
916 copy(g_unbantimes[g_total_bans], sizeof(g_unbantimes[]) - 1, unban_time);
917 copy(g_reasons[g_total_bans], sizeof(g_reasons[]) - 1, reason);
918 copy(g_admin_names[g_total_bans], sizeof(g_admin_names[]) - 1, admin_name);
919 copy(g_admin_steamids[g_total_bans], sizeof(g_admin_steamids[]) - 1, admin_steamid);
920 #endif
921
922 g_total_bans++;
923
924 #if MAX_BANS > 0
925 if( g_total_bans == MAX_BANS )
926 {
927 log_amx("Ban list is full! (%i)", g_total_bans);
928 }
929 #endif
930}
931
932#if defined USING_SQL
933public QueryAddBan(failstate, Handle:query, error[], errcode, data[], datasize, Float:queuetime)
934{
935 if( failstate == TQUERY_CONNECT_FAILED )
936 {
937 set_fail_state("Could not connect to database.");
938 }
939 else if( failstate == TQUERY_QUERY_FAILED )
940 {
941 set_fail_state("Query failed.");
942 }
943 else if( errcode )
944 {
945 log_amx("Error on query: %s", error);
946 }
947 else
948 {
949 // Yay, ban was added! We can all rejoice!
950 }
951}
952
953public QueryDeleteBan(failstate, Handle:query, error[], errcode, data[], datasize, Float:queuetime)
954{
955 if( failstate == TQUERY_CONNECT_FAILED )
956 {
957 set_fail_state("Could not connect to database.");
958 }
959 else if( failstate == TQUERY_QUERY_FAILED )
960 {
961 set_fail_state("Query failed.");
962 }
963 else if( errcode )
964 {
965 log_amx("Error on query: %s", error);
966 }
967 else
968 {
969 // Yay, ban was deleted! We can all rejoice!
970 }
971}
972
973public QueryLoadBans(failstate, Handle:query, error[], errcode, data[], datasize, Float:queuetime)
974{
975 if( failstate == TQUERY_CONNECT_FAILED )
976 {
977 set_fail_state("Could not connect to database.");
978 }
979 else if( failstate == TQUERY_QUERY_FAILED )
980 {
981 set_fail_state("Query failed.");
982 }
983 else if( errcode )
984 {
985 log_amx("Error on query: %s", error);
986 }
987 else
988 {
989 if( SQL_NumResults(query) )
990 {
991 #if MAX_BANS <= 0
992 static data[BannedData];
993 while( SQL_MoreResults(query) )
994 #else
995 while( SQL_MoreResults(query) && g_total_bans < MAX_BANS )
996 #endif
997 {
998 #if MAX_BANS <= 0
999 SQL_ReadResult(query, 0, data[bd_name], sizeof(data[bd_name]) - 1);
1000 SQL_ReadResult(query, 1, data[bd_steamid], sizeof(data[bd_steamid]) - 1);
1001 data[bd_banlength] = SQL_ReadResult(query, 2);
1002 SQL_ReadResult(query, 3, data[bd_unbantime], sizeof(data[bd_unbantime]) - 1);
1003 SQL_ReadResult(query, 4, data[bd_reason], sizeof(data[bd_reason]) - 1);
1004 SQL_ReadResult(query, 5, data[bd_admin_name], sizeof(data[bd_admin_name]) - 1);
1005 SQL_ReadResult(query, 6, data[bd_admin_steamid], sizeof(data[bd_admin_steamid]) - 1);
1006
1007 ArrayPushArray(g_array, data);
1008 TrieSetCell(g_trie, data[bd_steamid], g_total_bans);
1009 #else
1010 SQL_ReadResult(query, 0, g_names[g_total_bans], sizeof(g_names[]) - 1);
1011 SQL_ReadResult(query, 1, g_steamids[g_total_bans], sizeof(g_steamids[]) - 1);
1012 g_banlengths[g_total_bans] = SQL_ReadResult(query, 2);
1013 SQL_ReadResult(query, 3, g_unbantimes[g_total_bans], sizeof(g_unbantimes[]) - 1);
1014 SQL_ReadResult(query, 4, g_reasons[g_total_bans], sizeof(g_reasons[]) - 1);
1015 SQL_ReadResult(query, 5, g_admin_names[g_total_bans], sizeof(g_admin_names[]) - 1);
1016 SQL_ReadResult(query, 6, g_admin_steamids[g_total_bans], sizeof(g_admin_steamids[]) - 1);
1017 #endif
1018
1019 g_total_bans++;
1020
1021 SQL_NextRow(query);
1022 }
1023 }
1024
1025 set_task(RELOAD_BANS_INTERVAL, "LoadBans");
1026
1027 g_loading_bans = false;
1028 }
1029}
1030#endif
1031
1032#if MAX_BANS > 0
1033RemoveBan(remove)
1034{
1035 #if defined USING_SQL
1036 static query[128];
1037 formatex(query, sizeof(query) - 1,\
1038 "DELETE FROM `%s` WHERE `%s` = '%s';",\
1039 TABLE_NAME, KEY_STEAMID, g_steamids[remove]
1040 );
1041
1042 SQL_ThreadQuery(g_sql_tuple, "QueryDeleteBan", query);
1043 #endif
1044
1045 for( new i = remove; i < g_total_bans; i++ )
1046 {
1047 if( (i + 1) == g_total_bans )
1048 {
1049 copy(g_names[i], sizeof(g_names[]) - 1, "");
1050 copy(g_steamids[i], sizeof(g_steamids[]) - 1, "");
1051 g_banlengths[i] = 0;
1052 copy(g_unbantimes[i], sizeof(g_unbantimes[]) - 1, "");
1053 copy(g_reasons[i], sizeof(g_reasons[]) - 1, "");
1054 copy(g_admin_names[i], sizeof(g_admin_names[]) - 1, "");
1055 copy(g_admin_steamids[i], sizeof(g_admin_steamids[]) - 1, "");
1056 }
1057 else
1058 {
1059 copy(g_names[i], sizeof(g_names[]) - 1, g_names[i + 1]);
1060 copy(g_steamids[i], sizeof(g_steamids[]) - 1, g_steamids[i + 1]);
1061 g_banlengths[i] = g_banlengths[i + 1];
1062 copy(g_unbantimes[i], sizeof(g_unbantimes[]) - 1, g_unbantimes[i + 1]);
1063 copy(g_reasons[i], sizeof(g_reasons[]) - 1, g_reasons[i + 1]);
1064 copy(g_admin_names[i], sizeof(g_admin_names[]) - 1, g_admin_names[i + 1]);
1065 copy(g_admin_steamids[i], sizeof(g_admin_steamids[]) - 1, g_admin_steamids[i + 1]);
1066 }
1067 }
1068
1069 g_total_bans--;
1070
1071 #if !defined USING_SQL
1072 new f = fopen(g_ban_file, "wt");
1073
1074 static name[32], steamid[35], banlength, unbantime[32], reason[128], admin_name[32], admin_steamid[35];
1075 for( new i = 0; i < g_total_bans; i++ )
1076 {
1077 copy(name, sizeof(name) - 1, g_names[i]);
1078 copy(steamid, sizeof(steamid) - 1, g_steamids[i]);
1079 banlength = g_banlengths[i];
1080 copy(unbantime, sizeof(unbantime) - 1, g_unbantimes[i]);
1081 copy(reason, sizeof(reason) - 1, g_reasons[i]);
1082 copy(admin_name, sizeof(admin_name) - 1, g_admin_names[i]);
1083 copy(admin_steamid, sizeof(admin_steamid) - 1, g_admin_steamids[i]);
1084
1085 fprintf(f, "^"%s^" ^"%s^" %i ^"%s^" ^"%s^" ^"%s^" ^"%s^"^n",\
1086 steamid,\
1087 name,\
1088 banlength,\
1089 unbantime,\
1090 reason,\
1091 admin_name,\
1092 admin_steamid
1093 );
1094 }
1095
1096 fclose(f);
1097 #endif
1098}
1099#else
1100RemoveBan(pos, const authid[])
1101{
1102 TrieDeleteKey(g_trie, authid);
1103 ArrayDeleteItem(g_array, pos);
1104
1105 g_total_bans--;
1106
1107 #if defined USING_SQL
1108 static query[128];
1109 formatex(query, sizeof(query) - 1,\
1110 "DELETE FROM `%s` WHERE `%s` = '%s';",\
1111 TABLE_NAME, KEY_STEAMID, authid
1112 );
1113
1114 SQL_ThreadQuery(g_sql_tuple, "QueryDeleteBan", query);
1115
1116 new data[BannedData];
1117 for( new i = 0; i < g_total_bans; i++ )
1118 {
1119 ArrayGetArray(g_array, i, data);
1120 TrieSetCell(g_trie, data[bd_steamid], i);
1121 }
1122 #else
1123 new f = fopen(g_ban_file, "wt");
1124
1125 new data[BannedData];
1126 for( new i = 0; i < g_total_bans; i++ )
1127 {
1128 ArrayGetArray(g_array, i, data);
1129 TrieSetCell(g_trie, data[bd_steamid], i);
1130
1131 fprintf(f, "^"%s^" ^"%s^" %i ^"%s^" ^"%s^" ^"%s^" ^"%s^"^n",\
1132 data[bd_steamid],\
1133 data[bd_name],\
1134 data[bd_banlength],\
1135 data[bd_unbantime],\
1136 data[bd_reason],\
1137 data[bd_admin_name],\
1138 data[bd_admin_steamid]
1139 );
1140 }
1141
1142 fclose(f);
1143 #endif
1144}
1145#endif
1146
1147#if defined KEEP_DEFAULT_BANS
1148LoadOldBans(filename[])
1149{
1150 if( file_exists(filename) )
1151 {
1152 new f = fopen(filename, "rt");
1153
1154 static data[96];
1155 static command[10], minutes[10], steamid[35], length, unban_time[32];
1156
1157 while( !feof(f) )
1158 {
1159 fgets(f, data, sizeof(data) - 1);
1160 if( !data[0] ) continue;
1161
1162 parse(data, command, sizeof(command) - 1, minutes, sizeof(minutes) - 1, steamid, sizeof(steamid) - 1);
1163 if( filename[0] == 'b' && !equali(command, "banid") || filename[0] == 'l' && !equali(command, "addip") ) continue;
1164
1165 length = str_to_num(minutes);
1166 GenerateUnbanTime(length, unban_time, sizeof(unban_time) - 1);
1167
1168 AddBan("", steamid, "", length, unban_time, "", "");
1169 }
1170
1171 fclose(f);
1172
1173 static filename2[32];
1174
1175 // copy current
1176 copy(filename2, sizeof(filename2) - 1, filename);
1177
1178 // cut off at the "."
1179 // banned.cfg = banned
1180 // listip.cfg = listip
1181 filename2[containi(filename2, ".")] = 0;
1182
1183 // add 2.cfg
1184 // banned = banned2.cfg
1185 // listip = listip2.cfg
1186 add(filename2, sizeof(filename2) - 1, "2.cfg");
1187
1188 // rename file so that it isnt loaded again
1189 while( !rename_file(filename, filename2, 1) ) { }
1190 }
1191}
1192#endif
1193
1194public LoadBans()
1195{
1196 if( g_total_bans )
1197 {
1198 #if MAX_BANS <= 0
1199 TrieClear(g_trie);
1200 ArrayClear(g_array);
1201 #endif
1202
1203 g_total_bans = 0;
1204 }
1205
1206 #if defined USING_SQL
1207 static query[128];
1208 formatex(query, sizeof(query) - 1,\
1209 "SELECT * FROM `%s`;",\
1210 TABLE_NAME
1211 );
1212
1213 SQL_ThreadQuery(g_sql_tuple, "QueryLoadBans", query);
1214
1215 g_loading_bans = true;
1216 #else
1217 if( file_exists(g_ban_file) )
1218 {
1219 new f = fopen(g_ban_file, "rt");
1220
1221 static filedata[512], length[10];
1222
1223 #if MAX_BANS <= 0
1224 static data[BannedData];
1225 while( !feof(f) )
1226 #else
1227 while( !feof(f) && g_total_bans < MAX_BANS )
1228 #endif
1229 {
1230 fgets(f, filedata, sizeof(filedata) - 1);
1231
1232 if( !filedata[0] ) continue;
1233
1234 #if MAX_BANS <= 0
1235 parse(filedata,\
1236 data[bd_steamid], sizeof(data[bd_steamid]) - 1,\
1237 data[bd_name], sizeof(data[bd_name]) - 1,\
1238 length, sizeof(length) - 1,\
1239 data[bd_unbantime], sizeof(data[bd_unbantime]) - 1,\
1240 data[bd_reason], sizeof(data[bd_reason]) - 1,\
1241 data[bd_admin_name], sizeof(data[bd_admin_name]) - 1,\
1242 data[bd_admin_steamid], sizeof(data[bd_admin_steamid]) - 1
1243 );
1244
1245 data[bd_banlength] = str_to_num(length);
1246
1247 ArrayPushArray(g_array, data);
1248 TrieSetCell(g_trie, data[bd_steamid], g_total_bans);
1249 #else
1250 static steamid[35], name[32], unbantime[32], reason[128], admin_name[32], admin_steamid[35];
1251
1252 parse(filedata,\
1253 steamid, sizeof(steamid) - 1,\
1254 name, sizeof(name) - 1,\
1255 length, sizeof(length) - 1,\
1256 unbantime, sizeof(unbantime) - 1,\
1257 reason, sizeof(reason) - 1,\
1258 admin_name, sizeof(admin_name) - 1,\
1259 admin_steamid, sizeof(admin_steamid) - 1
1260 );
1261
1262 copy(g_names[g_total_bans], sizeof(g_names[]) - 1, name);
1263 copy(g_steamids[g_total_bans], sizeof(g_steamids[]) - 1, steamid);
1264 g_banlengths[g_total_bans] = str_to_num(length);
1265 copy(g_unbantimes[g_total_bans], sizeof(g_unbantimes[]) - 1, unbantime);
1266 copy(g_reasons[g_total_bans], sizeof(g_reasons[]) - 1, reason);
1267 copy(g_admin_names[g_total_bans], sizeof(g_admin_names[]) - 1, admin_name);
1268 copy(g_admin_steamids[g_total_bans], sizeof(g_admin_steamids[]) - 1, admin_steamid);
1269 #endif
1270
1271 g_total_bans++;
1272 }
1273
1274 fclose(f);
1275 }
1276 #endif
1277
1278 // load these after, so when they are added to the file with AddBan(), they aren't loaded again from above.
1279
1280 #if defined KEEP_DEFAULT_BANS
1281 LoadOldBans("banned.cfg");
1282 LoadOldBans("listip.cfg");
1283 #endif
1284}
1285
1286#if defined USING_SQL
1287MakeStringSQLSafe(const input[], output[], len)
1288{
1289 copy(output, len, input);
1290 replace_all(output, len, "'", "*");
1291 replace_all(output, len, "^"", "*");
1292 replace_all(output, len, "`", "*");
1293}
1294#endif
1295
1296GetBanTime(const bantime, length[], len)
1297{
1298 new minutes = bantime;
1299 new hours = 0;
1300 new days = 0;
1301
1302 while( minutes >= 60 )
1303 {
1304 minutes -= 60;
1305 hours++;
1306 }
1307
1308 while( hours >= 24 )
1309 {
1310 hours -= 24;
1311 days++;
1312 }
1313
1314 new bool:add_before;
1315 if( minutes )
1316 {
1317 formatex(length, len, "%i minute%s", minutes, minutes == 1 ? "" : "s");
1318
1319 add_before = true;
1320 }
1321 if( hours )
1322 {
1323 if( add_before )
1324 {
1325 format(length, len, "%i hour%s, %s", hours, hours == 1 ? "" : "s", length);
1326 }
1327 else
1328 {
1329 formatex(length, len, "%i hour%s", hours, hours == 1 ? "" : "s");
1330
1331 add_before = true;
1332 }
1333 }
1334 if( days )
1335 {
1336 if( add_before )
1337 {
1338 format(length, len, "%i day%s, %s", days, days == 1 ? "" : "s", length);
1339 }
1340 else
1341 {
1342 formatex(length, len, "%i day%s", days, days == 1 ? "" : "s");
1343
1344 add_before = true;
1345 }
1346 }
1347 if( !add_before )
1348 {
1349 // minutes, hours, and days = 0
1350 // assume permanent ban
1351 copy(length, len, "Permanent Ban");
1352 }
1353}
1354
1355GenerateUnbanTime(const bantime, unban_time[], len)
1356{
1357 static _hours[5], _minutes[5], _seconds[5], _month[5], _day[5], _year[7];
1358 format_time(_hours, sizeof(_hours) - 1, "%H");
1359 format_time(_minutes, sizeof(_minutes) - 1, "%M");
1360 format_time(_seconds, sizeof(_seconds) - 1, "%S");
1361 format_time(_month, sizeof(_month) - 1, "%m");
1362 format_time(_day, sizeof(_day) - 1, "%d");
1363 format_time(_year, sizeof(_year) - 1, "%Y");
1364
1365 new hours = str_to_num(_hours);
1366 new minutes = str_to_num(_minutes);
1367 new seconds = str_to_num(_seconds);
1368 new month = str_to_num(_month);
1369 new day = str_to_num(_day);
1370 new year = str_to_num(_year);
1371
1372 minutes += bantime;
1373
1374 while( minutes >= 60 )
1375 {
1376 minutes -= 60;
1377 hours++;
1378 }
1379
1380 while( hours >= 24 )
1381 {
1382 hours -= 24;
1383 day++;
1384 }
1385
1386 new max_days = GetDaysInMonth(month, year);
1387 while( day > max_days )
1388 {
1389 day -= max_days;
1390 month++;
1391 }
1392
1393 while( month > 12 )
1394 {
1395 month -= 12;
1396 year++;
1397 }
1398
1399 formatex(unban_time, len, "%i:%02i:%02i %i/%i/%i", hours, minutes, seconds, month, day, year);
1400}
1401
1402GetDaysInMonth(month, year=0)
1403{
1404 switch( month )
1405 {
1406 case 1: return 31; // january
1407 case 2: return ((year % 4) == 0) ? 29 : 28; // february
1408 case 3: return 31; // march
1409 case 4: return 30; // april
1410 case 5: return 31; // may
1411 case 6: return 30; // june
1412 case 7: return 31; // july
1413 case 8: return 31; // august
1414 case 9: return 30; // september
1415 case 10: return 31; // october
1416 case 11: return 30; // november
1417 case 12: return 31; // december
1418 }
1419
1420 return 30;
1421}
1422
1423GetTargetFlags(client)
1424{
1425 static const flags_no_immunity = (CMDTARGET_ALLOW_SELF|CMDTARGET_NO_BOTS);
1426 static const flags_immunity = (CMDTARGET_ALLOW_SELF|CMDTARGET_NO_BOTS|CMDTARGET_OBEY_IMMUNITY);
1427
1428 switch( get_pcvar_num(ab_immunity) )
1429 {
1430 case 1: return flags_immunity;
1431 case 2: return access(client, ADMIN_IMMUNITY) ? flags_no_immunity : flags_immunity;
1432 }
1433
1434 return flags_no_immunity;
1435}
1436
1437GetMaxBanTime(client)
1438{
1439 if( !g_total_maxban_times ) return 0;
1440
1441 new flags = get_user_flags(client);
1442
1443 for( new i = 0; i < g_total_maxban_times; i++ )
1444 {
1445 #if !defined MAX_BANLIMITS
1446 if( flags & ArrayGetCell(g_maxban_flags, i) )
1447 {
1448 return ArrayGetCell(g_maxban_times, i);
1449 }
1450 #else
1451 if( flags & g_maxban_flags[i] )
1452 {
1453 return g_maxban_times[i];
1454 }
1455 #endif
1456 }
1457
1458 return 0;
1459}
1460
1461PrintBanInformation(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)
1462{
1463 static website[64], ban_length[64];
1464 if( client == 0 )
1465 {
1466 server_print("************************************************");
1467 server_print("%L", client, "AB_BAN_INFORMATION");
1468 server_print("%L: %s", client, "AB_NAME", target_name);
1469 server_print("%L: %s", client, IsValidAuthid(target_authid) ? "AB_STEAMID" : "AB_IP", target_authid);
1470 server_print("%L: %s", client, "AB_REASON", reason);
1471 if( length > 0 )
1472 {
1473 GetBanTime(length, ban_length, sizeof(ban_length) - 1);
1474 server_print("%L: %s", client, "AB_BAN_LENGTH", ban_length);
1475 }
1476 server_print("%L: %s", client, "AB_UNBAN_TIME", unban_time);
1477 if( show_admin )
1478 {
1479 server_print("%L: %s", client, "AB_ADMIN_NAME", admin_name);
1480 server_print("%L: %s", client, "AB_ADMIN_STEAMID", admin_authid);
1481 }
1482 if( show_website )
1483 {
1484 get_pcvar_string(ab_website, website, sizeof(website) - 1);
1485 if( website[0] )
1486 {
1487 server_print("");
1488 server_print("%L", client, "AB_WEBSITE");
1489 server_print("%s", website);
1490 }
1491 }
1492 server_print("************************************************");
1493 }
1494 else
1495 {
1496 client_cmd(client, "echo ^"************************************************^"");
1497 client_cmd(client, "echo ^"%L^"", client, "AB_BAN_INFORMATION");
1498 client_cmd(client, "echo ^"%L: %s^"", client, "AB_NAME", target_name);
1499 client_cmd(client, "echo ^"%L: %s^"", client, IsValidAuthid(target_authid) ? "AB_STEAMID" : "AB_IP", target_authid);
1500 client_cmd(client, "echo ^"%L: %s^"", client, "AB_REASON", reason);
1501 if( length > 0 )
1502 {
1503 GetBanTime(length, ban_length, sizeof(ban_length) - 1);
1504 client_cmd(client, "echo ^"%L: %s^"", client, "AB_BAN_LENGTH", ban_length);
1505 }
1506 client_cmd(client, "echo ^"%L: %s^"", client, "AB_UNBAN_TIME", unban_time);
1507 if( show_admin )
1508 {
1509 client_cmd(client, "echo ^"%L: %s^"", client, "AB_ADMIN_NAME", admin_name);
1510 client_cmd(client, "echo ^"%L: %s^"", client, "AB_ADMIN_STEAMID", admin_authid);
1511 }
1512 if( show_website )
1513 {
1514 get_pcvar_string(ab_website, website, sizeof(website) - 1);
1515 if( website[0] )
1516 {
1517 client_cmd(client, "echo ^"^"");
1518 client_cmd(client, "echo ^"%L^"", client, "AB_WEBSITE");
1519 client_cmd(client, "echo ^"%s^"", website);
1520 }
1521 }
1522 client_cmd(client, "echo ^"************************************************^"");
1523 }
1524}
1525
1526PrintActivity(const admin_name[], const message_fmt[], any:...)
1527{
1528 if( !get_playersnum() ) return;
1529
1530 new activity = get_pcvar_num(amx_show_activity);
1531 if( !(0 <= activity <= 5) )
1532 {
1533 set_pcvar_num(amx_show_activity, (activity = 2));
1534 }
1535
1536 static message[192], temp[192];
1537 vformat(message, sizeof(message) - 1, message_fmt, 3);
1538
1539 for( new client = 1; client <= g_max_clients; client++ )
1540 {
1541 if( !is_user_connected(client) ) continue;
1542
1543 switch( is_user_admin(client) ? g_admin_activity[activity] : g_normal_activity[activity] )
1544 {
1545 case ACTIVITY_NONE:
1546 {
1547
1548 }
1549 case ACTIVITY_HIDE:
1550 {
1551 copy(temp, sizeof(temp) - 1, message);
1552 replace(temp, sizeof(temp) - 1, "$name", "ADMIN");
1553
1554 message_begin(MSG_ONE_UNRELIABLE, g_msgid_SayText, _, client);
1555 write_byte(client);
1556 write_string(temp);
1557 message_end();
1558 }
1559 case ACTIVITY_SHOW:
1560 {
1561 copy(temp, sizeof(temp) - 1, message);
1562 replace(temp, sizeof(temp) - 1, "$name", admin_name);
1563
1564 message_begin(MSG_ONE_UNRELIABLE, g_msgid_SayText, _, client);
1565 write_byte(client);
1566 write_string(temp);
1567 message_end();
1568 }
1569 }
1570 }
1571}
1572
1573Print(const message_fmt[], any:...)
1574{
1575 if( !get_playersnum() ) return;
1576
1577 static message[192];
1578 vformat(message, sizeof(message) - 1, message_fmt, 2);
1579
1580 for( new client = 1; client <= g_max_clients; client++ )
1581 {
1582 if( !is_user_connected(client) ) continue;
1583
1584 message_begin(MSG_ONE_UNRELIABLE, g_msgid_SayText, _, client);
1585 write_byte(client);
1586 write_string(message);
1587 message_end();
1588 }
1589}
1590
1591Log(const message_fmt[], any:...)
1592{
1593 static message[256];
1594 vformat(message, sizeof(message) - 1, message_fmt, 2);
1595
1596 static filename[96];
1597 #if defined HISTORY_ONE_FILE
1598 if( !filename[0] )
1599 {
1600 get_basedir(filename, sizeof(filename) - 1);
1601 add(filename, sizeof(filename) - 1, "/logs/ban_history.log");
1602 }
1603 #else
1604 static dir[64];
1605 if( !dir[0] )
1606 {
1607 get_basedir(dir, sizeof(dir) - 1);
1608 add(dir, sizeof(dir) - 1, "/logs");
1609 }
1610
1611 format_time(filename, sizeof(filename) - 1, "%m%d%Y");
1612 format(filename, sizeof(filename) - 1, "%s/BAN_HISTORY_%s.log", dir, filename);
1613 #endif
1614
1615 log_amx("%s", message);
1616 log_to_file(filename, "%s", message);
1617}
1618/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
1619*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1033\\ f0\\ fs16 \n\\ par }
1620*/