now fetching min/max player restrictions from the playtime frontned

This commit is contained in:
jenz
2026-11-16 19:43:44 +01:00
parent f79c1eb314
commit 7a4f26c2bd
@@ -129,6 +129,10 @@ Handle g_NominateList[MAXPLAYERS + 1];
StringMap g_OldMapList;
StringMap g_TimeMapList;
StringMap g_CooldownList;
//data-driven player-count restrictions from the playtime frontend (/api/maps/restrictions). 0 = no limit.
StringMap g_AutoMinPlayers;
StringMap g_AutoMaxPlayers;
bool g_bAutoPlayerRestrictions = true;
Handle g_NextMapList = INVALID_HANDLE;
Handle g_VoteMenu = INVALID_HANDLE;
KeyValues g_Config;
@@ -263,6 +267,8 @@ public void OnPluginStart()
g_OldMapList = new StringMap();
g_TimeMapList = new StringMap();
g_CooldownList = new StringMap();
g_AutoMinPlayers = new StringMap();
g_AutoMaxPlayers = new StringMap();
g_NextMapList = CreateArray(arraySize);
g_OfficialList = CreateArray(arraySize);
g_hTopImpactMaps = CreateArray(arraySize);
@@ -310,6 +316,11 @@ public void OnPluginStart()
g_iImpactExtraCooldownTime = cvar2_1.IntValue;
delete cvar2_1;
ConVar cvar2_3;
HookConVarChange((cvar2_3 = CreateConVar("mce_auto_player_restrictions", "1", "Use MinPlayers/MaxPlayers worked out by the playtime frontend instead of the config values for maps that have them.")), Cvar_auto_player_restrictions);
g_bAutoPlayerRestrictions = cvar2_3.BoolValue;
delete cvar2_3;
ConVar cvar2_2;
HookConVarChange((cvar2_2 = CreateConVar("mce_impact_extra_cooldown_max_hours", "240", "Maximum extra cooldown hours from the impact penalty. 0 = no cap.")), Cvar_impact_extra_cooldown_max);
g_iImpactExtraCooldownMaxHours = cvar2_2.IntValue;
@@ -476,6 +487,11 @@ public void Cvar_impact_extra_cooldown(ConVar convar, const char[] oldValue, con
g_iImpactExtraCooldownTime = convar.IntValue;
}
public void Cvar_auto_player_restrictions(ConVar convar, const char[] oldValue, const char[] newValue)
{
g_bAutoPlayerRestrictions = convar.BoolValue;
}
public void Cvar_impact_extra_cooldown_max(ConVar convar, const char[] oldValue, const char[] newValue)
{
g_iImpactExtraCooldownMaxHours = convar.IntValue;
@@ -633,9 +649,50 @@ public void GetMapsImpact(char[] currentmap)
public Action Timer_FillMapsByImpact(Handle timer)
{
FillMapsByImpact(0);
FetchAutoRestrictions();
return Plugin_Stop;
}
public void FetchAutoRestrictions()
{
HTTPRequest hRequest = new HTTPRequest("https://playtime-sessions.unloze.com/api/maps/restrictions");
hRequest.Get(OnAutoRestrictionsReceived);
}
public void OnAutoRestrictionsReceived(HTTPResponse response, any value)
{
//on failure we keep the restrictions from the previous successful fetch.
if (response.Status != HTTPStatus_OK || response.Data == null)
{
LogError("Auto restrictions request error: %d", response.Status);
return;
}
JSONObject root = view_as<JSONObject>(response.Data);
JSONArray maps = view_as<JSONArray>(root.Get("maps"));
if (maps == null)
{
delete root;
return;
}
g_AutoMinPlayers.Clear();
g_AutoMaxPlayers.Clear();
char mapName[PLATFORM_MAX_PATH];
for (int i = 0; i < maps.Length; i++)
{
JSONObject entry = view_as<JSONObject>(maps.Get(i));
if (entry == null)
{
continue;
}
entry.GetString("map_name", mapName, sizeof(mapName));
g_AutoMinPlayers.SetValue(mapName, entry.GetInt("min_players"), true);
g_AutoMaxPlayers.SetValue(mapName, entry.GetInt("max_players"), true);
delete entry;
}
delete maps;
delete root;
}
public void FillMapsByImpact(int offset)
{
char sRequest[256];
@@ -2358,6 +2415,10 @@ void CreateNextVote()
}
if (InternalGetMapCooldownTime(map) > GetTime())
continue;
//casual pool picks still skip the other restrictions, but respect the player-count range
//(which now comes from the playtime frontend data).
if (InternalAreRestrictionsActive() && InternalGetMapPlayerRestriction(map) != 0)
continue;
pickedFromCasualPool++;
//LogMessage("picked map %s from CasualPool", map);
break;
@@ -3431,6 +3492,12 @@ stock int InternalGetMapMinPlayers(const char[] map)
{
int MinPlayers = 0;
//a map listed by the playtime frontend uses its data-driven range for both sides (0 = no limit).
if (g_bAutoPlayerRestrictions && g_AutoMinPlayers.GetValue(map, MinPlayers))
{
return MinPlayers;
}
if(g_Config && g_Config.JumpToKey(map))
{
MinPlayers = g_Config.GetNum("MinPlayers", MinPlayers);
@@ -3455,6 +3522,12 @@ stock int InternalGetMapMaxPlayers(const char[] map)
{
int MaxPlayers = 0;
//a map listed by the playtime frontend uses its data-driven range for both sides (0 = no limit).
if (g_bAutoPlayerRestrictions && g_AutoMaxPlayers.GetValue(map, MaxPlayers))
{
return MaxPlayers;
}
if(g_Config && g_Config.JumpToKey(map))
{
MaxPlayers = g_Config.GetNum("MaxPlayers", MaxPlayers);