From b2a825652d8588dfb7f1c793403ca05555b1d75f Mon Sep 17 00:00:00 2001 From: Choupom Date: Tue, 6 Sep 2011 16:49:55 +0200 Subject: [PATCH] added a command to unban all --- src/engine/server/server.cpp | 13 +++++++++++ src/engine/server/server.h | 2 ++ src/engine/shared/network.h | 1 + src/engine/shared/network_server.cpp | 33 +++++++++++++++++++--------- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 93e96db9b..d253d3fce 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -1061,6 +1061,11 @@ int CServer::BanRemove(NETADDR Addr) return m_NetServer.BanRemove(Addr); } +int CServer::BanRemoveAll() +{ + return m_NetServer.BanRemoveAll(); +} + void CServer::PumpNetwork() { @@ -1463,6 +1468,13 @@ void CServer::ConUnban(IConsole::IResult *pResult, void *pUser) pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "invalid network address"); } +void CServer::ConUnbanAll(IConsole::IResult *pResult, void *pUser) +{ + CServer *pServer = (CServer *)pUser; + if(!pServer->BanRemoveAll()) + pServer->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "unbanned all"); +} + void CServer::ConBans(IConsole::IResult *pResult, void *pUser) { unsigned Now = time_timestamp(); @@ -1627,6 +1639,7 @@ void CServer::RegisterCommands() Console()->Register("kick", "i?r", CFGFLAG_SERVER, ConKick, this, "Kick player with specified id for any reason"); Console()->Register("ban", "s?ir", CFGFLAG_SERVER|CFGFLAG_STORE, ConBan, this, "Ban player with ip/id for x minutes for any reason"); Console()->Register("unban", "s", CFGFLAG_SERVER|CFGFLAG_STORE, ConUnban, this, "Unban ip"); + Console()->Register("unban_all", "", CFGFLAG_SERVER|CFGFLAG_STORE, ConUnbanAll, this, "Clear all bans"); Console()->Register("bans", "", CFGFLAG_SERVER|CFGFLAG_STORE, ConBans, this, "Show banlist"); Console()->Register("status", "", CFGFLAG_SERVER, ConStatus, this, "List players"); Console()->Register("shutdown", "", CFGFLAG_SERVER, ConShutdown, this, "Shut down"); diff --git a/src/engine/server/server.h b/src/engine/server/server.h index d8fdd8fa4..916eb37de 100644 --- a/src/engine/server/server.h +++ b/src/engine/server/server.h @@ -188,6 +188,7 @@ public: int BanAdd(NETADDR Addr, int Seconds, const char *pReason); int BanRemove(NETADDR Addr); + int BanRemoveAll(); void PumpNetwork(); @@ -200,6 +201,7 @@ public: static void ConKick(IConsole::IResult *pResult, void *pUser); static void ConBan(IConsole::IResult *pResult, void *pUser); static void ConUnban(IConsole::IResult *pResult, void *pUser); + static void ConUnbanAll(IConsole::IResult *pResult, void *pUser); static void ConBans(IConsole::IResult *pResult, void *pUser); static void ConStatus(IConsole::IResult *pResult, void *pUser); static void ConShutdown(IConsole::IResult *pResult, void *pUser); diff --git a/src/engine/shared/network.h b/src/engine/shared/network.h index d10c03b62..a9ace4e37 100644 --- a/src/engine/shared/network.h +++ b/src/engine/shared/network.h @@ -310,6 +310,7 @@ public: // banning int BanAdd(NETADDR Addr, int Seconds, const char *pReason); int BanRemove(NETADDR Addr); + int BanRemoveAll(); int BanNum(); // caution, slow int BanGet(int Index, CBanInfo *pInfo); // caution, slow diff --git a/src/engine/shared/network_server.cpp b/src/engine/shared/network_server.cpp index b100e1a2b..b4986bf0e 100644 --- a/src/engine/shared/network_server.cpp +++ b/src/engine/shared/network_server.cpp @@ -48,16 +48,7 @@ bool CNetServer::Open(NETADDR BindAddr, int MaxClients, int MaxClientsPerIP, int for(int i = 0; i < NET_MAX_CLIENTS; i++) m_aSlots[i].m_Connection.Init(m_Socket); - // setup all pointers for bans - for(int i = 1; i < NET_SERVER_MAXBANS-1; i++) - { - m_BanPool[i].m_pNext = &m_BanPool[i+1]; - m_BanPool[i].m_pPrev = &m_BanPool[i-1]; - } - - m_BanPool[0].m_pNext = &m_BanPool[1]; - m_BanPool[NET_SERVER_MAXBANS-1].m_pPrev = &m_BanPool[NET_SERVER_MAXBANS-2]; - m_BanPool_FirstFree = &m_BanPool[0]; + BanRemoveAll(); return true; } @@ -146,6 +137,28 @@ int CNetServer::BanRemove(NETADDR Addr) return -1; } +int CNetServer::BanRemoveAll() +{ + // clear bans memory + mem_zero(m_aBans, sizeof(m_aBans)); + mem_zero(m_BanPool, sizeof(m_BanPool)); + m_BanPool_FirstFree = 0; + m_BanPool_FirstUsed = 0; + + // setup all pointers for bans + for(int i = 1; i < NET_SERVER_MAXBANS-1; i++) + { + m_BanPool[i].m_pNext = &m_BanPool[i+1]; + m_BanPool[i].m_pPrev = &m_BanPool[i-1]; + } + + m_BanPool[0].m_pNext = &m_BanPool[1]; + m_BanPool[NET_SERVER_MAXBANS-1].m_pPrev = &m_BanPool[NET_SERVER_MAXBANS-2]; + m_BanPool_FirstFree = &m_BanPool[0]; + + return 0; +} + int CNetServer::BanAdd(NETADDR Addr, int Seconds, const char *pReason) { int IpHash = (Addr.ip[0]+Addr.ip[1]+Addr.ip[2]+Addr.ip[3]+Addr.ip[4]+Addr.ip[5]+Addr.ip[6]+Addr.ip[7]+