From 8f5f45c18f52cf34200c7666386014e29795ca21 Mon Sep 17 00:00:00 2001 From: eeeee Date: Wed, 14 Dec 2011 13:47:23 +0100 Subject: [PATCH 1/3] keep lifebans at the tail of bans list. Fixes #131 --- src/engine/shared/network_server.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/engine/shared/network_server.cpp b/src/engine/shared/network_server.cpp index 6ac266d56..26ba17444 100644 --- a/src/engine/shared/network_server.cpp +++ b/src/engine/shared/network_server.cpp @@ -206,14 +206,19 @@ int CNetServer::BanAdd(NETADDR Addr, int Seconds, const char *pReason) CBan *pInsertAfter = m_BanPool_FirstUsed; MACRO_LIST_FIND(pInsertAfter, m_pNext, Stamp < pInsertAfter->m_Info.m_Expires); - if(pInsertAfter) + if(pInsertAfter && Stamp != -1) pInsertAfter = pInsertAfter->m_pPrev; else { // add to last - pInsertAfter = m_BanPool_FirstUsed; - while(pInsertAfter->m_pNext) - pInsertAfter = pInsertAfter->m_pNext; + if (m_BanPool_FirstUsed->m_Info.m_Expires == -1) + pInsertAfter = 0; + else + { + pInsertAfter = m_BanPool_FirstUsed; + while(pInsertAfter->m_pNext && pInsertAfter->m_pNext->m_Info.m_Expires != -1) + pInsertAfter = pInsertAfter->m_pNext; + } } if(pInsertAfter) From 0c16a58563be79a09cc289781afe8348b45a8f61 Mon Sep 17 00:00:00 2001 From: eeeee Date: Wed, 14 Dec 2011 13:47:49 +0100 Subject: [PATCH 2/3] enforce upper limit on minutes to prevent unix timestamp from overflowing --- src/engine/server/server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index bb47c52a5..f7167c511 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -1444,7 +1444,7 @@ void CServer::ConBan(IConsole::IResult *pResult, void *pUser) const char *pReason = "No reason given"; if(pResult->NumArguments() > 1) - Minutes = max(0, pResult->GetInteger(1)); + Minutes = min(max(0, pResult->GetInteger(1)), 1000000); // todo: fix this in year 2035 if(pResult->NumArguments() > 2) pReason = pResult->GetString(2); From 385be8a7164fc98f474bd1da0cc8a408f3ceec62 Mon Sep 17 00:00:00 2001 From: eeeee Date: Wed, 14 Dec 2011 13:48:41 +0100 Subject: [PATCH 3/3] updating existing bans' expiration would break ordering in bans sorted list --- src/engine/shared/network_server.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/engine/shared/network_server.cpp b/src/engine/shared/network_server.cpp index 26ba17444..26c3d92c9 100644 --- a/src/engine/shared/network_server.cpp +++ b/src/engine/shared/network_server.cpp @@ -174,15 +174,11 @@ int CNetServer::BanAdd(NETADDR Addr, int Seconds, const char *pReason) if(Seconds) Stamp = time_timestamp() + Seconds; - // search to see if it already exists + // search to remove it if it already exists pBan = m_aBans[IpHash]; MACRO_LIST_FIND(pBan, m_pHashNext, net_addr_comp(&pBan->m_Info.m_Addr, &Addr) == 0); if(pBan) - { - // adjust the ban - pBan->m_Info.m_Expires = Stamp; - return 0; - } + BanRemoveByObject(pBan); if(!m_BanPool_FirstFree) return -1;