3608: Fix crash on autoban unsupported client r=heinrich5991 a=fokkonaut

I moved the check where it returns to after the join message because if a client uses the new CLIENTVER system it would just drop without even a join message, looks weird if the chat only shows a player leaving, but not joining :D

## 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 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: fokkonaut <35420825+fokkonaut@users.noreply.github.com>
This commit is contained in:
bors[bot] 2021-02-12 19:04:00 +00:00 committed by GitHub
commit 55a8293e7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 14 deletions

View file

@ -1246,13 +1246,6 @@ void CGameContext::OnClientEnter(int ClientID)
if(!Server()->ClientPrevIngame(ClientID))
{
IServer::CClientInfo Info;
Server()->GetClientInfo(ClientID, &Info);
if(Info.m_GotDDNetVersion)
{
OnClientDDNetVersionKnown(ClientID);
}
char aBuf[512];
str_format(aBuf, sizeof(aBuf), "'%s' entered and joined the %s", Server()->ClientName(ClientID), m_pController->GetTeamName(m_apPlayers[ClientID]->GetTeam()));
SendChat(-1, CGameContext::CHAT_ALL, aBuf, -1, CHAT_SIX);
@ -1266,6 +1259,14 @@ void CGameContext::OnClientEnter(int ClientID)
Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf);
IServer::CClientInfo Info;
Server()->GetClientInfo(ClientID, &Info);
if(Info.m_GotDDNetVersion)
{
if(OnClientDDNetVersionKnown(ClientID))
return; // kicked
}
if(g_Config.m_SvShowOthersDefault > 0)
{
if(g_Config.m_SvShowOthers)
@ -1440,7 +1441,7 @@ void CGameContext::OnClientEngineDrop(int ClientID, const char *pReason)
}
}
void CGameContext::OnClientDDNetVersionKnown(int ClientID)
bool CGameContext::OnClientDDNetVersionKnown(int ClientID)
{
IServer::CClientInfo Info;
Server()->GetClientInfo(ClientID, &Info);
@ -1459,6 +1460,13 @@ void CGameContext::OnClientDDNetVersionKnown(int ClientID)
}
}
// Autoban known bot versions.
if(g_Config.m_SvBannedVersions[0] != '\0' && IsVersionBanned(ClientVersion))
{
Server()->Kick(ClientID, "unsupported client");
return true;
}
CPlayer *pPlayer = m_apPlayers[ClientID];
if(ClientVersion >= VERSION_DDNET_GAMETICK)
pPlayer->m_TimerType = g_Config.m_SvDefaultTimerType;
@ -1479,11 +1487,8 @@ void CGameContext::OnClientDDNetVersionKnown(int ClientID)
// Tell known bot clients that they're botting and we know it.
if(((ClientVersion >= 15 && ClientVersion < 100) || ClientVersion == 502) && g_Config.m_SvClientSuggestionBot[0] != '\0')
SendBroadcast(g_Config.m_SvClientSuggestionBot, ClientID);
// Autoban known bot versions.
if(g_Config.m_SvBannedVersions[0] != '\0' && IsVersionBanned(ClientVersion))
{
Server()->Kick(ClientID, "unsupported client");
}
return false;
}
void *CGameContext::PreProcessMsg(int *MsgID, CUnpacker *pUnpacker, int ClientID)

View file

@ -273,7 +273,7 @@ public:
virtual const char *NetVersion();
// DDRace
void OnClientDDNetVersionKnown(int ClientID);
bool OnClientDDNetVersionKnown(int ClientID);
virtual void FillAntibot(CAntibotRoundData *pData);
int ProcessSpamProtection(int ClientID);
int GetDDRaceTeam(int ClientID);