Merge pull request #8650 from def-/pr-ban-time

Don't show ban time for vpn bans
This commit is contained in:
heinrich5991 2024-08-05 21:08:44 +00:00 committed by GitHub
commit 7dc682565b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 26 additions and 24 deletions

View file

@ -250,7 +250,7 @@ public:
virtual int GetAuthedState(int ClientId) const = 0; virtual int GetAuthedState(int ClientId) const = 0;
virtual const char *GetAuthName(int ClientId) const = 0; virtual const char *GetAuthName(int ClientId) const = 0;
virtual void Kick(int ClientId, const char *pReason) = 0; virtual void Kick(int ClientId, const char *pReason) = 0;
virtual void Ban(int ClientId, int Seconds, const char *pReason) = 0; virtual void Ban(int ClientId, int Seconds, const char *pReason, bool DisplayTime) = 0;
virtual void RedirectClient(int ClientId, int Port, bool Verbose = false) = 0; virtual void RedirectClient(int ClientId, int Port, bool Verbose = false) = 0;
virtual void ChangeMap(const char *pMap) = 0; virtual void ChangeMap(const char *pMap) = 0;

View file

@ -60,7 +60,7 @@ void CServerBan::InitServerBan(IConsole *pConsole, IStorage *pStorage, CServer *
} }
template<class T> template<class T>
int CServerBan::BanExt(T *pBanPool, const typename T::CDataType *pData, int Seconds, const char *pReason) int CServerBan::BanExt(T *pBanPool, const typename T::CDataType *pData, int Seconds, const char *pReason, bool DisplayTime)
{ {
// validate address // validate address
if(Server()->m_RconClientId >= 0 && Server()->m_RconClientId < MAX_CLIENTS && if(Server()->m_RconClientId >= 0 && Server()->m_RconClientId < MAX_CLIENTS &&
@ -99,7 +99,7 @@ int CServerBan::BanExt(T *pBanPool, const typename T::CDataType *pData, int Seco
} }
} }
int Result = Ban(pBanPool, pData, Seconds, pReason); int Result = Ban(pBanPool, pData, Seconds, pReason, DisplayTime);
if(Result != 0) if(Result != 0)
return Result; return Result;
@ -122,15 +122,15 @@ int CServerBan::BanExt(T *pBanPool, const typename T::CDataType *pData, int Seco
return Result; return Result;
} }
int CServerBan::BanAddr(const NETADDR *pAddr, int Seconds, const char *pReason) int CServerBan::BanAddr(const NETADDR *pAddr, int Seconds, const char *pReason, bool DisplayTime)
{ {
return BanExt(&m_BanAddrPool, pAddr, Seconds, pReason); return BanExt(&m_BanAddrPool, pAddr, Seconds, pReason, DisplayTime);
} }
int CServerBan::BanRange(const CNetRange *pRange, int Seconds, const char *pReason) int CServerBan::BanRange(const CNetRange *pRange, int Seconds, const char *pReason)
{ {
if(pRange->IsValid()) if(pRange->IsValid())
return BanExt(&m_BanRangePool, pRange, Seconds, pReason); return BanExt(&m_BanRangePool, pRange, Seconds, pReason, true);
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban failed (invalid range)"); Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban failed (invalid range)");
return -1; return -1;
@ -150,7 +150,7 @@ void CServerBan::ConBanExt(IConsole::IResult *pResult, void *pUser)
if(ClientId < 0 || ClientId >= MAX_CLIENTS || pThis->Server()->m_aClients[ClientId].m_State == CServer::CClient::STATE_EMPTY) if(ClientId < 0 || ClientId >= MAX_CLIENTS || pThis->Server()->m_aClients[ClientId].m_State == CServer::CClient::STATE_EMPTY)
pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban error (invalid client id)"); pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban error (invalid client id)");
else else
pThis->BanAddr(pThis->Server()->m_NetServer.ClientAddr(ClientId), Minutes * 60, pReason); pThis->BanAddr(pThis->Server()->m_NetServer.ClientAddr(ClientId), Minutes * 60, pReason, true);
} }
else else
ConBan(pResult, pUser); ConBan(pResult, pUser);
@ -473,11 +473,11 @@ void CServer::Kick(int ClientId, const char *pReason)
m_NetServer.Drop(ClientId, pReason); m_NetServer.Drop(ClientId, pReason);
} }
void CServer::Ban(int ClientId, int Seconds, const char *pReason) void CServer::Ban(int ClientId, int Seconds, const char *pReason, bool DisplayTime)
{ {
NETADDR Addr; NETADDR Addr;
GetClientAddr(ClientId, &Addr); GetClientAddr(ClientId, &Addr);
m_NetServer.NetBan()->BanAddr(&Addr, Seconds, pReason); m_NetServer.NetBan()->BanAddr(&Addr, Seconds, pReason, DisplayTime);
} }
void CServer::RedirectClient(int ClientId, int Port, bool Verbose) void CServer::RedirectClient(int ClientId, int Port, bool Verbose)
@ -1459,7 +1459,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
if(m_aClients[ClientId].m_Traffic > Limit) if(m_aClients[ClientId].m_Traffic > Limit)
{ {
m_NetServer.NetBan()->BanAddr(&pPacket->m_Address, 600, "Stressing network"); m_NetServer.NetBan()->BanAddr(&pPacket->m_Address, 600, "Stressing network", true);
return; return;
} }
if(Diff > 100) if(Diff > 100)
@ -1825,7 +1825,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
if(!Config()->m_SvRconBantime) if(!Config()->m_SvRconBantime)
m_NetServer.Drop(ClientId, "Too many remote console authentication tries"); m_NetServer.Drop(ClientId, "Too many remote console authentication tries");
else else
m_ServerBan.BanAddr(m_NetServer.ClientAddr(ClientId), Config()->m_SvRconBantime * 60, "Too many remote console authentication tries"); m_ServerBan.BanAddr(m_NetServer.ClientAddr(ClientId), Config()->m_SvRconBantime * 60, "Too many remote console authentication tries", true);
} }
} }
else else
@ -2893,7 +2893,7 @@ int CServer::Run()
if(Config()->m_SvDnsblBan) if(Config()->m_SvDnsblBan)
{ {
m_NetServer.NetBan()->BanAddr(m_NetServer.ClientAddr(ClientId), 60, Config()->m_SvDnsblBanReason); m_NetServer.NetBan()->BanAddr(m_NetServer.ClientAddr(ClientId), 60, Config()->m_SvDnsblBanReason, false);
} }
} }
} }

