Skip to content

Commit d668a11

Browse files
authored
online_checker: initial release (Mistrick#38)
1 parent 81d951c commit d668a11

3 files changed

Lines changed: 108 additions & 1 deletion

File tree

cstrike/addons/amxmodx/configs/map_manager.cfg

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,25 @@ mapm_freeze_in_vote "1"
302302
// RU: Игнорировать приоритеты для номированных карт.
303303
// 0 - disable, 1 - enable
304304
mapm_priority_ignore_nomination "1"
305+
306+
307+
// Online checker
308+
309+
// EN: Number of online checks.
310+
// RU: Кол-во проверок онлайна.
311+
// 0 - disable
312+
mapm_online_check_count "3"
313+
314+
// EN: Online check interval
315+
// Important: the settings are applied only after restarting the map.
316+
//
317+
// RU: Интервал проверок онлайна
318+
// Важно: настройки применяются только после перезапуска карты.
319+
//
320+
// seconds
321+
mapm_online_check_interval "30"
322+
323+
// EN: The time before the start of the online check.
324+
// RU: Время до начала проверок онлайна.
325+
// seconds
326+
mapm_online_check_timeout "120"

cstrike/addons/amxmodx/scripting/include/map_manager_consts.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ enum {
5151
VOTE_BY_CMD,
5252
VOTE_BY_RTV,
5353
VOTE_BY_SCHEDULER,
54-
VOTE_BY_SCHEDULER_SECOND
54+
VOTE_BY_SCHEDULER_SECOND,
55+
VOTE_BY_INCORRECT_ONLINE
5556
};
5657

5758
// used as return value in forward "mapm_analysis_of_results"
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#include <amxmodx>
2+
#include <map_manager>
3+
#include <map_manager_scheduler>
4+
5+
#define PLUGIN "Map Manager: Online checker"
6+
#define VERSION "1.0.0"
7+
#define AUTHOR "Sergey Shorokhov"
8+
9+
#pragma semicolon 1
10+
11+
#define get_num(%0) get_pcvar_num(g_pCvars[%0])
12+
#define get_float(%0) get_pcvar_float(g_pCvars[%0])
13+
14+
enum (+=100) {
15+
TASK_CHECK_ONLINE = 100
16+
};
17+
18+
enum Cvars {
19+
CHECK_INTERVAL,
20+
CHECKS_COUNT,
21+
CHECK_TIMEOUT
22+
};
23+
24+
new g_sPrefix[48];
25+
new g_pCvars[Cvars];
26+
27+
new g_CurrentMap[MapStruct];
28+
new g_Warnings;
29+
30+
public plugin_init() {
31+
register_plugin(PLUGIN, VERSION + VERSION_HASH, AUTHOR);
32+
33+
g_pCvars[CHECK_INTERVAL] = register_cvar("mapm_online_check_interval", "30");
34+
g_pCvars[CHECKS_COUNT] = register_cvar("mapm_online_check_count", "3");
35+
g_pCvars[CHECK_TIMEOUT] = register_cvar("mapm_online_check_timeout", "120");
36+
}
37+
38+
public plugin_cfg() {
39+
mapm_get_prefix(g_sPrefix, charsmax(g_sPrefix));
40+
get_mapname(g_CurrentMap[Map], charsmax(g_CurrentMap[Map]));
41+
}
42+
43+
public task_check_online() {
44+
if(get_num(CHECKS_COUNT) <= 0) {
45+
return;
46+
}
47+
48+
new current_online = get_players_num();
49+
if(current_online != 0 && get_float(CHECK_TIMEOUT) > get_gametime()) {
50+
return;
51+
}
52+
53+
new bool: is_online_incorrect = (current_online < g_CurrentMap[MinPlayers] || current_online > g_CurrentMap[MaxPlayers]);
54+
55+
g_Warnings = clamp(is_online_incorrect ? ++g_Warnings : --g_Warnings, 0, get_num(CHECKS_COUNT));
56+
if(g_Warnings != get_num(CHECKS_COUNT)) {
57+
return;
58+
}
59+
60+
client_print_color(0, print_team_default, "%s^1 %L", g_sPrefix, LANG_PLAYER, "MAPM_RTV_START_VOTE");
61+
62+
map_scheduler_start_vote(VOTE_BY_INCORRECT_ONLINE);
63+
}
64+
65+
public mapm_maplist_loaded(Array: maplist, const nextmap[]) {
66+
remove_task(TASK_CHECK_ONLINE);
67+
68+
new idx = mapm_get_map_index(g_CurrentMap[Map]);
69+
if(idx == INVALID_MAP_INDEX) {
70+
return;
71+
}
72+
73+
g_Warnings = 0;
74+
set_task(get_float(CHECK_INTERVAL), "task_check_online", .flags = "b", .id = TASK_CHECK_ONLINE);
75+
ArrayGetArray(maplist, idx, g_CurrentMap);
76+
}
77+
78+
public mapm_can_be_extended(type) {
79+
if(type != VOTE_BY_INCORRECT_ONLINE) {
80+
return EXTEND_ALLOWED;
81+
}
82+
83+
return EXTEND_BLOCKED;
84+
}

0 commit comments

Comments
 (0)