· 8 years ago · Feb 10, 2018, 11:06 PM
1/*
2
3 Advanced Bans
4
5
6
7 Version 0.8.1
8
9
10
11 by Exolent
12
13
14
15
16
17
18
19 Plugin Thread:
20
21
22
23 - http://forums.alliedmods.net/showthread.php?t=80858
24
25
26
27
28
29
30
31 Description:
32
33
34
35 - This plugin revamps the current amx_ban, amx_banip, amx_banid, amx_unban admin commands.
36
37
38
39 - It uses Real Time on the server
40
41 (Eg. Banned for 10 minutes, you will be unbanned 10 minutes later, regardless of map changing).
42
43
44
45 - It includes a list of who is banned.
46
47
48
49 - It does not use the banned.cfg or listip.cfg. It uses its own file where bans are stored.
50
51
52
53 - It saves what admin banned the player (name), the admin's steamid, the reason, the ban time,
54
55 the banned player's name, the banned player's steamid (or IP), and the estimated time of unban.
56
57
58
59 - It will load your currently banned players from the banned.cfg and listip.cfg files.
60
61 (Only if the #define below is uncommented)
62
63
64
65 - If you use the menu to ban players, you will have to type a reason after you choose a player.
66
67
68
69 - If you use the vote system to ban players, you will have to type a reason after you execute the amx_voteban command.
70
71
72
73 - You can limit the ban time for admins based on their admin flags.
74
75
76
77 - You can monitor all ban history (admins banning, unbanning, and when ban times are up) in
78
79 the addons/amxmodx/logs/BAN_HISTORY_MMDDYYYY.log (MM = month, DD = day, YYYY = year)
80
81
82
83 - If you wish to have only 1 file for ban history, uncomment the line at the top of the .sma file and recompile.
84
85
86
87 - Supports SQL for banning.
88
89
90
91
92
93
94
95 Commands:
96
97
98
99 - amx_ban <nick, #userid, authid> <time in minutes> <reason>
100
101
102
103 - amx_banip <nick, #userid, authid> <time in minutes> <reason>
104
105
106
107 - amx_addban <name> <authid or ip> <time in minutes> <reason>
108
109
110
111 - amx_unban <authid or ip>
112
113
114
115 - amx_banlist
116
117 - Shows a list of who is banned
118
119
120
121 - amx_addbanlimit <flags> <time in minutes>
122
123 - Adds a max ban time to the list
124
125 - Note: Use this command in the amxx.cfg
126
127
128
129
130
131
132
133 Cvars:
134
135
136
137 - ab_website <website>
138
139 - This is the website displayed to the banned player if you have an unban request section on your website.
140
141 - Leave blank to not show a website.
142
143 - Default: blank
144
145
146
147 - ab_immunity <0|1|2>
148
149 - 0 - Any admin can ban an immunity admin (flag 'a').
150
151 - 1 - Immunity admins (flag 'a') cannot be banned.
152
153 - 2 - Immunity admins (flag 'a') can only be banned by other immunity admins (flag 'a').
154
155 - Default: 1
156
157
158
159 - ab_bandelay <seconds>
160
161 - Delay of banned players being disconnected.
162
163 - Default: 1
164
165
166
167 - ab_unbancheck <seconds>
168
169 - Interval of checking if a player is unbanned.
170
171 - Default: 5
172
173
174
175
176
177
178
179 Requirements:
180
181
182
183 - AMX Mod X version 1.8.0 or higher
184
185
186
187
188
189
190
191 Changelog:
192
193
194
195 - Version 0.1 (with updates included)
196
197 - Initial Release
198
199 - Changed to dynamic arrays to hold ban information
200
201 - Added option #2 for ab_immunity
202
203 - Added support for banning by IP
204
205 - Added compatability for banned.cfg and listip.cfg
206
207 - Added menu support (plmenu.amxx)
208
209 - Added ML support
210
211
212
213 - Version 0.2
214
215 - Added simple max ban time feature
216
217
218
219 - Version 0.3
220
221 - Added more cvars for max ban times
222
223 - Added cvar for delay of player to disconenct after being banned
224
225 - Added cvar for interval of checking for unban time of banned players
226
227 - Added more translations
228
229
230
231 - Version 0.4
232
233 - Fixed the possible infinite loop, causing servers to crash
234
235 - Added ban history
236
237 - Removed max ban time cvars
238
239 - Added max ban times per admin flags
240
241 - Added more translations
242
243
244
245 - Version 0.5
246
247 - Fixed information not being printed into console
248
249 - Fixed "amx_addban" using the admin's name as the SteamID when saving the ban
250
251 - Added option for ban history to be one file
252
253 - Added translations
254
255
256
257 - Version 0.5b
258
259 - Fixed players not being unbanned
260
261 - Added translations
262
263
264
265 - Version 0.6
266
267 - Added small optimization for unban checking
268
269 - Changed "UnBan Time" in the logs and chat messages to "Ban Length"
270
271 - Fixed small code error where unban time was generated was used when length was 0
272
273 - Changed IsValidIP() method to use regex (Thanks to arkshine)
274
275 - Added plugin information inside the .sma file
276
277 - Added a #define option to use maximum bans for compatability for AMXX < 1.8.0
278
279 - Changed admin messages in chat to work with amx_show_activity cvar
280
281 - Added translations
282
283
284
285 - Version 0.6b
286
287 - Fixed a small bug
288
289
290
291 - Version 0.6c
292
293 - Fixed amx_banlist for server consoles
294
295 - Changed IsValidAuthid() method to use regex
296
297
298
299 - Version 0.6d
300
301 - Fixed ban limit for permanent bans
302
303
304
305 - Version 0.7
306
307 - Changed the "unlimited bans" version to be faster (Thanks to joaquimandrade)
308
309 - Added check when adding bans if the player is already banned.
310
311
312
313 - Version 0.8
314
315 - Added SQL support.
316
317
318
319 - Version 0.8.1
320
321 - Added unban logging for non-SQL version
322
323
324
325
326
327
328
329 Notes:
330
331
332
333 - If you plan to use this plugin, go to the plugin's thread.
334
335
336
337 - The plugin's thread has more information about the plugin, along with the multilingual file.
338
339
340
341 - It also has a modified plmenu.amxx plugin that adds the ban reason to the menu.
342
343
344
345 - And it has a modified adminvote.amxx plugin that adds the ban reason to amx_voteban.
346
347*/
348
349
350
351
352
353
354
355#include <amxmodx>
356
357#include <amxmisc>
358
359#include <engine>
360
361#include <regex>
362
363
364
365#define PLUGIN_NAME "Advanced Bans"
366
367#define PLUGIN_VERSION "0.8.1"
368
369#define PLUGIN_AUTHOR "Exolent"
370
371
372
373#pragma semicolon 1
374
375
376
377
378
379
380
381// ===============================================
382
383// CUSTOMIZATION STARTS HERE
384
385// ===============================================
386
387
388
389
390
391// uncomment the line below if you want this plugin to
392
393// load old bans from the banned.cfg and listip.cfg files
394
395//#define KEEP_DEFAULT_BANS
396
397
398
399
400
401// uncomment the line below if you want the history to be in one file
402
403//#define HISTORY_ONE_FILE
404
405
406
407
408
409// if you must have a maximum amount of bans to be compatible with AMXX versions before 1.8.0
410
411// change this number to your maximum amount
412
413// if you would rather have unlimited (requires AMXX 1.8.0 or higher) then set it to 0
414
415#define MAX_BANS 0
416
417
418
419
420
421// if you want to use SQL for your server, then uncomment the line below
422
423//#define USING_SQL
424
425
426
427
428
429// ===============================================
430
431// CUSTOMIZATION ENDS HERE
432
433// ===============================================
434
435
436
437
438
439
440
441#if defined USING_SQL
442
443#include <sqlx>
444
445
446
447#define TABLE_NAME "advanced_bans"
448
449#define KEY_NAME "name"
450
451#define KEY_STEAMID "steamid"
452
453#define KEY_BANLENGTH "banlength"
454
455#define KEY_UNBANTIME "unbantime"
456
457#define KEY_REASON "reason"
458
459#define KEY_ADMIN_NAME "admin_name"
460
461#define KEY_ADMIN_STEAMID "admin_steamid"
462
463
464
465#define RELOAD_BANS_INTERVAL 60.0
466
467#endif
468
469
470
471#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"
472
473#define REGEX_STEAMID_PATTERN "^^STEAM_0:(0|1):\d+$"
474
475
476
477new Regex:g_IP_pattern;
478
479new Regex:g_SteamID_pattern;
480
481new g_regex_return;
482
483
484
485/*bool:IsValidIP(const ip[])
486
487{
488
489 return regex_match_c(ip, g_IP_pattern, g_regex_return) > 0;
490
491}*/
492
493
494
495#define IsValidIP(%1) (regex_match_c(%1, g_IP_pattern, g_regex_return) > 0)
496
497
498
499/*bool:IsValidAuthid(const authid[])
500
501{
502
503 return regex_match_c(authid, g_SteamID_pattern, g_regex_return) > 0;
504
505}*/
506
507
508
509#define IsValidAuthid(%1) (regex_match_c(%1, g_SteamID_pattern, g_regex_return) > 0)
510
511
512
513
514
515enum // for name displaying
516
517{
518
519 ACTIVITY_NONE, // nothing is shown
520
521 ACTIVITY_HIDE, // admin name is hidden
522
523 ACTIVITY_SHOW // admin name is shown
524
525};
526
527new const g_admin_activity[] =
528
529{
530
531 ACTIVITY_NONE, // amx_show_activity 0 = show nothing to everyone
532
533 ACTIVITY_HIDE, // amx_show_activity 1 = hide admin name from everyone
534
535 ACTIVITY_SHOW, // amx_show_activity 2 = show admin name to everyone
536
537 ACTIVITY_SHOW, // amx_show_activity 3 = show name to admins but hide it from normal users
538
539 ACTIVITY_SHOW, // amx_show_activity 4 = show name to admins but show nothing to normal users
540
541 ACTIVITY_HIDE // amx_show_activity 5 = hide name from admins but show nothing to normal users
542
543};
544
545new const g_normal_activity[] =
546
547{
548
549 ACTIVITY_NONE, // amx_show_activity 0 = show nothing to everyone
550
551 ACTIVITY_HIDE, // amx_show_activity 1 = hide admin name from everyone
552
553 ACTIVITY_SHOW, // amx_show_activity 2 = show admin name to everyone
554
555 ACTIVITY_HIDE, // amx_show_activity 3 = show name to admins but hide it from normal users
556
557 ACTIVITY_NONE, // amx_show_activity 4 = show name to admins but show nothing to normal users
558
559 ACTIVITY_NONE // amx_show_activity 5 = hide name from admins but show nothing to normal users
560
561};
562
563
564
565
566
567#if MAX_BANS <= 0
568
569enum _:BannedData
570
571{
572
573 bd_name[32],
574
575 bd_steamid[35],
576
577 bd_banlength,
578
579 bd_unbantime[32],
580
581 bd_reason[128],
582
583 bd_admin_name[64],
584
585 bd_admin_steamid[35]
586
587};
588
589
590
591new Trie:g_trie;
592
593new Array:g_array;
594
595#else
596
597new g_names[MAX_BANS][32];
598
599new g_steamids[MAX_BANS][35];
600
601new g_banlengths[MAX_BANS];
602
603new g_unbantimes[MAX_BANS][32];
604
605new g_reasons[MAX_BANS][128];
606
607new g_admin_names[MAX_BANS][64];
608
609new g_admin_steamids[MAX_BANS][35];
610
611#endif
612
613new g_total_bans;
614
615
616
617#if !defined USING_SQL
618
619new g_ban_file[64];
620
621#else
622
623new Handle:g_sql_tuple;
624
625new bool:g_loading_bans = true;
626
627#endif
628
629
630
631new ab_website;
632
633new ab_immunity;
634
635new ab_bandelay;
636
637new ab_unbancheck;
638
639
640
641new amx_show_activity;
642
643
644
645#if MAX_BANS <= 0
646
647new Array:g_maxban_times;
648
649new Array:g_maxban_flags;
650
651#else
652
653#define MAX_BANLIMITS 30
654
655new g_maxban_times[MAX_BANLIMITS];
656
657new g_maxban_flags[MAX_BANLIMITS];
658
659#endif
660
661new g_total_maxban_times;
662
663
664
665new g_unban_entity;
666
667
668
669new g_max_clients;
670
671
672
673new g_msgid_SayText;
674
675
676
677public plugin_init()
678
679{
680
681 register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
682
683 register_cvar("advanced_bans", PLUGIN_VERSION, FCVAR_SPONLY);
684
685
686
687 register_dictionary("advanced_bans.txt");
688
689
690
691 register_concmd("amx_ban", "CmdBan", ADMIN_BAN, "<nick, #userid, authid> <time in minutes> <reason>");
692
693 register_concmd("amx_banip", "CmdBanIp", ADMIN_BAN, "<nick, #userid, authid> <time in minutes> <reason>");
694
695 register_concmd("amx_addban", "CmdAddBan", ADMIN_BAN, "<name> <authid or ip> <time in minutes> <reason>");
696
697 register_concmd("amx_unban", "CmdUnban", ADMIN_BAN, "<authid or ip>");
698
699 register_concmd("amx_banlist", "CmdBanList", ADMIN_BAN, "[start] -- shows everyone who is banned");
700
701 register_srvcmd("amx_addbanlimit", "CmdAddBanLimit", -1, "<flag> <time in minutes>");
702
703
704
705 ab_website = register_cvar("ab_website", "");
706
707 ab_immunity = register_cvar("ab_immunity", "1");
708
709 ab_bandelay = register_cvar("ab_bandelay", "1.0");
710
711 ab_unbancheck = register_cvar("ab_unbancheck", "5.0");
712
713
714
715 amx_show_activity = register_cvar("amx_show_activity", "2");
716
717
718
719 #if MAX_BANS <= 0
720
721 g_trie = TrieCreate();
722
723 g_array = ArrayCreate(BannedData);
724
725 #endif
726
727
728
729 #if !defined MAX_BANLIMITS
730
731 g_maxban_times = ArrayCreate(1);
732
733 g_maxban_flags = ArrayCreate(1);
734
735 #endif
736
737
738
739 #if !defined USING_SQL
740
741 get_datadir(g_ban_file, sizeof(g_ban_file) - 1);
742
743 add(g_ban_file, sizeof(g_ban_file) - 1, "/advanced_bans.txt");
744
745
746
747 LoadBans();
748
749 #else
750
751 g_sql_tuple = SQL_MakeStdTuple();
752
753 PrepareTable();
754
755 #endif
756
757
758
759 new error[2];
760
761 g_IP_pattern = regex_compile(REGEX_IP_PATTERN, g_regex_return, error, sizeof(error) - 1);
762
763 g_SteamID_pattern = regex_compile(REGEX_STEAMID_PATTERN, g_regex_return, error, sizeof(error) - 1);
764
765
766
767 g_max_clients = get_maxplayers();
768
769
770
771 g_msgid_SayText = get_user_msgid("SayText");
772
773}
774
775
776
777#if defined USING_SQL
778
779PrepareTable()
780
781{
782
783 new query[128];
784
785 formatex(query, sizeof(query) - 1,\
786
787 "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);",\
788
789 TABLE_NAME, KEY_NAME, KEY_STEAMID, KEY_BANLENGTH, KEY_UNBANTIME, KEY_REASON, KEY_ADMIN_NAME, KEY_ADMIN_STEAMID
790
791 );
792
793
794
795 SQL_ThreadQuery(g_sql_tuple, "QueryCreateTable", query);
796
797}
798
799
800
801public QueryCreateTable(failstate, Handle:query, error[], errcode, data[], datasize, Float:queuetime)
802
803{
804
805 if( failstate == TQUERY_CONNECT_FAILED )
806
807 {
808
809 set_fail_state("Could not connect to database.");
810
811 }
812
813 else if( failstate == TQUERY_QUERY_FAILED )
814
815 {
816
817 set_fail_state("Query failed.");
818
819 }
820
821 else if( errcode )
822
823 {
824
825 log_amx("Error on query: %s", error);
826
827 }
828
829 else
830
831 {
832
833 LoadBans();
834
835 }
836
837}
838
839#endif
840
841
842
843public plugin_cfg()
844
845{
846
847 CreateUnbanEntity();
848
849}
850
851
852
853public CreateUnbanEntity()
854
855{
856
857 static failtimes;
858
859
860
861 g_unban_entity = create_entity("info_target");
862
863
864
865 if( !is_valid_ent(g_unban_entity) )
866
867 {
868
869 ++failtimes;
870
871
872
873 log_amx("[ERROR] Failed to create unban entity (%i/10)", failtimes);
874
875
876
877 if( failtimes < 10 )
878
879 {
880
881 set_task(1.0, "CreateUnbanEntity");
882
883 }
884
885 else
886
887 {
888
889 log_amx("[ERROR] Could not create unban entity!");
890
891 }
892
893
894
895 return;
896
897 }
898
899
900
901 entity_set_string(g_unban_entity, EV_SZ_classname, "unban_entity");
902
903 entity_set_float(g_unban_entity, EV_FL_nextthink, get_gametime() + 1.0);
904
905
906
907 register_think("unban_entity", "FwdThink");
908
909}
910
911
912
913public client_authorized(client)
914
915{
916
917 static authid[35];
918
919 get_user_authid(client, authid, sizeof(authid) - 1);
920
921
922
923 static ip[35];
924
925 get_user_ip(client, ip, sizeof(ip) - 1, 1);
926
927
928
929 #if MAX_BANS > 0
930
931 static banned_authid[35], bool:is_ip;
932
933 for( new i = 0; i < g_total_bans; i++ )
934
935 {
936
937 copy(banned_authid, sizeof(banned_authid) - 1, g_steamids[i]);
938
939
940
941 is_ip = bool:(containi(banned_authid, ".") != -1);
942
943
944
945 if( is_ip && equal(ip, banned_authid) || !is_ip && equal(authid, banned_authid) )
946
947 {
948
949 static name[32], reason[128], unbantime[32], admin_name[32], admin_steamid[64];
950
951 copy(name, sizeof(name) - 1, g_names[i]);
952
953 copy(reason, sizeof(reason) - 1, g_reasons[i]);
954
955 new banlength = g_banlengths[i];
956
957 copy(unbantime, sizeof(unbantime) - 1, g_unbantimes[i]);
958
959 copy(admin_name, sizeof(admin_name) - 1, g_admin_names[i]);
960
961 copy(admin_steamid, sizeof(admin_steamid) - 1, g_admin_steamids[i]);
962
963
964
965 PrintBanInformation(client, name, banned_authid, reason, banlength, unbantime, admin_name, admin_steamid, true, true);
966
967
968
969 set_task(get_pcvar_float(ab_bandelay), "TaskDisconnectPlayer", client);
970
971 break;
972
973 }
974
975 }
976
977 #else
978
979 static array_pos;
980
981
982
983 if( TrieGetCell(g_trie, authid, array_pos) || TrieGetCell(g_trie, ip, array_pos) )
984
985 {
986
987 static data[BannedData];
988
989 ArrayGetArray(g_array, array_pos, data);
990
991
992
993 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);
994
995
996
997 set_task(get_pcvar_float(ab_bandelay), "TaskDisconnectPlayer", client);
998
999 }
1000
1001 #endif
1002
1003}
1004
1005
1006
1007public CmdBan(client, level, cid)
1008
1009{
1010
1011 if( !cmd_access(client, level, cid, 4) ) return PLUGIN_HANDLED;
1012
1013
1014
1015 static arg[128];
1016
1017 read_argv(1, arg, sizeof(arg) - 1);
1018
1019
1020
1021 new target = cmd_target(client, arg, GetTargetFlags(client));
1022
1023 if( !target ) return PLUGIN_HANDLED;
1024
1025
1026
1027 static target_authid[35];
1028
1029 get_user_authid(target, target_authid, sizeof(target_authid) - 1);
1030
1031
1032
1033 if( !IsValidAuthid(target_authid) )
1034
1035 {
1036
1037 console_print(client, "[PLAY-ARENA]: %L", client, "AB_NOT_AUTHORIZED");
1038
1039 return PLUGIN_HANDLED;
1040
1041 }
1042
1043
1044
1045 #if MAX_BANS <= 0
1046
1047 if( TrieKeyExists(g_trie, target_authid) )
1048
1049 {
1050
1051 console_print(client, "[PLAY-ARENA]: %L", client, "AB_ALREADY_BANNED_STEAMID");
1052
1053 return PLUGIN_HANDLED;
1054
1055 }
1056
1057 #else
1058
1059 for( new i = 0; i < g_total_bans; i++ )
1060
1061 {
1062
1063 if( !strcmp(target_authid, g_steamids[i], 1) )
1064
1065 {
1066
1067 console_print(client, "[PLAY-ARENA]:%L", client, "AB_ALREADY_BANNED_STEAMID");
1068
1069 return PLUGIN_HANDLED;
1070
1071 }
1072
1073 }
1074
1075 #endif
1076
1077
1078
1079 read_argv(2, arg, sizeof(arg) - 1);
1080
1081
1082
1083 new length = str_to_num(arg);
1084
1085 new maxlength = GetMaxBanTime(client);
1086
1087
1088
1089 if( maxlength && (!length || length > maxlength) )
1090
1091 {
1092
1093 console_print(client, "[PLAY-ARENA]:%L", client, "AB_MAX_BAN_TIME", maxlength);
1094
1095 return PLUGIN_HANDLED;
1096
1097 }
1098
1099
1100
1101 static unban_time[64];
1102
1103 if( length == 0 )
1104
1105 {
1106
1107 formatex(unban_time, sizeof(unban_time) - 1, "%L", client, "AB_PERMANENT_BAN");
1108
1109 }
1110
1111 else
1112
1113 {
1114
1115 GenerateUnbanTime(length, unban_time, sizeof(unban_time) - 1);
1116
1117 }
1118
1119
1120
1121 read_argv(3, arg, sizeof(arg) - 1);
1122
1123
1124
1125 static admin_name[64], target_name[32];
1126
1127 get_user_name(client, admin_name, sizeof(admin_name) - 1);
1128
1129 get_user_name(target, target_name, sizeof(target_name) - 1);
1130
1131
1132
1133 static admin_authid[35];
1134
1135 get_user_authid(client, admin_authid, sizeof(admin_authid) - 1);
1136
1137
1138
1139 AddBan(target_name, target_authid, arg, length, unban_time, admin_name, admin_authid);
1140
1141
1142
1143 PrintBanInformation(target, target_name, target_authid, arg, length, unban_time, admin_name, admin_authid, true, true);
1144
1145 PrintBanInformation(client, target_name, target_authid, arg, length, unban_time, admin_name, admin_authid, false, false);
1146
1147
1148
1149 set_task(get_pcvar_float(ab_bandelay), "TaskDisconnectPlayer", target);
1150
1151
1152
1153 GetBanTime(length, unban_time, sizeof(unban_time) - 1);
1154
1155
1156
1157 PrintActivity(admin_name, "^x04[PLAY-ARENA]: ^1Adminul ^x04$name ^1i-a dat ban lui ^x04%s. ^1Motiv: ^x04%s. ^1Durata: ^x04%s.", target_name, arg, unban_time);
1158
1159
1160
1161 Log("%s <%s> banned %s <%s> || Reason: ^"%s^" || Ban Length: %s", admin_name, admin_authid, target_name, target_authid, arg, unban_time);
1162
1163
1164
1165 return PLUGIN_HANDLED;
1166
1167}
1168
1169
1170
1171public CmdBanIp(client, level, cid)
1172
1173{
1174
1175 if( !cmd_access(client, level, cid, 4) ) return PLUGIN_HANDLED;
1176
1177
1178
1179 static arg[128];
1180
1181 read_argv(1, arg, sizeof(arg) - 1);
1182
1183
1184
1185 new target = cmd_target(client, arg, GetTargetFlags(client));
1186
1187 if( !target ) return PLUGIN_HANDLED;
1188
1189
1190
1191 static target_ip[35];
1192
1193 get_user_ip(target, target_ip, sizeof(target_ip) - 1, 1);
1194
1195
1196
1197 #if MAX_BANS <= 0
1198
1199 if( TrieKeyExists(g_trie, target_ip) )
1200
1201 {
1202
1203 console_print(client, "[PLAY-ARENA]:%L", client, "AB_ALREADY_BANNED_IP");
1204
1205 return PLUGIN_HANDLED;
1206
1207 }
1208
1209 #else
1210
1211 for( new i = 0; i < g_total_bans; i++ )
1212
1213 {
1214
1215 if( !strcmp(target_ip, g_steamids[i], 1) )
1216
1217 {
1218
1219 console_print(client, "[PLAY-ARENA]:%L", client, "AB_ALREADY_BANNED_IP");
1220
1221 return PLUGIN_HANDLED;
1222
1223 }
1224
1225 }
1226
1227 #endif
1228
1229
1230
1231 read_argv(2, arg, sizeof(arg) - 1);
1232
1233
1234
1235 new length = str_to_num(arg);
1236
1237 new maxlength = GetMaxBanTime(client);
1238
1239
1240
1241 if( maxlength && (!length || length > maxlength) )
1242
1243 {
1244
1245 console_print(client, "[PLAY-ARENA]:%L", client, "AB_MAX_BAN_TIME", maxlength);
1246
1247 return PLUGIN_HANDLED;
1248
1249 }
1250
1251
1252
1253 static unban_time[32];
1254
1255
1256
1257 if( length == 0 )
1258
1259 {
1260
1261 formatex(unban_time, sizeof(unban_time) - 1, "%L", client, "AB_PERMANENT_BAN");
1262
1263 }
1264
1265 else
1266
1267 {
1268
1269 GenerateUnbanTime(length, unban_time, sizeof(unban_time) - 1);
1270
1271 }
1272
1273
1274
1275 read_argv(3, arg, sizeof(arg) - 1);
1276
1277
1278
1279 static admin_name[64], target_name[32];
1280
1281 get_user_name(client, admin_name, sizeof(admin_name) - 1);
1282
1283 get_user_name(target, target_name, sizeof(target_name) - 1);
1284
1285
1286
1287 static admin_authid[35];
1288
1289 get_user_authid(client, admin_authid, sizeof(admin_authid) - 1);
1290
1291
1292
1293 AddBan(target_name, target_ip, arg, length, unban_time, admin_name, admin_authid);
1294
1295
1296
1297 PrintBanInformation(target, target_name, target_ip, arg, length, unban_time, admin_name, admin_authid, true, true);
1298
1299 PrintBanInformation(client, target_name, target_ip, arg, length, unban_time, admin_name, admin_authid, false, false);
1300
1301
1302
1303 set_task(get_pcvar_float(ab_bandelay), "TaskDisconnectPlayer", target);
1304
1305
1306
1307 GetBanTime(length, unban_time, sizeof(unban_time) - 1);
1308
1309
1310
1311 PrintActivity(admin_name, "^x04[PLAY-ARENA]: ^1Adminul ^x04$name ^1i-a dat ban lui ^x04%s. ^1Motiv: ^x04%s. ^1Durata: ^x04%s.", target_name, arg, unban_time);
1312
1313
1314
1315 Log("%s <%s> banned %s <%s> || Reason: ^"%s^" || Ban Length: %s", admin_name, admin_authid, target_name, target_ip, arg, unban_time);
1316
1317
1318
1319 return PLUGIN_HANDLED;
1320
1321}
1322
1323
1324
1325public CmdAddBan(client, level, cid)
1326
1327{
1328
1329 if( !cmd_access(client, level, cid, 5) ) return PLUGIN_HANDLED;
1330
1331
1332
1333 static target_name[32], target_authid[35], bantime[10], reason[128];
1334
1335 read_argv(1, target_name, sizeof(target_name) - 1);
1336
1337 read_argv(2, target_authid, sizeof(target_authid) - 1);
1338
1339 read_argv(3, bantime, sizeof(bantime) - 1);
1340
1341 read_argv(4, reason, sizeof(reason) - 1);
1342
1343
1344
1345 new bool:is_ip = bool:(containi(target_authid, ".") != -1);
1346
1347
1348
1349 if( !is_ip && !IsValidAuthid(target_authid) )
1350
1351 {
1352
1353 console_print(client, "[PLAY-ARENA]:%L", client, "AB_INVALID_STEAMID");
1354
1355 console_print(client, "[PLAY-ARENA]:%L", client, "AB_VALID_STEAMID_FORMAT");
1356
1357
1358
1359 return PLUGIN_HANDLED;
1360
1361 }
1362
1363 else if( is_ip )
1364
1365 {
1366
1367 new pos = contain(target_authid, ":");
1368
1369 if( pos > 0 )
1370
1371 {
1372
1373 target_authid[pos] = 0;
1374
1375 }
1376
1377
1378
1379 if( !IsValidIP(target_authid) )
1380
1381 {
1382
1383 console_print(client, "[PLAY-ARENA]:%L", client, "AB_INVALID_IP");
1384
1385
1386
1387 return PLUGIN_HANDLED;
1388
1389 }
1390
1391 }
1392
1393
1394
1395 #if MAX_BANS <= 0
1396
1397 if( TrieKeyExists(g_trie, target_authid) )
1398
1399 {
1400
1401 console_print(client, "[PLAY-ARENA]:%L", client, is_ip ? "AB_ALREADY_BANNED_IP" : "AB_ALREADY_BANNED_STEAMID");
1402
1403 return PLUGIN_HANDLED;
1404
1405 }
1406
1407 #else
1408
1409 for( new i = 0; i < g_total_bans; i++ )
1410
1411 {
1412
1413 if( !strcmp(target_authid, g_steamids[i], 1) )
1414
1415 {
1416
1417 console_print(client, "[PLAY-ARENA]:%L", client, is_ip ? "AB_ALREADY_BANNED_IP" : "AB_ALREADY_BANNED_STEAMID");
1418
1419 return PLUGIN_HANDLED;
1420
1421 }
1422
1423 }
1424
1425 #endif
1426
1427
1428
1429 new length = str_to_num(bantime);
1430
1431 new maxlength = GetMaxBanTime(client);
1432
1433
1434
1435 if( maxlength && (!length || length > maxlength) )
1436
1437 {
1438
1439 console_print(client, "[PLAY-ARENA]:%L", client, "AB_MAX_BAN_TIME", maxlength);
1440
1441 return PLUGIN_HANDLED;
1442
1443 }
1444
1445
1446
1447 if( is_user_connected(find_player(is_ip ? "d" : "c", target_authid)) )
1448
1449 {
1450
1451 client_cmd(client, "amx_ban ^"%s^" %i ^"%s^"", target_authid, length, reason);
1452
1453 return PLUGIN_HANDLED;
1454
1455 }
1456
1457
1458
1459 static unban_time[32];
1460
1461 if( length == 0 )
1462
1463 {
1464
1465 formatex(unban_time, sizeof(unban_time) - 1, "%L", client, "AB_PERMANENT_BAN");
1466
1467 }
1468
1469 else
1470
1471 {
1472
1473 GenerateUnbanTime(length, unban_time, sizeof(unban_time) - 1);
1474
1475 }
1476
1477
1478
1479 static admin_name[64], admin_authid[35];
1480
1481 get_user_name(client, admin_name, sizeof(admin_name) - 1);
1482
1483 get_user_authid(client, admin_authid, sizeof(admin_authid) - 1);
1484
1485
1486
1487 AddBan(target_name, target_authid, reason, length, unban_time, admin_name, admin_authid);
1488
1489
1490
1491 PrintBanInformation(client, target_name, target_authid, reason, length, unban_time, "", "", false, false);
1492
1493
1494
1495 GetBanTime(length, unban_time, sizeof(unban_time) - 1);
1496
1497
1498
1499 PrintActivity(admin_name, "^x04[PLAY-ARENA]: ^1Adminnul ^x04$name ^1a banat %s-ul ^x04%s.", is_ip ? "IP" : "SteamID", target_authid, reason, unban_time);
1500
1501
1502
1503 Log("%s <%s> banned %s <%s> || Reason: ^"%s^" || Ban Length: %s", admin_name, admin_authid, target_name, target_authid, reason, unban_time);
1504
1505
1506
1507 return PLUGIN_HANDLED;
1508
1509}
1510
1511
1512
1513public CmdUnban(client, level, cid)
1514
1515{
1516
1517 if( !cmd_access(client, level, cid, 2) ) return PLUGIN_HANDLED;
1518
1519
1520
1521 static arg[35];
1522
1523 read_argv(1, arg, sizeof(arg) - 1);
1524
1525
1526
1527 #if MAX_BANS > 0
1528
1529 static banned_authid[35];
1530
1531 for( new i = 0; i < g_total_bans; i++ )
1532
1533 {
1534
1535 copy(banned_authid, sizeof(banned_authid) - 1, g_steamids[i]);
1536
1537
1538
1539 if( equal(arg, banned_authid) )
1540
1541 {
1542
1543 static admin_name[64];
1544
1545 get_user_name(client, admin_name, sizeof(admin_name) - 1);
1546
1547
1548
1549 static name[32], reason[128];
1550
1551 copy(name, sizeof(name) - 1, g_names[i]);
1552
1553 copy(reason, sizeof(reason) - 1, g_reasons[i]);
1554
1555
1556
1557 PrintActivity(admin_name, "^x04[PLAY-ARENA]: ^1Adminul ^x04$name ^1i-a scos banul lui ^x04%s - %s.", name, arg, reason);
1558
1559
1560
1561 static authid[35];
1562
1563 get_user_authid(client, authid, sizeof(authid) - 1);
1564
1565
1566
1567 Log("%s <%s> unbanned %s <%s> || Ban Reason: ^"%s^"", admin_name, authid, name, arg, reason);
1568
1569
1570
1571 RemoveBan(i);
1572
1573
1574
1575 return PLUGIN_HANDLED;
1576
1577 }
1578
1579 }
1580
1581 #else
1582
1583 if( TrieKeyExists(g_trie, arg) )
1584
1585 {
1586
1587 static array_pos;
1588
1589 TrieGetCell(g_trie, arg, array_pos);
1590
1591
1592
1593 static data[BannedData];
1594
1595 ArrayGetArray(g_array, array_pos, data);
1596
1597
1598
1599 static unban_name[32];
1600
1601 get_user_name(client, unban_name, sizeof(unban_name) - 1);
1602
1603
1604
1605 PrintActivity(unban_name, "^x04[PLAY-ARENA]: ^1Adminul ^x04$name ^1i-a scos banul lui ^x04%s - %s.", data[bd_name], data[bd_steamid], data[bd_reason]);
1606
1607
1608
1609 static admin_name[64];
1610
1611 get_user_name(client, admin_name, sizeof(admin_name) - 1);
1612
1613
1614
1615 static authid[35];
1616
1617 get_user_authid(client, authid, sizeof(authid) - 1);
1618
1619
1620
1621 Log("%s <%s> unbanned %s <%s> || Ban Reason: ^"%s^"", admin_name, authid, data[bd_name], data[bd_steamid], data[bd_reason]);
1622
1623
1624
1625 RemoveBan(array_pos, data[bd_steamid]);
1626
1627
1628
1629 return PLUGIN_HANDLED;
1630
1631 }
1632
1633 #endif
1634
1635
1636
1637 console_print(client, "[PLAY-ARENA]:%L", client, "AB_NOT_IN_BAN_LIST", arg);
1638
1639
1640
1641 return PLUGIN_HANDLED;
1642
1643}
1644
1645
1646
1647public CmdBanList(client, level, cid)
1648
1649{
1650
1651 if( !cmd_access(client, level, cid, 1) ) return PLUGIN_HANDLED;
1652
1653
1654
1655 if( !g_total_bans )
1656
1657 {
1658
1659 console_print(client, "[PLAY-ARENA]:%L", client, "AB_NO_BANS");
1660
1661 return PLUGIN_HANDLED;
1662
1663 }
1664
1665
1666
1667 static start;
1668
1669
1670
1671 if( read_argc() > 1 )
1672
1673 {
1674
1675 static arg[5];
1676
1677 read_argv(1, arg, sizeof(arg) - 1);
1678
1679
1680
1681 start = min(str_to_num(arg), g_total_bans) - 1;
1682
1683 }
1684
1685 else
1686
1687 {
1688
1689 start = 0;
1690
1691 }
1692
1693
1694
1695 new last = min(start + 10, g_total_bans);
1696
1697
1698
1699 if( client == 0 )
1700
1701 {
1702
1703 server_cmd("echo ^"%L^"", client, "AB_BAN_LIST_NUM", start + 1, last);
1704
1705 }
1706
1707 else
1708
1709 {
1710
1711 client_cmd(client, "echo ^"%L^"", client, "AB_BAN_LIST_NUM", start + 1, last);
1712
1713 }
1714
1715
1716
1717 for( new i = start; i < last; i++ )
1718
1719 {
1720
1721 #if MAX_BANS <= 0
1722
1723 static data[BannedData];
1724
1725 ArrayGetArray(g_array, i, data);
1726
1727
1728
1729 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);
1730
1731 #else
1732
1733 static name[32], steamid[35], reason[128], banlength, unbantime[32], admin_name[32], admin_steamid[35];
1734
1735
1736
1737 copy(name, sizeof(name) - 1, g_names[i]);
1738
1739 copy(steamid, sizeof(steamid) - 1, g_steamids[i]);
1740
1741 copy(reason, sizeof(reason) - 1, g_reasons[i]);
1742
1743 banlength = g_banlengths[i];
1744
1745 copy(unbantime, sizeof(unbantime) - 1, g_unbantimes[i]);
1746
1747 copy(admin_name, sizeof(admin_name) - 1, g_admin_names[i]);
1748
1749 copy(admin_steamid, sizeof(admin_steamid) - 1, g_admin_steamids[i]);
1750
1751
1752
1753 PrintBanInformation(client, name, steamid, reason, banlength, unbantime, admin_name, admin_steamid, true, false);
1754
1755 #endif
1756
1757 }
1758
1759
1760
1761 if( ++last < g_total_bans )
1762
1763 {
1764
1765 if( client == 0 )
1766
1767 {
1768
1769 server_cmd("echo ^"%L^"", client, "AB_BAN_LIST_NEXT", last);
1770
1771 }
1772
1773 else
1774
1775 {
1776
1777 client_cmd(client, "echo ^"%L^"", client, "AB_BAN_LIST_NEXT", last);
1778
1779 }
1780
1781 }
1782
1783
1784
1785 return PLUGIN_HANDLED;
1786
1787}
1788
1789
1790
1791public CmdAddBanLimit()
1792
1793{
1794
1795 if( read_argc() != 3 )
1796
1797 {
1798
1799 log_amx("amx_addbanlimit was used with incorrect parameters!");
1800
1801 log_amx("Usage: amx_addbanlimit <flags> <time in minutes>");
1802
1803 return PLUGIN_HANDLED;
1804
1805 }
1806
1807
1808
1809 static arg[16];
1810
1811
1812
1813 read_argv(1, arg, sizeof(arg) - 1);
1814
1815 new flags = read_flags(arg);
1816
1817
1818
1819 read_argv(2, arg, sizeof(arg) - 1);
1820
1821 new minutes = str_to_num(arg);
1822
1823
1824
1825 #if !defined MAX_BANLIMITS
1826
1827 ArrayPushCell(g_maxban_flags, flags);
1828
1829 ArrayPushCell(g_maxban_times, minutes);
1830
1831 #else
1832
1833 if( g_total_maxban_times >= MAX_BANLIMITS )
1834
1835 {
1836
1837 static notified;
1838
1839 if( !notified )
1840
1841 {
1842
1843 log_amx("The amx_addbanlimit has reached its maximum!");
1844
1845 notified = 1;
1846
1847 }
1848
1849 return PLUGIN_HANDLED;
1850
1851 }
1852
1853
1854
1855 g_maxban_flags[g_total_maxban_times] = flags;
1856
1857 g_maxban_times[g_total_maxban_times] = minutes;
1858
1859 #endif
1860
1861 g_total_maxban_times++;
1862
1863
1864
1865 return PLUGIN_HANDLED;
1866
1867}
1868
1869
1870
1871public FwdThink(entity)
1872
1873{
1874
1875 if( entity != g_unban_entity ) return;
1876
1877
1878
1879 #if defined USING_SQL
1880
1881 if( g_total_bans > 0 && !g_loading_bans )
1882
1883 #else
1884
1885 if( g_total_bans > 0 )
1886
1887 #endif
1888
1889 {
1890
1891 static _hours[5], _minutes[5], _seconds[5], _month[5], _day[5], _year[7];
1892
1893 format_time(_hours, sizeof(_hours) - 1, "%H");
1894
1895 format_time(_minutes, sizeof(_minutes) - 1, "%M");
1896
1897 format_time(_seconds, sizeof(_seconds) - 1, "%S");
1898
1899 format_time(_month, sizeof(_month) - 1, "%m");
1900
1901 format_time(_day, sizeof(_day) - 1, "%d");
1902
1903 format_time(_year, sizeof(_year) - 1, "%Y");
1904
1905
1906
1907 // c = current
1908
1909 // u = unban
1910
1911
1912
1913 new c_hours = str_to_num(_hours);
1914
1915 new c_minutes = str_to_num(_minutes);
1916
1917 new c_seconds = str_to_num(_seconds);
1918
1919 new c_month = str_to_num(_month);
1920
1921 new c_day = str_to_num(_day);
1922
1923 new c_year = str_to_num(_year);
1924
1925
1926
1927 static unban_time[32];
1928
1929 static u_hours, u_minutes, u_seconds, u_month, u_day, u_year;
1930
1931
1932
1933 for( new i = 0; i < g_total_bans; i++ )
1934
1935 {
1936
1937 #if MAX_BANS <= 0
1938
1939 static data[BannedData];
1940
1941 ArrayGetArray(g_array, i, data);
1942
1943
1944
1945 if( data[bd_banlength] == 0 ) continue;
1946
1947 #else
1948
1949 if( g_banlengths[i] == 0 ) continue;
1950
1951 #endif
1952
1953
1954
1955 #if MAX_BANS <= 0
1956
1957 copy(unban_time, sizeof(unban_time) - 1, data[bd_unbantime]);
1958
1959 #else
1960
1961 copy(unban_time, sizeof(unban_time) - 1, g_unbantimes[i]);
1962
1963 #endif
1964
1965 replace_all(unban_time, sizeof(unban_time) - 1, ":", " ");
1966
1967 replace_all(unban_time, sizeof(unban_time) - 1, "/", " ");
1968
1969
1970
1971 parse(unban_time,\
1972
1973 _hours, sizeof(_hours) - 1,\
1974
1975 _minutes, sizeof(_minutes) - 1,\
1976
1977 _seconds, sizeof(_seconds) - 1,\
1978
1979 _month, sizeof(_month) - 1,\
1980
1981 _day, sizeof(_day) - 1,\
1982
1983 _year, sizeof(_year) - 1
1984
1985 );
1986
1987
1988
1989 u_hours = str_to_num(_hours);
1990
1991 u_minutes = str_to_num(_minutes);
1992
1993 u_seconds = str_to_num(_seconds);
1994
1995 u_month = str_to_num(_month);
1996
1997 u_day = str_to_num(_day);
1998
1999 u_year = str_to_num(_year);
2000
2001
2002
2003 if( u_year < c_year
2004
2005 || u_year == c_year && u_month < c_month
2006
2007 || u_year == c_year && u_month == c_month && u_day < c_day
2008
2009 || u_year == c_year && u_month == c_month && u_day == c_day && u_hours < c_hours
2010
2011 || u_year == c_year && u_month == c_month && u_day == c_day && u_hours == c_hours && u_minutes < c_minutes
2012
2013 || u_year == c_year && u_month == c_month && u_day == c_day && u_hours == c_hours && u_minutes == c_minutes && u_seconds <= c_seconds )
2014
2015 {
2016
2017 #if MAX_BANS <= 0
2018
2019 Log("Ban time is up for: %s [%s]", data[bd_name], data[bd_steamid]);
2020
2021
2022
2023 Print("^x04[PLAY-ARENA]: ^1Jucatorului ^x04%s - %s ^1i-a expirat banul. ^1Motivul banului: ^x04%s.", data[bd_name], data[bd_steamid], data[bd_reason]);
2024
2025
2026
2027 RemoveBan(i, data[bd_steamid]);
2028
2029 #else
2030
2031 Log("Ban time is up for: %s [%s]", g_names[i], g_steamids[i]);
2032
2033
2034
2035 Print("^x04[PLAY-ARENA]: ^1Jucatorului ^x04%s - %s ^1i-a expirat banul. ^1Motivul banului: ^x04%s.", g_names[i], g_steamids[i], g_reasons[i]);
2036
2037
2038
2039 RemoveBan(i);
2040
2041 #endif
2042
2043
2044
2045 i--; // current pos was replaced with another ban, so we need to check it again.
2046
2047 }
2048
2049 }
2050
2051 }
2052
2053
2054
2055 entity_set_float(g_unban_entity, EV_FL_nextthink, get_gametime() + get_pcvar_float(ab_unbancheck));
2056
2057}
2058
2059
2060
2061public TaskDisconnectPlayer(client)
2062
2063{
2064
2065 server_cmd("kick #%i ^"You are banned from this server. Check your console^"", get_user_userid(client));
2066
2067}
2068
2069
2070
2071AddBan(const target_name[], const target_steamid[], const reason[], const length, const unban_time[], const admin_name[], const admin_steamid[])
2072
2073{
2074
2075 #if MAX_BANS > 0
2076
2077 if( g_total_bans == MAX_BANS )
2078
2079 {
2080
2081 log_amx("Ban list is full! (%i)", g_total_bans);
2082
2083 return;
2084
2085 }
2086
2087 #endif
2088
2089
2090
2091 #if defined USING_SQL
2092
2093 static target_name2[32], reason2[128], admin_name2[32];
2094
2095 MakeStringSQLSafe(target_name, target_name2, sizeof(target_name2) - 1);
2096
2097 MakeStringSQLSafe(reason, reason2, sizeof(reason2) - 1);
2098
2099 MakeStringSQLSafe(admin_name, admin_name2, sizeof(admin_name2) - 1);
2100
2101
2102
2103 static query[512];
2104
2105 formatex(query, sizeof(query) - 1,\
2106
2107 "INSERT INTO `%s` (`%s`, `%s`, `%s`, `%s`, `%s`, `%s`, `%s`) VALUES ('%s', '%s', '%i', '%s', '%s', '%s', '%s');",\
2108
2109 TABLE_NAME, KEY_NAME, KEY_STEAMID, KEY_BANLENGTH, KEY_UNBANTIME, KEY_REASON, KEY_ADMIN_NAME, KEY_ADMIN_STEAMID,\
2110
2111 target_name2, target_steamid, length, unban_time, reason2, admin_name2, admin_steamid
2112
2113 );
2114
2115
2116
2117 SQL_ThreadQuery(g_sql_tuple, "QueryAddBan", query);
2118
2119 #else
2120
2121 new f = fopen(g_ban_file, "a+");
2122
2123
2124
2125 fprintf(f, "^"%s^" ^"%s^" %i ^"%s^" ^"%s^" ^"%s^" ^"%s^"^n",\
2126
2127 target_steamid,\
2128
2129 target_name,\
2130
2131 length,\
2132
2133 unban_time,\
2134
2135 reason,\
2136
2137 admin_name,\
2138
2139 admin_steamid
2140
2141 );
2142
2143
2144
2145 fclose(f);
2146
2147 #endif
2148
2149
2150
2151 #if MAX_BANS <= 0
2152
2153 static data[BannedData];
2154
2155 copy(data[bd_name], sizeof(data[bd_name]) - 1, target_name);
2156
2157 copy(data[bd_steamid], sizeof(data[bd_steamid]) - 1, target_steamid);
2158
2159 data[bd_banlength] = length;
2160
2161 copy(data[bd_unbantime], sizeof(data[bd_unbantime]) - 1, unban_time);
2162
2163 copy(data[bd_reason], sizeof(data[bd_reason]) - 1, reason);
2164
2165 copy(data[bd_admin_name], sizeof(data[bd_admin_name]) - 1, admin_name);
2166
2167 copy(data[bd_admin_steamid], sizeof(data[bd_admin_steamid]) - 1, admin_steamid);
2168
2169
2170
2171 TrieSetCell(g_trie, target_steamid, g_total_bans);
2172
2173 ArrayPushArray(g_array, data);
2174
2175 #else
2176
2177 copy(g_names[g_total_bans], sizeof(g_names[]) - 1, target_name);
2178
2179 copy(g_steamids[g_total_bans], sizeof(g_steamids[]) - 1, target_steamid);
2180
2181 g_banlengths[g_total_bans] = length;
2182
2183 copy(g_unbantimes[g_total_bans], sizeof(g_unbantimes[]) - 1, unban_time);
2184
2185 copy(g_reasons[g_total_bans], sizeof(g_reasons[]) - 1, reason);
2186
2187 copy(g_admin_names[g_total_bans], sizeof(g_admin_names[]) - 1, admin_name);
2188
2189 copy(g_admin_steamids[g_total_bans], sizeof(g_admin_steamids[]) - 1, admin_steamid);
2190
2191 #endif
2192
2193
2194
2195 g_total_bans++;
2196
2197
2198
2199 #if MAX_BANS > 0
2200
2201 if( g_total_bans == MAX_BANS )
2202
2203 {
2204
2205 log_amx("Ban list is full! (%i)", g_total_bans);
2206
2207 }
2208
2209 #endif
2210
2211}
2212
2213
2214
2215#if defined USING_SQL
2216
2217public QueryAddBan(failstate, Handle:query, error[], errcode, data[], datasize, Float:queuetime)
2218
2219{
2220
2221 if( failstate == TQUERY_CONNECT_FAILED )
2222
2223 {
2224
2225 set_fail_state("Could not connect to database.");
2226
2227 }
2228
2229 else if( failstate == TQUERY_QUERY_FAILED )
2230
2231 {
2232
2233 set_fail_state("Query failed.");
2234
2235 }
2236
2237 else if( errcode )
2238
2239 {
2240
2241 log_amx("Error on query: %s", error);
2242
2243 }
2244
2245 else
2246
2247 {
2248
2249 // Yay, ban was added! We can all rejoice!
2250
2251 }
2252
2253}
2254
2255
2256
2257public QueryDeleteBan(failstate, Handle:query, error[], errcode, data[], datasize, Float:queuetime)
2258
2259{
2260
2261 if( failstate == TQUERY_CONNECT_FAILED )
2262
2263 {
2264
2265 set_fail_state("Could not connect to database.");
2266
2267 }
2268
2269 else if( failstate == TQUERY_QUERY_FAILED )
2270
2271 {
2272
2273 set_fail_state("Query failed.");
2274
2275 }
2276
2277 else if( errcode )
2278
2279 {
2280
2281 log_amx("Error on query: %s", error);
2282
2283 }
2284
2285 else
2286
2287 {
2288
2289 // Yay, ban was deleted! We can all rejoice!
2290
2291 }
2292
2293}
2294
2295
2296
2297public QueryLoadBans(failstate, Handle:query, error[], errcode, data[], datasize, Float:queuetime)
2298
2299{
2300
2301 if( failstate == TQUERY_CONNECT_FAILED )
2302
2303 {
2304
2305 set_fail_state("Could not connect to database.");
2306
2307 }
2308
2309 else if( failstate == TQUERY_QUERY_FAILED )
2310
2311 {
2312
2313 set_fail_state("Query failed.");
2314
2315 }
2316
2317 else if( errcode )
2318
2319 {
2320
2321 log_amx("Error on query: %s", error);
2322
2323 }
2324
2325 else
2326
2327 {
2328
2329 if( SQL_NumResults(query) )
2330
2331 {
2332
2333 #if MAX_BANS <= 0
2334
2335 static data[BannedData];
2336
2337 while( SQL_MoreResults(query) )
2338
2339 #else
2340
2341 while( SQL_MoreResults(query) && g_total_bans < MAX_BANS )
2342
2343 #endif
2344
2345 {
2346
2347 #if MAX_BANS <= 0
2348
2349 SQL_ReadResult(query, 0, data[bd_name], sizeof(data[bd_name]) - 1);
2350
2351 SQL_ReadResult(query, 1, data[bd_steamid], sizeof(data[bd_steamid]) - 1);
2352
2353 data[bd_banlength] = SQL_ReadResult(query, 2);
2354
2355 SQL_ReadResult(query, 3, data[bd_unbantime], sizeof(data[bd_unbantime]) - 1);
2356
2357 SQL_ReadResult(query, 4, data[bd_reason], sizeof(data[bd_reason]) - 1);
2358
2359 SQL_ReadResult(query, 5, data[bd_admin_name], sizeof(data[bd_admin_name]) - 1);
2360
2361 SQL_ReadResult(query, 6, data[bd_admin_steamid], sizeof(data[bd_admin_steamid]) - 1);
2362
2363
2364
2365 ArrayPushArray(g_array, data);
2366
2367 TrieSetCell(g_trie, data[bd_steamid], g_total_bans);
2368
2369 #else
2370
2371 SQL_ReadResult(query, 0, g_names[g_total_bans], sizeof(g_names[]) - 1);
2372
2373 SQL_ReadResult(query, 1, g_steamids[g_total_bans], sizeof(g_steamids[]) - 1);
2374
2375 g_banlengths[g_total_bans] = SQL_ReadResult(query, 2);
2376
2377 SQL_ReadResult(query, 3, g_unbantimes[g_total_bans], sizeof(g_unbantimes[]) - 1);
2378
2379 SQL_ReadResult(query, 4, g_reasons[g_total_bans], sizeof(g_reasons[]) - 1);
2380
2381 SQL_ReadResult(query, 5, g_admin_names[g_total_bans], sizeof(g_admin_names[]) - 1);
2382
2383 SQL_ReadResult(query, 6, g_admin_steamids[g_total_bans], sizeof(g_admin_steamids[]) - 1);
2384
2385 #endif
2386
2387
2388
2389 g_total_bans++;
2390
2391
2392
2393 SQL_NextRow(query);
2394
2395 }
2396
2397 }
2398
2399
2400
2401 set_task(RELOAD_BANS_INTERVAL, "LoadBans");
2402
2403
2404
2405 g_loading_bans = false;
2406
2407 }
2408
2409}
2410
2411#endif
2412
2413
2414
2415#if MAX_BANS > 0
2416
2417RemoveBan(remove)
2418
2419{
2420
2421 #if defined USING_SQL
2422
2423 static query[128];
2424
2425 formatex(query, sizeof(query) - 1,\
2426
2427 "DELETE FROM `%s` WHERE `%s` = '%s';",\
2428
2429 TABLE_NAME, KEY_STEAMID, g_steamids[remove]
2430
2431 );
2432
2433
2434
2435 SQL_ThreadQuery(g_sql_tuple, "QueryDeleteBan", query);
2436
2437 #endif
2438
2439
2440
2441 for( new i = remove; i < g_total_bans; i++ )
2442
2443 {
2444
2445 if( (i + 1) == g_total_bans )
2446
2447 {
2448
2449 copy(g_names[i], sizeof(g_names[]) - 1, "");
2450
2451 copy(g_steamids[i], sizeof(g_steamids[]) - 1, "");
2452
2453 g_banlengths[i] = 0;
2454
2455 copy(g_unbantimes[i], sizeof(g_unbantimes[]) - 1, "");
2456
2457 copy(g_reasons[i], sizeof(g_reasons[]) - 1, "");
2458
2459 copy(g_admin_names[i], sizeof(g_admin_names[]) - 1, "");
2460
2461 copy(g_admin_steamids[i], sizeof(g_admin_steamids[]) - 1, "");
2462
2463 }
2464
2465 else
2466
2467 {
2468
2469 copy(g_names[i], sizeof(g_names[]) - 1, g_names[i + 1]);
2470
2471 copy(g_steamids[i], sizeof(g_steamids[]) - 1, g_steamids[i + 1]);
2472
2473 g_banlengths[i] = g_banlengths[i + 1];
2474
2475 copy(g_unbantimes[i], sizeof(g_unbantimes[]) - 1, g_unbantimes[i + 1]);
2476
2477 copy(g_reasons[i], sizeof(g_reasons[]) - 1, g_reasons[i + 1]);
2478
2479 copy(g_admin_names[i], sizeof(g_admin_names[]) - 1, g_admin_names[i + 1]);
2480
2481 copy(g_admin_steamids[i], sizeof(g_admin_steamids[]) - 1, g_admin_steamids[i + 1]);
2482
2483 }
2484
2485 }
2486
2487
2488
2489 g_total_bans--;
2490
2491
2492
2493 #if !defined USING_SQL
2494
2495 new f = fopen(g_ban_file, "wt");
2496
2497
2498
2499 static name[32], steamid[35], banlength, unbantime[32], reason[128], admin_name[32], admin_steamid[35];
2500
2501 for( new i = 0; i < g_total_bans; i++ )
2502
2503 {
2504
2505 copy(name, sizeof(name) - 1, g_names[i]);
2506
2507 copy(steamid, sizeof(steamid) - 1, g_steamids[i]);
2508
2509 banlength = g_banlengths[i];
2510
2511 copy(unbantime, sizeof(unbantime) - 1, g_unbantimes[i]);
2512
2513 copy(reason, sizeof(reason) - 1, g_reasons[i]);
2514
2515 copy(admin_name, sizeof(admin_name) - 1, g_admin_names[i]);
2516
2517 copy(admin_steamid, sizeof(admin_steamid) - 1, g_admin_steamids[i]);
2518
2519
2520
2521 fprintf(f, "^"%s^" ^"%s^" %i ^"%s^" ^"%s^" ^"%s^" ^"%s^"^n",\
2522
2523 steamid,\
2524
2525 name,\
2526
2527 banlength,\
2528
2529 unbantime,\
2530
2531 reason,\
2532
2533 admin_name,\
2534
2535 admin_steamid
2536
2537 );
2538
2539 }
2540
2541
2542
2543 fclose(f);
2544
2545 #endif
2546
2547}
2548
2549#else
2550
2551RemoveBan(pos, const authid[])
2552
2553{
2554
2555 TrieDeleteKey(g_trie, authid);
2556
2557 ArrayDeleteItem(g_array, pos);
2558
2559
2560
2561 g_total_bans--;
2562
2563
2564
2565 #if defined USING_SQL
2566
2567 static query[128];
2568
2569 formatex(query, sizeof(query) - 1,\
2570
2571 "DELETE FROM `%s` WHERE `%s` = '%s';",\
2572
2573 TABLE_NAME, KEY_STEAMID, authid
2574
2575 );
2576
2577
2578
2579 SQL_ThreadQuery(g_sql_tuple, "QueryDeleteBan", query);
2580
2581
2582
2583 new data[BannedData];
2584
2585 for( new i = 0; i < g_total_bans; i++ )
2586
2587 {
2588
2589 ArrayGetArray(g_array, i, data);
2590
2591 TrieSetCell(g_trie, data[bd_steamid], i);
2592
2593 }
2594
2595 #else
2596
2597 new f = fopen(g_ban_file, "wt");
2598
2599
2600
2601 new data[BannedData];
2602
2603 for( new i = 0; i < g_total_bans; i++ )
2604
2605 {
2606
2607 ArrayGetArray(g_array, i, data);
2608
2609 TrieSetCell(g_trie, data[bd_steamid], i);
2610
2611
2612
2613 fprintf(f, "^"%s^" ^"%s^" %i ^"%s^" ^"%s^" ^"%s^" ^"%s^"^n",\
2614
2615 data[bd_steamid],\
2616
2617 data[bd_name],\
2618
2619 data[bd_banlength],\
2620
2621 data[bd_unbantime],\
2622
2623 data[bd_reason],\
2624
2625 data[bd_admin_name],\
2626
2627 data[bd_admin_steamid]
2628
2629 );
2630
2631 }
2632
2633
2634
2635 fclose(f);
2636
2637 #endif
2638
2639}
2640
2641#endif
2642
2643
2644
2645#if defined KEEP_DEFAULT_BANS
2646
2647LoadOldBans(filename[])
2648
2649{
2650
2651 if( file_exists(filename) )
2652
2653 {
2654
2655 new f = fopen(filename, "rt");
2656
2657
2658
2659 static data[96];
2660
2661 static command[10], minutes[10], steamid[35], length, unban_time[32];
2662
2663
2664
2665 while( !feof(f) )
2666
2667 {
2668
2669 fgets(f, data, sizeof(data) - 1);
2670
2671 if( !data[0] ) continue;
2672
2673
2674
2675 parse(data, command, sizeof(command) - 1, minutes, sizeof(minutes) - 1, steamid, sizeof(steamid) - 1);
2676
2677 if( filename[0] == 'b' && !equali(command, "banid") || filename[0] == 'l' && !equali(command, "addip") ) continue;
2678
2679
2680
2681 length = str_to_num(minutes);
2682
2683 GenerateUnbanTime(length, unban_time, sizeof(unban_time) - 1);
2684
2685
2686
2687 AddBan("", steamid, "", length, unban_time, "", "");
2688
2689 }
2690
2691
2692
2693 fclose(f);
2694
2695
2696
2697 static filename2[32];
2698
2699
2700
2701 // copy current
2702
2703 copy(filename2, sizeof(filename2) - 1, filename);
2704
2705
2706
2707 // cut off at the "."
2708
2709 // banned.cfg = banned
2710
2711 // listip.cfg = listip
2712
2713 filename2[containi(filename2, ".")] = 0;
2714
2715
2716
2717 // add 2.cfg
2718
2719 // banned = banned2.cfg
2720
2721 // listip = listip2.cfg
2722
2723 add(filename2, sizeof(filename2) - 1, "2.cfg");
2724
2725
2726
2727 // rename file so that it isnt loaded again
2728
2729 while( !rename_file(filename, filename2, 1) ) { }
2730
2731 }
2732
2733}
2734
2735#endif
2736
2737
2738
2739public LoadBans()
2740
2741{
2742
2743 if( g_total_bans )
2744
2745 {
2746
2747 #if MAX_BANS <= 0
2748
2749 TrieClear(g_trie);
2750
2751 ArrayClear(g_array);
2752
2753 #endif
2754
2755
2756
2757 g_total_bans = 0;
2758
2759 }
2760
2761
2762
2763 #if defined USING_SQL
2764
2765 static query[128];
2766
2767 formatex(query, sizeof(query) - 1,\
2768
2769 "SELECT * FROM `%s`;",\
2770
2771 TABLE_NAME
2772
2773 );
2774
2775
2776
2777 SQL_ThreadQuery(g_sql_tuple, "QueryLoadBans", query);
2778
2779
2780
2781 g_loading_bans = true;
2782
2783 #else
2784
2785 if( file_exists(g_ban_file) )
2786
2787 {
2788
2789 new f = fopen(g_ban_file, "rt");
2790
2791
2792
2793 static filedata[512], length[10];
2794
2795
2796
2797 #if MAX_BANS <= 0
2798
2799 static data[BannedData];
2800
2801 while( !feof(f) )
2802
2803 #else
2804
2805 while( !feof(f) && g_total_bans < MAX_BANS )
2806
2807 #endif
2808
2809 {
2810
2811 fgets(f, filedata, sizeof(filedata) - 1);
2812
2813
2814
2815 if( !filedata[0] ) continue;
2816
2817
2818
2819 #if MAX_BANS <= 0
2820
2821 parse(filedata,\
2822
2823 data[bd_steamid], sizeof(data[bd_steamid]) - 1,\
2824
2825 data[bd_name], sizeof(data[bd_name]) - 1,\
2826
2827 length, sizeof(length) - 1,\
2828
2829 data[bd_unbantime], sizeof(data[bd_unbantime]) - 1,\
2830
2831 data[bd_reason], sizeof(data[bd_reason]) - 1,\
2832
2833 data[bd_admin_name], sizeof(data[bd_admin_name]) - 1,\
2834
2835 data[bd_admin_steamid], sizeof(data[bd_admin_steamid]) - 1
2836
2837 );
2838
2839
2840
2841 data[bd_banlength] = str_to_num(length);
2842
2843
2844
2845 ArrayPushArray(g_array, data);
2846
2847 TrieSetCell(g_trie, data[bd_steamid], g_total_bans);
2848
2849 #else
2850
2851 static steamid[35], name[32], unbantime[32], reason[128], admin_name[32], admin_steamid[35];
2852
2853
2854
2855 parse(filedata,\
2856
2857 steamid, sizeof(steamid) - 1,\
2858
2859 name, sizeof(name) - 1,\
2860
2861 length, sizeof(length) - 1,\
2862
2863 unbantime, sizeof(unbantime) - 1,\
2864
2865 reason, sizeof(reason) - 1,\
2866
2867 admin_name, sizeof(admin_name) - 1,\
2868
2869 admin_steamid, sizeof(admin_steamid) - 1
2870
2871 );
2872
2873
2874
2875 copy(g_names[g_total_bans], sizeof(g_names[]) - 1, name);
2876
2877 copy(g_steamids[g_total_bans], sizeof(g_steamids[]) - 1, steamid);
2878
2879 g_banlengths[g_total_bans] = str_to_num(length);
2880
2881 copy(g_unbantimes[g_total_bans], sizeof(g_unbantimes[]) - 1, unbantime);
2882
2883 copy(g_reasons[g_total_bans], sizeof(g_reasons[]) - 1, reason);
2884
2885 copy(g_admin_names[g_total_bans], sizeof(g_admin_names[]) - 1, admin_name);
2886
2887 copy(g_admin_steamids[g_total_bans], sizeof(g_admin_steamids[]) - 1, admin_steamid);
2888
2889 #endif
2890
2891
2892
2893 g_total_bans++;
2894
2895 }
2896
2897
2898
2899 fclose(f);
2900
2901 }
2902
2903 #endif
2904
2905
2906
2907 // load these after, so when they are added to the file with AddBan(), they aren't loaded again from above.
2908
2909
2910
2911 #if defined KEEP_DEFAULT_BANS
2912
2913 LoadOldBans("banned.cfg");
2914
2915 LoadOldBans("listip.cfg");
2916
2917 #endif
2918
2919}
2920
2921
2922
2923#if defined USING_SQL
2924
2925MakeStringSQLSafe(const input[], output[], len)
2926
2927{
2928
2929 copy(output, len, input);
2930
2931 replace_all(output, len, "'", "*");
2932
2933 replace_all(output, len, "^"", "*");
2934
2935 replace_all(output, len, "`", "*");
2936
2937}
2938
2939#endif
2940
2941
2942
2943GetBanTime(const bantime, length[], len)
2944
2945{
2946
2947 new minutes = bantime;
2948
2949 new hours = 0;
2950
2951 new days = 0;
2952
2953
2954
2955 while( minutes >= 60 )
2956
2957 {
2958
2959 minutes -= 60;
2960
2961 hours++;
2962
2963 }
2964
2965
2966
2967 while( hours >= 24 )
2968
2969 {
2970
2971 hours -= 24;
2972
2973 days++;
2974
2975 }
2976
2977
2978
2979 new bool:add_before;
2980
2981 if( minutes )
2982
2983 {
2984
2985 formatex(length, len, "%i minut%s", minutes, minutes == 1 ? "" : "e");
2986
2987
2988
2989 add_before = true;
2990
2991 }
2992
2993 if( hours )
2994
2995 {
2996
2997 if( add_before )
2998
2999 {
3000
3001 format(length, len, "%i or%s, %s", hours, hours == 1 ? "" : "e", length);
3002
3003 }
3004
3005 else
3006
3007 {
3008
3009 formatex(length, len, "%i or%s", hours, hours == 1 ? "" : "e");
3010
3011
3012
3013 add_before = true;
3014
3015 }
3016
3017 }
3018
3019 if( days )
3020
3021 {
3022
3023 if( add_before )
3024
3025 {
3026
3027 format(length, len, "%i zil%s, %s", days, days == 1 ? "" : "e", length);
3028
3029 }
3030
3031 else
3032
3033 {
3034
3035 formatex(length, len, "%i zil%s", days, days == 1 ? "" : "e");
3036
3037
3038
3039 add_before = true;
3040
3041 }
3042
3043 }
3044
3045 if( !add_before )
3046
3047 {
3048
3049 // minutes, hours, and days = 0
3050
3051 // assume permanent ban
3052
3053 copy(length, len, "permanent");
3054
3055 }
3056
3057}
3058
3059
3060
3061GenerateUnbanTime(const bantime, unban_time[], len)
3062
3063{
3064
3065 static _hours[5], _minutes[5], _seconds[5], _month[5], _day[5], _year[7];
3066
3067 format_time(_hours, sizeof(_hours) - 1, "%H");
3068
3069 format_time(_minutes, sizeof(_minutes) - 1, "%M");
3070
3071 format_time(_seconds, sizeof(_seconds) - 1, "%S");
3072
3073 format_time(_month, sizeof(_month) - 1, "%m");
3074
3075 format_time(_day, sizeof(_day) - 1, "%d");
3076
3077 format_time(_year, sizeof(_year) - 1, "%Y");
3078
3079
3080
3081 new hours = str_to_num(_hours);
3082
3083 new minutes = str_to_num(_minutes);
3084
3085 new seconds = str_to_num(_seconds);
3086
3087 new month = str_to_num(_month);
3088
3089 new day = str_to_num(_day);
3090
3091 new year = str_to_num(_year);
3092
3093
3094
3095 minutes += bantime;
3096
3097
3098
3099 while( minutes >= 60 )
3100
3101 {
3102
3103 minutes -= 60;
3104
3105 hours++;
3106
3107 }
3108
3109
3110
3111 while( hours >= 24 )
3112
3113 {
3114
3115 hours -= 24;
3116
3117 day++;
3118
3119 }
3120
3121
3122
3123 new max_days = GetDaysInMonth(month, year);
3124
3125 while( day > max_days )
3126
3127 {
3128
3129 day -= max_days;
3130
3131 month++;
3132
3133 }
3134
3135
3136
3137 while( month > 12 )
3138
3139 {
3140
3141 month -= 12;
3142
3143 year++;
3144
3145 }
3146
3147
3148
3149 formatex(unban_time, len, "%i:%02i:%02i %i/%i/%i", hours, minutes, seconds, month, day, year);
3150
3151}
3152
3153
3154
3155GetDaysInMonth(month, year=0)
3156
3157{
3158
3159 switch( month )
3160
3161 {
3162
3163 case 1: return 31; // january
3164
3165 case 2: return ((year % 4) == 0) ? 29 : 28; // february
3166
3167 case 3: return 31; // march
3168
3169 case 4: return 30; // april
3170
3171 case 5: return 31; // may
3172
3173 case 6: return 30; // june
3174
3175 case 7: return 31; // july
3176
3177 case 8: return 31; // august
3178
3179 case 9: return 30; // september
3180
3181 case 10: return 31; // october
3182
3183 case 11: return 30; // november
3184
3185 case 12: return 31; // december
3186
3187 }
3188
3189
3190
3191 return 30;
3192
3193}
3194
3195
3196
3197GetTargetFlags(client)
3198
3199{
3200
3201 static const flags_no_immunity = (CMDTARGET_ALLOW_SELF|CMDTARGET_NO_BOTS);
3202
3203 static const flags_immunity = (CMDTARGET_ALLOW_SELF|CMDTARGET_NO_BOTS|CMDTARGET_OBEY_IMMUNITY);
3204
3205
3206
3207 switch( get_pcvar_num(ab_immunity) )
3208
3209 {
3210
3211 case 1: return flags_immunity;
3212
3213 case 2: return access(client, ADMIN_IMMUNITY) ? flags_no_immunity : flags_immunity;
3214
3215 }
3216
3217
3218
3219 return flags_no_immunity;
3220
3221}
3222
3223
3224
3225GetMaxBanTime(client)
3226
3227{
3228
3229 if( !g_total_maxban_times ) return 0;
3230
3231
3232
3233 new flags = get_user_flags(client);
3234
3235
3236
3237 for( new i = 0; i < g_total_maxban_times; i++ )
3238
3239 {
3240
3241 #if !defined MAX_BANLIMITS
3242
3243 if( flags & ArrayGetCell(g_maxban_flags, i) )
3244
3245 {
3246
3247 return ArrayGetCell(g_maxban_times, i);
3248
3249 }
3250
3251 #else
3252
3253 if( flags & g_maxban_flags[i] )
3254
3255 {
3256
3257 return g_maxban_times[i];
3258
3259 }
3260
3261 #endif
3262
3263 }
3264
3265
3266
3267 return 0;
3268
3269}
3270
3271
3272
3273PrintBanInformation(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)
3274
3275{
3276
3277 static website[64], ban_length[64];
3278
3279 if( client == 0 )
3280
3281 {
3282
3283 server_print("================================================");
3284
3285 server_print("%L", client, "AB_BAN_INFORMATION");
3286
3287 server_print("%L: %s", client, "AB_NAME", target_name);
3288
3289 server_print("%L: %s", client, IsValidAuthid(target_authid) ? "AB_STEAMID" : "AB_IP", target_authid);
3290
3291 server_print("%L: %s", client, "AB_REASON", reason);
3292
3293 if( length > 0 )
3294
3295 {
3296
3297 GetBanTime(length, ban_length, sizeof(ban_length) - 1);
3298
3299 server_print("%L: %s", client, "AB_BAN_LENGTH", ban_length);
3300
3301 }
3302
3303 server_print("%L: %s", client, "AB_UNBAN_TIME", unban_time);
3304
3305 if( show_admin )
3306
3307 {
3308
3309 server_print("%L: %s", client, "AB_ADMIN_NAME", admin_name);
3310
3311 server_print("%L: %s", client, "AB_ADMIN_STEAMID", admin_authid);
3312
3313 }
3314
3315 if( show_website )
3316
3317 {
3318
3319 get_pcvar_string(ab_website, website, sizeof(website) - 1);
3320
3321 if( website[0] )
3322
3323 {
3324
3325 server_print("");
3326
3327 server_print("%L", client, "AB_WEBSITE");
3328
3329 server_print("%s", website);
3330
3331 }
3332
3333 }
3334
3335 server_print("================================================");
3336
3337 }
3338
3339 else
3340
3341 {
3342
3343 client_cmd(client, "echo ^"================================================^"");
3344
3345 client_cmd(client, "echo ^"%L^"", client, "AB_BAN_INFORMATION");
3346
3347 client_cmd(client, "echo ^"%L: %s^"", client, "AB_NAME", target_name);
3348
3349 client_cmd(client, "echo ^"%L: %s^"", client, IsValidAuthid(target_authid) ? "AB_STEAMID" : "AB_IP", target_authid);
3350
3351 client_cmd(client, "echo ^"%L: %s^"", client, "AB_REASON", reason);
3352
3353 if( length > 0 )
3354
3355 {
3356
3357 GetBanTime(length, ban_length, sizeof(ban_length) - 1);
3358
3359 client_cmd(client, "echo ^"%L: %s^"", client, "AB_BAN_LENGTH", ban_length);
3360
3361 }
3362
3363 client_cmd(client, "echo ^"%L: %s^"", client, "AB_UNBAN_TIME", unban_time);
3364
3365 if( show_admin )
3366
3367 {
3368
3369 client_cmd(client, "echo ^"%L: %s^"", client, "AB_ADMIN_NAME", admin_name);
3370
3371 client_cmd(client, "echo ^"%L: %s^"", client, "AB_ADMIN_STEAMID", admin_authid);
3372
3373 }
3374
3375 if( show_website )
3376
3377 {
3378
3379 get_pcvar_string(ab_website, website, sizeof(website) - 1);
3380
3381 if( website[0] )
3382
3383 {
3384
3385 client_cmd(client, "echo ^"^"");
3386
3387 client_cmd(client, "echo ^"%L^"", client, "AB_WEBSITE");
3388
3389 client_cmd(client, "echo ^"%s^"", website);
3390
3391 }
3392
3393 }
3394
3395 client_cmd(client, "echo ^"================================================^"");
3396
3397 }
3398
3399}
3400
3401
3402
3403PrintActivity(const admin_name[], const message_fmt[], any:...)
3404
3405{
3406
3407 if( !get_playersnum() ) return;
3408
3409
3410
3411 new activity = get_pcvar_num(amx_show_activity);
3412
3413 if( !(0 <= activity <= 5) )
3414
3415 {
3416
3417 set_pcvar_num(amx_show_activity, (activity = 2));
3418
3419 }
3420
3421
3422
3423 static message[192], temp[192];
3424
3425 vformat(message, sizeof(message) - 1, message_fmt, 3);
3426
3427
3428
3429 for( new client = 1; client <= g_max_clients; client++ )
3430
3431 {
3432
3433 if( !is_user_connected(client) ) continue;
3434
3435
3436
3437 switch( is_user_admin(client) ? g_admin_activity[activity] : g_normal_activity[activity] )
3438
3439 {
3440
3441 case ACTIVITY_NONE:
3442
3443 {
3444
3445
3446
3447 }
3448
3449 case ACTIVITY_HIDE:
3450
3451 {
3452
3453 copy(temp, sizeof(temp) - 1, message);
3454
3455 replace(temp, sizeof(temp) - 1, "$name", "ADMIN");
3456
3457
3458
3459 message_begin(MSG_ONE_UNRELIABLE, g_msgid_SayText, _, client);
3460
3461 write_byte(client);
3462
3463 write_string(temp);
3464
3465 message_end();
3466
3467 }
3468
3469 case ACTIVITY_SHOW:
3470
3471 {
3472
3473 copy(temp, sizeof(temp) - 1, message);
3474
3475 replace(temp, sizeof(temp) - 1, "$name", admin_name);
3476
3477
3478
3479 message_begin(MSG_ONE_UNRELIABLE, g_msgid_SayText, _, client);
3480
3481 write_byte(client);
3482
3483 write_string(temp);
3484
3485 message_end();
3486
3487 }
3488
3489 }
3490
3491 }
3492
3493}
3494
3495
3496
3497Print(const message_fmt[], any:...)
3498
3499{
3500
3501 if( !get_playersnum() ) return;
3502
3503
3504
3505 static message[192];
3506
3507 vformat(message, sizeof(message) - 1, message_fmt, 2);
3508
3509
3510
3511 for( new client = 1; client <= g_max_clients; client++ )
3512
3513 {
3514
3515 if( !is_user_connected(client) ) continue;
3516
3517
3518
3519 message_begin(MSG_ONE_UNRELIABLE, g_msgid_SayText, _, client);
3520
3521 write_byte(client);
3522
3523 write_string(message);
3524
3525 message_end();
3526
3527 }
3528
3529}
3530
3531
3532
3533Log(const message_fmt[], any:...)
3534
3535{
3536
3537 static message[256];
3538
3539 vformat(message, sizeof(message) - 1, message_fmt, 2);
3540
3541
3542
3543 static filename[96];
3544
3545 #if defined HISTORY_ONE_FILE
3546
3547 if( !filename[0] )
3548
3549 {
3550
3551 get_basedir(filename, sizeof(filename) - 1);
3552
3553 add(filename, sizeof(filename) - 1, "/logs/ban_history.log");
3554
3555 }
3556
3557 #else
3558
3559 static dir[64];
3560
3561 if( !dir[0] )
3562
3563 {
3564
3565 get_basedir(dir, sizeof(dir) - 1);
3566
3567 add(dir, sizeof(dir) - 1, "/logs");
3568
3569 }
3570
3571
3572
3573 format_time(filename, sizeof(filename) - 1, "%m%d%Y");
3574
3575 format(filename, sizeof(filename) - 1, "%s/BAN_HISTORY_%s.log", dir, filename);
3576
3577 #endif
3578
3579
3580
3581 log_amx("%s", message);
3582
3583 log_to_file(filename, "%s", message);
3584
3585}
3586
3587/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
3588
3589*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1033\\ f0\\ fs16 \n\\ par }
3590
3591*/