From deaab4bb4b0bd98983c8487ddca19d7c2b6f4725 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Fri, 12 Apr 2019 19:50:02 +0200 Subject: [PATCH] Add functions instead of goto --- src/game/server/ddracecommands.cpp | 58 +++++++++++++++++------------- src/game/server/gamecontext.h | 2 ++ 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/game/server/ddracecommands.cpp b/src/game/server/ddracecommands.cpp index 83ef3b8e7..70bd57c60 100644 --- a/src/game/server/ddracecommands.cpp +++ b/src/game/server/ddracecommands.cpp @@ -343,7 +343,7 @@ void CGameContext::ConForcePause(IConsole::IResult *pResult, void *pUserData) pPlayer->ForcePause(Seconds); } -bool CGameContext::VoteMute(const NETADDR *pAddr, int Secs, const char *pDisplayName, int AuthedID) +bool CGameContext::TryVoteMute(const NETADDR *pAddr, int Secs) { // find a matching vote mute for this ip, update expiration time if found for(int i = 0; i < m_NumVoteMutes; i++) @@ -352,7 +352,7 @@ bool CGameContext::VoteMute(const NETADDR *pAddr, int Secs, const char *pDisplay { m_aVoteMutes[i].m_Expire = Server()->Tick() + Secs * Server()->TickSpeed(); - goto success; + return true; } } @@ -363,21 +363,25 @@ bool CGameContext::VoteMute(const NETADDR *pAddr, int Secs, const char *pDisplay m_aVoteMutes[m_NumVoteMutes].m_Expire = Server()->Tick() + Secs * Server()->TickSpeed(); m_NumVoteMutes++; - goto success; + return true; } - // no free slot found Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "votemute", "vote mute array is full"); return false; +} - success: - if(pDisplayName) - { - char aBuf[128]; - str_format(aBuf, sizeof aBuf, "'%s' banned '%s' for %d seconds from voting.", - Server()->ClientName(AuthedID), pDisplayName, Secs); - Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "votemute", aBuf); - } +bool CGameContext::VoteMute(const NETADDR *pAddr, int Secs, const char *pDisplayName, int AuthedID) +{ + if (!TryVoteMute(pAddr, Secs)) + return false; + + if(!pDisplayName) + return true; + + char aBuf[128]; + str_format(aBuf, sizeof aBuf, "'%s' banned '%s' for %d seconds from voting.", + Server()->ClientName(AuthedID), pDisplayName, Secs); + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "votemute", aBuf); return true; } @@ -402,7 +406,7 @@ bool CGameContext::VoteUnmute(const NETADDR *pAddr, const char *pDisplayName, in return false; } -void CGameContext::Mute(const NETADDR *pAddr, int Secs, const char *pDisplayName) +bool CGameContext::TryMute(const NETADDR *pAddr, int Secs) { // find a matching mute for this ip, update expiration time if found for(int i = 0; i < m_NumMutes; i++) @@ -411,7 +415,7 @@ void CGameContext::Mute(const NETADDR *pAddr, int Secs, const char *pDisplayName { m_aMutes[i].m_Expire = Server()->Tick() + Secs * Server()->TickSpeed(); - goto success; + return true; } } @@ -422,21 +426,25 @@ void CGameContext::Mute(const NETADDR *pAddr, int Secs, const char *pDisplayName m_aMutes[m_NumMutes].m_Expire = Server()->Tick() + Secs * Server()->TickSpeed(); m_NumMutes++; - goto success; + return true; } - // no free slot found Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "mutes", "mute array is full"); - return; + return false; +} - success: - if(pDisplayName) - { - char aBuf[128]; - str_format(aBuf, sizeof aBuf, "'%s' has been muted for %d seconds.", - pDisplayName, Secs); - SendChat(-1, CHAT_ALL, aBuf); - } +void CGameContext::Mute(const NETADDR *pAddr, int Secs, const char *pDisplayName) +{ + if (!TryVoteMute(pAddr, Secs)) + return; + + if(!pDisplayName) + return; + + char aBuf[128]; + str_format(aBuf, sizeof aBuf, "'%s' has been muted for %d seconds.", + pDisplayName, Secs); + SendChat(-1, CHAT_ALL, aBuf); } void CGameContext::ConVoteMute(IConsole::IResult *pResult, void *pUserData) diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index 079014b27..bfff9c8e6 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -386,7 +386,9 @@ private: int m_NumMutes; CVoteMute m_aVoteMutes[MAX_VOTE_MUTES]; int m_NumVoteMutes; + bool TryMute(const NETADDR *pAddr, int Secs); void Mute(const NETADDR *pAddr, int Secs, const char *pDisplayName); + bool TryVoteMute(const NETADDR *pAddr, int Secs); bool VoteMute(const NETADDR *pAddr, int Secs, const char *pDisplayName, int AuthedID); bool VoteUnmute(const NETADDR *pAddr, const char *pDisplayName, int AuthedID); void Whisper(int ClientID, char *pStr);