View file

@ -46,14 +46,14 @@ class CServerBan : public CNetBan
class CServer *m_pServer; class CServer *m_pServer;
template<class T> template<class T>
int BanExt(T *pBanPool, const typename T::CDataType *pData, int Seconds, const char *pReason); int BanExt(T *pBanPool, const typename T::CDataType *pData, int Seconds, const char *pReason, bool DisplayTime);
public: public:
class CServer *Server() const { return m_pServer; } class CServer *Server() const { return m_pServer; }
void InitServerBan(class IConsole *pConsole, class IStorage *pStorage, class CServer *pServer); void InitServerBan(class IConsole *pConsole, class IStorage *pStorage, class CServer *pServer);
int BanAddr(const NETADDR *pAddr, int Seconds, const char *pReason) override; int BanAddr(const NETADDR *pAddr, int Seconds, const char *pReason, bool DisplayTime) override;
int BanRange(const CNetRange *pRange, int Seconds, const char *pReason) override; int BanRange(const CNetRange *pRange, int Seconds, const char *pReason) override;
static void ConBanExt(class IConsole::IResult *pResult, void *pUser); static void ConBanExt(class IConsole::IResult *pResult, void *pUser);
@ -279,7 +279,7 @@ public:
void SetClientFlags(int ClientId, int Flags) override; void SetClientFlags(int ClientId, int Flags) override;
void Kick(int ClientId, const char *pReason) override; void Kick(int ClientId, const char *pReason) override;
void Ban(int ClientId, int Seconds, const char *pReason) override; void Ban(int ClientId, int Seconds, const char *pReason, bool DisplayTime) override;
void RedirectClient(int ClientId, int Port, bool Verbose = false) override; void RedirectClient(int ClientId, int Port, bool Verbose = false) override;
void DemoRecorder_HandleAutoStart() override; void DemoRecorder_HandleAutoStart() override;

View file

@ -130,7 +130,7 @@ void CEcon::Update()
if(!g_Config.m_EcBantime) if(!g_Config.m_EcBantime)
m_NetConsole.Drop(ClientId, "Too many authentication tries"); m_NetConsole.Drop(ClientId, "Too many authentication tries");
else else
m_NetConsole.NetBan()->BanAddr(m_NetConsole.ClientAddr(ClientId), g_Config.m_EcBantime * 60, "Too many authentication tries"); m_NetConsole.NetBan()->BanAddr(m_NetConsole.ClientAddr(ClientId), g_Config.m_EcBantime * 60, "Too many authentication tries", true);
} }
} }
} }

View file

@ -208,7 +208,7 @@ typename CNetBan::CBan<T> *CNetBan::CBanPool<T, HashCount>::Get(int Index) const
} }
template<class T> template<class T>
int CNetBan::Ban(T *pBanPool, const typename T::CDataType *pData, int Seconds, const char *pReason) int CNetBan::Ban(T *pBanPool, const typename T::CDataType *pData, int Seconds, const char *pReason, bool DisplayTime)
{ {
// do not ban localhost // do not ban localhost
if(NetMatch(pData, &m_LocalhostIpV4) || NetMatch(pData, &m_LocalhostIpV6)) if(NetMatch(pData, &m_LocalhostIpV4) || NetMatch(pData, &m_LocalhostIpV6))
@ -222,6 +222,7 @@ int CNetBan::Ban(T *pBanPool, const typename T::CDataType *pData, int Seconds, c
// set up info // set up info
CBanInfo Info = {0}; CBanInfo Info = {0};
Info.m_Expires = Stamp; Info.m_Expires = Stamp;
Info.m_DisplayTime = DisplayTime;
str_copy(Info.m_aReason, pReason); str_copy(Info.m_aReason, pReason);
// check if it already exists // check if it already exists
@ -308,15 +309,15 @@ void CNetBan::Update()
} }
} }
int CNetBan::BanAddr(const NETADDR *pAddr, int Seconds, const char *pReason) int CNetBan::BanAddr(const NETADDR *pAddr, int Seconds, const char *pReason, bool DisplayTime)
{ {
return Ban(&m_BanAddrPool, pAddr, Seconds, pReason); return Ban(&m_BanAddrPool, pAddr, Seconds, pReason, DisplayTime);
} }
int CNetBan::BanRange(const CNetRange *pRange, int Seconds, const char *pReason) int CNetBan::BanRange(const CNetRange *pRange, int Seconds, const char *pReason)
{ {
if(pRange->IsValid()) if(pRange->IsValid())
return Ban(&m_BanRangePool, pRange, Seconds, pReason); return Ban(&m_BanRangePool, pRange, Seconds, pReason, true);
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban failed (invalid range)"); Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban failed (invalid range)");
return -1; return -1;
@ -414,7 +415,7 @@ void CNetBan::ConBan(IConsole::IResult *pResult, void *pUser)
NETADDR Addr; NETADDR Addr;
if(net_addr_from_str(&Addr, pStr) == 0) if(net_addr_from_str(&Addr, pStr) == 0)
pThis->BanAddr(&Addr, Minutes * 60, pReason); pThis->BanAddr(&Addr, Minutes * 60, pReason, true);
else else
pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban error (invalid network address)"); pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban error (invalid network address)");
} }

View file

@ -81,6 +81,7 @@ protected:
}; };
int64_t m_Expires; int64_t m_Expires;
char m_aReason[REASON_LENGTH]; char m_aReason[REASON_LENGTH];
bool m_DisplayTime;
}; };
template<class T> template<class T>
@ -150,7 +151,7 @@ protected:
template<class T> template<class T>
void MakeBanInfo(const CBan<T> *pBan, char *pBuf, unsigned BuffSize, int Type) const; void MakeBanInfo(const CBan<T> *pBan, char *pBuf, unsigned BuffSize, int Type) const;
template<class T> template<class T>
int Ban(T *pBanPool, const typename T::CDataType *pData, int Seconds, const char *pReason); int Ban(T *pBanPool, const typename T::CDataType *pData, int Seconds, const char *pReason, bool DisplayTime);
template<class T> template<class T>
int Unban(T *pBanPool, const typename T::CDataType *pData); int Unban(T *pBanPool, const typename T::CDataType *pData);
@ -176,7 +177,7 @@ public:
void Init(class IConsole *pConsole, class IStorage *pStorage); void Init(class IConsole *pConsole, class IStorage *pStorage);
void Update(); void Update();
virtual int BanAddr(const NETADDR *pAddr, int Seconds, const char *pReason); virtual int BanAddr(const NETADDR *pAddr, int Seconds, const char *pReason, bool DisplayTime);
virtual int BanRange(const CNetRange *pRange, int Seconds, const char *pReason); virtual int BanRange(const CNetRange *pRange, int Seconds, const char *pReason);
int UnbanByAddr(const NETADDR *pAddr); int UnbanByAddr(const NETADDR *pAddr);
int UnbanByRange(const CNetRange *pRange); int UnbanByRange(const CNetRange *pRange);
@ -227,7 +228,7 @@ void CNetBan::MakeBanInfo(const CBan<T> *pBan, char *pBuf, unsigned BuffSize, in
} }
// add info part // add info part
if(pBan->m_Info.m_Expires != CBanInfo::EXPIRES_NEVER) if(pBan->m_Info.m_DisplayTime && pBan->m_Info.m_Expires != CBanInfo::EXPIRES_NEVER)
{ {
int Mins = ((pBan->m_Info.m_Expires - time_timestamp()) + 59) / 60; int Mins = ((pBan->m_Info.m_Expires - time_timestamp()) + 59) / 60;
if(Mins <= 1) if(Mins <= 1)