22#include < map_manager>
33
44# define PLUGIN " Map Manager: BlockList"
5- # define VERSION " 0.0.6 "
5+ # define VERSION " 0.0.7 "
66# define AUTHOR " Mistrick"
77
88#pragma semicolon 1
99
1010# define get_num (%0 ) get_pcvar_num(g_pCvars[%0 ])
1111
1212enum Cvars {
13+ BLOCK_MODE,
1314 BAN_LAST_MAPS
1415};
1516
17+ enum {
18+ BLOCK_BY_NAME,
19+ BLOCK_BY_PREFIX
20+ };
21+
1622new g_pCvars[Cvars];
1723
1824new const FILE_BLOCKED_MAPS[] = " blockedmaps.ini" ; // datadir
1925
2026new Trie: g_tBlockedList;
27+ new Trie: g_tBlockedPrefix;
2128new g_iMaxItems;
2229new bool: g_bNeedCheck;
2330
2431public plugin_init ()
2532{
2633 register_plugin (PLUGIN, VERSION + VERSION_HASH, AUTHOR);
2734
35+ g_pCvars[BLOCK_MODE] = register_cvar (" mapm_blocklist_mode" , " 0" );
2836 g_pCvars[BAN_LAST_MAPS] = register_cvar (" mapm_blocklist_ban_last_maps" , " 10" );
2937}
3038public plugin_natives ()
@@ -44,36 +52,62 @@ public native_get_blocked_count(plugin, params)
4452 get_string (arg_map, map, charsmax (map));
4553 strtolower (map);
4654
47- if (! TrieKeyExists (g_tBlockedList, map)) {
48- return 0 ;
49- }
55+ new count;
5056
51- new count; TrieGetCell (g_tBlockedList, map, count);
57+ if (get_num (BLOCK_MODE) == BLOCK_BY_PREFIX) {
58+ new prefix[MAPNAME_LENGTH];
59+ get_map_prefix (map, prefix, charsmax (prefix));
60+
61+ if (! TrieKeyExists (g_tBlockedPrefix, prefix)) {
62+ return 0 ;
63+ }
64+ TrieGetCell (g_tBlockedPrefix, prefix, count);
65+ } else {
66+ if (! TrieKeyExists (g_tBlockedList, map)) {
67+ return 0 ;
68+ }
69+ TrieGetCell (g_tBlockedList, map, count);
70+ }
5271
5372 return count;
5473}
5574public mapm_maplist_loaded (Array: mapslist)
5675{
5776 if (! g_tBlockedList) {
5877 g_tBlockedList = TrieCreate ();
78+ g_tBlockedPrefix = TrieCreate ();
5979 load_blocklist ();
6080 }
6181
6282 new map_info[MapStruct], blocked, size = ArraySize (mapslist);
83+ new mode = get_num (BLOCK_MODE) == BLOCK_BY_PREFIX;
84+ new map[MAPNAME_LENGTH], prefix[MAPNAME_LENGTH];
85+
6386 for (new i; i < size; i++ ) {
6487 ArrayGetArray (mapslist, i, map_info);
65- if (TrieKeyExists (g_tBlockedList, map_info[Map])) {
66- blocked++ ;
88+ copy (map, charsmax (map), map_info[Map]);
89+ strtolower (map);
90+
91+ if (mode) {
92+ get_map_prefix (map, prefix, charsmax (prefix));
93+ if (TrieKeyExists (g_tBlockedPrefix, prefix)) {
94+ blocked++ ;
95+ }
96+ } else {
97+ if (TrieKeyExists (g_tBlockedList, map)) {
98+ blocked++ ;
99+ }
67100 }
68101 }
69102
70103 new votelist_size = min (mapm_get_votelist_size (), size);
71- new valid_maps = size - blocked;
104+ new valid_maps = votelist_size - blocked;
72105
73106 g_iMaxItems = 0 ;
74107
75108 if (valid_maps <= 0 ) {
76109 TrieClear (g_tBlockedList);
110+ TrieClear (g_tBlockedPrefix);
77111 log_amx (" Blocklist cleared. More blocked maps than available." );
78112 }
79113 else if (valid_maps < votelist_size) {
@@ -97,7 +131,7 @@ load_blocklist()
97131 f = fopen (file_path, " rt" );
98132 temp = fopen (temp_file_path, " wt" );
99133
100- new buffer[40 ], map[MAPNAME_LENGTH], str_count[6 ], count;
134+ new buffer[40 ], map[MAPNAME_LENGTH], prefix[MAPNAME_LENGTH], str_count[6 ], count;
101135
102136 while (! feof (f)) {
103137 fgets (f, buffer, charsmax (buffer));
@@ -113,6 +147,9 @@ load_blocklist()
113147 fprintf (temp, " ^" % s^ " ^" % d^ " ^n" , map, count);
114148 strtolower (map);
115149 TrieSetCell (g_tBlockedList, map, count);
150+
151+ get_map_prefix (map, prefix, charsmax (prefix));
152+ TrieSetCell (g_tBlockedPrefix, prefix, count);
116153 }
117154
118155 fprintf (temp, " ^" % s^ " ^" % d^ " ^n" , cur_map, block_value);
@@ -148,5 +185,13 @@ public mapm_can_be_in_votelist(const map[])
148185 new lower[MAPNAME_LENGTH];
149186 copy (lower, charsmax (lower), map);
150187 strtolower (lower);
151- return TrieKeyExists (g_tBlockedList, lower) ? MAP_BLOCKED : MAP_ALLOWED;
188+
189+ if (get_num (BLOCK_MODE) == BLOCK_BY_PREFIX) {
190+ new prefix[MAPNAME_LENGTH];
191+ get_map_prefix (lower, prefix, charsmax (prefix));
192+ return TrieKeyExists (g_tBlockedPrefix, prefix) ? MAP_BLOCKED : MAP_ALLOWED;
193+ }
194+ else {
195+ return TrieKeyExists (g_tBlockedList, lower) ? MAP_BLOCKED : MAP_ALLOWED;
196+ }
152197}
0 commit comments