mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 22:48:18 +00:00
Fix veto vote, simplified logic
Also allow IPs to change their vote when multiple players are connected, with 1 player it always worked. Reported by Lenah on Discord
This commit is contained in:
parent
e6cf5bcacd
commit
e981d1b477
|
@ -820,11 +820,12 @@ void CGameContext::OnTick()
|
|||
}
|
||||
}
|
||||
|
||||
bool aVoteChecked[MAX_CLIENTS] = {0};
|
||||
// remember checked players, only the first player with a specific ip will be handled
|
||||
bool aVoteChecked[MAX_CLIENTS] = {false};
|
||||
int64 Now = Server()->Tick();
|
||||
for(int i = 0; i < MAX_CLIENTS; i++)
|
||||
{
|
||||
if(!m_apPlayers[i])
|
||||
if(!m_apPlayers[i] || aVoteChecked[i])
|
||||
continue;
|
||||
|
||||
if((IsKickVote() || IsSpecVote()) && (m_apPlayers[i]->GetTeam() == TEAM_SPECTATORS ||
|
||||
|
@ -851,41 +852,49 @@ void CGameContext::OnTick()
|
|||
int ActVotePos = m_apPlayers[i]->m_VotePos;
|
||||
|
||||
// only allow IPs to vote once, but keep veto ability
|
||||
if(!aVoteChecked[i])
|
||||
// check for more players with the same ip (only use the vote of the one who voted first)
|
||||
for(int j = i + 1; j < MAX_CLIENTS; j++)
|
||||
{
|
||||
// check for more players with the same ip (only use the vote of the one who voted first)
|
||||
for(int j = i + 1; j < MAX_CLIENTS; ++j)
|
||||
{
|
||||
if(!m_apPlayers[j] || aVoteChecked[j] || str_comp(aaBuf[j], aaBuf[i]))
|
||||
continue;
|
||||
if(!m_apPlayers[j] || aVoteChecked[j] || str_comp(aaBuf[j], aaBuf[i]) != 0)
|
||||
continue;
|
||||
|
||||
aVoteChecked[j] = true;
|
||||
if(m_apPlayers[j]->m_Vote && (!ActVote || ActVotePos > m_apPlayers[j]->m_VotePos))
|
||||
{
|
||||
ActVote = m_apPlayers[j]->m_Vote;
|
||||
ActVotePos = m_apPlayers[j]->m_VotePos;
|
||||
}
|
||||
// count the latest vote by this ip
|
||||
if(ActVotePos < m_apPlayers[j]->m_VotePos)
|
||||
{
|
||||
ActVote = m_apPlayers[j]->m_Vote;
|
||||
ActVotePos = m_apPlayers[j]->m_VotePos;
|
||||
}
|
||||
|
||||
Total++;
|
||||
if(ActVote > 0)
|
||||
Yes++;
|
||||
else if(ActVote < 0)
|
||||
No++;
|
||||
aVoteChecked[j] = true;
|
||||
}
|
||||
|
||||
Total++;
|
||||
if(ActVote > 0)
|
||||
Yes++;
|
||||
else if(ActVote < 0)
|
||||
No++;
|
||||
|
||||
// veto right for players who have been active on server for long and who're not afk
|
||||
if(!IsKickVote() && !IsSpecVote() && m_apPlayers[i] &&
|
||||
!m_apPlayers[i]->m_Afk && m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS &&
|
||||
g_Config.m_SvVoteVetoTime &&
|
||||
((Server()->Tick() - m_apPlayers[i]->m_JoinTick) / (Server()->TickSpeed() * 60) > g_Config.m_SvVoteVetoTime ||
|
||||
(m_apPlayers[i]->GetCharacter() && m_apPlayers[i]->GetCharacter()->m_DDRaceState == DDRACE_STARTED &&
|
||||
(Server()->Tick() - m_apPlayers[i]->GetCharacter()->m_StartTime) / (Server()->TickSpeed() * 60) > g_Config.m_SvVoteVetoTime)))
|
||||
if(!IsKickVote() && !IsSpecVote() && g_Config.m_SvVoteVetoTime)
|
||||
{
|
||||
if(ActVote == 0)
|
||||
Veto = true;
|
||||
else if(ActVote < 0)
|
||||
VetoStop = true;
|
||||
// look through all players with same IP again
|
||||
for(int j = i + 1; j < MAX_CLIENTS; j++)
|
||||
{
|
||||
if(!m_apPlayers[j] || str_comp(aaBuf[j], aaBuf[i]) != 0)
|
||||
continue;
|
||||
|
||||
if(m_apPlayers[j] && !m_apPlayers[j]->m_Afk && m_apPlayers[j]->GetTeam() != TEAM_SPECTATORS &&
|
||||
((Server()->Tick() - m_apPlayers[j]->m_JoinTick) / (Server()->TickSpeed() * 60) > g_Config.m_SvVoteVetoTime ||
|
||||
(m_apPlayers[j]->GetCharacter() && m_apPlayers[j]->GetCharacter()->m_DDRaceState == DDRACE_STARTED &&
|
||||
(Server()->Tick() - m_apPlayers[j]->GetCharacter()->m_StartTime) / (Server()->TickSpeed() * 60) > g_Config.m_SvVoteVetoTime)))
|
||||
{
|
||||
if(ActVote == 0)
|
||||
Veto = true;
|
||||
else if(ActVote < 0)
|
||||
VetoStop = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue