Skip to content

Commit

Permalink
Automatically remove nominations when min/max player count requiremen…
Browse files Browse the repository at this point in the history
…ts not met
  • Loading branch information
m-arcuri committed Nov 17, 2024
1 parent b91a2a6 commit 65ad87f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/map_votes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,4 +805,29 @@ bool CMapVoteSystem::WriteMapCooldownsToFile()
}

return true;
}

void CMapVoteSystem::ClearInvalidNominations()
{
if (!g_bVoteManagerEnable || m_bIsVoteOngoing)
return;

for (int i = 0; i < gpGlobals->maxClients; i++) {
int iNominatedMapIndex = m_arrPlayerNominations[i];

// Ignore unset nominations (negative index)
if (iNominatedMapIndex < 0)
continue;

// Check if nominated index still meets criteria for nomination
if (!IsMapIndexEnabled(iNominatedMapIndex))
{
ClearPlayerInfo(i);
CCSPlayerController* pPlayer = CCSPlayerController::FromSlot(i);
if (!pPlayer)
continue;

ClientPrint(pPlayer, HUD_PRINTTALK, CHAT_PREFIX "Your nomination for \x06%s \x01has been removed because the player count requirements are no longer met.", GetMapName(iNominatedMapIndex));
}
}
}
1 change: 1 addition & 0 deletions src/map_votes.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class CMapVoteSystem
bool GetMapEnabledStatus(int iMapIndex) { return m_vecMapList[iMapIndex].IsEnabled(); }
int GetDefaultMapCooldown() { return m_iDefaultMapCooldown; }
void SetDefaultMapCooldown(int iMapCooldown) { m_iDefaultMapCooldown = iMapCooldown; }
void ClearInvalidNominations();

private:
int WinningMapIndex();
Expand Down
2 changes: 2 additions & 0 deletions src/playermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ bool CPlayerManager::OnClientConnected(CPlayerSlot slot, uint64 xuid, const char
ResetPlayerFlags(slot.Get());

g_pMapVoteSystem->ClearPlayerInfo(slot.Get());
g_pMapVoteSystem->ClearInvalidNominations();

return true;
}
Expand All @@ -627,6 +628,7 @@ void CPlayerManager::OnClientDisconnect(CPlayerSlot slot)
ResetPlayerFlags(slot.Get());

g_pMapVoteSystem->ClearPlayerInfo(slot.Get());
g_pMapVoteSystem->ClearInvalidNominations();

g_pPanoramaVoteHandler->RemovePlayerFromVote(slot.Get());
}
Expand Down

0 comments on commit 65ad87f

Please sign in to comment.