added a command to unban all

This commit is contained in:
Choupom 2011-09-06 16:49:55 +02:00 committed by oy
parent 873c5a77bc
commit b2a825652d
4 changed files with 39 additions and 10 deletions

View file

@ -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");

View file

@ -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);

View file

@ -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

View file

@ -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]+