Skip to content

Commit

Permalink
Minor refactoring of server vote handling
Browse files Browse the repository at this point in the history
Avoid local references and nested assignment for readability when sending vote messages.

Remove unnecessary temporary variable.

Remove dead code.
  • Loading branch information
Robyt3 committed Dec 12, 2024
1 parent 2ec51d7 commit 3058b1c
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/game/server/gamecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,30 +814,32 @@ void CGameContext::SendVoteSet(int ClientId)
{
Msg6.m_Timeout = Msg7.m_Timeout = (m_VoteCloseTime - time_get()) / time_freq();
Msg6.m_pDescription = m_aVoteDescription;
Msg7.m_pDescription = m_aSixupVoteDescription;
Msg6.m_pReason = Msg7.m_pReason = m_aVoteReason;

int &Type = (Msg7.m_Type = protocol7::VOTE_UNKNOWN);
Msg7.m_pDescription = m_aSixupVoteDescription;
if(IsKickVote())
Type = protocol7::VOTE_START_KICK;
Msg7.m_Type = protocol7::VOTE_START_KICK;
else if(IsSpecVote())
Type = protocol7::VOTE_START_SPEC;
Msg7.m_Type = protocol7::VOTE_START_SPEC;
else if(IsOptionVote())
Type = protocol7::VOTE_START_OP;
Msg7.m_Type = protocol7::VOTE_START_OP;
else
Msg7.m_Type = protocol7::VOTE_UNKNOWN;
}
else
{
Msg6.m_Timeout = Msg7.m_Timeout = 0;
Msg6.m_pDescription = Msg7.m_pDescription = "";
Msg6.m_pReason = Msg7.m_pReason = "";

int &Type = (Msg7.m_Type = protocol7::VOTE_UNKNOWN);
if(m_VoteEnforce == VOTE_ENFORCE_NO || m_VoteEnforce == VOTE_ENFORCE_NO_ADMIN)
Type = protocol7::VOTE_END_FAIL;
Msg7.m_Type = protocol7::VOTE_END_FAIL;
else if(m_VoteEnforce == VOTE_ENFORCE_YES || m_VoteEnforce == VOTE_ENFORCE_YES_ADMIN)
Type = protocol7::VOTE_END_PASS;
Msg7.m_Type = protocol7::VOTE_END_PASS;
else if(m_VoteEnforce == VOTE_ENFORCE_ABORT || m_VoteEnforce == VOTE_ENFORCE_CANCEL)
Type = protocol7::VOTE_END_ABORT;
Msg7.m_Type = protocol7::VOTE_END_ABORT;
else
Msg7.m_Type = protocol7::VOTE_UNKNOWN;

if(m_VoteEnforce == VOTE_ENFORCE_NO_ADMIN || m_VoteEnforce == VOTE_ENFORCE_YES_ADMIN)
Msg7.m_ClientId = -1;
Expand Down Expand Up @@ -1218,7 +1220,6 @@ void CGameContext::OnTick()
EndVote();
SendChat(-1, TEAM_ALL, "Vote failed enforced by authorized player", -1, FLAG_SIX);
}
//else if(m_VoteEnforce == VOTE_ENFORCE_NO || time_get() > m_VoteCloseTime)
else if(m_VoteEnforce == VOTE_ENFORCE_NO || (time_get() > m_VoteCloseTime && g_Config.m_SvVoteMajority))
{
EndVote();
Expand Down Expand Up @@ -2478,9 +2479,7 @@ void CGameContext::OnVoteNetMessage(const CNetMsg_Cl_Vote *pMsg, int ClientId)
if(g_Config.m_SvSpamprotection && pPlayer->m_LastVoteTry && pPlayer->m_LastVoteTry + Server()->TickSpeed() * 3 > Server()->Tick())
return;

int64_t Now = Server()->Tick();

pPlayer->m_LastVoteTry = Now;
pPlayer->m_LastVoteTry = Server()->Tick();
pPlayer->UpdatePlaytime();

if(!pMsg->m_Vote)
Expand Down

0 comments on commit 3058b1c

Please sign in to comment.