Skip to content

Commit

Permalink
Lots of map system updates (#327)
Browse files Browse the repository at this point in the history
* Add individual map cooldown configuration
List cooldown of all maps when running !nominate without having set a nomination

* Add map cooldown saving and loading from file

* Move processing of map cooldowns to after vote

This is the same behavour as the map vote system in CS:GO, where the current map will not be set on cooldown until after it is voted off

* Min and Max player requirements

* Update example maplist.cfg

* Add Minimum and Maximum player information to !nominate map list when requirements are not met

* Use snake case format for min/max player keyvalues in maplist.cfg

* Re-add !mapcooldowns chat command

* Change map cooldown file path

* Re-add cs2f_vote_maps_cooldown cvar as the default map cooldown

* Automatically remove nominations when min/max player count requirements not met

* Fix string format of console messages when loading map list

* Add shared function for player count

* Fix a possible edge case with KV1 capitalization handling

Basically, KV1 will cache whichever capitalization gets used first for a string, *globally*.

This previously caused issues with CS:GO's mapchooser cooldown saving, because a map could pack a KV1 cfg with the string "ze_Mako". Then, when we go to save "ze_mako", it will instead be auto-converted to "ze_Mako" because that's what the server used first. So we are just re-implementing the checks to avoid this being an issue.

* Fix nomination resetting not working

* Allow changing map by ID if admin already has console access

* Make !mapcooldowns print in order again

* Don't show disabled maps in !nominate map list

* Fix & update !setnextmap

* Allow immediate RTV's when enabled manually at map start

* Update GetNeededRTVCount to use GetOnlinePlayerCount

* Add more detailed error messages to !nominate

* Added warning on several map-related commands for non-unique queries

* Adjustments for logging

Improves behaviour with a logging backend.. still need to upstream that :)

---------

Co-authored-by: m-arcuri <[email protected]>
Co-authored-by: Hichatu <[email protected]>
  • Loading branch information
3 people authored Nov 25, 2024
1 parent 223a007 commit 85af0af
Show file tree
Hide file tree
Showing 9 changed files with 438 additions and 159 deletions.
2 changes: 1 addition & 1 deletion cfg/cs2fixes/cs2fixes.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ cs2f_rtv_success_ratio 0.6 // Ratio needed to pass RTV
cs2f_rtv_endround 0 // Whether to immediately end the round when RTV succeeds

// Map vote settings
cs2f_vote_maps_cooldown 10 // Number of maps to wait until a map can be voted / nominated again i.e. cooldown.
cs2f_vote_maps_cooldown 10 // Default number of maps to wait until a map can be voted / nominated again i.e. cooldown.
cs2f_vote_max_nominations 10 // Number of nominations to include per vote, out of a maximum of 10.

// User preferences settings
Expand Down
7 changes: 7 additions & 0 deletions configs/maplist.cfg.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@
{
"workshop_id" "123"
"enabled" "1"
"min_players" "30"
"cooldown" "2"
}
"ze_my_second_ze_map"
{
"workshop_id" "456"
"enabled" "1"
"min_players" "5"
"max_players" "10"
"cooldown" "3"
}
"ze_my_third_ze_map"
{
"workshop_id" "789"
"enabled" "1"
"max_players" "20"
"cooldown" "1"
}
}
23 changes: 17 additions & 6 deletions src/adminsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ CON_COMMAND_CHAT_FLAGS(map, "<mapname> - Change map", ADMFLAG_CHANGEMAP)
for (int i = 0; sMapName[i]; i++)
{
// Injection prevention, because we may pass user input to ServerCommand
if (sMapName[i] == ';')
if (sMapName[i] == ';' || sMapName[i] == '|')
return;

sMapName[i] = tolower(sMapName[i]);
Expand All @@ -602,16 +602,27 @@ CON_COMMAND_CHAT_FLAGS(map, "<mapname> - Change map", ADMFLAG_CHANGEMAP)
if (!g_pEngineServer2->IsMapValid(pszMapName))
{
std::string sCommand;
std::vector<int> foundIndexes = g_pMapVoteSystem->GetMapIndexesFromSubstring(pszMapName);

// Check if input is numeric (workshop ID)
// Not safe to expose until crashing on failed workshop addon downloads is fixed
/*if (V_StringToUint64(pszMapName, 0) != 0)
// Not safe to expose to all admins until crashing on failed workshop addon downloads is fixed
if ((!player || player->GetZEPlayer()->IsAdminFlagSet(ADMFLAG_RCON)) && V_StringToUint64(pszMapName, 0) != 0)
{
sCommand = "host_workshop_map " + sMapName;
}*/
if (g_bVoteManagerEnable && g_pMapVoteSystem->GetMapIndexFromSubstring(pszMapName) != -1)
}
else if (g_bVoteManagerEnable && foundIndexes.size() > 0)
{
sCommand = "host_workshop_map " + std::to_string(g_pMapVoteSystem->GetMapWorkshopId(g_pMapVoteSystem->GetMapIndexFromSubstring(pszMapName)));
if (foundIndexes.size() > 1)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Multiple maps matched \x06%s\x01, try being more specific:", pszMapName);

for (int i = 0; i < foundIndexes.size() && i < 5; i++)
ClientPrint(player, HUD_PRINTTALK, "- %s", g_pMapVoteSystem->GetMapName(foundIndexes[i]));

return;
}

sCommand = "host_workshop_map " + std::to_string(g_pMapVoteSystem->GetMapWorkshopId(foundIndexes[0]));
}
else
{
Expand Down
17 changes: 1 addition & 16 deletions src/leader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,6 @@ FAKE_INT_CVAR(cs2f_leader_max_glows, "Max amount of glows set by leaders (doesn'
FAKE_INT_CVAR(cs2f_leader_max_tracers, "Max amount of tracers set by leaders (doesn't impact admins)", g_iMaxTracers, 3, false)
FAKE_INT_CVAR(cs2f_leader_max_beacons, "Max amount of beacons set by leaders (doesn't impact admins)", g_iMaxBeacons, 3, false)

int Leader_GetNeededLeaderVoteCount()
{
int iOnlinePlayers = 0;

for (int i = 0; i < gpGlobals->maxClients; i++)
{
ZEPlayer* pPlayer = g_playerManager->GetPlayer(i);

if (pPlayer && !pPlayer->IsFakeClient())
iOnlinePlayers++;
}

return (int)(iOnlinePlayers * g_flLeaderVoteRatio) + 1;
}

bool Leader_SetNewLeader(ZEPlayer* zpLeader, std::string strColor = "")
{
CCSPlayerController* pLeader = CCSPlayerController::FromSlot(zpLeader->GetPlayerSlot());
Expand Down Expand Up @@ -587,7 +572,7 @@ CON_COMMAND_CHAT(vl, "<name> - Vote for a player to become a leader")
}

int iLeaderVoteCount = pPlayerTarget->GetLeaderVoteCount();
int iNeededLeaderVoteCount = Leader_GetNeededLeaderVoteCount();
int iNeededLeaderVoteCount = (int)(g_playerManager->GetOnlinePlayerCount(false) * g_flLeaderVoteRatio) + 1;;

pPlayer->SetLeaderVoteTime(gpGlobals->curtime);

Expand Down
Loading

0 comments on commit 85af0af

Please sign in to comment.