3440: Fix veto vote, simplified logic r=heinrich5991 a=def-

Reported by Lenah on Discord

Also allow IPs to change their vote when multiple players are connected, with 1 player it always worked.

Further broken by https://github.com/ddnet/ddnet/pull/3405

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
bors[bot] 2020-12-23 11:13:38 +00:00 committed by GitHub
commit 2eae2c9a97
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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(); int64 Now = Server()->Tick();
for(int i = 0; i < MAX_CLIENTS; i++) for(int i = 0; i < MAX_CLIENTS; i++)
{ {
if(!m_apPlayers[i]) if(!m_apPlayers[i] || aVoteChecked[i])
continue; continue;
if((IsKickVote() || IsSpecVote()) && (m_apPlayers[i]->GetTeam() == TEAM_SPECTATORS || if((IsKickVote() || IsSpecVote()) && (m_apPlayers[i]->GetTeam() == TEAM_SPECTATORS ||
@ -851,20 +852,20 @@ void CGameContext::OnTick()
int ActVotePos = m_apPlayers[i]->m_VotePos; int ActVotePos = m_apPlayers[i]->m_VotePos;
// only allow IPs to vote once, but keep veto ability // 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) // 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) for(int j = i + 1; j < MAX_CLIENTS; j++)
{ {
if(!m_apPlayers[j] || aVoteChecked[j] || str_comp(aaBuf[j], aaBuf[i])) if(!m_apPlayers[j] || aVoteChecked[j] || str_comp(aaBuf[j], aaBuf[i]) != 0)
continue; continue;
aVoteChecked[j] = true; // count the latest vote by this ip
if(m_apPlayers[j]->m_Vote && (!ActVote || ActVotePos > m_apPlayers[j]->m_VotePos)) if(ActVotePos < m_apPlayers[j]->m_VotePos)
{ {
ActVote = m_apPlayers[j]->m_Vote; ActVote = m_apPlayers[j]->m_Vote;
ActVotePos = m_apPlayers[j]->m_VotePos; ActVotePos = m_apPlayers[j]->m_VotePos;
} }
aVoteChecked[j] = true;
} }
Total++; Total++;
@ -872,20 +873,28 @@ void CGameContext::OnTick()
Yes++; Yes++;
else if(ActVote < 0) else if(ActVote < 0)
No++; No++;
}
// veto right for players who have been active on server for long and who're not afk // veto right for players who have been active on server for long and who're not afk
if(!IsKickVote() && !IsSpecVote() && m_apPlayers[i] && if(!IsKickVote() && !IsSpecVote() && g_Config.m_SvVoteVetoTime)
!m_apPlayers[i]->m_Afk && m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS && {
g_Config.m_SvVoteVetoTime && // look through all players with same IP again
((Server()->Tick() - m_apPlayers[i]->m_JoinTick) / (Server()->TickSpeed() * 60) > g_Config.m_SvVoteVetoTime || for(int j = i + 1; j < MAX_CLIENTS; j++)
(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(!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) if(ActVote == 0)
Veto = true; Veto = true;
else if(ActVote < 0) else if(ActVote < 0)
VetoStop = true; VetoStop = true;
break;
}
}
} }
} }