6070: Add reason to vote mute, fix vote mute r=def- a=Vy0x2

<!-- What is the motivation for the changes of this pull request? -->
When vote muting a player, the message which notifies the player got send in team chat (should be chat_all) and a second message appeared in rcon. Furthermore you couldnt add a reason to vote mutes.

Fixed those issues.
<!-- Note that builds and other checks will be run for your change. Don't feel intimidated by failures in some of the checks. If you can't resolve them yourself, experienced devs can also resolve them before merging your pull request. -->

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [x] Considered possible null pointers and out of bounds array indexing
- [x] 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: Vy0x2 <denispaul43@gmail.com>
This commit is contained in:
bors[bot] 2022-11-28 07:36:59 +00:00 committed by GitHub
commit cb5c2c0d02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 24 deletions

View file

@ -46,7 +46,7 @@ CONSOLE_COMMAND("force_unpause", "v[id]", CFGFLAG_SERVER, ConForcePause, this, "
CONSOLE_COMMAND("set_team_ddr", "v[id] i[team]", CFGFLAG_SERVER, ConSetDDRTeam, this, "Set ddrace team of a player")
CONSOLE_COMMAND("uninvite", "v[id] i[team]", CFGFLAG_SERVER, ConUninvite, this, "Uninvite player from team")
CONSOLE_COMMAND("vote_mute", "v[id] i[seconds]", CFGFLAG_SERVER, ConVoteMute, this, "Remove v's right to vote for i seconds")
CONSOLE_COMMAND("vote_mute", "v[id] i[seconds] ?r[reason]", CFGFLAG_SERVER, ConVoteMute, this, "Remove v's right to vote for i seconds")
CONSOLE_COMMAND("vote_unmute", "v[id]", CFGFLAG_SERVER, ConVoteUnmute, this, "Give back v's right to vote.")
CONSOLE_COMMAND("vote_mutes", "", CFGFLAG_SERVER, ConVoteMutes, this, "List the current active vote mutes.")
CONSOLE_COMMAND("mute", "", CFGFLAG_SERVER, ConMute, this, "")

View file

@ -385,7 +385,7 @@ void CGameContext::ConForcePause(IConsole::IResult *pResult, void *pUserData)
pPlayer->ForcePause(Seconds);
}
bool CGameContext::TryVoteMute(const NETADDR *pAddr, int Secs)
bool CGameContext::TryVoteMute(const NETADDR *pAddr, int Secs, const char *pReason)
{
// find a matching vote mute for this ip, update expiration time if found
for(int i = 0; i < m_NumVoteMutes; i++)
@ -393,6 +393,7 @@ bool CGameContext::TryVoteMute(const NETADDR *pAddr, int Secs)
if(net_addr_comp_noport(&m_aVoteMutes[i].m_Addr, pAddr) == 0)
{
m_aVoteMutes[i].m_Expire = Server()->Tick() + Secs * Server()->TickSpeed();
str_copy(m_aVoteMutes[i].m_aReason, pReason, sizeof(m_aVoteMutes[i].m_aReason));
return true;
}
}
@ -402,6 +403,7 @@ bool CGameContext::TryVoteMute(const NETADDR *pAddr, int Secs)
{
m_aVoteMutes[m_NumVoteMutes].m_Addr = *pAddr;
m_aVoteMutes[m_NumVoteMutes].m_Expire = Server()->Tick() + Secs * Server()->TickSpeed();
str_copy(m_aVoteMutes[m_NumVoteMutes].m_aReason, pReason, sizeof(m_aVoteMutes[m_NumVoteMutes].m_aReason));
m_NumVoteMutes++;
return true;
}
@ -410,19 +412,21 @@ bool CGameContext::TryVoteMute(const NETADDR *pAddr, int Secs)
return false;
}
bool CGameContext::VoteMute(const NETADDR *pAddr, int Secs, const char *pDisplayName, int AuthedID)
void CGameContext::VoteMute(const NETADDR *pAddr, int Secs, const char *pReason, const char *pDisplayName, int AuthedID)
{
if(!TryVoteMute(pAddr, Secs))
return false;
if(!TryVoteMute(pAddr, Secs, pReason))
return;
if(!pDisplayName)
return true;
return;
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;
if(pReason[0])
str_format(aBuf, sizeof aBuf, "'%s' banned '%s' for %d seconds from voting (%s)",
Server()->ClientName(AuthedID), pDisplayName, Secs, pReason);
else
str_format(aBuf, sizeof aBuf, "'%s' banned '%s' for %d seconds from voting",
Server()->ClientName(AuthedID), pDisplayName, Secs);
SendChat(-1, CHAT_ALL, aBuf);
}
bool CGameContext::VoteUnmute(const NETADDR *pAddr, const char *pDisplayName, int AuthedID)
@ -513,15 +517,8 @@ void CGameContext::ConVoteMute(IConsole::IResult *pResult, void *pUserData)
pSelf->Server()->GetClientAddr(Victim, &Addr);
int Seconds = clamp(pResult->GetInteger(1), 1, 86400);
bool Found = pSelf->VoteMute(&Addr, Seconds, pSelf->Server()->ClientName(Victim), pResult->m_ClientID);
if(Found)
{
char aBuf[128];
str_format(aBuf, sizeof aBuf, "'%s' banned '%s' for %d seconds from voting.",
pSelf->Server()->ClientName(pResult->m_ClientID), pSelf->Server()->ClientName(Victim), Seconds);
pSelf->SendChat(-1, 0, aBuf);
}
const char *pReason = pResult->NumArguments() > 2 ? pResult->GetString(2) : "";
pSelf->VoteMute(&Addr, Seconds, pReason, pSelf->Server()->ClientName(Victim), pResult->m_ClientID);
}
void CGameContext::ConVoteUnmute(IConsole::IResult *pResult, void *pUserData)
@ -568,8 +565,8 @@ void CGameContext::ConVoteMutes(IConsole::IResult *pResult, void *pUserData)
for(int i = 0; i < pSelf->m_NumVoteMutes; i++)
{
net_addr_str(&pSelf->m_aVoteMutes[i].m_Addr, aIpBuf, sizeof(aIpBuf), false);
str_format(aBuf, sizeof aBuf, "%d: \"%s\", %d seconds left", i,
aIpBuf, (pSelf->m_aVoteMutes[i].m_Expire - pSelf->Server()->Tick()) / pSelf->Server()->TickSpeed());
str_format(aBuf, sizeof aBuf, "%d: \"%s\", %d seconds left (%s)", i,
aIpBuf, (pSelf->m_aVoteMutes[i].m_Expire - pSelf->Server()->Tick()) / pSelf->Server()->TickSpeed(), pSelf->m_aVoteMutes[i].m_aReason);
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "votemutes", aBuf);
}
}

View file

@ -440,8 +440,8 @@ private:
int m_NumVoteMutes;
bool TryMute(const NETADDR *pAddr, int Secs, const char *pReason, bool InitialChatDelay);
void Mute(const NETADDR *pAddr, int Secs, const char *pDisplayName, const char *pReason = "", bool InitialChatDelay = false);
bool TryVoteMute(const NETADDR *pAddr, int Secs);
bool VoteMute(const NETADDR *pAddr, int Secs, const char *pDisplayName, int AuthedID);
bool TryVoteMute(const NETADDR *pAddr, int Secs, const char *pReason);
void VoteMute(const NETADDR *pAddr, int Secs, const char *pReason, const char *pDisplayName, int AuthedID);
bool VoteUnmute(const NETADDR *pAddr, const char *pDisplayName, int AuthedID);
void Whisper(int ClientID, char *pStr);
void WhisperID(int ClientID, int VictimID, const char *pMessage);